IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wb-submit-container-request.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import makeArvadosRequest from 'make-arvados-request';
  2. import wbUuidsToCwl from 'wb-uuids-to-cwl';
  3. function wbParseWorkflowInputs(workflowDefinition, userInputs, errors) {
  4. // first see if all inputs are parseable
  5. const inputs = {};
  6. const main = workflowDefinition['$graph'].find(a => (a.id === '#main'));
  7. for (let k in userInputs) {
  8. try {
  9. let val = jsyaml.safeLoad(userInputs[k]);
  10. val = wbUuidsToCwl(val);
  11. k = k.split('/').slice(1).join('/');
  12. inputs[k] = (val === undefined ? null : val);
  13. } catch (exc) {
  14. errors.push('Error parsing ' + k + ': ' + exc.message);
  15. }
  16. }
  17. return inputs;
  18. }
  19. function ensureSubProject(arvHost, arvToken, projectUuid) {
  20. const filters = [
  21. [ 'group_class', '=', 'project' ],
  22. [ 'owner_uuid', '=', projectUuid ],
  23. [ 'properties.type', '=', 'daily_process_subproject_container' ]
  24. ];
  25. let prom = makeArvadosRequest(arvHost, arvToken,
  26. '/arvados/v1/groups?filters=' + encodeURIComponent(JSON.stringify(filters)));
  27. prom = prom.then(xhr => {
  28. if (xhr.response.items.length === 0) {
  29. let prom_1 = new Promise(accept => accept());
  30. prom_1 = prom_1.then(() => makeArvadosRequest(arvHost, arvToken,
  31. '/arvados/v1/groups', { method: 'POST',
  32. data: JSON.stringify({ owner_uuid: projectUuid,
  33. group_class: 'project',
  34. name: 'Container for daily sub-projects for processes',
  35. properties: { type: 'daily_process_subproject_container' } }) }));
  36. prom_1 = prom_1.then(xhr_1 => xhr_1.response.uuid);
  37. return prom_1;
  38. }
  39. return xhr.response.items[0].uuid;
  40. });
  41. let date = new Date();
  42. date = (date.getYear() + 1900) + '-' +
  43. ('00' + (date.getMonth() + 1)).slice(-2) + '-' +
  44. ('00' + date.getDate()).slice(-2);
  45. let containerUuid;
  46. prom = prom.then(uuid => {
  47. containerUuid = uuid;
  48. const filters_1 = [
  49. [ 'group_class', '=', 'project'],
  50. [ 'owner_uuid', '=', containerUuid ],
  51. [ 'properties.type', '=', 'daily_process_subproject' ],
  52. [ 'properties.date', '=', date ]
  53. ];
  54. return makeArvadosRequest(arvHost, arvToken,
  55. '/arvados/v1/groups?filters=' + encodeURIComponent(JSON.stringify(filters_1)));
  56. });
  57. prom = prom.then(xhr => {
  58. if (xhr.response.items.length === 0) {
  59. let prom_1 = new Promise(accept => accept());
  60. prom_1 = prom_1.then(() => makeArvadosRequest(arvHost, arvToken,
  61. '/arvados/v1/groups', { method: 'POST',
  62. data: JSON.stringify({ owner_uuid: containerUuid,
  63. group_class: 'project',
  64. name: 'Daily processes sub-project for ' + date,
  65. properties: { type: 'daily_process_subproject', date } }) }));
  66. prom_1 = prom_1.then(xhr => xhr.response.uuid);
  67. return prom_1;
  68. }
  69. return xhr.response.items[0].uuid;
  70. });
  71. return prom;
  72. }
  73. // params:
  74. // arvHost, arvToken, inputs,
  75. // projectUuid, workflowDefinition, workflowUuid
  76. // processName, processDescription, placeInSubProject
  77. function wbSubmitContainerRequest(params) {
  78. const { workflowDefinition, workflowUuid,
  79. processName, processDescription, inputs,
  80. arvHost, arvToken,
  81. placeInSubProject } = params;
  82. let { projectUuid } = params;
  83. let prom = new Promise(accept => accept());
  84. if (placeInSubProject) {
  85. prom = prom.then(() => ensureSubProject(arvHost, arvToken, projectUuid));
  86. prom = prom.then(subProjUuid => (projectUuid = subProjUuid));
  87. }
  88. prom = prom.then(() => {
  89. // prepare a request
  90. const req = {
  91. name: processName,
  92. description: processDescription,
  93. owner_uuid: projectUuid,
  94. container_image: 'arvados/jobs',
  95. properties: {
  96. template_uuid: workflowUuid
  97. },
  98. runtime_constraints: {
  99. API: true,
  100. vcpus: 1,
  101. ram: 1073741824
  102. },
  103. cwd: '/var/spool/cwl',
  104. command: [
  105. 'arvados-cwl-runner',
  106. '--local',
  107. '--api=containers',
  108. '--project-uuid=' + projectUuid,
  109. '--collection-cache-size=256',
  110. '/var/lib/cwl/workflow.json#main',
  111. '/var/lib/cwl/cwl.input.json'],
  112. output_path: '/var/spool/cwl',
  113. priority: 1,
  114. state: 'Committed',
  115. mounts: {
  116. 'stdout': {
  117. kind: 'file',
  118. path: '/var/spool/cwl/cwl.output.json'
  119. },
  120. '/var/spool/cwl': {
  121. kind: 'collection',
  122. writable: true
  123. },
  124. '/var/lib/cwl/workflow.json': {
  125. kind: 'json',
  126. content: workflowDefinition
  127. },
  128. '/var/lib/cwl/cwl.input.json': {
  129. kind: 'json',
  130. content: inputs
  131. }
  132. }
  133. };
  134. return makeArvadosRequest(arvHost, arvToken,
  135. '/arvados/v1/container_requests',
  136. { method: 'POST', data: JSON.stringify(req) });
  137. });
  138. return prom;
  139. }
  140. export { wbParseWorkflowInputs, wbSubmitContainerRequest };