diff --git a/node/app/src/Dockerfile b/node/app/src/Dockerfile index 73215d1..5cbf82c 100644 --- a/node/app/src/Dockerfile +++ b/node/app/src/Dockerfile @@ -9,6 +9,9 @@ RUN addgroup -S databox && adduser -S -g databox databox && \ ADD ./package.json package.json +# only if using git +RUN apk --no-cache add git + RUN npm install --production USER databox diff --git a/node/app/src/Dockerfile-dev b/node/app/src/Dockerfile-dev index dca793b..d4b24ea 100644 --- a/node/app/src/Dockerfile-dev +++ b/node/app/src/Dockerfile-dev @@ -6,6 +6,9 @@ RUN addgroup -S databox && adduser -S -g databox databox && \ apk --no-cache add build-base pkgconfig nodejs npm libzmq zeromq-dev libsodium-dev python && \ npm install zeromq@4.6.0 --zmq-external --verbose +# if using git +RUN apk --no-cache add git + #globally install node packages and add to path ADD ./package.json package.json RUN npm install -g diff --git a/node/app/src/main.js b/node/app/src/main.js index c4771b1..f75fab2 100644 --- a/node/app/src/main.js +++ b/node/app/src/main.js @@ -5,12 +5,14 @@ var bodyParser = require("body-parser"); var databox = require("node-databox"); var WebSocket = require("ws"); +const DATABOX_ARBITER_ENDPOINT = process.env.DATABOX_ARBITER_ENDPOINT || 'tcp://127.0.0.1:4444'; const DATABOX_ZMQ_ENDPOINT = process.env.DATABOX_ZMQ_ENDPOINT || "tcp://127.0.0.1:5555"; const DATABOX_TESTING = !(process.env.DATABOX_VERSION); const PORT = DATABOX_TESTING ? 8090 : process.env.PORT || '8080'; -//this will ref the timeseriesblob client which will observe and write to the databox actuator (created in the driver) -let tsc; +//this will ref the store client which will observe and write to the databox actuator (created in the driver) +let store; +let helloWorldActuatorDataSourceID; //server and websocket connection; let ws, server = null; @@ -20,37 +22,33 @@ const listenToActuator = (emitter) => { console.log("started listening to actuator"); emitter.on('data', (data) => { - console.log("seen data from the hello world actuator!", JSON.parse(data.data)); + console.log("seen data from the hello world actuator!", data); if (ws) { - ws.send(data.data); - databox.export.longpoll('https://export.amar.io/', data.data) - .catch((err) => { - console.log("[error] export.longpoll ", err) - }) + let json = JSON.stringify(data.data) + ws.send(json); + // Note, export service deprecated and not currently supported } }); emitter.on('error', (err) => { - console.warn(err); + console.warn("error from actuator", err); }); } if (DATABOX_TESTING) { - tsc = databox.NewTimeSeriesBlobClient(DATABOX_ZMQ_ENDPOINT, false); - tsc.Observe("helloWorldActuator").then((emitter) => { + store = databox.NewStoreClient(DATABOX_ZMQ_ENDPOINT, DATABOX_ARBITER_ENDPOINT, false); + helloWorldActuatorDataSourceID = "helloWorldActuator"; + store.TSBlob.Observe(helloWorldActuatorDataSourceID).then((emitter) => { listenToActuator(emitter); }); } else { - let helloWorldActuator; - //listen in on the helloWorld Actuator, which we have asked permissions for in the manifest - databox.HypercatToSourceDataMetadata(process.env[`DATASOURCE_helloWorldActuator`]).then((data) => { - helloWorldActuator = data - return databox.NewTimeSeriesBlobClient(helloWorldActuator.DataSourceURL, false) - }).then((store) => { - tsc = store; - return store.Observe(helloWorldActuator.DataSourceMetadata.DataSourceID) - }).then((emitter) => { + let helloWorldActuator = databox.HypercatToDataSourceMetadata(process.env[`DATASOURCE_helloWorldActuator`]); + helloWorldActuatorDataSourceID = helloWorldActuator.DataSourceID; + let helloWorldStore = databox.GetStoreURLFromHypercat(process.env[`DATASOURCE_helloWorldActuator`]); + store = databox.NewStoreClient(helloWorldStore, DATABOX_ARBITER_ENDPOINT, false) + store.TSBlob.Observe(helloWorldActuatorDataSourceID, 0) + .then((emitter) => { listenToActuator(emitter); }).catch((err) => { console.warn("Error Observing helloWorldActuator", err); @@ -75,8 +73,9 @@ app.get("/ui", function (req, res) { app.get('/ui/actuate', (req, res) => { + let data = { msg: `${Date.now()}: databox actuation event` }; return new Promise((resolve, reject) => { - tsc.Write("helloWorldActuator", { msg: `${Date.now()}: databox actuation event` }).then(() => { + store.TSBlob.Write(helloWorldActuatorDataSourceID, data).then(() => { console.log("successfully actuated!"); resolve(); }).catch((err) => { @@ -101,7 +100,7 @@ if (DATABOX_TESTING) { } else { console.log("[Creating https server]", PORT); - const credentials = databox.getHttpsCredentials(); + const credentials = databox.GetHttpsCredentials(); server = https.createServer(credentials, app).listen(PORT); } diff --git a/node/app/src/package.json b/node/app/src/package.json index 604a1c9..e3e0391 100644 --- a/node/app/src/package.json +++ b/node/app/src/package.json @@ -29,7 +29,7 @@ "express": "^4.16.3", "http": "0.0.0", "https": "^1.0.0", - "node-databox": "0.9.0", + "node-databox": "^0.10.7", "ws": "^6.0.0" } } diff --git a/node/driver/src/Dockerfile b/node/driver/src/Dockerfile index 7567bd1..75b2605 100644 --- a/node/driver/src/Dockerfile +++ b/node/driver/src/Dockerfile @@ -9,6 +9,9 @@ apk del build-base pkgconfig libsodium-dev python zeromq-dev ADD ./package.json package.json +# only if using git... +RUN apk --no-cache add git + RUN npm install --production USER databox diff --git a/node/driver/src/databox-manifest.json b/node/driver/src/databox-manifest.json index 4cf985d..a024904 100644 --- a/node/driver/src/databox-manifest.json +++ b/node/driver/src/databox-manifest.json @@ -28,8 +28,8 @@ { "data-source-type": "helloWorldActuator", "description": "hello world actuator", - "store-type": "kv", + "store-type": "ts/blob", "schema": {} } ] -} \ No newline at end of file +} diff --git a/node/driver/src/main.js b/node/driver/src/main.js index c2cd584..4b620a0 100644 --- a/node/driver/src/main.js +++ b/node/driver/src/main.js @@ -4,15 +4,12 @@ var express = require("express"); var bodyParser = require("body-parser"); var databox = require("node-databox"); +const DATABOX_ARBITER_ENDPOINT = process.env.DATABOX_ARBITER_ENDPOINT || 'tcp://127.0.0.1:4444'; const DATABOX_ZMQ_ENDPOINT = process.env.DATABOX_ZMQ_ENDPOINT || "tcp://127.0.0.1:5555"; const DATABOX_TESTING = !(process.env.DATABOX_VERSION); const PORT = process.env.port || '8080'; -//create a timeseries blob client for communicating with the timeseries store -const tsc = databox.NewTimeSeriesBlobClient(DATABOX_ZMQ_ENDPOINT, false); - -//create a keyvalue client for storing config -const kvc = databox.NewKeyValueClient(DATABOX_ZMQ_ENDPOINT, false); +const store = databox.NewStoreClient(DATABOX_ZMQ_ENDPOINT, DATABOX_ARBITER_ENDPOINT, false); //get the default store metadata const metaData = databox.NewDataSourceMetadata(); @@ -36,18 +33,18 @@ const helloWorldActuator = { Vendor: 'Databox Inc.', DataSourceType: 'helloWorldActuator', DataSourceID: 'helloWorldActuator', - StoreType: 'ts', + StoreType: 'ts/blob', IsActuator: true, } ///now create our stores using our clients. -kvc.RegisterDatasource(helloWorldConfig).then(() => { +store.RegisterDatasource(helloWorldConfig).then(() => { console.log("registered helloWorldConfig"); //now register the actuator - return tsc.RegisterDatasource(helloWorldActuator) + return store.RegisterDatasource(helloWorldActuator) }).catch((err) => { console.log("error registering helloWorld config datasource", err) }).then(() => { console.log("registered helloWorldActuator, observing", helloWorldActuator.DataSourceID); - tsc.Observe(helloWorldActuator.DataSourceID, 0) + store.TSBlob.Observe(helloWorldActuator.DataSourceID, 0) .catch((err) => { console.log("[Actuation observing error]", err); }) @@ -75,7 +72,7 @@ app.get("/", function (req, res) { }); app.get("/ui", function (req, res) { - kvc.Read(helloWorldConfig.DataSourceID, "config").then((result) => { + store.KV.Read(helloWorldConfig.DataSourceID, "config").then((result) => { console.log("result:", helloWorldConfig.DataSourceID, result); res.render('index', { config: result.value }); }).catch((err) => { @@ -89,7 +86,7 @@ app.post('/ui/setConfig', (req, res) => { const config = req.body.config; return new Promise((resolve, reject) => { - kvc.Write(helloWorldConfig.DataSourceID, "config", { key: helloWorldConfig.DataSourceID, value: config }).then(() => { + store.KV.Write(helloWorldConfig.DataSourceID, "config", { key: helloWorldConfig.DataSourceID, value: config }).then(() => { console.log("successfully written!", config); resolve(); }).catch((err) => { @@ -111,6 +108,6 @@ if (DATABOX_TESTING) { http.createServer(app).listen(PORT); } else { console.log("[Creating https server]", PORT); - const credentials = databox.getHttpsCredentials(); + const credentials = databox.GetHttpsCredentials(); https.createServer(credentials, app).listen(PORT); } diff --git a/node/driver/src/package.json b/node/driver/src/package.json index 6927421..3b894cf 100644 --- a/node/driver/src/package.json +++ b/node/driver/src/package.json @@ -29,6 +29,6 @@ "express": "^4.16.3", "http": "0.0.0", "https": "^1.0.0", - "node-databox": "^0.9.0" + "node-databox": "^0.10.7" } }