- 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 the deployment placement of edge services. 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 helloworld node policy file:
wget https://raw.githubusercontent.com/open-horizon/examples/master/edge/services/helloworld/horizon/node.policy.json
- Below is the
node.policy.json
file you obtained in step one:
{
"properties": [
{ "name": "openhorizon.example", "value": "helloworld" }
],
"constraints": [
]
}
- It provides values for one just
properties
(openhorizon.example
), that should restrict the services that get deployed to this edge node to thehelloworld
service.
- Register your Node Policy with this policy
hzn register --policy node.policy.json
- When the registration completes, use the following command to review the Node Policy:
hzn policy list
- Notice that in addition to the three
properties
stated in the node_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 toibm.helloworld
when it was published:
{
"properties": [
],
"constraints": [
"openhorizon.memory >= 100"
]
}
- Note this simple Service Policy doesn't provide any
properties
, but it does have aconstraint
. This exampleconstraint
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.helloworld
:
hzn exchange service listpolicy IBM/ibm.helloworld_1.0.0_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 you have set up the Policy for your Edge Node and the published Service policy is in the exchange, 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 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
for thehelloworld
service that has been published into the Exchange when it was created:
{
"label": "$SERVICE_NAME Deployment Policy",
"description": "A super-simple sample Horizon Deployment Policy",
"service": {
"name": "$SERVICE_NAME",
"org": "IBM",
"arch": "*",
"serviceVersions": [
{
"version": "$SERVICE_VERSION",
"priority":{}
}
]
},
"properties": [
],
"constraints": [
"openhorizon.example == helloworld"
],
"userInput": [
{
"serviceOrgid": "IBM",
"serviceUrl": "$SERVICE_NAME",
"serviceVersionRange": "[0.0.0,INFINITY)",
"inputs": [
{
"name": "HW_WHO",
"value": "Valued Customer"
}
]
}
]
}
-
This simple example of a Deployment Policy doesn't provide any
properties
, but it does have oneconstraints
value that is satisfied by theproperties
set in thenode.policy.json
file, so this Deployment Policy should successfully deploy our Service onto the Edge Node. -
At the end, the userInput section has the same purpose as the
horizon/userinput.json
files provided for other examples if the given services requires them. In this case the helloworld service defines only one configuration variable, HW_WHO, and the userInput section here provides a value for HW_WHO (i.e., Valued Customer).
- By now your edge device should have formed 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
- After the agreement is made, list the edge service docker container that has been started as a result:
sudo docker ps
- See the
ibm.helloworld
service output:
hzn service log -f ibm.helloworld
- Note: Press Ctrl C to stop the command output.
- Unregister your edge node:
hzn unregister -f