-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* WIP Add ImplicitOperation to metamodel * Update pipeline seed to 0.20.0 * remove auto-created operation in implicit operation * Record data provenance in Data nodes. Closes #1705 * Add ExecutionHelpers * WIP clean up debug logs and comments * Update tests * Update pipeline library in project seed * Update devProject seed * Update devProject * Update pipeline seed * Update project, devProject seeds * Include assets in devProject * Use all valid names - not just set values
- Loading branch information
Showing
12 changed files
with
218 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*globals define*/ | ||
define([ | ||
'underscore', | ||
], function( | ||
_, | ||
) { | ||
class ExecutionHelpers { | ||
constructor(core, rootNode) { | ||
this.core = core; | ||
this.rootNode = rootNode; | ||
} | ||
|
||
async snapshotOperation(node, dst, base) { | ||
// If we are making a snapshot, we should copy the base operation | ||
// and set the attributes, add the child nodes, etc | ||
if (!base) { | ||
base = this.core.getBase(node); | ||
} | ||
const snapshot = this.core.createNode({ | ||
base: base, | ||
parent: dst | ||
}); | ||
|
||
const names = this.core.getValidAttributeNames(node); | ||
const values = names.map(name => this.core.getAttribute(node, name)); | ||
names.forEach((name, i) => | ||
this.core.setAttribute(snapshot, name, values[i])); | ||
|
||
const ptrNames = this.core.getValidPointerNames(node) | ||
.filter(name => name !== 'base'); | ||
const setPointers = Promise.all( | ||
ptrNames.map(async name => { | ||
const targetPath = this.core.getPointerPath(node, name); | ||
if (targetPath) { | ||
const target = await this.core.loadByPath(this.rootNode, targetPath); | ||
const targetCopy = this.core.copyNode(target, snapshot); | ||
this.core.setPointer(snapshot, name, targetCopy); | ||
} | ||
}) | ||
); | ||
await setPointers; | ||
|
||
// Copy the data I/O | ||
const metaTypeComparator = (a, b) => { | ||
const aId = this.core.getPath(this.core.getMetaType(a)); | ||
const bId = this.core.getPath(this.core.getMetaType(b)); | ||
|
||
return aId < bId ? -1 : 1; | ||
}; | ||
|
||
const srcCntrs = (await this.core.loadChildren(node)) | ||
.sort(metaTypeComparator); | ||
const [dstInput, dstOutput] = (await this.core.loadChildren(snapshot)) | ||
.sort(metaTypeComparator); | ||
const [srcInputs, srcOutputs] = await Promise.all(srcCntrs.map(ctr => this.core.loadChildren(ctr))); | ||
const copies = srcInputs.map(n => this.core.copyNode(n, dstInput)); | ||
copies.push(...srcOutputs.map(n => this.shallowCopy(n, dstOutput))); | ||
const oldNewPairs = _.zip(srcInputs.concat(srcOutputs), copies); | ||
oldNewPairs.push([node, snapshot]); | ||
return {snapshot, pairs: oldNewPairs}; | ||
} | ||
|
||
shallowCopy (original, dst) { | ||
const attrNames = this.core.getAttributeNames(original); | ||
const copy = this.core.createNode({ | ||
base: this.core.getMetaType(original), | ||
parent: dst | ||
}); | ||
|
||
const values = attrNames.map(name => this.core.getAttribute(original, name)); | ||
attrNames.forEach((name, i) => | ||
this.core.setAttribute(copy, name, values[i])); | ||
|
||
return copy; | ||
} | ||
} | ||
|
||
return ExecutionHelpers; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.