diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
13 files changed, 225 insertions, 18 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java index 6b89387a82..55eaf3681c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java @@ -156,10 +156,13 @@ public class SniroHomingV2 { log.trace("Completed Sniro Homing Call Sniro"); }catch(BpmnError e){ + log.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage()); }catch(BadResponseException e){ + log.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage()); }catch(Exception e){ + log.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while preparing sniro request: " + e.getMessage()); } } @@ -203,10 +206,13 @@ public class SniroHomingV2 { log.trace("Completed Sniro Homing Process Solution"); }catch(BpmnError e){ + log.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage()); }catch(BadResponseException e){ + log.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage()); }catch(Exception e){ + log.error(e); exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage()); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 10ee13ebed..50f2091ae2 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -344,6 +344,18 @@ public class WorkflowAction { } return vfModuleResources; } + + protected List<Resource> sortVfModulesByBaseLast(List<Resource> vfModuleResources) { + int count = 0; + for(Resource resource : vfModuleResources){ + if(resource.isBaseVfModule()){ + Collections.swap(vfModuleResources, vfModuleResources.size()-1, count); + break; + } + count++; + } + return vfModuleResources; + } private void updateResourceIdsFromAAITraversal(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceCounter, List<Pair<WorkflowType, String>> aaiResourceIds, String serviceInstanceId) { @@ -969,8 +981,14 @@ public class WorkflowAction { requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, true, resource.getVirtualLinkKey(), false)); } } else if (orchFlow.getFlowName().contains(VFMODULE)) { - List<Resource> vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType()) + List<Resource> vfModuleResourcesSorted = null; + if(requestAction.equals("createInstance")||requestAction.equals("assignInstance")||requestAction.equals("activateInstance")){ + vfModuleResourcesSorted = sortVfModulesByBaseFirst(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType()) .collect(Collectors.toList())); + }else{ + vfModuleResourcesSorted = sortVfModulesByBaseLast(resourceCounter.stream().filter(x -> WorkflowType.VFMODULE == x.getResourceType()) + .collect(Collectors.toList())); + } for (int i = 0; i < vfModuleResourcesSorted.size(); i++) { flowsToExecute.add(buildExecuteBuildingBlock(orchFlow, requestId, vfModuleResourcesSorted.get(i), apiVersion, resourceId, requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, false)); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java index f91ad44f2b..6bee5a9b1e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java @@ -1,5 +1,6 @@ package org.onap.so.client.namingservice; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -17,6 +18,7 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; @@ -34,21 +36,31 @@ public class NamingClient{ @Autowired private NamingClientResponseValidator namingClientResponseValidator; - public String postNameGenRequest(NameGenRequest request) throws BadResponseException { + public String postNameGenRequest(NameGenRequest request) throws BadResponseException, IOException { String targetUrl = env.getProperty(ENDPOINT); HttpHeaders headers = setHeaders(env.getProperty(AUTH)); msoLogger.info("Sending postNameGenRequest to url: " + targetUrl); HttpEntity<NameGenRequest> requestEntity = new HttpEntity<>(request, headers); - ResponseEntity<NameGenResponse> response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class); + ResponseEntity<NameGenResponse> response; + try{ + response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class); + }catch(HttpStatusCodeException e){ + throw new BadResponseException(namingClientResponseValidator.formatError(e)); + } return namingClientResponseValidator.validateNameGenResponse(response); } - public String deleteNameGenRequest(NameGenDeleteRequest request) throws BadResponseException { + public String deleteNameGenRequest(NameGenDeleteRequest request) throws BadResponseException, IOException { String targetUrl = env.getProperty(ENDPOINT); HttpHeaders headers = setHeaders(env.getProperty(AUTH)); msoLogger.info("Sending deleteNameGenRequest to url: " + targetUrl); HttpEntity<NameGenDeleteRequest> requestEntity = new HttpEntity<>(request, headers); - ResponseEntity<NameGenDeleteResponse> response = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, NameGenDeleteResponse.class); + ResponseEntity<NameGenDeleteResponse> response; + try{ + response = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, NameGenDeleteResponse.class); + }catch(HttpStatusCodeException e){ + throw new BadResponseException(namingClientResponseValidator.formatError(e)); + } return namingClientResponseValidator.validateNameGenDeleteResponse(response); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java index ab0639574c..e790fa4b72 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java @@ -1,5 +1,6 @@ package org.onap.so.client.namingservice; +import java.io.IOException; import java.util.List; import org.apache.http.HttpStatus; @@ -12,6 +13,9 @@ import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpStatusCodeException; + +import com.fasterxml.jackson.databind.ObjectMapper; @Component public class NamingClientResponseValidator { @@ -99,5 +103,20 @@ public class NamingClientResponseValidator { private boolean isHttpCodeSuccess(int code) { return code >= HttpStatus.SC_OK && code < HttpStatus.SC_MULTIPLE_CHOICES || code == 0; } + + protected String formatError(HttpStatusCodeException e) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + NameGenResponse errorResponse = mapper.readValue(e.getResponseBodyAsString(), NameGenResponse.class); + NameGenResponseError error = errorResponse.getError(); + + String errorMessageString = null; + if (error != null) { + errorMessageString = error.getMessage(); + } + String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString); + msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, errorMessage, "BPMN", MsoLogger.getServiceName(), + MsoLogger.ErrorCode.DataError, errorMessage); + return errorMessage; + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java index c3f216e288..82bad8db79 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java @@ -13,11 +13,11 @@ public class NamingRequestObjectBuilder{ public Element elementMapper(String instanceGroupId, String policyInstanceName, String namingType, String nfNamingCode, String instanceGroupName){ Element element = new Element(); - element.setExternalKey(instanceGroupId); - element.setPolicyInstanceName(policyInstanceName); - element.setNamingType(namingType); - element.setResourceName(instanceGroupName); - element.setNamingIngredientsZeroOrMore(nfNamingCode); + element.put("external-key", instanceGroupId); + element.put("policy-instance-name", policyInstanceName); + element.put("naming-type", namingType); + element.put("resource-name", instanceGroupName); + element.put("nf-naming-code", nfNamingCode); return element; } public Deleteelement deleteElementMapper(String instanceGroupId){ diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java index 8b443a165b..d0bf6da6c9 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java @@ -20,6 +20,7 @@ package org.onap.so.client.orchestration; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -44,14 +45,14 @@ public class NamingServiceResources { @Autowired private NamingRequestObjectBuilder namingRequestObjectBuilder; - public String generateInstanceGroupName(InstanceGroup instanceGroup, String policyInstanceName, String nfNamingCode) throws BadResponseException { + public String generateInstanceGroupName(InstanceGroup instanceGroup, String policyInstanceName, String nfNamingCode) throws BadResponseException, IOException { Element element = namingRequestObjectBuilder.elementMapper(instanceGroup.getId(), policyInstanceName, NAMING_TYPE, nfNamingCode, instanceGroup.getInstanceGroupName()); List<Element> elements = new ArrayList<Element>(); elements.add(element); return(namingClient.postNameGenRequest(namingRequestObjectBuilder.nameGenRequestMapper(elements))); } - public String deleteInstanceGroupName(InstanceGroup instanceGroup) throws BadResponseException { + public String deleteInstanceGroupName(InstanceGroup instanceGroup) throws BadResponseException, IOException { Deleteelement deleteElement = namingRequestObjectBuilder.deleteElementMapper(instanceGroup.getId()); List<Deleteelement> deleteElements = new ArrayList<Deleteelement>(); deleteElements.add(deleteElement); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 5699c94137..72f0ce4e6d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -1200,6 +1200,24 @@ public class WorkflowActionTest extends BaseTaskTest { assertEquals("111",result.get(2).getResourceId()); } + @Test + public void sortVfModulesByBaseLastTest(){ + List<Resource> resources = new ArrayList<>(); + Resource resource1 = new Resource(WorkflowType.VFMODULE,"111",false); + resource1.setBaseVfModule(true); + resources.add(resource1); + Resource resource2 = new Resource(WorkflowType.VFMODULE,"222",false); + resource2.setBaseVfModule(false); + resources.add(resource2); + Resource resource3 = new Resource(WorkflowType.VFMODULE,"333",false); + resource3.setBaseVfModule(false); + resources.add(resource3); + List<Resource> result = workflowAction.sortVfModulesByBaseLast(resources); + assertEquals("333",result.get(0).getResourceId()); + assertEquals("222",result.get(1).getResourceId()); + assertEquals("111",result.get(2).getResourceId()); + } + private List<OrchestrationFlow> createFlowList (String... flowNames){ List<OrchestrationFlow> result = new ArrayList<>(); for(String flowName : flowNames){ diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java new file mode 100644 index 0000000000..c1769e3680 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java @@ -0,0 +1,99 @@ +package org.onap.so.client.namingservice; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.namingservice.model.Deleteelement; +import org.onap.namingservice.model.Element; +import org.onap.namingservice.model.NameGenDeleteRequest; +import org.onap.namingservice.model.NameGenRequest; +import org.onap.so.BaseIntegrationTest; +import org.onap.so.client.exception.BadResponseException; +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.core.JsonProcessingException; + +public class NamingClientTest extends BaseIntegrationTest{ + @Autowired + NamingClient client; + @Autowired + NamingRequestObjectBuilder requestBuilder; + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void assignNameGenRequest() throws BadResponseException, IOException{ + stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("NamingClient/AssignResponse.json") + .withStatus(HttpStatus.SC_ACCEPTED))); + + NameGenRequest request = assignSetup(); + String response = client.postNameGenRequest(request); + assertTrue(response.equals("$vnf-name")); + } + @Test + public void assignNameGenRequestError() throws BadResponseException, IOException{ + stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("NamingClient/ErrorResponse.json") + .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + + thrown.expect(BadResponseException.class); + thrown.expectMessage("Error from Naming Service: External Key is required and must be unique"); + NameGenRequest request = assignSetup(); + client.postNameGenRequest(request); + } + @Test + public void unassignNameGenRequest() throws BadResponseException, IOException{ + stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("NamingClient/UnassignResponse.json") + .withStatus(HttpStatus.SC_ACCEPTED))); + + String response = client.deleteNameGenRequest(unassignSetup()); + assertTrue(response.equals("")); + } + @Test + public void unassignNameGenRequestError() throws BadResponseException, IOException{ + stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("NamingClient/ErrorResponse.json") + .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + + thrown.expect(BadResponseException.class); + thrown.expectMessage("Error from Naming Service: External Key is required and must be unique"); + client.deleteNameGenRequest(unassignSetup()); + } + + public NameGenRequest assignSetup() throws JsonProcessingException{ + NameGenRequest request = new NameGenRequest(); + List<Element> elements = new ArrayList<>(); + Element testElement = new Element(); + testElement = requestBuilder.elementMapper("SomeUniqueValue", "SDNC_Policy.Config_MS_1806SRIOV_VNATJson.4.xml", "VNF", "nfNamingCode", "vnf_name"); + elements.add(testElement); + request = requestBuilder.nameGenRequestMapper(elements); + return request; + } + public NameGenDeleteRequest unassignSetup() throws JsonProcessingException{ + NameGenDeleteRequest request = new NameGenDeleteRequest(); + List<Deleteelement> deleteElements = new ArrayList<>(); + Deleteelement testElement = new Deleteelement(); + testElement = requestBuilder.deleteElementMapper("instanceGroupId"); + deleteElements.add(testElement); + request = requestBuilder.nameGenDeleteRequestMapper(deleteElements); + return request; + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java index 0a2dc1e4fa..27839d665b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java @@ -26,11 +26,11 @@ public class NamingRequestObjectBuilderTest { public void elementMapperTest(){ // Expected element Element expected = new Element(); - expected.setExternalKey(instanceGroupId); - expected.setPolicyInstanceName(policyInstanceName); - expected.setNamingType(namingType); - expected.setResourceName(instanceGroupName); - expected.setNamingIngredientsZeroOrMore(nfNamingCode); + expected.put("external-key", instanceGroupId); + expected.put("policy-instance-name", policyInstanceName); + expected.put("naming-type", namingType); + expected.put("resource-name", instanceGroupName); + expected.put("nf-naming-code", nfNamingCode); // Actual element Element actual = mapper.elementMapper(instanceGroupId, policyInstanceName, namingType, nfNamingCode, instanceGroupName); diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/AssignResponse.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/AssignResponse.json new file mode 100644 index 0000000000..b065c21339 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/AssignResponse.json @@ -0,0 +1,14 @@ +{ + "elements": [ + { + "external-key": "$vnf-id", + "resource-name": "instance-group-name", + "resource-value": "$vnf-name" + }, + { + "external-key": "$vnf-id", + "resource-name": "vm-name", + "resource-value": "$vm-name" + } + ] +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/ErrorResponse.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/ErrorResponse.json new file mode 100644 index 0000000000..8bac7cd1f9 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/ErrorResponse.json @@ -0,0 +1,6 @@ +{ + "error": { + "errorId": "NELGEN-0003", + "message": "External Key is required and must be unique" + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/UnassignResponse.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/UnassignResponse.json new file mode 100644 index 0000000000..b065c21339 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/NamingClient/UnassignResponse.json @@ -0,0 +1,14 @@ +{ + "elements": [ + { + "external-key": "$vnf-id", + "resource-name": "instance-group-name", + "resource-value": "$vnf-name" + }, + { + "external-key": "$vnf-id", + "resource-name": "vm-name", + "resource-value": "$vm-name" + } + ] +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml index 3d45caddce..fed2aa69c7 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml +++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml @@ -43,7 +43,7 @@ pnf: mso: naming: endpoint: http://localhost:${wiremock.server.port}/web/service/v1/genNetworkElementName - auth: Basic YnBlbDptc28tZGItMTUwNyE= + auth: Basic YnBlbDptc28tZGItMTUwNyE= adapters: requestDb: auth: Basic YnBlbDptc28tZGItMTUwNyE= |