2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.so.apihandlerinfra.tenantisolation.process;
23 import java.util.List;
25 import javax.ws.rs.core.Response;
27 import org.apache.http.HttpStatus;
28 import org.json.JSONObject;
29 import org.onap.so.apihandler.common.ErrorNumbers;
30 import org.onap.so.requestsdb.client.RequestsDbClient;
31 import org.onap.so.apihandlerinfra.exceptions.ApiException;
32 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
33 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
34 import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
35 import org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientHelper;
36 import org.onap.so.apihandlerinfra.tenantisolation.helpers.ActivateVnfDBHelper;
37 import org.onap.so.apihandlerinfra.tenantisolation.helpers.SDCClientHelper;
38 import org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList;
39 import org.onap.so.client.aai.entities.AAIResultWrapper;
40 import org.onap.so.client.aai.objects.AAIOperationalEnvironment;
41 import org.onap.so.db.request.beans.OperationalEnvDistributionStatus;
42 import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
43 import org.onap.so.logger.MessageEnum;
44 import org.onap.so.logger.MsoLogger;
45 import org.onap.so.requestsdb.RequestsDBHelper;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.beans.factory.annotation.Value;
48 import org.springframework.stereotype.Component;
52 public class ActivateVnfOperationalEnvironment {
54 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, ActivateVnfOperationalEnvironment.class);
55 private static final int DEFAULT_ACTIVATE_RETRY_COUNT = 3;
56 private static final String DISTRIBUTION_STATUS_SENT = "SENT";
59 private ActivateVnfDBHelper dbHelper;
61 private AAIClientHelper aaiHelper;
63 private RequestsDBHelper requestDb;
65 private SDCClientHelper sdcClientHelper;
67 @Value("${mso.tenant.isolation.retry.count}")
68 private String sdcRetryCount;
71 RequestsDbClient client;
74 * The Point-Of-Entry from APIH with VID request to send activate request
75 * @param requestId - String
76 * @param request - CloudOrchestrationRequest object
77 * @return void - nothing
79 public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException{
80 String operationalEnvironmentId = request.getOperationalEnvironmentId();
82 String vidWorkloadContext = request.getRequestDetails().getRequestParameters().getWorkloadContext();
83 List<ServiceModelList> serviceModelVersionIdList = request.getRequestDetails().getRequestParameters().getManifest().getServiceModelList();
86 AAIOperationalEnvironment operationalEnv = getAAIOperationalEnvironment(operationalEnvironmentId);
87 String workloadContext = operationalEnv.getWorkloadContext();
88 msoLogger.debug(" aai workloadContext: " + workloadContext);
89 if (!vidWorkloadContext.equals(workloadContext)) {
92 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.BusinessProcesssError).build();
93 throw new ValidateException.Builder(" The vid workloadContext did not match from aai record. " + " vid workloadContext:" + vidWorkloadContext + " aai workloadContext:" + workloadContext,
94 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
97 processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext);
103 * The Method to send the Activation Requests to SDC
104 * @param requestId - String
105 * @param operationalEnvironmentId - String
106 * @param serviceModelVersionIdList - List<ServiceModelList> list
107 * @param workloadContext - String
108 * @return jsonResponse - JSONObject object
110 public void processActivateSDCRequest(String requestId, String operationalEnvironmentId,
111 List<ServiceModelList> serviceModelVersionIdList,
112 String workloadContext) throws ApiException {
114 JSONObject jsonResponse = null;
117 retryCount = Integer.parseInt(sdcRetryCount);
118 } catch (NumberFormatException e) {
119 retryCount = DEFAULT_ACTIVATE_RETRY_COUNT;
122 // loop through the serviceModelVersionId, and send request SDC
123 for(ServiceModelList serviceModelList : serviceModelVersionIdList){
124 String serviceModelVersionId = serviceModelList.getServiceModelVersionId();
125 String recoveryAction = serviceModelList.getRecoveryAction().toString().toUpperCase();
127 // should insert 1 row
128 OperationalEnvServiceModelStatus serviceModelStatus =
129 dbHelper.insertRecordToOperationalEnvServiceModelStatus(requestId,
130 operationalEnvironmentId,
131 serviceModelVersionId,
132 DISTRIBUTION_STATUS_SENT,
136 client.save(serviceModelStatus);
138 String distributionId = "";
140 jsonResponse = sdcClientHelper.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext);
142 String statusCode = jsonResponse.get("statusCode").toString();
143 if (statusCode.equals(String.valueOf(Response.Status.ACCEPTED.getStatusCode()))) {
144 distributionId = jsonResponse.get("distributionId").toString();
145 // should insert 1 row
146 OperationalEnvDistributionStatus distStatus =
147 dbHelper.insertRecordToOperationalEnvDistributionStatus(distributionId,
148 operationalEnvironmentId,
149 serviceModelVersionId,
151 DISTRIBUTION_STATUS_SENT,
153 client.save(distStatus);
156 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.BusinessProcesssError).build();
157 String dbErrorMessage = " Failure calling SDC: statusCode: " + statusCode +
158 "; messageId: " + jsonResponse.get("messageId") +
159 "; message: " + jsonResponse.get("message");
161 requestDb.updateInfraFailureCompletion(dbErrorMessage, requestId, operationalEnvironmentId);
162 throw new ValidateException.Builder(dbErrorMessage,
163 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
170 * Get AAIOperationalEnvironment object
171 * @param operationalEnvironmentId - String
172 * @return operationalEnv - AAIOperationalEnvironment object
174 public AAIOperationalEnvironment getAAIOperationalEnvironment(String operationalEnvironmentId) {
175 AAIResultWrapper aaiResult = aaiHelper.getAaiOperationalEnvironment(operationalEnvironmentId);
176 return aaiResult.asBean(AAIOperationalEnvironment.class).orElse(new AAIOperationalEnvironment());