2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.job.command;
23 import com.google.common.collect.ImmutableMap;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.onap.vid.asdc.AsdcCatalogException;
26 import org.onap.vid.job.*;
27 import org.onap.vid.job.command.CommandParentData.CommandDataKey;
28 import org.onap.vid.job.impl.JobSharedData;
29 import org.onap.vid.model.serviceInstantiation.VfModule;
30 import org.onap.vid.model.serviceInstantiation.Vnf;
31 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
32 import org.springframework.context.annotation.Scope;
33 import org.springframework.stereotype.Component;
35 import javax.inject.Inject;
36 import java.util.ArrayList;
37 import java.util.List;
39 import java.util.stream.Collectors;
42 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
43 public class WatchingCommandBaseModule extends BaseWatchingCommand {
45 protected JobsBrokerService jobsBrokerService;
48 protected JobAdapter jobAdapter;
49 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(WatchingCommandBaseModule.class);
51 public WatchingCommandBaseModule(
52 JobSharedData sharedData,
53 List<String> childrenJobsIds,
55 CommandParentData commandParentData) {
56 super(sharedData, childrenJobsIds, isService);
57 this.commandParentData = commandParentData;
60 public WatchingCommandBaseModule() {
65 protected NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus) {
67 if (cumulativeJobsStatus== Job.JobStatus.IN_PROGRESS) {
68 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this);
71 if(cumulativeJobsStatus==Job.JobStatus.FAILED || cumulativeJobsStatus==Job.JobStatus.COMPLETED_WITH_ERRORS){
72 return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS);
74 Vnf request = (Vnf) getSharedData().getRequest();
75 Map<String, Object> dataForChild = buildDataForChild();
76 //Create non-base Volume groups job
77 List<VfModule> vfModules = request.getVfModules().values().stream().flatMap(vfKey -> vfKey.values().stream()).collect(Collectors.toList());
78 List<String> vgNonBaseJobs = new ArrayList<>();
79 for( VfModule vfModule : vfModules){
81 if(!commandUtils.isVfModuleBaseModule(commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO).getModelVersionId(), vfModule.getModelInfo().getModelVersionId())) {
82 vgNonBaseJobs.add(jobsBrokerService.add(
83 jobAdapter.createChildJob(JobType.VolumeGroupInstantiation, Job.JobStatus.CREATING, vfModule, getSharedData(), dataForChild)).toString());
85 } catch (AsdcCatalogException e) {
86 LOG.error("Failed to retrieve service definitions from SDC, for VfModule is BaseModule. Error: "+e.getMessage() , e);
87 return new NextCommand(Job.JobStatus.COMPLETED_WITH_ERRORS);
90 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vgNonBaseJobs, false));
94 public WatchingCommandBaseModule init(JobSharedData sharedData, Map<String, Object> commandData) {
95 super.init(sharedData, commandData);
96 commandParentData.initParentData(commandData);
100 protected Map<String, Object> buildDataForChild() {
101 return commandParentData.getParentData();
105 public Map<String, Object> getData() {
106 return ImmutableMap.<String, Object>builder()
107 .putAll(super.getData())
108 .putAll(commandParentData.getParentData())