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 preparation step to compute/storage config. Closes #2013 #2014

Merged
merged 1 commit into from
Mar 23, 2021
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
8 changes: 8 additions & 0 deletions src/common/compute/backends/ComputeBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define([
this.name = name;
this.dashboardPath = dashboard;
this.clientPath = client || './Client';
this._metadata = metadata;
}

getClient (logger, blobClient, config) {
Expand All @@ -30,6 +31,13 @@ define([
}
}

async prepareConfig (config) {
if (this._metadata.prepare) {
return await this._metadata.prepare(config);
}
return config;
}

require (path) { // helper for loading async
return new Promise((resolve, reject) =>
require([path], resolve, reject)
Expand Down
5 changes: 5 additions & 0 deletions src/common/compute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
return new ComputeBackend(id, metadata);
};

Compute.prepareConfig = async function(id, config) {
const backend = this.getBackend(id);
return backend.prepareConfig(config);
};

Compute.getMetadata = function(id) {
id = id.toLowerCase();
if (!COMPUTE_BACKENDS.includes(id)) {
Expand Down
8 changes: 8 additions & 0 deletions src/common/storage/backends/StorageBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ define([
this.id = id;
this.name = name;
this.clientPath = client || './Client';
this._metadata = metadata;
};

StorageBackend.prototype.getClient = async function(logger, config) {
const Client = await this.require(`deepforge/storage/backends/${this.id}/${this.clientPath}`);
return new Client(this.id, this.name, logger, config);
};

StorageBackend.prototype.prepareConfig = async function(config) {
if (this._metadata.prepare) {
return await this._metadata.prepare(config);
}
return config;
};

StorageBackend.prototype.require = function(path) { // helper for loading async
return new Promise((resolve, reject) =>
require([path], resolve, reject)
Expand Down
18 changes: 17 additions & 1 deletion src/common/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,29 @@ define([
return await backend.getClient(logger, config);
};

Storage.prepareConfig = async function(id, config) {
const backend = this.getBackend(id);
return backend.prepareConfig(config);
};

Storage.getClient = async function(id, logger, config={}) {
const backend = this.getBackend(id);
return await backend.getClient(logger, config);
};

function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj));
if (Array.isArray(obj)) {
return obj.slice();
} else if (typeof obj === 'object') {
const result = {};
Object.entries(obj).forEach(entry => {
const [key, val] = entry;
result[key] = deepCopy(val);
});
return result;
} else {
return obj;
}
}

return Storage;
Expand Down
20 changes: 20 additions & 0 deletions src/common/viz/Execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define([
'deepforge/api/JobOriginClient',
'deepforge/Constants',
'panel/FloatingActionButton/styles/Materialize',
'underscore',
], function(
Q,
Compute,
Expand All @@ -18,6 +19,7 @@ define([
JobOriginClient,
CONSTANTS,
Materialize,
_,
) {

var Execute = function(client, logger) {
Expand Down Expand Up @@ -152,6 +154,24 @@ define([
onPluginInitiated
);

// Prepare configurations
const inputPairs = await Promise.all(inputConfigs.map(async pair => {
const [node] = pair;
const {backend} = JSON.parse(node.getAttribute('data'));
const config = context.pluginConfig.inputs[node.getId()];
return [node.getId(), await Storage.prepareConfig(backend, config)];
}));
context.pluginConfig.inputs = _.object(inputPairs);
context.pluginConfig.storage.config = await Storage.prepareConfig(
context.pluginConfig.storage.id,
context.pluginConfig.storage.config
);
context.pluginConfig.compute.config = await Compute.prepareConfig(
context.pluginConfig.compute.id,
context.pluginConfig.compute.config
);

// Run plugins
this.client.runServerPlugin(pluginId, context, (err, result) => {
const name = node.getAttribute('name');
let msg = err ? `${name} failed!` : `${name} executed successfully!`,
Expand Down
3 changes: 2 additions & 1 deletion src/visualizers/panels/ArtifactIndex/ArtifactIndexControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ define([
if (deleteDataFromStorage) {
const dataInfo = this.getDataInfo(node);
const {backend} = dataInfo;
const storage = await Storage.getClient(backend, this._logger, config);
const preparedConfig = await Storage.prepareConfig(backend, config);
const storage = await Storage.getClient(backend, this._logger, preparedConfig);
await storage.deleteFile(dataInfo);
}

Expand Down