mirror of
https://github.com/openstf/stf
synced 2025-10-03 17:59:28 +02:00
Add provider to device data.
This commit is contained in:
parent
389db73f08
commit
6ab252857f
6 changed files with 29 additions and 6 deletions
21
lib/cli.js
21
lib/cli.js
|
@ -1,4 +1,5 @@
|
||||||
var util = require('util')
|
var util = require('util')
|
||||||
|
var os = require('os')
|
||||||
|
|
||||||
var program = require('commander')
|
var program = require('commander')
|
||||||
|
|
||||||
|
@ -19,6 +20,10 @@ program
|
||||||
.option('-p, --connect-push <endpoint>'
|
.option('-p, --connect-push <endpoint>'
|
||||||
, 'push endpoint'
|
, 'push endpoint'
|
||||||
, cliutil.list)
|
, cliutil.list)
|
||||||
|
.option('-n, --name <name>'
|
||||||
|
, 'name (or os.hostname())'
|
||||||
|
, String
|
||||||
|
, os.hostname())
|
||||||
.action(function() {
|
.action(function() {
|
||||||
var serials = cliutil.allUnknownArgs(arguments)
|
var serials = cliutil.allUnknownArgs(arguments)
|
||||||
, options = cliutil.lastArg(arguments)
|
, options = cliutil.lastArg(arguments)
|
||||||
|
@ -31,13 +36,15 @@ program
|
||||||
}
|
}
|
||||||
|
|
||||||
require('./roles/provider')({
|
require('./roles/provider')({
|
||||||
filter: function(device) {
|
name: options.name
|
||||||
|
, filter: function(device) {
|
||||||
return serials.length === 0 || serials.indexOf(device.id) !== -1
|
return serials.length === 0 || serials.indexOf(device.id) !== -1
|
||||||
}
|
}
|
||||||
, fork: function(device) {
|
, fork: function(device) {
|
||||||
var fork = require('child_process').fork
|
var fork = require('child_process').fork
|
||||||
return fork(__filename, [
|
return fork(__filename, [
|
||||||
'device', device.id
|
'device', device.id
|
||||||
|
, '--provider', options.name
|
||||||
, '--connect-sub', options.connectSub.join(',')
|
, '--connect-sub', options.connectSub.join(',')
|
||||||
, '--connect-push', options.connectPush.join(',')
|
, '--connect-push', options.connectPush.join(',')
|
||||||
])
|
])
|
||||||
|
@ -52,6 +59,9 @@ program
|
||||||
program
|
program
|
||||||
.command('device <serial>')
|
.command('device <serial>')
|
||||||
.description('start device worker')
|
.description('start device worker')
|
||||||
|
.option('-n, --provider <name>'
|
||||||
|
, 'provider name'
|
||||||
|
, String)
|
||||||
.option('-s, --connect-sub <endpoint>'
|
.option('-s, --connect-sub <endpoint>'
|
||||||
, 'sub endpoint'
|
, 'sub endpoint'
|
||||||
, cliutil.list)
|
, cliutil.list)
|
||||||
|
@ -65,9 +75,13 @@ program
|
||||||
if (!options.connectPush) {
|
if (!options.connectPush) {
|
||||||
this.missingArgument('--connect-push')
|
this.missingArgument('--connect-push')
|
||||||
}
|
}
|
||||||
|
if (!options.provider) {
|
||||||
|
this.missingArgument('--provider')
|
||||||
|
}
|
||||||
|
|
||||||
require('./roles/device')({
|
require('./roles/device')({
|
||||||
serial: serial
|
serial: serial
|
||||||
|
, provider: options.provider
|
||||||
, endpoints: {
|
, endpoints: {
|
||||||
sub: options.connectSub
|
sub: options.connectSub
|
||||||
, push: options.connectPush
|
, push: options.connectPush
|
||||||
|
@ -322,6 +336,10 @@ program
|
||||||
, 'app port'
|
, 'app port'
|
||||||
, Number
|
, Number
|
||||||
, 7100)
|
, 7100)
|
||||||
|
.option('--provider <name>'
|
||||||
|
, 'provider name (or os.hostname())'
|
||||||
|
, String
|
||||||
|
, os.hostname())
|
||||||
.action(function() {
|
.action(function() {
|
||||||
var log = logger.createLogger('cli')
|
var log = logger.createLogger('cli')
|
||||||
, options = cliutil.lastArg(arguments)
|
, options = cliutil.lastArg(arguments)
|
||||||
|
@ -371,6 +389,7 @@ program
|
||||||
// provider
|
// provider
|
||||||
procutil.fork(__filename, [
|
procutil.fork(__filename, [
|
||||||
'provider'
|
'provider'
|
||||||
|
, '--name', options.provider
|
||||||
, '--connect-sub', options.bindDevPub
|
, '--connect-sub', options.bindDevPub
|
||||||
, '--connect-push', options.bindDevPull
|
, '--connect-push', options.bindDevPull
|
||||||
].concat(cliutil.allUnknownArgs(arguments)))
|
].concat(cliutil.allUnknownArgs(arguments)))
|
||||||
|
|
|
@ -26,14 +26,16 @@ module.exports.saveDeviceLog = function(serial, entry) {
|
||||||
|
|
||||||
module.exports.saveDeviceStatus = function(serial, status) {
|
module.exports.saveDeviceStatus = function(serial, status) {
|
||||||
return db.run(r.table('devices').get(serial).update({
|
return db.run(r.table('devices').get(serial).update({
|
||||||
status: status
|
status: status.status
|
||||||
|
, provider: status.provider
|
||||||
, statusChangedAt: r.now()
|
, statusChangedAt: r.now()
|
||||||
}))
|
}))
|
||||||
.then(function(stats) {
|
.then(function(stats) {
|
||||||
if (stats.skipped) {
|
if (stats.skipped) {
|
||||||
return db.run(r.table('devices').insert({
|
return db.run(r.table('devices').insert({
|
||||||
serial: serial
|
serial: serial
|
||||||
, status: status
|
, provider: status.provider
|
||||||
|
, status: status.status
|
||||||
, statusChangedAt: r.now()
|
, statusChangedAt: r.now()
|
||||||
, createdAt: r.now()
|
, createdAt: r.now()
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -55,7 +55,7 @@ module.exports = function(options) {
|
||||||
break
|
break
|
||||||
case wire.MessageType.DEVICE_STATUS:
|
case wire.MessageType.DEVICE_STATUS:
|
||||||
var message = wire.DeviceStatusMessage.decode(wrapper.message)
|
var message = wire.DeviceStatusMessage.decode(wrapper.message)
|
||||||
dbapi.saveDeviceStatus(message.serial, message.status)
|
dbapi.saveDeviceStatus(message.serial, message)
|
||||||
break
|
break
|
||||||
case wire.MessageType.DEVICE_PROPERTIES:
|
case wire.MessageType.DEVICE_PROPERTIES:
|
||||||
var message = wire.DevicePropertiesMessage.decode(wrapper.message)
|
var message = wire.DevicePropertiesMessage.decode(wrapper.message)
|
||||||
|
|
|
@ -54,7 +54,7 @@ module.exports = function(options) {
|
||||||
|
|
||||||
function pushDeviceStatus(device, type) {
|
function pushDeviceStatus(device, type) {
|
||||||
push.send([wireutil.global,
|
push.send([wireutil.global,
|
||||||
wireutil.makeDeviceStatusMessage(device.id, type)])
|
wireutil.makeDeviceStatusMessage(device.id, type, options.name)])
|
||||||
}
|
}
|
||||||
|
|
||||||
function isWantedDevice(device) {
|
function isWantedDevice(device) {
|
||||||
|
|
|
@ -111,10 +111,11 @@ module.exports = function(wire) {
|
||||||
|
|
||||||
return wireutil.envelope(wire.MessageType.DEVICE_PROPERTIES, message)
|
return wireutil.envelope(wire.MessageType.DEVICE_PROPERTIES, message)
|
||||||
}
|
}
|
||||||
, makeDeviceStatusMessage: function(serial, type) {
|
, makeDeviceStatusMessage: function(serial, type, provider) {
|
||||||
var message = new wire.DeviceStatusMessage(
|
var message = new wire.DeviceStatusMessage(
|
||||||
serial
|
serial
|
||||||
, wireutil.toDeviceStatus(type)
|
, wireutil.toDeviceStatus(type)
|
||||||
|
, provider
|
||||||
)
|
)
|
||||||
|
|
||||||
return wireutil.envelope(wire.MessageType.DEVICE_STATUS, message)
|
return wireutil.envelope(wire.MessageType.DEVICE_STATUS, message)
|
||||||
|
|
|
@ -53,6 +53,7 @@ enum DeviceStatus {
|
||||||
message DeviceStatusMessage {
|
message DeviceStatusMessage {
|
||||||
required string serial = 1;
|
required string serial = 1;
|
||||||
required DeviceStatus status = 2;
|
required DeviceStatus status = 2;
|
||||||
|
required string provider = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DeviceType {
|
enum DeviceType {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue