X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=vid-app-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvid%2Fmso%2FMsoBusinessLogicImpl.java;h=3d980dce80ef7ea161870f9d9fc85c52538791aa;hb=497e040b5569b0b0139a5cbc8115a63bc7f99244;hp=ad07eacae897f9982df0beaf2d1e11ec03d0e7fa;hpb=30794f9184dc2220a557ba5610a434c2a2bac801;p=vid.git diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java index ad07eacae..3d980dce8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java @@ -8,9 +8,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,44 +20,76 @@ */ package org.onap.vid.mso; +import static com.fasterxml.jackson.module.kotlin.ExtensionsKt.jacksonObjectMapper; +import static java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toList; +import static org.apache.commons.lang.StringUtils.upperCase; +import static org.onap.vid.changeManagement.ChangeManagementRequest.MsoChangeManagementRequest; +import static org.onap.vid.controller.MsoController.CONFIGURATION_ID; +import static org.onap.vid.controller.MsoController.REQUEST_TYPE; +import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID; +import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID; +import static org.onap.vid.controller.MsoController.WORKFLOW_ID; +import static org.onap.vid.mso.MsoProperties.MSO_REST_API_CLOUD_RESOURCES_REQUEST_STATUS; +import static org.onap.vid.mso.MsoProperties.MSO_REST_API_OPERATIONAL_ENVIRONMENT_ACTIVATE; +import static org.onap.vid.mso.MsoProperties.MSO_REST_API_OPERATIONAL_ENVIRONMENT_CREATE; +import static org.onap.vid.mso.MsoProperties.MSO_REST_API_OPERATIONAL_ENVIRONMENT_DEACTIVATE; +import static org.onap.vid.mso.MsoProperties.MSO_REST_API_WORKFLOW_SPECIFICATIONS; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; +import static org.onap.vid.utils.Logging.debugRequestDetails; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import io.joshworks.restclient.http.HttpResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.ws.rs.BadRequestException; +import org.apache.commons.collections4.ListUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.vid.aai.ExceptionWithRequestInfo; +import org.onap.vid.aai.HttpResponseWithRequestInfo; import org.onap.vid.changeManagement.ChangeManagementRequest; import org.onap.vid.changeManagement.RequestDetailsWrapper; -import org.onap.vid.changeManagement.UIWorkflowsRequest; import org.onap.vid.changeManagement.WorkflowRequestDetail; -import org.onap.vid.controller.ControllersUtils; import org.onap.vid.controller.OperationalEnvironmentController; import org.onap.vid.exceptions.GenericUncheckedException; -import org.onap.vid.model.RequestReferencesContainer; +import org.onap.vid.model.SOWorkflowList; import org.onap.vid.model.SoftDeleteRequest; -import org.onap.vid.mso.model.*; +import org.onap.vid.model.probes.ErrorMetadata; +import org.onap.vid.model.probes.ExternalComponentStatus; +import org.onap.vid.model.probes.HttpRequestMetadata; +import org.onap.vid.model.probes.StatusMetadata; +import org.onap.vid.mso.model.CloudConfiguration; +import org.onap.vid.mso.model.ModelInfo; +import org.onap.vid.mso.model.OperationalEnvironmentActivateInfo; +import org.onap.vid.mso.model.OperationalEnvironmentDeactivateInfo; +import org.onap.vid.mso.model.RequestInfo; +import org.onap.vid.mso.model.RequestParameters; import org.onap.vid.mso.rest.OperationalEnvironment.OperationEnvironmentRequestDetails; -import org.onap.vid.mso.rest.*; +import org.onap.vid.mso.rest.RelatedInstance; +import org.onap.vid.mso.rest.Request; +import org.onap.vid.mso.rest.RequestDetails; +import org.onap.vid.mso.rest.RequestList; +import org.onap.vid.mso.rest.RequestWrapper; +import org.onap.vid.mso.rest.Task; +import org.onap.vid.mso.rest.TaskList; +import org.onap.vid.utils.Logging; import org.springframework.beans.factory.annotation.Autowired; -import org.togglz.core.manager.FeatureManager; - -import javax.ws.rs.BadRequestException; -import java.io.IOException; -import java.util.*; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static java.util.stream.Collectors.collectingAndThen; -import static java.util.stream.Collectors.toList; -import static org.apache.commons.lang.StringUtils.upperCase; -import static org.onap.vid.changeManagement.ChangeManagementRequest.MsoChangeManagementRequest; -import static org.onap.vid.controller.MsoController.*; -import static org.onap.vid.mso.MsoProperties.*; -import static org.onap.vid.properties.Features.FLAG_UNASSIGN_SERVICE; -import static org.onap.vid.utils.Logging.debugRequestDetails; +import org.springframework.http.HttpStatus; public class MsoBusinessLogicImpl implements MsoBusinessLogic { @@ -89,15 +121,13 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { * This should be replaced with mso client factory. */ private final MsoInterface msoClientInterface; - FeatureManager featureManager; @Autowired - public MsoBusinessLogicImpl(MsoInterface msoClientInterface, FeatureManager featureManager) { + public MsoBusinessLogicImpl(MsoInterface msoClientInterface) { this.msoClientInterface = msoClientInterface; - this.featureManager = featureManager; } - public static String validateEndpointPath(String endpointEnvVariable) { + public static String validateEndpointPath(String endpointEnvVariable) { String endpoint = SystemProperties.getProperty(endpointEnvVariable); if (endpoint == null || endpoint.isEmpty()) { throw new GenericUncheckedException(endpointEnvVariable + " env variable is not defined"); @@ -110,7 +140,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { public MsoResponseWrapper createSvcInstance(RequestDetails msoRequest) { logInvocationInDebug("createSvcInstance"); - String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE); + String endpoint = validateEndpointPath(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE); return msoClientInterface.createSvcInstance(msoRequest, endpoint); } @@ -137,17 +167,19 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { public MsoResponseWrapper createNwInstance(RequestDetails requestDetails, String serviceInstanceId) { logInvocationInDebug("createNwInstance"); - String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE); + String endpoint; + endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE); - String nw_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - return msoClientInterface.createNwInstance(requestDetails, nw_endpoint); + String nwEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + return msoClientInterface.createNwInstance(requestDetails, nwEndpoint); } @Override public MsoResponseWrapper createVolumeGroupInstance(RequestDetails requestDetails, String serviceInstanceId, String vnfInstanceId) { logInvocationInDebug("createVolumeGroupInstance"); - String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE); + String endpoint; + endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE); String vnfEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); vnfEndpoint = vnfEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); @@ -161,10 +193,10 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE); - String partial_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - String vf_module_endpoint = partial_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + String partialEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + String vfModuleEndpoint = partialEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); - return msoClientInterface.createVfModuleInstance(requestDetails, vf_module_endpoint); + return msoClientInterface.createVfModuleInstance(requestDetails, vfModuleEndpoint); } @Override @@ -228,19 +260,15 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logInvocationInDebug("deleteSvcInstance"); String endpoint; - if (featureManager.isActive(FLAG_UNASSIGN_SERVICE)) { - endpoint = validateEndpointPath(MsoProperties.MSO_DELETE_OR_UNASSIGN_REST_API_SVC_INSTANCE); - if (shouldUnassignService(serviceStatus)) { - logger.debug(EELFLoggerDelegate.debugLogger, "unassign service"); - String svc_endpoint = endpoint + "/" + serviceInstanceId + "/unassign"; - return msoClientInterface.unassignSvcInstance(requestDetails, svc_endpoint); - } - } else { - endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE); + endpoint = validateEndpointPath(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE); + if (shouldUnassignService(serviceStatus)){ + logger.debug(EELFLoggerDelegate.debugLogger, "unassign service"); + String svcEndpoint = endpoint + "/" + serviceInstanceId + "/unassign"; + return msoClientInterface.unassignSvcInstance(requestDetails, svcEndpoint); } - String svc_endpoint = endpoint + "/" + serviceInstanceId; - return msoClientInterface.deleteSvcInstance(requestDetails, svc_endpoint); + String svcEndpoint = endpoint + "/" + serviceInstanceId; + return msoClientInterface.deleteSvcInstance(requestDetails, svcEndpoint); } private boolean shouldUnassignService(String serviceStatus) { @@ -263,10 +291,10 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logInvocationInDebug("deleteVfModule"); String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE); - String vf__modules_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId).replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); - String delete_vf_endpoint = vf__modules_endpoint + '/' + vfModuleId; + String vfModulesEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId).replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + String deleteVfEndpoint = vfModulesEndpoint + '/' + vfModuleId; - return msoClientInterface.deleteVfModule(requestDetails, delete_vf_endpoint); + return msoClientInterface.deleteVfModule(requestDetails, deleteVfEndpoint); } @Override @@ -274,11 +302,11 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logInvocationInDebug("deleteVolumeGroupInstance"); String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_VOLUME_GROUP_INSTANCE); - String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - String vnfEndpoint = svc_endpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); - String delete_volume_group_endpoint = vnfEndpoint + "/" + volumeGroupId; + String svcEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + String vnfEndpoint = svcEndpoint.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); + String deleteVolumeGroupEndpoint = vnfEndpoint + "/" + volumeGroupId; - return msoClientInterface.deleteVolumeGroupInstance(requestDetails, delete_volume_group_endpoint); + return msoClientInterface.deleteVolumeGroupInstance(requestDetails, deleteVolumeGroupEndpoint); } @Override @@ -286,10 +314,10 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logInvocationInDebug("deleteNwInstance"); String endpoint = validateEndpointPath(MsoProperties.MSO_REST_API_NETWORK_INSTANCE); - String svc_endpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - String delete_nw_endpoint = svc_endpoint + "/" + networkInstanceId; + String svcEndpoint = endpoint.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); + String deleteNwEndpoint = svcEndpoint + "/" + networkInstanceId; - return msoClientInterface.deleteNwInstance(requestDetails, delete_nw_endpoint); + return msoClientInterface.deleteNwInstance(requestDetails, deleteNwEndpoint); } @Override @@ -358,18 +386,19 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } private List getOrchestrationRequestsByFilter(String filterName, String filterValue) { + HttpResponseWithRequestInfo msoResponseWrapper = getRawOrchestrationRequestsByFilter(filterName, filterValue); + return deserializeOrchestrationRequestsJson(msoResponseWrapper.getResponse().getBody()); + } + + private HttpResponseWithRequestInfo getRawOrchestrationRequestsByFilter(String filterName, String filterValue) { String orchestrationReqPath = constructOrchestrationRequestFilter(filterName, filterValue); - RestObject restObjStr = new RestObject<>(); - String str = new String(); - restObjStr.set(str); - MsoResponseWrapper msoResponseWrapper = msoClientInterface.getOrchestrationRequest(str, "", orchestrationReqPath, restObjStr, true); - return deserializeOrchestrationRequestsJson(msoResponseWrapper.getEntity()); + return msoClientInterface.getOrchestrationRequest(orchestrationReqPath, true); } private List deserializeOrchestrationRequestsJson(String orchestrationRequestsJson) { logInvocationInDebug("deserializeOrchestrationRequestsJson"); - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = jacksonObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true); RequestList requestList; @@ -378,7 +407,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } catch (IOException e) { throw new GenericUncheckedException(e); } - return requestList.getRequestList(); + return ListUtils.emptyIfNull(requestList.getRequestList()); } @@ -392,7 +421,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String path = p + "?originalRequestId=" + originalRequestId; RestObject restObjStr = new RestObject<>(); - String str = new String(); + String str = ""; restObjStr.set(str); MsoResponseWrapper msoResponseWrapper = msoClientInterface.getManualTasksByRequestId(str, "", path, restObjStr); @@ -404,12 +433,11 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } } - private List deserializeManualTasksJson(String manualTasksJson) { + private List deserializeManualTasksJson(String manualTasksJson) { logInvocationInDebug("deserializeManualTasksJson"); - ObjectMapper mapper = new ObjectMapper(); try { - TaskList taskList = mapper.readValue(manualTasksJson, TaskList.class); + TaskList taskList = JACKSON_OBJECT_MAPPER.readValue(manualTasksJson, TaskList.class); return taskList.getTaskList(); } catch (IOException e) { throw new GenericUncheckedException(e); @@ -426,7 +454,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String path = p + "/" + taskId + "/complete"; RestObject restObjStr = new RestObject<>(); - String str = new String(); + String str = ""; restObjStr.set(str); return msoClientInterface.completeManualTask(requestDetails, str, "", path, restObjStr); @@ -442,14 +470,14 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String methodName = "activateServiceInstance"; logInvocationInDebug(methodName); try { - String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE); + String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE); String activateServicePath = serviceEndpoint + "/" + serviceInstanceId + ACTIVATE; RestObject restObjStr = new RestObject<>(); String str = ""; restObjStr.set(str); - msoClientInterface.setServiceInstanceStatus(requestDetails, str, "", activateServicePath, restObjStr); + msoClientInterface.setServiceInstanceStatus(requestDetails, activateServicePath); return MsoUtil.wrapResponse(restObjStr); @@ -506,7 +534,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { @Override public String getActivateFabricConfigurationPath(String serviceInstanceId) { - String path = validateEndpointPath(MsoProperties.MSO_REST_API_SERVICE_INSTANCE_CREATE); + String path = validateEndpointPath(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE); path += "/" + serviceInstanceId + ACTIVATE_FABRIC_CONFIGURATION; return path; @@ -530,9 +558,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { requestInfo.setRequestorId(softDeleteRequest.getUserId()); requestDetails.setRequestInfo(requestInfo); - CloudConfiguration cloudConfiguration = new CloudConfiguration(); - cloudConfiguration.setTenantId(softDeleteRequest.getTenantId()); - cloudConfiguration.setLcpCloudRegionId(softDeleteRequest.getLcpCloudRegionId()); + CloudConfiguration cloudConfiguration = new CloudConfiguration(softDeleteRequest.getLcpCloudRegionId(), softDeleteRequest.getTenantId(), null); requestDetails.setCloudConfiguration(cloudConfiguration); ModelInfo modelInfo = new ModelInfo(); @@ -547,15 +573,17 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } @Override - public MsoResponseWrapper2 deactivateAndCloudDelete(String serviceInstanceId, String vnfInstanceId, String vfModuleInstanceId, RequestDetails requestDetails) { - String path = getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId); - return new MsoResponseWrapper2<>(msoClientInterface.post(path, new RequestDetailsWrapper<>(requestDetails), RequestReferencesContainer.class)); - } + public SOWorkflowList getWorkflowListByModelId(String modelVersionId) { + logInvocationInDebug("getWorkflowListByModelId"); + String pathTemplate = validateEndpointPath(MSO_REST_API_WORKFLOW_SPECIFICATIONS); + String path = pathTemplate.replaceFirst("", modelVersionId); - @Override - public MsoResponseWrapper2 activateFabricConfiguration(String serviceInstanceId, RequestDetails requestDetails) { - String path = getActivateFabricConfigurationPath(serviceInstanceId); - return new MsoResponseWrapper2<>(msoClientInterface.post(path, new RequestDetailsWrapper<>(requestDetails), RequestReferencesContainer.class)); + HttpResponse workflowListByModelId = msoClientInterface.getWorkflowListByModelId(path); + if (!isSuccessful(workflowListByModelId)) { + logger.error(EELFLoggerDelegate.errorLogger, workflowListByModelId.getStatusText()); + throw new WorkflowListException(String.format("Get worklflow list for id: %s failed due to %s", modelVersionId, workflowListByModelId.getStatusText())); + } + return workflowListByModelId.getBody(); } @@ -589,7 +617,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { } Object payloadRaw = requestDetails.getRequestParameters().getAdditionalProperties().get("payload"); try { - return objectMapper.readValue((String) payloadRaw, Map.class); + return JACKSON_OBJECT_MAPPER.readValue((String) payloadRaw, Map.class); } catch (Exception exception) { throw new BadRequestException(message); } @@ -656,21 +684,13 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logInvocationInDebug("setServiceInstanceStatus"); String methodName = "setServiceInstanceStatus"; try { - String serviceEndpoint = validateEndpointPath(MsoProperties.MSO_REST_API_SVC_INSTANCE); + String serviceEndpoint = validateEndpointPath(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE); String endpoint = serviceEndpoint + "/" + serviceInstanceId; String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE); endpoint = endpoint + isActivateState; - - RestObject restObjStr = new RestObject<>(); - String str = ""; - restObjStr.set(str); - - msoClientInterface.setServiceInstanceStatus(requestDetails, str, "", endpoint, restObjStr); - - return MsoUtil.wrapResponse(restObjStr); - + return msoClientInterface.setServiceInstanceStatus(requestDetails, endpoint); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, methodName + e.toString()); logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString()); @@ -802,7 +822,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { public MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String serviceInstanceId) { logInvocationInDebug("removeRelationshipFromServiceInstance"); - String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE); + String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE); String removeRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/removeRelationships"; return msoClientInterface.removeRelationshipFromServiceInstance(requestDetails, removeRelationshipsPath); @@ -812,12 +832,49 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { public MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String serviceInstanceId) { logInvocationInDebug("addRelationshipToServiceInstance"); - String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_REST_API_SVC_INSTANCE); + String serviceEndpoint = SystemProperties.getProperty(MsoProperties.MSO_RESTAPI_SERVICE_INSTANCE); String addRelationshipsPath = serviceEndpoint + "/" + serviceInstanceId + "/addRelationships"; return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath); } + + @Override + public ExternalComponentStatus probeComponent() { + final long startTime = System.currentTimeMillis(); + HttpResponseWithRequestInfo responseWithRequestInfo = null; + try { + responseWithRequestInfo = getRawOrchestrationRequestsByFilter("requestExecutionDate", "01-01-2100" ); + int httpCode = responseWithRequestInfo.getResponse().getStatus(); + boolean isAvailable = httpCode == 200 || httpCode == 202; + if (isAvailable) { + //make sure response can be parsed to RequestList.class + JACKSON_OBJECT_MAPPER.readValue(responseWithRequestInfo.getResponse().getBody(), RequestList.class); + } + + HttpRequestMetadata metadata = new HttpRequestMetadata(responseWithRequestInfo, + isAvailable ? "OK" : "MSO returned no orchestration requests", + System.currentTimeMillis() - startTime, true); + return new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, isAvailable, metadata); + + } catch (ExceptionWithRequestInfo e) { + long duration = System.currentTimeMillis() - startTime; + return new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, false, + new HttpRequestMetadata(e, duration)); + } catch (Exception e) { + StatusMetadata metadata; + long duration = System.currentTimeMillis() - startTime; + + if (responseWithRequestInfo == null) { + metadata = new ErrorMetadata(Logging.exceptionToDescription(e), duration); + } else { + metadata = new HttpRequestMetadata(responseWithRequestInfo, Logging.exceptionToDescription(e), duration, true); + } + + return new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, false, metadata); + } + } + private void validateUpdateVnfConfig(RequestDetails requestDetails) { final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request"; @@ -842,7 +899,19 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString()); } - enum RequestType { + private boolean isSuccessful(HttpResponse workflowListByModelId) { + int status = workflowListByModelId.getStatus(); + return HttpStatus.OK.value() == status || HttpStatus.ACCEPTED.value() == status; + } + + static class WorkflowListException extends RuntimeException{ + + WorkflowListException(String message) { + super(message); + } + } + + public enum RequestType { CREATE_INSTANCE("createInstance"), DELETE_INSTANCE("deleteInstance"),