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 org.apache.commons.collections.MapUtils;
24 import org.onap.vid.job.Job;
25 import org.onap.vid.job.Job.JobStatus;
26 import org.onap.vid.job.JobCommand;
27 import org.onap.vid.job.JobType;
28 import org.onap.vid.job.NextCommand;
29 import org.onap.vid.job.command.CommandParentData.CommandDataKey;
30 import org.onap.vid.job.impl.JobSharedData;
31 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
32 import org.onap.vid.properties.Features;
33 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Component;
37 import java.util.List;
39 import java.util.stream.Collectors;
40 import java.util.stream.Stream;
43 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
44 public class ServiceInProgressStatusCommand extends BaseInProgressStatusCommand {
46 public ServiceInProgressStatusCommand() {
49 ServiceInProgressStatusCommand(JobSharedData sharedData, MsoResourceIds msoResourceIds) {
50 init(sharedData, msoResourceIds.getRequestId(), msoResourceIds.getInstanceId());
54 protected ExpiryChecker getExpiryChecker() {
55 return new ServiceExpiryChecker();
58 protected NextCommand processJobStatus(Job.JobStatus jobStatus) {
59 JobCommand jobCommand = this;
60 Job.JobStatus nextJobStatus = jobStatus;
63 asyncInstantiationBL.handleFailedInstantiation(getSharedData().getJobUuid());
64 return new NextCommand(nextJobStatus, jobCommand);
66 nextJobStatus = Job.JobStatus.IN_PROGRESS;
69 ServiceInstantiation request = (ServiceInstantiation) getSharedData().getRequest();
70 if (isNeedToCreateChildJobs(request)) {
71 List<String> childrenJobs = getChildJobs(request);
72 nextJobStatus = Job.JobStatus.IN_PROGRESS;
73 jobCommand = new WatchingCommand(getSharedData(), childrenJobs, true);
74 return new NextCommand(nextJobStatus, jobCommand);
79 asyncInstantiationBL.updateServiceInfoAndAuditStatus(getSharedData().getJobUuid(), jobStatus);
80 return new NextCommand(nextJobStatus, jobCommand);
83 private List<String> getChildJobs(ServiceInstantiation request) {
84 Map<String, Object> dataForChild = buildDataForChild(request);
86 Stream<String> vnfJobs = request.getVnfs().values().stream().map(
87 vnf -> jobsBrokerService.add(
88 jobAdapter.createChildJob(JobType.VnfInstantiation, JobStatus.CREATING , vnf, getSharedData(), dataForChild)).toString()
91 Stream<String> networkJobs = request.getNetworks().values().stream().map(
92 network -> jobsBrokerService.add(
93 jobAdapter.createChildJob(JobType.NetworkInstantiation, JobStatus.CREATING , network, getSharedData(), dataForChild)).toString()
96 Stream<String> instanceGroupJobs = request.getVnfGroups().values().stream().map(
97 instanceGroup -> jobsBrokerService.add(
98 jobAdapter.createChildJob(JobType.InstanceGroupInstantiation, JobStatus.CREATING , instanceGroup, getSharedData(), dataForChild)).toString()
101 return Stream.of(vnfJobs, networkJobs, instanceGroupJobs)
102 .reduce(Stream::concat)
103 .orElseGet(Stream::empty)
104 .collect(Collectors.toList());
107 public boolean isNeedToCreateChildJobs(ServiceInstantiation request) {
108 return featureManager.isActive(Features.FLAG_ASYNC_ALACARTE_VNF) && request.isALaCarte() &&
110 MapUtils.isNotEmpty(request.getVnfs()) || MapUtils.isNotEmpty(request.getNetworks()) ||
111 (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && MapUtils.isNotEmpty(request.getVnfGroups()))
115 protected Map<String, Object> buildDataForChild(ServiceInstantiation request) {
116 commandParentData.addInstanceId(CommandDataKey.SERVICE_INSTANCE_ID, this.instanceId);
117 commandParentData.addModelInfo(CommandDataKey.SERVICE_MODEL_INFO, request.getModelInfo());
118 return commandParentData.getParentData();