Chilkat Online Tools

GetLifecyclePolicy Android Example

Amazon Data Lifecycle Manager

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 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("dlm");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://dlm.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("dlm.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

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

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/policies/{policyId}/",sbResponseBody);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    Log.i(TAG, "response status code = " + String.valueOf(respStatusCode));
    if (respStatusCode != 200) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, rest.responseHeader());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, 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 Name;
    int j;
    int count_j;
    String CmkArn;
    int Encrypted;
    int Interval;
    String IntervalUnit;
    String Target;
    String strVal;
    int CopyTags;
    String CronExpression;
    int CreateRuleInterval;
    String CreateRuleIntervalUnit;
    String Location;
    int Count;
    int DeprecateRuleInterval;
    String DeprecateRuleIntervalUnit;
    int FastRestoreRuleCount;
    int FastRestoreRuleInterval;
    String FastRestoreRuleIntervalUnit;
    int RetainRuleCount;
    int RetainRuleInterval;
    String RetainRuleIntervalUnit;
    String TargetRegion;
    int UnshareInterval;
    String UnshareIntervalUnit;
    int k;
    int count_k;
    String Key;
    String Value;

    int DateCreated = jResp.IntOf("Policy.DateCreated");
    int DateModified = jResp.IntOf("Policy.DateModified");
    String Description = jResp.stringOf("Policy.Description");
    String ExecutionRoleArn = jResp.stringOf("Policy.ExecutionRoleArn");
    String PolicyArn = jResp.stringOf("Policy.PolicyArn");
    String DescriptionRegex = jResp.stringOf("Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex");
    String EventType = jResp.stringOf("Policy.PolicyDetails.EventSource.Parameters.EventType");
    String v_Type = jResp.stringOf("Policy.PolicyDetails.EventSource.Type");
    int ExcludeBootVolume = jResp.IntOf("Policy.PolicyDetails.Parameters.ExcludeBootVolume");
    int NoReboot = jResp.IntOf("Policy.PolicyDetails.Parameters.NoReboot");
    String PolicyType = jResp.stringOf("Policy.PolicyDetails.PolicyType");
    String PolicyId = jResp.stringOf("Policy.PolicyId");
    String State = jResp.stringOf("Policy.State");
    String StatusMessage = jResp.stringOf("Policy.StatusMessage");
    String v_String = jResp.stringOf("Policy.Tags.string");
    int i = 0;
    int count_i = jResp.SizeOfArray("Policy.PolicyDetails.Actions");
    while (i < count_i) {
        jResp.put_I(i);
        Name = jResp.stringOf("Policy.PolicyDetails.Actions[i].Name");
        j = 0;
        count_j = jResp.SizeOfArray("Policy.PolicyDetails.Actions[i].CrossRegionCopy");
        while (j < count_j) {
            jResp.put_J(j);
            CmkArn = jResp.stringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn");
            Encrypted = jResp.IntOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted");
            Interval = jResp.IntOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval");
            IntervalUnit = jResp.stringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit");
            Target = jResp.stringOf("Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target");
            j = j + 1;
            }

        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]");
        i = i + 1;
        }

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

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

    i = 0;
    count_i = jResp.SizeOfArray("Policy.PolicyDetails.Schedules");
    while (i < count_i) {
        jResp.put_I(i);
        CopyTags = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CopyTags");
        CronExpression = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression");
        CreateRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CreateRule.Interval");
        CreateRuleIntervalUnit = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit");
        Location = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CreateRule.Location");
        Count = jResp.IntOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.Count");
        DeprecateRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval");
        DeprecateRuleIntervalUnit = jResp.stringOf("Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit");
        FastRestoreRuleCount = jResp.IntOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count");
        FastRestoreRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval");
        FastRestoreRuleIntervalUnit = jResp.stringOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit");
        Name = jResp.stringOf("Policy.PolicyDetails.Schedules[i].Name");
        RetainRuleCount = jResp.IntOf("Policy.PolicyDetails.Schedules[i].RetainRule.Count");
        RetainRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].RetainRule.Interval");
        RetainRuleIntervalUnit = jResp.stringOf("Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit");
        j = 0;
        count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].CreateRule.Times");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]");
            j = j + 1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules");
        while (j < count_j) {
            jResp.put_J(j);
            CmkArn = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn");
            CopyTags = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags");
            DeprecateRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval");
            DeprecateRuleIntervalUnit = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit");
            Encrypted = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted");
            RetainRuleInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval");
            RetainRuleIntervalUnit = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit");
            Target = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target");
            TargetRegion = jResp.stringOf("Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion");
            j = j + 1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]");
            j = j + 1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].ShareRules");
        while (j < count_j) {
            jResp.put_J(j);
            UnshareInterval = jResp.IntOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval");
            UnshareIntervalUnit = jResp.stringOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit");
            k = 0;
            count_k = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts");
            while (k < count_k) {
                jResp.put_K(k);
                strVal = jResp.stringOf("Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]");
                k = k + 1;
                }

            j = j + 1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].TagsToAdd");
        while (j < count_j) {
            jResp.put_J(j);
            Key = jResp.stringOf("Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key");
            Value = jResp.stringOf("Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value");
            j = j + 1;
            }

        j = 0;
        count_j = jResp.SizeOfArray("Policy.PolicyDetails.Schedules[i].VariableTags");
        while (j < count_j) {
            jResp.put_J(j);
            Key = jResp.stringOf("Policy.PolicyDetails.Schedules[i].VariableTags[j].Key");
            Value = jResp.stringOf("Policy.PolicyDetails.Schedules[i].VariableTags[j].Value");
            j = j + 1;
            }

        i = i + 1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("Policy.PolicyDetails.TargetTags");
    while (i < count_i) {
        jResp.put_I(i);
        Key = jResp.stringOf("Policy.PolicyDetails.TargetTags[i].Key");
        Value = jResp.stringOf("Policy.PolicyDetails.TargetTags[i].Value");
        i = i + 1;
        }

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

    // {
    //   "Policy": {
    //     "DateCreated": number,
    //     "DateModified": number,
    //     "Description": "string",
    //     "ExecutionRoleArn": "string",
    //     "PolicyArn": "string",
    //     "PolicyDetails": {
    //       "Actions": [
    //         {
    //           "CrossRegionCopy": [
    //             {
    //               "EncryptionConfiguration": {
    //                 "CmkArn": "string",
    //                 "Encrypted": boolean
    //               },
    //               "RetainRule": {
    //                 "Interval": number,
    //                 "IntervalUnit": "string"
    //               },
    //               "Target": "string"
    //             }
    //           ],
    //           "Name": "string"
    //         }
    //       ],
    //       "EventSource": {
    //         "Parameters": {
    //           "DescriptionRegex": "string",
    //           "EventType": "string",
    //           "SnapshotOwner": [
    //             "string"
    //           ]
    //         },
    //         "Type": "string"
    //       },
    //       "Parameters": {
    //         "ExcludeBootVolume": boolean,
    //         "NoReboot": boolean
    //       },
    //       "PolicyType": "string",
    //       "ResourceLocations": [
    //         "string"
    //       ],
    //       "ResourceTypes": [
    //         "string"
    //       ],
    //       "Schedules": [
    //         {
    //           "CopyTags": boolean,
    //           "CreateRule": {
    //             "CronExpression": "string",
    //             "Interval": number,
    //             "IntervalUnit": "string",
    //             "Location": "string",
    //             "Times": [
    //               "string"
    //             ]
    //           },
    //           "CrossRegionCopyRules": [
    //             {
    //               "CmkArn": "string",
    //               "CopyTags": boolean,
    //               "DeprecateRule": {
    //                 "Interval": number,
    //                 "IntervalUnit": "string"
    //               },
    //               "Encrypted": boolean,
    //               "RetainRule": {
    //                 "Interval": number,
    //                 "IntervalUnit": "string"
    //               },
    //               "Target": "string",
    //               "TargetRegion": "string"
    //             }
    //           ],
    //           "DeprecateRule": {
    //             "Count": number,
    //             "Interval": number,
    //             "IntervalUnit": "string"
    //           },
    //           "FastRestoreRule": {
    //             "AvailabilityZones": [
    //               "string"
    //             ],
    //             "Count": number,
    //             "Interval": number,
    //             "IntervalUnit": "string"
    //           },
    //           "Name": "string",
    //           "RetainRule": {
    //             "Count": number,
    //             "Interval": number,
    //             "IntervalUnit": "string"
    //           },
    //           "ShareRules": [
    //             {
    //               "TargetAccounts": [
    //                 "string"
    //               ],
    //               "UnshareInterval": number,
    //               "UnshareIntervalUnit": "string"
    //             }
    //           ],
    //           "TagsToAdd": [
    //             {
    //               "Key": "string",
    //               "Value": "string"
    //             }
    //           ],
    //           "VariableTags": [
    //             {
    //               "Key": "string",
    //               "Value": "string"
    //             }
    //           ]
    //         }
    //       ],
    //       "TargetTags": [
    //         {
    //           "Key": "string",
    //           "Value": "string"
    //         }
    //       ]
    //     },
    //     "PolicyId": "string",
    //     "State": "string",
    //     "StatusMessage": "string",
    //     "Tags": {
    //       "string": "string"
    //     }
    //   }
    // }

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}