Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

Introduction

  • Any operations that can be performed on orders, workflows, jobs and related objects such as cancelling, suspending and resuming orders are performed by the JS7 REST Web Service API.
  • The JS7 - Unix Shell Command Line Interfacen is offered for frequently used operations based on the REST Web Service API.
  • In addition, a PowerShell module is available for simplified access to the REST Web Service API, see JS7 - PowerShell Module.

Design

  • The REST Web Service implements a stateless API.
    • Except for the facts that a session is started by logging into the REST Web Service API and is terminated either by logging out or by expiration any operations performed with the REST Web Service API cannot rely on the previous state of an object.
    • For example, retrieving an order at a given time does not prevent this order from transitioning to a subsequent state before the next call to the API is executed.
  • The REST Web Service API is asynchronous for most parts.
    • Any operations that affect a Controller or Agent are handled asynchronously. In fact such operations are managed by the JOC Cockpit Proxy Service that forwards them to a Controller, see JS7 - Implementation Architecture.
      • The result of an operation is not returned with the response to the API call but will become available later on. In a situation when JOC Cockpit is not connected to a Controller or if a Controller is not connected to an Agent, e.g. due to network issues, API calls will still work. Such calls are handled by the Proxy Service that will forward them when the Controller becomes available.
      • For example, consider an API call to cancel an existing order. The response to this call will return acceptance/denial of the request. The operation is forwarded to a Controller and to an Agent respectively, however, the result will become available only after acknowledgement by the Agent and the respective response from the Controller.
    • API calls for asynchronous operations pending with the JOC Cockpit Proxy Service will be lost if the JOC Cockpit is restarted. There is no need to restart JOC Cockpit after a connection loss to a Controller as it will reconnect automatically.
    • A few API calls are handled synchronously, mainly when it comes to operations on the inventory. For example, API calls to store objects with the inventory will immediately return results. However, API calls to remove objects such as a workflow from the inventory are handled asynchronously as this operation requires interaction with a Controller to remove the workflow from its journal and from the journals of respective Agents. REST Clients therefore should not rely on any operation to return synchronous results.
  • The REST Web Service API is designed for cluster operation.
    • If a Controller cluster is operated then the JOC Cockpit Proxy Service will automatically connect to the active Controller instance. In case of fail-over or switch-over the Proxy Service will connect to the cluster member instance that is the resulting active instance.
    • Any changes to objects caused by API calls are synchronized between the active Controller and the passive Controller. In case of later reconnection the Controller instances will reconcile to have the information about changed object states synchronized.
    • This behavior does not affect a REST Client that makes use of the API, therefore REST clients will continue to work even in the case of cluster fail-over or switch-over operations.

Usage

  • The REST Web Service API is called by using an HTTP client that sends JSON based requests and that receives JSON based responses.
  • The following REST Web Service API requests are supportedavailable:
    • URL joc/api/authentication/login
    • URL  joc/api/* 
      • Subsequent calls to URLs can, for example, retrieve the inventory and current information about workflows and jobs.of workflow.
      • Find the respective URLs from the Technical Documentation of the REST Web Service API
      • The JS7 REST Web Service will return API returns the respective relevant JSON response indicated with the docs.
    • URL joc/api/authentication/logout
      • The last operation of a client should be is a call to this URL in order to logout from the web serviceREST Web Service API.
  • Requirements
    • REST Web Service API requests should use HTTP POST or GET operations as indicated.
    • Should an idle timeout of 15 minutes between two web service requests be exceeded then the current session is invalidated and a login has to be performed. The timeout value can be adjusted with shiro.ini.
    Example: Get the list of orders scheduled until a given dateFind attached example order_list_sample.sh for use with curl. We do not consider curl to be perfectly prepared to handle web service requests, however, it shows the building blocks:
    • Code Block
      languagebash
      titleSample for use with curl to get list of orders scheduled until a given date
      linenumberstrue
      collapsetrue
      #!/usr/bin/sh
      # ----------------------------------------
      # Protocol, host and port of JOC Cockpit
      JS7_URL="http://localhost:7446"
      
      # Identification of JS7 instance
      JS7_CONTROLLER_ID="testsuite"
      
      # Date up to that scheduled orders are returned
      JS7_DATETO="+1d"
      
      # Base64 encoded string "user:password" for authentication. The below string represents "root:root"
      JS7_BASIC_AUTHENTICATION="`echo "root:root" | base64`"
      JS7_BASIC_AUTHENTICATION="${JS7_BASIC_AUTHENTICATION:0:${#JS7_BASIC_AUTHENTICATION}-4}"
      # -----------------------------------------
      
      
      # -----------------------------------------
      # Perform login
      echo ""
      echo "PERFORMING LOGIN"
      JS7_JSON="`curl -k -s -S -X POST -i -m 15 -H "Authorization: Basic $JS7_BASIC_AUTHENTICATION" -H "Accept: application/json" -H "Content-Type: application/json" $JS7_URL/joc/api/authentication/login`"
      JS7_ACCESS_TOKEN=$(echo $JS7_JSON | grep -Po '"accessToken":.*?[^\\]"' | awk -F ':' '{print $2}' | tr -d \" )
      # -----------------------------------------
      
      
      # -----------------------------------------
      # Get the list of orders for a date range
      echo ""
      echo "Get the list of orders for date range: $JS7_DATETO"
      # Execute web service request
      JS7_REST_BODY="{ \"controllerId\": \"$JS7_CONTROLLER_ID\", \"compact\": true, \"dateTo\": \"$JS7_DATETO\" }"
      JS7_JSON="`curl -k -s -S -X POST -d "$JS7_REST_BODY" -i -m 15 -H "X-Access-Token: $JS7_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/xml" $JS7_URL/joc/api/orders`"
      echo $JS7_JSON
      # -----------------------------------------
      
      
      # -----------------------------------------
      # Perform logout
      echo ""
      echo "PERFORMING LOGOUT"
      curl -k -s -S -X POST -i -m 15 -H "X-Access-Token: $JS7_ACCESS_TOKEN" -H "Accept: application/json" -H "Content-Type: application/json" $JS7_URL/joc/api/authentication/logout
      # -----------------------------------------
      echo ""
      
    • Explanations

      • Line 7: Depending on your JOC Cockpit installation the protocol will be http or https. The default port is 4446 but might have been modified during setup.
      • Line 10: The Controller ID is specified during installation of the Controller and identifies a Controler standalone instance or a Controller cluster.
      • Line 13, 16: Specify the relative date up to that you want the list of scheduled orders to be returned.
      • Line 19, 20: Default credentials after installation include the account "root" and password "root". The credentials might have been changed after setup of JOC Cockpit.
      • Lin 27: Consider to use Basic HTTP authentication
      • Line 28: The request to the /authentication/login web service returns an access token that is used with further requests.
      • Line 38, 39: Consider the JSON body created for the request and the URL used for status information about job chains.
      • Line 59: Always perform a logout and consider the session idle timeout.
  • xx
  • Example: Suspend an orderFind attached example joc_cockpit_curl_sample.sh for use with curl. We do not consider curl to be perfectly prepared to handle web service requests, however, it shows the building blocks:
  • xx
  • x
  • x

Further Resources

Display content by label
Labelsjs7 api shell
OtherTitleHow To .. Shell

Display content by label
Labelsjs7 api powershell
OtherTitleHow To .. PowerShell