open-horizon / examples

Code examples you can use with Horizon.
Apache License 2.0
40 stars 65 forks source link

Provide Rene KC content for 4.1 blank pages #317

Closed t-fine closed 3 years ago

t-fine commented 4 years ago
t-fine commented 4 years ago

8. Using Deployment Patterns

Using a deployment pattern is a straightforward and easy way to deploy a service to your edge node. You specify the top-level service, or multiple top-level services, you want to be deployed to your edge node and IBM Edge Application Manager (IEAM) will handle the rest, including the deployment of any dependent services your top-level service may have.

Once you have a service created and added to the IEAM Exchange you will need to create a pattern.json file, like the one in the following code snippet.

{
  "name": "pattern-ibm.cpu2evtstreams-arm",
  "label": "Edge ibm.cpu2evtstreams Service Pattern for arm",
  "description": "Pattern for ibm.cpu2evtstreams for arm",
  "public": true,
  "services": [
    {
      "serviceUrl": "ibm.cpu2evtstreams",
      "serviceOrgid": "IBM",
      "serviceArch": "arm",
      "serviceVersions": [
        {
          "version": "1.4.3",
          "priority": {
            "priority_value": 1,
            "retries": 1,
            "retry_durations": 1800,
            "verified_durations": 45
          }
        },
        {
          "version": "1.4.2",
          "priority": {
            "priority_value": 2,
            "retries": 1,
            "retry_durations": 3600
          }
        }
      ]
    }
  ],
  "userInput": [
    {
      "serviceOrgid": "IBM",
      "serviceUrl": "ibm.cpu2evtstreams",
      "serviceVersionRange": "[0.0.0,INFINITY)",
      "inputs": [
        {
          "name": "EVTSTREAMS_API_KEY",
          "value": "$EVTSTREAMS_API_KEY"
        },
        {
          "name": "EVTSTREAMS_BROKER_URL",
          "value": "$EVTSTREAMS_BROKER_URL"
        },
        {
          "name": "EVTSTREAMS_CERT_ENCODED",
          "value": "$EVTSTREAMS_CERT_ENCODED"
        }
      ]
    }
  ]
}

Above is an example of a patter.json file for the ibm.cpu2evtstreams service for arm devices. You can see there is no need to specify cpu_percent and gps (dependent services of cpu2evtstreams) because that is already taken care of by the service_definition.json file, so a successfully registered edge node will begin running those workloads automatically.

The pattern.json file gives you the ability to customize rollback settings in the serviceVersions section. You can specify multiple older versions of your service and give each version a priority for your edge node to roll back to if there is an error with your new version. In addition to assigning a priority to each rollback version, you can specify things like number and duration of retry attempts before falling back to a lower priority version of the specified service.

You can also set any configuration variables your service might need to function correctly centrally when you publish your deployment pattern by including them in the userInput section near the bottom. In the case when the ibm.cpu2evtstreams service is published it will pass with it the credentials necessary to publish data to IBM Event Streams, which can be done with the following command:

hzn exchange pattern publish -f pattern.json

With the pattern published, you can then register an arm device to it:

hzn register -p pattern-ibm.cpu2evtstreams-arm

This will cause the ibm.cpu2evtstreams and any dependent services to be deployed to your node. Note that we are not passing a userInput.json file into the hzn register command above, like it you would do if you were following the steps in open-horizon examples (LINK: https://github.com/open-horizon/examples/tree/master/edge/evtstreams/cpu2evtstreams#-using-the-cpu-to-ibm-event-streams-edge-service-with-deployment-pattern) repository because we passed the userInputs with the pattern itself, so any edge node that registers will automatically have access to those environment variables.

All ibm.cpu2evtstreams workloads can be terminated bu unregistering.

hzn unregister -fD

For more information about patterns and the hzn commands you can use to interact with them, run the following

hzn exchange pattern -h
t-fine commented 4 years ago

In this section you will learn how to deploy workloads to your edge nodes by walking thru several examples in the Edge service examples (LINK: https://www-03preprod.ibm.com/support/knowledgecenter/SSFKVV_4.1/devices/installing/additional_examples.html) section.

After working thru examples using deployment policy and deployment patterns, you can further your understanding of these topics by reading the following topics under the Using deployment policies (LINK: https://www-03preprod.ibm.com/support/knowledgecenter/SSFKVV_4.1/devices/using_edge_devices/detailed_policy.html) section.