1 package org.onap.vid.job.command;
3 import org.onap.vid.changeManagement.RequestDetailsWrapper;
4 import org.onap.vid.job.Job;
5 import org.onap.vid.job.JobAdapter;
6 import org.onap.vid.job.JobCommand;
7 import org.onap.vid.job.NextCommand;
8 import org.onap.vid.job.impl.JobSharedData;
9 import org.onap.vid.model.RequestReferencesContainer;
10 import org.onap.vid.mso.RestMsoImplementation;
11 import org.onap.vid.mso.RestObject;
12 import org.onap.vid.mso.model.BaseResourceInstantiationRequestDetails;
13 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
14 import org.onap.vid.services.AuditService;
15 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
16 import org.springframework.context.annotation.Scope;
17 import org.springframework.stereotype.Component;
19 import javax.inject.Inject;
24 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
25 public abstract class ResourceInstantiationCommand extends BaseInstantiationCommand implements JobCommand {
29 protected RestMsoImplementation restMso;
32 private AsyncInstantiationBusinessLogic asyncInstantiationBL;
35 private AuditService auditService;
38 public ResourceInstantiationCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
39 super.init(sharedData, commandData);
44 public Map<String, Object> getData() {
45 return commandParentData.getParentData();
49 public NextCommand call() {
50 if (!shouldInstantiateMyself()) {
51 return new NextCommand(Job.JobStatus.COMPLETED_WITH_NO_ACTION);
54 RequestDetailsWrapper<? extends BaseResourceInstantiationRequestDetails> requestDetailsWrapper = generateMSORequest(
55 getSharedData().getRequest(),
56 getSharedData().getUserId()
58 String instantiatePath = getRequestPath();
60 RestObject<RequestReferencesContainer> msoResponse = restMso.PostForObject(requestDetailsWrapper,
61 instantiatePath, RequestReferencesContainer.class);
63 if (msoResponse.getStatusCode() >= 200 && msoResponse.getStatusCode() < 400) {
64 String requestId = msoResponse.get().getRequestReferences().getRequestId();
65 String instanceId = msoResponse.get().getRequestReferences().getInstanceId();
66 asyncInstantiationBL.auditMsoStatus(getSharedData().getRootJobId(), getJobAuditMSOStatus(), requestId, null);
67 return getNextCommand(requestId, instanceId);
70 auditService.setFailedAuditStatusFromMso(getSharedData().getRootJobId(), null, msoResponse.getStatusCode(), msoResponse.getRaw());
71 return new NextCommand(Job.JobStatus.FAILED);
74 protected NextCommand getNextCommand(String requestId, String instanceId){
75 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new ResourceInProgressStatusCommand(getSharedData(), requestId, instanceId));
78 protected boolean shouldInstantiateMyself() {
82 protected abstract String getRequestPath();
83 protected abstract RequestDetailsWrapper<? extends BaseResourceInstantiationRequestDetails> generateMSORequest(JobAdapter.AsyncJobRequest request, String userId);
84 protected abstract String getJobAuditMSOStatus();