diff options
Diffstat (limited to 'mso-api-handlers')
72 files changed, 2831 insertions, 1489 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java index 7feb1ae758..e9062effad 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2018 IBM. + * ================================================================================ * 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 @@ -110,7 +112,7 @@ public class CamundaClient extends RequestClient{ public HttpResponse post(RequestClientParameter parameterObject) throws ClientProtocolException, IOException{ HttpPost post = new HttpPost(url); - msoLogger.debug("Camunda url is: "+ url); + msoLogger.debug(CAMUNDA_URL_MESAGE+ url); String jsonReq = wrapVIDRequest(parameterObject.getRequestId(), parameterObject.isBaseVfModule(), parameterObject.getRecipeTimeout(), parameterObject.getRequestAction(), parameterObject.getServiceInstanceId(), parameterObject.getCorrelationId(), parameterObject.getVnfId(), parameterObject.getVfModuleId(), parameterObject.getVolumeGroupId(), parameterObject.getNetworkId(), parameterObject.getConfigurationId(), parameterObject.getServiceType(), parameterObject.getVnfType(), parameterObject.getVfModuleType(), parameterObject.getNetworkType(), parameterObject.getRequestDetails(), parameterObject.getApiVersion(), parameterObject.isaLaCarte(), parameterObject.getRequestUri(), parameterObject.getRecipeParamXsd()); diff --git a/mso-api-handlers/mso-api-handler-infra/pom.xml b/mso-api-handlers/mso-api-handler-infra/pom.xml index f871e120e7..37941b83e0 100644 --- a/mso-api-handlers/mso-api-handler-infra/pom.xml +++ b/mso-api-handlers/mso-api-handler-infra/pom.xml @@ -151,6 +151,11 @@ </dependency> <dependency> <groupId>org.onap.so</groupId> + <artifactId>mso-requests-db-repositories</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.so</groupId> <artifactId>mso-catalog-db</artifactId> <version>${project.version}</version> </dependency> diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java index 8f8cf0898d..1a95aa0e09 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java @@ -58,10 +58,10 @@ import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceRecipe; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.OperationStatus; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoAlarmLogger; import org.onap.so.logger.MsoLogger; -import org.onap.so.requestsdb.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.RequestDetails; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java index 1700e121f0..e6bbc4de4a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java @@ -29,7 +29,7 @@ import org.onap.so.apihandler.filters.RequestUriFilter; import org.onap.so.apihandlerinfra.exceptions.ApiExceptionMapper; import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestration; import org.onap.so.apihandlerinfra.tenantisolation.CloudResourcesOrchestration; -import org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging; +import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging; import org.onap.so.web.exceptions.RuntimeExceptionMapper; import org.springframework.context.annotation.Configuration; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index 1a1b45ac8e..753e712d71 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -62,10 +62,11 @@ import org.onap.so.apihandlerinfra.vnfbeans.RequestStatusType; import org.onap.so.apihandlerinfra.vnfbeans.VnfInputs; import org.onap.so.apihandlerinfra.vnfbeans.VnfRequest; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; -import org.onap.so.requestsdb.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.InstanceDirection; import org.onap.so.serviceinstancebeans.ModelInfo; @@ -741,4 +742,4 @@ public class MsoRequest { return vnfType; } -}
\ No newline at end of file +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index 753b4c48d4..50d2639b2d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -23,6 +23,7 @@ package org.onap.so.apihandlerinfra; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,11 +49,12 @@ import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.RequestProcessingData; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoAlarmLogger; import org.onap.so.logger.MsoLogger; -import org.onap.so.requestsdb.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse; import org.onap.so.serviceinstancebeans.GetOrchestrationResponse; import org.onap.so.serviceinstancebeans.InstanceReferences; @@ -97,10 +99,11 @@ public class OrchestrationRequests { GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse(); - InfraActiveRequests requestDB = null; - + InfraActiveRequests infraActiveRequest = null; + List<org.onap.so.db.request.beans.RequestProcessingData> requestProcessingData = null; try { - requestDB = requestsDbClient.getInfraActiveRequestbyRequestId(requestId); + infraActiveRequest = requestsDbClient.getInfraActiveRequestbyRequestId(requestId); + requestProcessingData = requestsDbClient.getRequestProcessingDataBySoRequestId(requestId); } catch (Exception e) { msoLogger.error(e); @@ -115,8 +118,8 @@ public class OrchestrationRequests { throw validateException; } - - if(requestDB == null) { + + if(infraActiveRequest == null) { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MsoLogger.ErrorCode.BusinessProcesssError).build(); @@ -126,8 +129,11 @@ public class OrchestrationRequests { throw validateException; } - - Request request = mapInfraActiveRequestToRequest(requestDB); + + Request request = mapInfraActiveRequestToRequest(infraActiveRequest); + if(!requestProcessingData.isEmpty()){ + request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); + } request.setRequestId(requestId); orchestrationResponse.setRequest(request); @@ -171,8 +177,12 @@ public class OrchestrationRequests { List<RequestList> requestLists = new ArrayList<>(); for(InfraActiveRequests infraActive : activeRequests){ + List<RequestProcessingData> requestProcessingData = requestsDbClient.getRequestProcessingDataBySoRequestId(infraActive.getRequestId()); RequestList requestList = new RequestList(); Request request = mapInfraActiveRequestToRequest(infraActive); + if(!requestProcessingData.isEmpty()){ + request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); + } requestList.setRequest(request); requestLists.add(requestList); } @@ -337,4 +347,46 @@ public class OrchestrationRequests { return request; } + + public List<org.onap.so.serviceinstancebeans.RequestProcessingData> mapRequestProcessingData(List<org.onap.so.db.request.beans.RequestProcessingData> processingData){ + List<org.onap.so.serviceinstancebeans.RequestProcessingData> addedRequestProcessingData = new ArrayList<>(); + org.onap.so.serviceinstancebeans.RequestProcessingData finalProcessingData = new org.onap.so.serviceinstancebeans.RequestProcessingData(); + String currentGroupingId = null; + HashMap<String, String> tempMap = new HashMap<>(); + List<HashMap<String, String>> tempList = new ArrayList<>(); + for(RequestProcessingData data : processingData){ + String groupingId = data.getGroupingId(); + String tag = data.getTag(); + if(currentGroupingId == null || !currentGroupingId.equals(groupingId)){ + if(!tempMap.isEmpty()){ + tempList.add(tempMap); + finalProcessingData.setDataPairs(tempList); + addedRequestProcessingData.add(finalProcessingData); + } + finalProcessingData = new org.onap.so.serviceinstancebeans.RequestProcessingData(); + if(groupingId != null){ + finalProcessingData.setGroupingId(groupingId); + } + if(tag != null){ + finalProcessingData.setTag(tag); + } + currentGroupingId = groupingId; + tempMap = new HashMap<>(); + tempList = new ArrayList<>(); + if(data.getName() != null && data.getValue() != null){ + tempMap.put(data.getName(), data.getValue()); + } + }else{ + if(data.getName() != null && data.getValue() != null){ + tempMap.put(data.getName(), data.getValue()); + } + } + } + if(tempMap.size() > 0){ + tempList.add(tempMap); + finalProcessingData.setDataPairs(tempList); + } + addedRequestProcessingData.add(finalProcessingData); + return addedRequestProcessingData; + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index a7dac34aa0..60b07fdeab 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -58,10 +58,10 @@ import org.onap.so.db.catalog.beans.VnfResource; import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; -import org.onap.so.requestsdb.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; @@ -1511,7 +1511,9 @@ public class ServiceInstances { } }else{ //ok for version < 3 and action delete - recipe = catalogDbClient.getFirstNetworkRecipeByModelNameAndAction(modelName, action.toString()); + if(modelName != null){ + recipe = catalogDbClient.getFirstNetworkRecipeByModelNameAndAction(modelName, action.toString()); + } } if(recipe == null){ @@ -1656,4 +1658,4 @@ public class ServiceInstances { infraActiveRequestsClient.save(aq); } } -}
\ No newline at end of file +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java index 0a996dc3dc..6d61d3bb34 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SpringContextHelper.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2018 IBM. + * ================================================================================ * 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 @@ -20,7 +22,6 @@ package org.onap.so.apihandlerinfra; -import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; @@ -31,7 +32,7 @@ public class SpringContextHelper implements ApplicationContextAware { private static ApplicationContext context; @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + public void setApplicationContext(ApplicationContext applicationContext) { context = applicationContext; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java index cfe32a3833..d743c440e7 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java @@ -40,7 +40,6 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.Constants; -import org.onap.so.requestsdb.client.RequestsDbClient; import org.onap.so.apihandlerinfra.Status; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException; @@ -51,6 +50,7 @@ import org.onap.so.apihandlerinfra.tenantisolationbeans.OperationalEnvironment; import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestReferences; import org.onap.so.apihandlerinfra.tenantisolationbeans.TenantSyncResponse; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; @@ -237,4 +237,4 @@ public class CloudOrchestration { private String getRequestId(ContainerRequestContext requestContext) { return requestContext.getProperty("requestId").toString(); } -}
\ No newline at end of file +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java index 3b7a326f3e..a35f40baf6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java @@ -44,7 +44,6 @@ import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandler.common.ResponseBuilder; import org.onap.so.apihandlerinfra.Constants; import org.onap.so.apihandlerinfra.Messages; -import org.onap.so.requestsdb.client.RequestsDbClient; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo; @@ -56,6 +55,7 @@ import org.onap.so.apihandlerinfra.tenantisolationbeans.Request; import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails; import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestStatus; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoAlarmLogger; @@ -294,4 +294,4 @@ public class CloudResourcesOrchestration { return request; } -}
\ No newline at end of file +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java index b13008b3d3..855a5433f3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java @@ -30,7 +30,6 @@ import javax.ws.rs.core.MultivaluedMap; import org.apache.commons.lang3.StringUtils; import org.onap.so.apihandlerinfra.Constants; -import org.onap.so.requestsdb.client.RequestsDbClient; import org.onap.so.apihandlerinfra.Status; import org.onap.so.apihandlerinfra.tenantisolationbeans.Action; import org.onap.so.apihandlerinfra.tenantisolationbeans.Manifest; @@ -44,6 +43,7 @@ import org.onap.so.apihandlerinfra.tenantisolationbeans.ResourceType; import org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList; import org.onap.so.apihandlerinfra.vnfbeans.RequestStatusType; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; @@ -384,4 +384,4 @@ public class TenantIsolationRequest { public void setOperationalEnvironmentId(String operationalEnvironmentId) { this.operationalEnvironmentId = operationalEnvironmentId; } -}
\ No newline at end of file +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java index e89b5c8d42..ac9a000d3b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java @@ -27,7 +27,7 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.json.JSONObject; import org.onap.so.apihandler.common.ErrorNumbers; -import org.onap.so.requestsdb.client.RequestsDbClient; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java index 6eb5157568..66cfd349df 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java @@ -28,7 +28,7 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.json.JSONObject; import org.onap.so.apihandler.common.ErrorNumbers; -import org.onap.so.requestsdb.client.RequestsDbClient; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironment.java index c16f7bb9ef..b09bbae0ad 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironment.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironment.java @@ -76,8 +76,8 @@ public class CreateEcompOperationalEnvironment { requestDb.updateInfraFailureCompletion(e.getMessage(), requestId, request.getOperationalEnvironmentId()); throw validateException; } - //Update request database - requestDb.updateInfraSuccessCompletion("SUCCESSFULLY Created ECOMP OperationalEnvironment.", requestId, request.getOperationalEnvironmentId()); + //Update request database + requestDb.updateInfraSuccessCompletion("SUCCESSFULLY Created ECOMP OperationalEnvironment.", requestId, request.getOperationalEnvironmentId()); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java index d2730406e6..52ed34ac3f 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java @@ -28,7 +28,6 @@ import com.github.tomakehurst.wiremock.client.WireMock; import org.junit.After; import org.junit.BeforeClass; import org.junit.runner.RunWith; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.onap.so.logger.MsoLogger; import org.onap.so.logger.MsoLogger.Catalog; import org.springframework.beans.factory.annotation.Autowired; @@ -45,8 +44,7 @@ import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.junit4.SpringRunner; import javax.transaction.Transactional; -import java.io.File; -import java.io.IOException; + import java.nio.file.Files; import java.nio.file.Paths; @@ -55,7 +53,7 @@ import java.nio.file.Paths; @ActiveProfiles("test") @ContextConfiguration @Transactional -@Sql(executionPhase=ExecutionPhase.AFTER_TEST_METHOD,scripts="classpath:InfraActiveRequestsReset.sql") +//@Sql(executionPhase=ExecutionPhase.AFTER_TEST_METHOD,scripts="classpath:InfraActiveRequestsReset.sql") @AutoConfigureWireMock(port = 0) public abstract class BaseTest { protected MsoLogger logger = MsoLogger.getMsoLogger(Catalog.GENERAL, BaseTest.class); @@ -65,26 +63,16 @@ public abstract class BaseTest { @Autowired protected Environment env; - - @Autowired - protected InfraActiveRequestsRepository iar; - + @LocalServerPort private int port; - protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{ - ObjectMapper mapper = new ObjectMapper(); - JsonNode jsonNode = mapper.readTree(new File(fileLocation)); - return jsonNode.asText(); - } - protected String createURLWithPort(String uri) { return "http://localhost:" + port + uri; } @After public void tearDown(){ - iar.deleteAll(); WireMock.reset(); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java index 5d6aa43a9b..76d4b48a36 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ManualTasksTest.java @@ -39,6 +39,7 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.apache.log4j.MDC; import org.junit.Test; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandlerinfra.tasksbeans.RequestDetails; import org.onap.so.apihandlerinfra.tasksbeans.RequestInfo; import org.onap.so.apihandlerinfra.tasksbeans.TaskRequestReference; @@ -110,8 +111,8 @@ public class ManualTasksTest extends BaseTest{ logEvent.getMarker().getName().equals("ENTRY") ){ Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(MsoLogger.BEGINTIME)); - assertNotNull(mdc.get(MsoLogger.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); assertNotNull(mdc.get(MsoLogger.INVOCATION_ID)); assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME)); assertEquals("tasks/v1/55/complete",mdc.get(MsoLogger.SERVICE_NAME)); @@ -119,9 +120,9 @@ public class ManualTasksTest extends BaseTest{ }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging") && logEvent.getMarker().getName().equals("EXIT")){ Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(MsoLogger.BEGINTIME)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); assertNotNull(mdc.get(MsoLogger.ENDTIME)); - assertNotNull(mdc.get(MsoLogger.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); assertNotNull(mdc.get(MsoLogger.INVOCATION_ID)); assertEquals("202",mdc.get(MsoLogger.RESPONSECODE)); assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME)); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java index 582bc12077..0af9826020 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java @@ -20,50 +20,63 @@ package org.onap.so.apihandlerinfra; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.any; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import org.apache.http.HttpStatus; import org.junit.Ignore; import org.junit.Test; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; +import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; -import org.onap.so.requestsdb.client.RequestsDbClient; -import org.onap.so.serviceinstancebeans.*; +import org.onap.so.serviceinstancebeans.GetOrchestrationListResponse; +import org.onap.so.serviceinstancebeans.GetOrchestrationResponse; +import org.onap.so.serviceinstancebeans.Request; +import org.onap.so.serviceinstancebeans.RequestError; +import org.onap.so.serviceinstancebeans.RequestProcessingData; +import org.onap.so.serviceinstancebeans.ServiceException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static com.shazam.shazamcrest.MatcherAssert.assertThat; -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.junit.Assert.assertEquals; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; public class OrchestrationRequestsTest extends BaseTest { @Autowired - private InfraActiveRequestsRepository iar; - - @Autowired private RequestsDbClient requestsDbClient; + + @Autowired + private OrchestrationRequests orchReq; - private static final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title></title></head><body></body></html>"; private static final GetOrchestrationListResponse ORCHESTRATION_LIST = generateOrchestrationList(); private static final String INVALID_REQUEST_ID = "invalid-request-id"; @@ -162,9 +175,14 @@ public class OrchestrationRequestsTest extends BaseTest { List<String> values = new ArrayList<>(); values.add("EQUALS"); values.add("vfModule"); + + ObjectMapper mapper = new ObjectMapper(); + GetOrchestrationListResponse testResponse = mapper.readValue(new File("src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json"), + GetOrchestrationListResponse.class); Map<String, List<String>> orchestrationMap = new HashMap<>(); orchestrationMap.put("modelType", values); + List<GetOrchestrationResponse> testResponses = new ArrayList<>(); List<InfraActiveRequests> requests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap); HttpEntity<Request> entity = new HttpEntity<Request>(null, headers); @@ -175,8 +193,11 @@ public class OrchestrationRequestsTest extends BaseTest { ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationListResponse.class); + assertThat(response.getBody(), + sameBeanAs(testResponse).ignoring("requestList.request.startTime").ignoring("requestList.request.requestStatus.finishTime")); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); assertEquals(requests.size(), response.getBody().getRequestList().size()); + } @Test @@ -315,7 +336,7 @@ public class OrchestrationRequestsTest extends BaseTest { requests.setRequestId("requestId"); requests.setRequestScope("service"); requests.setRequestType("createInstance"); - iar.save(requests); +// iar.save(requests); headers.set("Accept", MediaType.APPLICATION_JSON); headers.set("Content-Type", MediaType.APPLICATION_JSON); @@ -334,12 +355,48 @@ public class OrchestrationRequestsTest extends BaseTest { assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0)); assertEquals("requestId", response.getHeaders().get("X-TransactionID").get(0)); } + @Test + public void mapRequestProcessingDataTest() throws JsonParseException, JsonMappingException, IOException{ + RequestProcessingData entry = new RequestProcessingData(); + RequestProcessingData secondEntry = new RequestProcessingData(); + List<HashMap<String, String>> expectedList = new ArrayList<>(); + HashMap<String, String> expectedMap = new HashMap<>(); + List<HashMap<String, String>> secondExpectedList = new ArrayList<>(); + HashMap<String, String> secondExpectedMap = new HashMap<>(); + List<RequestProcessingData> expectedDataList = new ArrayList<>(); + entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); + entry.setTag("pincFabricConfigRequest"); + expectedMap.put("requestAction", "assign"); + expectedMap.put("pincFabricId", "testId"); + expectedList.add(expectedMap); + entry.setDataPairs(expectedList); + secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715"); + secondEntry.setTag("pincFabricConfig"); + secondExpectedMap.put("requestAction", "unassign"); + secondExpectedList.add(secondExpectedMap); + secondEntry.setDataPairs(secondExpectedList); + expectedDataList.add(entry); + expectedDataList.add(secondEntry); + + List<org.onap.so.db.request.beans.RequestProcessingData> processingData = new ArrayList<>(); + List<RequestProcessingData> actualProcessingData = new ArrayList<>(); + ObjectMapper mapper = new ObjectMapper(); + processingData = mapper.readValue(new File("src/test/resources/OrchestrationRequest/RequestProcessingData.json"), + new TypeReference<List<org.onap.so.db.request.beans.RequestProcessingData>>(){}); + actualProcessingData = orchReq.mapRequestProcessingData(processingData); + assertThat(actualProcessingData,sameBeanAs(expectedDataList)); + } public void setupTestGetOrchestrationRequest() throws Exception{ //For testGetOrchestrationRequest stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-na18-42e5-965d-8ea592502018")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequest.json")))) .withStatus(HttpStatus.SC_OK))); + stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/")) + .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-na18-42e5-965d-8ea592502018")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json")))) + .withStatus(HttpStatus.SC_OK))); } private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception{ @@ -379,4 +436,4 @@ public class OrchestrationRequestsTest extends BaseTest { .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestDetailsFilter.json")))) .withStatus(HttpStatus.SC_OK))); } -}
\ No newline at end of file +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index 5b37d772c6..e4ec850c4e 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -29,6 +29,7 @@ import com.github.tomakehurst.wiremock.http.Fault; import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Test; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceRecipe; import org.onap.so.db.request.beans.InfraActiveRequests; @@ -188,8 +189,8 @@ public class ServiceInstancesTest extends BaseTest{ logEvent.getMarker().getName().equals("ENTRY") ){ Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(MsoLogger.BEGINTIME)); - assertNotNull(mdc.get(MsoLogger.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); assertNotNull(mdc.get(MsoLogger.INVOCATION_ID)); assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME)); assertEquals("onap/so/infra/serviceInstantiation/v5/serviceInstances",mdc.get(MsoLogger.SERVICE_NAME)); @@ -197,9 +198,9 @@ public class ServiceInstancesTest extends BaseTest{ }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging") && logEvent.getMarker().getName().equals("EXIT")){ Map<String,String> mdc = logEvent.getMDCPropertyMap(); - assertNotNull(mdc.get(MsoLogger.BEGINTIME)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); assertNotNull(mdc.get(MsoLogger.ENDTIME)); - assertNotNull(mdc.get(MsoLogger.REQUEST_ID)); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID)); assertNotNull(mdc.get(MsoLogger.INVOCATION_ID)); assertEquals("202",mdc.get(MsoLogger.RESPONSECODE)); assertEquals("UNKNOWN",mdc.get(MsoLogger.PARTNERNAME)); @@ -1632,7 +1633,7 @@ public class ServiceInstancesTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + - "modelName=GR-API-DEFAULT&action=deleteInstance")) + "modelName=VNF-API-DEFAULT&action=deleteInstance")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) .withStatus(org.apache.http.HttpStatus.SC_OK))); @@ -1934,7 +1935,7 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void invalidRequestId() throws IOException { String illegalRequestId = "1234"; - headers.set("X-ECOMP-RequestID", illegalRequestId); + headers.set(ONAPLogConstants.Headers.REQUEST_ID, illegalRequestId); uri = servInstanceuri + "v5/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestrationTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestrationTest.java index e759752c33..1e11b74215 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestrationTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestrationTest.java @@ -30,7 +30,6 @@ import org.onap.so.apihandlerinfra.Status; import org.onap.so.apihandlerinfra.tenantisolationbeans.Action; import org.onap.so.apihandlerinfra.tenantisolationbeans.TenantIsolationRequest; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestrationTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestrationTest.java index 5f18e28ba6..8ac84d6598 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestrationTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestrationTest.java @@ -25,9 +25,6 @@ import org.junit.Before; import org.junit.Test; import org.onap.so.apihandlerinfra.BaseTest; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -44,15 +41,8 @@ import static org.junit.Assert.assertTrue; public class CloudResourcesOrchestrationTest extends BaseTest{ - @Autowired - private InfraActiveRequestsRepository iarRepo; private String requestJSON = "{\"requestDetails\":{\"requestInfo\":{\"source\":\"VID\",\"requestorId\":\"xxxxxx\" } } }"; private static final String path = "/onap/so/infra/cloudResourcesRequests"; - - @LocalServerPort - private int port; - - HttpHeaders headers = new HttpHeaders(); @Before @@ -275,8 +265,6 @@ public class CloudResourcesOrchestrationTest extends BaseTest{ iar.setRequestStatus("COMPLETE"); iar.setRequestAction("TEST"); - iarRepo.saveAndFlush(iar); - headers.set("Accept", MediaType.APPLICATION_JSON); headers.set("Content-Type", MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<>("", headers); @@ -303,8 +291,6 @@ public class CloudResourcesOrchestrationTest extends BaseTest{ iar.setRequestStatus("COMPLETE"); iar.setRequestAction("TEST"); - iarRepo.saveAndFlush(iar); - headers.set("Accept", MediaType.APPLICATION_JSON); headers.set("Content-Type", MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<>(null, headers); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java index eba90496ba..9a5334081f 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java @@ -30,8 +30,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.containing; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; + import static org.junit.Assert.assertThat; import com.fasterxml.jackson.core.JsonProcessingException; @@ -39,7 +38,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.HttpStatus; import org.json.JSONObject; import org.junit.Rule; -import org.junit.After; import org.junit.Test; import org.junit.Ignore; import org.junit.rules.ExpectedException; @@ -47,16 +45,12 @@ import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.BaseTest; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestrationRequest; -import org.onap.so.apihandlerinfra.tenantisolation.helpers.ActivateVnfDBHelper; import org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution; import org.onap.so.apihandlerinfra.tenantisolationbeans.DistributionStatus; import org.onap.so.apihandlerinfra.tenantisolationbeans.Status; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; -import org.onap.so.db.request.data.repository.OperationalEnvDistributionStatusRepository; -import org.onap.so.db.request.data.repository.OperationalEnvServiceModelStatusRepository; import org.springframework.beans.factory.annotation.Autowired; import javax.ws.rs.core.HttpHeaders; @@ -66,10 +60,6 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ @Autowired private ActivateVnfStatusOperationalEnvironment activateVnfStatus; - @Autowired - private InfraActiveRequestsRepository infraActiveRequestsRepository; - @Autowired - private ActivateVnfDBHelper dbHelper; @Rule public ExpectedException thrown = ExpectedException.none(); @@ -185,10 +175,7 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig); - - // do nothing, waiting for more - assertNull(infraActiveRequestsRepository.findOne(requestIdOrig)); - } + } @Test public void executionTest_Ok() throws Exception { diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java index 0ace9d5445..585eff23c4 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateEcompOperationalEnvironmentTest.java @@ -23,7 +23,7 @@ package org.onap.so.apihandlerinfra.tenantisolation.process; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertThat; - +import java.util.UUID; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.HttpStatus; @@ -107,22 +107,23 @@ public class CreateEcompOperationalEnvironmentTest extends BaseTest{ .errorInfo(errorLoggerInfo).build(); InfraActiveRequests iar = new InfraActiveRequests(); - iar.setRequestId("123"); + String uuid = UUID.randomUUID().toString(); + iar.setRequestId(uuid); iar.setOperationalEnvName("myOpEnv"); iar.setRequestScope("create"); iar.setRequestStatus("PENDING"); iar.setRequestAction("UNKNOWN"); - stubFor(get(urlPathEqualTo("/infraActiveRequests/123")) + stubFor(get(urlPathEqualTo("/infraActiveRequests/"+uuid)) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(iar)) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/infraActiveRequests/")) - .withRequestBody(containing("{\"requestId\":\"123\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"FAILED\",\"statusMessage\":\"FAILURE, operationalEnvironmentId - operationalEnvId; Error message: empty")) + .withRequestBody(containing("{\"requestId\":\""+uuid+ "\",\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"FAILED\",\"statusMessage\":\"FAILURE, operationalEnvironmentId - operationalEnvId; Error message:")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); try { - createEcompOpEn.execute("123", getCloudOrchestrationRequest()); + createEcompOpEn.execute(uuid, getCloudOrchestrationRequest()); }catch(ApiException e){ assertThat(e, sameBeanAs((ApiException) expectedException).ignoring("cause")); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java index 1dfafce40c..809e39c772 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/CreateVnfOperationalEnvironmentTest.java @@ -40,7 +40,6 @@ import org.onap.so.client.aai.objects.AAIOperationalEnvironment; import org.onap.so.client.grm.beans.Property; import org.onap.so.client.grm.beans.ServiceEndPointList; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.springframework.beans.factory.annotation.Autowired; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java index 5b0e1f6bfd..7c24050775 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/DeactivateVnfOperationalEnvironmentTest.java @@ -37,7 +37,6 @@ import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.tenantisolation.CloudOrchestrationRequest; import org.onap.so.client.aai.AAIVersion; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.springframework.beans.factory.annotation.Autowired; import javax.ws.rs.core.HttpHeaders; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json new file mode 100644 index 0000000000..561ed0d31f --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json @@ -0,0 +1,189 @@ +{ + "requestList": [ + { + "request": { + "requestId": "001619d2-a297-4a4b-a9f5-e2823c88458f", + "startTime": "Fri, 01 Jul 2016 04:41:42 GMT", + "requestScope": "vfModule", + "requestType": "createInstance", + "requestDetails": { + "modelInfo": { + "modelType": "vfModule", + "modelName": "test::base::module-0" + }, + "requestInfo": { + "source": "VID", + "suppressRollback": false + }, + "cloudConfiguration": { + "tenantId": "6accefef3cb442ff9e644d589fb04107", + "lcpCloudRegionId": "n6" + }, + "instanceName": [] + }, + "instanceReferences": { + "vnfInstanceName": "test-vscp", + "vfModuleInstanceName": "MODULENAME1" + }, + "requestStatus": { + "requestState": "COMPLETE", + "statusMessage": "COMPLETED", + "percentProgress": 100, + "finishTime": "Tue, 02 May 2017 06:33:34 GMT" + } + } + }, + { + "request": { + "requestId": "00032ab7-3fb3-42e5-965d-8ea592502017", + "startTime": "Thu, 22 Dec 2016 08:29:54 GMT", + "requestScope": "vfModule", + "requestType": "deleteInstance", + "requestDetails": { + "modelInfo": { + "modelType": "vfModule", + "modelName": "test::base::module-0" + }, + "requestInfo": { + "source": "VID", + "suppressRollback": false + }, + "cloudConfiguration": { + "tenantId": "6accefef3cb442ff9e644d589fb04107", + "lcpCloudRegionId": "n6" + }, + "instanceName": [] + }, + "instanceReferences": { + "serviceInstanceId": "e3b5744d-2ad1-4cdd-8390-c999a38829bc", + "vnfInstanceId": "b92f60c8-8de3-46c1-8dc1-e4390ac2b005", + "vfModuleInstanceId": "c7d527b1-7a91-49fd-b97d-1c8c0f4a7992" + }, + "requestStatus": { + "requestState": "COMPLETE", + "statusMessage": "Vf Module has been deleted successfully.", + "percentProgress": 100, + "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT" + } + } + }, + { + "request": { + "requestId": "00032ab7-na18-42e5-965d-8ea592502018", + "startTime": "Thu, 22 Dec 2016 08:29:54 GMT", + "requestScope": "vfModule", + "requestType": "deleteInstance", + "requestDetails": { + "modelInfo": { + "modelType": "vfModule", + "modelName": "test::base::module-0" + }, + "requestInfo": { + "source": "VID", + "suppressRollback": false + }, + "cloudConfiguration": { + "tenantId": "6accefef3cb442ff9e644d589fb04107", + "lcpCloudRegionId": "n6" + }, + "instanceName": [] + }, + "instanceReferences": { + "serviceInstanceId": "e3b5744d-2ad1-4cdd-8390-c999a38829bc", + "vnfInstanceId": "b92f60c8-8de3-46c1-8dc1-e4390ac2b005", + "vfModuleInstanceId": "c7d527b1-7a91-49fd-b97d-1c8c0f4a7992" + }, + "requestStatus": { + "requestState": "PENDING", + "statusMessage": "Vf Module deletion pending.", + "percentProgress": 0, + "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT" + } + } + }, + { + "request": { + "requestId": "5ffbabd6-b793-4377-a1ab-082670fbc7ac", + "startTime": "Thu, 22 Dec 2016 08:29:54 GMT", + "requestScope": "vfModule", + "requestType": "deleteInstance", + "requestDetails": { + "modelInfo": { + "modelInvariantId": "78ca26d0-246d-11e7-93ae-92361f002671", + "modelType": "vfModule", + "modelId": "20c4431c-246d-11e7-93ae-92361f002671", + "modelName": "test::base::module-0", + "modelVersion": "2", + "modelCustomizationUuid": "cb82ffd8-252a-11e7-93ae-92361f002671", + "modelVersionId": "20c4431c-246d-11e7-93ae-92361f002671", + "modelCustomizationId": "cb82ffd8-252a-11e7-93ae-92361f002671", + "modelUuid": "20c4431c-246d-11e7-93ae-92361f002671", + "modelInvariantUuid": "78ca26d0-246d-11e7-93ae-92361f002671" + }, + "requestInfo": { + "source": "VID", + "instanceName": "MSO-DEV-VF-1806BB-v10-base-it2-1", + "suppressRollback": false, + "requestorId": "xxxxxx" + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "76fa8849-4c98-473f-b431-2590b192a653", + "modelInfo": { + "modelInvariantId": "9647dfc4-2083-11e7-93ae-92361f002671", + "modelType": "service", + "modelId": "5df8b6de-2083-11e7-93ae-92361f002671", + "modelName": "Infra_v10_Service", + "modelVersion": "1.0", + "modelVersionId": "5df8b6de-2083-11e7-93ae-92361f002671", + "modelUuid": "5df8b6de-2083-11e7-93ae-92361f002671", + "modelInvariantUuid": "9647dfc4-2083-11e7-93ae-92361f002671" + } + } + }, + { + "relatedInstance": { + "instanceId": "d57970e1-5075-48a5-ac5e-75f2d6e10f4c", + "modelInfo": { + "modelCustomizationName": "v10 1", + "modelInvariantId": "2fff5b20-214b-11e7-93ae-92361f002671", + "modelType": "vnf", + "modelId": "ff2ae348-214a-11e7-93ae-92361f002671", + "modelName": "v10", + "modelVersion": "1.0", + "modelCustomizationUuid": "68dc9a92-214c-11e7-93ae-92361f002671", + "modelVersionId": "ff2ae348-214a-11e7-93ae-92361f002671", + "modelCustomizationId": "68dc9a92-214c-11e7-93ae-92361f002671", + "modelUuid": "ff2ae348-214a-11e7-93ae-92361f002671", + "modelInvariantUuid": "2fff5b20-214b-11e7-93ae-92361f002671", + "modelInstanceName": "v10 1" + } + } + } + ], + "cloudConfiguration": { + "tenantId": "0422ffb57ba042c0800a29dc85ca70f8", + "lcpCloudRegionId": "n6" + }, + "requestParameters": { + "userParams": [], + "usePreload": true + }, + "instanceName": [] + }, + "instanceReferences": { + "serviceInstanceId": "e3b5744d-2ad1-4cdd-8390-c999a38829bc", + "vnfInstanceId": "b92f60c8-8de3-46c1-8dc1-e4390ac2b005", + "vfModuleInstanceId": "c7d527b1-7a91-49fd-b97d-1c8c0f4a7992" + }, + "requestStatus": { + "requestState": "UNLOCKED", + "statusMessage": "Vf Module deletion pending.", + "percentProgress": 0, + "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT" + } + } + } + ] +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json index 124513de0d..1b1530d3a6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json @@ -1 +1,298 @@ -{"requestList":[{"request":{"requestId":"00032ab7-3fb3-42e5-965d-8ea592502017","requestScope":"vfModule","requestType":"deleteInstance","requestDetails":{"modelInfo":{"modelType":"vfModule","modelName":"test::base::module-0"},"requestInfo":{"source":"VID","suppressRollback":false},"cloudConfiguration":{"tenantId":"6accefef3cb442ff9e644d589fb04107","lcpCloudRegionId":"n6"}},"instanceReferences":{"serviceInstanceId":"e3b5744d-2ad1-4cdd-8390-c999a38829bc","vnfInstanceId":"b92f60c8-8de3-46c1-8dc1-e4390ac2b005","vfModuleInstanceId":"c7d527b1-7a91-49fd-b97d-1c8c0f4a7992"},"requestStatus":{"requestState":"COMPLETE","statusMessage":"Vf Module has been deleted successfully.","percentProgress":100}}},{"request":{"requestId":"00032ab7-na18-42e5-965d-8ea592502018","requestScope":"vfModule","requestType":"deleteInstance","requestDetails":{"modelInfo":{"modelType":"vfModule","modelName":"test::base::module-0"},"requestInfo":{"source":"VID","suppressRollback":false},"cloudConfiguration":{"tenantId":"6accefef3cb442ff9e644d589fb04107","lcpCloudRegionId":"n6"}},"instanceReferences":{"serviceInstanceId":"e3b5744d-2ad1-4cdd-8390-c999a38829bc","vnfInstanceId":"b92f60c8-8de3-46c1-8dc1-e4390ac2b005","vfModuleInstanceId":"c7d527b1-7a91-49fd-b97d-1c8c0f4a7992"},"requestStatus":{"requestState":"PENDING","statusMessage":"Vf Module deletion pending.","percentProgress":0}}},{"request":{"requestId":"00093944-bf16-4373-ab9a-3adfe730ff2d","requestScope":"service","requestType":"createInstance","requestDetails":{"modelInfo":{"modelInvariantId":"9647dfc4-2083-11e7-93ae-92361f002671","modelType":"service","modelName":"MSOTADevInfra_v10_Service","modelVersion":"1.0","modelVersionId":"5df8b6de-2083-11e7-93ae-92361f002671"},"requestInfo":{"source":"VID","instanceName":"MSODEV_1707_SI_v10_011-4","suppressRollback":false,"requestorId":"xxxxxx"},"subscriberInfo":{"globalSubscriberId":"MSO_1610_dev","subscriberName":"MSO_1610_dev"},"cloudConfiguration":{"tenantId":"19123c2924c648eb8e42a3c1f14b7682","lcpCloudRegionId":"n6"},"requestParameters":{"subscriptionServiceType":"MSO-dev-service-type","userParams":[{"name":"someUserParam","value":"someValue"}],"aLaCarte":true,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true}},"instanceReferences":{},"requestStatus":{"requestState":"FAILED","statusMessage":"Error: Locked instance - This service (MSODEV_1707_SI_v10_011-4) already has a request being worked with a status of IN_PROGRESS (RequestId - 278e83b1-4f9f-450e-9e7d-3700a6ed22f4). The existing request must finish or be cleaned up before proceeding.","percentProgress":100}}},{"request":{"requestId":"001619d2-a297-4a4b-a9f5-e2823c88458f","requestScope":"vfModule","requestType":"createInstance","instanceReferences":{},"requestStatus":{"requestState":"COMPLETE","statusMessage":"COMPLETED","percentProgress":100}}},{"request":{"requestId":"00164b9e-784d-48a8-8973-bbad6ef818ed","requestScope":"service","requestType":"createInstance","requestDetails":{"modelInfo":{"modelInvariantId":"52b49b5d-3086-4ffd-b5e6-1b1e5e7e062f","modelType":"service","modelName":"MSO Test Network","modelVersion":"1.0","modelVersionId":"aed5a5b7-20d3-44f7-90a3-ddbd16f14d1e"},"requestInfo":{"source":"VID","instanceName":"DEV-n6-3100-0927-1","suppressRollback":false,"requestorId":"xxxxxx"},"subscriberInfo":{"globalSubscriberId":"MSO_1610_dev","subscriberName":"MSO_1610_dev"},"cloudConfiguration":{"tenantId":"19123c2924c648eb8e42a3c1f14b7682","lcpCloudRegionId":"n6"},"requestParameters":{"subscriptionServiceType":"MSO-dev-service-type","userParams":[{"name":"someUserParam","value":"someValue"}],"aLaCarte":true,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true}},"instanceReferences":{"serviceInstanceId":"b2f59173-b7e5-4e0f-8440-232fd601b865"},"requestStatus":{"requestState":"COMPLETE","statusMessage":"Service Instance was created successfully.","percentProgress":100}}},{"request":{"requestId":"00173cc9-5ce2-4673-a810-f87fefb2829e","requestScope":"service","requestType":"createInstance","requestDetails":{"modelInfo":{"modelInvariantId":"ff6163d4-7214-459e-9f76-507b4eb00f51","modelType":"service","modelName":"ConstraintsSrvcVID","modelVersion":"2.0","modelVersionId":"722d256c-a374-4fba-a14f-a59b76bb7656"},"requestInfo":{"productFamilyId":"LRSI-OSPF","source":"VID","suppressRollback":false,"requestorId":"xxxxxx"},"subscriberInfo":{"globalSubscriberId":"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"},"cloudConfiguration":{"tenantId":"a259ae7b7c3f493cb3d91f95a7c18149","lcpCloudRegionId":"mtn16"},"requestParameters":{"subscriptionServiceType":"Mobility","userParams":[{"name":"neutronport6_name","value":"8"},{"name":"neutronnet5_network_name","value":"8"},{"name":"contrailv2vlansubinterface3_name","value":"false"}]}},"instanceReferences":{},"requestStatus":{"requestState":"FAILED","statusMessage":"Error parsing request. No valid instanceName is specified","percentProgress":100}}},{"request":{"requestId":"0017f68c-eb2d-45bb-b7c7-ec31b37dc349","requestScope":"configuration","requestType":"activateInstance","requestDetails":{"modelInfo":{"modelInvariantId":"1587cf0e-f12f-478d-8530-5c55ac578c39","modelType":"configuration","modelVersionId":"36a3a8ea-49a6-4ac8-b06c-89a545444455","modelCustomizationId":"68dc9a92-214c-11e7-93ae-92361f002671"},"requestInfo":{"source":"VID","suppressRollback":false,"requestorId":"xxxxxx"},"relatedInstanceList":[{"relatedInstance":{"instanceId":"9e15a443-af65-4f05-9000-47ae495e937d","modelInfo":{"modelInvariantId":"de19ae10-9a25-11e7-abc4-cec278b6b50a","modelType":"service","modelName":"MSOTADevInfra_Configuration_Service","modelVersion":"1.0","modelVersionId":"ee938612-9a25-11e7-abc4-cec278b6b50a"}}}],"cloudConfiguration":{"lcpCloudRegionId":"n6"},"requestParameters":{"aLaCarte":false,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true}},"instanceReferences":{"serviceInstanceId":"9e15a443-af65-4f05-9000-47ae495e937d"},"requestStatus":{"requestState":"UNLOCKED","percentProgress":20}}},{"request": {"requestId":"0017f68c-eb2d-45bb-b7c7-ec31b37dc350","requestScope":"service","requestType":"createInstance","requestStatus": {"requestState": "IN_PROGRESS", "statusMessage": "Error parsing request.\n\tNo valid instanceName is specified"}}}]}
\ No newline at end of file +{ + "requestList":[ + { + "request":{ + "requestId":"00032ab7-3fb3-42e5-965d-8ea592502017", + "requestScope":"vfModule", + "requestType":"deleteInstance", + "requestDetails":{ + "modelInfo":{ + "modelType":"vfModule", + "modelName":"test::base::module-0" + }, + "requestInfo":{ + "source":"VID", + "suppressRollback":false + }, + "cloudConfiguration":{ + "tenantId":"6accefef3cb442ff9e644d589fb04107", + "lcpCloudRegionId":"n6" + } + }, + "instanceReferences":{ + "serviceInstanceId":"e3b5744d-2ad1-4cdd-8390-c999a38829bc", + "vnfInstanceId":"b92f60c8-8de3-46c1-8dc1-e4390ac2b005", + "vfModuleInstanceId":"c7d527b1-7a91-49fd-b97d-1c8c0f4a7992" + }, + "requestStatus":{ + "requestState":"COMPLETE", + "statusMessage":"Vf Module has been deleted successfully.", + "percentProgress":100 + } + } + }, + { + "request":{ + "requestId":"00032ab7-na18-42e5-965d-8ea592502018", + "requestScope":"vfModule", + "requestType":"deleteInstance", + "requestDetails":{ + "modelInfo":{ + "modelType":"vfModule", + "modelName":"test::base::module-0" + }, + "requestInfo":{ + "source":"VID", + "suppressRollback":false + }, + "cloudConfiguration":{ + "tenantId":"6accefef3cb442ff9e644d589fb04107", + "lcpCloudRegionId":"n6" + } + }, + "instanceReferences":{ + "serviceInstanceId":"e3b5744d-2ad1-4cdd-8390-c999a38829bc", + "vnfInstanceId":"b92f60c8-8de3-46c1-8dc1-e4390ac2b005", + "vfModuleInstanceId":"c7d527b1-7a91-49fd-b97d-1c8c0f4a7992" + }, + "requestStatus":{ + "requestState":"PENDING", + "statusMessage":"Vf Module deletion pending.", + "percentProgress":0 + } + } + }, + { + "request":{ + "requestId":"00093944-bf16-4373-ab9a-3adfe730ff2d", + "requestScope":"service", + "requestType":"createInstance", + "requestDetails":{ + "modelInfo":{ + "modelInvariantId":"9647dfc4-2083-11e7-93ae-92361f002671", + "modelType":"service", + "modelName":"MSOTADevInfra_v10_Service", + "modelVersion":"1.0", + "modelVersionId":"5df8b6de-2083-11e7-93ae-92361f002671" + }, + "requestInfo":{ + "source":"VID", + "instanceName":"MSODEV_1707_SI_v10_011-4", + "suppressRollback":false, + "requestorId":"xxxxxx" + }, + "subscriberInfo":{ + "globalSubscriberId":"MSO_1610_dev", + "subscriberName":"MSO_1610_dev" + }, + "cloudConfiguration":{ + "tenantId":"19123c2924c648eb8e42a3c1f14b7682", + "lcpCloudRegionId":"n6" + }, + "requestParameters":{ + "subscriptionServiceType":"MSO-dev-service-type", + "userParams":[ + { + "name":"someUserParam", + "value":"someValue" + } + ], + "aLaCarte":true, + "autoBuildVfModules":false, + "cascadeDelete":false, + "usePreload":true + } + }, + "instanceReferences":{ + + }, + "requestStatus":{ + "requestState":"FAILED", + "statusMessage":"Error: Locked instance - This service (MSODEV_1707_SI_v10_011-4) already has a request being worked with a status of IN_PROGRESS (RequestId - 278e83b1-4f9f-450e-9e7d-3700a6ed22f4). The existing request must finish or be cleaned up before proceeding.", + "percentProgress":100 + } + } + }, + { + "request":{ + "requestId":"001619d2-a297-4a4b-a9f5-e2823c88458f", + "requestScope":"vfModule", + "requestType":"createInstance", + "instanceReferences":{ + + }, + "requestStatus":{ + "requestState":"COMPLETE", + "statusMessage":"COMPLETED", + "percentProgress":100 + } + } + }, + { + "request":{ + "requestId":"00164b9e-784d-48a8-8973-bbad6ef818ed", + "requestScope":"service", + "requestType":"createInstance", + "requestDetails":{ + "modelInfo":{ + "modelInvariantId":"52b49b5d-3086-4ffd-b5e6-1b1e5e7e062f", + "modelType":"service", + "modelName":"MSO Test Network", + "modelVersion":"1.0", + "modelVersionId":"aed5a5b7-20d3-44f7-90a3-ddbd16f14d1e" + }, + "requestInfo":{ + "source":"VID", + "instanceName":"DEV-n6-3100-0927-1", + "suppressRollback":false, + "requestorId":"xxxxxx" + }, + "subscriberInfo":{ + "globalSubscriberId":"MSO_1610_dev", + "subscriberName":"MSO_1610_dev" + }, + "cloudConfiguration":{ + "tenantId":"19123c2924c648eb8e42a3c1f14b7682", + "lcpCloudRegionId":"n6" + }, + "requestParameters":{ + "subscriptionServiceType":"MSO-dev-service-type", + "userParams":[ + { + "name":"someUserParam", + "value":"someValue" + } + ], + "aLaCarte":true, + "autoBuildVfModules":false, + "cascadeDelete":false, + "usePreload":true + } + }, + "instanceReferences":{ + "serviceInstanceId":"b2f59173-b7e5-4e0f-8440-232fd601b865" + }, + "requestStatus":{ + "requestState":"COMPLETE", + "statusMessage":"Service Instance was created successfully.", + "percentProgress":100 + } + } + }, + { + "request":{ + "requestId":"00173cc9-5ce2-4673-a810-f87fefb2829e", + "requestScope":"service", + "requestType":"createInstance", + "requestDetails":{ + "modelInfo":{ + "modelInvariantId":"ff6163d4-7214-459e-9f76-507b4eb00f51", + "modelType":"service", + "modelName":"ConstraintsSrvcVID", + "modelVersion":"2.0", + "modelVersionId":"722d256c-a374-4fba-a14f-a59b76bb7656" + }, + "requestInfo":{ + "productFamilyId":"LRSI-OSPF", + "source":"VID", + "suppressRollback":false, + "requestorId":"xxxxxx" + }, + "subscriberInfo":{ + "globalSubscriberId":"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb" + }, + "cloudConfiguration":{ + "tenantId":"a259ae7b7c3f493cb3d91f95a7c18149", + "lcpCloudRegionId":"mtn16" + }, + "requestParameters":{ + "subscriptionServiceType":"Mobility", + "userParams":[ + { + "name":"neutronport6_name", + "value":"8" + }, + { + "name":"neutronnet5_network_name", + "value":"8" + }, + { + "name":"contrailv2vlansubinterface3_name", + "value":"false" + } + ] + } + }, + "instanceReferences":{ + + }, + "requestStatus":{ + "requestState":"FAILED", + "statusMessage":"Error parsing request. No valid instanceName is specified", + "percentProgress":100 + } + } + }, + { + "request":{ + "requestId":"0017f68c-eb2d-45bb-b7c7-ec31b37dc349", + "requestScope":"configuration", + "requestType":"activateInstance", + "requestDetails":{ + "modelInfo":{ + "modelInvariantId":"1587cf0e-f12f-478d-8530-5c55ac578c39", + "modelType":"configuration", + "modelVersionId":"36a3a8ea-49a6-4ac8-b06c-89a545444455", + "modelCustomizationId":"68dc9a92-214c-11e7-93ae-92361f002671" + }, + "requestInfo":{ + "source":"VID", + "suppressRollback":false, + "requestorId":"xxxxxx" + }, + "relatedInstanceList":[ + { + "relatedInstance":{ + "instanceId":"9e15a443-af65-4f05-9000-47ae495e937d", + "modelInfo":{ + "modelInvariantId":"de19ae10-9a25-11e7-abc4-cec278b6b50a", + "modelType":"service", + "modelName":"MSOTADevInfra_Configuration_Service", + "modelVersion":"1.0", + "modelVersionId":"ee938612-9a25-11e7-abc4-cec278b6b50a" + } + } + } + ], + "cloudConfiguration":{ + "lcpCloudRegionId":"n6" + }, + "requestParameters":{ + "aLaCarte":false, + "autoBuildVfModules":false, + "cascadeDelete":false, + "usePreload":true + } + }, + "instanceReferences":{ + "serviceInstanceId":"9e15a443-af65-4f05-9000-47ae495e937d" + }, + "requestStatus":{ + "requestState":"UNLOCKED", + "percentProgress":20 + } + } + }, + { + "request":{ + "requestId":"0017f68c-eb2d-45bb-b7c7-ec31b37dc350", + "requestScope":"service", + "requestType":"createInstance", + "requestStatus":{ + "requestState":"IN_PROGRESS", + "statusMessage":"Error parsing request.\n\tNo valid instanceName is specified" + } + } + } + ] +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json new file mode 100644 index 0000000000..79caa33419 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json @@ -0,0 +1,24 @@ +[ + { + "id": 1, + "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", + "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", + "name": "requestAction", + "value": "assign", + "tag": "pincFabricConfigRequest" + },{ + "id": 2, + "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", + "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", + "name": "pincFabricId", + "value": "testId", + "tag": "pincFabricConfigRequest" + },{ + "id": 3, + "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", + "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca715", + "name": "requestAction", + "value": "unassign", + "tag": "pincFabricConfig" + } +]
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json new file mode 100644 index 0000000000..af28007900 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json @@ -0,0 +1,8 @@ +{ + "id": 1, + "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", + "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", + "name": "requestAction", + "value": "assign", + "tag": "pincFabricConfigRequest" +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/NetworkInstance.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/NetworkInstance.json index 993310d48f..a37fe050eb 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/NetworkInstance.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/NetworkInstance.json @@ -1,45 +1,18 @@ { - "requestDetails": { - "cloudConfiguration": { - "lcpCloudRegionId": "mtn6", - "tenantId": "19123c2924c648eb8e42a3c1f14b7682" - }, - "modelInfo": { - "modelInvariantId": "1710f6e8-1c29-4990-9aea-e943a2ec3d21", - "modelName": "TestNetworkType", - "modelType": "network", - "modelVersion": "2.0", - "modelVersionId": "1710966e-097c-4d63-afda-e0d3bb7015fb", - "modelCustomizationId": "3bdbb104-476c-483e-9f8b-c095b3d308ac" - }, - "requestInfo": { - "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", - "requestorId": "xxxxxx", - "source": "VID", - "suppressRollback": false, - "instanceName": "tested" - }, - "requestParameters": { - "aLaCarte" : true, - "autoBuildVfModules": false, - "subscriptionServiceType": "MSO-dev-service-type", - "userParams": [ - { - "name": "aic_zone", - "value": "mtn6" - } - ] - }, - "subscriberInfo": { - "globalSubscriberId": "MSO_1610_dev", - "subscriberName": "MSO_1610_dev" - }, - "project": { - "projectName": "projectName" - }, - "owningEntity": { - "owningEntityId": "oeId", - "owningEntityName": "oeName" - } - } + "requestDetails":{ + "modelInfo":{ + "modelType":"network" + }, + "requestInfo":{ + "source":"VID", + "requestorId":"xxxxxx" + }, + "requestParameters":{ + "testApi":"VNF_API" + }, + "cloudConfiguration":{ + "lcpCloudRegionId":"cloudRegionId", + "tenantId":"821553e85fd2461ab205bcd45cc3eeda" + } + } }
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql index 3540110351..381330b928 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql @@ -770,6 +770,77 @@ FOREIGN KEY (`NB_REQ_REF_LOOKUP_ID`) REFERENCES `northbound_request_ref_lookup` ON DELETE CASCADE ON UPDATE CASCADE) ENGINE = InnoDB DEFAULT CHARACTER SET = latin1; +CREATE TABLE IF NOT EXISTS vnfc_customization ( +`MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, +`MODEL_INSTANCE_NAME` VARCHAR(200) NOT NULL, +`MODEL_UUID` VARCHAR(200) NOT NULL, +`MODEL_INVARIANT_UUID` VARCHAR(200) NOT NULL, +`MODEL_VERSION` VARCHAR(20) NOT NULL, +`MODEL_NAME` VARCHAR(200) NOT NULL, +`TOSCA_NODE_TYPE` VARCHAR(200) NOT NULL, +`DESCRIPTION` VARCHAR(1200) NULL DEFAULT NULL, +`CREATION_TIMESTAMP` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, +PRIMARY KEY (`MODEL_CUSTOMIZATION_UUID`)) +ENGINE = InnoDB +AUTO_INCREMENT = 20654 +DEFAULT CHARACTER SET = latin1; + +CREATE TABLE IF NOT EXISTS cvnfc_customization ( +`ID` INT(11) NOT NULL AUTO_INCREMENT, +`MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, +`MODEL_INSTANCE_NAME` VARCHAR(200) NOT NULL, +`MODEL_UUID` VARCHAR(200) NOT NULL, +`MODEL_INVARIANT_UUID` VARCHAR(200) NOT NULL, +`MODEL_VERSION` VARCHAR(20) NOT NULL, +`MODEL_NAME` VARCHAR(200) NOT NULL, +`TOSCA_NODE_TYPE` VARCHAR(200) NOT NULL, +`DESCRIPTION` VARCHAR(1200) NULL DEFAULT NULL, +`NFC_FUNCTION` VARCHAR(200) NULL, +`NFC_NAMING_CODE` VARCHAR(200) NULL, +`CREATION_TIMESTAMP` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, +`VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, +`VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, +`VNFC_CUST_MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, PRIMARY KEY (`ID`), INDEX `fk_cvnfc_customization__vf_module_customization1_idx` (`VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID` ASC), INDEX `fk_cvnfc_customization__vnfc_customization1_idx` (`VNFC_CUST_MODEL_CUSTOMIZATION_UUID` ASC), INDEX `fk_cvnfc_customization__vnf_resource_customization1_idx` (`VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID` ASC), UNIQUE INDEX `UK_cvnfc_customization` (`VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID` ASC, `VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID` ASC, `MODEL_CUSTOMIZATION_UUID` ASC), INDEX `fk_cvnfc_customization__vnf_vfmod_cvnfc_config_cust1_idx` (`MODEL_CUSTOMIZATION_UUID` ASC), CONSTRAINT `fk_cvnfc_customization__vf_module_customization1` FOREIGN KEY (`VF_MODULE_CUST_MODEL_CUSTOMIZATION_UUID`) REFERENCES `vf_module_customization` (`MODEL_CUSTOMIZATION_UUID`) ON +DELETE CASCADE ON +UPDATE CASCADE, CONSTRAINT `fk_cvnfc_customization__vnfc_customization1` FOREIGN KEY (`VNFC_CUST_MODEL_CUSTOMIZATION_UUID`) REFERENCES `vnfc_customization` (`MODEL_CUSTOMIZATION_UUID`) ON +DELETE CASCADE ON +UPDATE CASCADE, CONSTRAINT `fk_cvnfc_customization__vnf_resource_customization1` FOREIGN KEY (`VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID`) REFERENCES `vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`) ON +DELETE CASCADE ON +UPDATE CASCADE) ENGINE = InnoDB AUTO_INCREMENT = 20654 DEFAULT CHARACTER SET = latin1; + +CREATE TABLE IF NOT EXISTS vnf_vfmodule_cvnfc_configuration_customization ( + `ID` INT(11) NOT NULL AUTO_INCREMENT, + `MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, + `VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, + `VF_MODULE_MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, + `CVNFC_MODEL_CUSTOMIZATION_UUID` VARCHAR(200) NOT NULL, + `MODEL_INSTANCE_NAME` VARCHAR(200) NOT NULL, + `CONFIGURATION_TYPE` VARCHAR(200) NULL, + `CONFIGURATION_ROLE` VARCHAR(200) NULL, + `CONFIGURATION_FUNCTION` VARCHAR(200) NULL, + `POLICY_NAME` VARCHAR(200) NULL, + `CREATION_TIMESTAMP` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `CONFIGURATION_MODEL_UUID` VARCHAR(200) NOT NULL, + PRIMARY KEY (`ID`), + INDEX `fk_vnf_vfmodule_cvnfc_config_cust__configuration_idx` (`CONFIGURATION_MODEL_UUID` ASC), + UNIQUE INDEX `UK_vnf_vfmodule_cvnfc_configuration_customization` (`VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID` ASC , `VF_MODULE_MODEL_CUSTOMIZATION_UUID` ASC , `CVNFC_MODEL_CUSTOMIZATION_UUID` ASC , `MODEL_CUSTOMIZATION_UUID` ASC), + INDEX `fk_vnf_vfmodule_cvnfc_config_cust__cvnfc_cust1_idx` (`CVNFC_MODEL_CUSTOMIZATION_UUID` ASC), + INDEX `fk_vnf_vfmodule_cvnfc_config_cust__vf_module_cust_idx` (`VF_MODULE_MODEL_CUSTOMIZATION_UUID` ASC), + INDEX `fk_vnf_vfmodule_cvnfc_config_cust__vnf_res_cust_idx` (`VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID` ASC), + CONSTRAINT `fk_vnf_vfmod_cvnfc_config_cust__configuration_resource` FOREIGN KEY (`CONFIGURATION_MODEL_UUID`) + REFERENCES `configuration` (`MODEL_UUID`) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_cvnfc_configuration_customization__cvnfc_customization1` FOREIGN KEY (`CVNFC_MODEL_CUSTOMIZATION_UUID`) + REFERENCES `cvnfc_customization` (`MODEL_CUSTOMIZATION_UUID`) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_vnf_configuration_cvnfc_customization__vf_module_customiza1` FOREIGN KEY (`VF_MODULE_MODEL_CUSTOMIZATION_UUID`) + REFERENCES `vf_module_customization` (`MODEL_CUSTOMIZATION_UUID`) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_vfmodule_cvnfc_configuration_customization__vnf_resource_c1` FOREIGN KEY (`VNF_RESOURCE_CUST_MODEL_CUSTOMIZATION_UUID`) + REFERENCES `vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=INNODB AUTO_INCREMENT=20654 DEFAULT CHARACTER SET=LATIN1; + --------START Request DB SCHEMA -------- CREATE DATABASE requestdb; USE requestdb; diff --git a/mso-api-handlers/mso-requests-db-repositories/pom.xml b/mso-api-handlers/mso-requests-db-repositories/pom.xml new file mode 100644 index 0000000000..a46111bf96 --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/pom.xml @@ -0,0 +1,55 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.onap.so</groupId> + <artifactId>mso-api-handlers</artifactId> + <version>1.3.0-SNAPSHOT</version> + </parent> + + <artifactId>mso-requests-db-repositories</artifactId> + + <name>mso-requests-db-repositories</name> + <description>SO Request Database JPA Respositories</description> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + </properties> + <dependencies> + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>mso-requests-db</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-rest</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <packaging>jar</packaging> + <build> + <finalName>${project.artifactId}</finalName> + </build> +</project>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java index 603f9bb494..603f9bb494 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java index cd25b122be..cd25b122be 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepository.java diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java new file mode 100644 index 0000000000..570861dfa1 --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.request.data.repository; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.springframework.stereotype.Repository; + +@Repository +public interface InfraActiveRequestsRepositoryCustom { + + public boolean healthCheck(); + + public InfraActiveRequests getRequestFromInfraActive(String requestId); + + public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, + String requestScope); + + public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap); + + // Added this method for Tenant Isolation project ( 1802-295491a) to query the mso_requests DB + // (infra_active_requests table) for operationalEnvId and OperationalEnvName + public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap); + + public List<InfraActiveRequests> getRequestListFromInfraActive(String queryAttributeName, String queryValue, + String requestType); + + public InfraActiveRequests getRequestFromInfraActive(String requestId, String requestType); + + public InfraActiveRequests checkDuplicateByVnfName(String vnfName, String action, String requestType); + + public InfraActiveRequests checkDuplicateByVnfId(String vnfId, String action, String requestType); + + public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId); + + List<InfraActiveRequests> getInfraActiveRequests(final Map<String, String[]> filters, final long startTime, + final long endTime, final Integer maxResult); + +} diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java new file mode 100644 index 0000000000..d66e378146 --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java @@ -0,0 +1,618 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.request.data.repository; + +import java.sql.Timestamp; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import javax.persistence.EntityManager; +import javax.persistence.NonUniqueResultException; +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Order; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + + +@Repository +@Transactional(readOnly = true) +public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRepositoryCustom { + + + @Qualifier("requestEntityManagerFactory") + @Autowired + private EntityManager entityManager; + + protected static MsoLogger msoLogger = + MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, InfraActiveRequestsRepositoryImpl.class); + + protected static final String REQUEST_STATUS = "requestStatus"; + protected static final String SOURCE = "source"; + protected static final String START_TIME = "startTime"; + protected static final String END_TIME = "endTime"; + protected static final String REQUEST_TYPE = "requestType"; + protected static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; + protected static final String SERVICE_INSTANCE_NAME = "serviceInstanceName"; + protected static final String VNF_INSTANCE_NAME = "vnfName"; + protected static final String VNF_INSTANCE_ID = "vnfId"; + protected static final String VOLUME_GROUP_INSTANCE_NAME = "volumeGroupName"; + protected static final String VOLUME_GROUP_INSTANCE_ID = "volumeGroupId"; + protected static final String VFMODULE_INSTANCE_NAME = "vfModuleName"; + protected static final String VFMODULE_INSTANCE_ID = "vfModuleId"; + protected static final String NETWORK_INSTANCE_NAME = "networkName"; + protected static final String CONFIGURATION_INSTANCE_ID = "configurationId"; + protected static final String CONFIGURATION_INSTANCE_NAME = "configurationName"; + protected static final String OPERATIONAL_ENV_ID = "operationalEnvId"; + protected static final String OPERATIONAL_ENV_NAME = "operationalEnvName"; + protected static final String NETWORK_INSTANCE_ID = "networkId"; + protected static final String GLOBAL_SUBSCRIBER_ID = "globalSubscriberId"; + protected static final String SERVICE_NAME_VERSION_ID = "serviceNameVersionId"; + protected static final String SERVICE_ID = "serviceId"; + protected static final String SERVICE_VERSION = "serviceVersion"; + protected static final String REQUEST_ID = "requestId"; + protected static final String REQUESTOR_ID = "requestorId"; + protected static final String ACTION = "action"; + + private static final List<String> VALID_COLUMNS = + Arrays.asList(REQUEST_ID, SERVICE_INSTANCE_ID, SERVICE_INSTANCE_NAME, ACTION, REQUEST_STATUS); + + + /* + * (non-Javadoc) + * + * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#healthCheck() + */ + @Override + public boolean healthCheck() { + + final Query query = entityManager.createNativeQuery(" show tables "); + + final List<?> list = query.getResultList(); + + return true; + } + + private List<InfraActiveRequests> executeInfraQuery(final CriteriaQuery<InfraActiveRequests> crit, + final List<Predicate> predicates, final Order order) { + + final long startTime = System.currentTimeMillis(); + msoLogger.debug("Execute query on infra active request table"); + + List<InfraActiveRequests> results = new ArrayList<InfraActiveRequests>(); + + try { + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + crit.where(cb.and(predicates.toArray(new Predicate[0]))); + crit.orderBy(order); + results = entityManager.createQuery(crit).getResultList(); + + } finally { + msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "RequestDB", "getInfraActiveRequest", null); + } + return results; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getRequestFromInfraActive(java. + * lang.String) + */ + @Override + public InfraActiveRequests getRequestFromInfraActive(final String requestId) { + final long startTime = System.currentTimeMillis(); + msoLogger.debug("Get request " + requestId + " from InfraActiveRequests DB"); + + InfraActiveRequests ar = null; + try { + final Query query = entityManager.createQuery( + "from InfraActiveRequests where requestId = :requestId OR clientRequestId = :requestId"); + query.setParameter(REQUEST_ID, requestId); + ar = this.getSingleResult(query); + } finally { + + msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "InfraRequestDB", "getRequestFromInfraActive", null); + } + return ar; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkInstanceNameDuplicate(java. + * util.HashMap, java.lang.String, java.lang.String) + */ + @Override + public InfraActiveRequests checkInstanceNameDuplicate(final HashMap<String, String> instanceIdMap, + final String instanceName, final String requestScope) { + + final List<Predicate> predicates = new LinkedList<>(); + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); + final Root<InfraActiveRequests> tableRoot = crit.from(InfraActiveRequests.class); + + if (instanceName != null && !instanceName.equals("")) { + + if ("service".equals(requestScope)) { + predicates.add(cb.equal(tableRoot.get(SERVICE_INSTANCE_NAME), instanceName)); + } else if ("vnf".equals(requestScope)) { + predicates.add(cb.equal(tableRoot.get(VNF_INSTANCE_NAME), instanceName)); + } else if ("volumeGroup".equals(requestScope)) { + predicates.add(cb.equal(tableRoot.get(VOLUME_GROUP_INSTANCE_NAME), instanceName)); + } else if ("vfModule".equals(requestScope)) { + predicates.add(cb.equal(tableRoot.get(VFMODULE_INSTANCE_NAME), instanceName)); + } else if ("network".equals(requestScope)) { + predicates.add(cb.equal(tableRoot.get(NETWORK_INSTANCE_NAME), instanceName)); + } else if (requestScope.equals("configuration")) { + predicates.add(cb.equal(tableRoot.get(CONFIGURATION_INSTANCE_NAME), instanceName)); + } else if (requestScope.equals("operationalEnvironment")) { + predicates.add(cb.equal(tableRoot.get(OPERATIONAL_ENV_NAME), instanceName)); + } + + } else { + if (instanceIdMap != null) { + if ("service".equals(requestScope) && instanceIdMap.get("serviceInstanceId") != null) { + predicates + .add(cb.equal(tableRoot.get(SERVICE_INSTANCE_ID), instanceIdMap.get("serviceInstanceId"))); + } + + if ("vnf".equals(requestScope) && instanceIdMap.get("vnfInstanceId") != null) { + predicates.add(cb.equal(tableRoot.get(VNF_INSTANCE_ID), instanceIdMap.get("vnfInstanceId"))); + } + + if ("vfModule".equals(requestScope) && instanceIdMap.get("vfModuleInstanceId") != null) { + predicates.add( + cb.equal(tableRoot.get(VFMODULE_INSTANCE_ID), instanceIdMap.get("vfModuleInstanceId"))); + } + + if ("volumeGroup".equals(requestScope) && instanceIdMap.get("volumeGroupInstanceId") != null) { + predicates.add(cb.equal(tableRoot.get(VOLUME_GROUP_INSTANCE_ID), + instanceIdMap.get("volumeGroupInstanceId"))); + } + + if ("network".equals(requestScope) && instanceIdMap.get("networkInstanceId") != null) { + predicates + .add(cb.equal(tableRoot.get(NETWORK_INSTANCE_ID), instanceIdMap.get("networkInstanceId"))); + } + + if (requestScope.equals("configuration") && instanceIdMap.get("configurationInstanceId") != null) { + predicates.add(cb.equal(tableRoot.get(CONFIGURATION_INSTANCE_ID), + instanceIdMap.get("configurationInstanceId"))); + } + + if (requestScope.equals("operationalEnvironment") + && instanceIdMap.get("operationalEnvironmentId") != null) { + predicates.add( + cb.equal(tableRoot.get(OPERATIONAL_ENV_ID), instanceIdMap.get("operationalEnvironmentId"))); + } + } + } + + predicates.add(tableRoot.get(REQUEST_STATUS) + .in(Arrays.asList("PENDING", "IN_PROGRESS", "TIMEOUT", "PENDING_MANUAL_TASK"))); + + final Order order = cb.desc(tableRoot.get(START_TIME)); + + final List<InfraActiveRequests> dupList = executeInfraQuery(crit, predicates, order); + + InfraActiveRequests infraActiveRequests = null; + + if (dupList != null && !dupList.isEmpty()) { + infraActiveRequests = dupList.get(0); + } + + return infraActiveRequests; + } + + /* + * (non-Javadoc) + * + * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom# + * getOrchestrationFiltersFromInfraActive(java.util.Map) + */ + @Override + public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive( + final Map<String, List<String>> orchestrationMap) { + + + final List<Predicate> predicates = new LinkedList<>(); + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); + final Root<InfraActiveRequests> tableRoot = crit.from(InfraActiveRequests.class); + for (final Map.Entry<String, List<String>> entry : orchestrationMap.entrySet()) { + String mapKey = entry.getKey(); + if ("serviceInstanceId".equalsIgnoreCase(mapKey)) { + mapKey = "serviceInstanceId"; + } else if ("serviceInstanceName".equalsIgnoreCase(mapKey)) { + mapKey = "serviceInstanceName"; + } else if ("vnfInstanceId".equalsIgnoreCase(mapKey)) { + mapKey = "vnfId"; + } else if ("vnfInstanceName".equalsIgnoreCase(mapKey)) { + mapKey = "vnfName"; + } else if ("vfModuleInstanceId".equalsIgnoreCase(mapKey)) { + mapKey = "vfModuleId"; + } else if ("vfModuleInstanceName".equalsIgnoreCase(mapKey)) { + mapKey = "vfModuleName"; + } else if ("volumeGroupInstanceId".equalsIgnoreCase(mapKey)) { + mapKey = "volumeGroupId"; + } else if ("volumeGroupInstanceName".equalsIgnoreCase(mapKey)) { + mapKey = "volumeGroupName"; + } else if ("networkInstanceId".equalsIgnoreCase(mapKey)) { + mapKey = "networkId"; + } else if ("networkInstanceName".equalsIgnoreCase(mapKey)) { + mapKey = "networkName"; + } else if (mapKey.equalsIgnoreCase("configurationInstanceId")) { + mapKey = "configurationId"; + } else if (mapKey.equalsIgnoreCase("configurationInstanceName")) { + mapKey = "configurationName"; + } else if ("lcpCloudRegionId".equalsIgnoreCase(mapKey)) { + mapKey = "aicCloudRegion"; + } else if ("tenantId".equalsIgnoreCase(mapKey)) { + mapKey = "tenantId"; + } else if ("modelType".equalsIgnoreCase(mapKey)) { + mapKey = "requestScope"; + } else if ("requestorId".equalsIgnoreCase(mapKey)) { + mapKey = "requestorId"; + } else if ("requestExecutionDate".equalsIgnoreCase(mapKey)) { + mapKey = "startTime"; + } + + final String propertyValue = entry.getValue().get(1); + if ("startTime".equals(mapKey)) { + final SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); + try { + final Date thisDate = format.parse(propertyValue); + final Timestamp minTime = new Timestamp(thisDate.getTime()); + final Timestamp maxTime = new Timestamp(thisDate.getTime() + TimeUnit.DAYS.toMillis(1)); + + if ("DOES_NOT_EQUAL".equalsIgnoreCase(entry.getValue().get(0))) { + predicates.add(cb.or(cb.lessThan(tableRoot.get(mapKey), minTime), + cb.greaterThanOrEqualTo(tableRoot.get(mapKey), maxTime))); + } else { + predicates.add(cb.between(tableRoot.get(mapKey), minTime, maxTime)); + } + } catch (final Exception e) { + msoLogger.debug("Exception in getOrchestrationFiltersFromInfraActive(): + " + e.getMessage(), e); + return null; + } + } else if ("DOES_NOT_EQUAL".equalsIgnoreCase(entry.getValue().get(0))) { + predicates.add(cb.notEqual(tableRoot.get(mapKey), propertyValue)); + } else { + predicates.add(cb.equal(tableRoot.get(mapKey), propertyValue)); + } + + } + + final Order order = cb.asc(tableRoot.get(START_TIME)); + + return executeInfraQuery(crit, predicates, order); + } + + // Added this method for Tenant Isolation project ( 1802-295491a) to query the mso_requests DB + // (infra_active_requests table) for operationalEnvId and OperationalEnvName + /* + * (non-Javadoc) + * + * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom# + * getCloudOrchestrationFiltersFromInfraActive(java.util.Map) + */ + @Override + public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive( + final Map<String, String> orchestrationMap) { + final List<Predicate> predicates = new LinkedList<>(); + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); + final Root<InfraActiveRequests> tableRoot = crit.from(InfraActiveRequests.class); + + // Add criteria on OperationalEnvironment RequestScope when requestorId is only specified in + // the filter + // as the same requestorId can also match on different API methods + final String resourceType = orchestrationMap.get("resourceType"); + if (resourceType == null) { + predicates.add(cb.equal(tableRoot.get("requestScope"), "operationalEnvironment")); + } + + for (final Map.Entry<String, String> entry : orchestrationMap.entrySet()) { + String mapKey = entry.getKey(); + if (mapKey.equalsIgnoreCase("requestorId")) { + mapKey = "requestorId"; + } else if (mapKey.equalsIgnoreCase("requestExecutionDate")) { + mapKey = "startTime"; + } else if (mapKey.equalsIgnoreCase("operationalEnvironmentId")) { + mapKey = "operationalEnvId"; + } else if (mapKey.equalsIgnoreCase("operationalEnvironmentName")) { + mapKey = "operationalEnvName"; + } else if (mapKey.equalsIgnoreCase("resourceType")) { + mapKey = "requestScope"; + } + + final String propertyValue = entry.getValue(); + if (mapKey.equals("startTime")) { + final SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); + try { + final Date thisDate = format.parse(propertyValue); + final Timestamp minTime = new Timestamp(thisDate.getTime()); + final Timestamp maxTime = new Timestamp(thisDate.getTime() + TimeUnit.DAYS.toMillis(1)); + + predicates.add(cb.between(tableRoot.get(mapKey), minTime, maxTime)); + } catch (final Exception e) { + msoLogger.debug("Exception in getCloudOrchestrationFiltersFromInfraActive(): + " + e.getMessage()); + return null; + } + } else { + predicates.add(cb.equal(tableRoot.get(mapKey), propertyValue)); + } + } + + final Order order = cb.asc(tableRoot.get(START_TIME)); + return executeInfraQuery(crit, predicates, order); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getRequestListFromInfraActive(java + * .lang.String, java.lang.String, java.lang.String) + */ + @Override + public List<InfraActiveRequests> getRequestListFromInfraActive(final String queryAttributeName, + final String queryValue, final String requestType) { + msoLogger.debug("Get list of infra requests from DB with " + queryAttributeName + " = " + queryValue); + + + try { + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); + final Root<InfraActiveRequests> candidateRoot = crit.from(InfraActiveRequests.class); + final Predicate isEqual = cb.equal(candidateRoot.get(queryAttributeName), queryValue); + final Predicate equalRequestType = cb.equal(candidateRoot.get(REQUEST_TYPE), requestType); + final Predicate isNull = cb.isNull(candidateRoot.get(REQUEST_TYPE)); + final Predicate orClause = cb.or(equalRequestType, isNull); + final Order orderDesc = cb.desc(candidateRoot.get(START_TIME)); + final Order orderAsc = cb.asc(candidateRoot.get(SOURCE)); + crit.where(cb.and(isEqual, orClause)).orderBy(orderDesc, orderAsc); + + final List<InfraActiveRequests> arList = entityManager.createQuery(crit).getResultList(); + if (arList != null && !arList.isEmpty()) { + return arList; + } + } catch (final Exception exception) { + msoLogger.error("Unable to execute query", exception); + } + return Collections.emptyList(); + } + + + /* + * (non-Javadoc) + * + * @see + * org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getRequestFromInfraActive(java. + * lang.String, java.lang.String) + */ + @Override + public InfraActiveRequests getRequestFromInfraActive(final String requestId, final String requestType) { + final long startTime = System.currentTimeMillis(); + msoLogger.debug("Get infra request from DB with id " + requestId); + + InfraActiveRequests ar = null; + try { + final Query query = entityManager.createQuery( + "from InfraActiveRequests where (requestId = :requestId OR clientRequestId = :requestId) and requestType = :requestType"); + query.setParameter(REQUEST_ID, requestId); + query.setParameter(REQUEST_TYPE, requestType); + ar = this.getSingleResult(query); + } finally { + msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "RequestDB", "getRequestFromInfraActive", null); + } + return ar; + } + + + /* + * (non-Javadoc) + * + * @see + * org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkDuplicateByVnfName(java.lang. + * String, java.lang.String, java.lang.String) + */ + @Override + public InfraActiveRequests checkDuplicateByVnfName(final String vnfName, final String action, + final String requestType) { + + final long startTime = System.currentTimeMillis(); + msoLogger.debug("Get infra request from DB for VNF " + vnfName + " and action " + action + " and requestType " + + requestType); + + InfraActiveRequests ar = null; + try { + final Query query = entityManager.createQuery( + "from InfraActiveRequests where vnfName = :vnfName and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT' or requestStatus = 'PENDING_MANUAL_TASK') and requestType = :requestType ORDER BY startTime DESC"); + query.setParameter("vnfName", vnfName); + query.setParameter("action", action); + query.setParameter(REQUEST_TYPE, requestType); + @SuppressWarnings("unchecked") + final List<InfraActiveRequests> results = query.getResultList(); + if (!results.isEmpty()) { + ar = results.get(0); + } + } finally { + msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "RequestDB", "checkDuplicateByVnfName", null); + } + + return ar; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkDuplicateByVnfId(java.lang. + * String, java.lang.String, java.lang.String) + */ + @Override + public InfraActiveRequests checkDuplicateByVnfId(final String vnfId, final String action, + final String requestType) { + + final long startTime = System.currentTimeMillis(); + msoLogger.debug("Get list of infra requests from DB for VNF " + vnfId + " and action " + action); + + InfraActiveRequests ar = null; + try { + final Query query = entityManager.createQuery( + "from InfraActiveRequests where vnfId = :vnfId and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT' or requestStatus = 'PENDING_MANUAL_TASK') and requestType = :requestType ORDER BY startTime DESC"); + query.setParameter("vnfId", vnfId); + query.setParameter("action", action); + query.setParameter(REQUEST_TYPE, requestType); + @SuppressWarnings("unchecked") + final List<InfraActiveRequests> results = query.getResultList(); + if (!results.isEmpty()) { + ar = results.get(0); + } + } finally { + msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "RequestDB", "checkDuplicateByVnfId", null); + } + + return ar; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkVnfIdStatus(java.lang.String) + */ + @Override + public InfraActiveRequests checkVnfIdStatus(final String operationalEnvironmentId) { + final long startTime = System.currentTimeMillis(); + msoLogger.debug("Get Infra request from DB for OperationalEnvironmentId " + operationalEnvironmentId); + + InfraActiveRequests ar = null; + try { + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); + final Root<InfraActiveRequests> candidateRoot = crit.from(InfraActiveRequests.class); + final Predicate operationalEnvEq = + cb.equal(candidateRoot.get("operationalEnvId"), operationalEnvironmentId); + final Predicate requestStatusNotEq = cb.notEqual(candidateRoot.get(REQUEST_STATUS), "COMPLETE"); + final Predicate actionEq = cb.equal(candidateRoot.get("action"), "create"); + final Order startTimeOrder = cb.desc(candidateRoot.get("startTime")); + crit.select(candidateRoot); + crit.where(cb.and(operationalEnvEq, requestStatusNotEq, actionEq)); + crit.orderBy(startTimeOrder); + final TypedQuery<InfraActiveRequests> query = entityManager.createQuery(crit); + final List<InfraActiveRequests> results = query.getResultList(); + if (!results.isEmpty()) { + ar = results.get(0); + } + } finally { + msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, + "Successfully", "RequestDB", "checkDuplicateByVnfName", null); + } + + return ar; + } + + protected <T> T getSingleResult(final Query query) { + query.setMaxResults(1); + final List<T> list = query.getResultList(); + if (list == null || list.isEmpty()) { + return null; + } else if (list.size() == 1) { + return list.get(0); + } else { + throw new NonUniqueResultException(); + } + + } + + @Override + public List<InfraActiveRequests> getInfraActiveRequests(final Map<String, String[]> filters, final long startTime, + final long endTime, final Integer maxResult) { + if (filters == null) { + return Collections.emptyList(); + } + try { + final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + final CriteriaQuery<InfraActiveRequests> criteriaQuery = + criteriaBuilder.createQuery(InfraActiveRequests.class); + final Root<InfraActiveRequests> tableRoot = criteriaQuery.from(InfraActiveRequests.class); + final List<Predicate> predicates = getPredicates(filters, criteriaBuilder, tableRoot); + + final Timestamp minTime = new Timestamp(startTime); + final Timestamp maxTime = new Timestamp(endTime); + predicates.add(criteriaBuilder.greaterThanOrEqualTo(tableRoot.get(START_TIME), minTime)); + predicates.add(criteriaBuilder.lessThanOrEqualTo(tableRoot.get(END_TIME), maxTime)); + + criteriaQuery.where(criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]))); + if (maxResult != null) { + return entityManager.createQuery(criteriaQuery).setMaxResults(maxResult).getResultList(); + } + return entityManager.createQuery(criteriaQuery).getResultList(); + } catch (final Exception exception) { + msoLogger.error("Unable to execute query using filters: " + filters, exception); + return Collections.emptyList(); + } + } + + private List<Predicate> getPredicates(final Map<String, String[]> filters, final CriteriaBuilder criteriaBuilder, + final Root<InfraActiveRequests> tableRoot) { + final List<Predicate> predicates = new LinkedList<>(); + for (final Entry<String, String[]> entry : filters.entrySet()) { + final String[] params = entry.getValue(); + if (VALID_COLUMNS.contains(entry.getKey()) && params.length == 2) { + final QueryOperationType operationType = QueryOperationType.getQueryOperationType(params[0]); + final Predicate predicate = + operationType.getPredicate(criteriaBuilder, tableRoot, entry.getKey(), params[1]); + predicates.add(predicate); + } + } + return predicates; + } +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java index 16e10e3d5b..16e10e3d5b 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java index e89755d565..e89755d565 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java index bcad9ce6d5..bcad9ce6d5 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java new file mode 100644 index 0000000000..f80be0525c --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.request.data.repository; + +import java.util.List; + +import org.onap.so.db.request.beans.RequestProcessingData; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource(collectionResourceRel = "requestProcessingData", path = "requestProcessingData") +public interface RequestProcessingDataRepository extends JpaRepository<RequestProcessingData, Integer> { + RequestProcessingData findOneBySoRequestIdAndGroupingIdAndNameAndTag( + @Param("SO_REQUEST_ID") String soRequestId, @Param("GROUPING_ID") String groupingId, + @Param("NAME") String name, @Param("TAG") String tag); + + List<RequestProcessingData> findBySoRequestIdOrderByGroupingIdDesc(@Param("SO_REQUEST_ID") String soRequestId); +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java index b93bf7840b..b93bf7840b 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java index 179d40ad23..179d40ad23 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java index 138ec0fb4d..138ec0fb4d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java index fde8485e6d..fde8485e6d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java index b9585d495e..b9585d495e 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/BaseTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/BaseTest.java new file mode 100644 index 0000000000..5a8df1d556 --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/BaseTest.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public abstract class BaseTest { + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/TestApplication.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java index ec2c41bf8c..00d212a23e 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/TestApplication.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/TestApplication.java @@ -24,7 +24,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Profile; -@SpringBootApplication(scanBasePackages = { "org.onap" }) +@SpringBootApplication(scanBasePackages = { "org.onap.so.db" }) @Profile("test") public class TestApplication { public static void main(String... args) { diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/OperationStatusTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationStatusTest.java index a10d948b8f..a10d948b8f 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/OperationStatusTest.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationStatusTest.java diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java index c12d3cbb7b..c12d3cbb7b 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/OperationalEnvServiceModelStatusTest.java diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/RequestDBConfig.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/RequestDBConfig.java index 9bcff13699..9bcff13699 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/RequestDBConfig.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/RequestDBConfig.java diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/SiteStatusTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/SiteStatusTest.java index 917f52d4ad..917f52d4ad 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/SiteStatusTest.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/SiteStatusTest.java diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java new file mode 100644 index 0000000000..d889a15fc4 --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImplTest.java @@ -0,0 +1,184 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.db.request.data.repository; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.onap.so.db.request.data.repository.InfraActiveRequestsRepositoryImpl.ACTION; +import static org.onap.so.db.request.data.repository.InfraActiveRequestsRepositoryImpl.REQUEST_ID; +import static org.onap.so.db.request.data.repository.InfraActiveRequestsRepositoryImpl.SERVICE_INSTANCE_ID; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.TestApplication; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class InfraActiveRequestsRepositoryImplTest { + + private static final int MAX_LIMIT = 1; + private static final long END_TIME_IN_MILISEC = 1482436800000l; + private static final long START_TIME_IN_MILISEC = 1482429600000l; + private static final String REQUEST_ID_VALUE = "00032ab7-3fb3-42e5-965d-8ea592502017"; + private static final String SERVICE_INSTANCE_ID_VALUE = "e3b5744d-2ad1-4cdd-8390-c999a38829bc"; + + @Autowired + private InfraActiveRequestsRepository objUnderTest; + + @Test + public void test_GetInfraActiveRequests_emptyFiltersMap() { + final List<InfraActiveRequests> actualRequests = objUnderTest.getInfraActiveRequests(Collections.emptyMap(), + START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, null); + assertFalse(actualRequests.isEmpty()); + } + + @Test + public void test_GetInfraActiveRequests_invalidFiltersMap() { + final Map<String, String[]> filters = new HashMap<>(); + filters.put("OverTheMoon", new String[] {"Humpty Dumpty Sat On The Wall"}); + final long startTime = START_TIME_IN_MILISEC - TimeUnit.DAYS.toMillis(20); + final long endTime = END_TIME_IN_MILISEC - TimeUnit.DAYS.toMillis(20); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(filters, startTime, endTime, null); + assertTrue(actualRequests.isEmpty()); + } + + @Test + public void test_GetInfraActiveRequests_invalidFiltersMapWithInvalidKey() { + final Map<String, String[]> filters = new HashMap<>(); + filters.put("OverTheMoon", new String[] {"Avengers", "Humpty Dumpty Sat On The Wall"}); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(filters, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, null); + assertFalse(actualRequests.isEmpty()); + } + + @Test + public void test_GetInfraActiveRequestsData_withEqualServiceInstanceId() { + final Map<String, String[]> values = new HashMap<>(); + values.put(SERVICE_INSTANCE_ID, new String[] {QueryOperationType.EQ.name(), SERVICE_INSTANCE_ID_VALUE}); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(values, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, 1); + assertFalse(actualRequests.isEmpty()); + + assertEquals(SERVICE_INSTANCE_ID_VALUE, actualRequests.get(0).getServiceInstanceId()); + } + + + @Test + public void test_GetInfraActiveRequestsData_withLikeRequestID() { + final Map<String, String[]> values = new HashMap<>(); + values.put(REQUEST_ID, new String[] {QueryOperationType.LIKE.name(), "00032ab7"}); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(values, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, 1); + assertFalse(actualRequests.isEmpty()); + + assertEquals(REQUEST_ID_VALUE, actualRequests.get(0).getRequestId()); + assertEquals(SERVICE_INSTANCE_ID_VALUE, actualRequests.get(0).getServiceInstanceId()); + } + + + @Test + public void test_GetInfraActiveRequestsData_withLikeRequestIDAndEqualToServiceInstanceId() { + final Map<String, String[]> values = new HashMap<>(); + values.put(REQUEST_ID, new String[] {QueryOperationType.LIKE.name(), "00032ab7"}); + values.put(SERVICE_INSTANCE_ID, new String[] {QueryOperationType.EQ.name(), SERVICE_INSTANCE_ID_VALUE}); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(values, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, 1); + assertFalse(actualRequests.isEmpty()); + + assertEquals(REQUEST_ID_VALUE, actualRequests.get(0).getRequestId()); + assertEquals(SERVICE_INSTANCE_ID_VALUE, actualRequests.get(0).getServiceInstanceId()); + } + + + @Test + public void test_GetInfraActiveRequestsData_withNotEqualAction() { + final Map<String, String[]> values = new HashMap<>(); + values.put(ACTION, new String[] {QueryOperationType.NEQ.name(), "createInstance"}); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(values, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, null); + assertFalse(actualRequests.isEmpty()); + for (final InfraActiveRequests actualActiveRequests : actualRequests) { + assertNotEquals("createInstance", actualActiveRequests.getAction()); + } + } + + + @Test + public void test_GetInfraActiveRequestsData_withNotEqualToServiceInstanceNameAndServiceInstanceIdNul() { + final Map<String, String[]> values = new HashMap<>(); + values.put(ACTION, new String[] {QueryOperationType.NEQ.name(), "createInstance"}); + values.put(SERVICE_INSTANCE_ID, new String[] {QueryOperationType.EQ.name(), SERVICE_INSTANCE_ID_VALUE}); + + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(values, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, null); + assertFalse(actualRequests.isEmpty()); + for (final InfraActiveRequests actualActiveRequests : actualRequests) { + assertNotEquals("createInstance", actualActiveRequests.getAction()); + assertEquals(SERVICE_INSTANCE_ID_VALUE, actualActiveRequests.getServiceInstanceId()); + } + } + + @Test + public void test_GetInfraActiveRequestsData_withStartEndDateTimeNotEqualAction() { + final Map<String, String[]> values = new HashMap<>(); + values.put(ACTION, new String[] {QueryOperationType.NEQ.name(), "createInstance"}); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(values, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, null); + assertFalse(actualRequests.isEmpty()); + for (final InfraActiveRequests actualActiveRequests : actualRequests) { + assertNotEquals("createInstance", actualActiveRequests.getAction()); + } + } + + @Test + public void test_GetInfraActiveRequestsData_withLimitNotEqualAction() { + final Map<String, String[]> values = new HashMap<>(); + values.put(ACTION, new String[] {QueryOperationType.NEQ.name(), "createInstance"}); + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(values, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, MAX_LIMIT); + assertFalse(actualRequests.isEmpty()); + for (final InfraActiveRequests actualActiveRequests : actualRequests) { + assertNotEquals("createInstance", actualActiveRequests.getAction()); + } + } + + @Test + public void test_GetInfraActiveRequestsData_withNullFilters() { + final List<InfraActiveRequests> actualRequests = + objUnderTest.getInfraActiveRequests(null, START_TIME_IN_MILISEC, END_TIME_IN_MILISEC, MAX_LIMIT); + assertTrue(actualRequests.isEmpty()); + } +} diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/resources/afterMigrate.sql b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/afterMigrate.sql new file mode 100644 index 0000000000..897dd3faca --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/afterMigrate.sql @@ -0,0 +1,35 @@ +use requestdb; + +insert into operation_status(service_id, operation_id, service_name, user_id, result, operation_content, progress, reason, operate_at, finished_at) values +('serviceid', 'operationid', 'servicename', 'userid', 'result', 'operationcontent', 'progress', 'reason', '2016-11-24 13:19:10', '2016-11-24 13:19:10'); + + +insert into infra_active_requests(request_id, client_request_id, action, request_status, status_message, progress, start_time, end_time, source, vnf_id, vnf_name, vnf_type, service_type, aic_node_clli, tenant_id, prov_status, vnf_params, vnf_outputs, request_body, response_body, last_modified_by, modify_time, request_type, volume_group_id, volume_group_name, vf_module_id, vf_module_name, vf_module_model_name, aai_service_id, aic_cloud_region, callback_url, correlator, network_id, network_name, network_type, request_scope, request_action, service_instance_id, service_instance_name, requestor_id, configuration_id, configuration_name, operational_env_id, operational_env_name) values +('00032ab7-3fb3-42e5-965d-8ea592502017', '00032ab7-3fb3-42e5-965d-8ea592502016', 'deleteInstance', 'COMPLETE', 'Vf Module has been deleted successfully.', '100', '2016-12-22 18:59:54', '2016-12-22 19:00:28', 'VID', 'b92f60c8-8de3-46c1-8dc1-e4390ac2b005', null, null, null, null, '6accefef3cb442ff9e644d589fb04107', null, null, null, '{"requestDetails":{"modelInfo":{"modelType":"vfModule","modelName":"vSAMP10aDEV::base::module-0"},"requestInfo":{"source":"VID"},"cloudConfiguration":{"tenantId":"6accefef3cb442ff9e644d589fb04107","lcpCloudRegionId":"mtn6"}}}', null, 'BPMN', '2016-12-22 19:00:28', null, null, null, 'c7d527b1-7a91-49fd-b97d-1c8c0f4a7992', null, 'vSAMP10aDEV::base::module-0', null, 'mtn6', null, null, null, null, null, 'vfModule', 'deleteInstance', 'e3b5744d-2ad1-4cdd-8390-c999a38829bc', null, null, null, null, null, null), +('00093944-bf16-4373-ab9a-3adfe730ff2d', null, 'createInstance', 'FAILED', 'Error: Locked instance - This service (MSODEV_1707_SI_vSAMP10a_011-4) already has a request being worked with a status of IN_PROGRESS (RequestId - 278e83b1-4f9f-450e-9e7d-3700a6ed22f4). The existing request must finish or be cleaned up before proceeding.', '100', '2017-07-11 18:33:26', '2017-07-11 18:33:26', 'VID', null, null, null, null, null, '19123c2924c648eb8e42a3c1f14b7682', null, null, null, '{"requestDetails":{"modelInfo":{"modelInvariantId":"9647dfc4-2083-11e7-93ae-92361f002671","modelType":"service","modelName":"MSOTADevInfra_vSAMP10a_Service","modelVersion":"1.0","modelVersionId":"5df8b6de-2083-11e7-93ae-92361f002671"},"requestInfo":{"source":"VID","instanceName":"MSODEV_1707_SI_vSAMP10a_011-4","suppressRollback":false,"requestorId":"xxxxxx"},"subscriberInfo":{"globalSubscriberId":"MSO_1610_dev","subscriberName":"MSO_1610_dev"},"cloudConfiguration":{"tenantId":"19123c2924c648eb8e42a3c1f14b7682","lcpCloudRegionId":"mtn6"},"requestParameters":{"subscriptionServiceType":"MSO-dev-service-type","userParams":[{"name":"someUserParam","value":"someValue"}],"aLaCarte":true,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true,"alaCarteSet":true,"alaCarte":true}}}', null, 'APIH', '2016-12-22 19:00:28', null, null, null, null, null, null, null, 'mtn6', null, null, null, null, null, 'service', 'createInstance', null, 'MSODEV_1707_SI_vSAMP10a_011-4', 'xxxxxx', null, null, null, null), +('001619d2-a297-4a4b-a9f5-e2823c88458f', '001619d2-a297-4a4b-a9f5-e2823c88458f', 'CREATE_VF_MODULE', 'COMPLETE', 'COMPLETED', '100', '2016-07-01 14:11:42', '2017-05-02 16:03:34', 'PORTAL', null, 'test-vscp', 'elena_test21', null, null, '381b9ff6c75e4625b7a4182f90fc68d3', null, null, null, '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<vnf-request xmlns=\"http://org.onap.so/mso/infra/vnf-request/v1\">\n <request-info>\n <request-id>001619d2-a297-4a4b-a9f5-e2823c88458f</request-id>\n <action>CREATE_VF_MODULE</action>\n <source>PORTAL</source>\n </request-info>\n <vnf-inputs>\n <vnf-name>test-vscp</vnf-name>\n <vf-module-name>moduleName</vf-module-name>\n <vnf-type>elena_test21</vnf-type>\n <vf-module-model-name>moduleModelName</vf-module-model-name>\n <asdc-service-model-version>1.0</asdc-service-model-version>\n <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>\n <aic-cloud-region>mtn9</aic-cloud-region>\n <tenant-id>381b9ff6c75e4625b7a4182f90fc68d3</tenant-id>\n <persona-model-id></persona-model-id>\n <persona-model-version></persona-model-version>\n <is-base-vf-module>false</is-base-vf-module>\n </vnf-inputs>\n <vnf-params xmlns:tns=\"http://org.onap.so/mso/infra/vnf-request/v1\"/>\n</vnf-request>\n', 'NONE', 'RDBTEST', '2016-07-01 14:11:42', 'VNF', null, null, null, 'MODULENAME1', 'moduleModelName', 'a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb', 'mtn9', null, null, null, null, null, 'vfModule', 'createInstance', null, null, null, null, null, null, null), +('00164b9e-784d-48a8-8973-bbad6ef818ed', null, 'createInstance', 'COMPLETE', 'Service Instance was created successfully.', '100', '2017-09-28 12:45:51', '2017-09-28 12:45:53', 'VID', null, null, null, null, null, '19123c2924c648eb8e42a3c1f14b7682', null, null, null, '{"requestDetails":{"requestDetails":{"modelInfo":{"modelCustomizationName":null,"modelInvariantId":"52b49b5d-3086-4ffd-b5e6-1b1e5e7e062f","modelType":"service","modelNameVersionId":null,"modelName":"MSO Test Network","modelVersion":"1.0","modelCustomizationUuid":null,"modelVersionId":"aed5a5b7-20d3-44f7-90a3-ddbd16f14d1e","modelCustomizationId":null,"modelUuid":null,"modelInvariantUuid":null,"modelInstanceName":null},"requestInfo":{"billingAccountNumber":null,"callbackUrl":null,"correlator":null,"orderNumber":null,"productFamilyId":null,"orderVersion":null,"source":"VID","instanceName":"DEV-MTN6-3100-0927-1","suppressRollback":false,"requestorId":"xxxxxx"},"relatedInstanceList":null,"subscriberInfo":{"globalSubscriberId":"MSO_1610_dev","subscriberName":"MSO_1610_dev"},"cloudConfiguration":{"aicNodeClli":null,"tenantId":"19123c2924c648eb8e42a3c1f14b7682","lcpCloudRegionId":"mtn6"},"requestParameters":{"subscriptionServiceType":"MSO-dev-service-type","userParams":[{"name":"someUserParam","value":"someValue"}],"aLaCarte":true,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true,"alaCarte":true},"project":null,"owningEntity":null,"platform":null,"lineOfBusiness":null}}}', null, 'CreateGenericALaCarteServiceInstance', '2017-09-28 12:45:52', null, null, null, null, null, null, null, 'mtn6', null, null, null, null, null, 'service', 'createInstance', 'b2f59173-b7e5-4e0f-8440-232fd601b865', 'DEV-MTN6-3100-0927-1', 'xxxxxx', null, null, null, null), +('00173cc9-5ce2-4673-a810-f87fefb2829e', null, 'createInstance', 'FAILED', 'Error parsing request. No valid instanceName is specified', '100', '2017-04-14 21:08:46', '2017-04-14 21:08:46', 'VID', null, null, null, null, null, 'a259ae7b7c3f493cb3d91f95a7c18149', null, null, null, '{"requestDetails":{"modelInfo":{"modelInvariantId":"ff6163d4-7214-459e-9f76-507b4eb00f51","modelType":"service","modelName":"ConstraintsSrvcVID","modelVersion":"2.0","modelVersionId":"722d256c-a374-4fba-a14f-a59b76bb7656"},"requestInfo":{"productFamilyId":"LRSI-OSPF","source":"VID","requestorId":"xxxxxx"},"subscriberInfo":{"globalSubscriberId":"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"},"cloudConfiguration":{"tenantId":"a259ae7b7c3f493cb3d91f95a7c18149","lcpCloudRegionId":"mtn16"},"requestParameters":{"subscriptionServiceType":"Mobility","userParams":[{"name":"neutronport6_name","value":"8"},{"name":"neutronnet5_network_name","value":"8"},{"name":"contrailv2vlansubinterface3_name","value":"false"}]}}}', null, 'APIH', '2016-12-22 19:00:28', null, null, null, null, null, null, null, 'mtn16', null, null, null, null, null, 'service', 'createInstance', null, null, null, null, null, null, null), +('0017f68c-eb2d-45bb-b7c7-ec31b37dc349', null, 'activateInstance', 'UNLOCKED', null, '20', '2017-09-26 16:09:29', '2017-09-28 12:45:53', 'VID', null, null, null, null, null, null, null, null, null, '{"requestDetails":{"modelInfo":{"modelCustomizationName":null,"modelInvariantId":"1587cf0e-f12f-478d-8530-5c55ac578c39","modelType":"configuration","modelNameVersionId":null,"modelName":null,"modelVersion":null,"modelCustomizationUuid":null,"modelVersionId":"36a3a8ea-49a6-4ac8-b06c-89a545444455","modelCustomizationId":"68dc9a92-214c-11e7-93ae-92361f002671","modelUuid":null,"modelInvariantUuid":null,"modelInstanceName":null},"requestInfo":{"billingAccountNumber":null,"callbackUrl":null,"correlator":null,"orderNumber":null,"productFamilyId":null,"orderVersion":null,"source":"VID","instanceName":null,"suppressRollback":false,"requestorId":"xxxxxx"},"relatedInstanceList":[{"relatedInstance":{"instanceName":null,"instanceId":"9e15a443-af65-4f05-9000-47ae495e937d","modelInfo":{"modelCustomizationName":null,"modelInvariantId":"de19ae10-9a25-11e7-abc4-cec278b6b50a","modelType":"service","modelNameVersionId":null,"modelName":"MSOTADevInfra_Configuration_Service","modelVersion":"1.0","modelCustomizationUuid":null,"modelVersionId":"ee938612-9a25-11e7-abc4-cec278b6b50a","modelCustomizationId":null,"modelUuid":null,"modelInvariantUuid":null,"modelInstanceName":null},"instanceDirection":null}}],"subscriberInfo":null,"cloudConfiguration":{"aicNodeClli":null,"tenantId":null,"lcpCloudRegionId":"mtn6"},"requestParameters":{"subscriptionServiceType":null,"userParams":[],"aLaCarte":false,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true,"alaCarte":false},"project":null,"owningEntity":null,"platform":null,"lineOfBusiness":null}}', null, 'APIH', '2017-09-26 16:09:29', null, null, null, null, null, null, null, 'mtn6', null, null, null, null, null, 'configuration', 'activateInstance', '9e15a443-af65-4f05-9000-47ae495e937d', null, 'xxxxxx', '26ef7f15-57bb-48df-8170-e59edc26234c', null, null, null); + +insert into watchdog_distributionid_status(distribution_id, distribution_id_status, create_time, modify_time) values +('1533c4bd-a3e3-493f-a16d-28c20614415e', '', '2017-11-30 15:48:09', '2017-11-30 15:48:09'), +('55429711-809b-4a3b-9ee5-5120d46d9de0', '', '2017-11-30 16:35:36', '2017-11-30 16:35:36'), +('67f0b2d1-9013-4b2b-9914-bbe2288284fb', '', '2017-11-30 15:54:39', '2017-11-30 15:54:39'); + +insert into watchdog_per_component_distribution_status(distribution_id, component_name, component_distribution_status, create_time, modify_time) values +('1533c4bd-a3e3-493f-a16d-28c20614415e', 'MSO', 'COMPONENT_DONE_OK', '2017-11-30 15:48:09', '2017-11-30 15:48:09'), +('55429711-809b-4a3b-9ee5-5120d46d9de0', 'MSO', 'COMPONENT_DONE_ERROR', '2017-11-30 16:35:36', '2017-11-30 16:35:36'), +('67f0b2d1-9013-4b2b-9914-bbe2288284fb', 'MSO', 'COMPONENT_DONE_OK', '2017-11-30 15:54:39', '2017-11-30 15:54:39'); + +insert into watchdog_service_mod_ver_id_lookup(distribution_id, service_model_version_id, create_time, modify_time) values +('1533c4bd-a3e3-493f-a16d-28c20614415e', '7e813ab5-88d3-4fcb-86c0-498c5d7eef9a', '2017-11-30 15:48:08', '2017-11-30 15:48:08'), +('55429711-809b-4a3b-9ee5-5120d46d9de0', 'cc031e75-4442-4d1a-b774-8a2b434e0a50', '2017-11-30 16:35:36', '2017-11-30 16:35:36'), +('67f0b2d1-9013-4b2b-9914-bbe2288284fb', 'eade1e9d-c1ec-4ef3-bc31-60570fba1573', '2017-11-30 15:54:39', '2017-11-30 15:54:39'); + + +insert into site_status(site_name, status, creation_timestamp) values +('testsite', 0, '2017-11-30 15:48:09'); + +INSERT INTO requestdb.request_processing_data (ID, SO_REQUEST_ID, GROUPING_ID, NAME, VALUE, TAG) VALUES +(1, 'fbb8df64-9be5-11e8-98d0-529269fb1459', '12b84dc6-9be6-11e8-98d0-529269fb1459', 'test-name', 'test-value', 'test-tag');
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/resources/application-test.yaml b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/application-test.yaml new file mode 100644 index 0000000000..c4dd60356b --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/application-test.yaml @@ -0,0 +1,45 @@ +# will be used as entry in DB to say SITE OFF/ON for healthcheck + +server: + port: 8080 + tomcat: + max-threads: 50 +ssl-enable: false +mso: + adapters: + requestDb: + auth: Basic YnBlbDptc28tZGItMTUwNyE= + endpoint: http://localhost:8081 + site-name: localDevEnv + logPath: logs + +# H2 +spring: + datasource: + url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1; + username: sa + password: sa + driver-class-name: org.h2.Driver + h2: + console: + enabled: true + path: /h2 + + jpa: + show-sql: true + hibernate: + dialect: org.hibernate.dialect.MySQL5Dialect + ddl-auto: none + naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy + enable-lazy-load-no-trans: true + + +#Actuator +management: + security: + enabled: false + basic: + enabled: false + + + diff --git a/mso-api-handlers/mso-requests-db-repositories/src/test/resources/logback-test.xml b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..1951484752 --- /dev/null +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/logback-test.xml @@ -0,0 +1,46 @@ +<configuration > + + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - %msg%n</pattern> + </encoder> + </appender> + + + <logger name="com.att.ecomp.audit" level="info" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="com.att.eelf.metrics" level="info" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="com.att.eelf.error" level="trace" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="org.onap" level="${so.log.level:-DEBUG}" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + <root level="debug"> + <appender-ref ref="STDOUT" /> + </root> + + <!-- Spring related loggers --> + <logger name="org.springframework" level="WARN" /> + <logger name="org.springframework.beans" level="WARN" /> + <logger name="org.springframework.web" level="WARN" /> + <logger name="com.blog.spring.jms" level="WARN" /> + + <logger name="org.hibernate" level="WARN" /> + + + <!-- Tomcat related loggers --> + <logger name="org.apache.tomcat.util.digester.Digester" level="WARN" /> + <logger name="org.apache.tomcat.util.modeler.modules.*" level="WARN" /> + <logger name="org.apache.tomcat.util.IntrospectionUtils" level="WARN" /> + <logger name="org.apache.catalina.loader.WebappClassLoaderBase" level="WARN" /> + <logger name="wiremock.org.eclipse.jetty" level="WARN" /> + +</configuration>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/test/resources/schema.sql b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql index a01153a43c..ab554d440b 100644 --- a/mso-api-handlers/mso-requests-db/src/test/resources/schema.sql +++ b/mso-api-handlers/mso-requests-db-repositories/src/test/resources/schema.sql @@ -207,6 +207,4 @@ ALTER TABLE PUBLIC.SITE_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_C PRIMARY KEY(SI ALTER TABLE PUBLIC.WATCHDOG_DISTRIBUTIONID_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_7 PRIMARY KEY(DISTRIBUTION_ID); ALTER TABLE PUBLIC.WATCHDOG_PER_COMPONENT_DISTRIBUTION_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_D PRIMARY KEY(DISTRIBUTION_ID, COMPONENT_NAME); ALTER TABLE PUBLIC.WATCHDOG_SERVICE_MOD_VER_ID_LOOKUP ADD CONSTRAINT PUBLIC.CONSTRAINT_6 PRIMARY KEY(DISTRIBUTION_ID, SERVICE_MODEL_VERSION_ID); -ALTER TABLE PUBLIC.WATCHDOG_PER_COMPONENT_DISTRIBUTION_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_DE FOREIGN KEY(DISTRIBUTION_ID) REFERENCES PUBLIC.WATCHDOG_DISTRIBUTIONID_STATUS(DISTRIBUTION_ID) NOCHECK; - - +ALTER TABLE PUBLIC.WATCHDOG_PER_COMPONENT_DISTRIBUTION_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_DE FOREIGN KEY(DISTRIBUTION_ID) REFERENCES PUBLIC.WATCHDOG_DISTRIBUTIONID_STATUS(DISTRIBUTION_ID) NOCHECK;
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/hibernate.properties b/mso-api-handlers/mso-requests-db/hibernate.properties deleted file mode 100644 index cf56960f4b..0000000000 --- a/mso-api-handlers/mso-requests-db/hibernate.properties +++ /dev/null @@ -1,2 +0,0 @@ -hibernate.show_sql=true -hibernate.format_sql=true diff --git a/mso-api-handlers/mso-requests-db/hibernate.reveng.xml b/mso-api-handlers/mso-requests-db/hibernate.reveng.xml deleted file mode 100644 index cb1e8c6669..0000000000 --- a/mso-api-handlers/mso-requests-db/hibernate.reveng.xml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" > - -<hibernate-reverse-engineering> - - <schema-selection match-schema="MSO"/> - <type-mapping> - <sql-type jdbc-type="OTHER" hibernate-type="java.sql.Timestamp" /> - </type-mapping> - <table-filter match-schema="MSO" match-name=".*"/> -</hibernate-reverse-engineering>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/pom.xml b/mso-api-handlers/mso-requests-db/pom.xml index 006058e98d..5ef683b444 100644 --- a/mso-api-handlers/mso-requests-db/pom.xml +++ b/mso-api-handlers/mso-requests-db/pom.xml @@ -9,7 +9,6 @@ </parent> <artifactId>mso-requests-db</artifactId> - <name>mso-requests-db</name> <description>MSO Requests Database definition and Hibernate objects</description> <properties> @@ -21,84 +20,20 @@ <groupId>uk.co.blackpepper.bowman</groupId> <artifactId>bowman-client</artifactId> <version>0.3.0</version> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-entitymanager</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.hibernate.javax.persistence</groupId> - <artifactId>hibernate-jpa-2.1-api</artifactId> - <version>1.0.0.Final</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </dependency> + </dependency> <dependency> <groupId>org.onap.so</groupId> <artifactId>common</artifactId> <version>${project.version}</version> - </dependency> - <dependency> - <groupId>javax.annotation</groupId> - <artifactId>javax.annotation-api</artifactId> - <version>1.2</version> - </dependency> + </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mariadb.jdbc</groupId> - <artifactId>mariadb-java-client</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-rest</artifactId> - </dependency> </dependencies> <packaging>jar</packaging> <build> - <finalName>${project.artifactId}</finalName> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>jar</goal> - </goals> - <configuration> - <classifier>beans</classifier> - <includes> - <include>**/beans/**</include> - </includes> - </configuration> - </execution> - </executions> - </plugin> - </plugins> + <finalName>${project.artifactId}</finalName> </build> - </project>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml b/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml deleted file mode 100644 index d62640525b..0000000000 --- a/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ============LICENSE_START======================================================= - ECOMP MSO - ================================================================================ - Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - ================================================================================ - 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. - See the License for the specific language governing permissions and - limitations under the License. - ============LICENSE_END========================================================= - --> - -<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://www.hibernate.org/dtd//hibernate-reverse-engineering-3.0.dtd" > - -<hibernate-reverse-engineering> - <schema-selection match-schema="MSO" /> - <type-mapping> - <sql-type jdbc-type="OTHER" hibernate-type="java.sql.Timestamp" /> - </type-mapping> - <table-filter match-schema="MSO" match-name=".*" /> -</hibernate-reverse-engineering> diff --git a/mso-api-handlers/mso-requests-db/src/main/java/META-INF/MANIFEST.MF b/mso-api-handlers/mso-requests-db/src/main/java/META-INF/MANIFEST.MF deleted file mode 100644 index 5e9495128c..0000000000 --- a/mso-api-handlers/mso-requests-db/src/main/java/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0
-Class-Path:
-
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java index 924f8870d3..348fc524ef 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraActiveRequests.java @@ -36,60 +36,59 @@ import org.apache.commons.lang3.builder.ToStringBuilder; @Table(name = "infra_active_requests") public class InfraActiveRequests extends InfraRequests { - private static final long serialVersionUID = -6818265918910035170L; + private static final long serialVersionUID = -6818265918910035170L; - public InfraActiveRequests() { - } + public InfraActiveRequests() {} - public InfraActiveRequests(String requestId, String action) { - setRequestId(requestId); - setAction(action); - } + public InfraActiveRequests(final String requestId, final String action) { + setRequestId(requestId); + setAction(action); + } - public InfraActiveRequests(String requestId) { - setRequestId(requestId); - } - - @Override - public boolean equals(final Object other) { - if (this == other) { - return true; - } - if (!(other instanceof InfraActiveRequests)) { - return false; - } - InfraActiveRequests castOther = (InfraActiveRequests) other; - return Objects.equals(getRequestId(), castOther.getRequestId()); - } + public InfraActiveRequests(final String requestId) { + setRequestId(requestId); + } - @Override - public int hashCode() { - return Objects.hash(getRequestId()); - } + @Override + public boolean equals(final Object other) { + if (this == other) { + return true; + } + if (!(other instanceof InfraActiveRequests)) { + return false; + } + final InfraActiveRequests castOther = (InfraActiveRequests) other; + return Objects.equals(getRequestId(), castOther.getRequestId()); + } - @Override - public String toString() { - return new ToStringBuilder(this).append("requestId", getRequestId()) - .append("clientRequestId", getClientRequestId()).append("action", getAction()) - .append("requestStatus", getRequestStatus()).append("statusMessage", getStatusMessage()) - .append("progress", getProgress()).append("startTime", getStartTime()).append("endTime", getEndTime()) - .append("source", getSource()).append("vnfId", getVnfId()).append("vnfName", getVnfName()) - .append("vnfType", getVnfType()).append("serviceType", getServiceType()) - .append("aicNodeClli", getAicNodeClli()).append("tenantId", getTenantId()) - .append("provStatus", getProvStatus()).append("vnfParams", getVnfParams()) - .append("vnfOutputs", getVnfOutputs()).append("requestBody", getRequestBody()) - .append("responseBody", getResponseBody()).append("lastModifiedBy", getLastModifiedBy()) - .append("modifyTime", getModifyTime()).append("requestType", getRequestType()) - .append("volumeGroupId", getVolumeGroupId()).append("volumeGroupName", getVolumeGroupName()) - .append("vfModuleId", getVfModuleId()).append("vfModuleName", getVfModuleName()) - .append("vfModuleModelName", getVfModuleModelName()).append("aaiServiceId", getAaiServiceId()) - .append("aicCloudRegion", getAicCloudRegion()).append("callBackUrl", getCallBackUrl()) - .append("correlator", getCorrelator()).append("serviceInstanceId", getServiceInstanceId()) - .append("serviceInstanceName", getServiceInstanceName()).append("requestScope", getRequestScope()) - .append("requestAction", getRequestAction()).append("networkId", getNetworkId()) - .append("networkName", getNetworkName()).append("networkType", getNetworkType()) - .append("requestorId", getRequestorId()).append("configurationId", getConfigurationId()) - .append("configurationName", getConfigurationName()).append("operationalEnvId", getOperationalEnvId()) - .append("operationalEnvName", getOperationalEnvName()).toString(); - } + @Override + public int hashCode() { + return Objects.hash(getRequestId()); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("requestId", getRequestId()) + .append("clientRequestId", getClientRequestId()).append("action", getAction()) + .append("requestStatus", getRequestStatus()).append("statusMessage", getStatusMessage()) + .append("progress", getProgress()).append("startTime", getStartTime()).append("endTime", getEndTime()) + .append("source", getSource()).append("vnfId", getVnfId()).append("vnfName", getVnfName()) + .append("vnfType", getVnfType()).append("serviceType", getServiceType()) + .append("aicNodeClli", getAicNodeClli()).append("tenantId", getTenantId()) + .append("provStatus", getProvStatus()).append("vnfParams", getVnfParams()) + .append("vnfOutputs", getVnfOutputs()).append("requestBody", getRequestBody()) + .append("responseBody", getResponseBody()).append("lastModifiedBy", getLastModifiedBy()) + .append("modifyTime", getModifyTime()).append("requestType", getRequestType()) + .append("volumeGroupId", getVolumeGroupId()).append("volumeGroupName", getVolumeGroupName()) + .append("vfModuleId", getVfModuleId()).append("vfModuleName", getVfModuleName()) + .append("vfModuleModelName", getVfModuleModelName()).append("aaiServiceId", getAaiServiceId()) + .append("aicCloudRegion", getAicCloudRegion()).append("callBackUrl", getCallBackUrl()) + .append("correlator", getCorrelator()).append("serviceInstanceId", getServiceInstanceId()) + .append("serviceInstanceName", getServiceInstanceName()).append("requestScope", getRequestScope()) + .append("requestAction", getRequestAction()).append("networkId", getNetworkId()) + .append("networkName", getNetworkName()).append("networkType", getNetworkType()) + .append("requestorId", getRequestorId()).append("configurationId", getConfigurationId()) + .append("configurationName", getConfigurationName()).append("operationalEnvId", getOperationalEnvId()) + .append("operationalEnvName", getOperationalEnvName()).toString(); + } } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java index 48a6cf3ff0..4a46a0d00d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java @@ -35,522 +35,522 @@ import javax.persistence.TemporalType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.onap.so.requestsdb.adapter.TimestampXMLAdapter; +import org.onap.so.requestsdb.TimestampXMLAdapter; import uk.co.blackpepper.bowman.annotation.ResourceId; @MappedSuperclass public abstract class InfraRequests implements java.io.Serializable { - private static final long serialVersionUID = -5497583682393936143L; - private static final String UNKNOWN = "unknown"; - - - @Id - @Column(name = "REQUEST_ID", length=45) + private static final long serialVersionUID = -5497583682393936143L; + private static final String UNKNOWN = "unknown"; + + + @Id + @Column(name = "REQUEST_ID", length = 45) private String requestId; - @Column(name = "CLIENT_REQUEST_ID", length=45, unique=true) - private String clientRequestId; - @Column(name = "ACTION", length=45) - private String action; - @Column(name = "REQUEST_STATUS", length=20) - private String requestStatus; - @Column(name = "STATUS_MESSAGE", length=2000) - private String statusMessage; - @Column(name = "PROGRESS", precision=11) - private Long progress; - - @Column(name = "START_TIME") - private Timestamp startTime; - @Column(name = "END_TIME") - private Timestamp endTime; - @Column(name = "SOURCE", length=45) - private String source; - @Column(name = "VNF_ID", length=45) - private String vnfId; - @Column(name = "VNF_NAME", length=80) - private String vnfName; - @Column(name = "VNF_TYPE", length=200) - private String vnfType; - @Column(name = "SERVICE_TYPE", length=45) - private String serviceType; - @Column(name = "AIC_NODE_CLLI", length=11) - private String aicNodeClli; - @Column(name = "TENANT_ID", length=45) - private String tenantId; - @Column(name = "PROV_STATUS", length=20) - private String provStatus; - @Column(name = "VNF_PARAMS") - private String vnfParams; - @Column(name = "VNF_OUTPUTS") - private String vnfOutputs; - @Column(name = "REQUEST_BODY") - private String requestBody; - @Column(name = "RESPONSE_BODY") - private String responseBody; - @Column(name = "LAST_MODIFIED_BY", length=50) - private String lastModifiedBy; - @Column(name = "MODIFY_TIME") - @Temporal(TemporalType.TIMESTAMP) - private Date modifyTime; - @Column(name = "REQUEST_TYPE", length=20) - private String requestType; - @Column(name = "VOLUME_GROUP_ID", length=45) - private String volumeGroupId; - @Column(name = "VOLUME_GROUP_NAME", length=45) - private String volumeGroupName; - @Column(name = "VF_MODULE_ID", length=45) - private String vfModuleId; - @Column(name = "VF_MODULE_NAME", length=200) - private String vfModuleName; - @Column(name = "VF_MODULE_MODEL_NAME", length=200) - private String vfModuleModelName; - @Column(name = "AAI_SERVICE_ID", length=50) - private String aaiServiceId; - @Column(name = "AIC_CLOUD_REGION", length=11) - private String aicCloudRegion; - @Column(name = "CALLBACK_URL", length=200) - private String callBackUrl; - @Column(name = "CORRELATOR", length=80) - private String correlator; - @Column(name = "SERVICE_INSTANCE_ID", length=45) - private String serviceInstanceId; - @Column(name = "SERVICE_INSTANCE_NAME", length=80) - private String serviceInstanceName; - @Column(name = "REQUEST_SCOPE", length=45) - private String requestScope; - @Column(name = "REQUEST_ACTION", length=45) - private String requestAction; - @Column(name = "NETWORK_ID", length=45) - private String networkId; - @Column(name = "NETWORK_NAME", length=80) - private String networkName; - @Column(name = "NETWORK_TYPE", length=80) - private String networkType; - @Column(name = "REQUESTOR_ID", length=80) - private String requestorId; - @Column(name = "CONFIGURATION_ID", length=45) - private String configurationId; - @Column(name = "CONFIGURATION_NAME", length=200) - private String configurationName; - @Column(name = "OPERATIONAL_ENV_ID", length=45) - private String operationalEnvId; - @Column(name = "OPERATIONAL_ENV_NAME", length=200) - private String operationalEnvName; - - @ResourceId - public URI getRequestURI() { - return URI.create(this.requestId); - } - - public String getRequestId() { - return this.requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getClientRequestId() { - return clientRequestId; - } - - public void setClientRequestId(String clientRequestId) { - this.clientRequestId = clientRequestId; - } - - public String getAction() { - return this.action; - } - - public void setAction(String action) { - this.action = action; - } - - public String getRequestStatus() { - return this.requestStatus; - } - - public void setRequestStatus(String requestStatus) { - this.requestStatus = requestStatus; - } - - public String getStatusMessage() { - return this.statusMessage; - } - - public void setStatusMessage(String statusMessage) { - this.statusMessage = statusMessage; - } - - public Long getProgress() { - return this.progress; - } - - public void setProgress(Long progress) { - this.progress = progress; - } + @Column(name = "CLIENT_REQUEST_ID", length = 45, unique = true) + private String clientRequestId; + @Column(name = "ACTION", length = 45) + private String action; + @Column(name = "REQUEST_STATUS", length = 20) + private String requestStatus; + @Column(name = "STATUS_MESSAGE", length = 2000) + private String statusMessage; + @Column(name = "PROGRESS", precision = 11) + private Long progress; + + @Column(name = "START_TIME") + private Timestamp startTime; + @Column(name = "END_TIME") + private Timestamp endTime; + @Column(name = "SOURCE", length = 45) + private String source; + @Column(name = "VNF_ID", length = 45) + private String vnfId; + @Column(name = "VNF_NAME", length = 80) + private String vnfName; + @Column(name = "VNF_TYPE", length = 200) + private String vnfType; + @Column(name = "SERVICE_TYPE", length = 45) + private String serviceType; + @Column(name = "AIC_NODE_CLLI", length = 11) + private String aicNodeClli; + @Column(name = "TENANT_ID", length = 45) + private String tenantId; + @Column(name = "PROV_STATUS", length = 20) + private String provStatus; + @Column(name = "VNF_PARAMS") + private String vnfParams; + @Column(name = "VNF_OUTPUTS") + private String vnfOutputs; + @Column(name = "REQUEST_BODY") + private String requestBody; + @Column(name = "RESPONSE_BODY") + private String responseBody; + @Column(name = "LAST_MODIFIED_BY", length = 50) + private String lastModifiedBy; + @Column(name = "MODIFY_TIME") + @Temporal(TemporalType.TIMESTAMP) + private Date modifyTime; + @Column(name = "REQUEST_TYPE", length = 20) + private String requestType; + @Column(name = "VOLUME_GROUP_ID", length = 45) + private String volumeGroupId; + @Column(name = "VOLUME_GROUP_NAME", length = 45) + private String volumeGroupName; + @Column(name = "VF_MODULE_ID", length = 45) + private String vfModuleId; + @Column(name = "VF_MODULE_NAME", length = 200) + private String vfModuleName; + @Column(name = "VF_MODULE_MODEL_NAME", length = 200) + private String vfModuleModelName; + @Column(name = "AAI_SERVICE_ID", length = 50) + private String aaiServiceId; + @Column(name = "AIC_CLOUD_REGION", length = 11) + private String aicCloudRegion; + @Column(name = "CALLBACK_URL", length = 200) + private String callBackUrl; + @Column(name = "CORRELATOR", length = 80) + private String correlator; + @Column(name = "SERVICE_INSTANCE_ID", length = 45) + private String serviceInstanceId; + @Column(name = "SERVICE_INSTANCE_NAME", length = 80) + private String serviceInstanceName; + @Column(name = "REQUEST_SCOPE", length = 45) + private String requestScope; + @Column(name = "REQUEST_ACTION", length = 45) + private String requestAction; + @Column(name = "NETWORK_ID", length = 45) + private String networkId; + @Column(name = "NETWORK_NAME", length = 80) + private String networkName; + @Column(name = "NETWORK_TYPE", length = 80) + private String networkType; + @Column(name = "REQUESTOR_ID", length = 80) + private String requestorId; + @Column(name = "CONFIGURATION_ID", length = 45) + private String configurationId; + @Column(name = "CONFIGURATION_NAME", length = 200) + private String configurationName; + @Column(name = "OPERATIONAL_ENV_ID", length = 45) + private String operationalEnvId; + @Column(name = "OPERATIONAL_ENV_NAME", length = 200) + private String operationalEnvName; + + @ResourceId + public URI getRequestURI() { + return URI.create(this.requestId); + } + + public String getRequestId() { + return this.requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getClientRequestId() { + return clientRequestId; + } + + public void setClientRequestId(String clientRequestId) { + this.clientRequestId = clientRequestId; + } + + public String getAction() { + return this.action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getRequestStatus() { + return this.requestStatus; + } + + public void setRequestStatus(String requestStatus) { + this.requestStatus = requestStatus; + } + + public String getStatusMessage() { + return this.statusMessage; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + + public Long getProgress() { + return this.progress; + } + + public void setProgress(Long progress) { + this.progress = progress; + } @XmlJavaTypeAdapter(TimestampXMLAdapter.class) - public Timestamp getStartTime() { - return this.startTime; - } + public Timestamp getStartTime() { + return this.startTime; + } - public void setStartTime(Timestamp startTime) { - this.startTime = startTime; - } + public void setStartTime(Timestamp startTime) { + this.startTime = startTime; + } @XmlJavaTypeAdapter(TimestampXMLAdapter.class) - public Timestamp getEndTime() { - return this.endTime; - } + public Timestamp getEndTime() { + return this.endTime; + } + + public void setEndTime(Timestamp endTime) { + this.endTime = endTime; + } + + public String getSource() { + return this.source; + } + + public void setSource(String source) { + this.source = source; + } + + public String getVnfId() { + return this.vnfId; + } + + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } + + public String getVnfName() { + return this.vnfName; + } + + public void setVnfName(String vnfName) { + this.vnfName = vnfName; + } + + public String getVnfType() { + return this.vnfType; + } + + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + public String getServiceType() { + return this.serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public String getAicNodeClli() { + return this.aicNodeClli; + } + + public void setAicNodeClli(String aicNodeClli) { + this.aicNodeClli = aicNodeClli; + } + + public String getTenantId() { + return this.tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getProvStatus() { + return this.provStatus; + } + + public void setProvStatus(String provStatus) { + this.provStatus = provStatus; + } + + public String getVnfParams() { + return this.vnfParams; + } + + public void setVnfParams(String vnfParams) { + this.vnfParams = vnfParams; + } + + public String getVnfOutputs() { + return this.vnfOutputs; + } + + public void setVnfOutputs(String vnfOutputs) { + this.vnfOutputs = vnfOutputs; + } + + public String getRequestBody() { + return this.requestBody; + } + + public void setRequestBody(String requestBody) { + this.requestBody = requestBody; + } + + public String getResponseBody() { + return this.responseBody; + } + + public void setResponseBody(String responseBody) { + this.responseBody = responseBody; + } - public void setEndTime(Timestamp endTime) { - this.endTime = endTime; - } + public String getLastModifiedBy() { + return this.lastModifiedBy; + } - public String getSource() { - return this.source; - } + public void setLastModifiedBy(String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } - public void setSource(String source) { - this.source = source; - } - - public String getVnfId() { - return this.vnfId; - } - - public void setVnfId(String vnfId) { - this.vnfId = vnfId; - } - - public String getVnfName() { - return this.vnfName; - } - - public void setVnfName(String vnfName) { - this.vnfName = vnfName; - } - - public String getVnfType() { - return this.vnfType; - } - - public void setVnfType(String vnfType) { - this.vnfType = vnfType; - } - - public String getServiceType() { - return this.serviceType; - } - - public void setServiceType(String serviceType) { - this.serviceType = serviceType; - } - - public String getAicNodeClli() { - return this.aicNodeClli; - } - - public void setAicNodeClli(String aicNodeClli) { - this.aicNodeClli = aicNodeClli; - } - - public String getTenantId() { - return this.tenantId; - } - - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - public String getProvStatus() { - return this.provStatus; - } - - public void setProvStatus(String provStatus) { - this.provStatus = provStatus; - } - - public String getVnfParams() { - return this.vnfParams; - } - - public void setVnfParams(String vnfParams) { - this.vnfParams = vnfParams; - } - - public String getVnfOutputs() { - return this.vnfOutputs; - } - - public void setVnfOutputs(String vnfOutputs) { - this.vnfOutputs = vnfOutputs; - } - - public String getRequestBody() { - return this.requestBody; - } - - public void setRequestBody(String requestBody) { - this.requestBody = requestBody; - } - - public String getResponseBody() { - return this.responseBody; - } - - public void setResponseBody(String responseBody) { - this.responseBody = responseBody; - } + public Date getModifyTime() { + return this.modifyTime; + } - public String getLastModifiedBy() { - return this.lastModifiedBy; - } + public String getRequestType() { + return this.requestType; + } - public void setLastModifiedBy(String lastModifiedBy) { - this.lastModifiedBy = lastModifiedBy; - } + public void setRequestType(String requestType) { + this.requestType = requestType; + } - public Date getModifyTime() { - return this.modifyTime; - } - - public String getRequestType() { - return this.requestType; - } + public String getVolumeGroupId() { + return this.volumeGroupId; + } - public void setRequestType(String requestType) { - this.requestType = requestType; - } + public void setVolumeGroupId(String volumeGroupId) { + this.volumeGroupId = volumeGroupId; + } - public String getVolumeGroupId() { - return this.volumeGroupId; - } + public String getVolumeGroupName() { + return this.volumeGroupName; + } - public void setVolumeGroupId(String volumeGroupId) { - this.volumeGroupId = volumeGroupId; - } + public void setVolumeGroupName(String volumeGroupName) { + this.volumeGroupName = volumeGroupName; + } - public String getVolumeGroupName() { - return this.volumeGroupName; - } + public String getVfModuleId() { + return this.vfModuleId; + } - public void setVolumeGroupName(String volumeGroupName) { - this.volumeGroupName = volumeGroupName; - } + public void setVfModuleId(String vfModuleId) { + this.vfModuleId = vfModuleId; + } - public String getVfModuleId() { - return this.vfModuleId; - } + public String getVfModuleName() { + return this.vfModuleName; + } - public void setVfModuleId(String vfModuleId) { - this.vfModuleId = vfModuleId; - } + public void setVfModuleName(String vfModuleName) { + this.vfModuleName = vfModuleName; + } - public String getVfModuleName() { - return this.vfModuleName; - } + public String getVfModuleModelName() { + return this.vfModuleModelName; + } - public void setVfModuleName(String vfModuleName) { - this.vfModuleName = vfModuleName; - } + public void setVfModuleModelName(String vfModuleModelName) { + this.vfModuleModelName = vfModuleModelName; + } - public String getVfModuleModelName() { - return this.vfModuleModelName; - } + public String getAaiServiceId() { + return this.aaiServiceId; + } - public void setVfModuleModelName(String vfModuleModelName) { - this.vfModuleModelName = vfModuleModelName; - } + public void setAaiServiceId(String aaiServiceId) { + this.aaiServiceId = aaiServiceId; + } - public String getAaiServiceId() { - return this.aaiServiceId; - } + public String getAicCloudRegion() { + return this.aicCloudRegion; + } - public void setAaiServiceId(String aaiServiceId) { - this.aaiServiceId = aaiServiceId; - } + public void setAicCloudRegion(String aicCloudRegion) { + this.aicCloudRegion = aicCloudRegion; + } - public String getAicCloudRegion() { - return this.aicCloudRegion; - } + public String getCallBackUrl() { + return callBackUrl; + } - public void setAicCloudRegion(String aicCloudRegion) { - this.aicCloudRegion = aicCloudRegion; - } + public void setCallBackUrl(String callBackUrl) { + this.callBackUrl = callBackUrl; + } - public String getCallBackUrl() { - return callBackUrl; - } + public String getCorrelator() { + return correlator; + } - public void setCallBackUrl(String callBackUrl) { - this.callBackUrl = callBackUrl; - } + public void setCorrelator(String correlator) { + this.correlator = correlator; + } - public String getCorrelator() { - return correlator; - } - - public void setCorrelator(String correlator) { - this.correlator = correlator; - } - - public String getServiceInstanceId() { - return serviceInstanceId; - } - - public void setServiceInstanceId(String serviceInstanceId) { - this.serviceInstanceId = serviceInstanceId; - } - - public String getServiceInstanceName() { - return serviceInstanceName; - } - - public void setServiceInstanceName(String serviceInstanceName) { - this.serviceInstanceName = serviceInstanceName; - } - - public String getRequestScope() { - return requestScope; - } - - public void setRequestScope(String requestScope) { - this.requestScope = requestScope; - } - - public String getRequestAction() { - return requestAction; - } - - public void setRequestAction(String requestAction) { - this.requestAction = requestAction; - } - - public String getNetworkId() { - return networkId; - } - - public void setNetworkId(String networkId) { - this.networkId = networkId; - } - - public String getNetworkName() { - return networkName; - } - - public void setNetworkName(String networkName) { - this.networkName = networkName; - } - - public String getNetworkType() { - return networkType; - } - - public void setNetworkType(String networkType) { - this.networkType = networkType; - } - - public String getRequestorId() { - return requestorId; - } - - public void setRequestorId(String requestorId) { - this.requestorId = requestorId; - } - - public String getConfigurationId() { - return configurationId; - } - - public void setConfigurationId(String configurationId) { - this.configurationId = configurationId; - } - - public String getConfigurationName() { - return configurationName; - } - - public void setConfigurationName(String configurationName) { - this.configurationName = configurationName; - } - - public String getOperationalEnvId() { - return operationalEnvId; - } - - public void setOperationalEnvId(String operationalEnvId) { - this.operationalEnvId = operationalEnvId; - } - - public String getOperationalEnvName() { - return operationalEnvName; - } - - public void setOperationalEnvName(String operationalEnvName) { - this.operationalEnvName = operationalEnvName; - } - - @PrePersist - protected void onCreate() { - if(requestScope==null) - requestScope=UNKNOWN; - if(requestAction==null) - requestAction=UNKNOWN; - this.modifyTime = new Date(); - } - - @PreUpdate - protected void onUpdate() { - if(requestScope==null) - requestScope=UNKNOWN; - if(requestAction==null) - requestAction=UNKNOWN; - this.modifyTime = new Date(); - } - - @Override - public boolean equals(final Object other) { - if (this == other) { - return true; - } - if (!(other instanceof InfraRequests)) { - return false; - } - InfraRequests castOther = (InfraRequests) other; - return Objects.equals(getRequestId(), castOther.getRequestId()); - } - - @Override - public int hashCode() { - return Objects.hash(getRequestId()); - } - - @Override - public String toString() { - return new ToStringBuilder(this).append("requestId", getRequestId()) - .append("clientRequestId", getClientRequestId()).append("action", getAction()) - .append("requestStatus", getRequestStatus()).append("statusMessage", getStatusMessage()) - .append("progress", getProgress()).append("startTime", getStartTime()).append("endTime", getEndTime()) - .append("source", getSource()).append("vnfId", getVnfId()).append("vnfName", getVnfName()) - .append("vnfType", getVnfType()).append("serviceType", getServiceType()) - .append("aicNodeClli", getAicNodeClli()).append("tenantId", getTenantId()) - .append("provStatus", getProvStatus()).append("vnfParams", getVnfParams()) - .append("vnfOutputs", getVnfOutputs()).append("requestBody", getRequestBody()) - .append("responseBody", getResponseBody()).append("lastModifiedBy", getLastModifiedBy()) - .append("modifyTime", getModifyTime()).append("requestType", getRequestType()) - .append("volumeGroupId", getVolumeGroupId()).append("volumeGroupName", getVolumeGroupName()) - .append("vfModuleId", getVfModuleId()).append("vfModuleName", getVfModuleName()) - .append("vfModuleModelName", getVfModuleModelName()).append("aaiServiceId", getAaiServiceId()) - .append("aicCloudRegion", getAicCloudRegion()).append("callBackUrl", getCallBackUrl()) - .append("correlator", getCorrelator()).append("serviceInstanceId", getServiceInstanceId()) - .append("serviceInstanceName", getServiceInstanceName()).append("requestScope", getRequestScope()) - .append("requestAction", getRequestAction()).append("networkId", getNetworkId()) - .append("networkName", getNetworkName()).append("networkType", getNetworkType()) - .append("requestorId", getRequestorId()).append("configurationId", getConfigurationId()) - .append("configurationName", getConfigurationName()).append("operationalEnvId", getOperationalEnvId()) - .append("operationalEnvName", getOperationalEnvName()).toString(); - } + public String getServiceInstanceId() { + return serviceInstanceId; + } + + public void setServiceInstanceId(String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + public String getServiceInstanceName() { + return serviceInstanceName; + } + + public void setServiceInstanceName(String serviceInstanceName) { + this.serviceInstanceName = serviceInstanceName; + } + + public String getRequestScope() { + return requestScope; + } + + public void setRequestScope(String requestScope) { + this.requestScope = requestScope; + } + + public String getRequestAction() { + return requestAction; + } + + public void setRequestAction(String requestAction) { + this.requestAction = requestAction; + } + + public String getNetworkId() { + return networkId; + } + + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + + public String getNetworkName() { + return networkName; + } + + public void setNetworkName(String networkName) { + this.networkName = networkName; + } + + public String getNetworkType() { + return networkType; + } + + public void setNetworkType(String networkType) { + this.networkType = networkType; + } + + public String getRequestorId() { + return requestorId; + } + + public void setRequestorId(String requestorId) { + this.requestorId = requestorId; + } + + public String getConfigurationId() { + return configurationId; + } + + public void setConfigurationId(String configurationId) { + this.configurationId = configurationId; + } + + public String getConfigurationName() { + return configurationName; + } + + public void setConfigurationName(String configurationName) { + this.configurationName = configurationName; + } + + public String getOperationalEnvId() { + return operationalEnvId; + } + + public void setOperationalEnvId(String operationalEnvId) { + this.operationalEnvId = operationalEnvId; + } + + public String getOperationalEnvName() { + return operationalEnvName; + } + + public void setOperationalEnvName(String operationalEnvName) { + this.operationalEnvName = operationalEnvName; + } + + @PrePersist + protected void onCreate() { + if (requestScope == null) + requestScope = UNKNOWN; + if (requestAction == null) + requestAction = UNKNOWN; + this.modifyTime = new Date(); + } + + @PreUpdate + protected void onUpdate() { + if (requestScope == null) + requestScope = UNKNOWN; + if (requestAction == null) + requestAction = UNKNOWN; + this.modifyTime = new Date(); + } + + @Override + public boolean equals(final Object other) { + if (this == other) { + return true; + } + if (!(other instanceof InfraRequests)) { + return false; + } + InfraRequests castOther = (InfraRequests) other; + return Objects.equals(getRequestId(), castOther.getRequestId()); + } + + @Override + public int hashCode() { + return Objects.hash(getRequestId()); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("requestId", getRequestId()) + .append("clientRequestId", getClientRequestId()).append("action", getAction()) + .append("requestStatus", getRequestStatus()).append("statusMessage", getStatusMessage()) + .append("progress", getProgress()).append("startTime", getStartTime()).append("endTime", getEndTime()) + .append("source", getSource()).append("vnfId", getVnfId()).append("vnfName", getVnfName()) + .append("vnfType", getVnfType()).append("serviceType", getServiceType()) + .append("aicNodeClli", getAicNodeClli()).append("tenantId", getTenantId()) + .append("provStatus", getProvStatus()).append("vnfParams", getVnfParams()) + .append("vnfOutputs", getVnfOutputs()).append("requestBody", getRequestBody()) + .append("responseBody", getResponseBody()).append("lastModifiedBy", getLastModifiedBy()) + .append("modifyTime", getModifyTime()).append("requestType", getRequestType()) + .append("volumeGroupId", getVolumeGroupId()).append("volumeGroupName", getVolumeGroupName()) + .append("vfModuleId", getVfModuleId()).append("vfModuleName", getVfModuleName()) + .append("vfModuleModelName", getVfModuleModelName()).append("aaiServiceId", getAaiServiceId()) + .append("aicCloudRegion", getAicCloudRegion()).append("callBackUrl", getCallBackUrl()) + .append("correlator", getCorrelator()).append("serviceInstanceId", getServiceInstanceId()) + .append("serviceInstanceName", getServiceInstanceName()).append("requestScope", getRequestScope()) + .append("requestAction", getRequestAction()).append("networkId", getNetworkId()) + .append("networkName", getNetworkName()).append("networkType", getNetworkType()) + .append("requestorId", getRequestorId()).append("configurationId", getConfigurationId()) + .append("configurationName", getConfigurationName()).append("operationalEnvId", getOperationalEnvId()) + .append("operationalEnvName", getOperationalEnvName()).toString(); + } } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java new file mode 100644 index 0000000000..34832b9917 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.request.beans; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.PrePersist; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import com.openpojo.business.annotation.BusinessKey; + +/** + * persist the request identifiers created when MSO POSTs a request to PINC + * <br> + * <p> + * </p> + * + * @author + * @version + */ + +@Entity +@Table(name = "request_processing_data") +public class RequestProcessingData implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -3497593687393936143L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID") + private Integer id; + + @BusinessKey + @Column(name = "SO_REQUEST_ID", length=50, unique=true) + private String soRequestId; + + @BusinessKey + @Column(name = "GROUPING_ID", length=100, unique=true) + private String groupingId; + + @BusinessKey + @Column(name = "NAME", length=200) + private String name; + + @Column(name = "VALUE", columnDefinition = "LONGTEXT") + private String value; + + @BusinessKey + @Column(name = "TAG", length=200) + private String tag; + + @Column(name = "CREATE_TIME", insertable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) + private Date created = null; + + @Override + public boolean equals(final Object other) { + if (!(other instanceof RequestProcessingData)) { + return false; + } + RequestProcessingData castOther = (RequestProcessingData) other; + return new EqualsBuilder().append(soRequestId, castOther.soRequestId).append(groupingId, castOther.groupingId) + .append(name, castOther.name).append(tag, castOther.tag).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(soRequestId).append(groupingId).append(name).append(tag).toHashCode(); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("id", id).append("soRequestId", soRequestId) + .append("groupingId", groupingId).append("name", name).append("value", value).append("tag", tag) + .toString(); + } + + @PrePersist + protected void createdAt() { + this.created = new Date(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getSoRequestId() { + return soRequestId; + } + + public void setSoRequestId(String soRequestId) { + this.soRequestId = soRequestId; + } + + public String getGroupingId() { + return groupingId; + } + + public void setGroupingId(String groupingId) { + this.groupingId = groupingId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public Date getCreated() { + return created; + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 8e291aa15b..54fec3ad4d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -18,60 +18,77 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.requestsdb.client; +package org.onap.so.db.request.client; + +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.ws.rs.core.UriBuilder; import org.apache.http.HttpStatus; +import org.onap.so.db.request.beans.ArchivedInfraRequests; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; import org.onap.so.db.request.beans.OperationStatus; +import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; -import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; -import org.onap.so.db.request.beans.ArchivedInfraRequests; +import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.db.request.beans.ResourceOperationStatus; +import org.onap.so.db.request.beans.SiteStatus; import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; import org.onap.so.db.request.beans.WatchdogDistributionStatus; -import org.onap.so.db.request.beans.SiteStatus; +import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; + import uk.co.blackpepper.bowman.Client; import uk.co.blackpepper.bowman.ClientFactory; import uk.co.blackpepper.bowman.Configuration; +import uk.co.blackpepper.bowman.RestTemplateConfigurer; -import javax.annotation.PostConstruct; -import javax.ws.rs.core.UriBuilder; -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -@Component +@Component("RequestsDbClient") +@Primary public class RequestsDbClient { private static final String SERVICE_ID = "SERVICE_ID"; private static final String OPERATION_ID = "OPERATION_ID"; + private static final String SO_REQUEST_ID = "SO_REQUEST_ID"; + private static final String GROUPING_ID = "GROUPING_ID"; + private static final String REQUEST_ID = "REQUEST_ID"; private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENVIRONMENT_ID"; private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID"; - private static final String REQUEST_ID = "REQUEST_ID"; - - private final Client<InfraActiveRequests> infraActiveRequestClient; - private final Client<OperationStatus> operationStatusClient; + private static final String NAME = "NAME"; + private static final String VALUE = "VALUE"; + private static final String TAG = "TAG"; + + private Client<InfraActiveRequests> infraActiveRequestClient; + private Client<OperationStatus> operationStatusClient; + private Client<RequestProcessingData> requestProcessingDataClient; private final Client<OperationalEnvDistributionStatus> distributionStatusClient; private final Client<OperationalEnvServiceModelStatus> serviceModelStatusClient; @Value("${mso.adapters.requestDb.endpoint}") - private String endpoint; + protected String endpoint; @Value("${mso.adapters.requestDb.auth}") private String msoAdaptersAuth; @@ -80,29 +97,38 @@ public class RequestsDbClient { private static final String OPERATION_STATUS_SEARCH = "/operationStatus/search"; private static final String OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH = "/operationalEnvServiceModelStatus/search"; + private String checkVnfIdStatus = "/infraActiveRequests/checkVnfIdStatus/"; private String infraActiveRequestURI = "/infraActiveRequests/"; private String checkInstanceNameDuplicate = "/infraActiveRequests/checkInstanceNameDuplicate"; + private String operationalEnvDistributionStatusURI = "/operationalEnvDistributionStatus/"; + private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId"; - private String operationalEnvDistributionStatusURI = "/operationalEnvDistributionStatus/"; - - private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive"; - private String findOneByOperationalEnvIdAndServiceModelVersionIdURI = "/findOneByOperationalEnvIdAndServiceModelVersionId"; private String findAllByOperationalEnvIdAndRequestIdURI = "/findAllByOperationalEnvIdAndRequestId"; - private HttpHeaders headers; + private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive"; + + private String requestProcessingDataURI = "/requestProcessingData"; + + private String findOneBySoRequestIdAndGroupingIdAndNameAndTagURI = "/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndNameAndTag/"; + + private String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"; + protected HttpHeaders headers; + + protected ClientFactory clientFactory; + @Autowired - private RestTemplate restTemplate; + protected RestTemplate restTemplate; + @Autowired ClassURLMapper classURLMapper; - @PostConstruct public void init() { @@ -112,6 +138,7 @@ public class RequestsDbClient { checkInstanceNameDuplicate = endpoint + checkInstanceNameDuplicate; cloudOrchestrationFiltersFromInfraActive = endpoint + cloudOrchestrationFiltersFromInfraActive; findOneByServiceIdAndOperationIdURI = endpoint + OPERATION_STATUS_SEARCH + findOneByServiceIdAndOperationIdURI; + requestProcessingDataURI = endpoint + requestProcessingDataURI; operationalEnvDistributionStatusURI = endpoint + operationalEnvDistributionStatusURI; findOneByOperationalEnvIdAndServiceModelVersionIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findOneByOperationalEnvIdAndServiceModelVersionIdURI; findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI; @@ -120,15 +147,28 @@ public class RequestsDbClient { } public RequestsDbClient() { - ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(restTemplate -> restTemplate.getInterceptors().add((request, body, execution) -> { - request.getHeaders().add("Authorization", msoAdaptersAuth); - return execution.execute(request, body); - })).build().buildClientFactory(); + ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(new RestTemplateConfigurer() { + + public void configure(RestTemplate restTemplate) { + + restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() { + + public ClientHttpResponse intercept(HttpRequest request, byte[] body, + ClientHttpRequestExecution execution) throws IOException { + + request.getHeaders().add("Authorization", msoAdaptersAuth); + return execution.execute(request, body); + } + }); + } + }).build().buildClientFactory(); infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class); operationStatusClient = clientFactory.create(OperationStatus.class); + requestProcessingDataClient = clientFactory.create(RequestProcessingData.class); distributionStatusClient = clientFactory.create(OperationalEnvDistributionStatus.class); serviceModelStatusClient = clientFactory.create(OperationalEnvServiceModelStatus.class); } + public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){ URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); HttpEntity<Map> entity = new HttpEntity<>(orchestrationMap, headers); @@ -175,7 +215,7 @@ public class RequestsDbClient { .queryParam(OPERATION_ID,operationId) .build()); } - + public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(String operationalEnvironmentId, String serviceModelVersionId) { return this.getSingleOperationalEnvServiceModelStatus(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdURI) .queryParam(OPERATIONAL_ENVIRONMENT_ID,operationalEnvironmentId) @@ -211,7 +251,7 @@ public class RequestsDbClient { HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(infraActiveRequests, headers); restTemplate.postForLocation(uri, entity); } - + public <T> void save(T object){ URI uri = getUri(endpoint+classURLMapper.getURI(object.getClass())); HttpEntity<T> entity = new HttpEntity<>(object, headers); @@ -221,8 +261,8 @@ public class RequestsDbClient { private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){ return distributionStatusClient.get(uri); } - - private InfraActiveRequests getSingleInfraActiveRequests(URI uri) { + + protected InfraActiveRequests getSingleInfraActiveRequests(URI uri) { return infraActiveRequestClient.get(uri); } @@ -230,12 +270,56 @@ public class RequestsDbClient { infraActiveRequestClient.put(request); } - private OperationStatus getSingleOperationStatus(URI uri){ + protected URI getUri(String uri) { + return URI.create(uri); + } + + + + public OperationStatus getSingleOperationStatus(URI uri){ return operationStatusClient.get(uri); } - private URI getUri(String uri) { - return URI.create(uri); + public void saveRequestProcessingData(RequestProcessingData requestProcessingData) { + URI uri = getUri(endpoint + requestProcessingDataURI); + HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers); + restTemplate.postForLocation(uri, entity); + } + + public RequestProcessingData getRequestProcessingDataBySoRequestIdAndGroupingIdAndNameAndTag(String soRequestId, + String groupingId, String name, String tag) { + return this.getSingleRequestProcessingData(UriBuilder.fromUri(endpoint + findOneBySoRequestIdAndGroupingIdAndNameAndTagURI) + .queryParam(SO_REQUEST_ID,soRequestId) + .queryParam(GROUPING_ID,groupingId) + .queryParam(NAME,name) + .queryParam(TAG,tag) + .build()); + } + public List<RequestProcessingData> getRequestProcessingDataBySoRequestId(String soRequestId) { + return this.getRequestProcessingData(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc) + .queryParam(SO_REQUEST_ID,soRequestId) + .build()); + } + + public RequestProcessingData getSingleRequestProcessingData(URI uri){ + return requestProcessingDataClient.get(uri); + } + + private List<RequestProcessingData> getRequestProcessingData(URI uri) { + Iterable<RequestProcessingData> requestProcessingDataIterator = requestProcessingDataClient.getAll(uri); + List<RequestProcessingData> requestProcessingDataList = new ArrayList<>(); + Iterator<RequestProcessingData> it = requestProcessingDataIterator.iterator(); + it.forEachRemaining(requestProcessingDataList::add); + return requestProcessingDataList; + } + + public List<RequestProcessingData> getAllRequestProcessingData() { + + return (List<RequestProcessingData>) this.getAllRequestProcessingData(UriBuilder.fromUri(endpoint + "/requestProcessingData").build()); + } + + private Iterable<RequestProcessingData> getAllRequestProcessingData(URI uri) { + return requestProcessingDataClient.getAll(uri); } @Bean @@ -269,4 +353,14 @@ public class RequestsDbClient { return classURLMap.get(actualClass); } } + + //USED FOR TEST ONLY + public void setPortToEndpoint(String port) { + endpoint = endpoint + port; + } + + //USED FOR TEST ONLY + public void removePortFromEndpoint() { + endpoint = endpoint.substring(0, endpoint.lastIndexOf(':') + 1); + } } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java deleted file mode 100644 index ba237bfa35..0000000000 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryCustom.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.db.request.data.repository; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.onap.so.db.request.beans.InfraActiveRequests; -import org.springframework.stereotype.Repository; - -@Repository -public interface InfraActiveRequestsRepositoryCustom { - - public boolean healthCheck(); - - public InfraActiveRequests getRequestFromInfraActive(String requestId); - - public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, - String requestScope); - - public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap); - - // Added this method for Tenant Isolation project ( 1802-295491a) to query the mso_requests DB - // (infra_active_requests table) for operationalEnvId and OperationalEnvName - public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap); - - public List<InfraActiveRequests> getRequestListFromInfraActive(String queryAttributeName, String queryValue, - String requestType); - - public InfraActiveRequests getRequestFromInfraActive(String requestId, String requestType); - - public InfraActiveRequests checkDuplicateByVnfName(String vnfName, String action, String requestType); - - public InfraActiveRequests checkDuplicateByVnfId(String vnfId, String action, String requestType); - - public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId); - -} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java deleted file mode 100644 index 3240972a58..0000000000 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/InfraActiveRequestsRepositoryImpl.java +++ /dev/null @@ -1,566 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.db.request.data.repository; - -import java.sql.Timestamp; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import javax.persistence.EntityManager; -import javax.persistence.NonUniqueResultException; -import javax.persistence.Query; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Order; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - -import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.beans.OperationStatus; -import org.onap.so.db.request.beans.ResourceOperationStatus; -import org.onap.so.logger.MsoLogger; -import org.onap.so.requestsdb.RequestsDbConstant; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.domain.Example; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - - -@Repository -@Transactional(readOnly = true) -public class InfraActiveRequestsRepositoryImpl implements InfraActiveRequestsRepositoryCustom { - - @Qualifier("requestEntityManagerFactory") - @Autowired - private EntityManager entityManager; - - protected static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL, InfraActiveRequestsRepositoryImpl.class); - - protected static final String SOURCE = "source"; - protected static final String START_TIME = "startTime"; - protected static final String REQUEST_TYPE = "requestType"; - protected static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; - protected static final String SERVICE_INSTANCE_NAME = "serviceInstanceName"; - protected static final String VNF_INSTANCE_NAME = "vnfName"; - protected static final String VNF_INSTANCE_ID = "vnfId"; - protected static final String VOLUME_GROUP_INSTANCE_NAME = "volumeGroupName"; - protected static final String VOLUME_GROUP_INSTANCE_ID = "volumeGroupId"; - protected static final String VFMODULE_INSTANCE_NAME = "vfModuleName"; - protected static final String VFMODULE_INSTANCE_ID = "vfModuleId"; - protected static final String NETWORK_INSTANCE_NAME = "networkName"; - protected static final String CONFIGURATION_INSTANCE_ID = "configurationId"; - protected static final String CONFIGURATION_INSTANCE_NAME= "configurationName"; - protected static final String OPERATIONAL_ENV_ID = "operationalEnvId"; - protected static final String OPERATIONAL_ENV_NAME = "operationalEnvName"; - protected static final String NETWORK_INSTANCE_ID = "networkId"; - protected static final String GLOBAL_SUBSCRIBER_ID = "globalSubscriberId"; - protected static final String SERVICE_NAME_VERSION_ID = "serviceNameVersionId"; - protected static final String SERVICE_ID = "serviceId"; - protected static final String SERVICE_VERSION = "serviceVersion"; - protected static final String REQUEST_ID = "requestId"; - protected static final String REQUESTOR_ID = "requestorId"; - - @Autowired - private OperationStatusRepository operationStatusRepository; - - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#healthCheck() - */ - @Override - public boolean healthCheck () { - - Query query = entityManager.createNativeQuery(" show tables "); - - List<?> list = query.getResultList(); - - return true; - } - - private List<InfraActiveRequests> executeInfraQuery (CriteriaQuery<InfraActiveRequests> crit, List <Predicate> predicates, Order order) { - - long startTime = System.currentTimeMillis (); - msoLogger.debug ("Execute query on infra active request table"); - - List <InfraActiveRequests> results = new ArrayList<InfraActiveRequests>(); - - try { - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - crit.where(cb.and(predicates.toArray(new Predicate[0]))); - crit.orderBy(order); - results = entityManager.createQuery(crit).getResultList(); - - } finally { - msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "getInfraActiveRequest", null); - } - return results; - } - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getRequestFromInfraActive(java.lang.String) - */ - @Override - public InfraActiveRequests getRequestFromInfraActive (String requestId) { - long startTime = System.currentTimeMillis (); - msoLogger.debug ("Get request " + requestId + " from InfraActiveRequests DB"); - - InfraActiveRequests ar = null; - try { - Query query = entityManager.createQuery ("from InfraActiveRequests where requestId = :requestId OR clientRequestId = :requestId"); - query.setParameter (REQUEST_ID, requestId); - ar = this.getSingleResult(query); - } finally { - - msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "InfraRequestDB", "getRequestFromInfraActive", null); - } - return ar; - } - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkInstanceNameDuplicate(java.util.HashMap, java.lang.String, java.lang.String) - */ - @Override - public InfraActiveRequests checkInstanceNameDuplicate (HashMap<String,String> instanceIdMap, String instanceName, String requestScope) { - - List <Predicate> predicates = new LinkedList <> (); - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); - Root<InfraActiveRequests> tableRoot = crit.from(InfraActiveRequests.class); - - if(instanceName != null && !instanceName.equals("")) { - - if("service".equals(requestScope)){ - predicates.add (cb.equal(tableRoot.get(SERVICE_INSTANCE_NAME), instanceName)); - } else if("vnf".equals(requestScope)){ - predicates.add (cb.equal(tableRoot.get(VNF_INSTANCE_NAME), instanceName)); - } else if("volumeGroup".equals(requestScope)){ - predicates.add (cb.equal(tableRoot.get(VOLUME_GROUP_INSTANCE_NAME), instanceName)); - } else if("vfModule".equals(requestScope)){ - predicates.add (cb.equal(tableRoot.get(VFMODULE_INSTANCE_NAME), instanceName)); - } else if("network".equals(requestScope)){ - predicates.add (cb.equal(tableRoot.get(NETWORK_INSTANCE_NAME), instanceName)); - } else if(requestScope.equals("configuration")) { - predicates.add (cb.equal(tableRoot.get(CONFIGURATION_INSTANCE_NAME), instanceName)); - } else if(requestScope.equals("operationalEnvironment")) { - predicates.add (cb.equal(tableRoot.get(OPERATIONAL_ENV_NAME), instanceName)); - } - - } else { - if(instanceIdMap != null){ - if("service".equals(requestScope) && instanceIdMap.get("serviceInstanceId") != null){ - predicates.add (cb.equal(tableRoot.get(SERVICE_INSTANCE_ID), instanceIdMap.get("serviceInstanceId"))); - } - - if("vnf".equals(requestScope) && instanceIdMap.get("vnfInstanceId") != null){ - predicates.add (cb.equal(tableRoot.get(VNF_INSTANCE_ID), instanceIdMap.get("vnfInstanceId" ))); - } - - if("vfModule".equals(requestScope) && instanceIdMap.get("vfModuleInstanceId") != null){ - predicates.add (cb.equal(tableRoot.get(VFMODULE_INSTANCE_ID), instanceIdMap.get("vfModuleInstanceId"))); - } - - if("volumeGroup".equals(requestScope) && instanceIdMap.get("volumeGroupInstanceId") != null){ - predicates.add (cb.equal(tableRoot.get(VOLUME_GROUP_INSTANCE_ID), instanceIdMap.get("volumeGroupInstanceId"))); - } - - if("network".equals(requestScope) && instanceIdMap.get("networkInstanceId") != null){ - predicates.add (cb.equal(tableRoot.get(NETWORK_INSTANCE_ID), instanceIdMap.get("networkInstanceId"))); - } - - if(requestScope.equals("configuration") && instanceIdMap.get("configurationInstanceId") != null){ - predicates.add (cb.equal(tableRoot.get(CONFIGURATION_INSTANCE_ID), instanceIdMap.get("configurationInstanceId"))); - } - - if(requestScope.equals("operationalEnvironment") && instanceIdMap.get("operationalEnvironmentId") != null) { - predicates.add (cb.equal(tableRoot.get(OPERATIONAL_ENV_ID), instanceIdMap.get("operationalEnvironmentId"))); - } - } - } - - predicates.add (tableRoot.get("requestStatus").in(Arrays.asList("PENDING", "IN_PROGRESS", "TIMEOUT", "PENDING_MANUAL_TASK"))); - - Order order = cb.desc(tableRoot.get(START_TIME)); - - List<InfraActiveRequests> dupList = executeInfraQuery(crit, predicates, order); - - InfraActiveRequests infraActiveRequests = null; - - if(dupList != null && !dupList.isEmpty()){ - infraActiveRequests = dupList.get(0); - } - - return infraActiveRequests; - } - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getOrchestrationFiltersFromInfraActive(java.util.Map) - */ - @Override - public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive (Map<String, List<String>> orchestrationMap) { - - - List <Predicate> predicates = new LinkedList <> (); - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); - Root<InfraActiveRequests> tableRoot = crit.from(InfraActiveRequests.class); - for (Map.Entry<String, List<String>> entry : orchestrationMap.entrySet()) - { - String mapKey = entry.getKey(); - if("serviceInstanceId".equalsIgnoreCase(mapKey)) { - mapKey = "serviceInstanceId"; - } else if("serviceInstanceName".equalsIgnoreCase(mapKey)) { - mapKey = "serviceInstanceName"; - } else if("vnfInstanceId".equalsIgnoreCase(mapKey)){ - mapKey = "vnfId"; - } else if("vnfInstanceName".equalsIgnoreCase(mapKey)) { - mapKey = "vnfName"; - } else if("vfModuleInstanceId".equalsIgnoreCase(mapKey)) { - mapKey = "vfModuleId"; - } else if("vfModuleInstanceName".equalsIgnoreCase(mapKey)) { - mapKey = "vfModuleName"; - } else if("volumeGroupInstanceId".equalsIgnoreCase(mapKey)) { - mapKey = "volumeGroupId"; - } else if("volumeGroupInstanceName".equalsIgnoreCase(mapKey)) { - mapKey = "volumeGroupName"; - } else if("networkInstanceId".equalsIgnoreCase(mapKey)) { - mapKey = "networkId"; - } else if("networkInstanceName".equalsIgnoreCase(mapKey)) { - mapKey = "networkName"; - } else if(mapKey.equalsIgnoreCase("configurationInstanceId")) { - mapKey = "configurationId"; - } else if(mapKey.equalsIgnoreCase("configurationInstanceName")) { - mapKey = "configurationName"; - } else if("lcpCloudRegionId".equalsIgnoreCase(mapKey)) { - mapKey = "aicCloudRegion"; - } else if("tenantId".equalsIgnoreCase(mapKey)) { - mapKey = "tenantId"; - } else if("modelType".equalsIgnoreCase(mapKey)) { - mapKey = "requestScope"; - } else if("requestorId".equalsIgnoreCase(mapKey)) { - mapKey = "requestorId"; - } else if("requestExecutionDate".equalsIgnoreCase(mapKey)) { - mapKey = "startTime"; - } - - String propertyValue = entry.getValue().get(1); - if ("startTime".equals(mapKey)) { - SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); - try { - Date thisDate = format.parse(propertyValue); - Timestamp minTime = new Timestamp(thisDate.getTime()); - Timestamp maxTime = new Timestamp(thisDate.getTime() + TimeUnit.DAYS.toMillis(1)); - - if("DOES_NOT_EQUAL".equalsIgnoreCase(entry.getValue().get(0))) { - predicates.add(cb.or(cb.lessThan(tableRoot.get(mapKey), minTime), cb.greaterThanOrEqualTo(tableRoot.get(mapKey), maxTime))); - } else { - predicates.add(cb.between(tableRoot.get(mapKey), minTime, maxTime)); - } - } - catch (Exception e){ - msoLogger.debug("Exception in getOrchestrationFiltersFromInfraActive(): + " + e.getMessage(), e); - return null; - } - } - else if("DOES_NOT_EQUAL".equalsIgnoreCase(entry.getValue().get(0))) { - predicates.add(cb.notEqual(tableRoot.get(mapKey), propertyValue)); - } else { - predicates.add(cb.equal(tableRoot.get(mapKey), propertyValue)); - } - - } - - Order order = cb.asc(tableRoot.get(START_TIME)); - - return executeInfraQuery (crit, predicates, order); - } - - // Added this method for Tenant Isolation project ( 1802-295491a) to query the mso_requests DB - // (infra_active_requests table) for operationalEnvId and OperationalEnvName - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getCloudOrchestrationFiltersFromInfraActive(java.util.Map) - */ - @Override - public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive (Map<String, String> orchestrationMap) { - List <Predicate> predicates = new LinkedList <> (); - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); - Root<InfraActiveRequests> tableRoot = crit.from(InfraActiveRequests.class); - - // Add criteria on OperationalEnvironment RequestScope when requestorId is only specified in the filter - // as the same requestorId can also match on different API methods - String resourceType = orchestrationMap.get("resourceType"); - if(resourceType == null) { - predicates.add(cb.equal(tableRoot.get("requestScope"), "operationalEnvironment")); - } - - for (Map.Entry<String, String> entry : orchestrationMap.entrySet()) { - String mapKey = entry.getKey(); - if(mapKey.equalsIgnoreCase("requestorId")) { - mapKey = "requestorId"; - } else if(mapKey.equalsIgnoreCase("requestExecutionDate")) { - mapKey = "startTime"; - } else if(mapKey.equalsIgnoreCase("operationalEnvironmentId")) { - mapKey = "operationalEnvId"; - } else if(mapKey.equalsIgnoreCase("operationalEnvironmentName")) { - mapKey = "operationalEnvName"; - } else if(mapKey.equalsIgnoreCase("resourceType")) { - mapKey = "requestScope"; - } - - String propertyValue = entry.getValue(); - if (mapKey.equals("startTime")) { - SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); - try { - Date thisDate = format.parse(propertyValue); - Timestamp minTime = new Timestamp(thisDate.getTime()); - Timestamp maxTime = new Timestamp(thisDate.getTime() + TimeUnit.DAYS.toMillis(1)); - - predicates.add(cb.between(tableRoot.get(mapKey), minTime, maxTime)); - } - catch (Exception e){ - msoLogger.debug("Exception in getCloudOrchestrationFiltersFromInfraActive(): + " + e.getMessage()); - return null; - } - } else { - predicates.add(cb.equal(tableRoot.get(mapKey), propertyValue)); - } - } - - Order order = cb.asc(tableRoot.get(START_TIME)); - return executeInfraQuery (crit, predicates, order); - } - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getRequestListFromInfraActive(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public List <InfraActiveRequests> getRequestListFromInfraActive (String queryAttributeName, - String queryValue, - String requestType) { - msoLogger.debug ("Get list of infra requests from DB with " + queryAttributeName + " = " + queryValue); - - - try { - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); - Root<InfraActiveRequests> candidateRoot = crit.from(InfraActiveRequests.class); - Predicate isEqual = cb.equal(candidateRoot.get(queryAttributeName), queryValue); - Predicate equalRequestType = cb.equal(candidateRoot.get(REQUEST_TYPE), requestType); - Predicate isNull = cb.isNull(candidateRoot.get(REQUEST_TYPE)); - Predicate orClause = cb.or(equalRequestType, isNull); - Order orderDesc = cb.desc(candidateRoot.get(START_TIME)); - Order orderAsc = cb.asc(candidateRoot.get(SOURCE)); - crit.where(cb.and(isEqual, orClause)).orderBy(orderDesc, orderAsc); - - @SuppressWarnings("unchecked") - List <InfraActiveRequests> arList = entityManager.createQuery(crit).getResultList(); - if (arList != null && !arList.isEmpty ()) { - return arList; - } - } finally { - // msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "getRequestListFromInfraActive", null); - } - return null; - } - - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#getRequestFromInfraActive(java.lang.String, java.lang.String) - */ - @Override - public InfraActiveRequests getRequestFromInfraActive (String requestId, String requestType) { - long startTime = System.currentTimeMillis (); - msoLogger.debug ("Get infra request from DB with id " + requestId); - - InfraActiveRequests ar = null; - try { - Query query = entityManager.createQuery ("from InfraActiveRequests where (requestId = :requestId OR clientRequestId = :requestId) and requestType = :requestType"); - query.setParameter (REQUEST_ID, requestId); - query.setParameter (REQUEST_TYPE, requestType); - ar = this.getSingleResult(query); - } finally { - msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "getRequestFromInfraActive", null); - } - return ar; - } - - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkDuplicateByVnfName(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public InfraActiveRequests checkDuplicateByVnfName (String vnfName, String action, String requestType) { - - long startTime = System.currentTimeMillis (); - msoLogger.debug ("Get infra request from DB for VNF " + vnfName + " and action " + action + " and requestType " + requestType); - - InfraActiveRequests ar = null; - try { - Query query = entityManager.createQuery ("from InfraActiveRequests where vnfName = :vnfName and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT' or requestStatus = 'PENDING_MANUAL_TASK') and requestType = :requestType ORDER BY startTime DESC"); - query.setParameter ("vnfName", vnfName); - query.setParameter ("action", action); - query.setParameter (REQUEST_TYPE, requestType); - @SuppressWarnings("unchecked") - List <InfraActiveRequests> results = query.getResultList(); - if (!results.isEmpty ()) { - ar = results.get (0); - } - } finally { - msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "checkDuplicateByVnfName", null); - } - - return ar; - } - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkDuplicateByVnfId(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public InfraActiveRequests checkDuplicateByVnfId (String vnfId, String action, String requestType) { - - long startTime = System.currentTimeMillis (); - msoLogger.debug ("Get list of infra requests from DB for VNF " + vnfId + " and action " + action); - - InfraActiveRequests ar = null; - try { - Query query = entityManager.createQuery ("from InfraActiveRequests where vnfId = :vnfId and action = :action and (requestStatus = 'PENDING' or requestStatus = 'IN_PROGRESS' or requestStatus = 'TIMEOUT' or requestStatus = 'PENDING_MANUAL_TASK') and requestType = :requestType ORDER BY startTime DESC"); - query.setParameter ("vnfId", vnfId); - query.setParameter ("action", action); - query.setParameter (REQUEST_TYPE, requestType); - @SuppressWarnings("unchecked") - List <InfraActiveRequests> results = query.getResultList(); - if (!results.isEmpty ()) { - ar = results.get (0); - } - } finally { - msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "checkDuplicateByVnfId", null); - } - - return ar; - } - - /** - * update service operation status when a operation resource status updated - * <br> - * - * @param operStatus the resource operation status - * @since ONAP Amsterdam Release - */ - private void updateOperationStatusBasedOnResourceStatus(ResourceOperationStatus operStatus) { - long startTime = System.currentTimeMillis(); - msoLogger.debug("Request database - query Resource Operation Status with service Id:" - + operStatus.getServiceId() + ", operationId:" + operStatus.getOperationId()); - try { - // query all resources of the service - String hql = "FROM ResourceOperationStatus WHERE SERVICE_ID = :service_id and OPERATION_ID = :operation_id"; - Query query = entityManager.createQuery(hql); - query.setParameter("service_id", operStatus.getServiceId()); - query.setParameter("operation_id", operStatus.getOperationId()); - @SuppressWarnings("unchecked") - List<ResourceOperationStatus> lstResourceStatus = (List<ResourceOperationStatus>)query.getResultList(); - // count the total progress - int resourceCount = lstResourceStatus.size(); - int progress = 0; - boolean isFinished = true; - for(int i = 0; i < resourceCount; i++) { - progress = progress + Integer.valueOf(lstResourceStatus.get(i).getProgress()) / resourceCount; - if(RequestsDbConstant.Status.PROCESSING.equals(lstResourceStatus.get(i).getStatus())) { - isFinished = false; - } - } - - OperationStatus serviceOperStatus = new OperationStatus(operStatus.getServiceId(), operStatus.getOperationId()); - serviceOperStatus = operationStatusRepository.findOne(Example.of(serviceOperStatus)); - progress = progress > 100 ? 100 : progress; - serviceOperStatus.setProgress(String.valueOf(progress)); - serviceOperStatus.setOperationContent(operStatus.getStatusDescription()); - // if current resource failed. service failed. - if(RequestsDbConstant.Status.ERROR.equals(operStatus.getStatus())) { - serviceOperStatus.setResult(RequestsDbConstant.Status.ERROR); - serviceOperStatus.setReason(operStatus.getStatusDescription()); - } else if(isFinished) { - // if finished - serviceOperStatus.setResult(RequestsDbConstant.Status.FINISHED); - serviceOperStatus.setProgress(RequestsDbConstant.Progress.ONE_HUNDRED); - } - operationStatusRepository.save(serviceOperStatus); - } finally { - msoLogger.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, - "Successfully", "RequestDB", "updateResOperStatus", null); - } - } - - /* (non-Javadoc) - * @see org.onap.so.requestsdb.InfraActiveRequestsRepositoryCustom#checkVnfIdStatus(java.lang.String) - */ - @Override - public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) { - long startTime = System.currentTimeMillis (); - msoLogger.debug ("Get Infra request from DB for OperationalEnvironmentId " + operationalEnvironmentId); - - InfraActiveRequests ar = null; - try { - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - CriteriaQuery<InfraActiveRequests> crit = cb.createQuery(InfraActiveRequests.class); - Root<InfraActiveRequests> candidateRoot = crit.from(InfraActiveRequests.class); - Predicate operationalEnvEq = cb.equal(candidateRoot.get("operationalEnvId"), operationalEnvironmentId); - Predicate requestStatusNotEq = cb.notEqual(candidateRoot.get("requestStatus"), "COMPLETE"); - Predicate actionEq = cb.equal(candidateRoot.get("action"), "create"); - Order startTimeOrder = cb.desc(candidateRoot.get("startTime")); - crit.select(candidateRoot); - crit.where(cb.and(operationalEnvEq, requestStatusNotEq, actionEq)); - crit.orderBy(startTimeOrder); - TypedQuery<InfraActiveRequests> query = entityManager.createQuery(crit); - @SuppressWarnings("unchecked") - List <InfraActiveRequests> results = query.getResultList(); - if (!results.isEmpty ()) { - ar = results.get (0); - } - } finally { - msoLogger.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "RequestDB", "checkDuplicateByVnfName", null); - } - - return ar; - } - - protected <T> T getSingleResult(Query query) { - query.setMaxResults(1); - List<T> list = query.getResultList(); - if (list == null || list.isEmpty()) { - return null; - } else if (list.size() == 1) { - return list.get(0); - } else { - throw new NonUniqueResultException(); - } - - } -} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/QueryOperationType.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/QueryOperationType.java new file mode 100644 index 0000000000..4aaa8d2cbe --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/QueryOperationType.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.db.request.data.repository; + +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +/** + * @author waqas.ikram@ericsson.com + */ +public enum QueryOperationType { + + EQ { + @Override + public <T> Predicate getPredicate(final CriteriaBuilder criteriaBuilder, final Root<T> tableRoot, + final String key, final String value) { + return criteriaBuilder.equal(tableRoot.get(key), value); + } + + }, + NEQ { + + @Override + public <T> Predicate getPredicate(final CriteriaBuilder criteriaBuilder, final Root<T> tableRoot, + final String key, final String value) { + return criteriaBuilder.notEqual(tableRoot.get(key), value); + } + + }, + LIKE { + + @Override + public <T> Predicate getPredicate(final CriteriaBuilder criteriaBuilder, final Root<T> tableRoot, + final String key, final String value) { + return criteriaBuilder.like(tableRoot.get(key), "%" + value + "%"); + } + }; + + public static QueryOperationType getQueryOperationType(final String type) { + for (final QueryOperationType queryOperationType : QueryOperationType.values()) { + if (queryOperationType.name().equalsIgnoreCase(type)) { + return queryOperationType; + } + } + return QueryOperationType.EQ; + } + + public abstract <T> Predicate getPredicate(final CriteriaBuilder criteriaBuilder, final Root<T> tableRoot, + final String key, final String value); + +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java index 562e54ca6e..ea3ef30827 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java @@ -24,8 +24,9 @@ import java.sql.Timestamp; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.logger.MsoLogger; -import org.onap.so.requestsdb.client.RequestsDbClient; +import org.onap.so.db.request.client.RequestsDbClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @Component @@ -37,6 +38,7 @@ public class RequestsDBHelper { private String methodName = ""; private String classMethodMessage = ""; @Autowired + @Qualifier("RequestsDbClient") private RequestsDbClient requestsDbClient; /** * This util method is to update the InfraRequest table to Complete diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/adapter/TimestampXMLAdapter.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/TimestampXMLAdapter.java index 1cde1aac51..3a326598a7 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/adapter/TimestampXMLAdapter.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/TimestampXMLAdapter.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.requestsdb.adapter; +package org.onap.so.requestsdb; import java.sql.Timestamp; diff --git a/mso-api-handlers/mso-requests-db/src/main/resources/beans.xml b/mso-api-handlers/mso-requests-db/src/main/resources/beans.xml deleted file mode 100644 index cd1bc8b7d7..0000000000 --- a/mso-api-handlers/mso-requests-db/src/main/resources/beans.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:jpa="http://www.springframework.org/schema/data/jpa" - xsi:schemaLocation="http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/data/jpa - http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> - - <jpa:repositories base-package="org.onap.so.db.request.data.repository" /> - -</beans>
\ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml b/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml index 62ae4794f5..c4dd60356b 100644 --- a/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml +++ b/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml @@ -12,6 +12,7 @@ mso: endpoint: http://localhost:8081 site-name: localDevEnv logPath: logs + # H2 spring: datasource: diff --git a/mso-api-handlers/pom.xml b/mso-api-handlers/pom.xml index aed05209cb..078971ec29 100644 --- a/mso-api-handlers/pom.xml +++ b/mso-api-handlers/pom.xml @@ -14,6 +14,7 @@ <modules> <module>mso-requests-db</module> + <module>mso-requests-db-repositories</module> <module>mso-api-handler-common</module> <module>mso-api-handler-infra</module> </modules> |