Chilkat Online Tools

GetDeployment Java Example

AWS CodeDeploy

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRest rest = new CkRest();
    boolean success;

    CkAuthAws authAws = new CkAuthAws();
    authAws.put_AccessKey("AWS_ACCESS_KEY");
    authAws.put_SecretKey("AWS_SECRET_KEY");

    // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
    authAws.put_Region("us-west-2");
    authAws.put_ServiceName("codedeploy");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://codedeploy.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("codedeploy.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        System.out.println("ConnectFailReason: " + rest.get_ConnectFailReason());
        System.out.println(rest.lastErrorText());
        return;
        }

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.

    // Use this online tool to generate code from sample JSON:
    // Generate Code to Create JSON

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("deploymentId","string");

    // The JSON request body created by the above code:

    // {
    //   "deploymentId": "string"
    // }

    rest.AddHeader("Content-Type","application/x-amz-json-1.1");
    rest.AddHeader("X-Amz-Target","CodeDeploy_20141006.GetDeployment");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody);
    if (success != true) {
        System.out.println(rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    System.out.println("response status code = " + respStatusCode);
    if (respStatusCode != 200) {
        System.out.println("Response Header:");
        System.out.println(rest.responseHeader());
        System.out.println("Response Body:");
        System.out.println(sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    String strVal;
    String name;
    int j;
    int count_j;
    String v_Type;
    String Value;

    String AdditionalDeploymentStatusInfo = jResp.stringOf("deploymentInfo.additionalDeploymentStatusInfo");
    String ApplicationName = jResp.stringOf("deploymentInfo.applicationName");
    int Enabled = jResp.IntOf("deploymentInfo.autoRollbackConfiguration.enabled");
    String ActionOnTimeout = jResp.stringOf("deploymentInfo.blueGreenDeploymentConfiguration.deploymentReadyOption.actionOnTimeout");
    int WaitTimeInMinutes = jResp.IntOf("deploymentInfo.blueGreenDeploymentConfiguration.deploymentReadyOption.waitTimeInMinutes");
    String Action = jResp.stringOf("deploymentInfo.blueGreenDeploymentConfiguration.greenFleetProvisioningOption.action");
    String TerminateBlueInstancesOnDeploymentSuccessAction = jResp.stringOf("deploymentInfo.blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.action");
    int TerminationWaitTimeInMinutes = jResp.IntOf("deploymentInfo.blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.terminationWaitTimeInMinutes");
    int CompleteTime = jResp.IntOf("deploymentInfo.completeTime");
    String ComputePlatform = jResp.stringOf("deploymentInfo.computePlatform");
    int CreateTime = jResp.IntOf("deploymentInfo.createTime");
    String Creator = jResp.stringOf("deploymentInfo.creator");
    String DeploymentConfigName = jResp.stringOf("deploymentInfo.deploymentConfigName");
    String DeploymentGroupName = jResp.stringOf("deploymentInfo.deploymentGroupName");
    String DeploymentId = jResp.stringOf("deploymentInfo.deploymentId");
    int Failed = jResp.IntOf("deploymentInfo.deploymentOverview.Failed");
    int InProgress = jResp.IntOf("deploymentInfo.deploymentOverview.InProgress");
    int Pending = jResp.IntOf("deploymentInfo.deploymentOverview.Pending");
    int Ready = jResp.IntOf("deploymentInfo.deploymentOverview.Ready");
    int Skipped = jResp.IntOf("deploymentInfo.deploymentOverview.Skipped");
    int Succeeded = jResp.IntOf("deploymentInfo.deploymentOverview.Succeeded");
    String DeploymentOption = jResp.stringOf("deploymentInfo.deploymentStyle.deploymentOption");
    String DeploymentType = jResp.stringOf("deploymentInfo.deploymentStyle.deploymentType");
    String Description = jResp.stringOf("deploymentInfo.description");
    String Code = jResp.stringOf("deploymentInfo.errorInformation.code");
    String Message = jResp.stringOf("deploymentInfo.errorInformation.message");
    String ExternalId = jResp.stringOf("deploymentInfo.externalId");
    String FileExistsBehavior = jResp.stringOf("deploymentInfo.fileExistsBehavior");
    int IgnoreApplicationStopFailures = jResp.IntOf("deploymentInfo.ignoreApplicationStopFailures");
    int InstanceTerminationWaitTimeStarted = jResp.IntOf("deploymentInfo.instanceTerminationWaitTimeStarted");
    String Content = jResp.stringOf("deploymentInfo.previousRevision.appSpecContent.content");
    String Sha256 = jResp.stringOf("deploymentInfo.previousRevision.appSpecContent.sha256");
    String CommitId = jResp.stringOf("deploymentInfo.previousRevision.gitHubLocation.commitId");
    String Repository = jResp.stringOf("deploymentInfo.previousRevision.gitHubLocation.repository");
    String RevisionType = jResp.stringOf("deploymentInfo.previousRevision.revisionType");
    String Bucket = jResp.stringOf("deploymentInfo.previousRevision.s3Location.bucket");
    String BundleType = jResp.stringOf("deploymentInfo.previousRevision.s3Location.bundleType");
    String ETag = jResp.stringOf("deploymentInfo.previousRevision.s3Location.eTag");
    String Key = jResp.stringOf("deploymentInfo.previousRevision.s3Location.key");
    String Version = jResp.stringOf("deploymentInfo.previousRevision.s3Location.version");
    String StringContent = jResp.stringOf("deploymentInfo.previousRevision.string.content");
    String StringSha256 = jResp.stringOf("deploymentInfo.previousRevision.string.sha256");
    String AutoUpdateOutdatedInstancesRootDeploymentId = jResp.stringOf("deploymentInfo.relatedDeployments.autoUpdateOutdatedInstancesRootDeploymentId");
    String AppSpecContentContent = jResp.stringOf("deploymentInfo.revision.appSpecContent.content");
    String AppSpecContentSha256 = jResp.stringOf("deploymentInfo.revision.appSpecContent.sha256");
    String GitHubLocationCommitId = jResp.stringOf("deploymentInfo.revision.gitHubLocation.commitId");
    String GitHubLocationRepository = jResp.stringOf("deploymentInfo.revision.gitHubLocation.repository");
    String RevisionRevisionType = jResp.stringOf("deploymentInfo.revision.revisionType");
    String S3LocationBucket = jResp.stringOf("deploymentInfo.revision.s3Location.bucket");
    String S3LocationBundleType = jResp.stringOf("deploymentInfo.revision.s3Location.bundleType");
    String S3LocationETag = jResp.stringOf("deploymentInfo.revision.s3Location.eTag");
    String S3LocationKey = jResp.stringOf("deploymentInfo.revision.s3Location.key");
    String S3LocationVersion = jResp.stringOf("deploymentInfo.revision.s3Location.version");
    StringContent = jResp.stringOf("deploymentInfo.revision.string.content");
    StringSha256 = jResp.stringOf("deploymentInfo.revision.string.sha256");
    String RollbackDeploymentId = jResp.stringOf("deploymentInfo.rollbackInfo.rollbackDeploymentId");
    String RollbackMessage = jResp.stringOf("deploymentInfo.rollbackInfo.rollbackMessage");
    String RollbackTriggeringDeploymentId = jResp.stringOf("deploymentInfo.rollbackInfo.rollbackTriggeringDeploymentId");
    int StartTime = jResp.IntOf("deploymentInfo.startTime");
    String Status = jResp.stringOf("deploymentInfo.status");
    int UpdateOutdatedInstancesOnly = jResp.IntOf("deploymentInfo.updateOutdatedInstancesOnly");
    int i = 0;
    int count_i = jResp.SizeOfArray("deploymentInfo.autoRollbackConfiguration.events");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("deploymentInfo.autoRollbackConfiguration.events[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.deploymentStatusMessages");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("deploymentInfo.deploymentStatusMessages[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.loadBalancerInfo.elbInfoList");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf("deploymentInfo.loadBalancerInfo.elbInfoList[i].name");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.loadBalancerInfo.targetGroupInfoList");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf("deploymentInfo.loadBalancerInfo.targetGroupInfoList[i].name");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.loadBalancerInfo.targetGroupPairInfoList");
    while (i < count_i) {
        jResp.put_I(i);
        j = 0;
        count_j = jResp.SizeOfArray("deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].prodTrafficRoute.listenerArns");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].prodTrafficRoute.listenerArns[j]");
            j = j+1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].targetGroups");
        while (j < count_j) {
            jResp.put_J(j);
            name = jResp.stringOf("deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].targetGroups[j].name");
            j = j+1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].testTrafficRoute.listenerArns");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].testTrafficRoute.listenerArns[j]");
            j = j+1;
            }

        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.relatedDeployments.autoUpdateOutdatedInstancesDeploymentIds");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("deploymentInfo.relatedDeployments.autoUpdateOutdatedInstancesDeploymentIds[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.targetInstances.autoScalingGroups");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("deploymentInfo.targetInstances.autoScalingGroups[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList");
    while (i < count_i) {
        jResp.put_I(i);
        j = 0;
        count_j = jResp.SizeOfArray("deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i]");
        while (j < count_j) {
            jResp.put_J(j);
            Key = jResp.stringOf("deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i][j].Key");
            v_Type = jResp.stringOf("deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i][j].Type");
            Value = jResp.stringOf("deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i][j].Value");
            j = j+1;
            }

        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("deploymentInfo.targetInstances.tagFilters");
    while (i < count_i) {
        jResp.put_I(i);
        Key = jResp.stringOf("deploymentInfo.targetInstances.tagFilters[i].Key");
        v_Type = jResp.stringOf("deploymentInfo.targetInstances.tagFilters[i].Type");
        Value = jResp.stringOf("deploymentInfo.targetInstances.tagFilters[i].Value");
        i = i+1;
        }

    // A sample JSON response body parsed by the above code:

    // {
    //   "deploymentInfo": {
    //     "additionalDeploymentStatusInfo": "string",
    //     "applicationName": "string",
    //     "autoRollbackConfiguration": {
    //       "enabled": boolean,
    //       "events": [
    //         "string"
    //       ]
    //     },
    //     "blueGreenDeploymentConfiguration": {
    //       "deploymentReadyOption": {
    //         "actionOnTimeout": "string",
    //         "waitTimeInMinutes": number
    //       },
    //       "greenFleetProvisioningOption": {
    //         "action": "string"
    //       },
    //       "terminateBlueInstancesOnDeploymentSuccess": {
    //         "action": "string",
    //         "terminationWaitTimeInMinutes": number
    //       }
    //     },
    //     "completeTime": number,
    //     "computePlatform": "string",
    //     "createTime": number,
    //     "creator": "string",
    //     "deploymentConfigName": "string",
    //     "deploymentGroupName": "string",
    //     "deploymentId": "string",
    //     "deploymentOverview": {
    //       "Failed": number,
    //       "InProgress": number,
    //       "Pending": number,
    //       "Ready": number,
    //       "Skipped": number,
    //       "Succeeded": number
    //     },
    //     "deploymentStatusMessages": [
    //       "string"
    //     ],
    //     "deploymentStyle": {
    //       "deploymentOption": "string",
    //       "deploymentType": "string"
    //     },
    //     "description": "string",
    //     "errorInformation": {
    //       "code": "string",
    //       "message": "string"
    //     },
    //     "externalId": "string",
    //     "fileExistsBehavior": "string",
    //     "ignoreApplicationStopFailures": boolean,
    //     "instanceTerminationWaitTimeStarted": boolean,
    //     "loadBalancerInfo": {
    //       "elbInfoList": [
    //         {
    //           "name": "string"
    //         }
    //       ],
    //       "targetGroupInfoList": [
    //         {
    //           "name": "string"
    //         }
    //       ],
    //       "targetGroupPairInfoList": [
    //         {
    //           "prodTrafficRoute": {
    //             "listenerArns": [
    //               "string"
    //             ]
    //           },
    //           "targetGroups": [
    //             {
    //               "name": "string"
    //             }
    //           ],
    //           "testTrafficRoute": {
    //             "listenerArns": [
    //               "string"
    //             ]
    //           }
    //         }
    //       ]
    //     },
    //     "previousRevision": {
    //       "appSpecContent": {
    //         "content": "string",
    //         "sha256": "string"
    //       },
    //       "gitHubLocation": {
    //         "commitId": "string",
    //         "repository": "string"
    //       },
    //       "revisionType": "string",
    //       "s3Location": {
    //         "bucket": "string",
    //         "bundleType": "string",
    //         "eTag": "string",
    //         "key": "string",
    //         "version": "string"
    //       },
    //       "string": {
    //         "content": "string",
    //         "sha256": "string"
    //       }
    //     },
    //     "relatedDeployments": {
    //       "autoUpdateOutdatedInstancesDeploymentIds": [
    //         "string"
    //       ],
    //       "autoUpdateOutdatedInstancesRootDeploymentId": "string"
    //     },
    //     "revision": {
    //       "appSpecContent": {
    //         "content": "string",
    //         "sha256": "string"
    //       },
    //       "gitHubLocation": {
    //         "commitId": "string",
    //         "repository": "string"
    //       },
    //       "revisionType": "string",
    //       "s3Location": {
    //         "bucket": "string",
    //         "bundleType": "string",
    //         "eTag": "string",
    //         "key": "string",
    //         "version": "string"
    //       },
    //       "string": {
    //         "content": "string",
    //         "sha256": "string"
    //       }
    //     },
    //     "rollbackInfo": {
    //       "rollbackDeploymentId": "string",
    //       "rollbackMessage": "string",
    //       "rollbackTriggeringDeploymentId": "string"
    //     },
    //     "startTime": number,
    //     "status": "string",
    //     "targetInstances": {
    //       "autoScalingGroups": [
    //         "string"
    //       ],
    //       "ec2TagSet": {
    //         "ec2TagSetList": [
    //           [
    //             {
    //               "Key": "string",
    //               "Type": "string",
    //               "Value": "string"
    //             }
    //           ]
    //         ]
    //       },
    //       "tagFilters": [
    //         {
    //           "Key": "string",
    //           "Type": "string",
    //           "Value": "string"
    //         }
    //       ]
    //     },
    //     "updateOutdatedInstancesOnly": boolean
    //   }
    // }
  }
}