Chilkat Online Tools

StopExperiment SQL Server Example

AWS Fault Injection Simulator

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(max)
    -- This example requires the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @authAws int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.AuthAws', @authAws OUT

    EXEC sp_OASetProperty @authAws, 'AccessKey', 'AWS_ACCESS_KEY'
    EXEC sp_OASetProperty @authAws, '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.)
    EXEC sp_OASetProperty @authAws, 'Region', 'us-west-2'
    EXEC sp_OASetProperty @authAws, 'ServiceName', 'fis'
    -- SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @authAws

    -- URL: https://fis.us-west-2.amazonaws.com/
    -- Use the same region as specified above.
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'fis.us-west-2.amazonaws.com', 443, 1, 1
    IF @success <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        RETURN
      END

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/x-amz-json-1.1'
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'X-Amz-Target', 'StopExperiment'

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'DELETE', '/experiments/{id}', @sbResponseBody
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END
    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT

    PRINT 'response status code = ' + @respStatusCode
    IF @respStatusCode <> 200
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Response Body:'
        EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @authAws
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @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

    DECLARE @strVal nvarchar(max)

    DECLARE @source nvarchar(max)

    DECLARE @value nvarchar(max)

    DECLARE @path nvarchar(max)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @ActionId nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @ActionId OUT, 'experiment.actions.string.actionId'
    DECLARE @Description nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'experiment.actions.string.description'
    DECLARE @EndTime int
    EXEC sp_OAMethod @jResp, 'IntOf', @EndTime OUT, 'experiment.actions.string.endTime'
    DECLARE @v_String nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_String OUT, 'experiment.actions.string.parameters.string'
    DECLARE @StartTime int
    EXEC sp_OAMethod @jResp, 'IntOf', @StartTime OUT, 'experiment.actions.string.startTime'
    DECLARE @Reason nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Reason OUT, 'experiment.actions.string.state.reason'
    DECLARE @Status nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Status OUT, 'experiment.actions.string.state.status'
    DECLARE @TargetsString nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @TargetsString OUT, 'experiment.actions.string.targets.string'
    DECLARE @CreationTime int
    EXEC sp_OAMethod @jResp, 'IntOf', @CreationTime OUT, 'experiment.creationTime'
    DECLARE @experimentEndTime int
    EXEC sp_OAMethod @jResp, 'IntOf', @experimentEndTime OUT, 'experiment.endTime'
    DECLARE @ExperimentTemplateId nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @ExperimentTemplateId OUT, 'experiment.experimentTemplateId'
    DECLARE @Id nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'experiment.id'
    DECLARE @LogGroupArn nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @LogGroupArn OUT, 'experiment.logConfiguration.cloudWatchLogsConfiguration.logGroupArn'
    DECLARE @LogSchemaVersion int
    EXEC sp_OAMethod @jResp, 'IntOf', @LogSchemaVersion OUT, 'experiment.logConfiguration.logSchemaVersion'
    DECLARE @BucketName nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @BucketName OUT, 'experiment.logConfiguration.s3Configuration.bucketName'
    DECLARE @Prefix nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @Prefix OUT, 'experiment.logConfiguration.s3Configuration.prefix'
    DECLARE @RoleArn nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @RoleArn OUT, 'experiment.roleArn'
    DECLARE @experimentStartTime int
    EXEC sp_OAMethod @jResp, 'IntOf', @experimentStartTime OUT, 'experiment.startTime'
    DECLARE @StateReason nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @StateReason OUT, 'experiment.state.reason'
    DECLARE @StateStatus nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @StateStatus OUT, 'experiment.state.status'
    DECLARE @TagsString nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @TagsString OUT, 'experiment.tags.string'
    DECLARE @ParametersString nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @ParametersString OUT, 'experiment.targets.string.parameters.string'
    DECLARE @ResourceTagsString nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @ResourceTagsString OUT, 'experiment.targets.string.resourceTags.string'
    DECLARE @ResourceType nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @ResourceType OUT, 'experiment.targets.string.resourceType'
    DECLARE @SelectionMode nvarchar(max)
    EXEC sp_OAMethod @jResp, 'StringOf', @SelectionMode OUT, 'experiment.targets.string.selectionMode'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'experiment.actions.string.startAfter'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'experiment.actions.string.startAfter[i]'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'experiment.stopConditions'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @source OUT, 'experiment.stopConditions[i].source'
        EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'experiment.stopConditions[i].value'
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'experiment.targets.string.filters'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @path OUT, 'experiment.targets.string.filters[i].path'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'experiment.targets.string.filters[i].values'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'experiment.targets.string.filters[i].values[j]'
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END
    SELECT @i = 0
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'experiment.targets.string.resourceArns'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'experiment.targets.string.resourceArns[i]'
        SELECT @i = @i + 1
      END

    -- 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"
    --       }
    --     }
    --   }
    -- }

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @authAws
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO