This service exercises the edge-sync-service
(ESS). The edge sync service communicates with the cloud sync service (CSS) to send and receive data. For this example only the local ESS and CSS are utilized.
The esstest
service emits a JavaScript Object Notation (JSON) response when it receives a request for its status on its port (n.b. default 8080
). That status includes the count of models available from the ESS.
The following software is required:
hzn
- Open Horizon command-line-interface (CLI) and (optional) local agentdocker
- Docker command-line-interface and servicejq
- JSON query processorcurl
- retrieve resources identified by universal resource locators (URL)
The run.sh
script is called when the container is launched (n.b. CMD
instruction in Dockerfile
); it periodically calls the ess-objects-get.sh
script which performs three primary actions:
- Retrieve array of objects matching the objectType specified; e.g.
model
- For each object retrieve the data associated and store it in a file and send a
received
message indicating receipt - Generate a JSON payload array of objects received
Create a new directory, esstest
, and clone this repository:
mkdir -p ~/gitdir/esstest
cd ~/gitdir/esstest
git clone https://github.com/open-horizon/esstest .
Copy the IBM Cloud Platform API key file downloaded from IAM, and set environment variables for Open Horizon organization:
cp ~/Downloads/apiKey.json .
export HZN_EXCHANGE_APIKEY=$(jq -r '.apiKey' apiKey.json)
export HZN_ORG_ID=<organization>
Build the docker image locally using the native (i.e. amd64
) architecture.
DOCKER_NAMESPACE=<dockerhubid>
DOCKER_TAG="${DOCKER_NAMESPACE}/esstest_amd64:0.0.1"
docker build -t ${DOCKER_TAG} .
Configure as a new service using the hzn
command-line-interface (CLI) program:
hzn dev service new -o ${HZN_ORG_ID} -s "esstest" -V "0.0.1" -i ${DOCKER_NAMESPACE}/esstest --noImageGen
Start service (and ESS and CSS running locally); for example:
hzn dev service start
Check Docker logs; for example using a background process:
docker logs -f $(docker ps --format '{{.Names}}' | egrep esstest) &
The logs should indicate a FAILED; HTTP_CODE: 404
message repeatedly, indicating no new objects are available to the node.
Create an object using the css-object-create-local.sh
script:
% css-object-create-local.sh
Put data into the object using the css-object-put-local.sh
script; for example, put the string "Hello World"
:
% echo "Hello World" | css-object-put-local.sh
Check Docker logs; one object of type model
received, containing twelve (12) bytes of data (i.e. "Hello World"
).
The logs should indicate: SUCCESS; MODELS: [{"ID":"test","file":"/tmp/test.dat","size":12}]
Change the css-object-put-local.sh
script data to the string "Goodbye World"
:
% echo "Goodbye World" | css-object-put-local.sh
Check Docker logs; one object of type model
received, containing fourteen (14) bytes of data (i.e. "Goodbye World"
).
The logs should indicate: SUCCESS; MODELS: [{"ID":"test","file":"/tmp/test.dat","size":14}]
Repeat steps 7,8,9,10, and 11, but specify a new objectID (e.g. my_model_id
); for example:
% css-object-create-local.sh myModelID
% echo "This is my model data" | css-object-put-local.sh myModelID
% echo "Now I have changed my model data" | css-object-put-local.sh myModelID
And monitor the Docker logs for indications of FAILED
and SUCCESS
Shutdown service
hzn dev service stop