1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package org.onap.vid.job.command;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.job.Job;
import org.onap.vid.job.JobCommand;
import org.onap.vid.job.NextCommand;
import org.onap.vid.job.impl.JobSharedData;
import org.onap.vid.services.AsyncInstantiationBusinessLogic;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class BaseWatchingCommand extends BaseInstantiationCommand implements JobCommand {
private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BaseWatchingCommand.class);
@Inject
protected AsyncInstantiationBusinessLogic asyncInstantiationBL;
@Inject
private WatchChildrenJobsBL watchChildrenJobsBL;
private List<String> childrenJobsIds;
protected boolean isService;
public BaseWatchingCommand() {}
public BaseWatchingCommand(JobSharedData sharedData, List<String> childrenJobsIds, boolean isService) {
init(sharedData, childrenJobsIds, isService);
}
@Override
public NextCommand call() {
Job.JobStatus cumulativeJobsStatus = watchChildrenJobsBL.cumulateJobStatus(
watchChildrenJobsBL.retrieveChildrenJobsStatus(childrenJobsIds),
Job.JobStatus.COMPLETED);
return getNextCommand(cumulativeJobsStatus);
}
protected abstract NextCommand getNextCommand(Job.JobStatus cumulativeJobsStatus);
@Override
public BaseWatchingCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
return init(
sharedData,
(List<String>) commandData.get("childrenJobs"),
(boolean) commandData.get("isService")
);
}
protected BaseWatchingCommand init(JobSharedData sharedData, List<String> childrenJobsIds, boolean isService) {
super.init(sharedData);
this.childrenJobsIds = ObjectUtils.defaultIfNull(childrenJobsIds, new ArrayList<>());
this.isService = isService;
return this;
}
@Override
public Map<String, Object> getData() {
Map<String, Object> data = new HashMap<>();
data.put("childrenJobs", childrenJobsIds);
data.put("isService", isService);
return data;
}
}
|