Chilkat Online Tools

GetJob TCL Example

Amazon Braket

load ./chilkat.dll

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

set rest [new_CkRest]

set authAws [new_CkAuthAws]

CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "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.)
CkAuthAws_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "braket"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://braket.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "braket.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "GetJob"

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/job/{jobArn}" $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $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

set Uri [CkJsonObject_stringOf $jResp "algorithmSpecification.containerImage.uri"]
set CompressionType [CkJsonObject_stringOf $jResp "algorithmSpecification.scriptModeConfig.compressionType"]
set EntryPoint [CkJsonObject_stringOf $jResp "algorithmSpecification.scriptModeConfig.entryPoint"]
set S3Uri [CkJsonObject_stringOf $jResp "algorithmSpecification.scriptModeConfig.s3Uri"]
set billableDuration [CkJsonObject_IntOf $jResp "billableDuration"]
set LocalPath [CkJsonObject_stringOf $jResp "checkpointConfig.localPath"]
set checkpointConfigS3Uri [CkJsonObject_stringOf $jResp "checkpointConfig.s3Uri"]
set createdAt [CkJsonObject_IntOf $jResp "createdAt"]
set Device [CkJsonObject_stringOf $jResp "deviceConfig.device"]
set endedAt [CkJsonObject_IntOf $jResp "endedAt"]
set failureReason [CkJsonObject_stringOf $jResp "failureReason"]
set v_String [CkJsonObject_stringOf $jResp "hyperParameters.string"]
set InstanceCount [CkJsonObject_IntOf $jResp "instanceConfig.instanceCount"]
set InstanceType [CkJsonObject_stringOf $jResp "instanceConfig.instanceType"]
set VolumeSizeInGb [CkJsonObject_IntOf $jResp "instanceConfig.volumeSizeInGb"]
set jobArn [CkJsonObject_stringOf $jResp "jobArn"]
set jobName [CkJsonObject_stringOf $jResp "jobName"]
set KmsKeyId [CkJsonObject_stringOf $jResp "outputDataConfig.kmsKeyId"]
set S3Path [CkJsonObject_stringOf $jResp "outputDataConfig.s3Path"]
set roleArn [CkJsonObject_stringOf $jResp "roleArn"]
set startedAt [CkJsonObject_IntOf $jResp "startedAt"]
set status [CkJsonObject_stringOf $jResp "status"]
set MaxRuntimeInSeconds [CkJsonObject_IntOf $jResp "stoppingCondition.maxRuntimeInSeconds"]
set tagsString [CkJsonObject_stringOf $jResp "tags.string"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "events"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set eventType [CkJsonObject_stringOf $jResp "events[i].eventType"]
    set message [CkJsonObject_stringOf $jResp "events[i].message"]
    set timeOfEvent [CkJsonObject_IntOf $jResp "events[i].timeOfEvent"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "inputDataConfig"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set channelName [CkJsonObject_stringOf $jResp "inputDataConfig[i].channelName"]
    set contentType [CkJsonObject_stringOf $jResp "inputDataConfig[i].contentType"]
    set S3DataSourceS3Uri [CkJsonObject_stringOf $jResp "inputDataConfig[i].dataSource.s3DataSource.s3Uri"]
    set i [expr $i + 1]
}

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

# {
#   "algorithmSpecification": {
#     "containerImage": {
#       "uri": "string"
#     },
#     "scriptModeConfig": {
#       "compressionType": "string",
#       "entryPoint": "string",
#       "s3Uri": "string"
#     }
#   },
#   "billableDuration": number,
#   "checkpointConfig": {
#     "localPath": "string",
#     "s3Uri": "string"
#   },
#   "createdAt": number,
#   "deviceConfig": {
#     "device": "string"
#   },
#   "endedAt": number,
#   "events": [
#     {
#       "eventType": "string",
#       "message": "string",
#       "timeOfEvent": number
#     }
#   ],
#   "failureReason": "string",
#   "hyperParameters": {
#     "string": "string"
#   },
#   "inputDataConfig": [
#     {
#       "channelName": "string",
#       "contentType": "string",
#       "dataSource": {
#         "s3DataSource": {
#           "s3Uri": "string"
#         }
#       }
#     }
#   ],
#   "instanceConfig": {
#     "instanceCount": number,
#     "instanceType": "string",
#     "volumeSizeInGb": number
#   },
#   "jobArn": "string",
#   "jobName": "string",
#   "outputDataConfig": {
#     "kmsKeyId": "string",
#     "s3Path": "string"
#   },
#   "roleArn": "string",
#   "startedAt": number,
#   "status": "string",
#   "stoppingCondition": {
#     "maxRuntimeInSeconds": number
#   },
#   "tags": {
#     "string": "string"
#   }
# }

delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp