Develop & Publish Sample Edge Application
Sample Edge Application Introduction
- Mimics an edge manufacturing application running locally on-prem, receiving sensor data from the floor, processing it and taking a local action.
- Running on IBM cloud bare metal and virtual edges in the workshop sandbox.
- Packaged as a docker container. Deployed and managed by IEAM on both edges.
- The workshop uses Eurotech ESF framework to emulate and publish Industry 4.0 events (Temperature, Luminosity etc.). on an MQTT queue. The demo app reads events off MQTT and process data.
- After processing sensor data on the edge, the sample app posts it on a KAFKA event stream.
- In the Cloud Core instance of the workshop, the KAFKA topic is read via Watson Studio (CP4D) and data stored in a Cloudant DB.
- There is little change required to connect actual sensor devices to this demo rig via an IoT Gateway.
- The entire sandbox can be provisioned in IBM Cloud.
In below is the step by step guidance to develop and publish the Sample Edge Application. After completing the below steps, you will be able to:
- Publish the ESF emulator application esf-ieam that emulates the factory events such as buzzer, fan, light and temperature.
- Publish the sample edge application edge-app that reads the generated events, aggregate it to produce new events and publish it to Event Streams that will be read by IBM Watson Stream Flows to save it into IBM CloudantDB.
Navigation
Prerequisites
- Install the following tools:
- Create a public repo in docker hub.
- User ibm-workshop was created while installing the IEAM agent on the edge node.
Develop the Sample Edge Application
-
Log in to your edge node with the user id ibm-workshop created during IEAM agent deployment. Pull the sample Github code. Create the horizon private signing key.
Note: For edge node only Linux operating system is supported.
cd /home/ibm-workshop/workspace git clone https://github.com/gargpriyank/edge-app-skeleton.git mv edge-app-skeleton sample-edge-app cd sample-edge-app hzn key create IBM <your_email_id>
-
Look at the below sample code. HZN_ORG_ID is the IEAM organization id where the edge service will be published. DOCKER_IMAGE_BASE is your docker repo name. SERVICE_NAME is the edge service name with which the service will be published. SERVICE_VERSION is the version of edge service and the docker image. Copy and paste this code in
edge-app/horizon/hzn.json
file and update the values as per your requirement.{ "HZN_ORG_ID": "$HZN_ORG_ID", "MetadataVars": { "DOCKER_IMAGE_BASE": "sandboxedgeworkshop/edge-app", "SERVICE_NAME": "edge-app", "SERVICE_VERSION": "0.0.1" } }
-
Look at the below sample code. ARCH is the hardware architecture of the edge node where the edge service will be deployed. requiredServices section shows the required services that should start first to run this service. userInput section lists all the input variables required by this service. deployment section lists all the services that will be published and deployed. Copy and paste this code in
edge-app/horizon/service.definition.json
file and update the values as per your requirement.{ "org": "$HZN_ORG_ID", "label": "$SERVICE_NAME for $ARCH", "description": "Edge Application service", "public": true, "documentation": "", "url": "$SERVICE_NAME", "version": "$SERVICE_VERSION", "arch": "$ARCH", "sharable": "singleton", "requiredServices": [ { "url": "esf-ieam", "org": "$HZN_ORG_ID", "versionRange": "[0.0.0,INFINITY)", "arch": "$ARCH" } ], "userInput": [ { "name": "EVENTSTREAMS_TOPIC_NAME", "label": "The Topic name of the instance of IBM Event Streams", "type": "string", "defaultValue": "" }, { "name": "EVENTSTREAMS_BROKER_URL", "label": "The Broker URL of the instance of IBM Event Streams", "type": "string", "defaultValue": "" }, { "name": "EVENTSTREAMS_API_KEY", "label": "The API Key of the instance of IBM Event Streams", "type": "string", "defaultValue": "" } ], "deployment": { "services": { "$SERVICE_NAME": { "image": "${DOCKER_IMAGE_BASE}:$SERVICE_VERSION", "network": "edge_workshop", "privileged": true } } } }
-
Look at the below sample code. constraints section lists all the deployment constraints that should match with the node policy properties while registering. Copy and paste this code in
edge-app/horizon/deployment.policy.json
file and update the values as per your requirement.{ "label": "$SERVICE_NAME Deployment Policy", "description": "A Horizon Deployment Policy example to run edge-app", "service": { "name": "$SERVICE_NAME", "org": "$HZN_ORG_ID", "arch": "$ARCH", "serviceVersions": [ { "version": "$SERVICE_VERSION", "priority":{} } ] }, "properties": [ ], "constraints": [ "deploy-edge-app == true" ], "userInput": [ { "serviceOrgid": "$HZN_ORG_ID", "serviceUrl": "$SERVICE_NAME", "serviceVersionRange": "[0.0.0,INFINITY)", "inputs": [ { "name": "EVENTSTREAMS_TOPIC_NAME", "value": "$EVENTSTREAMS_TOPIC_NAME" }, { "name": "EVENTSTREAMS_BROKER_URL", "value": "$EVENTSTREAMS_BROKER_URL" }, { "name": "EVENTSTREAMS_API_KEY", "value": "$EVENTSTREAMS_API_KEY" } ] } ] }
-
Look at the below sample code. constraints section lists all the service policy constraints that uses the Open Horizon inbuild variable openhorizon.memory that should match with the node policy properties while registering. Copy and paste this code in
edge-app/horizon/service.policy.json
file and update the values as per your requirement.{ "properties": [], "constraints": [ "openhorizon.memory >= 100" ] }
-
Look at the content in below. Copy and paste it into
edge-app/Makefile
to build and publish the edge-app service.-include horizon/.hzn.json.tmp.mk export ARCH ?= $(shell hzn architecture) build: docker build -t $(DOCKER_IMAGE_BASE):$(SERVICE_VERSION) . publish-service: hzn exchange service publish -O -f horizon/service.definition.json publish-service-policy: hzn exchange service addpolicy -f horizon/service.policy.json $(HZN_ORG_ID)/$(SERVICE_NAME)_$(SERVICE_VERSION)_$(ARCH) publish-deployment-policy: hzn exchange deployment addpolicy -f horizon/deployment.policy.json $(HZN_ORG_ID)/policy-$(SERVICE_NAME)_$(SERVICE_VERSION)_$(ARCH) build-publish: $(MAKE) build $(MAKE) publish-service $(MAKE) publish-service-policy $(MAKE) publish-deployment-policy horizon/.hzn.json.tmp.mk: horizon/hzn.json @ hzn util configconv -f $< | sed 's/=/?=/' > $@
-
Look at the content in below. Copy and paste it into
Makefile
to build and publish the edge-app and esf services.export ARCH ?= $(shell hzn architecture) publish-esf-ieam: cd esf-ieam && $(MAKE) publish-service publish-edge-app: cd edge-app && $(MAKE) build-publish publish: $(MAKE) publish-esf-ieam $(MAKE) publish-edge-app
Publish the Sample Edge Application
Run the below command and that will build and publish the edge-app and esf services.
make publish