src/main/java/com/digitalglobe/util/maven/plugin/CloudFormationDeployMavenPlugin.java
/**
     * Use this method to determine if the CloudFormation Template was previously deployed to AWS.
     *
     * @param cfClient is the CloudFormation Client to use.
     * @param stackName is the name of the stack to investigate.
     * @return a flag indicating if the template was previously deployed.
     */
Use this method to determine if the CloudFormation Template was previously deployed to AWS.
@param cfClient is the CloudFormation Client to use.
@param stackName is the name of the stack to investigate.
@return a flag indicating if the template was previously deployed.
Use this method to determine if the CloudFormation Template was previously deployed to AWS . @param cfClient is the CloudFormation Client to use . @param stackName is the name of the stack to investigate . @return a flag indicating if the template was previously deployed .
private boolean isTemplatePreviouslyDeployed(CloudFormationAsyncClient cfClient, String stackName)  {
        boolean cloudFormationExists = true;
        boolean retry;
        int retry_count = 0;
        Random random = new Random();
        do {
            try {
                DescribeStacksResponse result = cfClient.describeStacks(DescribeStacksRequest.builder().stackName(stackName).build()).get();
                if (((result.stacks() == null) || (result.stacks().size() < 1)) && (retry_count == 2)) {
                    cloudFormationExists = false;
                    retry = false;
                } else if((result.stacks() != null) && (result.stacks().size() >= 1)) {
                    retry = false;
                } else if(retry_count < 2){
                    retry = true;
                    Thread.sleep(random.nextInt(5000) + 1);
                } else retry = false;
            } catch (InterruptedException ie) {
                retry = true;
            } catch (ExecutionException acfEx) {
                if (acfEx.getCause().getMessage().contains("Rate exceeded")) {
                    retry = true;
                } else if (acfEx.getCause().getMessage().contains("does not exist")) {
                    retry = false;
                    cloudFormationExists = false;
                } else {
                    System.out.println("Error encountered (retry): " + acfEx.getMessage());
                    retry = retry_count < 2;
                    if(!retry) cloudFormationExists = false;
                }
                try { Thread.sleep(random.nextInt(5000) + 1); } catch (InterruptedException iex) {  /* Ignore */ }
            }
            retry_count++;
        } while(retry);
        return cloudFormationExists;
    }
private boolean isTemplatePreviouslyDeployed ( CloudFormationAsyncClient cfClient , String stackName ) { boolean cloudFormationExists = true ; boolean retry ; int retry_count = 0 ; Random random = new Random ( ) ; do { try { DescribeStacksResponse result = cfClient . describeStacks ( DescribeStacksRequest . builder ( ) . stackName ( stackName ) . build ( ) ) . get ( ) ; if ( ( ( result . stacks ( ) == null ) || ( result . stacks ( ) . size ( ) < 1 ) ) && ( retry_count == 2 ) ) { cloudFormationExists = false ; retry = false ; } else if ( ( result . stacks ( ) != null ) && ( result . stacks ( ) . size ( ) >= 1 ) ) { retry = false ; } else if ( retry_count < 2 ) { retry = true ; Thread . sleep ( random . nextInt ( 5000 ) + 1 ) ; } else retry = false ; } catch ( InterruptedException ie ) { retry = true ; } catch ( ExecutionException acfEx ) { if ( acfEx . getCause ( ) . getMessage ( ) . contains ( "Rate exceeded" ) ) { retry = true ; } else if ( acfEx . getCause ( ) . getMessage ( ) . contains ( "does not exist" ) ) { retry = false ; cloudFormationExists = false ; } else { System . out . println ( "Error encountered (retry): " + acfEx . getMessage ( ) ) ; retry = retry_count < 2 ; if ( ! retry ) cloudFormationExists = false ; } try { Thread . sleep ( random . nextInt ( 5000 ) + 1 ) ; } catch ( InterruptedException iex ) { /* Ignore */ } } retry_count ++ ; } while ( retry ) ; return cloudFormationExists ; }
Use this method to determine if the CloudFormation Template was previously deployed to AWS.
Use this method to determine if the CloudFormation Template was previously deployed to AWS .
// Ignore interruptions and retry.