Remove restricted notice from TOSCA file
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / VolumeGroupInstantiationCommand.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.vid.job.command;
22
23
24 import org.apache.commons.lang3.StringUtils;
25 import org.onap.vid.changeManagement.RequestDetailsWrapper;
26 import org.onap.vid.job.*;
27 import org.onap.vid.job.command.CommandParentData.CommandDataKey;
28 import org.onap.vid.model.serviceInstantiation.VfModule;
29 import org.onap.vid.mso.model.VolumeGroupRequestDetails;
30 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
31 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
32 import org.springframework.context.annotation.Scope;
33 import org.springframework.stereotype.Component;
34
35 import javax.inject.Inject;
36 import java.util.Collections;
37 import java.util.List;
38 import java.util.Map;
39
40 @Component
41 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
42 public class VolumeGroupInstantiationCommand extends ResourceInstantiationCommand {
43     @Inject
44     private AsyncInstantiationBusinessLogic asyncInstantiationBL;
45
46     @Inject
47     protected JobsBrokerService jobsBrokerService;
48
49     @Inject
50     protected JobAdapter jobAdapter;
51
52     @Override
53     protected String getRequestPath() {
54         return asyncInstantiationBL.getVolumeGroupInstantiationPath(commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID),commandParentData.getInstanceId(CommandDataKey.VNF_INSTANCE_ID));
55     }
56
57     @Override
58     protected RequestDetailsWrapper<VolumeGroupRequestDetails> generateMSORequest(JobAdapter.AsyncJobRequest request, String userId) {
59         return asyncInstantiationBL.generateVolumeGroupInstantiationRequest(
60                 (VfModule) getSharedData().getRequest(),
61                 commandParentData.getModelInfo(CommandDataKey.SERVICE_MODEL_INFO),
62                 commandParentData.getInstanceId(CommandDataKey.SERVICE_INSTANCE_ID),
63                 commandParentData.getModelInfo(CommandDataKey.VNF_MODEL_INFO),
64                 commandParentData.getInstanceId(CommandDataKey.VNF_INSTANCE_ID),
65                 getSharedData().getUserId()
66         );
67     }
68
69     @Override
70     protected NextCommand getNextCommand(String requestId, String instanceId){
71         return new NextCommand(
72                 Job.JobStatus.RESOURCE_IN_PROGRESS,
73                 new VolumeGroupInProgressStatusCommand(getSharedData(), requestId, instanceId, commandParentData)
74         );
75     }
76
77     @Override
78     protected String getJobAuditMSOStatus() {
79         return "VOLUME_GROUP_REQUESTED";
80     }
81
82     @Override
83     public NextCommand call() {
84         String vgName = ((VfModule)getSharedData().getRequest()).getVolumeGroupInstanceName();
85         if(StringUtils.isNotEmpty(vgName)){
86             return super.call();//create volume group
87         }else {
88             //go to vf module creation
89             VfModule request = (VfModule) getSharedData().getRequest();
90             Map<String, Object> dataForChild = buildDataForChild();
91             List<String> vfModuleJob = Collections.singletonList(jobsBrokerService.add(
92                     jobAdapter.createChildJob(JobType.VfmoduleInstantiation, Job.JobStatus.CREATING, request, getSharedData(), dataForChild)).toString());
93
94             return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vfModuleJob, false));
95         }
96
97     }
98
99     private Map<String, Object> buildDataForChild() {
100        return commandParentData.getParentData();
101     }
102
103 }