2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.job.command;
23 import org.onap.vid.changeManagement.RequestDetailsWrapper;
24 import org.onap.vid.job.Job;
25 import org.onap.vid.job.JobAdapter;
26 import org.onap.vid.job.JobCommand;
27 import org.onap.vid.job.NextCommand;
28 import org.onap.vid.job.impl.JobSharedData;
29 import org.onap.vid.model.RequestReferencesContainer;
30 import org.onap.vid.mso.RestMsoImplementation;
31 import org.onap.vid.mso.RestObject;
32 import org.onap.vid.mso.model.BaseResourceInstantiationRequestDetails;
33 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
34 import org.onap.vid.services.AuditService;
35 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Component;
39 import javax.inject.Inject;
44 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
45 public abstract class ResourceInstantiationCommand extends BaseInstantiationCommand implements JobCommand {
49 protected RestMsoImplementation restMso;
52 private AsyncInstantiationBusinessLogic asyncInstantiationBL;
55 private AuditService auditService;
58 public ResourceInstantiationCommand init(JobSharedData sharedData, Map<String, Object> commandData) {
59 super.init(sharedData, commandData);
64 public Map<String, Object> getData() {
65 return commandParentData.getParentData();
69 public NextCommand call() {
70 if (!shouldInstantiateMyself()) {
71 return new NextCommand(Job.JobStatus.COMPLETED_WITH_NO_ACTION);
74 RequestDetailsWrapper<? extends BaseResourceInstantiationRequestDetails> requestDetailsWrapper = generateMSORequest(
75 getSharedData().getRequest(),
76 getSharedData().getUserId()
78 String instantiatePath = getRequestPath();
80 RestObject<RequestReferencesContainer> msoResponse = restMso.PostForObject(requestDetailsWrapper,
81 instantiatePath, RequestReferencesContainer.class);
83 if (msoResponse.getStatusCode() >= 200 && msoResponse.getStatusCode() < 400) {
84 String requestId = msoResponse.get().getRequestReferences().getRequestId();
85 String instanceId = msoResponse.get().getRequestReferences().getInstanceId();
86 asyncInstantiationBL.auditMsoStatus(getSharedData().getRootJobId(), getJobAuditMSOStatus(), requestId, null);
87 return getNextCommand(requestId, instanceId);
90 auditService.setFailedAuditStatusFromMso(getSharedData().getRootJobId(), null, msoResponse.getStatusCode(), msoResponse.getRaw());
91 return new NextCommand(Job.JobStatus.FAILED);
94 protected NextCommand getNextCommand(String requestId, String instanceId){
95 return new NextCommand(Job.JobStatus.RESOURCE_IN_PROGRESS, new ResourceInProgressStatusCommand(getSharedData(), requestId, instanceId));
98 protected boolean shouldInstantiateMyself() {
102 protected abstract String getRequestPath();
103 protected abstract RequestDetailsWrapper<? extends BaseResourceInstantiationRequestDetails> generateMSORequest(JobAdapter.AsyncJobRequest request, String userId);
104 protected abstract String getJobAuditMSOStatus();