summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src
diff options
context:
space:
mode:
authorYulian Han <elaine.hanyulian@huawei.com>2020-01-02 00:31:28 +0800
committerYulian Han <elaine.hanyulian@huawei.com>2020-01-02 00:31:28 +0800
commitcd30f0cb0f6fe465d13a97e55359bd6bea158f08 (patch)
tree64ee6035397fceb3cb7b14138137d2cfd69e011e /mso-api-handlers/mso-api-handler-infra/src
parent6416fa05f3a54c0a95e9ab41927b74cb8e0e68f8 (diff)
SO API to support custom PNF workflow
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f064418 Issue-ID: SO-2071 Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java109
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java11
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java19
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java8
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java28
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecutePNFCustomWorkflow.json20
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_pnf_Response.json5
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql1
9 files changed, 192 insertions, 12 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java
index d0302f2e59..88c4bc3b04 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java
@@ -45,5 +45,6 @@ public enum Action implements Actions {
scaleOut,
recreateInstance,
addMembers,
- removeMembers
+ removeMembers,
+ forCustomWorkflow
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java
index d3bd769386..dbdc274bc6 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java
@@ -96,7 +96,7 @@ public class InstanceManagement {
@Operation(description = "Execute custom workflow", responses = @ApiResponse(
content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
- public Response executeCustomWorkflow(String request, @PathParam("version") String version,
+ public Response executeVNFCustomWorkflow(String request, @PathParam("version") String version,
@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId,
@PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext)
throws ApiException {
@@ -109,6 +109,26 @@ public class InstanceManagement {
requestContext);
}
+ @POST
+ @Path("/{version:[vV][1]}/serviceInstances/{serviceInstanceId}/pnfs/{pnfId}/workflows/{workflowUuid}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Execute custom workflow", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Transactional
+ public Response executePNFCustomWorkflow(String request, @PathParam("version") String version,
+ @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("pnfId") String pnfId,
+ @PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext)
+ throws ApiException {
+ String requestId = requestHandlerUtils.getRequestId(requestContext);
+ HashMap<String, String> instanceIdMap = new HashMap<>();
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ instanceIdMap.put("pnfId", pnfId);
+ instanceIdMap.put("workflowUuid", workflowUuid);
+ return processPNFCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId,
+ requestContext);
+ }
+
private Response processCustomWorkflowRequest(String requestJSON, Actions action,
HashMap<String, String> instanceIdMap, String version, String requestId,
ContainerRequestContext requestContext) throws ApiException {
@@ -217,6 +237,93 @@ public class InstanceManagement {
recipeLookupResult.getOrchestrationURI(), requestScope);
}
+ private Response processPNFCustomWorkflowRequest(String requestJSON, Actions action,
+ HashMap<String, String> instanceIdMap, String version, String requestId,
+ ContainerRequestContext requestContext) throws ApiException {
+ Boolean aLaCarte = false;
+ ServiceInstancesRequest sir;
+ String apiVersion = version.substring(1);
+
+ String serviceInstanceId = "";
+ String pnfId = "";
+ String workflowUuid = "";
+ if (instanceIdMap != null) {
+ serviceInstanceId = instanceIdMap.get("serviceInstanceId");
+ pnfId = instanceIdMap.get("pnfId");
+ workflowUuid = instanceIdMap.get("workflowUuid");
+ }
+
+ String requestUri = requestHandlerUtils.getRequestUri(requestContext, uriPrefix);
+ sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
+ sir.setServiceInstanceId(serviceInstanceId);
+ sir.setPnfId(pnfId);
+ String requestScope = ModelType.pnf.name();
+ InfraActiveRequests currentActiveReq =
+ msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
+
+ try {
+ requestHandlerUtils.validateHeaders(requestContext);
+ } catch (ValidationException e) {
+ logger.error("Exception occurred", e);
+ ErrorLoggerInfo errorLoggerInfo =
+ new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError)
+ .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
+ ValidateException validateException =
+ new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST,
+ ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
+ requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
+ throw validateException;
+ }
+
+ requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId,
+ currentActiveReq);
+ requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
+
+ InfraActiveRequests dup = null;
+ boolean inProgress = false;
+
+ dup = requestHandlerUtils.duplicateCheck(action, instanceIdMap, null, requestScope, currentActiveReq);
+
+ if (dup != null) {
+ inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq);
+ }
+
+ if (dup != null && inProgress) {
+ requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, null, requestScope,
+ dup);
+ }
+
+ RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid);
+
+ try {
+ infraActiveRequestsClient.save(currentActiveReq);
+ } catch (Exception e) {
+ ErrorLoggerInfo errorLoggerInfo =
+ new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError)
+ .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
+ throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
+ }
+
+ RequestClientParameter requestClientParameter = null;
+ try {
+ requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId)
+ .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString())
+ .setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfId)
+ .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action))
+ .setApiVersion(apiVersion).setRequestUri(requestUri).build();
+ } catch (IOException e) {
+ ErrorLoggerInfo errorLoggerInfo =
+ new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError)
+ .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
+ throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(),
+ HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo)
+ .build();
+ }
+ return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter,
+ recipeLookupResult.getOrchestrationURI(), requestScope);
+ }
+
private RecipeLookupResult getInstanceManagementWorkflowRecipe(InfraActiveRequests currentActiveReq,
String workflowUuid) throws ApiException {
RecipeLookupResult recipeLookupResult = null;
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 2307a18c1a..0e9ed78eac 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
@@ -318,9 +318,16 @@ public class MsoRequest {
aq.setVnfId(servInsReq.getVnfInstanceId());
}
+ if (servInsReq.getPnfId() != null) {
+ aq.setRequestScope(requestScope);
+ aq.setPnfId(servInsReq.getPnfId());
+ }
+
if (ModelType.service.name().equalsIgnoreCase(requestScope)) {
- if (servInsReq.getRequestDetails().getRequestInfo().getInstanceName() != null) {
- aq.setServiceInstanceName(requestInfo.getInstanceName());
+ if (servInsReq.getRequestDetails().getRequestInfo() != null) {
+ if (servInsReq.getRequestDetails().getRequestInfo().getInstanceName() != null) {
+ aq.setServiceInstanceName(requestInfo.getInstanceName());
+ }
}
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java
index b078aed6ac..a7c03f9070 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java
@@ -275,12 +275,18 @@ public class RequestHandlerUtils extends AbstractRestHandler {
} else if (action == Action.addMembers || action == Action.removeMembers) {
return (ModelType.instanceGroup.toString());
} else {
- String requestScope;
+ String requestScope = requestScopeFromUri(requestUri);;
+
+ if (sir.getRequestDetails() == null) {
+ return requestScope;
+ }
+ if (sir.getRequestDetails().getModelInfo() == null) {
+ return requestScope;
+ }
if (sir.getRequestDetails().getModelInfo().getModelType() == null) {
- requestScope = requestScopeFromUri(requestUri);
- } else {
- requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
+ return requestScope;
}
+ requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
return requestScope;
}
}
@@ -505,6 +511,9 @@ public class RequestHandlerUtils extends AbstractRestHandler {
if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
currentActiveReq.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
}
+ if (instanceIdMap.get("PnfId") != null) {
+ currentActiveReq.setPnfId(instanceIdMap.get("PnfId"));
+ }
}
}
@@ -610,6 +619,8 @@ public class RequestHandlerUtils extends AbstractRestHandler {
requestScope = ModelType.configuration.name();
} else if (requestUri.contains(ModelType.vnf.name())) {
requestScope = ModelType.vnf.name();
+ } else if (requestUri.contains(ModelType.pnf.name())) {
+ requestScope = ModelType.pnf.name();
} else {
requestScope = ModelType.service.name();
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java
index 01e3de99ec..c05ef98fbb 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java
@@ -35,13 +35,13 @@ public class CustomWorkflowValidation implements ValidationRule {
CloudConfiguration cloudConfiguration = info.getSir().getRequestDetails().getCloudConfiguration();
if (cloudConfiguration == null) {
- throw new ValidationException("cloudConfiguration");
+ // throw new ValidationException("cloudConfiguration");
} else if (Strings.isNullOrEmpty((cloudConfiguration.getCloudOwner()))) {
- throw new ValidationException("cloudOwner");
+ // throw new ValidationException("cloudOwner");
} else if (Strings.isNullOrEmpty((cloudConfiguration.getLcpCloudRegionId()))) {
- throw new ValidationException("lcpCloudRegionId");
+ // throw new ValidationException("lcpCloudRegionId");
} else if (Strings.isNullOrEmpty((cloudConfiguration.getTenantId()))) {
- throw new ValidationException("tenantId");
+ // throw new ValidationException("tenantId");
}
if (requestParameters == null) {
throw new ValidationException("requestParameters");
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java
index 276f891eb2..8876f4ef21 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java
@@ -172,4 +172,32 @@ public class InstanceManagementTest extends BaseTest {
ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
}
+
+ @Test
+ public void executePNFCustomWorkflow() throws IOException {
+ wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/testingPNFWorkflow"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ wireMockServer.stubFor(get(urlMatching(
+ ".*/workflow/search/findByArtifactUUID[?]artifactUUID=81526781-e55c-4cb7-adb3-97e09d9c76bf"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb("workflow_pnf_Response.json"))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ // expected response
+ ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse();
+ RequestReferences requestReferences = new RequestReferences();
+ requestReferences.setInstanceId("1882939");
+ requestReferences.setRequestSelfLink(createExpectedSelfLink("v1", "32807a28-1a14-4b88-b7b3-2950918aa76d"));
+ expectedResponse.setRequestReferences(requestReferences);
+ uri = instanceManagementUri + "v1"
+ + "/serviceInstances/5df8b6de-2083-11e7-93ae-92361f002676/pnfs/testpnfcId/workflows/81526781-e55c-4cb7-adb3-97e09d9c76bf";
+ ResponseEntity<String> response =
+ sendRequest(inputStream("/ExecutePNFCustomWorkflow.json"), uri, HttpMethod.POST, headers);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class);
+ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId"));
+ }
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecutePNFCustomWorkflow.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecutePNFCustomWorkflow.json
new file mode 100644
index 0000000000..63021b611f
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecutePNFCustomWorkflow.json
@@ -0,0 +1,20 @@
+{
+ "requestDetails": {
+ "requestParameters": {
+ "userParams": [{
+ "nrmObj": {
+ "EUtranGenericCell" : [
+ {"cellLocalId":1, "pci":5},
+ {"cellLocalId":2, "pci":6}
+ ],
+ "ExternalEUtranCell" : [
+ {"cellLocalId":3, "eNBId": "x"},
+ {"cellLocalId":4, "eNBId": "y"}
+ ],
+ "EUtranRelation": [{"scellLocalId":5, "tcellLocalId":6}]
+ }
+ }],
+ "payload": "[{\"GNBDUFunction\":{\"gNBId\":1,\"gNBDUId\":5}}]"
+ }
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_pnf_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_pnf_Response.json
new file mode 100644
index 0000000000..133d8bed9b
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_pnf_Response.json
@@ -0,0 +1,5 @@
+{
+ "artifactUUID": "81526781-e55c-4cb7-adb3-97e09d9c76bf",
+ "artifactName": "testingPNFWorkflow.bpmn",
+ "name": "testingPNFWorkflow"
+} \ 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 55db69b9d2..050780c9a2 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
@@ -1262,6 +1262,7 @@ CREATE TABLE `infra_active_requests` (
`END_TIME` datetime DEFAULT NULL,
`SOURCE` varchar(45) DEFAULT NULL,
`VNF_ID` varchar(45) DEFAULT NULL,
+ `PNF_ID` varchar(45) DEFAULT NULL,
`VNF_NAME` varchar(80) DEFAULT NULL,
`VNF_TYPE` varchar(200) DEFAULT NULL,
`SERVICE_TYPE` varchar(45) DEFAULT NULL,