* 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.
*/
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.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.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.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.HttpMethod;
+import org.springframework.http.HttpStatus;
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");
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);
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
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_DELETE_OR_UNASSIGN_REST_API_SVC_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) {
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
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
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
private List<RequestWrapper> 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;
} catch (IOException e) {
throw new GenericUncheckedException(e);
}
- return requestList.getRequestList();
+ return ListUtils.emptyIfNull(requestList.getRequestList());
}
String path = p + "?originalRequestId=" + originalRequestId;
RestObject<String> restObjStr = new RestObject<>();
- String str = new String();
+ String str = "";
restObjStr.set(str);
MsoResponseWrapper msoResponseWrapper = msoClientInterface.getManualTasksByRequestId(str, "", path, restObjStr);
}
}
- private List<Task> deserializeManualTasksJson(String manualTasksJson) {
+ private List<Task> 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);
String path = p + "/" + taskId + "/complete";
RestObject<String> restObjStr = new RestObject<>();
- String str = new String();
+ String str = "";
restObjStr.set(str);
return msoClientInterface.completeManualTask(requestDetails, str, "", path, restObjStr);
String str = "";
restObjStr.set(str);
- msoClientInterface.setServiceInstanceStatus(requestDetails, str, "", activateServicePath, restObjStr);
+ msoClientInterface.setServiceInstanceStatus(requestDetails, activateServicePath);
return MsoUtil.wrapResponse(restObjStr);
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();
}
@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("<model_version_id>", 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<SOWorkflowList> 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();
}
}
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);
}
String isActivateState = (isActivate ? ACTIVATE : DEACTIVATE);
endpoint = endpoint + isActivateState;
-
- RestObject<String> 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());
return msoClientInterface.addRelationshipToServiceInstance(requestDetails, addRelationshipsPath);
}
+
+ @Override
+ public ExternalComponentStatus probeComponent() {
+ String url = SystemProperties.getProperty(
+ MsoProperties.MSO_SERVER_URL) + "/" + SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS);
+ long startTime = System.currentTimeMillis();
+ ExternalComponentStatus externalComponentStatus;
+
+ try {
+ String rawBody = objectMapper.writeValueAsString(getOrchestrationRequestsForDashboard());
+ StatusMetadata statusMetadata=new HttpRequestMetadata(HttpMethod.GET,200,url,rawBody,"VID-SO",System.currentTimeMillis() - startTime);
+
+ externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, true, statusMetadata);
+ } catch (Exception e) {
+ StatusMetadata statusMetadata = new HttpRequestMetadata(HttpMethod.GET, HttpStatus.INTERNAL_SERVER_ERROR.value(), url, "", e.getMessage(), System.currentTimeMillis() - startTime);
+ externalComponentStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.MSO, false, statusMetadata);
+ }
+
+ return externalComponentStatus;
+ }
+
private void validateUpdateVnfConfig(RequestDetails requestDetails) {
final String noValidPayloadMsg = "No valid payload in " + ChangeManagementRequest.CONFIG_UPDATE + " request";
logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString());
}
- enum RequestType {
+ private boolean isSuccessful(HttpResponse<SOWorkflowList> 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"),