1 package org.onap.vid.job.command;
3 import com.google.common.collect.ImmutableMap;
4 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
5 import org.onap.vid.asdc.AsdcCatalogException;
6 import org.onap.vid.job.*;
7 import org.onap.vid.job.command.CommandParentData.CommandDataKey;
8 import org.onap.vid.job.impl.JobSharedData;
9 import org.onap.vid.model.serviceInstantiation.VfModule;
10 import org.onap.vid.model.serviceInstantiation.Vnf;
11 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
12 import org.springframework.context.annotation.Scope;
13 import org.springframework.stereotype.Component;
15 import javax.inject.Inject;
16 import java.util.ArrayList;
17 import java.util.List;
19 import java.util.stream.Collectors;
22 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
23 public class WatchingCommandBaseModule extends BaseWatchingCommand {
25 protected JobsBrokerService jobsBrokerService;
28 protected JobAdapter jobAdapter;
29 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(WatchingCommandBaseModule.class);
31 public WatchingCommandBaseModule(
32 JobSharedData sharedData,
33 List<String> childrenJobsIds,
35 CommandParentData commandParentData) {
36 super(sharedData, childrenJobsIds, isService);
37 this.commandParentData = commandParentData;
40 public WatchingCommandBaseModule() {
45 protected NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus) {
47 if (cumulativeJobsStatus== Job.JobStatus.IN_PROGRESS) {
48 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this);
51 if(cumulativeJobsStatus==Job.JobStatus.FAILED || cumulativeJobsStatus==Job.JobStatus.COMPLETED_WITH_ERRORS){
52 return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS);
54 Vnf request = (Vnf) getSharedData().getRequest();
55 Map<String, Object> dataForChild = buildDataForChild();
56 //Create non-base Volume groups job
57 List<VfModule> vfModules = request.getVfModules().values().stream().flatMap(vfKey -> vfKey.values().stream()).collect(Collectors.toList());
58 List<String> vgNonBaseJobs = new ArrayList<>();
59 for( VfModule vfModule : vfModules){
61 if(!commandUtils.isVfModuleBaseModule(commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO).getModelVersionId(), vfModule.getModelInfo().getModelVersionId())) {
62 vgNonBaseJobs.add(jobsBrokerService.add(
63 jobAdapter.createChildJob(JobType.VolumeGroupInstantiation, Job.JobStatus.CREATING, vfModule, getSharedData(), dataForChild)).toString());
65 } catch (AsdcCatalogException e) {
66 LOG.error("Failed to retrieve service definitions from SDC, for VfModule is BaseModule. Error: "+e.getMessage() , e);
67 return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS);
70 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vgNonBaseJobs, false));
74 public WatchingCommandBaseModule init(JobSharedData sharedData, Map<String, Object> commandData) {
75 super.init(sharedData, commandData);
76 commandParentData.initParentData(commandData);
80 protected Map<String, Object> buildDataForChild() {
81 return commandParentData.getParentData();
85 public Map<String, Object> getData() {
86 return ImmutableMap.<String, Object>builder()
87 .putAll(super.getData())
88 .putAll(commandParentData.getParentData())