1 package org.onap.vid.job.command;
3 import org.apache.commons.collections.MapUtils;
4 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
5 import org.onap.vid.asdc.AsdcCatalogException;
6 import org.onap.vid.job.Job;
7 import org.onap.vid.job.JobType;
8 import org.onap.vid.job.NextCommand;
9 import org.onap.vid.job.command.CommandParentData.CommandDataKey;
10 import org.onap.vid.job.impl.JobSharedData;
11 import org.onap.vid.model.serviceInstantiation.BaseResource;
12 import org.onap.vid.model.serviceInstantiation.VfModule;
13 import org.onap.vid.model.serviceInstantiation.Vnf;
14 import org.onap.vid.properties.Features;
15 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
16 import org.springframework.context.annotation.Scope;
17 import org.springframework.stereotype.Component;
19 import java.util.ArrayList;
20 import java.util.List;
22 import java.util.stream.Collectors;
25 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
26 public class VnfInProgressStatusCommand extends ResourceWithChildrenInProgressCommand {
27 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VnfInProgressStatusCommand.class);
29 public VnfInProgressStatusCommand(JobSharedData sharedData,
32 CommandParentData commandParentData) {
33 super(sharedData, requestId, instanceId, commandParentData);
36 public VnfInProgressStatusCommand() {
40 protected NextCommand processJobStatus(Job.JobStatus jobStatus) {
41 if (jobStatus == Job.JobStatus.FAILED) {
42 return new NextCommand(jobStatus);
45 Vnf request = (Vnf) getSharedData().getRequest();
47 if (isNeedToCreateChildJobs(jobStatus, request)) {
48 commandParentData.addInstanceId(CommandDataKey.VNF_INSTANCE_ID, instanceId);
49 commandParentData.addModelInfo(CommandDataKey.VNF_MODEL_INFO, request.getModelInfo());
50 //create volume group of base module job
51 Map<String, Object> dataForChild = buildDataForChild();
52 List<VfModule> vfModules = request.getVfModules().values().stream().flatMap(vfKey -> vfKey.values().stream()).collect(Collectors.toList());
53 List<String> vgBaseJobs = new ArrayList<>();
54 for( VfModule vfModule : vfModules){
56 if(commandUtils.isVfModuleBaseModule(commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO).getModelVersionId(), vfModule.getModelInfo().getModelVersionId())) {
57 vgBaseJobs.add(jobsBrokerService.add(
58 jobAdapter.createChildJob(JobType.VolumeGroupInstantiation, Job.JobStatus.CREATING, vfModule, getSharedData(), dataForChild)).toString());
60 } catch (AsdcCatalogException e) {
61 LOG.error("Failed to retrieve service definitions from SDC, for VfModule is BaseModule. Error: "+e.getMessage() , e);
62 return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS);
65 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommandBaseModule(getSharedData(), vgBaseJobs, false, commandParentData));
68 //in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress
69 if (jobStatus == Job.JobStatus.PAUSE) {
70 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this);
72 return new NextCommand(jobStatus, this);
76 protected boolean isNeedToCreateChildJobs(Job.JobStatus jobStatus, BaseResource request) {
77 return featureManager.isActive(Features.FLAG_ASYNC_ALACARTE_VFMODULE) &&
78 jobStatus == Job.JobStatus.COMPLETED &&
79 MapUtils.isNotEmpty(((Vnf)request).getVfModules());
84 protected ExpiryChecker getExpiryChecker() {