Chilkat Online Tools

StartExperiment DataFlex Example

AWS Fault Injection Simulator

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vAuthAws
    Handle hoAuthAws
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Integer iRespStatusCode
    Handle hoJResp
    String sStrVal
    String sSource
    String sValue
    String sPath
    Integer j
    Integer iCount_j
    String sActionId
    String sDescription
    Integer iEndTime
    String sV_String
    Integer iStartTime
    String sReason
    String sStatus
    String sTargetsString
    Integer iCreationTime
    Integer iExperimentEndTime
    String sExperimentTemplateId
    String sId
    String sLogGroupArn
    Integer iLogSchemaVersion
    String sBucketName
    String sPrefix
    String sRoleArn
    Integer iExperimentStartTime
    String sStateReason
    String sStateStatus
    String sTagsString
    String sParametersString
    String sResourceTagsString
    String sResourceType
    String sSelectionMode
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
    If (Not(IsComObjectCreated(hoAuthAws))) Begin
        Send CreateComObject of hoAuthAws
    End
    Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
    Set ComSecretKey Of hoAuthAws To "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.)
    Set ComRegion Of hoAuthAws To "us-west-2"
    Set ComServiceName Of hoAuthAws To "fis"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    Get pvComObject of hoAuthAws to vAuthAws
    Get ComSetAuthAws Of hoRest vAuthAws To iSuccess

    // URL: https://fis.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    Get ComConnect Of hoRest "fis.us-west-2.amazonaws.com" 443 True True To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // 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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "clientToken" "string" To iSuccess
    Get ComUpdateString Of hoJson "experimentTemplateId" "string" To iSuccess
    Get ComUpdateString Of hoJson "tags.string" "string" To iSuccess

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

    // {
    //   "clientToken": "string",
    //   "experimentTemplateId": "string",
    //   "tags": {
    //     "string": "string"
    //   }
    // }

    Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.1" To iSuccess
    Get ComAddHeader Of hoRest "X-Amz-Target" "StartExperiment" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/experiments" vSbRequestBody vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iRespStatusCode
    Showln "response status code = " iRespStatusCode
    If (iRespStatusCode <> 200) Begin
        Showln "Response Header:"
        Get ComResponseHeader Of hoRest To sTemp1
        Showln sTemp1
        Showln "Response Body:"
        Get ComGetAsString Of hoSbResponseBody To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess

    // 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

    Get ComStringOf Of hoJResp "experiment.actions.string.actionId" To sActionId
    Get ComStringOf Of hoJResp "experiment.actions.string.description" To sDescription
    Get ComIntOf Of hoJResp "experiment.actions.string.endTime" To iEndTime
    Get ComStringOf Of hoJResp "experiment.actions.string.parameters.string" To sV_String
    Get ComIntOf Of hoJResp "experiment.actions.string.startTime" To iStartTime
    Get ComStringOf Of hoJResp "experiment.actions.string.state.reason" To sReason
    Get ComStringOf Of hoJResp "experiment.actions.string.state.status" To sStatus
    Get ComStringOf Of hoJResp "experiment.actions.string.targets.string" To sTargetsString
    Get ComIntOf Of hoJResp "experiment.creationTime" To iCreationTime
    Get ComIntOf Of hoJResp "experiment.endTime" To iExperimentEndTime
    Get ComStringOf Of hoJResp "experiment.experimentTemplateId" To sExperimentTemplateId
    Get ComStringOf Of hoJResp "experiment.id" To sId
    Get ComStringOf Of hoJResp "experiment.logConfiguration.cloudWatchLogsConfiguration.logGroupArn" To sLogGroupArn
    Get ComIntOf Of hoJResp "experiment.logConfiguration.logSchemaVersion" To iLogSchemaVersion
    Get ComStringOf Of hoJResp "experiment.logConfiguration.s3Configuration.bucketName" To sBucketName
    Get ComStringOf Of hoJResp "experiment.logConfiguration.s3Configuration.prefix" To sPrefix
    Get ComStringOf Of hoJResp "experiment.roleArn" To sRoleArn
    Get ComIntOf Of hoJResp "experiment.startTime" To iExperimentStartTime
    Get ComStringOf Of hoJResp "experiment.state.reason" To sStateReason
    Get ComStringOf Of hoJResp "experiment.state.status" To sStateStatus
    Get ComStringOf Of hoJResp "experiment.tags.string" To sTagsString
    Get ComStringOf Of hoJResp "experiment.targets.string.parameters.string" To sParametersString
    Get ComStringOf Of hoJResp "experiment.targets.string.resourceTags.string" To sResourceTagsString
    Get ComStringOf Of hoJResp "experiment.targets.string.resourceType" To sResourceType
    Get ComStringOf Of hoJResp "experiment.targets.string.selectionMode" To sSelectionMode
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "experiment.actions.string.startAfter" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "experiment.actions.string.startAfter[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "experiment.stopConditions" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "experiment.stopConditions[i].source" To sSource
        Get ComStringOf Of hoJResp "experiment.stopConditions[i].value" To sValue
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "experiment.targets.string.filters" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "experiment.targets.string.filters[i].path" To sPath
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "experiment.targets.string.filters[i].values" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "experiment.targets.string.filters[i].values[j]" To sStrVal
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "experiment.targets.string.resourceArns" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "experiment.targets.string.resourceArns[i]" To sStrVal
        Move (i + 1) To i
    Loop

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

    // {
    //   "experiment": {
    //     "actions": {
    //       "string": {
    //         "actionId": "string",
    //         "description": "string",
    //         "endTime": number,
    //         "parameters": {
    //           "string": "string"
    //         },
    //         "startAfter": [
    //           "string"
    //         ],
    //         "startTime": number,
    //         "state": {
    //           "reason": "string",
    //           "status": "string"
    //         },
    //         "targets": {
    //           "string": "string"
    //         }
    //       }
    //     },
    //     "creationTime": number,
    //     "endTime": number,
    //     "experimentTemplateId": "string",
    //     "id": "string",
    //     "logConfiguration": {
    //       "cloudWatchLogsConfiguration": {
    //         "logGroupArn": "string"
    //       },
    //       "logSchemaVersion": number,
    //       "s3Configuration": {
    //         "bucketName": "string",
    //         "prefix": "string"
    //       }
    //     },
    //     "roleArn": "string",
    //     "startTime": number,
    //     "state": {
    //       "reason": "string",
    //       "status": "string"
    //     },
    //     "stopConditions": [
    //       {
    //         "source": "string",
    //         "value": "string"
    //       }
    //     ],
    //     "tags": {
    //       "string": "string"
    //     },
    //     "targets": {
    //       "string": {
    //         "filters": [
    //           {
    //             "path": "string",
    //             "values": [
    //               "string"
    //             ]
    //           }
    //         ],
    //         "parameters": {
    //           "string": "string"
    //         },
    //         "resourceArns": [
    //           "string"
    //         ],
    //         "resourceTags": {
    //           "string": "string"
    //         },
    //         "resourceType": "string",
    //         "selectionMode": "string"
    //       }
    //     }
    //   }
    // }


End_Procedure