summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaoguang Wang <sunshine.wang@huawei.com>2020-02-13 17:41:38 +0800
committerYaoguang Wang <sunshine.wang@huawei.com>2020-02-18 16:17:19 +0800
commitbba9db24305b78214fd9f415d2ab4d7455ee762c (patch)
tree6b2ef53a794c54dc84029c3b9e2a44aa4b7ec636
parentc3c1ffae16d32747dc380a8311d3829d0e0cbd35 (diff)
extend query parameter to support pnfModelVersionId
Issue-ID: SO-2559 Signed-off-by: Yaoguang Wang <sunshine.wang@huawei.com> Change-Id: I51cb15f6750b378a9de3435951e3ea1644184a55
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java4
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java61
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java50
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json5
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json20
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfQuery_Response.json41
-rw-r--r--mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java8
-rw-r--r--mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java4
-rw-r--r--mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java3
9 files changed, 175 insertions, 21 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
index 739b4b62de..b4dfca3c6c 100644
--- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
@@ -718,8 +718,8 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest {
}
@Test
- public void getWorkflowByModelUUID_validUuid_expectedOutput() {
- List<Workflow> workflows = client.findWorkflowByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
+ public void getWorkflowByVnfModelUUID_validUuid_expectedOutput() {
+ List<Workflow> workflows = client.findWorkflowByVnfModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
assertTrue(workflows != null);
assertTrue(workflows.size() != 0);
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 925d10179f..0d0e6ee92f 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
@@ -23,6 +23,8 @@ package org.onap.so.apihandlerinfra;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.TreeSet;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -90,21 +92,40 @@ public class WorkflowSpecificationsHandler {
@Transactional
public Response queryWorkflowSpecifications(@QueryParam("vnfModelVersionId") String vnfModelVersionId,
- @PathParam("version") String version) throws Exception {
-
+ @QueryParam("pnfModelVersionId") String pnfModelVersionId, @PathParam("version") String version)
+ throws Exception {
String apiVersion = version.substring(1);
- ObjectMapper mapper1 = new ObjectMapper();
- mapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-
- List<Workflow> workflows = catalogDbClient.findWorkflowByModelUUID(vnfModelVersionId);
+ List<Workflow> workflows = new ArrayList<>();
+ if (vnfModelVersionId == null && pnfModelVersionId == null) {
+ workflows.addAll(queryWorkflowSpecificationsForAll());
+ } else {
+ // 1. query workflow specifications for given vnfModelVersionId if need.
+ if (vnfModelVersionId != null) {
+ List<Workflow> vnfWorkflows = queryWorkflowSpecificationsForVnf(vnfModelVersionId);
+ logger.debug("Retrieved " + vnfWorkflows.size() + " workflows for given vnfModelVersionId.");
+ if (vnfWorkflows.size() > 0) {
+ workflows.addAll(vnfWorkflows);
+ }
+ }
- List<Workflow> nativeWorkflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW);
- if (nativeWorkflows != null && !nativeWorkflows.isEmpty()) {
- workflows.addAll(nativeWorkflows);
+ // 2. query workflow specifications for given pnfModelVersionId if need.
+ if (pnfModelVersionId != null) {
+ List<Workflow> pnfWorkflows = queryWorkflowSpecificationsForPnf(pnfModelVersionId);
+ logger.debug("Retrieved " + pnfWorkflows.size() + " workflows for given pnfModelVerionId.");
+ if (pnfWorkflows.size() > 0) {
+ workflows.addAll(pnfWorkflows);
+ }
+ }
}
- WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(workflows);
+ // Deduplication
+ List<Workflow> retWorkflows = workflows.stream()
+ .collect(Collectors.collectingAndThen(
+ Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Workflow::getArtifactUUID))),
+ ArrayList::new));
+
+ WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(retWorkflows);
String jsonResponse;
try {
@@ -239,4 +260,24 @@ public class WorkflowSpecificationsHandler {
}
return validationList;
}
+
+ private List<Workflow> queryWorkflowSpecificationsForAll() {
+ List<Workflow> workflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW);
+ return workflows;
+ }
+
+ private List<Workflow> queryWorkflowSpecificationsForVnf(String vnfModelVersionId) {
+ List<Workflow> workflows = catalogDbClient.findWorkflowByVnfModelUUID(vnfModelVersionId);
+
+ List<Workflow> nativeWorkflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW);
+ if (!nativeWorkflows.isEmpty()) {
+ workflows.addAll(nativeWorkflows);
+ }
+ return workflows;
+ }
+
+ private List<Workflow> queryWorkflowSpecificationsForPnf(String pnfModelVersionId) {
+ List<Workflow> workflows = catalogDbClient.findWorkflowByPnfModelUUID(pnfModelVersionId);
+ 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 0beab1bd13..7af92cb8ef 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
@@ -68,7 +68,7 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
private final String basePath = "onap/so/infra/workflowSpecifications/v1/workflows";
@Test
- public void queryWorkflowSpecifications_Test_Success()
+ public void queryWorkflowSpecificationsByVnfModelUUID_Test_Success()
throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException {
HttpHeaders headers = new HttpHeaders();
@@ -77,7 +77,7 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
wireMockServer.stubFor(get(urlMatching(
- "/workflow/search/findWorkflowByModelUUID[?]vnfResourceModelUUID=b5fa707a-f55a-11e7-a796-005056856d52"))
+ "/workflow/search/findWorkflowByVnfModelUUID[?]vnfResourceModelUUID=b5fa707a-f55a-11e7-a796-005056856d52"))
.willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.withBody(getWiremockResponseForCatalogdb("WorkflowSpecificationsQuery_Response.json"))
.withStatus(org.apache.http.HttpStatus.SC_OK)));
@@ -324,6 +324,52 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertThat(expectedResult, sameBeanAs(workflowSpecifications).ignoring(WorkflowInputParameter.class));
}
+ @Test
+ public void queryWorkflowSpecificationsByPnfModelUUID_Test_Success()
+ throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException {
+
+ 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);
+
+ wireMockServer.stubFor(get(urlMatching(
+ "/workflow/search/findWorkflowByPnfModelUUID[?]pnfResourceModelUUID=f2d1f2b2-88bb-49da-b716-36ae420ccbff"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb(
+ "WorkflowSpecificationsForPnfQuery_Response.json"))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ wireMockServer.stubFor(get(urlMatching("/workflow/4/workflowActivitySpecSequence"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb("Empty_workflowActivitySpecSequence_Response.json"))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath))
+ .queryParam("pnfModelVersionId", "f2d1f2b2-88bb-49da-b716-36ae420ccbff");
+
+ ResponseEntity<String> response =
+ restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ WorkflowSpecifications expectedResponse = mapper.readValue(
+ new String(Files.readAllBytes(
+ Paths.get("src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json"))),
+ 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));
+ }
+
private String getWiremockResponseForCatalogdb(String file) {
try {
File resource = ResourceUtils.getFile("classpath:__files/catalogdb/" + file);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json
new file mode 100644
index 0000000000..89675e8f02
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json
@@ -0,0 +1,5 @@
+{
+ "_embedded": {
+ "workflowActivitySpecSequence": []
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json
new file mode 100644
index 0000000000..257b9dc843
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json
@@ -0,0 +1,20 @@
+{
+ "workflowSpecificationList": [
+ {
+ "workflowSpecification": {
+ "artifactInfo": {
+ "artifactType": "workflow",
+ "artifactUuid": "b2fd5627-55e4-4f4f-8064-9e6f443e9152",
+ "artifactName": "DummyPnfWorkflow",
+ "artifactVersion": "1.0",
+ "artifactDescription": "Dummy Pnf Workflow to test custom Pnf workflow",
+ "workflowName": "Dummy Pnf Workflow",
+ "operationName": "DummyPnfWorkflow",
+ "workflowSource": "native",
+ "workflowResourceTarget": "pnf"
+ },
+ "workflowInputParameters": []
+ }
+ }
+ ]
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfQuery_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfQuery_Response.json
new file mode 100644
index 0000000000..a4e1bbcdc5
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfQuery_Response.json
@@ -0,0 +1,41 @@
+{
+ "_embedded": {
+ "workflow": [
+ {
+ "artifactChecksum": "MANUAL RECORD",
+ "artifactName": "DummyPnfWorkflow",
+ "artifactUUID": "b2fd5627-55e4-4f4f-8064-9e6f443e9152",
+ "body": null,
+ "created": "2020-02-18T08:28:15.000+0000",
+ "description": "Dummy Pnf Workflow to test custom Pnf workflow",
+ "id": 4,
+ "name": "Dummy Pnf Workflow",
+ "operationName": "DummyPnfWorkflow",
+ "pnfResourceWorkflow": null,
+ "resourceTarget": "pnf",
+ "source": "native",
+ "timeoutMinutes": null,
+ "version": 1.0,
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findWorkflowByPnfModelUUID?pnfResourceModelUUID=f2d1f2b2-88bb-49da-b716-36ae420ccbff"
+ },
+ "workflow": {
+ "href": "http://localhost:8090/workflow/4"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/4/workflowActivitySpecSequence"
+ }
+ }
+ }
+ ]
+ },
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findWorkflowByPnfModelUUID?pnfResourceModelUUID=f2d1f2b2-88bb-49da-b716-36ae420ccbff"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/4/workflowActivitySpecSequence"
+ }
+ }
+}
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 161ca2a2fb..4090e19d34 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
@@ -201,7 +201,7 @@ public class CatalogDbClient {
private String findServiceByServiceInstanceId = "/findServiceByServiceInstanceId";
private String findPnfResourceCustomizationByModelUuid = "/findPnfResourceCustomizationByModelUuid";
private String findWorkflowByArtifactUUID = "/findByArtifactUUID";
- private String findWorkflowByModelUUID = "/findWorkflowByModelUUID";
+ private String findWorkflowByVnfModelUUID = "/findWorkflowByVnfModelUUID";
private String findWorkflowByPnfModelUUID = "/findWorkflowByPnfModelUUID";
private String findWorkflowBySource = "/findBySource";
private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid";
@@ -339,7 +339,7 @@ public class CatalogDbClient {
endpoint + PNF_RESOURCE_CUSTOMIZATION + SEARCH + findPnfResourceCustomizationByModelUuid;
findWorkflowByArtifactUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByArtifactUUID;
- findWorkflowByModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByModelUUID;
+ findWorkflowByVnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByVnfModelUUID;
findWorkflowByPnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByPnfModelUUID;
findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource;
@@ -1049,8 +1049,8 @@ public class CatalogDbClient {
.queryParam(ARTIFACT_UUID, artifactUUID).build().toString()));
}
- public List<Workflow> findWorkflowByModelUUID(String vnfResourceModelUUID) {
- return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByModelUUID)
+ public List<Workflow> findWorkflowByVnfModelUUID(String vnfResourceModelUUID) {
+ return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByVnfModelUUID)
.queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString()));
}
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
index f1b399325e..91c6940e95 100644
--- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
+++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
@@ -37,14 +37,14 @@ public interface WorkflowRepository extends JpaRepository<Workflow, Integer> {
* Used to fetch the @{link Workflow} by the Model UUID.
*
* This operation is required by {@link org.onap.so.db.catalog.client.CatalogDbClient} to provide Workflow based on
- * model UUID without projection.
+ * vnf model UUID without projection.
*
* @param vnfResourceModelUUID UUID
* @return List of Workflow
*/
@Query(value = "select b.* from vnf_resource_to_workflow a join workflow b where a.WORKFLOW_ID = b.ID and a.VNF_RESOURCE_MODEL_UUID = ?1",
nativeQuery = true)
- List<Workflow> findWorkflowByModelUUID(String vnfResourceModelUUID);
+ List<Workflow> findWorkflowByVnfModelUUID(String vnfResourceModelUUID);
/**
* Used to fetch the @{link Workflow} by the Pnf Model UUID.
diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java
index 7d1b8d0d96..b07e82b8a8 100644
--- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java
+++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java
@@ -36,7 +36,8 @@ public class WorkflowRepositoryTest extends BaseTest {
@Test
public void findByVnfResourceModelUUIDTest() throws Exception {
- List<Workflow> workflows = workflowRepository.findWorkflowByModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
+ List<Workflow> workflows =
+ workflowRepository.findWorkflowByVnfModelUUID("ff2ae348-214a-11e7-93ae-92361f002671");
Assert.assertTrue(workflows != null);
Assert.assertTrue(workflows.size() != 0);