in components/vam-api/packages/vam-services/lib/appstream/appstream-service.js [367:493]
async createWorkflow(
requestContext,
instanceType,
copiedAppKeys,
imageName,
imageBuilderID,
dapEnabled,
snapshotImage,
deleteImageBuilder,
appstreamImageArn,
) {
const destBucket = this.settings.get(settingKeys.installerHostWorkBucketName);
const [s3Service, stepTemplateService, workflowTriggerService, workflowDraftService] = await this.service([
's3Service',
'stepTemplateService',
'workflowTriggerService',
'workflowDraftService',
]);
const workflowIdRaw = `wf-${imageName}`;
const workflowId = this.getWorkflowId(imageName);
const prepareStepTpl = (
await stepTemplateService.listVersions(requestContext, { id: 'st-prepare-image-builder-environment' })
)[0];
const launchStepTpl = (
await stepTemplateService.listVersions(requestContext, { id: 'st-launch-image-builder' })
)[0];
const dyncatStepTpl = (
await stepTemplateService.listVersions(requestContext, { id: 'st-install-dynamic-catalog-script' })
)[0];
const waitStepTpl = (
await stepTemplateService.listVersions(requestContext, { id: 'st-wait-for-image-builder' })
)[0];
const cleanupStepTpl = (await stepTemplateService.listVersions(requestContext, { id: 'st-cleanup' }))[0];
await workflowDraftService.createDraft(requestContext, {
workflowId: workflowIdRaw,
templateId: 'wt-empty',
});
let stepNum = '';
const createStep = (tpl, configs = {}) => {
stepNum += 1;
return {
id: `wf-step_1_1499799482398_206_${stepNum}`,
stepTemplateId: tpl.id,
stepTemplateVer: tpl.v,
title: tpl.title,
desc: tpl.desc,
skippable: true,
configs,
};
};
const prepareStep = createStep(prepareStepTpl, {});
const launchStep = createStep(launchStepTpl, { dapEnabled, instanceType, appstreamImageArn });
const dyncatStep = createStep(dyncatStepTpl, { imageBuilderID });
const waitStep = createStep(waitStepTpl, { dapEnabled, imageBuilderID });
const cleanupStep = createStep(cleanupStepTpl, { imageBuilderID });
const applications = await Promise.all(copiedAppKeys.map(k => applicationFromInfo(s3Service, destBucket, k)));
const executeSteps = await Promise.all(
applications.map(async application => {
const step = await executeStep(requestContext, application, this, s3Service, dapEnabled, imageBuilderID);
return step;
}),
);
const selectedSteps = [];
if (!imageBuilderID || imageBuilderID.length === 0) {
selectedSteps.push(prepareStep);
selectedSteps.push(launchStep);
}
selectedSteps.push(...executeSteps);
// regardless of user preference on dapEnabled, we
// need to install the dyncat scripts if the environment is ad-joined.
// this is because we're going to create an implicit dynamic catalogue.
const adJoined = this.settings.get(settingKeys.adJoined);
if (adJoined) {
selectedSteps.push(dyncatStep);
}
if (snapshotImage) {
selectedSteps.push(waitStep);
}
if (deleteImageBuilder) {
selectedSteps.push(cleanupStep);
}
const by = _.get(requestContext, 'principalIdentifier.uid');
const updateParams = {
id: `${by}_${workflowId}_0`,
rev: 0,
workflow: {
id: workflowId,
title: imageName,
desc: `Installation of ${applications.map(a => a.applicationDisplayName).join(', ')}`,
v: 1,
rev: 0,
workflowTemplateId: 'wt-empty',
workflowTemplateVer: 1,
selectedSteps,
runSpec: { size: 'small', target: 'stepFunctions' },
},
};
await workflowDraftService.updateDraft(requestContext, updateParams);
updateParams.rev += 1;
await workflowDraftService.publishDraft(requestContext, updateParams);
const trigger = await workflowTriggerService.triggerWorkflow(
requestContext,
{
workflowId,
workflowVer: 1,
status: 'in_progress',
},
{},
);
return { workflowId, trigger };
}