diff --git a/src/common/viz/Execute.js b/src/common/viz/Execute.js index 11e75af0d..919a0cee8 100644 --- a/src/common/viz/Execute.js +++ b/src/common/viz/Execute.js @@ -1,15 +1,13 @@ -/* globals define, WebGMEGlobal */ +/* globals define */ // Mixin for executing jobs and pipelines define([ 'q', - 'executor/ExecutorClient', 'deepforge/api/ExecPulseClient', 'deepforge/api/JobOriginClient', 'deepforge/Constants', 'panel/FloatingActionButton/styles/Materialize' ], function( Q, - ExecutorClient, ExecPulseClient, JobOriginClient, CONSTANTS, @@ -22,11 +20,6 @@ define([ this.pulseClient = new ExecPulseClient({ logger: this.logger }); - this._executor = new ExecutorClient({ - logger: this.logger.fork('ExecutorClient'), - serverPort: WebGMEGlobal.gmeConfig.server.port, - httpsecure: window.location.protocol === 'https:' - }); this.originManager = new JobOriginClient({logger: this.logger}); }; @@ -39,9 +32,11 @@ define([ }; Execute.prototype.runExecutionPlugin = function(pluginId, opts) { - var context = this.client.getCurrentPluginContext(pluginId), + var deferred = Q.defer(), + context = this.client.getCurrentPluginContext(pluginId), node = opts.node || this.client.getNode(this._currentNodeId), name = node.getAttribute('name'), + onPluginInitiated, method; // Set the activeNode @@ -56,6 +51,17 @@ define([ return; } + onPluginInitiated = (sender, event) => { + this.client.removeEventListener(this._client.CONSTANTS.PLUGIN_INITIATED, onPluginInitiated); + this.client.setAttribute(node.getId(), 'executionId', event.executionId); + deferred.resolve(event.executionId); + }; + + this.client.addEventListener( + this.client.CONSTANTS.PLUGIN_INITIATED, + onPluginInitiated + ); + this.client[method](pluginId, context, (err, result) => { var msg = err ? `${name} failed!` : `${name} executed successfully!`, duration = err ? 4000 : 2000; @@ -68,76 +74,15 @@ define([ Materialize.toast(msg, duration); }); + + return deferred.promise; }; Execute.prototype.isRunning = function(node) { - var baseId, - base, - type; - node = node || this.client.getNode(this._currentNodeId); - baseId = node.getBaseId(); - base = this.client.getNode(baseId); - type = base.getAttribute('name'); - - if (type === 'Execution') { - return node.getAttribute('status') === 'running'; - } else if (type === 'Job') { - return this.isRunningJob(node); - } - return false; - }; - - Execute.prototype.isRunningJob = function(job) { - var status = job.getAttribute('status'); - - return (status === 'running' || status === 'pending') && - job.getAttribute('secret') && job.getAttribute('jobId'); - }; - - Execute.prototype.silentStopJob = function(job) { - var jobHash, - secret; - - job = job || this.client.getNode(this._currentNodeId); - jobHash = job.getAttribute('jobId'); - secret = job.getAttribute('secret'); - if (!jobHash || !secret) { - this.logger.error('Cannot stop job. Missing jobHash or secret'); - return; - } - - return this._executor.cancelJob(jobHash, secret) - .then(() => this.logger.info(`${jobHash} has been cancelled!`)) - .fail(err => this.logger.error(`Job cancel failed: ${err}`)); - }; - - Execute.prototype._setJobStopped = function(jobId, silent) { - if (!silent) { - var name = this.client.getNode(jobId).getAttribute('name'); - this.client.startTransaction(`Stopping "${name}" job`); - } - - this.client.delAttribute(jobId, 'jobId'); - this.client.delAttribute(jobId, 'secret'); - this.client.setAttribute(jobId, 'status', 'canceled'); - - if (!silent) { - this.client.completeTransaction(); - } + return node.getAttribute('executionId'); }; - Execute.prototype.stopJob = function(job, silent) { - var jobId; - - job = job || this.client.getNode(this._currentNodeId); - jobId = job.getId(); - - this.silentStopJob(job); - this._setJobStopped(jobId, silent); - }; - - Execute.prototype.loadChildren = function(id) { var deferred = Q.defer(), execNode = this.client.getNode(id || this._currentNodeId), @@ -163,49 +108,26 @@ define([ return deferred.promise; }; - Execute.prototype.stopExecution = function(id, inTransaction) { - var execNode = this.client.getNode(id || this._currentNodeId); - - return this.loadChildren(id) - .then(() => this._stopExecution(execNode, inTransaction)); - }; - - Execute.prototype.silentStopExecution = function(id) { - var execNode = this.client.getNode(id || this._currentNodeId); + Execute.prototype.stopExecution = function(nodeId=this._currentNodeId) { + const node = this.client.getNode(nodeId); + const base = this.client.getNode(node.getBaseId()); + const type = base.getAttribute('name'); - // Stop the execution w/o setting any attributes - return this.loadChildren(id) - .then(() => this._silentStopExecution(execNode)); - }; - - Execute.prototype._stopExecution = function(execNode, inTransaction) { - var msg = `Canceling ${execNode.getAttribute('name')} execution`, - jobIds; - - if (!inTransaction) { - this.client.startTransaction(msg); + let executionId = node.getAttribute('executionId'); + this.client.delAttribute(nodeId, 'executionId'); + if (type === 'Job' && !executionId) { + const execNode = this.client.getNode(node.getParentId()); + executionId = execNode.getAttribute('executionId'); + this.client.delAttribute(nodeId, 'executionId'); } - jobIds = this._silentStopExecution(execNode); - - this.client.setAttribute(execNode.getId(), 'status', 'canceled'); - jobIds.forEach(jobId => this._setJobStopped(jobId, true)); - - if (!inTransaction) { - this.client.completeTransaction(); + if (executionId) { + this.client.abortPlugin(executionId); + } else { + this.logger.warn(`Could not find execution ID for ${nodeId}`); } }; - Execute.prototype._silentStopExecution = function(execNode) { - var runningJobIds = execNode.getChildrenIds() - .map(id => this.client.getNode(id)) - .filter(job => this.isRunning(job)); // get running jobs - - runningJobIds.forEach(job => this.silentStopJob(job)); // stop them - - return runningJobIds; - }; - // Resuming Executions Execute.prototype.checkJobExecution= function (job) { var pipelineId = job.getParentId(), diff --git a/src/plugins/ExecuteJob/ExecuteJob.js b/src/plugins/ExecuteJob/ExecuteJob.js index 7048ef4a6..828ca67da 100644 --- a/src/plugins/ExecuteJob/ExecuteJob.js +++ b/src/plugins/ExecuteJob/ExecuteJob.js @@ -169,6 +169,10 @@ define([ .catch(err => this._callback(err, this.result)); }; + ExecuteJob.prototype.onAbort = function () { + this.canceled = true; + }; + ExecuteJob.prototype.checkExecutionEnv = function () { // Throw an exception if no resources this.logger.info(`Checking execution environment`); diff --git a/src/plugins/ExecuteJob/metadata.json b/src/plugins/ExecuteJob/metadata.json index 5520634de..299465bbd 100644 --- a/src/plugins/ExecuteJob/metadata.json +++ b/src/plugins/ExecuteJob/metadata.json @@ -10,5 +10,6 @@ "disableServerSideExecution": false, "disableBrowserSideExecution": false, "writeAccessRequired": false, + "canBeAborted": true, "configStructure": [] -} \ No newline at end of file +} diff --git a/src/plugins/ExecutePipeline/metadata.json b/src/plugins/ExecutePipeline/metadata.json index 4669fd5e1..a335bcd12 100644 --- a/src/plugins/ExecutePipeline/metadata.json +++ b/src/plugins/ExecutePipeline/metadata.json @@ -9,6 +9,7 @@ }, "disableServerSideExecution": false, "disableBrowserSideExecution": false, + "canBeAborted": true, "configStructure": [ { "name": "name", diff --git a/src/seeds/pipeline/pipeline.webgmex b/src/seeds/pipeline/pipeline.webgmex index 2e6599eaf..97df6856c 100644 Binary files a/src/seeds/pipeline/pipeline.webgmex and b/src/seeds/pipeline/pipeline.webgmex differ diff --git a/src/seeds/pipeline/version.txt b/src/seeds/pipeline/version.txt index 71172b43a..142464bf2 100644 --- a/src/seeds/pipeline/version.txt +++ b/src/seeds/pipeline/version.txt @@ -1 +1 @@ -0.10.1 \ No newline at end of file +0.11.0 \ No newline at end of file diff --git a/src/visualizers/panels/ForgeActionButton/Actions.js b/src/visualizers/panels/ForgeActionButton/Actions.js index 41de1e2fc..d11f77ed1 100644 --- a/src/visualizers/panels/ForgeActionButton/Actions.js +++ b/src/visualizers/panels/ForgeActionButton/Actions.js @@ -190,7 +190,7 @@ define([ return this.isRunning(); }, action: function() { - this.stopJob(); + this.stopExecution(); } } ], diff --git a/src/visualizers/panels/OperationCodeEditor/OperationCodeEditorControl.js b/src/visualizers/panels/OperationCodeEditor/OperationCodeEditorControl.js index 17de6ca0d..4e1fe0425 100644 --- a/src/visualizers/panels/OperationCodeEditor/OperationCodeEditorControl.js +++ b/src/visualizers/panels/OperationCodeEditor/OperationCodeEditorControl.js @@ -174,7 +174,7 @@ define([ if (this.currentJobId) { // Only if nested in a job job = this._client.getNode(this.currentJobId); if (this.isRunning(job)) { - this.stopJob(job); + this.stopExecution(this.currentJobId); } else { this.executeJob(job); }