1 package org.onap.vid.mso;
3 import com.fasterxml.jackson.core.JsonProcessingException;
4 import com.fasterxml.jackson.databind.DeserializationFeature;
5 import com.fasterxml.jackson.databind.ObjectMapper;
6 import com.fasterxml.jackson.databind.SerializationFeature;
7 import com.google.common.collect.ImmutableList;
8 import com.google.common.collect.ImmutableMap;
9 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
10 import org.openecomp.portalsdk.core.util.SystemProperties;
11 import org.onap.vid.changeManagement.ChangeManagementRequest;
12 import org.onap.vid.changeManagement.RequestDetailsWrapper;
13 import org.onap.vid.controller.OperationalEnvironmentController;
14 import org.onap.vid.domain.mso.RequestInfo;
15 import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo;
16 import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo;
17 import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails;
18 import org.onap.vid.mso.rest.*;
19 import org.springframework.beans.factory.annotation.Autowired;
21 import javax.ws.rs.BadRequestException;
22 import java.text.DateFormat;
23 import java.text.SimpleDateFormat;
25 import java.util.regex.Pattern;
27 import static org.onap.vid.changeManagement.ChangeManagementRequest.MsoChangeManagementRequest;
28 import static org.onap.vid.controller.MsoController.*;
29 import static org.onap.vid.mso.MsoProperties.*;
31 public class MsoBusinessLogicImpl implements MsoBusinessLogic {
34 * The Constant dateFormat.
36 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
37 final static Pattern SOFTWARE_VERSION_PATTERN = Pattern.compile("^[A-Za-z0-9.\\-]+$");
38 final static Pattern NUMBER_PATTERN = Pattern.compile("^[0-9]+$");
39 private static final String ACTIVATE = "/activate";
40 private static final String DEACTIVATE = "/deactivate";
41 private static final String ENABLE_PORT = "/enablePort";
42 private static final String DISABLE_PORT = "/disablePort";
43 private final static String RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT = "operationalEnvironment";
44 private final static String SOURCE_OPERATIONAL_ENVIRONMENT = "VID";
45 final static private ObjectMapper objectMapper = new ObjectMapper();
48 * This should be replaced with mso client factory.
50 private final MsoInterface msoClientInterface;
54 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoBusinessLogicImpl.class);
57 public MsoBusinessLogicImpl(MsoInterface msoClientInterface) {
58 this.msoClientInterface = msoClientInterface;
61 static String validateEndpointPath(String endpointEnvVariable) {
62 String endpoint = SystemProperties.getProperty(endpointEnvVariable);
63 if (endpoint == null || endpoint.isEmpty()) {
64 throw new RuntimeException(endpointEnvVariable + " env variable is not defined");
69 // this function should get params from tosca and send them to instance at mso, then return success response.
71 public MsoResponseWrapper createSvcInstance(RequestDetails msoRequest) throws Exception {
72 String methodName = "createSvcInstance ";
73 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
77 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
78 } catch (Exception exception) {
82 return msoClientInterface.createSvcInstance(msoRequest, endpoint);
85 void validateLineOfBusiness(RequestDetails requestDetails) {
87 Object value = requestDetails.getAdditionalProperties();
89 for(String prop: ImmutableList.of("requestDetails", "lineOfBusiness", "lineOfBusinessName")) {
90 if(value==null ||!(value instanceof Map)) {
95 value = ((Map)value).get(prop);
99 if(value == null || value.toString().isEmpty()) {
100 throw new BadRequestException("lineOfBusiness is required");
106 public MsoResponseWrapper createVnf(RequestDetails requestDetails, String serviceInstanceId) throws Exception {
107 String methodName = "createVnf";
108 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
112 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
113 } catch (Exception exception) {
117 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
118 return msoClientInterface.createVnf(requestDetails, vnf_endpoint);
122 public MsoResponseWrapper createNwInstance(RequestDetails requestDetails, String serviceInstanceId) throws Exception {
123 String methodName = "createNwInstance";
124 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
128 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
129 } catch (Exception exception) {
133 String nw_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
134 return msoClientInterface.createNwInstance(requestDetails, nw_endpoint);
138 public MsoResponseWrapper createVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) throws Exception {
139 String methodName = "createVolumeGroupInstance";
140 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
144 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
145 } catch (Exception exception) {
149 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
150 vnf_endpoint = vnf_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
152 return msoClientInterface.createVolumeGroupInstance(requestDetails, vnf_endpoint);
156 public MsoResponseWrapper createVfModuleInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) throws Exception {
157 String methodName = "createVfModuleInstance";
158 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
162 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
163 } catch (Exception exception) {
167 String partial_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
168 String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
170 return msoClientInterface.createVfModuleInstance(requestDetails, vf_module_endpoint);
174 public MsoResponseWrapper createConfigurationInstance(RequestDetails requestDetails, String serviceInstanceId) throws Exception {
175 String methodName = "createConfigurationInstance";
176 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
178 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATIONS);
179 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
181 return msoClientInterface.createConfigurationInstance(requestDetails, endpoint);
185 public MsoResponseWrapper deleteSvcInstance(RequestDetails requestDetails, String serviceInstanceId) throws Exception {
186 String methodName = "deleteSvcInstance";
187 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
191 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
192 } catch (Exception exception) {
196 String svc_endpoint = endpoint + "/" + serviceInstanceId;
198 return msoClientInterface.deleteSvcInstance(requestDetails, svc_endpoint);
202 public MsoResponseWrapper deleteVnf(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) throws Exception {
203 String methodName = "deleteVnf";
204 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
208 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
209 } catch (Exception exception) {
212 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
213 vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId;
215 return msoClientInterface.deleteVnf(requestDetails, vnf_endpoint);
219 public MsoResponseWrapper deleteVfModule(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String vfModuleId) throws Exception {
220 String methodName = "deleteVfModule";
221 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
225 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE);
226 } catch (Exception exception) {
230 String vf__modules_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId).replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
232 String delete_vf_endpoint = vf__modules_endpoint + '/' + vfModuleId;
234 return msoClientInterface.deleteVfModule(requestDetails, delete_vf_endpoint);
238 public MsoResponseWrapper deleteVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId, String volumeGroupId) throws Exception {
239 String methodName = "deleteVolumeGroupInstance";
240 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
244 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE);
245 } catch (Exception exception) {
249 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
250 String vnf_endpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId);
251 String delete_volume_group_endpoint = vnf_endpoint + "/" + volumeGroupId;
253 return msoClientInterface.deleteVolumeGroupInstance(requestDetails, delete_volume_group_endpoint);
257 public MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String serviceInstanceId, String networkInstanceId) throws Exception {
258 String methodName = "deleteNwInstance";
259 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
263 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE);
264 } catch (Exception exception) {
268 String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
269 String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId;
271 return msoClientInterface.deleteNwInstance(requestDetails, delete_nw_endpoint);
275 public MsoResponseWrapper getOrchestrationRequest(String requestId) throws Exception {
276 String methodName = "getOrchestrationRequest";
277 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
278 MsoResponseWrapper w = null;
280 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
281 String path = p + "/" + requestId;
283 RestObject<String> restObjStr = new RestObject<String>();
284 String str = new String();
287 msoClientInterface.getOrchestrationRequest(str, "", path, restObjStr);
289 return MsoUtil.wrapResponse(restObjStr);
291 } catch (Exception e) {
292 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
293 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
299 public MsoResponseWrapper getOrchestrationRequests(String filterString) throws Exception {
300 String methodName = "getOrchestrationRequest";
301 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
302 MsoResponseWrapper w = null;
304 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
305 String path = p + filterString;
307 RestObject<String> restObjStr = new RestObject<String>();
308 String str = new String();
311 msoClientInterface.getOrchestrationRequest(str, "", path, restObjStr);
313 return MsoUtil.wrapResponse(restObjStr);
315 } catch (Exception e) {
316 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
317 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
323 public List<Request> getOrchestrationRequestsForDashboard() throws Exception {
324 String methodName = "getOrchestrationRequestsForDashboard";
325 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
326 List<Request> filteredOrchestrationRequests = new ArrayList<>();
328 String path = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
329 path += "filter=modelType:EQUALS:vnf";
330 RestObject<String> restObjStr = new RestObject<String>();
331 String str = new String();
334 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequestsForDashboard(str, "", path, restObjStr);
335 List<RequestWrapper> allOrchestrationRequests = deserializeOrchestrationRequestsJson(msoResponseWrapper.getEntity());
338 for (RequestWrapper currentRequest : allOrchestrationRequests) {
339 if ((currentRequest.getRequest() != null) && (currentRequest.getRequest().getRequestScope() == Request.RequestScope.VNF) && ((currentRequest.getRequest().getRequestType() ==
340 Request.RequestType.REPLACE_INSTANCE) || (currentRequest.getRequest().getRequestType() ==
341 Request.RequestType.UPDATE_INSTANCE))) {
342 filteredOrchestrationRequests.add(currentRequest.getRequest());
345 } catch (Exception e) {
346 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
347 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
349 return filteredOrchestrationRequests;
353 private List<RequestWrapper> deserializeOrchestrationRequestsJson(String orchestrationRequestsJson) throws Exception {
354 String methodName = "deserializeOrchestrationRequestsJson";
355 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");
357 ObjectMapper mapper = new ObjectMapper();
358 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
359 mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true);
360 RequestList requestList = mapper.readValue(orchestrationRequestsJson, RequestList.class);
361 return requestList.getRequestList();
366 public List<Task> getManualTasksByRequestId(String originalRequestId) throws Exception {
367 String methodName = "getManualTasksByRequestId";
368 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
371 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
372 String path = p + "?originalRequestId=" + originalRequestId;
374 RestObject<String> restObjStr = new RestObject<String>();
375 String str = new String();
378 MsoResponseWrapper msoResponseWrapper = msoClientInterface.getManualTasksByRequestId(str, "", path, restObjStr);
379 return deserializeManualTasksJson(msoResponseWrapper.getEntity());
381 } catch (Exception e) {
382 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
383 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
388 private List<Task> deserializeManualTasksJson(String manualTasksJson) throws Exception {
389 String methodName = "deserializeManualTasksJson";
390 logger.debug(dateFormat.format(new Date()) + "<== " + methodName + " start");
392 ObjectMapper mapper = new ObjectMapper();
393 TaskList taskList = mapper.readValue(manualTasksJson, TaskList.class);
394 return taskList.getTaskList();
399 public MsoResponseWrapper completeManualTask(RequestDetails requestDetails, String taskId) throws Exception {
400 String methodName = "completeManualTask";
401 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
402 MsoResponseWrapper w = null;
404 String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_MAN_TASKS);
405 String path = p + "/" + taskId + "/complete";
407 RestObject<String> restObjStr = new RestObject<String>();
408 String str = new String();
411 msoClientInterface.completeManualTask(requestDetails, str, "", path, restObjStr);
413 return MsoUtil.wrapResponse(restObjStr);
415 } catch (Exception e) {
416 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
417 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
423 public MsoResponseWrapper activateServiceInstance(RequestDetails requestDetails, String serviceInstanceId) throws Exception {
424 String methodName = "activateServiceInstance";
425 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
427 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
428 String activateServicePath = serviceEndpoint + "/" + serviceInstanceId + "/activate";
430 RestObject<String> restObjStr = new RestObject<>();
434 msoClientInterface.setServiceInstanceStatus(requestDetails, str, "", activateServicePath, restObjStr);
436 return MsoUtil.wrapResponse(restObjStr);
438 } catch (Exception e) {
439 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
440 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
447 public MsoResponseWrapperInterface updateVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) throws Exception {
448 String methodName = "updateVnf";
449 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
453 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_INSTANCE);
454 } catch (Exception exception) {
457 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
458 vnf_endpoint = vnf_endpoint + '/' + vnfInstanceId;
459 return msoClientInterface.updateVnf(requestDetails, vnf_endpoint);
463 public MsoResponseWrapperInterface replaceVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) throws Exception {
464 String methodName = "replaceVnf";
465 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
469 endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
470 } catch (Exception exception) {
473 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
474 vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
475 vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, MsoChangeManagementRequest.REPLACE);
476 return msoClientInterface.replaceVnf(requestDetails, vnf_endpoint);
479 public RequestDetailsWrapper generateInPlaceMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails) throws Exception {
480 validateUpdateVnfSoftwarePayload(requestDetails);
481 RequestDetails inPlaceSoftwareUpdateRequest = new RequestDetails();
482 inPlaceSoftwareUpdateRequest.setCloudConfiguration(requestDetails.getCloudConfiguration());
483 inPlaceSoftwareUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
484 inPlaceSoftwareUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
485 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
486 requestDetailsWrapper.requestDetails = inPlaceSoftwareUpdateRequest;
487 return requestDetailsWrapper;
491 public RequestDetailsWrapper generateConfigMsoRequest(org.onap.vid.changeManagement.RequestDetails requestDetails) throws Exception {
492 validateUpdateVnfConfig(requestDetails);
493 RequestDetails ConfigUpdateRequest = new RequestDetails();
494 ConfigUpdateRequest.setRequestParameters(requestDetails.getRequestParameters());
495 ConfigUpdateRequest.setRequestInfo(requestDetails.getRequestInfo());
496 RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper();
497 requestDetailsWrapper.requestDetails = ConfigUpdateRequest;
498 return requestDetailsWrapper;
502 public MsoResponseWrapperInterface updateVnfSoftware(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) throws Exception {
503 String methodName = "updateVnfSoftware";
504 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
505 String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.SOFTWARE_UPDATE); //workflow name in mso is different than workflow name in vid UI
506 RequestDetailsWrapper finalRequestDetails = generateInPlaceMsoRequest(requestDetails);
507 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
511 public MsoResponseWrapperInterface updateVnfConfig(org.onap.vid.changeManagement.RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) throws Exception {
512 String methodName = "updateVnfConfig";
513 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
514 RequestDetailsWrapper finalRequestDetails = generateConfigMsoRequest(requestDetails);
515 String vnf_endpoint = getChangeManagementEndpoint(serviceInstanceId, vnfInstanceId, MsoChangeManagementRequest.CONFIG_UPDATE);
516 return msoClientInterface.changeManagementUpdate(finalRequestDetails, vnf_endpoint);
519 private String getChangeManagementEndpoint(String serviceInstanceId, String vnfInstanceId, String vnfRequestType) {
520 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VNF_CHANGE_MANAGEMENT_INSTANCE);
521 String vnf_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId);
522 vnf_endpoint = vnf_endpoint.replace(VNF_INSTANCE_ID, vnfInstanceId);
523 vnf_endpoint = vnf_endpoint.replace(REQUEST_TYPE, vnfRequestType);
527 private Map getChangeManagementPayload(RequestDetails requestDetails, String message) throws Exception{
528 if(requestDetails.getRequestParameters()==null||requestDetails.getRequestParameters().getAdditionalProperties()==null){
529 throw new BadRequestException(message);
531 Object payloadRaw=requestDetails.getRequestParameters().getAdditionalProperties().get("payload");
533 return objectMapper.readValue((String)payloadRaw,Map.class);
535 catch(Exception exception){
536 throw new BadRequestException(message);
540 private void validateUpdateVnfSoftwarePayload(RequestDetails requestDetails) throws Exception {
541 final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE + " request";
543 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
544 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "existing-software-version", SOFTWARE_VERSION_PATTERN);
545 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "new-software-version", SOFTWARE_VERSION_PATTERN);
547 //if "operations-timeout" is not integer, trying to read it as String that represent a number
548 if (!(payload.get("operations-timeout") instanceof Integer)) {
549 validateUpdateVnfSoftwarePayloadProperty(payload, noValidPayloadMsg, "operations-timeout", NUMBER_PATTERN);
554 private void validateUpdateVnfSoftwarePayloadProperty(Map payload, String noValidPayloadMsg, String propertyName, Pattern pattern) {
555 Object forValidation = payload.get(propertyName);
556 final String noValidPayloadPropertyMsg = noValidPayloadMsg + ", " + propertyName + " property is not valid";
557 if (!(forValidation instanceof String)) {
558 throw new BadRequestException(noValidPayloadPropertyMsg);
560 if (!pattern.matcher((String) forValidation).matches()) {
561 throw new BadRequestException(noValidPayloadPropertyMsg);
565 private void validateUpdateVnfConfig(RequestDetails requestDetails) throws Exception {
566 final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request";
568 Map payload = getChangeManagementPayload(requestDetails, noValidPayloadMsg);
569 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "request-parameters");
570 validateConfigUpdateVnfPayloadProperty(payload, noValidPayloadMsg, "configuration-parameters");
573 private void validateConfigUpdateVnfPayloadProperty(Map payload, String noValidPayloadMsg, String propertyName) {
574 Object forValidation = payload.get(propertyName);
575 final String noValidPayloadPropertyMsg = noValidPayloadMsg+ ", "+ propertyName + " property is not valid";
576 if(!payload.containsKey(propertyName)) {
577 throw new BadRequestException( noValidPayloadPropertyMsg);
582 public MsoResponseWrapper deleteConfiguration(
583 RequestDetails requestDetails,
584 String serviceInstanceId,
585 String configurationId) throws Exception {
587 String methodName = "deleteConfiguration";
588 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
590 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
591 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
592 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
594 return msoClientInterface.deleteConfiguration(requestDetails, endpoint);
598 public MsoResponseWrapper setConfigurationActiveStatus(
599 RequestDetails requestDetails,
600 String serviceInstanceId,
601 String configurationId,
602 boolean isActivate) throws Exception {
604 String methodName = "setConfigurationActiveStatus";
605 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
607 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
608 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
609 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
611 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
612 endpoint = endpoint + isActivateState;
614 return msoClientInterface.setConfigurationActiveStatus(requestDetails, endpoint);
618 public MsoResponseWrapper setServiceInstanceStatus(RequestDetails requestDetails , String serviceInstanceId, boolean isActivate)throws Exception{
619 String methodName = "setServiceInstanceStatus";
620 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
622 String serviceEndpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE);
623 String endpoint = serviceEndpoint + "/" + serviceInstanceId;
625 String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
626 endpoint = endpoint + isActivateState;
629 RestObject<String> restObjStr = new RestObject<>();
633 msoClientInterface.setServiceInstanceStatus(requestDetails , str, "", endpoint, restObjStr);
635 return MsoUtil.wrapResponse(restObjStr);
637 } catch (Exception e) {
638 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
639 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
645 public MsoResponseWrapper setPortOnConfigurationStatus(
646 RequestDetails requestDetails,
647 String serviceInstanceId,
648 String configurationId,
649 boolean isEnable) throws Exception {
650 String methodName = "setPortOnConfigurationStatus";
651 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
653 String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_CONFIGURATION_INSTANCE);
654 endpoint = endpoint.replace(SVC_INSTANCE_ID, serviceInstanceId);
655 endpoint = endpoint.replace(CONFIGURATION_ID, configurationId);
657 String isEnablePortStatus = (isEnable ? ENABLE_PORT : DISABLE_PORT);
658 endpoint = endpoint + isEnablePortStatus;
660 return msoClientInterface.setPortOnConfigurationStatus(requestDetails, endpoint);
665 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentActivationRequestDetails(OperationalEnvironmentActivateInfo details) {
666 RequestDetails requestDetails = new RequestDetails();
667 RequestInfo requestInfo = new RequestInfo();
668 requestInfo.setAdditionalProperty("resourceType", RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
669 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
670 requestInfo.setRequestorId(details.getUserId());
671 requestDetails.setRequestInfo(requestInfo);
673 org.onap.vid.domain.mso.RelatedInstance relatedInstance = new org.onap.vid.domain.mso.RelatedInstance();
674 relatedInstance.setAdditionalProperty("resourceType", RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
675 relatedInstance.setInstanceId(details.getRelatedInstanceId());
676 relatedInstance.setInstanceName(details.getRelatedInstanceName());
677 requestDetails.setAdditionalProperty("relatedInstanceList", Collections.singletonList(ImmutableMap.of("relatedInstance", relatedInstance)));
679 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
680 requestParameters.setUserParams(null);
681 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
682 requestParameters.setAdditionalProperty("workloadContext", details.getWorkloadContext());
683 requestParameters.setAdditionalProperty("manifest", details.getManifest());
684 requestDetails.setRequestParameters(requestParameters);
686 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
688 debugRequestDetails(requestDetailsWrapper);
690 return requestDetailsWrapper;
694 public String getOperationalEnvironmentActivationPath(OperationalEnvironmentActivateInfo details) {
695 String path = validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_ACTIVATE);
696 path = path.replace("<operational_environment_id>", details.getOperationalEnvironmentId());
701 public RequestDetailsWrapper<RequestDetails> createOperationalEnvironmentDeactivationRequestDetails(OperationalEnvironmentDeactivateInfo details) {
702 RequestDetails requestDetails = new RequestDetails();
704 RequestInfo requestInfo = new RequestInfo();
705 requestInfo.setAdditionalProperty("resourceType", RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT);
706 requestInfo.setSource(SOURCE_OPERATIONAL_ENVIRONMENT);
707 requestInfo.setRequestorId(details.getUserId());
708 requestDetails.setRequestInfo(requestInfo);
710 org.onap.vid.domain.mso.RequestParameters requestParameters = new org.onap.vid.domain.mso.RequestParameters();
711 requestParameters.setUserParams(null);
712 requestParameters.setAdditionalProperty("operationalEnvironmentType", "VNF");
713 requestDetails.setRequestParameters(requestParameters);
714 RequestDetailsWrapper<RequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
715 debugRequestDetails(requestDetailsWrapper);
716 return requestDetailsWrapper;
720 public String getCloudResourcesRequestsStatusPath(String requestId) {
721 String path = validateEndpointPath(MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS);
722 path = path.replace("<request_id>", requestId);
727 public String getOperationalEnvironmentDeactivationPath(OperationalEnvironmentDeactivateInfo details) {
728 String path = validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_DEACTIVATE);
729 path = path.replace("<operational_environment_id>", details.getOperationalEnvironmentId());
733 private void debugRequestDetails(Object requestDetails) {
734 if (logger.isDebugEnabled()) {
735 String requestDetailsAsString;
737 requestDetailsAsString = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(requestDetails);
738 } catch (JsonProcessingException e) {
739 requestDetailsAsString = "error: cannot stringify RequestDetails";
741 logger.debug(EELFLoggerDelegate.debugLogger, "requestDetailsAsString: {}", requestDetailsAsString);
746 public String getOperationalEnvironmentCreationPath() {
747 String path = validateEndpointPath(MSO_REST_API_OPERATIONAL_ENVIRONMENT_CREATE);
752 public RequestDetailsWrapper<OperationEnvironmentRequestDetails> convertParametersToRequestDetails(OperationalEnvironmentController.OperationalEnvironmentCreateBody input, String userId) {
753 OperationEnvironmentRequestDetails.RequestInfo requestInfo = new OperationEnvironmentRequestDetails.RequestInfo(
754 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
755 input.getInstanceName(),
756 SOURCE_OPERATIONAL_ENVIRONMENT,
759 OperationEnvironmentRequestDetails.RelatedInstance relatedInstance = new OperationEnvironmentRequestDetails.RelatedInstance(
760 RESOURCE_TYPE_OPERATIONAL_ENVIRONMENT,
761 input.getEcompInstanceId(),
762 input.getEcompInstanceName());
764 List<OperationEnvironmentRequestDetails.RelatedInstance> relatedInstanceList = Collections.singletonList((relatedInstance));
766 OperationEnvironmentRequestDetails.RequestParameters requestParameters = new OperationEnvironmentRequestDetails.RequestParameters(
767 input.getOperationalEnvironmentType(),
768 input.getTenantContext(),
769 input.getWorkloadContext());
771 OperationEnvironmentRequestDetails requestDetails = new OperationEnvironmentRequestDetails(requestInfo, relatedInstanceList, requestParameters);
772 RequestDetailsWrapper<OperationEnvironmentRequestDetails> requestDetailsWrapper = new RequestDetailsWrapper<>(requestDetails);
773 debugRequestDetails(requestDetailsWrapper);
774 return requestDetailsWrapper;
778 public MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String serviceInstanceId) throws Exception {
779 String methodName = "removeRelationshipFromServiceInstance";
780 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
782 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
783 String removeRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/removeRelationships";
785 return msoClientInterface.removeRelationshipFromServiceInstance(requestDetails, removeRelationshipsPath);
789 public MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String serviceInstanceId) throws Exception {
790 String methodName = "addRelationshipToServiceInstance";
791 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
793 String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE);
794 String addRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/addRelationships";
796 return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);