List of usage examples for com.amazonaws.services.cloudformation.model StackStatus ROLLBACK_COMPLETE
StackStatus ROLLBACK_COMPLETE
To view the source code for com.amazonaws.services.cloudformation.model StackStatus ROLLBACK_COMPLETE.
Click Source Link
From source file:com.nike.cerberus.operation.cms.CreateCmsClusterOperation.java
License:Apache License
@Override public void run(final CreateCmsClusterCommand command) { final String uniqueStackName = String.format("%s-%s", StackName.CMS.getName(), uuidSupplier.get()); final BaseOutputs baseOutputs = configStore.getBaseStackOutputs(); final Optional<String> cmsServerCertificateArn = configStore.getServerCertificateArn(StackName.CMS); final Optional<String> pubKey = configStore.getCertPart(StackName.CMS, ConfigConstants.CERT_PART_PUBKEY); final String internalElbCname = configStore.getInternalElbCname(StackName.CMS); if (!cmsServerCertificateArn.isPresent() || !pubKey.isPresent()) { throw new IllegalStateException("CMS certificate has not been uploaded!"); }/*from w w w .ja va2 s.c om*/ final CmsParameters cmsParameters = new CmsParameters() .setInstanceProfileName(baseOutputs.getCmsInstanceProfileName()) .setCmsElbSgId(baseOutputs.getCmsElbSgId()).setCmsSgId(baseOutputs.getCmsSgId()) .setToolsIngressSgId(baseOutputs.getToolsIngressSgId()).setVpcId(baseOutputs.getVpcId()) .setVpcSubnetIdForAz1(baseOutputs.getVpcSubnetIdForAz1()) .setVpcSubnetIdForAz2(baseOutputs.getVpcSubnetIdForAz2()) .setVpcSubnetIdForAz3(baseOutputs.getVpcSubnetIdForAz3()) .setHostedZoneId(baseOutputs.getVpcHostedZoneId()).setCname(internalElbCname); cmsParameters.getSslConfigParameters().setCertPublicKey(pubKey.get()); cmsParameters.getSslConfigParameters().setSslCertificateArn(cmsServerCertificateArn.get()); cmsParameters.getLaunchConfigParameters().setAmiId(command.getStackDelegate().getAmiId()); cmsParameters.getLaunchConfigParameters().setInstanceSize(command.getStackDelegate().getInstanceSize()); cmsParameters.getLaunchConfigParameters().setKeyPairName(command.getStackDelegate().getKeyPairName()); cmsParameters.getLaunchConfigParameters().setUserData( ec2UserDataService.getUserData(StackName.CMS, command.getStackDelegate().getOwnerGroup())); cmsParameters.getTagParameters().setTagEmail(command.getStackDelegate().getOwnerEmail()); cmsParameters.getTagParameters().setTagName(ConfigConstants.ENV_PREFIX + environmentMetadata.getName()); cmsParameters.getTagParameters().setTagCostcenter(command.getStackDelegate().getCostcenter()); final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() { }; final Map<String, String> parameters = cloudformationObjectMapper.convertValue(cmsParameters, typeReference); final String stackId = cloudFormationService.createStack( cloudFormationService.getEnvStackName(uniqueStackName), parameters, ConfigConstants.CMS_STACK_TEMPLATE_PATH, true); logger.info("Uploading data to the configuration bucket."); configStore.storeStackId(StackName.CMS, stackId); logger.info("Uploading complete."); final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.CREATE_COMPLETE, StackStatus.ROLLBACK_COMPLETE)); if (endStatus != StackStatus.CREATE_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } }
From source file:com.nike.cerberus.operation.consul.CreateConsulClusterOperation.java
License:Apache License
@Override public void run(final CreateConsulClusterCommand command) { final String uniqueStackName = String.format("%s-%s", StackName.CONSUL.getName(), uuidSupplier.get()); final BaseOutputs baseOutputs = configStore.getBaseStackOutputs(); final ConsulParameters consulParameters = new ConsulParameters() .setInstanceProfileName(baseOutputs.getConsulInstanceProfileName()) .setConsulClientSgId(baseOutputs.getConsulClientSgId()) .setConsulServerSgId(baseOutputs.getConsulServerSgId()) .setToolsIngressSgId(baseOutputs.getToolsIngressSgId()).setVpcId(baseOutputs.getVpcId()) .setVpcSubnetIdForAz1(baseOutputs.getVpcSubnetIdForAz1()) .setVpcSubnetIdForAz2(baseOutputs.getVpcSubnetIdForAz2()) .setVpcSubnetIdForAz3(baseOutputs.getVpcSubnetIdForAz3()); consulParameters.getLaunchConfigParameters().setAmiId(command.getStackDelegate().getAmiId()); consulParameters.getLaunchConfigParameters().setInstanceSize(command.getStackDelegate().getInstanceSize()); consulParameters.getLaunchConfigParameters().setKeyPairName(command.getStackDelegate().getKeyPairName()); consulParameters.getLaunchConfigParameters().setUserData( ec2UserDataService.getUserData(StackName.CONSUL, command.getStackDelegate().getOwnerGroup())); consulParameters.getTagParameters().setTagEmail(command.getStackDelegate().getOwnerEmail()); consulParameters.getTagParameters().setTagName(ConfigConstants.ENV_PREFIX + environmentMetadata.getName()); consulParameters.getTagParameters().setTagCostcenter(command.getStackDelegate().getCostcenter()); final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() { };/*from w w w. j av a 2 s.c o m*/ final Map<String, String> parameters = cloudformationObjectMapper.convertValue(consulParameters, typeReference); final String stackId = cloudFormationService.createStack( cloudFormationService.getEnvStackName(uniqueStackName), parameters, ConfigConstants.CONSUL_STACK_TEMPLATE_PATH, true); logger.info("Uploading data to the configuration bucket."); configStore.storeStackId(StackName.CONSUL, stackId); logger.info("Uploading complete."); final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.CREATE_COMPLETE, StackStatus.ROLLBACK_COMPLETE)); if (endStatus != StackStatus.CREATE_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } }
From source file:com.nike.cerberus.operation.core.CreateBaseOperation.java
License:Apache License
@Override public void run(final CreateBaseCommand command) { final String uniqueStackName = String.format("%s-%s", ConfigConstants.BASE_STACK_NAME, uuidSupplier.get()); final Map<Integer, String> azByIdentifier = mapAvailabilityZones(); final String dbMasterPassword = passwordGenerator.get(); final BaseParameters baseParameters = new BaseParameters(); baseParameters.setAccountAdminArn(command.getAdminRoleArn()).setAz1(azByIdentifier.get(1)) .setAz2(azByIdentifier.get(2)).setAz3(azByIdentifier.get(3)) .setCmsDbMasterUsername(ConfigConstants.DEFAULT_CMS_DB_NAME) .setCmsDbMasterPassword(dbMasterPassword).setCmsDbName(ConfigConstants.DEFAULT_CMS_DB_NAME) .setVpcHostedZoneName(command.getVpcHostedZoneName()); baseParameters.getTagParameters().setTagEmail(command.getOwnerEmail()); baseParameters.getTagParameters().setTagName(ConfigConstants.ENV_PREFIX + environmentMetadata.getName()); baseParameters.getTagParameters().setTagCostcenter(command.getCostcenter()); final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() { };//ww w. j a v a2s.co m final Map<String, String> parameters = cloudformationObjectMapper.convertValue(baseParameters, typeReference); final String stackId = cloudFormationService.createStack( cloudFormationService.getEnvStackName(uniqueStackName), parameters, ConfigConstants.BASE_STACK_TEMPLATE_PATH, true); final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.CREATE_COMPLETE, StackStatus.ROLLBACK_COMPLETE)); if (StackStatus.CREATE_COMPLETE == endStatus) { final Map<String, String> stackOutputs = cloudFormationService.getStackOutputs(stackId); final BaseOutputs outputParameters = cloudformationObjectMapper.convertValue(stackOutputs, BaseOutputs.class); logger.info("Stack creation complete, uploading data to the configuration bucket."); // ORDER IS IMPORTANT! // 1. First update the environment metadata with the new config bucket name. environmentMetadata.setBucketName(outputParameters.getConfigBucketName()); // 2. Initialize the environment config. configStore.initEnvironmentData(); // 3. Write the first configuration values to the config bucket. configStore.storeAzs(azByIdentifier.get(1), azByIdentifier.get(2), azByIdentifier.get(3)); configStore.storeStackId(StackName.BASE, stackId); configStore.storeConfigKeyId(outputParameters.getConfigFileKeyId()); // 4. Initialize the secrets config. configStore.initSecretsData(); // 5. Write the first secret value to the config bucket once the config key id has been saved. configStore.storeCmsDatabasePassword(dbMasterPassword); logger.info("Uploading complete."); } else { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } }
From source file:com.nike.cerberus.operation.core.UpdateStackOperation.java
License:Apache License
@Override public void run(final UpdateStackCommand command) { final String stackId = configStore.getStackId(command.getStackName()); final Class<? extends LaunchConfigParameters> parametersClass = stackParameterMap .get(command.getStackName()); final Map<String, String> parameters; if (parametersClass != null) { parameters = getUpdateLaunchConfigParameters(command.getStackName(), command, parametersClass); } else if (StackName.BASE == command.getStackName()) { parameters = getUpdatedBaseStackParameters(command); } else {// w ww. ja v a 2s . co m throw new IllegalArgumentException("The specified stack does not support the update stack command!"); } parameters.putAll(command.getDynamicParameters()); try { logger.info("Starting the update for {}.", command.getStackName().getName()); if (command.isOverwriteTemplate()) { cloudFormationService.updateStack(stackId, parameters, stackTemplatePathMap.get(command.getStackName()), true); } else { cloudFormationService.updateStack(stackId, parameters, true); } final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.UPDATE_COMPLETE, StackStatus.UPDATE_COMPLETE_CLEANUP_IN_PROGRESS, StackStatus.UPDATE_ROLLBACK_COMPLETE)); if (endStatus == StackStatus.ROLLBACK_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } logger.info("Update complete."); } catch (AmazonServiceException ase) { if (ase.getStatusCode() == 400 && StringUtils.equalsIgnoreCase(ase.getErrorMessage(), "No updates are to be performed.")) { logger.warn("CloudFormation reported no changes detected."); } else { throw ase; } } }
From source file:com.nike.cerberus.operation.gateway.CreateCloudFrontSecurityGroupUpdaterLambdaOperation.java
License:Apache License
private void createLambda() { final CloudFrontIpSynchronizerParameters cloudFrontIpSynchronizerParameters = new CloudFrontIpSynchronizerParameters() .setLambdaBucket(environmentMetadata.getBucketName()) .setLambdaKey(LambdaName.CLOUD_FRONT_SG_GROUP_IP_SYNC.getBucketKey()); final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() { };// w w w . java 2s. c om final Map<String, String> parameters = cloudformationObjectMapper .convertValue(cloudFrontIpSynchronizerParameters, typeReference); final String stackId = cloudFormationService.createStack(StackName.CLOUD_FRONT_IP_SYNCHRONIZER.getName(), parameters, ConfigConstants.CF_ELB_IP_SYNC_STACK_TEMPLATE_PATH, true); final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.CREATE_COMPLETE, StackStatus.ROLLBACK_COMPLETE)); if (endStatus != StackStatus.CREATE_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } }
From source file:com.nike.cerberus.operation.gateway.CreateGatewayClusterOperation.java
License:Apache License
@Override public void run(final CreateGatewayClusterCommand command) { final String uniqueStackName = String.format("%s-%s", StackName.GATEWAY.getName(), uuidSupplier.get()); final BaseOutputs baseOutputs = configStore.getBaseStackOutputs(); final Optional<String> gatewayServerCertificateArn = configStore.getServerCertificateArn(StackName.GATEWAY); final Optional<String> gatewayServerCertificateId = configStore.getServerCertificateId(StackName.GATEWAY); final Optional<String> pubKey = configStore.getCertPart(StackName.GATEWAY, ConfigConstants.CERT_PART_PUBKEY); if (!gatewayServerCertificateArn.isPresent() || !pubKey.isPresent()) { throw new IllegalStateException("Gateway certificate has not been uploaded!"); }//from ww w . j a va 2 s.c o m final GatewayParameters gatewayParameters = new GatewayParameters().setVpcId(baseOutputs.getVpcId()) .setInstanceProfileName(baseOutputs.getGatewayInstanceProfileName()) .setGatewayServerSgId(baseOutputs.getGatewayServerSgId()) .setGatewayElbSgId(baseOutputs.getGatewayElbSgId()) .setToolsIngressSgId(baseOutputs.getToolsIngressSgId()) .setVpcSubnetIdForAz1(baseOutputs.getVpcSubnetIdForAz1()) .setVpcSubnetIdForAz2(baseOutputs.getVpcSubnetIdForAz2()) .setVpcSubnetIdForAz3(baseOutputs.getVpcSubnetIdForAz3()).setHostedZoneId(command.getHostedZoneId()) .setHostname(command.getHostname()).setWafLambdaBucket(environmentMetadata.getBucketName()) .setWafLambdaKey(LambdaName.WAF.getBucketKey()) .setCloudFrontLogProcessorLambdaIamRoleArn(baseOutputs.getCloudFrontLogProcessorLambdaIamRoleArn()); gatewayParameters.getSslConfigParameters().setCertPublicKey(pubKey.get()); gatewayParameters.getSslConfigParameters().setSslCertificateArn(gatewayServerCertificateArn.get()); gatewayParameters.getSslConfigParameters().setSslCertificateId(gatewayServerCertificateId.get()); gatewayParameters.getLaunchConfigParameters().setAmiId(command.getStackDelegate().getAmiId()); gatewayParameters.getLaunchConfigParameters().setInstanceSize(command.getStackDelegate().getInstanceSize()); gatewayParameters.getLaunchConfigParameters().setKeyPairName(command.getStackDelegate().getKeyPairName()); gatewayParameters.getLaunchConfigParameters().setUserData( ec2UserDataService.getUserData(StackName.GATEWAY, command.getStackDelegate().getOwnerGroup())); gatewayParameters.getTagParameters().setTagEmail(command.getStackDelegate().getOwnerEmail()); gatewayParameters.getTagParameters().setTagName(ConfigConstants.ENV_PREFIX + environmentMetadata.getName()); gatewayParameters.getTagParameters().setTagCostcenter(command.getStackDelegate().getCostcenter()); final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() { }; final Map<String, String> parameters = cloudformationObjectMapper.convertValue(gatewayParameters, typeReference); final String stackId = cloudFormationService.createStack( cloudFormationService.getEnvStackName(uniqueStackName), parameters, ConfigConstants.GATEWAY_STACK_TEMPLATE_PATH, true); logger.info("Uploading data to the configuration bucket."); configStore.storeStackId(StackName.GATEWAY, stackId); logger.info("Uploading complete."); final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.CREATE_COMPLETE, StackStatus.ROLLBACK_COMPLETE)); if (endStatus != StackStatus.CREATE_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } }
From source file:com.nike.cerberus.operation.vault.CreateVaultClusterOperation.java
License:Apache License
@Override public void run(final CreateVaultClusterCommand command) { final String uniqueStackName = String.format("%s-%s", StackName.VAULT.getName(), uuidSupplier.get()); final BaseOutputs baseOutputs = configStore.getBaseStackOutputs(); final Optional<String> vaultServerCertificateArn = configStore.getServerCertificateArn(StackName.VAULT); final Optional<String> pubKey = configStore.getCertPart(StackName.VAULT, ConfigConstants.CERT_PART_PUBKEY); final String internalElbCname = configStore.getInternalElbCname(StackName.VAULT); if (!vaultServerCertificateArn.isPresent() || !pubKey.isPresent()) { throw new IllegalStateException("Vault server certificate has not been uploaded!"); }//from w w w. j a v a 2 s .c o m final VaultParameters vaultParameters = new VaultParameters() .setInstanceProfileName(baseOutputs.getVaultInstanceProfileName()) .setVaultClientSgId(baseOutputs.getVaultClientSgId()) .setVaultServerSgId(baseOutputs.getVaultServerSgId()) .setVaultServerElbSgId(baseOutputs.getVaultServerElbSgId()) .setConsulClientSgId(baseOutputs.getConsulClientSgId()) .setConsulServerSgId(baseOutputs.getConsulServerSgId()) .setToolsIngressSgId(baseOutputs.getToolsIngressSgId()).setVpcId(baseOutputs.getVpcId()) .setVpcSubnetIdForAz1(baseOutputs.getVpcSubnetIdForAz1()) .setVpcSubnetIdForAz2(baseOutputs.getVpcSubnetIdForAz2()) .setVpcSubnetIdForAz3(baseOutputs.getVpcSubnetIdForAz3()) .setHostedZoneId(baseOutputs.getVpcHostedZoneId()).setCname(internalElbCname); vaultParameters.getSslConfigParameters().setCertPublicKey(pubKey.get()); vaultParameters.getSslConfigParameters().setSslCertificateArn(vaultServerCertificateArn.get()); vaultParameters.getLaunchConfigParameters().setAmiId(command.getStackDelegate().getAmiId()); vaultParameters.getLaunchConfigParameters().setInstanceSize(command.getStackDelegate().getInstanceSize()); vaultParameters.getLaunchConfigParameters().setKeyPairName(command.getStackDelegate().getKeyPairName()); vaultParameters.getLaunchConfigParameters().setUserData( ec2UserDataService.getUserData(StackName.VAULT, command.getStackDelegate().getOwnerGroup())); vaultParameters.getTagParameters().setTagEmail(command.getStackDelegate().getOwnerEmail()); vaultParameters.getTagParameters().setTagName(ConfigConstants.ENV_PREFIX + environmentMetadata.getName()); vaultParameters.getTagParameters().setTagCostcenter(command.getStackDelegate().getCostcenter()); final TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() { }; final Map<String, String> parameters = cloudformationObjectMapper.convertValue(vaultParameters, typeReference); final String stackId = cloudFormationService.createStack( cloudFormationService.getEnvStackName(uniqueStackName), parameters, ConfigConstants.VAULT_STACK_TEMPLATE_PATH, true); logger.info("Uploading data to the configuration bucket."); configStore.storeStackId(StackName.VAULT, stackId); logger.info("Uploading complete."); final StackStatus endStatus = cloudFormationService.waitForStatus(stackId, Sets.newHashSet(StackStatus.CREATE_COMPLETE, StackStatus.ROLLBACK_COMPLETE)); if (endStatus != StackStatus.CREATE_COMPLETE) { final String errorMessage = String.format("Unexpected end status: %s", endStatus.name()); logger.error(errorMessage); throw new UnexpectedCloudFormationStatusException(errorMessage); } }