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(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);
188 return msoClientInterface.createVfModuleInstance(requestDetails, vf_module_endpoint);
191 public MsoResponseWrapper createConfigurationInstance(org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String serviceInstanceId) {
192 String methodName = "createConfigurationInstance";
193 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
195 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATIONS);
196 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
198 return msoClientInterface.createConfigurationInstance(requestDetailsWrapper, endpoint);
202 public MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String serviceInstanceId) {
203 String methodName = "deleteE2eSvcInstance";
204 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
207 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_E2E_SVC_INSTANCE) + "/" + serviceInstanceId;
209 return msoClientInterface.deleteE2eSvcInstance(requestDetails, endpoint);
213 public MsoResponseWrapper deleteSvcInstance(RequestDetails requestDetails, String serviceInstanceId, String serviceStatus) {
214 String methodName = "deleteSvcInstance";
215 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
218 if (featureManager.isActive(FLAG_UNASSIGN_SERVICE)){
219 endpoint = validateEndpointPath(MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE);
220 if (shouldUnassignService(serviceStatus)){
221 logger.debug(EELFLoggerDelegate.debugLogger, "unassign service");
222 String svc_endpoint = endpoint + "/" + serviceInstanceId + "/unassign";
223 return msoClientInterface.unassignSvcInstance(requestDetails, svc_endpoint);
226 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
229 String svc_endpoint = endpoint + "/" + serviceInstanceId;
230 return msoClientInterface.deleteSvcInstance(requestDetails, svc_endpoint);
233 private boolean shouldUnassignService(String serviceStatus) {
234 return ImmutableList.of("created","pendingdelete","pending-delete", "assigned").contains(serviceStatus.toLowerCase());
238 public MsoResponseWrapper deleteVnf(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
239 String methodName = "deleteVnf";
240 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
243 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
244 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
245 vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId;
247 return msoClientInterface.deleteVnf(requestDetails, vnf_endpoint);
251 public MsoResponseWrapper deleteVfModule(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String vfModuleId) {
252 String methodName = "deleteVfModule";
253 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
256 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
258 String vf__modules_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId).replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
260 String delete_vf_endpoint = vf__modules_endpoint + '/' + vfModuleId;
262 return msoClientInterface.deleteVfModule(requestDetails, delete_vf_endpoint);
266 public MsoResponseWrapper deleteVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String volumeGroupId) {
267 String methodName = "deleteVolumeGroupInstance";
268 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
271 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
273 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
274 String vnf_endpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
275 String delete_volume_group_endpoint = vnf_endpoint + "/" + volumeGroupId;
277 return msoClientInterface.deleteVolumeGroupInstance(requestDetails, delete_volume_group_endpoint);
281 public MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String serviceInstanceId, String networkInstanceId) {
282 String methodName = "deleteNwInstance";
283 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
286 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
288 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
289 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
291 return msoClientInterface.deleteNwInstance(requestDetails, delete_nw_endpoint);
295 public MsoResponseWrapper getOrchestrationRequest(String requestId) {
296 String methodName = "getOrchestrationRequest";
297 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
299 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
300 String path = p + "/" + requestId;
302 return msoClientInterface.getOrchestrationRequest(path);
304 } catch (Exception e) {
305 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
306 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
312 public MsoResponseWrapper getOrchestrationRequests(String filterString) {
313 String methodName = "getOrchestrationRequest";
314 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
316 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
317 String path = p + filterString;
319 return msoClientInterface.getOrchestrationRequest(path);
321 } catch (Exception e) {
322 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
323 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
329 public List<Request> getOrchestrationRequestsForDashboard() {
330 String methodName = "getOrchestrationRequestsForDashboard";
331 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
332 List<Request> filteredOrchestrationRequests = new ArrayList<>();
334 String path = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
335 path += "filter=modelType:EQUALS:vnf";
336 RestObject<String> restObjStr = new RestObject<>();
337 String str = new String();
340 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequestsForDashboard(str, "", path, restObjStr);
341 List<RequestWrapper> allOrchestrationRequests = deserializeOrchestrationRequestsJson(msoResponseWrapper.getEntity());
343 final ImmutableList<String> suppoertedRequestTypes = ImmutableList.of(
344 RequestType.REPLACE_INSTANCE.toString().toUpperCase(),
345 RequestType.UPDATE_INSTANCE.toString().toUpperCase(),
346 RequestType.APPLY_UPDATED_CONFIG.toString().toUpperCase(),
347 RequestType.IN_PLACE_SOFTWARE_UPDATE.toString().toUpperCase()
350 for (RequestWrapper currentRequest : allOrchestrationRequests) {
351 if (currentRequest.getRequest() != null
352 && "vnf".equalsIgnoreCase(currentRequest.getRequest().getRequestScope())
353 && suppoertedRequestTypes.contains(upperCase(currentRequest.getRequest().getRequestType()))
355 filteredOrchestrationRequests.add(currentRequest.getRequest());
358 } catch (Exception e) {
359 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
360 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
362 return filteredOrchestrationRequests;
365 private List<RequestWrapper> deserializeOrchestrationRequestsJson(String orchestrationRequestsJson) {
366 String methodName = "deserializeOrchestrationRequestsJson";
367 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
369 ObjectMapper mapper = new ObjectMapper();
370 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
371 mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
372 RequestList requestList = null;
374 requestList = mapper.readValue(orchestrationRequestsJson, RequestList.class);
375 } catch (IOException e) {
376 throw new GenericUncheckedException(e);
378 return requestList.getRequestList();
383 public List<Task> getManualTasksByRequestId(String originalRequestId) {
384 String methodName = "getManualTasksByRequestId";
385 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
388 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
389 String path = p + "?originalRequestId=" + originalRequestId;
391 RestObject<String> restObjStr = new RestObject<>();
392 String str = new String();
395 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getManualTasksByRequestId(str, "", path, restObjStr);
396 return deserializeManualTasksJson(msoResponseWrapper.getEntity());
398 } catch (Exception e) {
399 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
400 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
405 private List<Task> deserializeManualTasksJson(String manualTasksJson) {
406 String methodName = "deserializeManualTasksJson";
407 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START);
409 ObjectMapper mapper = new ObjectMapper();
411 TaskList taskList = mapper.readValue(manualTasksJson, TaskList.class);
412 return taskList.getTaskList();
413 } catch (IOException e) {
414 throw new GenericUncheckedException(e);
420 public MsoResponseWrapper completeManualTask(RequestDetails requestDetails, String taskId) {
421 String methodName = "completeManualTask";
422 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
424 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
425 String path = p + "/" + taskId + "/complete";
427 RestObject<String> restObjStr = new RestObject<>();
428 String str = new String();
431 msoClientInterface.completeManualTask(requestDetails, str, "", path, restObjStr);
433 return MsoUtil.wrapResponse(restObjStr);
435 } catch (Exception e) {
436 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
437 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
443 public MsoResponseWrapper activateServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
444 String methodName = "activateServiceInstance";
445 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
447 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
448 String activateServicePath = serviceEndpoint + "/" + serviceInstanceId + ACTIVATE;
450 RestObject<String> restObjStr = new RestObject<>();
454 msoClientInterface.setServiceInstanceStatus(requestDetails, str, "", activateServicePath, restObjStr);
456 return MsoUtil.wrapResponse(restObjStr);
458 } catch (Exception e) {
459 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
460 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
467 public MsoResponseWrapperInterface updateVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
468 String methodName = "updateVnf";
469 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
472 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
473 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
474 vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId;
475 return msoClientInterface.updateVnf(requestDetails, vnf_endpoint);
479 public MsoResponseWrapperInterface replaceVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
480 String methodName = "replaceVnf";
481 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
484 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
485 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
486 vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
487 vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, MsoChangeManagementRequest.REPLACE);
488 return msoClientInterface.replaceVnf(requestDetails, vnf_endpoint);
491 public RequestDetailsWrapper generateInPlaceMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails) {
492 validateUpdateVnfSoftwarePayload(requestDetails);
493 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
494 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
495 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
496 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
497 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
498 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
499 return requestDetailsWrapper;
503 public RequestDetailsWrapper generateConfigMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails) {
504 validateUpdateVnfConfig(requestDetails);
505 RequestDetails ConfigUpdateRequest = new RequestDetails();
506 ConfigUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
507 ConfigUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
508 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
509 requestDetailsWrapper.requestDetails = ConfigUpdateRequest;
510 return requestDetailsWrapper;
518 public MsoResponseWrapperInterface updateVnfSoftware(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
519 String methodName = "updateVnfSoftware";
520 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
521 String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.SOFTWARE_UPDATE); //workflow name in mso is different than workflow name in vid UI
522 RequestDetailsWrapper finalRequestDetails = generateInPlaceMsoRequest(requestDetails);
523 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
527 public MsoResponseWrapperInterface updateVnfConfig(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) {
528 String methodName = "updateVnfConfig";
529 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
530 RequestDetailsWrapper finalRequestDetails = generateConfigMsoRequest(requestDetails);
531 String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.CONFIG_UPDATE);
532 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
535 private String getChangeManagementEndpoint(String serviceInstanceId, String vnfInstanceId, String vnfRequestType) {
536 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
537 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
538 vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
539 vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, vnfRequestType);
543 private Map getChangeManagementPayload(RequestDetails requestDetails, String message){
544 if(requestDetails.getRequestParameters()==null||requestDetails.getRequestParameters().getAdditionalProperties()==null){
545 throw new BadRequestException(message);
547 Object payloadRaw=requestDetails.getRequestParameters().getAdditionalProperties().get("payload");
549 return objectMapper.readValue((String)payloadRaw,Map.class);
551 catch(Exception exception){
552 throw new BadRequestException(message);
556 private void validateUpdateVnfSoftwarePayload(RequestDetails requestDetails) {
557 final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE + " request";
559 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
560 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "existing_software_version", SOFTWARE_VERSION_PATTERN);
561 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "new_software_version", SOFTWARE_VERSION_PATTERN);
563 //if "operations_timeout" is not integer, trying to read it as String that represent a number
564 if (!(payload.get("operations_timeout") instanceof Integer)) {
565 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "operations_timeout", NUMBER_PATTERN);
569 private void validateUpdateVnfSoftwarePayloadProperty(Map payload, String noValidPayloadMsg, String propertyName, Pattern pattern) {
570 Object forValidation = payload.get(propertyName);
571 final String noValidPayloadPropertyMsg = noValidPayloadMsg + ", " + propertyName + " property is not valid";
572 if (!(forValidation instanceof String)) {
573 throw new BadRequestException(noValidPayloadPropertyMsg);
575 if (!pattern.matcher((String) forValidation).matches()) {
576 throw new BadRequestException(noValidPayloadPropertyMsg);
580 private void validateUpdateVnfConfig(RequestDetails requestDetails) {
581 final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request";
583 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
584 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "request-parameters");
585 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "configuration-parameters");
588 private void validateConfigUpdateVnfPayloadProperty(Map payload, String noValidPayloadMsg, String propertyName) {
589 final String noValidPayloadPropertyMsg = noValidPayloadMsg+ ", "+ propertyName + " property is not valid";
590 if(!payload.containsKey(propertyName)) {
591 throw new BadRequestException( noValidPayloadPropertyMsg);
596 public MsoResponseWrapper deleteConfiguration(
597 org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper,
598 String serviceInstanceId,
599 String configurationId) {
601 String methodName = "deleteConfiguration";
602 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
604 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
605 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
606 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
608 return msoClientInterface.deleteConfiguration(requestDetailsWrapper, endpoint);
612 public MsoResponseWrapper setConfigurationActiveStatus(
613 RequestDetails requestDetails,
614 String serviceInstanceId,
615 String configurationId,
616 boolean isActivate) {
618 String methodName = "setConfigurationActiveStatus";
619 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
621 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
622 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
623 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
625 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
626 endpoint = endpoint + isActivateState;
628 return msoClientInterface.setConfigurationActiveStatus(requestDetails, endpoint);
632 public MsoResponseWrapper setServiceInstanceStatus(RequestDetails requestDetails , String serviceInstanceId, boolean isActivate) {
633 String methodName = "setServiceInstanceStatus";
634 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
636 String serviceEndpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
637 String endpoint = serviceEndpoint + "/" + serviceInstanceId;
639 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
640 endpoint = endpoint + isActivateState;
643 RestObject<String> restObjStr = new RestObject<>();
647 msoClientInterface.setServiceInstanceStatus(requestDetails , str, "", endpoint, restObjStr);
649 return MsoUtil.wrapResponse(restObjStr);
651 } catch (Exception e) {
652 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
653 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
659 public MsoResponseWrapper setPortOnConfigurationStatus(
660 RequestDetails requestDetails,
661 String serviceInstanceId,
662 String configurationId,
664 String methodName = "setPortOnConfigurationStatus";
665 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
667 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
668 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
669 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
671 String isEnablePortStatus = (isEnable ? ENABLE_PORT : DISABLE_PORT);
672 endpoint = endpoint + isEnablePortStatus;
674 return msoClientInterface.setPortOnConfigurationStatus(requestDetails, endpoint);
679 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentActivationRequestDetails(OperationalEnvironmentActivateInfo details) {
680 RequestDetails requestDetails = new RequestDetails();
681 RequestInfo requestInfo = new RequestInfo();
682 requestInfo.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
683 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
684 requestInfo.setRequestorId(details.getUserId());
685 requestDetails.setRequestInfo(requestInfo);
687 org.onap.vid.domain.mso.RelatedInstance relatedInstance = new org.onap.vid.domain.mso.RelatedInstance();
688 relatedInstance.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
689 relatedInstance.setInstanceId(details.getRelatedInstanceId());
690 relatedInstance.setInstanceName(details.getRelatedInstanceName());
691 requestDetails.setAdditionalProperty("relatedInstanceList", Collections.singletonList(ImmutableMap.of("relatedInstance", relatedInstance)));
693 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
694 requestParameters.setUserParams(null);
695 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
696 requestParameters.setAdditionalProperty("workloadContext", details.getWorkloadContext());
697 requestParameters.setAdditionalProperty("manifest", details.getManifest());
698 requestDetails.setRequestParameters(requestParameters);
700 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
702 debugRequestDetails(requestDetailsWrapper, logger);
704 return requestDetailsWrapper;
708 public String getOperationalEnvironmentActivationPath(OperationalEnvironmentActivateInfo details) {
709 String path = validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_ACTIVATE);
710 path = path.replace("<operational_environment_id>", details.getOperationalEnvironmentId());
715 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentDeactivationRequestDetails(OperationalEnvironmentDeactivateInfo details) {
716 RequestDetails requestDetails = new RequestDetails();
718 RequestInfo requestInfo = new RequestInfo();
719 requestInfo.setAdditionalProperty(RESOURCE_TYPE, RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
720 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
721 requestInfo.setRequestorId(details.getUserId());
722 requestDetails.setRequestInfo(requestInfo);
724 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
725 requestParameters.setUserParams(null);
726 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
727 requestDetails.setRequestParameters(requestParameters);
728 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
729 debugRequestDetails(requestDetailsWrapper, logger);
730 return requestDetailsWrapper;
734 public String getCloudResourcesRequestsStatusPath(String requestId) {
735 String path = validateEndpointPath(MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS);
736 path = path.replace("<request_id>", requestId);
741 public String getOperationalEnvironmentDeactivationPath(OperationalEnvironmentDeactivateInfo details) {
742 String path = validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_DEACTIVATE);
743 path = path.replace("<operational_environment_id>", details.getOperationalEnvironmentId());
748 public String getOperationalEnvironmentCreationPath() {
749 return validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_CREATE);
755 public RequestDetailsWrapper<OperationEnvironmentRequestDetails> convertParametersToRequestDetails(OperationalEnvironmentController.OperationalEnvironmentCreateBody input, String userId) {
756 OperationEnvironmentRequestDetails.RequestInfo requestInfo = new OperationEnvironmentRequestDetails.RequestInfo(
757 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
758 input.getInstanceName(),
759 SOURCE_OPERATIONAL_ENVIRONMENT,
762 OperationEnvironmentRequestDetails.RelatedInstance relatedInstance = new OperationEnvironmentRequestDetails.RelatedInstance(
763 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
764 input.getEcompInstanceId(),
765 input.getEcompInstanceName());
767 List<OperationEnvironmentRequestDetails.RelatedInstance> relatedInstanceList = Collections.singletonList((relatedInstance));
769 OperationEnvironmentRequestDetails.RequestParameters requestParameters = new OperationEnvironmentRequestDetails.RequestParameters(
770 input.getOperationalEnvironmentType(),
771 input.getTenantContext(),
772 input.getWorkloadContext());
774 OperationEnvironmentRequestDetails requestDetails = new OperationEnvironmentRequestDetails(requestInfo, relatedInstanceList, requestParameters);
775 RequestDetailsWrapper<OperationEnvironmentRequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
776 debugRequestDetails(requestDetailsWrapper, logger);
777 return requestDetailsWrapper;
781 public MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
782 String methodName = "removeRelationshipFromServiceInstance";
783 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
785 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
786 String removeRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/removeRelationships";
788 return msoClientInterface.removeRelationshipFromServiceInstance(requestDetails, removeRelationshipsPath);
792 public MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String serviceInstanceId) {
793 String methodName = "addRelationshipToServiceInstance";
794 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START);
796 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
797 String addRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/addRelationships";
799 return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
803 public enum RequestType {
805 CREATE_INSTANCE("createInstance"),
806 DELETE_INSTANCE("deleteInstance"),
807 REPLACE_INSTANCE("replaceInstance"),
808 UPDATE_INSTANCE("updateInstance"),
809 ACTIVATE_INSTANCE("activateInstance"),
810 DEACTIVATE_INSTANCE("deactivateInstance"),
811 APPLY_UPDATED_CONFIG("applyUpdatedConfig"),
812 IN_PLACE_SOFTWARE_UPDATE("inPlaceSoftwareUpdate"),
814 NOT_PROVIDED("not provided");
815 private final String value;
816 private static final Map<String, RequestType> CONSTANTS = new HashMap<>();
819 for (RequestType c: values()) {
820 CONSTANTS.put(c.value, c);
824 RequestType(String value) {
830 public String toString() {
835 public static RequestType fromValue(String value) {
836 RequestType constant = CONSTANTS.get(value);
837 if (constant == null) {
838 throw new IllegalArgumentException(value);