Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / VolumeGroupInProgressStatusCommand.java
1 package org.onap.vid.job.command;
2
3 import org.onap.vid.job.Job;
4 import org.onap.vid.job.JobType;
5 import org.onap.vid.job.NextCommand;
6 import org.onap.vid.job.command.CommandParentData.CommandDataKey;
7 import org.onap.vid.job.impl.JobSharedData;
8 import org.onap.vid.model.serviceInstantiation.VfModule;
9 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
10 import org.springframework.context.annotation.Scope;
11 import org.springframework.stereotype.Component;
12
13 import java.util.Arrays;
14 import java.util.List;
15 import java.util.Map;
16
17 @Component
18 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
19 public class VolumeGroupInProgressStatusCommand extends ResourceWithChildrenInProgressCommand {
20
21     public VolumeGroupInProgressStatusCommand(
22             JobSharedData sharedData,
23             String requestId,
24             String instanceId,
25             CommandParentData parentData) {
26         super(sharedData, requestId, instanceId, parentData);
27     }
28
29     public VolumeGroupInProgressStatusCommand() {
30     }
31
32     @Override
33     protected NextCommand processJobStatus(Job.JobStatus jobStatus) {
34         if (jobStatus == Job.JobStatus.FAILED) {
35             return new NextCommand(Job.JobStatus.FAILED);
36         }
37         VfModule request = (VfModule) getSharedData().getRequest();
38
39         if (jobStatus == Job.JobStatus.COMPLETED) {
40             //vf module creation
41             Map<String, Object> dataForChild = buildDataForChild();
42             List<String> vfModuleJob = Arrays.asList(jobsBrokerService.add(
43                             jobAdapter.createChildJob(JobType.VfmoduleInstantiation, Job.JobStatus.CREATING , request, getSharedData(), dataForChild)).toString());
44
45             return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new WatchingCommand(getSharedData(), vfModuleJob, false));
46         }
47
48         //in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress
49         if (jobStatus == Job.JobStatus.PAUSE) {
50             return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, this);
51         }
52         return new NextCommand(jobStatus, this);
53     }
54
55     @Override
56     protected Map<String, Object> buildDataForChild() {
57         commandParentData.addInstanceId(CommandDataKey.VG_INSTANCE_ID, this.instanceId);
58         return super.buildDataForChild();
59     }
60
61     @Override
62     protected ExpiryChecker getExpiryChecker() {
63         return x->false;
64     }
65 }