Skip to content

Commit

Permalink
WIP #1186 Moved backend whitelisting to execution
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Sep 17, 2019
1 parent 8b7c468 commit ea1c7e5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
4 changes: 2 additions & 2 deletions config/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
}
]
},
"ExecuteJob": {
"executionBackend": "GME"
"Compute": {
"backends": ["local", "gme"]
}
}
51 changes: 44 additions & 7 deletions src/common/execution/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
/*globals define, requirejs */
define([
'./backends/GME',
'./backends/Local'
'underscore',
'module',
], function(
GME,
Local
_,
module
) {
// FIXME: Add more intelligent interface here...
// - fetch a given backend and configure
return Local;
const Execution = {};
const BACKENDS = ['gme', 'local'];

Execution.getBackend = function(name) {
name = name.toLowerCase();
if (!BACKENDS.includes(name)) {
throw new Error(`Execution backend not found: ${name}`);
}

const relativePath = `backends/${name}/index`;
const Backend = requirejs(`deepforge/execution/${relativePath}`);
return new Backend();
};

Execution.getAvailableBackends = function() {
const settings = {backends: ['local', 'gme']};
if (require.isBrowser) {
const ComponentSettings = requirejs('js/Utils/ComponentSettings');
ComponentSettings.resolveWithWebGMEGlobal(
settings,
this.getComponentId()
);
} else { // Running in NodeJS
const path = require('path');
const dirname = path.dirname(module.uri);
const deploymentSettings = JSON.parse(requirejs('text!' + dirname + '/../../../config/components.json'));
_.extend(settings, deploymentSettings[this.getComponentId()]);
}

return settings.backends;
};

Execution.getComponentId = function() {
return 'Compute';
};

//Execution.getProjectRoot = function() {

return Execution;
});
17 changes: 2 additions & 15 deletions src/plugins/ExecuteJob/ExecuteJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,8 @@ define([
this.pulseClient = new ExecPulseClient(params);
this._execHashToJobNode = {};

this.settings = _.extend({}, DEFAULT_SETTINGS);
if (require.isBrowser) {
const ComponentSettings = requirejs('js/Utils/ComponentSettings');
ComponentSettings.resolveWithWebGMEGlobal(
this.settings,
this.getComponentId()
);
} else { // Running in NodeJS
const path = require('path');
const dirname = path.dirname(module.uri);
const deploymentSettings = JSON.parse(requirejs('text!' + dirname + '/../../../config/components.json'));
_.extend(this.settings, deploymentSettings[this.getComponentId()]);
}

const backend = Execution.getBackend(this.settings.executionBackend);
const name = Execution.getAvailableBackends()[0]; // FIXME: enable the user to select one
const backend = Execution.getBackend(name);
this.executor = backend.getClient(this.logger);
this.executor.on(
'data',
Expand Down

0 comments on commit ea1c7e5

Please sign in to comment.