2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.vid.mso;
23 import com.fasterxml.jackson.annotation.JsonCreator;
24 import com.fasterxml.jackson.annotation.JsonValue;
25 import com.fasterxml.jackson.databind.DeserializationFeature;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.google.common.collect.ImmutableList;
28 import com.google.common.collect.ImmutableMap;
29 import org.onap.vid.changeManagement.ChangeManagementRequest;
30 import org.onap.vid.changeManagement.RequestDetailsWrapper;
31 import org.onap.vid.controllers.OperationalEnvironmentController;
32 import org.onap.vid.domain.mso.RequestInfo;
33 import org.onap.vid.exceptions.GenericUncheckedException;
34 import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
35 import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
36 import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
37 import org.onap.vid.mso.rest.*;
38 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
39 import org.onap.portalsdk.core.util.SystemProperties;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.togglz.core.manager.FeatureManager;
43 import javax.ws.rs.BadRequestException;
44 import java.io.IOException;
45 import java.text.DateFormat;
46 import java.text.SimpleDateFormat;
48 import java.util.regex.Pattern;
50 import static org.apache.commons.lang.StringUtils.upperCase;
51 import static org.onap.vid.changeManagement.ChangeManagementRequest.MsoChangeManagementRequest;
52 import static org.onap.vid.controllers.MsoController.*;
53 import static org.onap.vid.mso.MsoProperties.*;
54 import static org.onap.vid.properties.Features.FLAG_UNASSIGN_SERVICE;
55 import static org.onap.vid.utils.Logging.debugRequestDetails;
57 public class MsoBusinessLogicImpl implements MsoBusinessLogic {
59 public static final String START = " start";
60 public static final String RESOURCE_TYPE = "resourceType";
61 FeatureManager featureManager;
64 * The Constant dateFormat.
66 private static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
67 private static final Pattern SOFTWARE_VERSION_PATTERN = Pattern.compile("^[A-Za-z0-9.\\-]+$");
68 private static final Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]+$");
69 private static final String ACTIVATE = "/activate";
70 private static final String DEACTIVATE = "/deactivate";
71 private static final String ENABLE_PORT = "/enablePort";
72 private static final String DISABLE_PORT = "/disablePort";
73 private static final String RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT = "operationalEnvironment";
74 private static final String SOURCE_OPERATIONAL_ENVIRONMENT = "VID";
75 private static final ObjectMapper objectMapper = new ObjectMapper();
78 * This should be replaced with mso client factory.
80 private final MsoInterface msoClientInterface;
85 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoBusinessLogicImpl.class);
88 public MsoBusinessLogicImpl(MsoInterface msoClientInterface, FeatureManager featureManager) {
89 this.msoClientInterface = msoClientInterface;
90 this.featureManager = featureManager;
93 public static String validateEndpointPath(String endpointEnvVariable) {
94 String endpoint = SystemProperties.getProperty(endpointEnvVariable);
95 if (endpoint == null || endpoint.isEmpty()) {
96 throw new GenericUncheckedException(endpointEnvVariable + " env variable is not defined");
101 // this function should get params from tosca and send them to instance at mso, then return success response.
103 public MsoResponseWrapper createSvcInstance(RequestDetails msoRequest) {
104 String methodName = "createSvcInstance ";
105 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
108 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
110 return msoClientInterface.createSvcInstance(msoRequest, endpoint);
114 public MsoResponseWrapper createE2eSvcInstance(Object msoRequest){
115 String methodName = "createE2eSvcInstance ";
116 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
119 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE);
122 return msoClientInterface.createE2eSvcInstance(msoRequest, endpoint);
126 public MsoResponseWrapper createVnf(RequestDetails requestDetails, String serviceInstanceId) {
127 String methodName = "createVnf";
128 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
131 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
133 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
134 return msoClientInterface.createVnf(requestDetails, vnf_endpoint);
138 public MsoResponseWrapper createNwInstance(RequestDetails requestDetails, String serviceInstanceId) {
139 String methodName = "createNwInstance";
140 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
143 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
145 String nw_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
146 return msoClientInterface.createNwInstance(requestDetails, nw_endpoint);
150 public MsoResponseWrapper createVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
151 String methodName = "createVolumeGroupInstance";
152 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
155 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
157 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
158 vnf_endpoint = vnf_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
160 return msoClientInterface.createVolumeGroupInstance(requestDetails, vnf_endpoint);
164 public MsoResponseWrapper createVfModuleInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
165 String methodName = "createVfModuleInstance";
166 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
169 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
171 String partial_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
172 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
174 return msoClientInterface.createVfModuleInstance(requestDetails, vf_module_endpoint);
178 public MsoResponseWrapper scaleOutVfModuleInstance(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
179 String methodName = "scaleOutVfModuleInstance";
180 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
183 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_SCALE_OUT);
185 String partial_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
186 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
187 RequestDetailsWrapper wrapper = new RequestDetailsWrapper();
188 requestDetails.setVnfName(null);
189 requestDetails.setVnfInstanceId(null);
190 wrapper.requestDetails = requestDetails;
192 return msoClientInterface.scaleOutVFModuleInstance(wrapper, vf_module_endpoint);
195 public MsoResponseWrapper createConfigurationInstance(org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String serviceInstanceId) {
196 String methodName = "createConfigurationInstance";
197 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
199 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATIONS);
200 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
202 return msoClientInterface.createConfigurationInstance(requestDetailsWrapper, endpoint);
206 public MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String serviceInstanceId) {
207 String methodName = "deleteE2eSvcInstance";
208 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
211 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
213 return msoClientInterface.deleteE2eSvcInstance(requestDetails, endpoint);
217 public MsoResponseWrapper deleteSvcInstance(RequestDetails requestDetails, String serviceInstanceId, String serviceStatus) {
218 String methodName = "deleteSvcInstance";
219 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
222 if (featureManager.isActive(FLAG_UNASSIGN_SERVICE)){
223 endpoint = validateEndpointPath(MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE);
224 if (shouldUnassignService(serviceStatus)){
225 logger.debug(EELFLoggerDelegate.debugLogger, "unassign service");
226 String svc_endpoint = endpoint + "/" + serviceInstanceId + "/unassign";
227 return msoClientInterface.unassignSvcInstance(requestDetails, svc_endpoint);
230 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
233 String svc_endpoint = endpoint + "/" + serviceInstanceId;
234 return msoClientInterface.deleteSvcInstance(requestDetails, svc_endpoint);
237 private boolean shouldUnassignService(String serviceStatus) {
238 return ImmutableList.of("created","pendingdelete","pending-delete", "assigned").contains(serviceStatus.toLowerCase());
242 public MsoResponseWrapper deleteVnf(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
243 String methodName = "deleteVnf";
244 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
247 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
248 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
249 vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId;
251 return msoClientInterface.deleteVnf(requestDetails, vnf_endpoint);
255 public MsoResponseWrapper deleteVfModule(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String vfModuleId) {
256 String methodName = "deleteVfModule";
257 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
260 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
262 String vf__modules_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId).replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
264 String delete_vf_endpoint = vf__modules_endpoint + '/' + vfModuleId;
266 return msoClientInterface.deleteVfModule(requestDetails, delete_vf_endpoint);
270 public MsoResponseWrapper deleteVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
271 String methodName = "deleteVolumeGroupInstance";
272 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
275 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
277 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
278 String vnf_endpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
279 String delete_volume_group_endpoint = vnf_endpoint + "/" + volumeGroupId;
281 return msoClientInterface.deleteVolumeGroupInstance(requestDetails, delete_volume_group_endpoint);
285 public MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String serviceInstanceId, String networkInstanceId) {
286 String methodName = "deleteNwInstance";
287 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
290 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
292 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
293 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
295 return msoClientInterface.deleteNwInstance(requestDetails, delete_nw_endpoint);
299 public MsoResponseWrapper getOrchestrationRequest(String requestId) {
300 String methodName = "getOrchestrationRequest";
301 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
303 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
304 String path = p + "/" + requestId;
306 return msoClientInterface.getOrchestrationRequest(path);
308 } catch (Exception e) {
309 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
310 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
316 public MsoResponseWrapper getOrchestrationRequests(String filterString) {
317 String methodName = "getOrchestrationRequest";
318 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
320 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
321 String path = p + filterString;
323 return msoClientInterface.getOrchestrationRequest(path);
325 } catch (Exception e) {
326 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
327 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
333 public List<Request> getOrchestrationRequestsForDashboard() {
334 String methodName = "getOrchestrationRequestsForDashboard";
335 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
336 List<Request> filteredOrchestrationRequests = new ArrayList<>();
338 String path = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
339 path += "filter=modelType:EQUALS:vnf";
340 RestObject<String> restObjStr = new RestObject<>();
341 String str = new String();
344 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequestsForDashboard(str, "", path, restObjStr);
345 List<RequestWrapper> allOrchestrationRequests = deserializeOrchestrationRequestsJson(msoResponseWrapper.getEntity());
347 final ImmutableList<String> suppoertedRequestTypes = ImmutableList.of(
348 RequestType.REPLACE_INSTANCE.toString().toUpperCase(),
349 RequestType.UPDATE_INSTANCE.toString().toUpperCase(),
350 RequestType.APPLY_UPDATED_CONFIG.toString().toUpperCase(),
351 RequestType.IN_PLACE_SOFTWARE_UPDATE.toString().toUpperCase()
354 for (RequestWrapper currentRequest : allOrchestrationRequests) {
355 if (currentRequest.getRequest() != null
356 && "vnf".equalsIgnoreCase(currentRequest.getRequest().getRequestScope())
357 && suppoertedRequestTypes.contains(upperCase(currentRequest.getRequest().getRequestType()))
359 filteredOrchestrationRequests.add(currentRequest.getRequest());
362 } catch (Exception e) {
363 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
364 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
366 return filteredOrchestrationRequests;
369 private List<RequestWrapper> deserializeOrchestrationRequestsJson(String orchestrationRequestsJson) {
370 String methodName = "deserializeOrchestrationRequestsJson";
371 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
373 ObjectMapper mapper = new ObjectMapper();
374 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
375 mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
376 RequestList requestList = null;
378 requestList = mapper.readValue(orchestrationRequestsJson, RequestList.class);
379 } catch (IOException e) {
380 throw new GenericUncheckedException(e);
382 return requestList.getRequestList();
387 public List<Task> getManualTasksByRequestId(String originalRequestId) {
388 String methodName = "getManualTasksByRequestId";
389 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
392 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
393 String path = p + "?originalRequestId=" + originalRequestId;
395 RestObject<String> restObjStr = new RestObject<>();
396 String str = new String();
399 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getManualTasksByRequestId(str, "", path, restObjStr);
400 return deserializeManualTasksJson(msoResponseWrapper.getEntity());
402 } catch (Exception e) {
403 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
404 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
409 private List<Task> deserializeManualTasksJson(String manualTasksJson) {
410 String methodName = "deserializeManualTasksJson";
411 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
413 ObjectMapper mapper = new ObjectMapper();
415 TaskList taskList = mapper.readValue(manualTasksJson, TaskList.class);
416 return taskList.getTaskList();
417 } catch (IOException e) {
418 throw new GenericUncheckedException(e);
424 public MsoResponseWrapper completeManualTask(RequestDetails requestDetails, String taskId) {
425 String methodName = "completeManualTask";
426 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
428 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
429 String path = p + "/" + taskId + "/complete";
431 RestObject<String> restObjStr = new RestObject<>();
432 String str = new String();
435 msoClientInterface.completeManualTask(requestDetails, str, "", path, restObjStr);
437 return MsoUtil.wrapResponse(restObjStr);
439 } catch (Exception e) {
440 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
441 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
447 public MsoResponseWrapper activateServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
448 String methodName = "activateServiceInstance";
449 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
451 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
452 String activateServicePath = serviceEndpoint + "/" + serviceInstanceId + ACTIVATE;
454 RestObject<String> restObjStr = new RestObject<>();
458 msoClientInterface.setServiceInstanceStatus(requestDetails, str, "", activateServicePath, restObjStr);
460 return MsoUtil.wrapResponse(restObjStr);
462 } catch (Exception e) {
463 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
464 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
471 public MsoResponseWrapperInterface updateVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
472 String methodName = "updateVnf";
473 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
476 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
477 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
478 vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId;
479 return msoClientInterface.updateVnf(requestDetails, vnf_endpoint);
483 public MsoResponseWrapperInterface replaceVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
484 String methodName = "replaceVnf";
485 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
488 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
489 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
490 vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
491 vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, MsoChangeManagementRequest.REPLACE);
492 return msoClientInterface.replaceVnf(requestDetails, vnf_endpoint);
495 public RequestDetailsWrapper generateInPlaceMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails) {
496 validateUpdateVnfSoftwarePayload(requestDetails);
497 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
498 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
499 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
500 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
501 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
502 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
503 return requestDetailsWrapper;
507 public RequestDetailsWrapper generateConfigMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails) {
508 validateUpdateVnfConfig(requestDetails);
509 RequestDetails ConfigUpdateRequest = new RequestDetails();
510 ConfigUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
511 ConfigUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
512 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
513 requestDetailsWrapper.requestDetails = ConfigUpdateRequest;
514 return requestDetailsWrapper;
522 public MsoResponseWrapperInterface updateVnfSoftware(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
523 String methodName = "updateVnfSoftware";
524 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
525 String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.SOFTWARE_UPDATE); //workflow name in mso is different than workflow name in vid UI
526 RequestDetailsWrapper finalRequestDetails = generateInPlaceMsoRequest(requestDetails);
527 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
531 public MsoResponseWrapperInterface updateVnfConfig(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
532 String methodName = "updateVnfConfig";
533 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
534 RequestDetailsWrapper finalRequestDetails = generateConfigMsoRequest(requestDetails);
535 String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.CONFIG_UPDATE);
536 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
539 private String getChangeManagementEndpoint(String serviceInstanceId, String vnfInstanceId, String vnfRequestType) {
540 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
541 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
542 vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
543 vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, vnfRequestType);
547 private Map getChangeManagementPayload(RequestDetails requestDetails, String message){
548 if(requestDetails.getRequestParameters()==null||requestDetails.getRequestParameters().getAdditionalProperties()==null){
549 throw new BadRequestException(message);
551 Object payloadRaw=requestDetails.getRequestParameters().getAdditionalProperties().get("payload");
553 return objectMapper.readValue((String)payloadRaw,Map.class);
555 catch(Exception exception){
556 throw new BadRequestException(message);
560 private void validateUpdateVnfSoftwarePayload(RequestDetails requestDetails) {
561 final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE + " request";
563 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
564 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "existing_software_version", SOFTWARE_VERSION_PATTERN);
565 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "new_software_version", SOFTWARE_VERSION_PATTERN);
567 //if "operations_timeout" is not integer, trying to read it as String that represent a number
568 if (!(payload.get("operations_timeout") instanceof Integer)) {
569 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "operations_timeout", NUMBER_PATTERN);
573 private void validateUpdateVnfSoftwarePayloadProperty(Map payload, String noValidPayloadMsg, String propertyName, Pattern pattern) {
574 Object forValidation = payload.get(propertyName);
575 final String noValidPayloadPropertyMsg = noValidPayloadMsg + ", " + propertyName + " property is not valid";
576 if (!(forValidation instanceof String)) {
577 throw new BadRequestException(noValidPayloadPropertyMsg);
579 if (!pattern.matcher((String) forValidation).matches()) {
580 throw new BadRequestException(noValidPayloadPropertyMsg);
584 private void validateUpdateVnfConfig(RequestDetails requestDetails) {
585 final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request";
587 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
588 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "request-parameters");
589 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "configuration-parameters");
592 private void validateConfigUpdateVnfPayloadProperty(Map payload, String noValidPayloadMsg, String propertyName) {
593 final String noValidPayloadPropertyMsg = noValidPayloadMsg+ ", "+ propertyName + " property is not valid";
594 if(!payload.containsKey(propertyName)) {
595 throw new BadRequestException( noValidPayloadPropertyMsg);
600 public MsoResponseWrapper deleteConfiguration(
601 org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper,
602 String serviceInstanceId,
603 String configurationId) {
605 String methodName = "deleteConfiguration";
606 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
608 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
609 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
610 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
612 return msoClientInterface.deleteConfiguration(requestDetailsWrapper, endpoint);
616 public MsoResponseWrapper setConfigurationActiveStatus(
617 RequestDetails requestDetails,
618 String serviceInstanceId,
619 String configurationId,
620 boolean isActivate) {
622 String methodName = "setConfigurationActiveStatus";
623 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
625 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
626 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
627 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
629 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
630 endpoint = endpoint + isActivateState;
632 return msoClientInterface.setConfigurationActiveStatus(requestDetails, endpoint);
636 public MsoResponseWrapper setServiceInstanceStatus(RequestDetails requestDetails , String serviceInstanceId, boolean isActivate) {
637 String methodName = "setServiceInstanceStatus";
638 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
640 String serviceEndpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
641 String endpoint = serviceEndpoint + "/" + serviceInstanceId;
643 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
644 endpoint = endpoint + isActivateState;
647 RestObject<String> restObjStr = new RestObject<>();
651 msoClientInterface.setServiceInstanceStatus(requestDetails , str, "", endpoint, restObjStr);
653 return MsoUtil.wrapResponse(restObjStr);
655 } catch (Exception e) {
656 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
657 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
663 public MsoResponseWrapper setPortOnConfigurationStatus(
664 RequestDetails requestDetails,
665 String serviceInstanceId,
666 String configurationId,
668 String methodName = "setPortOnConfigurationStatus";
669 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
671 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
672 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
673 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
675 String isEnablePortStatus = (isEnable ? ENABLE_PORT : DISABLE_PORT);
676 endpoint = endpoint + isEnablePortStatus;
678 return msoClientInterface.setPortOnConfigurationStatus(requestDetails, endpoint);
683 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentActivationRequestDetails(OperationalEnvironmentActivateInfo details) {
684 RequestDetails requestDetails = new RequestDetails();
685 RequestInfo requestInfo = new RequestInfo();
686 requestInfo.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
687 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
688 requestInfo.setRequestorId(details.getUserId());
689 requestDetails.setRequestInfo(requestInfo);
691 org.onap.vid.domain.mso.RelatedInstance relatedInstance = new org.onap.vid.domain.mso.RelatedInstance();
692 relatedInstance.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
693 relatedInstance.setInstanceId(details.getRelatedInstanceId());
694 relatedInstance.setInstanceName(details.getRelatedInstanceName());
695 requestDetails.setAdditionalProperty("relatedInstanceList", Collections.singletonList(ImmutableMap.of("relatedInstance", relatedInstance)));
697 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
698 requestParameters.setUserParams(null);
699 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
700 requestParameters.setAdditionalProperty("workloadContext", details.getWorkloadContext());
701 requestParameters.setAdditionalProperty("manifest", details.getManifest());
702 requestDetails.setRequestParameters(requestParameters);
704 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
706 debugRequestDetails(requestDetailsWrapper, logger);
708 return requestDetailsWrapper;
712 public String getOperationalEnvironmentActivationPath(OperationalEnvironmentActivateInfo details) {
713 String path = validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_ACTIVATE);
714 path = path.replace("<operational_environment_id>", details.getOperationalEnvironmentId());
719 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentDeactivationRequestDetails(OperationalEnvironmentDeactivateInfo details) {
720 RequestDetails requestDetails = new RequestDetails();
722 RequestInfo requestInfo = new RequestInfo();
723 requestInfo.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
724 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
725 requestInfo.setRequestorId(details.getUserId());
726 requestDetails.setRequestInfo(requestInfo);
728 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
729 requestParameters.setUserParams(null);
730 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
731 requestDetails.setRequestParameters(requestParameters);
732 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
733 debugRequestDetails(requestDetailsWrapper, logger);
734 return requestDetailsWrapper;
738 public String getCloudResourcesRequestsStatusPath(String requestId) {
739 String path = validateEndpointPath(MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS);
740 path = path.replace("<request_id>", requestId);
745 public String getOperationalEnvironmentDeactivationPath(OperationalEnvironmentDeactivateInfo details) {
746 String path = validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_DEACTIVATE);
747 path = path.replace("<operational_environment_id>", details.getOperationalEnvironmentId());
752 public String getOperationalEnvironmentCreationPath() {
753 return validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_CREATE);
759 public RequestDetailsWrapper<OperationEnvironmentRequestDetails> convertParametersToRequestDetails(OperationalEnvironmentController.OperationalEnvironmentCreateBody input, String userId) {
760 OperationEnvironmentRequestDetails.RequestInfo requestInfo = new OperationEnvironmentRequestDetails.RequestInfo(
761 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
762 input.getInstanceName(),
763 SOURCE_OPERATIONAL_ENVIRONMENT,
766 OperationEnvironmentRequestDetails.RelatedInstance relatedInstance = new OperationEnvironmentRequestDetails.RelatedInstance(
767 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
768 input.getEcompInstanceId(),
769 input.getEcompInstanceName());
771 List<OperationEnvironmentRequestDetails.RelatedInstance> relatedInstanceList = Collections.singletonList((relatedInstance));
773 OperationEnvironmentRequestDetails.RequestParameters requestParameters = new OperationEnvironmentRequestDetails.RequestParameters(
774 input.getOperationalEnvironmentType(),
775 input.getTenantContext(),
776 input.getWorkloadContext());
778 OperationEnvironmentRequestDetails requestDetails = new OperationEnvironmentRequestDetails(requestInfo, relatedInstanceList, requestParameters);
779 RequestDetailsWrapper<OperationEnvironmentRequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
780 debugRequestDetails(requestDetailsWrapper, logger);
781 return requestDetailsWrapper;
785 public MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
786 String methodName = "removeRelationshipFromServiceInstance";
787 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
789 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
790 String removeRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/removeRelationships";
792 return msoClientInterface.removeRelationshipFromServiceInstance(requestDetails, removeRelationshipsPath);
796 public MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
797 String methodName = "addRelationshipToServiceInstance";
798 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
800 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
801 String addRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/addRelationships";
803 return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
807 public enum RequestType {
809 CREATE_INSTANCE("createInstance"),
810 DELETE_INSTANCE("deleteInstance"),
811 REPLACE_INSTANCE("replaceInstance"),
812 UPDATE_INSTANCE("updateInstance"),
813 ACTIVATE_INSTANCE("activateInstance"),
814 DEACTIVATE_INSTANCE("deactivateInstance"),
815 APPLY_UPDATED_CONFIG("applyUpdatedConfig"),
816 IN_PLACE_SOFTWARE_UPDATE("inPlaceSoftwareUpdate"),
818 NOT_PROVIDED("not provided");
819 private final String value;
820 private static final Map<String, RequestType> CONSTANTS = new HashMap<>();
823 for (RequestType c: values()) {
824 CONSTANTS.put(c.value, c);
828 RequestType(String value) {
834 public String toString() {
839 public static RequestType fromValue(String value) {
840 RequestType constant = CONSTANTS.get(value);
841 if (constant == null) {
842 throw new IllegalArgumentException(value);