Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config dialog for selecting compute backend to use. Closes #1232 #1244

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions src/common/viz/Execute.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/* globals define */
/* globals define, WebGMEGlobal */
// Mixin for executing jobs and pipelines
define([
'q',
'deepforge/compute/index',
'deepforge/viz/ConfigDialog',
'deepforge/api/ExecPulseClient',
'deepforge/api/JobOriginClient',
'deepforge/Constants',
'panel/FloatingActionButton/styles/Materialize'
'panel/FloatingActionButton/styles/Materialize',
], function(
Q,
Compute,
ConfigDialog,
ExecPulseClient,
JobOriginClient,
CONSTANTS,
Materialize
Materialize,
) {

var Execute = function(client, logger) {
Expand All @@ -24,28 +28,52 @@ define([
};

Execute.prototype.executeJob = function(node) {
return this.runExecutionPlugin('ExecuteJob', {node: node});
return this.runExecutionPlugin('ExecuteJob', node);
};

Execute.prototype.executePipeline = function(node) {
return this.runExecutionPlugin('ExecutePipeline', {node: node});
return this.runExecutionPlugin('ExecutePipeline', node);
};

Execute.prototype.runExecutionPlugin = function(pluginId, activeNode) {
Execute.prototype.runExecutionPlugin = async function(pluginId, activeNode) {
var deferred = Q.defer(),
context = this.client.getCurrentPluginContext(pluginId),
node = activeNode || this.client.getNode(this._currentNodeId);

// Set the activeNode
context.managerConfig.namespace = 'pipeline';
context.managerConfig.activeNode = node.getId();

if (this.client.getBranchStatus() !== this.client.CONSTANTS.BRANCH_STATUS.SYNC) {

Materialize.toast('Cannot execute operations when client is out-of-sync', 2000);
return;
}

context.managerConfig.namespace = 'pipeline';
context.managerConfig.activeNode = node.getId();

const configDialog = new ConfigDialog(this.client, this._currentNodeId);
const metadata = JSON.parse(JSON.stringify(WebGMEGlobal.allPluginsMetadata[pluginId]));
metadata.configStructure.unshift({
name: 'basicHeader',
displayName: 'Basic Options',
valueType: 'section'
});
metadata.configStructure.push({
name: 'computeHeader',
displayName: 'Compute Options',
valueType: 'section'
});
metadata.configStructure.push({
name: 'compute',
displayName: 'Compute',
description: 'Computational resources to use for execution.',
valueType: 'dict',
value: Compute.getBackend(Compute.getAvailableBackends()[0]).name,
valueItems: Compute.getAvailableBackends()
.map(id => Compute.getMetadata(id)),
});

const allConfigs = await configDialog.show(metadata);
context.pluginConfig = allConfigs[pluginId];

const onPluginInitiated = (sender, event) => {
this.client.removeEventListener(this._client.CONSTANTS.PLUGIN_INITIATED, onPluginInitiated);
this.client.setAttribute(node.getId(), 'executionId', event.executionId);
Expand Down
64 changes: 34 additions & 30 deletions src/plugins/ExecuteJob/ExecuteJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ define([
this.logManager = null;
};

// TODO: Update plugin metadata for the compute options
ExecuteJob.metadata = pluginMetadata;
ExecuteJob.HEARTBEAT_INTERVAL = 2500;

Expand All @@ -95,35 +94,7 @@ define([
this.pulseClient = new ExecPulseClient(params);
this._execHashToJobNode = {};

const name = Compute.getAvailableBackends()[0]; // FIXME: enable the user to select one
const backend = Compute.getBackend(name);
this.compute = backend.getClient(this.logger);
this.compute.on(
'data',
(id, data) => {
const job = this.getNodeForJobId(id);
this.onConsoleOutput(job, data.toString());
}
);

this.compute.on('update', (jobId, status) => {
try {
this.onUpdate(jobId, status);
} catch (err) {
this.logger.error(`Error when processing operation update: ${err}`);
}
});

this.compute.on('end',
(id, info) => {
try {
this.onOperationEnd(id);
} catch (err) {
this.logger.error(`Error when processing operation end: ${err}`);
}
}
);

this.compute = null;
return result;
};

Expand Down Expand Up @@ -158,6 +129,7 @@ define([
this.currentForkName = null;
this.forkNameBase = this.getAttribute(this.activeNode, 'name');
const isResuming = await this.isResuming(this.activeNode);
this.configureCompute();
await this.prepare(isResuming);

if (isResuming) {
Expand All @@ -179,6 +151,38 @@ define([
}
};

ExecuteJob.prototype.configureCompute = async function () {
const config = this.getCurrentConfig();
const backend = Compute.getBackend(config.compute.id);
this.compute = backend.getClient(this.logger, config.compute.config);
this.compute.on(
'data',
(id, data) => {
const job = this.getNodeForJobId(id);
this.onConsoleOutput(job, data.toString());
}
);

this.compute.on('update', (jobId, status) => {
try {
this.onUpdate(jobId, status);
} catch (err) {
this.logger.error(`Error when processing operation update: ${err}`);
}
});

this.compute.on('end',
(id, info) => {
try {
this.onOperationEnd(id);
} catch (err) {
this.logger.error(`Error when processing operation end: ${err}`);
}
}
);
};


ExecuteJob.prototype.getJobId = function (node) {
return JSON.parse(this.getAttribute(node, 'jobInfo')).hash;
};
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/ExecutePipeline/ExecutePipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ define([
*/
ExecutePipeline.prototype.main = async function (callback) {

this.initRun();
if (!this.META.Pipeline) {
return callback(new Error('Incorrect namespace. Expected to be executed in the "pipeline" namespace'));
}

this.configureCompute();
this.initRun();

if (this.core.isTypeOf(this.activeNode, this.META.Pipeline)) {
// If starting with a pipeline, we will create an Execution first
const execNode = await this.createExecution(this.activeNode);
Expand Down
8 changes: 8 additions & 0 deletions src/visualizers/panels/ForgeActionButton/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ define([
Materialize.toast(`Export failed: ${err}`, 4000);
});
}
},
{
name: 'Execute Pipeline',
icon: 'play_arrow',
priority: 1,
action: function() {
return this.executePipeline();
}
}
],
MyUtilities_META: [
Expand Down