Follow the steps on this page to deploy CPU To IBM Event Streams Edge Service using deployment policy.
- If you have not already done so, complete the steps in this section:
- The Horizon Policy mechanism offers an alternative to using Deployment Patterns. Policies provide much finer control over agreement forming between Horizon Agents on Edge Nodes, and the Horizon AgBots. It also provides a greater separation of concerns, allowing Edge Nodes owners, Service code developers, and Business owners to each independently articulate their own Policies. There are therefore three types of Horizon Policies:
-
Node Policy (provided at registration time by the node owner)
-
Service Policy (may be applied to a published Service in the Exchange)
-
Deployment Policy (which approximately corresponds to a Deployment Pattern)
- As an alternative to specifying a Deployment Pattern when you register your Edge Node, you may register with a Node Policy.
- Get the required
cpu2evtstreams
node policy file and the user input file:
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/evtstreams/cpu2evtstreams/horizon/node.policy.json
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/evtstreams/cpu2evtstreams/horizon/use/userinput.json
- Below is the
node_policy.json
file you just grabbed in step one:
{
"properties": [
{
"name": "openhorizon.example", "value": "cpu2evtstreams"
}
],
"constraints": []
}
- It provides values for one just properties (
openhorizon.example
), that should restrict the services that get deployed to this edge node to thecpu2evtstreams
service.
- Register your Node Policy using this command:
hzn register --policy node.policy.json -f userinput.json
- When the registration completes, use the following command to review the Node Policy:
hzn policy list
- Notice that in addition to the
properties
stated in thenode.policy.json
file, Horizon has added a few more (openhorizon.cpu, openhorizon.arch, and openhorizon.memory). Horizon provides this additional information automatically and theseproperties
may be used in any of your Policyconstraints
.
-
Like the other two Policy types, Service Policy contains a set of
properties
and a set ofconstraints
. Theproperties
of a Service Policy could state characteristics of the Service code that Node Policy authors or Deployment Policy authors may find relevant. Theconstraints
of a Service Policy can be used to restrict where this Service can be run. The Service developer could, for example, assert that this Service requires a particular hardware setup such as CPU/GPU constraints, memory constraints, specific sensors, actuators or other peripheral devices required, etc. -
Below is the
service.policy.json
file the service developer attached to theibm.cpu2evtstreams
service when it was published to the exchange:
{
"properties": [],
"constraints": [
"openhorizon.memory >= 100"
]
}
- Note this simple Service Policy doesn't provide any
properties
, but it does have aconstraint
. This example constraint is one that a Service developer might add, stating that their Service must only run on edge nodes with 100 MB or more memory.
- View the pubished service policy attached to
ibm.cpu2evtstreams
:
hzn exchange service listpolicy IBM/ibm.cpu2evtstreams_1.4.3_amd64
-
Notice that Horizon has again automatically added some additional
properties
to your Policy. These generated property values can be used inconstraints
in Node Policies and Deployment Policies. -
Now that we have set up the Policies for an Edge Node and the Policies for a published Service, we can move on to the final step of defining a Deployment Policy to tie them all together and cause software to be automatically deployed on your Edge Node.
-
Deployment Policy (sometimes called Business Policy) is what ties together Edge Nodes, Published Services, and the Policies defined for each of those, making it roughly analogous to the Deployment Patterns you have previously worked with.
-
Deployment Policy, like the other two Policy types, contains a set of
properties
and a set ofconstraints
, but it contains other things as well. For example, it explicitly identifies the Service it will cause to be deployed onto Edge Nodes if negotiation is successful, in addition to configuration variable values, performing the equivalent function to the-f horizon/userinput.json
clause of a Deployment Patternhzn register ...
command. The Deployment Policy approach for configuration values is more powerful because this operation can be performed centrally (no need to connect directly to the Edge Node). -
Below is the
deployment.policy.json
forcpu2evtstreams
that was published to the Exchange when it was created:
{
"label": "$SERVICE_NAME Deployment Policy",
"description": "A Horizon Deployment Policy example to run cpu2evtstreams",
"service": {
"name": "$SERVICE_NAME",
"org": "IBM",
"arch": "*",
"serviceVersions": [
{
"version": "$SERVICE_VERSION",
"priority":{}
}
]
},
"properties": [
],
"constraints": [
"openhorizon.example == cpu2evtstreams"
],
"userInput": []
}
]
}
- This simple example of a Deployment Policy doesn't provide any
properties
, but it does have oneconstraints
value that are satisfied by theproperties
set in thehorizon/node.policy.json
file, so this Deployment Policy should successfully deploy our Service onto the Edge Node.
- Run the following commands to set the environment variables needed by the
deployment.policy.json
file in your shell:
export ARCH=$(hzn architecture)
eval $(hzn util configconv -f hzn.json)
eval export $(cat agent-install.cfg)
- Publish this Deployment Policy to the Exchange and get this Service running on the Edge Node and give it a memorable name:
hzn exchange deployment addpolicy -f deployment.policy.json <choose-any-policy-name>
- The results should look very similar to your original
horizon/deployment.policy.json
file, except thatowner
,created
, andlastUpdated
and a few other fields have been added.
- The edge device will make an agreement with one of the Horizon agreement bots (this typically takes about 15 seconds). Repeatedly query the agreements of this device until the
agreement_finalized_time
andagreement_execution_start_time
fields are filled in:
hzn agreement list
- Once the agreement is made, list the docker container edge service that has been started as a result:
sudo docker ps
- On any machine, install kafkacat, then subscribe to the Event Streams topic to see the json data that
cpu2evtstreams
is sending:
kafkacat -C -q -o end -f "%t/%p/%o/%k: %s\n" -b $EVTSTREAMS_BROKER_URL -X api.version.request=true -X security.protocol=sasl_ssl -X sasl.mechanisms=PLAIN -X sasl.username=token -X sasl.password=$EVTSTREAMS_API_KEY -X ssl.ca.location=$EVTSTREAMS_CERT_FILE -t cpu2evtstreams
- Note: Press Ctrl C to stop the command output.
- See the cpu2evtstreams service output:
hzn service log -f ibm.cpu2evtstreams
- Note: Press Ctrl C to stop the command output.
- Unregister your edge node, stopping the cpu2evtstreams service:
hzn unregister -f