summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java14
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java100
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/DeleteVfModuleNoModelInvariantId.json23
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/TestBadResponse.json7
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/UnauthorizedResponse.json7
-rw-r--r--mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java56
6 files changed, 176 insertions, 31 deletions
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 60b07fdeab..5d9ad767bf 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
@@ -663,14 +663,14 @@ public class ServiceInstances {
// Get VF Module-specific base module indicator
- VfModule vfm;
+ VfModule vfm = null;
String modelVersionId = modelInfo.getModelVersionId();
if(modelVersionId != null) {
vfm = catalogDbClient.getVfModuleByModelUUID(modelVersionId);
- } else {
- vfm = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(modelInfo.getModelInvariantId(), modelInfo.getModelVersion());
+ } else if(modelInfo.getModelInvariantId() != null && modelInfo.getModelVersion() != null){
+ vfm = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(modelInfo.getModelInvariantId(), modelInfo.getModelVersion());
}
if (vfm != null) {
@@ -831,9 +831,8 @@ public class ServiceInstances {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
ValidateException validateException = new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
.errorInfo(errorLoggerInfo).build();
- currentActiveReq.setRequestStatus(Status.FAILED.name());
- currentActiveReq.setStatusMessage(validateException.getMessage());
- throw validateException;
+ updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
+ throw validateException;
}
// BPEL accepted the request, the request is in progress
@@ -850,8 +849,7 @@ public class ServiceInstances {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
ValidateException validateException = new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_NOT_ACCEPTABLE, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
.errorInfo(errorLoggerInfo).build();
- currentActiveReq.setRequestStatus(Status.FAILED.name());
- currentActiveReq.setStatusMessage(validateException.getMessage());
+ updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
throw validateException;
}
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 e4ec850c4e..cdb4c40981 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
@@ -1392,6 +1392,33 @@ public class ServiceInstancesTest extends BaseTest{
assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
}
@Test
+ public void deleteVfModuleNoModelInvariantId() throws IOException {
+ stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" +
+ "[?]vfModuleModelUUID=VNF-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json"))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ //expected response
+ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
+ RequestReferences requestReferences = new RequestReferences();
+ requestReferences.setInstanceId("1882939");
+ expectedResponse.setRequestReferences(requestReferences);
+ uri = servInstanceuri + "v7" + "/serviceInstances/196b4a84-0858-4317-a1f6-497e2e52ae43/vnfs/36e4f902-ec32-451e-8d53-e3edc19e40a4/vfModules/09f3a38d-933f-450a-8784-9e6c4dec3f72";
+ ResponseEntity<String> response = sendRequest(inputStream("/DeleteVfModuleNoModelInvariantId.json"), uri, HttpMethod.DELETE);
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
+ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
+ }
+ @Test
public void deactivateAndCloudDeleteVfModuleInstance() throws IOException {
stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
.willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
@@ -1980,6 +2007,43 @@ public class ServiceInstancesTest extends BaseTest{
RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
assertEquals("Request Failed due to BPEL error with HTTP Status = 202{\"instanceId\": \"1882939\"}", realResponse.getServiceException().getText());
}
+ @Test
+ public void unauthorizedBPELResponse() throws IOException{
+
+ ServiceRecipe serviceRecipe = new ServiceRecipe();
+ serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
+ serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
+ serviceRecipe.setAction(Action.createInstance.toString());
+ serviceRecipe.setId(1);
+ serviceRecipe.setRecipeTimeout(180);
+ Service defaultService = new Service();
+ defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
+
+ stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBodyFile("Camunda/UnauthorizedResponse.json").withStatus(org.apache.http.HttpStatus.SC_UNAUTHORIZED)));
+
+ stubFor(get(urlMatching(".*/service/.*"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(defaultService))
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceRecipe))
+ .withStatus(HttpStatus.SC_OK)));
+
+ uri = servInstanceuri + "v5/serviceInstances";
+ ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
+
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
+ RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
+ assertEquals("Exception caught mapping Camunda JSON response to object", realResponse.getServiceException().getText());
+ }
@Test
public void invalidBPELResponse2() throws IOException{
@@ -2145,4 +2209,40 @@ public class ServiceInstancesTest extends BaseTest{
assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
assertTrue(response.getBody().contains("1882939"));
}
+ @Test
+ public void createServiceInstanceBadResponse() throws IOException{
+ ServiceRecipe serviceRecipe = new ServiceRecipe();
+ serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB");
+ serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
+ serviceRecipe.setAction(Action.createInstance.toString());
+ serviceRecipe.setId(1);
+ serviceRecipe.setRecipeTimeout(180);
+ Service defaultService = new Service();
+ defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
+
+ stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBodyFile("Camunda/TestBadResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ stubFor(get(urlMatching(".*/service/.*"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(defaultService))
+ .withStatus(HttpStatus.SC_OK)));
+
+ stubFor(get(urlMatching(".*/serviceRecipe/search.*"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceRecipe))
+ .withStatus(HttpStatus.SC_OK)));
+
+ uri = servInstanceuri + "v5/serviceInstances";
+ ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST);
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
+
+ assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode().value());
+ RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class);
+ assertEquals("Exception caught mapping Camunda JSON response to object", realResponse.getServiceException().getText());
+ }
} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/DeleteVfModuleNoModelInvariantId.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/DeleteVfModuleNoModelInvariantId.json
new file mode 100644
index 0000000000..64c60b871e
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/DeleteVfModuleNoModelInvariantId.json
@@ -0,0 +1,23 @@
+{
+ "requestDetails":{
+ "modelInfo":{
+ "modelType":"vfModule",
+ "modelName":"InframsoVsamp1214..vSAMP12_base..module-0"
+ },
+ "cloudConfiguration":{
+ "lcpCloudRegionId":"mtn6",
+ "tenantId":"0422ffb57ba042c0800a29dc85ca70f8"
+ },
+ "requestInfo":{
+ "instanceName":"bdb-vSAMP12_14_1.0-VF-Base-1810-est01-VNF_API-10201",
+ "source":"VID",
+ "requestorId":"xxxxxx"
+ },
+ "requestParameters":{
+ "testApi":"VNF_API",
+ "userParams":[
+
+ ]
+ }
+ }
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/TestBadResponse.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/TestBadResponse.json
new file mode 100644
index 0000000000..231bb679f9
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/TestBadResponse.json
@@ -0,0 +1,7 @@
+{
+ "response": "{\"test\"}}",
+ "messageCode": "1",
+ "message": "Success",
+ "processInstanceID": "1",
+ "variables": "null"
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/UnauthorizedResponse.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/UnauthorizedResponse.json
new file mode 100644
index 0000000000..d6273bbcfd
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/UnauthorizedResponse.json
@@ -0,0 +1,7 @@
+{
+ "timestamp": 1533899092159,
+ "status": 401,
+ "error": "Unauthorized",
+ "message": "Bad credentials",
+ "path": "/onap/so/infra/serviceInstances/v7"
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
index 5eb2addc0a..6ab92853d1 100644
--- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
+++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
@@ -82,10 +82,6 @@ public class RequestsDbClient {
private static final String VALUE = "VALUE";
private static final String TAG = "TAG";
- private Client<InfraActiveRequests> infraActiveRequestClient;
- private Client<RequestProcessingData> requestProcessingDataClient;
- private final Client<OperationalEnvDistributionStatus> distributionStatusClient;
- private final Client<OperationalEnvServiceModelStatus> serviceModelStatusClient;
@Value("${mso.adapters.requestDb.endpoint}")
protected String endpoint;
@@ -140,11 +136,12 @@ public class RequestsDbClient {
findOneByOperationalEnvIdAndServiceModelVersionIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findOneByOperationalEnvIdAndServiceModelVersionIdURI;
findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI;
}
-
- public RequestsDbClient() {
+
+ public ClientFactory getClientFactory(){
+ URI baseUri = UriBuilder.fromUri(endpoint).build();
ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
- ClientFactory clientFactory = Configuration.builder().setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> {
+ return Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> {
restTemplate.getInterceptors().add((new SpringClientFilter()));
restTemplate.getInterceptors().add((request, body, execution) -> {
@@ -153,11 +150,8 @@ public class RequestsDbClient {
return execution.execute(request, body);
});
}).build().buildClientFactory();
- infraActiveRequestClient = clientFactory.create(InfraActiveRequests.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);
@@ -176,7 +170,10 @@ public class RequestsDbClient {
public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) {
try {
- InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody();
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Authorization", msoAdaptersAuth);
+ HttpEntity<?> entity = new HttpEntity<>(headers);
+ InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, entity, InfraActiveRequests.class).getBody();
if (infraActiveRequests != null) {
infraActiveRequests.setRequestId(requestId);
}
@@ -198,9 +195,13 @@ public class RequestsDbClient {
}
public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Authorization", msoAdaptersAuth);
+ HttpEntity<?> entity = new HttpEntity<>(headers);
URI uri = getUri(checkVnfIdStatus + operationalEnvironmentId);
- return restTemplate.exchange(uri, HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody();
+ return restTemplate.exchange(uri, HttpMethod.GET, entity, InfraActiveRequests.class).getBody();
}
+
public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, String requestScope) {
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", msoAdaptersAuth);
@@ -219,10 +220,13 @@ public class RequestsDbClient {
public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId) {
try {
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Authorization", msoAdaptersAuth);
+ HttpEntity<?> entity = new HttpEntity<>(headers);
OperationStatus operationStatus = restTemplate.exchange(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI))
.queryParam(SERVICE_ID, serviceId)
.queryParam(OPERATION_ID, operationId)
- .build(), HttpMethod.GET, HttpEntity.EMPTY, OperationStatus.class).getBody();
+ .build(), HttpMethod.GET, entity, OperationStatus.class).getBody();
if (operationStatus != null) {
operationStatus.setServiceId(serviceId);
operationStatus.setOperationId(operationId);
@@ -256,11 +260,11 @@ public class RequestsDbClient {
}
private OperationalEnvServiceModelStatus getSingleOperationalEnvServiceModelStatus(URI uri){
- return serviceModelStatusClient.get(uri);
+ return getClientFactory().create(OperationalEnvServiceModelStatus.class).get(uri);
}
private List<OperationalEnvServiceModelStatus> getMultipleOperationalEnvServiceModelStatus(URI uri){
- Iterable <OperationalEnvServiceModelStatus> iterable = serviceModelStatusClient.getAll(uri);
+ Iterable <OperationalEnvServiceModelStatus> iterable = getClientFactory().create(OperationalEnvServiceModelStatus.class).getAll(uri);
List<OperationalEnvServiceModelStatus> serviceModelStatuses = new ArrayList<>();
Iterator<OperationalEnvServiceModelStatus> statusIterator = iterable.iterator();
statusIterator.forEachRemaining(serviceModelStatuses::add);
@@ -284,11 +288,17 @@ public class RequestsDbClient {
}
private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){
- return distributionStatusClient.get(uri);
+ return getClientFactory().create(OperationalEnvDistributionStatus.class).get(uri);
}
- public void updateInfraActiveRequests(InfraActiveRequests request) {
- infraActiveRequestClient.put(request);
+ public void updateInfraActiveRequests(InfraActiveRequests request) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Authorization", msoAdaptersAuth);
+ headers.set(HttpHeaders.CONTENT_TYPE,"application/json");
+ headers.set(HttpHeaders.ACCEPT, "application/json");
+ URI uri = getUri(infraActiveRequestURI+request.getRequestId());
+ HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, headers);
+ restTemplate.put(uri, entity);
}
protected URI getUri(String uri) {
@@ -319,11 +329,11 @@ public class RequestsDbClient {
}
public RequestProcessingData getSingleRequestProcessingData(URI uri){
- return requestProcessingDataClient.get(uri);
+ return getClientFactory().create(RequestProcessingData.class).get(uri);
}
private List<RequestProcessingData> getRequestProcessingData(URI uri) {
- Iterable<RequestProcessingData> requestProcessingDataIterator = requestProcessingDataClient.getAll(uri);
+ Iterable<RequestProcessingData> requestProcessingDataIterator = getClientFactory().create(RequestProcessingData.class).getAll(uri);
List<RequestProcessingData> requestProcessingDataList = new ArrayList<>();
Iterator<RequestProcessingData> it = requestProcessingDataIterator.iterator();
it.forEachRemaining(requestProcessingDataList::add);
@@ -335,8 +345,8 @@ public class RequestsDbClient {
return (List<RequestProcessingData>) this.getAllRequestProcessingData(UriBuilder.fromUri(endpoint + "/requestProcessingData").build());
}
- private Iterable<RequestProcessingData> getAllRequestProcessingData(URI uri) {
- return requestProcessingDataClient.getAll(uri);
+ private Iterable<RequestProcessingData> getAllRequestProcessingData(URI uri) {
+ return getClientFactory().create(RequestProcessingData.class).getAll(uri);
}
@Component