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/WorkflowSpecificationsHandler.java29
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java53
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json20
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json41
4 files changed, 136 insertions, 7 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
index 357497591d..0f7cf5fc6a 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
@@ -81,12 +81,13 @@ public class WorkflowSpecificationsHandler {
@Transactional
public Response queryWorkflowSpecifications(@QueryParam("vnfModelVersionId") String vnfModelVersionId,
- @QueryParam("pnfModelVersionId") String pnfModelVersionId, @PathParam("version") String version)
+ @QueryParam("pnfModelVersionId") String pnfModelVersionId,
+ @QueryParam("resourceTarget") String resourceTarget, @PathParam("version") String version)
throws Exception {
String apiVersion = version.substring(1);
List<Workflow> workflows = new ArrayList<>();
- if (vnfModelVersionId == null && pnfModelVersionId == null) {
+ if (vnfModelVersionId == null && pnfModelVersionId == null && resourceTarget == null) {
workflows.addAll(queryWorkflowSpecificationsForAll());
} else {
// 1. query workflow specifications for given vnfModelVersionId if need.
@@ -106,6 +107,16 @@ public class WorkflowSpecificationsHandler {
workflows.addAll(pnfWorkflows);
}
}
+
+ // 3. query workflow specifications for given resourceTarget
+ if (resourceTarget != null) {
+ List<Workflow> workflowsForResourceTarget = queryWorkflowsForResourceTarget(resourceTarget);
+ logger.debug(
+ "Retrieved " + workflowsForResourceTarget.size() + " workflows for given resource target.");
+ if (workflowsForResourceTarget.size() > 0) {
+ workflows.addAll(workflowsForResourceTarget);
+ }
+ }
}
// Deduplication
@@ -119,11 +130,16 @@ public class WorkflowSpecificationsHandler {
apiVersion);
}
+ /**
+ * @deprecated As of G release, workflows for all resource types (pnf,vnf,service) can be fetched using
+ * /workflowSpecifications/{version:[vV]1}/workflows?resourceTarget={resourceType} API
+ */
@Path("/{version:[vV]1}/pnfWorkflows")
@GET
@Operation(description = "Finds pnf workflow specifications", responses = @ApiResponse(
content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
+ @Deprecated
public Response getWorkflowsSpecForPnf(@PathParam("version") String version) throws Exception {
final String pnf_resource = "pnf";
@@ -132,7 +148,7 @@ public class WorkflowSpecificationsHandler {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- List<Workflow> workflows = catalogDbClient.findWorkflowByResourceTarget(pnf_resource);
+ List<Workflow> workflows = queryWorkflowsForResourceTarget(pnf_resource);
Optional<String> optional = getResponseByWorkflowSpec(workflows);
return builder.buildResponse(HttpStatus.SC_OK, "", optional.isPresent() ? optional.get() : EMPTY_BODY,
@@ -296,4 +312,11 @@ public class WorkflowSpecificationsHandler {
List<Workflow> workflows = catalogDbClient.findWorkflowByPnfModelUUID(pnfModelVersionId);
return workflows;
}
+
+ private List<Workflow> queryWorkflowsForResourceTarget(String resourceTarget) {
+ List<Workflow> workflows = catalogDbClient.findWorkflowByResourceTarget(resourceTarget);
+ return workflows;
+ }
+
+
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
index 4ab88f40f6..1fa71cefc2 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
@@ -58,6 +58,9 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
@Autowired
WorkflowSpecificationsHandler workflowSpecificationsHandler;
+ @Autowired
+ ObjectMapper mapper;
+
@Value("${wiremock.server.port}")
private String wiremockPort;
@@ -152,7 +155,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
WorkflowSpecifications expectedResponse = mapper.readValue(
@@ -306,7 +308,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
WorkflowSpecifications workflowSpecifications =
workflowSpecificationsHandler.mapWorkflowsToWorkflowSpecifications(workflows);
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String workflowSpecificationsJson = mapper.writeValueAsString(workflowSpecifications);
@@ -349,7 +350,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
WorkflowSpecifications expectedResponse = mapper.readValue(
@@ -367,6 +367,52 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
}
@Test
+ public void queryWorkflowSpecificationsByResourceTarget_Test_Success() throws JSONException, IOException {
+
+ String URL_PATH = basePath + "/v1/workflows";
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Accept", MediaType.APPLICATION_JSON);
+ headers.set("Content-Type", MediaType.APPLICATION_JSON);
+ HttpEntity<String> entity = new HttpEntity<String>(null, headers);
+ String WORKFLOW_QUERY = "/workflow/search/findByResourceTarget[?]resourceTarget=service";
+ String WORKFLOW_SPEC_QUERY = "/workflow/5/workflowActivitySpecSequence";
+ String JSON_FILE_PATH = "src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json";
+ String MOCK_RESP_FILE = "WorkflowSpecificationsForServiceWorkflows_Response.json";
+ String MOCK_RESP_SPEC_FILE = "Empty_workflowActivitySpecSequence_Response.json";
+
+ wireMockServer.stubFor(get(urlMatching(WORKFLOW_QUERY))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_FILE))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ wireMockServer.stubFor(get(urlMatching(WORKFLOW_SPEC_QUERY))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_SPEC_FILE))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ UriComponentsBuilder builder =
+ UriComponentsBuilder.fromHttpUrl(createURLWithPort(URL_PATH)).queryParam("resourceTarget", "service");
+
+ ResponseEntity<String> response =
+ restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ WorkflowSpecifications expectedResponse = mapper
+ .readValue(new String(Files.readAllBytes(Paths.get(JSON_FILE_PATH))), WorkflowSpecifications.class);
+ WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(expectedResponse, sameBeanAs(realResponse));
+ assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
+ assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
+ assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
+ assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
+ }
+
+ @Test
public void testWorkflowSpecificationsForPnf_Success() throws JSONException, IOException {
final String urlPath = basePath + "/v1/pnfWorkflows";
@@ -397,7 +443,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
WorkflowSpecifications expectedResponse = mapper.readValue(
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json
new file mode 100644
index 0000000000..aaaad17470
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json
@@ -0,0 +1,20 @@
+{
+ "workflowSpecificationList": [
+ {
+ "workflowSpecification": {
+ "artifactInfo": {
+ "artifactType": "workflow",
+ "artifactUuid": "a1fe8726-66d5-3e7f-2212-7e5h662e9255",
+ "artifactName": "DummyServiceWorkflow",
+ "artifactVersion": "1.0",
+ "artifactDescription": "Dummy Service Workflow to test custom Service workflow",
+ "workflowName": "Dummy Service Workflow",
+ "operationName": "DummyServiceWorkflow",
+ "workflowSource": "native",
+ "workflowResourceTarget": "service"
+ },
+ "workflowInputParameters": []
+ }
+ }
+ ]
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json
new file mode 100644
index 0000000000..9a836e033b
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json
@@ -0,0 +1,41 @@
+{
+ "_embedded": {
+ "workflow": [
+ {
+ "artifactChecksum": "MANUAL RECORD",
+ "artifactName": "DummyServiceWorkflow",
+ "artifactUUID": "a1fe8726-66d5-3e7f-2212-7e5h662e9255",
+ "body": null,
+ "created": "2020-06-29T08:28:15.000+0000",
+ "description": "Dummy Service Workflow to test custom Service workflow",
+ "id": 4,
+ "name": "Dummy Service Workflow",
+ "operationName": "DummyServiceWorkflow",
+ "pnfResourceWorkflow": null,
+ "resourceTarget": "service",
+ "source": "native",
+ "timeoutMinutes": null,
+ "version": 1.0,
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findByResourceTarget?resourceTarget=service"
+ },
+ "workflow": {
+ "href": "http://localhost:8090/workflow/5"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/5/workflowActivitySpecSequence"
+ }
+ }
+ }
+ ]
+ },
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findByResourceTarget?resourceTarget=service"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/5/workflowActivitySpecSequence"
+ }
+ }
+} \ No newline at end of file