9c4d7b82505a487111288551a0b25bd57816d826
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / VolumeGroupInProgressStatusCommand.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 import org.onap.vid.job.Job;
24 import org.onap.vid.job.JobType;
25 import org.onap.vid.job.NextCommand;
26 import org.onap.vid.job.command.CommandParentData.CommandDataKey;
27 import org.onap.vid.job.impl.JobSharedData;
28 import org.onap.vid.model.serviceInstantiation.VfModule;
29 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
30 import org.springframework.context.annotation.Scope;
31 import org.springframework.stereotype.Component;
32
33 import java.util.Arrays;
34 import java.util.List;
35 import java.util.Map;
36
37 @Component
38 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
39 public class VolumeGroupInProgressStatusCommand extends ResourceWithChildrenInProgressCommand {
40
41     public VolumeGroupInProgressStatusCommand(
42             JobSharedData sharedData,
43             String requestId,
44             String instanceId,
45             CommandParentData parentData) {
46         super(sharedData, requestId, instanceId, parentData);
47     }
48
49     public VolumeGroupInProgressStatusCommand() {
50     }
51
52     @Override
53     protected NextCommand processJobStatus(Job.JobStatus jobStatus) {
54         if (jobStatus == Job.JobStatus.FAILED) {
55             return new NextCommand(Job.JobStatus.FAILED);
56         }
57         VfModule request = (VfModule) getSharedData().getRequest();
58
59         if (jobStatus == Job.JobStatus.COMPLETED) {
60             //vf module creation
61             Map<String, Object> dataForChild = buildDataForChild();
62             List<String> vfModuleJob = Arrays.asList(jobsBrokerService.add(
63                             jobAdapter.createChildJob(JobType.VfmoduleInstantiation, Job.JobStatus.CREATING , request, getSharedData(), dataForChild)).toString());
64
65             return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vfModuleJob, false));
66         }
67
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);
71         }
72         return new NextCommand(jobStatus, this);
73     }
74
75     @Override
76     protected Map<String, Object> buildDataForChild() {
77         commandParentData.addInstanceId(CommandDataKey.VG_INSTANCE_ID, this.instanceId);
78         return super.buildDataForChild();
79     }
80
81     @Override
82     protected ExpiryChecker getExpiryChecker() {
83         return x->false;
84     }
85 }