E2EServiceInstances to be free of catalogdb
Fixing Junits
Making MSO requests free from direct repository calls
Add @Param annotation so as to fix JPA methods with query parameters
Fix createE2EServiceInstance Test
Add Unit Tests for Sunny day scenarios
revert import auto-alignment
Issue-ID: SO-811
Change-Id: I9f69d817622b0807642a783311d6959817a77970
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
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 ee50d92..e8a6beb 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
@@ -56,10 +56,8 @@
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.ServiceRecipe;
-import org.onap.so.db.catalog.data.repository.ServiceRecipeRepository;
-import org.onap.so.db.catalog.data.repository.ServiceRepository;
+import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.db.request.beans.OperationStatus;
-import org.onap.so.db.request.data.repository.OperationStatusRepository;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoAlarmLogger;
import org.onap.so.logger.MsoLogger;
@@ -84,14 +82,12 @@
public class E2EServiceInstances {
private HashMap<String, String> instanceIdMap = new HashMap<>();
- private static MsoLogger msoLogger = MsoLogger
+ private static final MsoLogger msoLogger = MsoLogger
.getMsoLogger(MsoLogger.Catalog.APIH, E2EServiceInstances.class);
- private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
- public static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
+ private static final MsoAlarmLogger alarmLogger = new MsoAlarmLogger();
+ private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA";
- public static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: ";
- public static final String EXCEPTION_CREATING_DB_RECORD = "Exception while creating record in DB";
- public static final String EXCEPTION_COMMUNICATE_BPMN_ENGINE = "Exception while communicate with BPMN engine";
+ private static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: ";
@Autowired
private MsoRequest msoRequest;
@@ -100,13 +96,10 @@
private RequestClientFactory requestClientFactory;
@Autowired
- private OperationStatusRepository osRepo;
+ private RequestsDbClient requestsDbClient;
@Autowired
- private ServiceRepository serviceRepo;
-
- @Autowired
- private ServiceRecipeRepository sRecipeRepo;
+ private CatalogDbClient catalogDbClient;
@Autowired
private ResponseBuilder builder;
@@ -224,7 +217,7 @@
long startTime = System.currentTimeMillis();
msoLogger.debug("requestId is: " + requestId);
- CompareModelsRequest e2eCompareModelReq = null;
+ CompareModelsRequest e2eCompareModelReq;
ObjectMapper mapper = new ObjectMapper();
try {
@@ -256,8 +249,8 @@
String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance";
int recipeTimeout = 180;
- RequestClient requestClient = null;
- HttpResponse response = null;
+ RequestClient requestClient;
+ HttpResponse response;
long subStartTime = System.currentTimeMillis();
@@ -327,12 +320,11 @@
long startTime = System.currentTimeMillis();
- OperationStatus operationStatus = null;
+ OperationStatus operationStatus;
try {
- operationStatus = osRepo.findOneByServiceIdAndOperationId(serviceId,
+ operationStatus = requestsDbClient.getOneByServiceIdAndOperationId(serviceId,
operationId);
-
} catch (Exception e) {
msoLogger
.error(MessageEnum.APIH_DB_ACCESS_EXC,
@@ -353,7 +345,7 @@
MsoLogger.ResponseCode.DBAccessError,
"Exception while communciate with Request DB");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
+ + response.getEntity());
return response;
}
@@ -371,7 +363,7 @@
MsoLogger.ResponseCode.DataNotFound,
"Null response from RequestDB when searching by serviceId");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) resp.getEntity());
+ + resp.getEntity());
return resp;
}
@@ -387,7 +379,7 @@
String requestId = UUIDChecker.generateUUID(msoLogger);
long startTime = System.currentTimeMillis();
msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceDeleteRequest e2eDelReq = null;
+ E2EServiceInstanceDeleteRequest e2eDelReq;
ObjectMapper mapper = new ObjectMapper();
try {
@@ -410,11 +402,11 @@
MsoLogger.ResponseCode.SchemaError,
"Mapping of request to JSON object failed");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
+ + response.getEntity());
return response;
}
- RecipeLookupResult recipeLookupResult = null;
+ RecipeLookupResult recipeLookupResult;
try {
//TODO Get the service template model version uuid from AAI.
recipeLookupResult = getServiceInstanceOrchestrationURI(null, action);
@@ -436,7 +428,7 @@
MsoLogger.ResponseCode.DBAccessError,
"Exception while communciate with DB");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
+ + response.getEntity());
return response;
}
if (recipeLookupResult == null) {
@@ -454,12 +446,12 @@
MsoLogger.ResponseCode.DataNotFound,
"No recipe found in DB");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
+ + response.getEntity());
return response;
}
- RequestClient requestClient = null;
- HttpResponse response = null;
+ RequestClient requestClient;
+ HttpResponse response;
long subStartTime = System.currentTimeMillis();
try {
@@ -514,7 +506,7 @@
MsoLogger.ResponseCode.CommunicationError,
"Exception while communicate with BPMN engine");
msoLogger.debug("End of the transaction, the final response is: "
- + (String) resp.getEntity());
+ + resp.getEntity());
return resp;
}
@@ -530,7 +522,7 @@
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
MsoLogger.ResponseCode.InternalError,
"Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
return resp;
}
@@ -548,7 +540,7 @@
String requestId = UUIDChecker.generateUUID(msoLogger);
long startTime = System.currentTimeMillis();
msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceRequest e2eSir = null;
+ E2EServiceInstanceRequest e2eSir;
String serviceId = instanceIdMap.get("serviceId");
ObjectMapper mapper = new ObjectMapper();
@@ -565,7 +557,7 @@
MsoLogger.ErrorCode.SchemaError, requestJSON, e);
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
"Mapping of request to JSON object failed");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
@@ -585,11 +577,11 @@
MsoLogger.ErrorCode.SchemaError, requestJSON, e);
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
"Validation of the input request failed");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
- RecipeLookupResult recipeLookupResult = null;
+ RecipeLookupResult recipeLookupResult;
try {
recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
} catch (Exception e) {
@@ -603,7 +595,7 @@
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
"Exception while communciate with DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
@@ -617,15 +609,15 @@
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
"No recipe found in DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
String serviceInstanceType = e2eSir.getService().getServiceType();
- RequestClient requestClient = null;
- HttpResponse response = null;
+ RequestClient requestClient;
+ HttpResponse response;
long subStartTime = System.currentTimeMillis();
String sirRequestJson = convertToString(sir);
@@ -665,7 +657,7 @@
MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
"Exception while communicate with BPMN engine");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity());
return getBPMNResp;
}
@@ -677,7 +669,7 @@
MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,
"Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity());
return getBPMNResp;
}
@@ -694,7 +686,7 @@
String requestId = UUIDChecker.generateUUID(msoLogger);
long startTime = System.currentTimeMillis();
msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceRequest e2eSir = null;
+ E2EServiceInstanceRequest e2eSir;
MsoRequest msoRequest = new MsoRequest();
ObjectMapper mapper = new ObjectMapper();
@@ -711,7 +703,7 @@
MsoLogger.ErrorCode.SchemaError, requestJSON, e);
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
"Mapping of request to JSON object failed");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
@@ -731,11 +723,11 @@
MsoLogger.ErrorCode.SchemaError, requestJSON, e);
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
"Validation of the input request failed");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
- RecipeLookupResult recipeLookupResult = null;
+ RecipeLookupResult recipeLookupResult;
try {
recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
} catch (Exception e) {
@@ -749,7 +741,7 @@
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError,
"Exception while communciate with DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
@@ -762,15 +754,15 @@
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound,
"No recipe found in DB");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity());
return response;
}
String serviceInstanceType = e2eSir.getService().getServiceType();
String serviceId = "";
- RequestClient requestClient = null;
- HttpResponse response = null;
+ RequestClient requestClient;
+ HttpResponse response;
long subStartTime = System.currentTimeMillis();
String sirRequestJson = convertToString(sir);
@@ -809,7 +801,7 @@
MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
"Exception while communicate with BPMN engine");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
return resp;
}
@@ -820,7 +812,7 @@
MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,
"Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
return resp;
}
@@ -837,7 +829,7 @@
String requestId = UUIDChecker.generateUUID(msoLogger);
long startTime = System.currentTimeMillis();
msoLogger.debug("requestId is: " + requestId);
- E2EServiceInstanceScaleRequest e2eScaleReq = null;
+ E2EServiceInstanceScaleRequest e2eScaleReq;
ObjectMapper mapper = new ObjectMapper();
try {
@@ -860,11 +852,11 @@
MsoLogger.ResponseCode.SchemaError,
"Mapping of request to JSON object failed");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
+ + response.getEntity());
return response;
}
- RecipeLookupResult recipeLookupResult = null;
+ RecipeLookupResult recipeLookupResult;
try {
//TODO Get the service template model version uuid from AAI.
recipeLookupResult = getServiceInstanceOrchestrationURI(null, action);
@@ -886,7 +878,7 @@
MsoLogger.ResponseCode.DBAccessError,
"Exception while communciate with DB");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
+ + response.getEntity());
return response;
}
if (recipeLookupResult == null) {
@@ -903,12 +895,12 @@
MsoLogger.ResponseCode.DataNotFound,
"No recipe found in DB");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) response.getEntity());
+ + response.getEntity());
return response;
}
- RequestClient requestClient = null;
- HttpResponse response = null;
+ RequestClient requestClient;
+ HttpResponse response;
long subStartTime = System.currentTimeMillis();
try {
@@ -963,7 +955,7 @@
MsoLogger.ResponseCode.CommunicationError,
"Exception while communicate with BPMN engine");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) resp.getEntity());
+ + resp.getEntity());
return resp;
}
@@ -979,7 +971,7 @@
msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR,
MsoLogger.ResponseCode.InternalError,
"Null response from BPMN");
- msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity());
+ msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity());
return resp;
}
@@ -1028,7 +1020,7 @@
MsoLogger.ResponseCode.InternalError,
"Response from BPMN engine is failed");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) resp.getEntity());
+ + resp.getEntity());
return resp;
} else {
Response resp = msoRequest
@@ -1047,7 +1039,7 @@
MsoLogger.ResponseCode.InternalError,
"Response from BPEL engine is empty");
msoLogger.debug(END_OF_THE_TRANSACTION
- + (String) resp.getEntity());
+ + resp.getEntity());
return resp;
}
}
@@ -1056,7 +1048,6 @@
/**
* Getting recipes from catalogDb
*
- * @param db the catalog db
* @param serviceModelUUID the service model version uuid
* @param action the action for the service
* @return the service recipe result
@@ -1079,7 +1070,6 @@
/**
* Getting recipes from catalogDb
* If Service recipe is not set, use default recipe, if set , use special recipe.
- * @param db the catalog db
* @param serviceModelUUID the service version uuid
* @param action the action of the service.
* @return the service recipe result.
@@ -1088,13 +1078,12 @@
String defaultServiceModelName = "UUI_DEFAULT";
- Service defaultServiceRecord = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
- ServiceRecipe defaultRecipe = sRecipeRepo.findFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name());
+ Service defaultServiceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
//set recipe as default generic recipe
- ServiceRecipe recipe = defaultRecipe;
+ ServiceRecipe recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name());
//check the service special recipe
if(null != serviceModelUUID && ! serviceModelUUID.isEmpty()){
- ServiceRecipe serviceSpecialRecipe = sRecipeRepo.findFirstByServiceModelUUIDAndAction(
+ ServiceRecipe serviceSpecialRecipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(
serviceModelUUID, action.name());
if(null != serviceSpecialRecipe){
//set service special recipe.
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 a93feb6..38b3dd6 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
@@ -95,7 +95,7 @@
public class MsoRequest {
@Autowired
- private InfraActiveRequestsRepository iarRepo;
+ private RequestsDbClient requestsDbClient;
@Autowired
private ResponseBuilder builder;
@@ -426,7 +426,7 @@
request.setRequestBody(requestJSON);
Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
request.setEndTime(endTimeStamp);
- iarRepo.save(request);
+ requestsDbClient.save(request);
} catch (Exception e) {
msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB");
msoLogger.debug ("Exception: ", e);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java
index 466de0a..380ee2c 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java
@@ -22,6 +22,7 @@
import org.apache.http.HttpStatus;
import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.beans.OperationStatus;
import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -30,10 +31,6 @@
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;
@@ -41,10 +38,9 @@
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 java.io.IOException;
+import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
@@ -53,7 +49,11 @@
@Component("RequestDbClient")
public class RequestsDbClient {
+ private static final String SERVICE_ID = "SERVICE_ID";
+ private static final String OPERATION_ID = "OPERATION_ID";
+
private Client<InfraActiveRequests> infraActiveRequestClient;
+ private Client<OperationStatus> operationStatusClient;
@Value("${mso.adapters.requestDb.endpoint}")
private String endpoint;
@@ -62,12 +62,15 @@
private String msoAdaptersAuth;
private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/";
+ private static final String OPERATION_STATUS_REPOSITORY_SEARCH = "/operationStatusRepository/search";
private String checkVnfIdStatus = "/infraActiveRequests/checkVnfIdStatus/";
private String infraActiveRequestURI = "/infraActiveRequests/";
private String checkInstanceNameDuplicate = "/infraActiveRequests/checkInstanceNameDuplicate";
+
+ private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId";
private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive";
@@ -83,27 +86,18 @@
checkVnfIdStatus = endpoint + checkVnfIdStatus;
checkInstanceNameDuplicate = endpoint + checkInstanceNameDuplicate;
cloudOrchestrationFiltersFromInfraActive = endpoint + cloudOrchestrationFiltersFromInfraActive;
+ findOneByServiceIdAndOperationIdURI = endpoint + OPERATION_STATUS_REPOSITORY_SEARCH + findOneByServiceIdAndOperationIdURI;
headers = new HttpHeaders();
headers.set("Authorization", msoAdaptersAuth);
}
public RequestsDbClient() {
- 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();
+ ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(restTemplate -> restTemplate.getInterceptors().add((request, body, execution) -> {
+ request.getHeaders().add("Authorization", msoAdaptersAuth);
+ return execution.execute(request, body);
+ })).build().buildClientFactory();
infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class);
+ operationStatusClient = clientFactory.create(OperationStatus.class);
}
public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){
@@ -145,6 +139,13 @@
}
}
+
+ public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId){
+ return this.getSingleOperationStatus(UriBuilder.fromUri(findOneByServiceIdAndOperationIdURI)
+ .queryParam(SERVICE_ID,serviceId)
+ .queryParam(OPERATION_ID,operationId)
+ .build());
+ }
public void save(InfraActiveRequests infraActiveRequests) {
URI uri = getUri(infraActiveRequestURI);
@@ -159,6 +160,10 @@
public void updateInfraActiveRequests(InfraActiveRequests request) {
infraActiveRequestClient.put(request);
}
+
+ public OperationStatus getSingleOperationStatus(URI uri){
+ return operationStatusClient.get(uri);
+ }
protected URI getUri(String uri) {
return URI.create(uri);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml
index 3252146..226814f 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml
@@ -17,6 +17,10 @@
mso:
+ adapters:
+ requestDb:
+ auth: Basic YnBlbDptc28tZGItMTUwNyE=
+ endpoint: http://localhost:8081
logPath: logs
site-name: mtanj
catalog:
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
index 2baa54f..a63b778 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/E2EServiceInstancesTest.java
@@ -20,10 +20,7 @@
package org.onap.so.apihandlerinfra;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-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.github.tomakehurst.wiremock.client.WireMock.*;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -33,11 +30,17 @@
import java.nio.file.Files;
import java.nio.file.Paths;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.junit.Ignore;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.apache.http.HttpStatus;
+import org.junit.Before;
import org.junit.Test;
+import org.onap.so.db.catalog.beans.Service;
+import org.onap.so.db.catalog.beans.ServiceRecipe;
+import org.onap.so.db.request.beans.OperationStatus;
import org.onap.so.serviceinstancebeans.RequestError;
import org.onap.so.serviceinstancebeans.ServiceException;
import org.springframework.http.HttpEntity;
@@ -45,43 +48,65 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.util.UriComponentsBuilder;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.http.Fault;
public class E2EServiceInstancesTest extends BaseTest {
-private ObjectMapper mapper = new ObjectMapper();
+private final ObjectMapper mapper = new ObjectMapper();
private final String e2eServInstancesUri = "/e2eServiceInstances/";
+
+ @Before
+ public void init() throws JsonProcessingException {
+ stubFor(post(urlPathEqualTo("/testOrchestrationUri"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+ stubFor(post(urlPathEqualTo("/infraActiveRequests/")).withRequestBody(equalToJson("{\"clientRequestId\":null,\"action\":null,\"requestStatus\":\"FAILED\",\"statusMessage\":\"Error parsing request: No valid requestorId is specified\",\"progress\":100,\"startTime\":1533541051247,\"endTime\":1533541051247,\"source\":null,\"vnfId\":null,\"vnfName\":null,\"vnfType\":null,\"serviceType\":null,\"aicNodeClli\":null,\"tenantId\":null,\"provStatus\":null,\"vnfParams\":null,\"vnfOutputs\":null,\"requestBody\":\"{\\r\\n \\\"service\\\":{\\r\\n \\\"name\\\":\\\"so_test4\\\",\\r\\n \\\"description\\\":\\\"so_test2\\\",\\r\\n \\\"serviceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561519\\\",\\r\\n \\\"serviceUuid\\\":\\\"592f9437-a9c0-4303-b9f6-c445bb7e9814\\\",\\r\\n \\\"globalSubscriberId\\\":\\\"123457\\\",\\r\\n \\\"serviceType\\\":\\\"voLTE\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"resources\\\":[\\r\\n {\\r\\n \\\"resourceName\\\":\\\"vIMS\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561516\\\",\\r\\n \\\"resourceUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561512\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n {\\r\\n \\\"vnfProfileId\\\":\\\"zte-vBAS-1.0\\\",\\r\\n \\\"locationConstraints\\\":{\\r\\n \\\"vimId\\\":\\\"4050083f-465f-4838-af1e-47a545222ad0\\\"\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"vnfProfileId\\\":\\\"zte-vMME-1.0\\\",\\r\\n \\\"locationConstraints\\\":{\\r\\n \\\"vimId\\\":\\\"4050083f-465f-4838-af1e-47a545222ad0\\\"\\r\\n }\\r\\n }\\r\\n ]\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"resourceName\\\":\\\"vEPC\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"61c3e96e-0970-4871-b6e0-3b6de7561516\\\",\\r\\n \\\"resourceUuid\\\":\\\"62c3e96e-0970-4871-b6e0-3b6de7561512\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n {\\r\\n \\\"vnfProfileId\\\":\\\"zte-CSCF-1.0\\\",\\r\\n \\\"locationConstraints\\\":{\\r\\n \\\"vimId\\\":\\\"4050083f-465f-4838-af1e-47a545222ad1\\\"\\r\\n }\\r\\n }\\r\\n ]\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"resourceName\\\":\\\"underlayvpn\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561513\\\",\\r\\n \\\"resourceUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561514\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n\\r\\n ]\\r\\n }\\r\\n },\\r\\n {\\r\\n \\\"resourceName\\\":\\\"overlayvpn\\\",\\r\\n \\\"resourceInvariantUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561517\\\",\\r\\n \\\"resourceUuid\\\":\\\"60c3e96e-0970-4871-b6e0-3b6de7561518\\\",\\r\\n \\\"parameters\\\":{\\r\\n \\\"locationConstraints\\\":[\\r\\n\\r\\n ]\\r\\n }\\r\\n }\\r\\n ],\\r\\n \\\"requestInputs\\\":{\\r\\n \\\"externalDataNetworkName\\\":\\\"Flow_out_net\\\",\\r\\n \\\"m6000_mng_ip\\\":\\\"181.18.20.2\\\",\\r\\n \\\"externalCompanyFtpDataNetworkName\\\":\\\"Flow_out_net\\\",\\r\\n \\\"externalPluginManageNetworkName\\\":\\\"plugin_net_2014\\\",\\r\\n \\\"externalManageNetworkName\\\":\\\"mng_net_2017\\\",\\r\\n \\\"sfc_data_network\\\":\\\"sfc_data_net_2016\\\",\\r\\n \\\"NatIpRange\\\":\\\"210.1.1.10-210.1.1.20\\\",\\r\\n \\\"location\\\":\\\"4050083f-465f-4838-af1e-47a545222ad0\\\",\\r\\n \\\"sdncontroller\\\":\\\"9b9f02c0-298b-458a-bc9c-be3692e4f35e\\\"\\r\\n }\\r\\n }\\r\\n\\r\\n }\\r\\n\\r\\n}\",\"responseBody\":null,\"lastModifiedBy\":\"APIH\",\"modifyTime\":null,\"requestType\":null,\"volumeGroupId\":null,\"volumeGroupName\":null,\"vfModuleId\":null,\"vfModuleName\":null,\"vfModuleModelName\":null,\"aaiServiceId\":null,\"aicCloudRegion\":null,\"callBackUrl\":null,\"correlator\":null,\"serviceInstanceId\":null,\"serviceInstanceName\":null,\"requestScope\":\"service\",\"requestAction\":\"createInstance\",\"networkId\":null,\"networkName\":null,\"networkType\":null,\"requestorId\":null,\"configurationId\":null,\"configurationName\":null,\"operationalEnvId\":null,\"operationalEnvName\":null,\"requestURI\":\"d167c9d0-1785-4e93-b319-996ebbcc3272\"}")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(HttpStatus.SC_OK)));
+ Service defaultService = new Service();
+ defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
+ ServiceRecipe serviceRecipe = new ServiceRecipe();
+ serviceRecipe.setServiceModelUUID(defaultService.getModelUUID());
+ serviceRecipe.setAction(Action.scaleInstance.name());
+ serviceRecipe.setRecipeTimeout(180);
+ serviceRecipe.setOrchestrationUri("/testOrchestrationUri");
+
+ stubFor(get(urlPathEqualTo("/service/search/findFirstByModelNameOrderByModelVersionDesc"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(defaultService))
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlPathEqualTo("/serviceRecipe/search/findFirstByServiceModelUUIDAndAction"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceRecipe))
+ .withStatus(HttpStatus.SC_OK)));
+
+ }
public String inputStream(String JsonInput)throws IOException{
JsonInput = "src/test/resources/E2EServiceInstancesTest" + JsonInput;
- String input = new String(Files.readAllBytes(Paths.get(JsonInput)));
- return input;
+ return new String(Files.readAllBytes(Paths.get(JsonInput)));
}
public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod){
headers.set("Accept", MediaType.APPLICATION_JSON);
headers.set("Content-Type",MediaType.APPLICATION_JSON);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath));
- HttpEntity<String> request = new HttpEntity<String>(requestJson, headers);
- ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),
+ HttpEntity<String> request = new HttpEntity<>(requestJson, headers);
+
+ return restTemplate.exchange(builder.toUriString(),
reqMethod, request, String.class);
-
- return response;
}
- //Currently returning a 500 response
- @Ignore
+
@Test
- public void createE2EServiceInstanceNoRequestInfo() throws JsonParseException, JsonMappingException, IOException{
- String uri = e2eServInstancesUri + "v5";
+ public void createE2EServiceInstanceNoRequestInfo() throws IOException{
+ String uri = e2eServInstancesUri + "v3";
ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.POST);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
}
@Test
- public void updateE2EServiceInstanceJSONMappingError() throws JsonParseException, JsonMappingException, IOException{
+ public void updateE2EServiceInstanceJSONMappingError() throws IOException{
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e";
ResponseEntity<String> response = sendRequest(inputStream("/CompareModelRequest.json"), uri, HttpMethod.PUT);
@@ -90,7 +115,7 @@
assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed"));
}
@Test
- public void updateE2EServiceInstanceNoRequestorId() throws JsonParseException, JsonMappingException, IOException{
+ public void updateE2EServiceInstanceNoRequestorId() throws IOException{
RequestError expectedResponse = new RequestError();
ServiceException exception = new ServiceException();
exception.setMessageId("SVC0002");
@@ -105,7 +130,7 @@
assertThat(realResponse, sameBeanAs(expectedResponse));
}
@Test
- public void deleteE2EServiceInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException{
+ public void deleteE2EServiceInstance() throws IOException{
RequestError expectedResponse = new RequestError();
ServiceException exception = new ServiceException();
exception.setMessageId("SVC1000");
@@ -115,12 +140,10 @@
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e";
ResponseEntity<String> response = sendRequest(inputStream("/DeleteRequest.json"), uri, HttpMethod.DELETE);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
- RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
- assertThat(realResponse, sameBeanAs(expectedResponse));
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
}
@Test
- public void deleteE2EServiceInstanceNotValid() throws JsonParseException, JsonMappingException, IOException{
+ public void deleteE2EServiceInstanceNotValid() throws IOException{
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e";
ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.DELETE);
@@ -129,14 +152,14 @@
assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed"));
}
@Test
- public void getE2EServiceInstanceNullOperationalStatus() throws JsonParseException, JsonMappingException, IOException{
+ public void getE2EServiceInstanceNullOperationalStatus() throws IOException{
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/operations/9b9f02c0-298b-458a-bc9c-be3692e4f35e";
ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.GET);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatusCode().value());
}
@Test
- public void scaleE2EServiceInstanceMappingError() throws JsonParseException, JsonMappingException, IOException{
+ public void scaleE2EServiceInstanceMappingError() throws IOException{
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/scale";
ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.POST);
@@ -145,22 +168,35 @@
assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed"));
}
@Test
- public void scaleE2EServiceInstance() throws JsonParseException, JsonMappingException, IOException{
- RequestError expectedResponse = new RequestError();
- ServiceException exception = new ServiceException();
- exception.setMessageId("SVC1000");
- exception.setText("No communication to catalog DB null");
- expectedResponse.setServiceException(exception);
-
+ public void scaleE2EServiceInstance() throws IOException{
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/scale";
ResponseEntity<String> response = sendRequest(inputStream("/ScaleRequest.json"), uri, HttpMethod.POST);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
- RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
- assertThat(realResponse, sameBeanAs(expectedResponse));
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void updateE2EServiceInstance() throws IOException{
+ String uri = e2eServInstancesUri + "v3/9b9f02c0-298b-458a-bc9c-be3692e4f35e";
+ ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.PUT);
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
+ }
+
+ @Test
+ public void getE2EServiceInstance() throws IOException{
+ OperationStatus status = new OperationStatus();
+ status.setOperationId("operationId");
+ status.setServiceId("9b9f02c0-298b-458a-bc9c-be3692e4f35e");
+ stubFor(get(urlPathEqualTo("/operationStatusRepository/search/findOneByServiceIdAndOperationId"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(status))
+ .withStatus(HttpStatus.SC_OK)));
+ String uri = e2eServInstancesUri + "v3/9b9f02c0-298b-458a-bc9c-be3692e4f35e/operations/operationId";
+ ResponseEntity<String> response = sendRequest("", uri, HttpMethod.GET);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
}
@Test
- public void compareModelWithTargetVersionBadRequest() throws JsonParseException, JsonMappingException, IOException{
+ public void compareModelWithTargetVersionBadRequest() throws IOException{
String uri = e2eServInstancesUri + "v5/9b9f02c0-298b-458a-bc9c-be3692e4f35e/modeldifferences";
ResponseEntity<String> response = sendRequest(inputStream("/Request.json"), uri, HttpMethod.POST);
@@ -169,7 +205,7 @@
assertTrue(realResponse.getServiceException().getText().contains("Mapping of request to JSON object failed"));
}
@Test
- public void compareModelWithTargetVersion() throws JsonParseException, JsonMappingException, IOException{
+ public void compareModelWithTargetVersion() throws IOException{
stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBodyFile("Camunda/SuccessfulResponse.json").withStatus(org.apache.http.HttpStatus.SC_ACCEPTED)));
@@ -183,7 +219,7 @@
assertEquals(expectedResponse, actualResponse);
}
@Test
- public void compareModelWithTargetVersionEmptyResponse() throws JsonParseException, JsonMappingException, IOException{
+ public void compareModelWithTargetVersionEmptyResponse() throws IOException{
stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance"))
.willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
@@ -201,7 +237,7 @@
assertThat(realResponse, sameBeanAs(expectedResponse));
}
@Test
- public void compareModelWithTargetVersionBadBpelResponse() throws JsonParseException, JsonMappingException, IOException{
+ public void compareModelWithTargetVersionBadBpelResponse() throws IOException{
stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY)));
@@ -214,7 +250,7 @@
assertTrue(realResponse.getServiceException().getText().contains("Request Failed due to BPEL error with HTTP Status"));
}
@Test
- public void compareModelWithTargetVersionNoBPELResponse() throws JsonParseException, JsonMappingException, IOException{
+ public void compareModelWithTargetVersionNoBPELResponse() throws IOException{
stubFor(post(urlPathEqualTo("/mso/async/services/CompareModelofE2EServiceInstance"))
.willReturn(aResponse().withHeader("Content-Type", "application/json")
.withBody("{}").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY)));
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
index c5b3b70..b7b6a8c 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
@@ -29,7 +29,7 @@
catalog:
db:
spring:
- endpoint: "http://localhost:"
+ endpoint: http://localhost:${wiremock.server.port}
db:
auth: Basic YnBlbDptc28tZGItMTUwNyE=
config:
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/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java
index c51e4ed..22a1604 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/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java
@@ -23,12 +23,13 @@
import org.onap.so.db.request.beans.OperationStatus;
import org.onap.so.db.request.beans.OperationStatusId;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
+import org.springframework.data.repository.query.Param;
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
-@Repository
+@RepositoryRestResource(collectionResourceRel = "operationStatusRepository", path = "operationStatusRepository")
public interface OperationStatusRepository extends JpaRepository<OperationStatus, OperationStatusId> {
- OperationStatus findOneByServiceIdAndOperationId(String serviceId, String operationId);
+ OperationStatus findOneByServiceIdAndOperationId(@Param("SERVICE_ID") String serviceId, @Param("OPERATION_ID") String operationId);
public OperationStatus findOneByServiceName(String serviceName);
public OperationStatus findOneByServiceId(String serviceId);
}
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java
index d3a1c5d..edfaba0 100644
--- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java
+++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java
@@ -20,14 +20,6 @@
package org.onap.so.db.catalog.client;
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.ws.rs.core.UriBuilder;
-
import org.onap.so.db.catalog.beans.BuildingBlockDetail;
import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
@@ -40,6 +32,7 @@
import org.onap.so.db.catalog.beans.Service;
import org.onap.so.db.catalog.beans.VfModuleCustomization;
import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
+import org.onap.so.db.catalog.beans.ServiceRecipe;
import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
@@ -54,38 +47,58 @@
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Component;
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.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
@Component("CatalogDbClient")
public class CatalogDbClient {
- protected Client<Service> serviceClient;
-
- protected Client<VfModuleCustomization> vfModuleCustomizationClient;
-
- protected Client<OrchestrationFlow> orchestrationClient;
-
- protected Client<NorthBoundRequest> northBoundRequestClient;
-
- protected Client<RainyDayHandlerStatus> rainyDayHandlerStatusClient;
-
- protected Client<BuildingBlockDetail> buildingBlockDetailClient;
-
- protected Client<OrchestrationStatusStateTransitionDirective> orchestrationStatusStateTransitionDirectiveClient;
-
- protected Client<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizationClient;
-
- protected Client<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationClient;
-
- protected Client<InstanceGroup> instanceGroupClient;
+ private static final String SERVICE_RECIPE_SEARCH = "/serviceRecipe/search";
+ private static final String SERVICE_MODEL_UUID = "SERVICE_MODEL_UUID";
+ private static final String ACTION = "ACTION";
+ private static final String MODEL_NAME = "MODEL_NAME";
+ private static final String SERVICE_SEARCH = "/service/search";
+ private static final String MODEL_VERSION = "MODEL_VERSION";
+ private static final String MODEL_INVARIANT_UUID = "MODEL_INVARIANT_UUID";
+ private String findFirstByModelNameURI = "/findFirstByModelNameOrderByModelVersionDesc";
+ private String findFirstByServiceModelUUIDAndActionURI = "/findFirstByServiceModelUUIDAndAction";
+ private String findByModelVersionAndModelInvariantUUIDURI = "/findByModelVersionAndModelInvariantUUID";
- protected Client<NetworkCollectionResourceCustomization> networkCollectionResourceCustomizationClient;
+ private Client<Service> serviceClient;
+
+ private Client<VfModuleCustomization> vfModuleCustomizationClient;
+
+ private Client<OrchestrationFlow> orchestrationClient;
+
+ private Client<NorthBoundRequest> northBoundRequestClient;
+
+ private Client<RainyDayHandlerStatus> rainyDayHandlerStatusClient;
+
+ private Client<BuildingBlockDetail> buildingBlockDetailClient;
+
+ private Client<OrchestrationStatusStateTransitionDirective> orchestrationStatusStateTransitionDirectiveClient;
+
+ private Client<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizationClient;
+
+ private Client<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationClient;
+
+ private Client<InstanceGroup> instanceGroupClient;
- protected Client<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationClient;
+ private Client<NetworkCollectionResourceCustomization> networkCollectionResourceCustomizationClient;
+
+ private Client<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationClient;
+
+ private Client<ServiceRecipe> serviceRecipeClient;
@Value("${mso.catalog.db.spring.endpoint}")
protected String endpoint;
@@ -93,6 +106,13 @@
@Value("${mso.db.auth}")
private String msoAdaptersAuth;
+ @PostConstruct
+ public void init(){
+ findFirstByModelNameURI = endpoint + SERVICE_SEARCH + findFirstByModelNameURI;
+ findByModelVersionAndModelInvariantUUIDURI = endpoint + SERVICE_SEARCH + findByModelVersionAndModelInvariantUUIDURI;
+ findFirstByServiceModelUUIDAndActionURI = endpoint + SERVICE_RECIPE_SEARCH + findFirstByServiceModelUUIDAndActionURI;
+ }
+
public CatalogDbClient() {
ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
@@ -126,6 +146,7 @@
instanceGroupClient = clientFactory.create(InstanceGroup.class);
networkCollectionResourceCustomizationClient = clientFactory.create(NetworkCollectionResourceCustomization.class);
collectionNetworkResourceCustomizationClient = clientFactory.create(CollectionNetworkResourceCustomization.class);
+ serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
}
public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID(String modelCustomizationUUID) {
@@ -198,7 +219,7 @@
return this.getMultipleOrchestrationFlows(UriBuilder.fromUri(endpoint + "/orchestrationFlow/").build());
}
- protected List<OrchestrationFlow> getMultipleOrchestrationFlows(URI uri) {
+ private List<OrchestrationFlow> getMultipleOrchestrationFlows(URI uri) {
Iterable<OrchestrationFlow> orchIterator = orchestrationClient.getAll(uri);
List<OrchestrationFlow> orchList = new ArrayList<>();
Iterator<OrchestrationFlow> it = orchIterator.iterator();
@@ -229,7 +250,7 @@
return collectionInstanceGroupCustList;
}
- protected List<VnfcInstanceGroupCustomization> getMultipleVnfcInstanceGroupCustomizations(URI uri) {
+ private List<VnfcInstanceGroupCustomization> getMultipleVnfcInstanceGroupCustomizations(URI uri) {
Iterable<VnfcInstanceGroupCustomization> vnfcIterator = vnfcInstanceGroupCustomizationClient.getAll(uri);
List<VnfcInstanceGroupCustomization> vnfcList = new ArrayList<>();
Iterator<VnfcInstanceGroupCustomization> it = vnfcIterator.iterator();
@@ -264,35 +285,53 @@
.build());
}
- protected CollectionNetworkResourceCustomization getSingleCollectionNetworkResourceCustomization(URI uri) {
+ public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action){
+ return this.getSingleServiceRecipe(UriBuilder.fromUri(findFirstByServiceModelUUIDAndActionURI)
+ .queryParam(SERVICE_MODEL_UUID,modelUUID)
+ .queryParam(ACTION,action)
+ .build());
+ }
+
+ public Service getFirstByModelNameOrderByModelVersionDesc(String modelName){
+ return this.getSingleService(UriBuilder.fromUri(findFirstByModelNameURI)
+ .queryParam(MODEL_NAME,modelName)
+ .build());
+ }
+
+
+ private CollectionNetworkResourceCustomization getSingleCollectionNetworkResourceCustomization(URI uri) {
return collectionNetworkResourceCustomizationClient.get(uri);
}
- protected InstanceGroup getSingleInstanceGroup(URI uri) {
+ private InstanceGroup getSingleInstanceGroup(URI uri) {
return instanceGroupClient.get(uri);
}
- protected Service getSingleService(URI uri) {
+ private Service getSingleService(URI uri) {
return serviceClient.get(uri);
}
- protected VfModuleCustomization getSingleVfModuleCustomization(URI uri) {
+ private VfModuleCustomization getSingleVfModuleCustomization(URI uri) {
return vfModuleCustomizationClient.get(uri);
}
- protected NorthBoundRequest getSingleNorthBoundRequest(URI uri) {
+ private NorthBoundRequest getSingleNorthBoundRequest(URI uri) {
return northBoundRequestClient.get(uri);
}
- protected RainyDayHandlerStatus getSingleRainyDayHandlerStatus(URI uri) {
+ private RainyDayHandlerStatus getSingleRainyDayHandlerStatus(URI uri) {
return rainyDayHandlerStatusClient.get(uri);
}
+
+ private ServiceRecipe getSingleServiceRecipe(URI uri){
+ return serviceRecipeClient.get(uri);
+ }
public Service getServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
return this.getSingleService(
- UriBuilder.fromUri(endpoint + "/service/search/findByModelVersionAndModelInvariantUUID")
- .queryParam("MODEL_VERSION", modelVersion)
- .queryParam("MODEL_INVARIANT_UUID", modelInvariantUUID).build());
+ UriBuilder.fromUri(findByModelVersionAndModelInvariantUUIDURI)
+ .queryParam(MODEL_VERSION, modelVersion)
+ .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build());
}
//USED FOR TEST ONLY
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java
index 57578cf..cd46846 100644
--- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java
+++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRecipeRepository.java
@@ -22,6 +22,7 @@
import org.onap.so.db.catalog.beans.ServiceRecipe;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource(collectionResourceRel = "serviceRecipe", path = "serviceRecipe")
@@ -30,5 +31,5 @@
public ServiceRecipe findByAction(String action);
- public ServiceRecipe findFirstByServiceModelUUIDAndAction(String serviceModelUUID, String action);
+ public ServiceRecipe findFirstByServiceModelUUIDAndAction(@Param("SERVICE_MODEL_UUID") String serviceModelUUID, @Param("ACTION") String action);
}
\ No newline at end of file
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRepository.java
index eac432a..25b1757 100644
--- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRepository.java
+++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceRepository.java
@@ -41,7 +41,7 @@
* @return
*/
@Query(value = "SELECT * FROM service WHERE MODEL_NAME = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
- Service findFirstByModelNameOrderByModelVersionDesc(String modelName);
+ Service findFirstByModelNameOrderByModelVersionDesc(@Param("MODEL_NAME") String modelName);
/**
* This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
@@ -59,7 +59,7 @@
/**
* This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
- * @param modelName
+ * @param modelUUID
* @return
*/
@Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
@@ -67,7 +67,7 @@
/**
* This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
- * @param modelName
+ * @param modelUUID
* @return
*/
@Query(value = "SELECT * FROM service WHERE MODEL_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)
@@ -78,7 +78,7 @@
/**
* This method will not work for versions greater than 255, as it is utilizing an ip address function to do the sorting
- * @param modelName
+ * @param modelInvariantUUID
* @return
*/
@Query(value = "SELECT * FROM service WHERE MODEL_INVARIANT_UUID = ?1 ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(MODEL_VERSION,'.0.0.0'),'.',4)) DESC LIMIT 1;", nativeQuery = true)