Modernizing Scripts into the Cloud

Looking back at Lake Tahoe
OCI Console — compute instance, Oracle Cloud Agent
Run a command from OCI Console in Compute Instance

Create Command on OCI Compute

See the documentation here for creating a command on the compute instance. We will use this REST endpoint in an OCI Data REST task, the first step is defining the POST method and the URL.

Create a REST task in OCI Data Integration
Parameterize the URL — make it resuable
Content-Type: application/jsonAccept = application/json
Define the headers in REST task

Define the create command payload

The payload for the create command has a number of parameters including the compartment where the command is created, the name for the jobs, the instance to run the job on and the script to run. The output can be saved to Object Storage, below we are just reporting to standard output.

{  "compartmentId": "${COMPARTMENT_ID}", "executionTimeOutInSeconds": 3600,  "displayName": "${COMMAND_NAME}",  "target": {    "instanceId": "${INSTANCE_ID}"  },  "content": {    "source": {      "sourceType": "TEXT",     "text": "${SCRIPT_TEXT}"    },    "output": {      "outputType": "TEXT"    }  }}
Define the request payload in the REST task

Getting Status of Command

Extract the command id from the create command above;

COMMAND_ID CAST(json_path(SYS.RESPONSE_PAYLOAD, '$.id') AS String)
Define an expression to get the command id from the response
GET https://iaas.us-ashburn-1.oraclecloud.com/20180530/instanceAgentCommands/#{COMMAND_ID}/status?instanceId=${INSTANCE_ID}
Define the polling status check REST endpoint

Canceling the Command

Cancel/delete the command using the COMMAND_ID expression and the REST endpoint to DELETE the command;

DELETE https://iaas.${REGION}.oraclecloud.com/20180530/instanceAgentCommands/#{COMMAND_ID}
Define the cancel REST endpoint

Poll and Success Conditions

Finally we have to define the polling and success conditions.

CAST(json_path(SYS.RESPONSE_PAYLOAD, '$.lifecycleState') AS String) != 'SUCCEEDED' AND CAST(json_path(SYS.RESPONSE_PAYLOAD, '$.lifecycleState') AS String) != 'FAILED'
SYS.RESPONSE_STATUS >= 200 AND SYS.RESPONSE_STATUS <= 300 AND CAST(json_path(SYS.RESPONSE_PAYLOAD, '$.lifecycleState') AS String) == 'SUCCEEDED'

Orchestrating the Command

We can execute the REST task from within OCI Data Integration and also schedule this so that we can do this over and over. Below we have a task schedule which executes a REST task, the task schedule can configure any parameters to specific values also!

Schedule the command to run on cadence

Summary

Here we have seen how we can modernize existing scripts in the cloud and how we can automate tasks that are time consuming and need to be performed over and over again. Hopefully this gives you some good insight into running scripts, tools and commands on OCI. Let me know what you think.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
David Allan

David Allan

80 Followers

Architect at @Oracle developing cloud services for data. Connect on Twitter @i_m_dave