aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java18
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java4
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java119
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java4
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java13
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecutePNFCustomWorkflow.json63
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql2
8 files changed, 183 insertions, 43 deletions
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 028abd6d25..88028d32a1 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
@@ -95,7 +95,7 @@ public class InstanceManagement {
@Path("/{version:[vV][1]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/workflows/{workflowUuid}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Execute custom workflow", responses = @ApiResponse(
+ @Operation(description = "Execute custom VNF workflow", responses = @ApiResponse(
content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response executeVNFCustomWorkflow(String request, @PathParam("version") String version,
@@ -112,20 +112,20 @@ public class InstanceManagement {
}
@POST
- @Path("/{version:[vV][1]}/serviceInstances/{serviceInstanceId}/pnfs/{pnfId}/workflows/{workflowUuid}")
+ @Path("/{version:[vV][1]}/serviceInstances/{serviceInstanceId}/pnfs/{pnfName}/workflows/{workflowUuid}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- @Operation(description = "Execute custom workflow", responses = @ApiResponse(
+ @Operation(description = "Execute custom PNF 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("serviceInstanceId") String serviceInstanceId, @PathParam("pnfName") String pnfName,
@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("pnfName", pnfName);
instanceIdMap.put("workflowUuid", workflowUuid);
return processPNFCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId,
requestContext);
@@ -255,18 +255,18 @@ public class InstanceManagement {
String apiVersion = version.substring(1);
String serviceInstanceId = "";
- String pnfId = "";
+ String pnfName = "";
String workflowUuid = "";
if (instanceIdMap != null) {
serviceInstanceId = instanceIdMap.get("serviceInstanceId");
- pnfId = instanceIdMap.get("pnfId");
+ pnfName = instanceIdMap.get("pnfName");
workflowUuid = instanceIdMap.get("workflowUuid");
}
String requestUri = requestHandlerUtils.getRequestUri(requestContext, uriPrefix);
sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
sir.setServiceInstanceId(serviceInstanceId);
- sir.setPnfId(pnfId);
+ sir.setPnfName(pnfName);
String requestScope = ModelType.pnf.name();
InfraActiveRequests currentActiveReq =
msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
@@ -299,7 +299,7 @@ public class InstanceManagement {
try {
requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId)
.setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString())
- .setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfId)
+ .setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfName)
.setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action))
.setApiVersion(apiVersion).setRequestUri(requestUri).build();
} catch (IOException e) {
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 5c81f4e6a5..31e026b332 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
@@ -311,9 +311,9 @@ public class MsoRequest {
aq.setVnfId(servInsReq.getVnfInstanceId());
}
- if (servInsReq.getPnfId() != null) {
+ if (servInsReq.getPnfName() != null) {
aq.setRequestScope(requestScope);
- aq.setPnfId(servInsReq.getPnfId());
+ aq.setPnfName(servInsReq.getPnfName());
}
if (ModelType.service.name().equalsIgnoreCase(requestScope)) {
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java
new file mode 100644
index 0000000000..7961cb0886
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.apihandlerinfra;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import org.apache.http.HttpStatus;
+import org.json.JSONObject;
+import org.onap.so.apihandler.common.ErrorNumbers;
+import org.onap.so.apihandler.common.ResponseBuilder;
+import org.onap.so.apihandlerinfra.exceptions.ApiException;
+import org.onap.so.db.request.beans.OrchestrationTask;
+import org.onap.so.db.request.client.RequestsDbClient;
+import org.onap.so.logger.ErrorCode;
+import org.onap.so.logger.LoggingAnchor;
+import org.onap.so.logger.MessageEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import javax.transaction.Transactional;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import static org.onap.so.apihandlerinfra.Constants.MSO_PROP_APIHANDLER_INFRA;
+
+@Path("/onap/so/infra/orchestrationTasks")
+@OpenAPIDefinition(
+ info = @Info(title = "onap/so/infra/orchestrationTasks", description = "API Requests for Orchestration Task"))
+@Component
+public class OrchestrationTasks {
+
+ private static Logger logger = LoggerFactory.getLogger(OrchestrationTasks.class);
+
+ @Autowired
+ private MsoRequest msoRequest;
+
+ @Autowired
+ private CamundaRequestHandler camundaRequestHandler;
+
+ @Autowired
+ private RequestsDbClient requestsDbClient;
+
+ @Autowired
+ private ResponseBuilder builder;
+
+ private ObjectMapper mapper = new ObjectMapper();
+
+ @GET
+ @Path("/{version:[vV][4-7]}/")
+ @Operation(description = "Find All Orchestrated Task", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Produces(MediaType.APPLICATION_JSON)
+ @Transactional
+ public Response getAllOrchestrationTasks(@QueryParam("status") String status,
+ @PathParam("version") String version) {
+ List<OrchestrationTask> orchestrationTaskList = requestsDbClient.getAllOrchestrationTasks();
+ if (status != null && !status.isEmpty()) {
+ for (Iterator<OrchestrationTask> it = orchestrationTaskList.iterator(); it.hasNext();) {
+ OrchestrationTask task = it.next();
+ if (!status.equals(task.getStatus())) {
+ it.remove();
+ }
+ }
+ }
+ return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTaskList, version);
+ }
+
+ @GET
+ @Path("/{version:[vV][4-7]}/{taskId}")
+ @Operation(description = "Find Orchestrated Task for a given TaskId", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Produces(MediaType.APPLICATION_JSON)
+ @Transactional
+ public Response getOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version)
+ throws ApiException {
+ try {
+ OrchestrationTask orchestrationTask = requestsDbClient.getOrchestrationTask(taskId);
+ return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTask, version);
+ } catch (Exception e) {
+ logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA,
+ ErrorCode.AvailabilityError.getValue(),
+ "Exception while communciate with Request DB - Orchestration Task Lookup", e);
+ Response response =
+ msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException,
+ e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version);
+ return response;
+ }
+ }
+
+}
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 75b7e74d49..38fb1596d0 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
@@ -506,8 +506,8 @@ 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"));
+ if (instanceIdMap.get("pnfName") != null) {
+ currentActiveReq.setPnfName(instanceIdMap.get("pnfName"));
}
}
}
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 c05ef98fbb..01c7fd33f9 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
@@ -29,20 +29,13 @@ import com.google.common.base.Strings;
public class CustomWorkflowValidation implements ValidationRule {
+ /**
+ * This function should be generic both for custom VNF workflow and PNF workflow
+ */
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
RequestParameters requestParameters = info.getSir().getRequestDetails().getRequestParameters();
- CloudConfiguration cloudConfiguration = info.getSir().getRequestDetails().getCloudConfiguration();
- if (cloudConfiguration == null) {
- // throw new ValidationException("cloudConfiguration");
- } else if (Strings.isNullOrEmpty((cloudConfiguration.getCloudOwner()))) {
- // throw new ValidationException("cloudOwner");
- } else if (Strings.isNullOrEmpty((cloudConfiguration.getLcpCloudRegionId()))) {
- // throw new ValidationException("lcpCloudRegionId");
- } else if (Strings.isNullOrEmpty((cloudConfiguration.getTenantId()))) {
- // 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 5c78af3601..ba7fe2b9cb 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
@@ -192,11 +192,12 @@ public class InstanceManagementTest extends BaseTest {
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";
+ + "/serviceInstances/5df8b6de-2083-11e7-93ae-92361f002676/pnfs/testPnfName/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
index 63021b611f..09f94b61a4 100644
--- 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
@@ -1,20 +1,47 @@
{
- "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}}]"
- }
- }
+ "requestDetails":{
+ "subscriberInfo":{
+ "globalSubscriberId":"Test"
+ },
+ "requestInfo":{
+ "suppressRollback": false,
+ "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
+ "requestorId": "tester",
+ "instanceName":"testInstanceName",
+ "source":"test"
+ },
+ "cloudConfiguration":{
+ "lcpCloudRegionId": "RegionOne",
+ "tenantId": "7320ec4a5b9d4589ba7c4412ccfd290f",
+ "cloudOwner": "CloudOwner"
+ },
+ "requestParameters":{
+ "subscriptionServiceType": "test",
+ "userParams":[
+ {
+ "name": "key1",
+ "value": "val1"
+ },
+ {
+ "name": "key2",
+ "value": "val2"
+ }],
+ "aLaCarte": false,
+ "payload": "{\"k1\": \"v1\"}"
+ },
+ "project":{
+ "projectName": "Test"
+ },
+ "owningEntity":{
+ "owningEntityId":"67f2e84c-734d-4e90-a1e4-d2ffa2e75849",
+ "owningEntityName":"OE-Test"
+ },
+ "modelInfo":{
+ "modelVersion": "2.0",
+ "modelVersionId": "test-version-id",
+ "modelInvariantId": "test-invariantUUID",
+ "modelName": "test-name",
+ "modelType": "pnf"
+ }
+ }
}
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 050780c9a2..1a1e9bec79 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,7 +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,
+ `PNF_NAME` varchar(45) DEFAULT NULL,
`VNF_NAME` varchar(80) DEFAULT NULL,
`VNF_TYPE` varchar(200) DEFAULT NULL,
`SERVICE_TYPE` varchar(45) DEFAULT NULL,