From f273c2214e3e72757fc730c0b1db0301466db4c5 Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Tue, 21 Feb 2017 10:35:41 +0100 Subject: [PATCH] Save runtime to registry when adding manually, refs noflo/noflo-nodejs#105 --- components/StoreRemoteRuntime.coffee | 33 ++++++++++++++++++++++++++++ elements/noflo-ui.html | 2 +- graphs/RegistryMiddleware.fbp | 14 +++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 components/StoreRemoteRuntime.coffee diff --git a/components/StoreRemoteRuntime.coffee b/components/StoreRemoteRuntime.coffee new file mode 100644 index 000000000..95b32656a --- /dev/null +++ b/components/StoreRemoteRuntime.coffee @@ -0,0 +1,33 @@ +noflo = require 'noflo' +registry = require 'flowhub-registry' + +exports.getComponent = -> + c = new noflo.Component + c.inPorts.add 'in', + datatype: 'object' + c.inPorts.add 'user', + datatype: 'object' + c.outPorts.add 'out', + datatype: 'object' + c.outPorts.add 'error', + datatype: 'object' + + noflo.helpers.WirePattern c, + in: 'in' + params: 'user' + out: 'out' + async: true + , (data, groups, out, callback) -> + unless c.params?.user?['grid-token'] + # User not logged in, persist runtime only locally + out.send data + do callback + return + + data.user = c.params.user['grid-user']?.id + rt = new registry.Runtime data, + host: '$NOFLO_REGISTRY_SERVICE' + rt.register (err) -> + return callback err if err + out.send data + do callback diff --git a/elements/noflo-ui.html b/elements/noflo-ui.html index 6aaf22a86..008c58e0f 100644 --- a/elements/noflo-ui.html +++ b/elements/noflo-ui.html @@ -92,7 +92,7 @@ this.emitEvent('project:save:graph', event.detail); }.bind(this)); this.$.main.addEventListener('newruntime', function (event) { - this.emitEvent('project:save:runtime', event.detail); + this.emitEvent('flowhub:runtimes:register', event.detail); }.bind(this)); this.$.main.addEventListener('newproject', function (event) { this.emitEvent('project:save:project', event.detail); diff --git a/graphs/RegistryMiddleware.fbp b/graphs/RegistryMiddleware.fbp index 21406f2d2..95fe3575a 100644 --- a/graphs/RegistryMiddleware.fbp +++ b/graphs/RegistryMiddleware.fbp @@ -2,7 +2,7 @@ INPORT=Dispatch.IN:IN OUTPORT=Dispatch.PASS:PASS OUTPORT=NewActions.OUT:NEW -'flowhub:runtimes:fetch' -> ROUTES Dispatch(ui/DispatchAction) +'flowhub:runtimes:fetch,flowhub:runtimes:register' -> ROUTES Dispatch(ui/DispatchAction) # New actions generated by this middleware 'project:save:runtime' -> ACTION RuntimeSaveAction(ui/SetAction) @@ -11,8 +11,16 @@ RuntimeSaveAction OUT -> IN NewActions(core/Merge) RegistryErrorAction OUT -> IN NewActions # Fetching list of user's registered runtimes -'user' -> KEYS GetUserState(ui/GetActionValues) +'user' -> KEYS GetUserStateFetch(ui/GetActionValues) Dispatch HANDLE[0] -> IN GetUserState -GetUserState VALUES[0] -> USER GetRuntimes(ui/GetRemoteRuntimes) +GetUserStateFetch VALUES[0] -> USER GetRuntimes(ui/GetRemoteRuntimes) GetRuntimes RUNTIME -> IN RuntimeSaveAction GetRuntimes ERROR -> IN RegistryErrorAction + +# Storing a new runtime definition to registry +'user' -> KEYS GetUserStatePut(ui/GetActionValues) +Dispatch HANDLE[1] -> IN GetUserState +GetUserStatePut VALUES[0] -> USER SaveRuntime(ui/StoreRemoteRuntime) +GetUserStatePut OUT -> IN SaveRuntime +SaveRuntime OUT -> IN RuntimeSaveAction +SaveRuntime ERROR -> IN RegistryErrorAction