GetJob delphiDll Example
var
rest: HCkRest;
success: Boolean;
authAws: HCkAuthAws;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jResp: HCkJsonObject;
eventType: PWideChar;
message: PWideChar;
timeOfEvent: Integer;
channelName: PWideChar;
contentType: PWideChar;
S3DataSourceS3Uri: PWideChar;
Uri: PWideChar;
CompressionType: PWideChar;
EntryPoint: PWideChar;
S3Uri: PWideChar;
billableDuration: Integer;
LocalPath: PWideChar;
checkpointConfigS3Uri: PWideChar;
createdAt: Integer;
Device: PWideChar;
endedAt: Integer;
failureReason: PWideChar;
v_String: PWideChar;
InstanceCount: Integer;
InstanceType: PWideChar;
VolumeSizeInGb: Integer;
jobArn: PWideChar;
jobName: PWideChar;
KmsKeyId: PWideChar;
S3Path: PWideChar;
roleArn: PWideChar;
startedAt: Integer;
status: PWideChar;
MaxRuntimeInSeconds: Integer;
tagsString: PWideChar;
i: Integer;
count_i: Integer;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest := CkRest_Create();
authAws := CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(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_putRegion(authAws,'us-west-2');
CkAuthAws_putServiceName(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.
success := CkRest_Connect(rest,'braket.us-west-2.amazonaws.com',443,True,True);
if (success <> True) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
CkRest_AddHeader(rest,'X-Amz-Target','GetJob');
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/job/{jobArn}',sbResponseBody);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
respStatusCode := CkRest_getResponseStatusCode(rest);
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
if (respStatusCode <> 200) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkRest__responseHeader(rest));
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
Exit;
end;
jResp := CkJsonObject_Create();
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
Uri := CkJsonObject__stringOf(jResp,'algorithmSpecification.containerImage.uri');
CompressionType := CkJsonObject__stringOf(jResp,'algorithmSpecification.scriptModeConfig.compressionType');
EntryPoint := CkJsonObject__stringOf(jResp,'algorithmSpecification.scriptModeConfig.entryPoint');
S3Uri := CkJsonObject__stringOf(jResp,'algorithmSpecification.scriptModeConfig.s3Uri');
billableDuration := CkJsonObject_IntOf(jResp,'billableDuration');
LocalPath := CkJsonObject__stringOf(jResp,'checkpointConfig.localPath');
checkpointConfigS3Uri := CkJsonObject__stringOf(jResp,'checkpointConfig.s3Uri');
createdAt := CkJsonObject_IntOf(jResp,'createdAt');
Device := CkJsonObject__stringOf(jResp,'deviceConfig.device');
endedAt := CkJsonObject_IntOf(jResp,'endedAt');
failureReason := CkJsonObject__stringOf(jResp,'failureReason');
v_String := CkJsonObject__stringOf(jResp,'hyperParameters.string');
InstanceCount := CkJsonObject_IntOf(jResp,'instanceConfig.instanceCount');
InstanceType := CkJsonObject__stringOf(jResp,'instanceConfig.instanceType');
VolumeSizeInGb := CkJsonObject_IntOf(jResp,'instanceConfig.volumeSizeInGb');
jobArn := CkJsonObject__stringOf(jResp,'jobArn');
jobName := CkJsonObject__stringOf(jResp,'jobName');
KmsKeyId := CkJsonObject__stringOf(jResp,'outputDataConfig.kmsKeyId');
S3Path := CkJsonObject__stringOf(jResp,'outputDataConfig.s3Path');
roleArn := CkJsonObject__stringOf(jResp,'roleArn');
startedAt := CkJsonObject_IntOf(jResp,'startedAt');
status := CkJsonObject__stringOf(jResp,'status');
MaxRuntimeInSeconds := CkJsonObject_IntOf(jResp,'stoppingCondition.maxRuntimeInSeconds');
tagsString := CkJsonObject__stringOf(jResp,'tags.string');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'events');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
eventType := CkJsonObject__stringOf(jResp,'events[i].eventType');
message := CkJsonObject__stringOf(jResp,'events[i].message');
timeOfEvent := CkJsonObject_IntOf(jResp,'events[i].timeOfEvent');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'inputDataConfig');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
channelName := CkJsonObject__stringOf(jResp,'inputDataConfig[i].channelName');
contentType := CkJsonObject__stringOf(jResp,'inputDataConfig[i].contentType');
S3DataSourceS3Uri := CkJsonObject__stringOf(jResp,'inputDataConfig[i].dataSource.s3DataSource.s3Uri');
i := i + 1;
end;
// 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"
// }
// }
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);