|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import makeArvadosRequest from 'make-arvados-request';
- import wbUuidsToCwl from 'wb-uuids-to-cwl';
-
- function wbParseWorkflowInputs(workflowDefinition, userInputs, errors) {
- // first see if all inputs are parseable
- const inputs = {};
-
- const main = workflowDefinition['$graph'].find(a => (a.id === '#main'));
-
- for (let k in userInputs) {
- try {
- let val = jsyaml.safeLoad(userInputs[k]);
- val = wbUuidsToCwl(val);
- k = k.split('/').slice(1).join('/');
- inputs[k] = (val === undefined ? null : val);
- } catch (exc) {
- errors.push('Error parsing ' + k + ': ' + exc.message);
- }
- }
-
- return inputs;
- }
-
- function ensureSubProject(arvHost, arvToken, projectUuid) {
- const filters = [
- [ 'group_class', '=', 'project' ],
- [ 'owner_uuid', '=', projectUuid ],
- [ 'properties.type', '=', 'daily_process_subproject_container' ]
- ];
-
- let prom = makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/groups?filters=' + encodeURIComponent(JSON.stringify(filters)));
-
- prom = prom.then(xhr => {
- if (xhr.response.items.length === 0) {
- let prom_1 = new Promise(accept => accept());
- prom_1 = prom_1.then(() => makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/groups', { method: 'POST',
- data: JSON.stringify({ owner_uuid: projectUuid,
- group_class: 'project',
- name: 'Container for daily sub-projects for processes',
- properties: { type: 'daily_process_subproject_container' } }) }));
- prom_1 = prom_1.then(xhr_1 => xhr_1.response.uuid);
- return prom_1;
- }
- return xhr.response.items[0].uuid;
- });
-
- let date = new Date();
- date = (date.getYear() + 1900) + '-' +
- ('00' + (date.getMonth() + 1)).slice(-2) + '-' +
- ('00' + date.getDate()).slice(-2);
-
- let containerUuid;
-
- prom = prom.then(uuid => {
- containerUuid = uuid;
-
- const filters_1 = [
- [ 'group_class', '=', 'project'],
- [ 'owner_uuid', '=', containerUuid ],
- [ 'properties.type', '=', 'daily_process_subproject' ],
- [ 'properties.date', '=', date ]
- ];
-
- return makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/groups?filters=' + encodeURIComponent(JSON.stringify(filters_1)));
- });
-
- prom = prom.then(xhr => {
- if (xhr.response.items.length === 0) {
- let prom_1 = new Promise(accept => accept());
- prom_1 = prom_1.then(() => makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/groups', { method: 'POST',
- data: JSON.stringify({ owner_uuid: containerUuid,
- group_class: 'project',
- name: 'Daily processes sub-project for ' + date,
- properties: { type: 'daily_process_subproject', date } }) }));
- prom_1 = prom_1.then(xhr => xhr.response.uuid);
- return prom_1;
- }
- return xhr.response.items[0].uuid;
- });
- return prom;
- }
-
- // params:
- // arvHost, arvToken, inputs,
- // projectUuid, workflowDefinition, workflowUuid
- // processName, processDescription, placeInSubProject
- function wbSubmitContainerRequest(params) {
-
- const { workflowDefinition, workflowUuid,
- processName, processDescription, inputs,
- arvHost, arvToken,
- placeInSubProject } = params;
-
- let { projectUuid } = params;
-
- let prom = new Promise(accept => accept());
-
- if (placeInSubProject) {
- prom = prom.then(() => ensureSubProject(arvHost, arvToken, projectUuid));
- prom = prom.then(subProjUuid => (projectUuid = subProjUuid));
- }
-
- prom = prom.then(() => {
- // prepare a request
- const req = {
- name: processName,
- description: processDescription,
- owner_uuid: projectUuid,
- container_image: 'arvados/jobs',
- properties: {
- template_uuid: workflowUuid
- },
- runtime_constraints: {
- API: true,
- vcpus: 1,
- ram: 1073741824
- },
- cwd: '/var/spool/cwl',
- command: [
- 'arvados-cwl-runner',
- '--local',
- '--api=containers',
- '--project-uuid=' + projectUuid,
- '--collection-cache-size=256',
- '/var/lib/cwl/workflow.json#main',
- '/var/lib/cwl/cwl.input.json'],
- output_path: '/var/spool/cwl',
- priority: 1,
- state: 'Committed',
- mounts: {
- 'stdout': {
- kind: 'file',
- path: '/var/spool/cwl/cwl.output.json'
- },
- '/var/spool/cwl': {
- kind: 'collection',
- writable: true
- },
- '/var/lib/cwl/workflow.json': {
- kind: 'json',
- content: workflowDefinition
- },
- '/var/lib/cwl/cwl.input.json': {
- kind: 'json',
- content: inputs
- }
- }
- };
-
- return makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/container_requests',
- { method: 'POST', data: JSON.stringify(req) });
- });
-
- return prom;
- }
-
- export { wbParseWorkflowInputs, wbSubmitContainerRequest };
|