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