com.amazonaws.services.codedeploy.model.GetDeploymentRequest Java Examples

The following examples show how to use com.amazonaws.services.codedeploy.model.GetDeploymentRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WaitDeployStep.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected Void run() throws Exception {
	TaskListener listener = this.getContext().get(TaskListener.class);
	AmazonCodeDeploy client = AWSClientFactory.create(AmazonCodeDeployClientBuilder.standard(), this.getContext());

	listener.getLogger().format("Checking Deployment(%s) status", this.deploymentId);

	while (true) {
		GetDeploymentRequest getDeploymentRequest = new GetDeploymentRequest().withDeploymentId(this.deploymentId);
		GetDeploymentResult deployment = client.getDeployment(getDeploymentRequest);
		String deploymentStatus = deployment.getDeploymentInfo().getStatus();

		listener.getLogger().format("DeploymentStatus(%s)", deploymentStatus);

		if (SUCCEEDED_STATUS.equals(deploymentStatus)) {
			listener.getLogger().println("Deployment completed successfully");
			return null;
		} else if (FAILED_STATUS.equals(deploymentStatus)) {
			listener.getLogger().println("Deployment completed in error");
			String errorMessage = deployment.getDeploymentInfo().getErrorInformation().getMessage();
			throw new Exception("Deployment Failed: " + errorMessage);
		} else if (STOPPED_STATUS.equals(deploymentStatus)) {
			listener.getLogger().println("Deployment was stopped");
			throw new Exception("Deployment was stopped");
		} else {
			listener.getLogger().println("Deployment still in progress... sleeping");
			try {
				Thread.sleep(POLLING_INTERVAL);
			} catch (InterruptedException e) {
				//
			}
		}

	}

}
 
Example #2
Source File: CodeDeployUtils.java    From herd-mdl with Apache License 2.0 4 votes vote down vote up
/**
 * Waits for a given deployment to succeed (or fail).
 *
 * @param deploymentId: String. The specified deployment's id.
 */
public static void waitForMostRecentDeployment(String deploymentId) {

  LOGGER.debug("Waiting on deployment with id: \'{}\'", deploymentId);

  AmazonCodeDeploy codeDeployClient = AmazonCodeDeployClientBuilder.standard()
      .withRegion(Regions.US_EAST_1).build();

  GetDeploymentRequest getDeploymentRequest = new GetDeploymentRequest();
  getDeploymentRequest.setDeploymentId(deploymentId);

  Waiter<GetDeploymentRequest> waiter = codeDeployClient.waiters().deploymentSuccessful();
  try {

    waiter.run(new WaiterParameters<>(getDeploymentRequest));
    LOGGER.info("Deployment was successful.");

  } catch (WaiterUnrecoverableException | WaiterTimedOutException e) {
    LOGGER.error("Deployment with id: {} was unsuccessful.", deploymentId);
  }

}
 
Example #3
Source File: AWSCodeDeployPublisher.java    From aws-codedeploy-plugin with Apache License 2.0 4 votes vote down vote up
private boolean waitForDeployment(AWSClients aws, String deploymentId) throws InterruptedException {

        if (!this.waitForCompletion) {
            return true;
        }

        logger.println("Monitoring deployment with ID " + deploymentId + "...");
        GetDeploymentRequest deployInfoRequest = new GetDeploymentRequest();
        deployInfoRequest.setDeploymentId(deploymentId);

        DeploymentInfo deployStatus = aws.codedeploy.getDeployment(deployInfoRequest).getDeploymentInfo();

        long startTimeMillis;
        if (deployStatus == null || deployStatus.getStartTime() == null) {
            startTimeMillis = new Date().getTime();
        } else {
            startTimeMillis = deployStatus.getStartTime().getTime();
        }

        boolean success = true;
        long pollingTimeoutMillis = this.pollingTimeoutSec * 1000L;
        long pollingFreqMillis = this.pollingFreqSec * 1000L;

        while (deployStatus == null || deployStatus.getCompleteTime() == null) {

            if (deployStatus == null) {
                logger.println("Deployment status: unknown.");
            } else {
                DeploymentOverview overview = deployStatus.getDeploymentOverview();
                logger.println("Deployment status: " + deployStatus.getStatus() + "; instances: " + overview);
            }

            deployStatus = aws.codedeploy.getDeployment(deployInfoRequest).getDeploymentInfo();
            Date now = new Date();

            if (now.getTime() - startTimeMillis >= pollingTimeoutMillis) {
                this.logger.println("Exceeded maximum polling time of " + pollingTimeoutMillis + " milliseconds.");
                success = false;
                break;
            }

            Thread.sleep(pollingFreqMillis);
        }

        logger.println("Deployment status: " + deployStatus.getStatus() + "; instances: " + deployStatus.getDeploymentOverview());

        if (!deployStatus.getStatus().equals(DeploymentStatus.Succeeded.toString())) {
            this.logger.println("Deployment did not succeed. Final status: " + deployStatus.getStatus());
            success = false;
        }

        return success;
    }