Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions node/app/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions node/app/src/Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] --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
Expand Down
43 changes: 21 additions & 22 deletions node/app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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) => {
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion node/app/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 3 additions & 0 deletions node/driver/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions node/driver/src/databox-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
{
"data-source-type": "helloWorldActuator",
"description": "hello world actuator",
"store-type": "kv",
"store-type": "ts/blob",
"schema": {}
}
]
}
}
21 changes: 9 additions & 12 deletions node/driver/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
})
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion node/driver/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}