Skip to content

Commit

Permalink
Save runtime to registry when adding manually, refs noflo/noflo-nodej…
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed May 9, 2017
1 parent f7cefdb commit 74e8157
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
33 changes: 33 additions & 0 deletions components/StoreRemoteRuntime.coffee
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion elements/noflo-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,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);
Expand Down
14 changes: 11 additions & 3 deletions graphs/RegistryMiddleware.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 74e8157

Please sign in to comment.