diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-04-14 09:21:10 -0400 |
---|---|---|
committer | Boslet, Cory (cb645j) <cb645j@att.com> | 2019-04-23 14:31:16 -0500 |
commit | 279c53ce4ff89ae58cb87d1458e538f686031d65 (patch) | |
tree | cdbed4c17e5a470eb0adc15e7b0fed25bc91b2ab /bpmn/so-bpmn-tasks/src | |
parent | 48478b9531fb2901c392ce1142f9443b5d805148 (diff) |
Sniro BB now supports sole service proxies
Enhanced sniro BB to account for sole service proxies to support 1908.
Change-Id: I4bf57c7c43de755be03d2284cde321d182255ceb
Issue-ID: SO-1790
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
4 files changed, 168 insertions, 4 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 29037980cc..a927767ec7 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 @@ -334,6 +334,18 @@ public class SniroHomingV2 { } } } + List<ServiceProxy> serviceProxies = serviceInstance.getServiceProxies(); + if (!serviceProxies.isEmpty()) { + logger.debug("Adding service proxies to placement demands list"); + for (ServiceProxy sp : serviceProxies) { + if (isBlank(sp.getId())) { + sp.setId(UUID.randomUUID().toString()); + } + Demand demand = buildDemand(sp.getId(), sp.getModelInfoServiceProxy()); + addCandidates(sp, demand); + placementDemands.add(demand); + } + } return placementDemands; } @@ -400,6 +412,7 @@ public class SniroHomingV2 { private void addCandidates(SolutionCandidates candidates, Demand demand) { List<Candidate> required = candidates.getRequiredCandidates(); List<Candidate> excluded = candidates.getExcludedCandidates(); + List<Candidate> existing = candidates.getExistingCandidates(); if (!required.isEmpty()) { List<org.onap.so.client.sniro.beans.Candidate> cans = new ArrayList<org.onap.so.client.sniro.beans.Candidate>(); @@ -424,7 +437,18 @@ public class SniroHomingV2 { } demand.setExcludedCandidates(cans); } - // TODO support existing candidates + if (!existing.isEmpty()) { + List<org.onap.so.client.sniro.beans.Candidate> cans = + new ArrayList<org.onap.so.client.sniro.beans.Candidate>(); + for (Candidate c : existing) { + org.onap.so.client.sniro.beans.Candidate can = new org.onap.so.client.sniro.beans.Candidate(); + can.setIdentifierType(c.getIdentifierType()); + can.setIdentifiers(c.getIdentifiers()); + can.setCloudOwner(c.getCloudOwner()); + cans.add(can); + } + demand.setExistingCandidates(cans); + } } /** @@ -462,6 +486,7 @@ public class SniroHomingV2 { List<VpnBondingLink> links = serviceInstance.getVpnBondingLinks(); List<AllottedResource> allottes = serviceInstance.getAllottedResources(); List<GenericVnf> vnfs = serviceInstance.getVnfs(); + List<ServiceProxy> serviceProxies = serviceInstance.getServiceProxies(); logger.debug("Processing placement solution " + i + 1); for (int p = 0; p < placements.length(); p++) { @@ -502,6 +527,12 @@ public class SniroHomingV2 { break search; } } + for (ServiceProxy proxy : serviceProxies) { + if (placement.getString(SERVICE_RESOURCE_ID).equals(proxy.getId())) { + proxy.setServiceInstance(setSolution(solutionInfo, placement)); + break search; + } + } } } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java index 19378cdbfa..fe2b63ff92 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/beans/Demand.java @@ -7,9 +7,9 @@ * 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. @@ -38,6 +38,8 @@ public class Demand implements Serializable { private List<Candidate> requiredCandidates; @JsonProperty("excludedCandidates") private List<Candidate> excludedCandidates; + @JsonProperty("existingCandidates") + private List<Candidate> existingCandidates; public List<Candidate> getRequiredCandidates() { @@ -80,4 +82,12 @@ public class Demand implements Serializable { this.modelInfo = modelInfo; } + public List<Candidate> getExistingCandidates() { + return existingCandidates; + } + + public void setExistingCandidates(List<Candidate> existingCandidates) { + this.existingCandidates = existingCandidates; + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java index 8d51ceb65f..b5a8318ce9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -23,7 +23,7 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.isA; @@ -53,6 +53,7 @@ import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.sniro.beans.SniroManagerRequest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; public class SniroHomingV2IT extends BaseIntegrationTest { @@ -107,6 +108,18 @@ public class SniroHomingV2IT extends BaseIntegrationTest { serviceInstance.getAllottedResources().add(setAllottedResource("3")); } + public void beforeServiceProxy() { + ServiceProxy sp = setServiceProxy("1", "infrastructure"); + Candidate requiredCandidate = new Candidate(); + requiredCandidate.setIdentifierType(CandidateType.CLOUD_REGION_ID); + List<String> c = new ArrayList<String>(); + c.add("testCloudRegionId"); + requiredCandidate.setCloudOwner("att"); + requiredCandidate.setIdentifiers(c); + sp.addRequiredCandidates(requiredCandidate); + serviceInstance.getServiceProxies().add(sp); + } + public void beforeVnf() { setGenericVnf(); } @@ -191,6 +204,23 @@ public class SniroHomingV2IT extends BaseIntegrationTest { verify(sniroClient, times(1)).postDemands(isA(SniroManagerRequest.class)); } + @Test + public void testCallSniro_success_1ServiceProxy() throws JsonProcessingException, BadResponseException { + beforeServiceProxy(); + + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")).willReturn( + aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody(mockResponse))); + + sniroHoming.callSniro(execution); + + String request = readResourceFile(RESOURCE_PATH + "SniroManagerRequest1SP.json"); + request = request.replace("28080", wireMockPort); + + ArgumentCaptor<SniroManagerRequest> argument = ArgumentCaptor.forClass(SniroManagerRequest.class); + verify(sniroClient, times(1)).postDemands(argument.capture()); + assertEquals(request, argument.getValue().toJsonString()); + } + @Test(expected = Test.None.class) public void testProcessSolution_success_1VpnLink_1Solution() { beforeVpnBondingLink("1"); @@ -563,10 +593,57 @@ public class SniroHomingV2IT extends BaseIntegrationTest { assertEquals(2, vnf.getLicense().getLicenseKeyGroupUuids().size()); assertEquals("f1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getEntitlementPoolUuids().get(0)); assertEquals("s1d563e8-e714-4393-8f99-cc480144a05e", vnf.getLicense().getLicenseKeyGroupUuids().get(0)); + } + + @Test + public void testProcessSolution_success_1ServiceProxy_1Solutions() { + beforeServiceProxy(); + + JSONObject asyncResponse = new JSONObject(); + asyncResponse.put("transactionId", "testRequestId").put("requestId", "testRequestId").put("requestState", + "completed"); + JSONArray solution1 = new JSONArray(); + solution1 + .put(new JSONObject() + .put("serviceResourceId", "testProxyId1").put( + "solution", + new JSONObject() + .put("identifierType", "serviceInstanceId") + .put("identifiers", new JSONArray().put("testServiceInstanceId1"))) + .put("assignmentInfo", + new JSONArray().put(new JSONObject().put("key", "isRehome").put("value", "False")) + .put(new JSONObject().put("key", "cloudOwner").put("value", "")) + .put(new JSONObject().put("key", "aicClli").put("value", "testAicClli1")) + .put(new JSONObject().put("key", "aicVersion").put("value", "3")) + .put(new JSONObject().put("key", "cloudRegionId").put("value", "")) + .put(new JSONObject().put("key", "primaryPnfName").put("value", + "testPrimaryPnfName")) + .put(new JSONObject().put("key", "secondaryPnfName").put("value", + "testSecondaryPnfName")))); + + asyncResponse.put("solutions", new JSONObject().put("placementSolutions", new JSONArray().put(solution1)) + .put("licenseSolutions", new JSONArray())); + sniroHoming.processSolution(execution, asyncResponse.toString()); + ServiceInstance si = + execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0); + + ServiceProxy sp = si.getServiceProxies().get(0); + assertNotNull(sp); + assertNotNull(sp.getServiceInstance()); + + assertEquals("testServiceInstanceId1", sp.getServiceInstance().getServiceInstanceId()); + assertNotNull(sp.getServiceInstance().getSolutionInfo()); + + assertFalse(sp.getServiceInstance().getPnfs().isEmpty()); + assertEquals("testPrimaryPnfName", sp.getServiceInstance().getPnfs().get(0).getPnfName()); + assertEquals("primary", sp.getServiceInstance().getPnfs().get(0).getRole()); + assertEquals("testSecondaryPnfName", sp.getServiceInstance().getPnfs().get(1).getPnfName()); + assertEquals("secondary", sp.getServiceInstance().getPnfs().get(1).getRole()); } + @Test(expected = BpmnError.class) public void testCallSniro_error_0Resources() throws BadResponseException, JsonProcessingException { diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1SP.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1SP.json new file mode 100644 index 0000000000..27463350ab --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/SniroHoming/SniroManagerRequest1SP.json @@ -0,0 +1,46 @@ +{ + "requestInfo" : { + "transactionId" : "testRequestId", + "requestId" : "testRequestId", + "callbackUrl" : "http://localhost:28080/mso/WorkflowMesssage/SNIROResponse/testRequestId", + "sourceId" : "mso", + "requestType" : "create", + "timeout" : 1800 + }, + "serviceInfo" : { + "modelInfo" : { + "modelName" : "testModelName1", + "modelVersionId" : "testModelUUID1", + "modelVersion" : "testModelVersion1", + "modelInvariantId" : "testModelInvariantUUID1" + }, + "serviceRole" : "testServiceRole1", + "serviceInstanceId" : "testServiceInstanceId1", + "serviceName" : "testServiceType1" + }, + "placementInfo" : { + "subscriberInfo" : { + "globalSubscriberId" : "testCustomerId", + "subscriberName" : "testCustomerName" + }, + "placementDemands" : [ { + "serviceResourceId" : "testProxyId1", + "resourceModuleName" : "testProxyInstanceName1", + "resourceModelInfo" : { + "modelName" : "testProxyModelName1", + "modelVersionId" : "testProxyModelUuid1", + "modelVersion" : "testProxyModelVersion1", + "modelInvariantId" : "testProxyModelInvariantUuid1" + }, + "requiredCandidates" : [ { + "identifierType" : "cloudRegionId", + "identifiers" : [ "testCloudRegionId" ], + "cloudOwner" : "att" + } ] + } ], + "requestParameters" : {"subscriptionServiceType":"testSubscriptionServiceType","aLaCarte":false} + }, + "licenseInfo" : { + "licenseDemands" : [ ] + } +}
\ No newline at end of file |