diff options
author | Norm Traxler <normant@amdocs.com> | 2019-01-17 20:57:54 +0000 |
---|---|---|
committer | Norm Traxler <normant@amdocs.com> | 2019-01-17 20:58:15 +0000 |
commit | cdad28821c2ac6834e284aae72f10ad2d0529147 (patch) | |
tree | 3fc4bb2be3fb373e013a6436fd821d570251a6fb | |
parent | fbcdb700fdf2bcc469317d19838ecfac075f1729 (diff) |
Fix NetworkDisc Ctx Builder
Issue-ID: LOG-931
Change-Id: I0a1d26b51a5690380210d026637c9c4cd1f56cfc
Signed-off-by: Norm Traxler <normant@amdocs.com>
5 files changed, 388 insertions, 16 deletions
diff --git a/config/ndQuery.spec b/config/ndQuery.spec index 20914d2..d9248be 100644 --- a/config/ndQuery.spec +++ b/config/ndQuery.spec @@ -2,28 +2,28 @@ // Use https://jolt-demo.appspot.com/#inception to develop/test
// any changes to this file
{
- // This section converts the updated json from service-decompostion
- // to org.onap.pomba.common.datatypes.ModelContext
+ // This section converts the updated json from service-decomposition
+ // to org.onap.pomba.contextbuilder.networkdiscovery.model.NdQuery
"operation": "shift",
"spec": {
"generic-vnfs": {
"*": {
"vservers": {
"*": {
- "vserver-id": "ndQuery[&3].ndResourceList[0].ndResource[&1].resourceId",
- "#vserver": "ndQuery[&3].ndResourceList[0].ndResource[&1].resourceType"
+ "vserver-id": "ndQuery[&3].ndResourcesList[0].ndResources[&1].resourceId",
+ "#vserver": "ndQuery[&3].ndResourcesList[0].ndResources[&1].resourceType"
}
},
"l3-networks": {
"*": {
- "network-id": "ndQuery[&3].ndResourceList[1].ndResource[&1].resourceId",
- "#l3-network": "ndQuery[&3].ndResourceList[1].ndResource[&1].resourceType"
+ "network-id": "ndQuery[&3].ndResourcesList[1].ndResources[&1].resourceId",
+ "#l3-network": "ndQuery[&3].ndResourcesList[1].ndResources[&1].resourceType"
}
},
"vnfcs": {
"*": {
- "vnfc-id": "ndQuery[&3].ndResourceList[2].ndResource[&1].resourceId",
- "#vnfc": "ndQuery[&3].ndResourceList[2].ndResource[&1].resourceType"
+ "vnfc-id": "ndQuery[&3].ndResourcesList[2].ndResources[&1].resourceId",
+ "#vnfc": "ndQuery[&3].ndResourcesList[2].ndResources[&1].resourceType"
}
}
}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java index e73a132..b6c1d12 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/service/SpringServiceImpl.java @@ -20,12 +20,14 @@ package org.onap.pomba.contextbuilder.networkdiscovery.service; import com.bazaarvoice.jolt.Chainr; import com.bazaarvoice.jolt.JsonUtils; import com.google.gson.Gson; + import java.net.InetAddress; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; + import javax.servlet.http.HttpServletRequest; import javax.ws.rs.client.Client; import javax.ws.rs.core.HttpHeaders; @@ -33,6 +35,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status.Family; + import org.onap.aai.restclient.client.Headers; import org.onap.pomba.common.datatypes.Attribute; import org.onap.pomba.common.datatypes.ModelContext; @@ -234,25 +237,46 @@ public class SpringServiceImpl implements SpringService { } } - private void updateServiceDecompCtx(ModelContext networkDiscoveryCtx, Resource resource) { + private void updateNetworkDiscoveryCtx(ModelContext networkDiscoveryCtx, Resource resource) { for (VNF vnf : networkDiscoveryCtx.getVnfs()) { for (VFModule vfModule : vnf.getVfModules()) { for (VM vm : vfModule.getVms()) { - if (vm.getUuid().equals(resource.getId())) { + if (vm.getUuid().equals(resource.getId())) { vm.setDataQuality(resource.getDataQuality()); if (null != resource.getAttributeList()) { for (org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.Attribute ndattribute : resource.getAttributeList()) { try { String ndattributeName = ndattribute.getName(); - if (ndattributeName.equals("name")) { + // Some Network Discovery attribute name do not exactly + // match the pomba-audit-common model Attribute Enums, + // so we have to do some custom mapping here: + switch (ndattributeName) { + case "id": + vm.setUuid(ndattribute.getValue()); + break; + case "name": vm.setName(ndattribute.getValue()); - } - else { + break; + case "inMaintenance": Attribute attribute = new Attribute(); - attribute.setName(Attribute.Name.valueOf(ndattributeName)); + attribute.setName(Attribute.Name.lockedBoolean); attribute.setValue(ndattribute.getValue()); attribute.setDataQuality(ndattribute.getDataQuality()); vm.addAttribute(attribute); + break; + case "hostname": + attribute = new Attribute(); + attribute.setName(Attribute.Name.hostName); + attribute.setValue(ndattribute.getValue()); + attribute.setDataQuality(ndattribute.getDataQuality()); + vm.addAttribute(attribute); + break; + default: + attribute = new Attribute(); + attribute.setName(Attribute.Name.valueOf(ndattributeName)); + attribute.setValue(ndattribute.getValue()); + attribute.setDataQuality(ndattribute.getDataQuality()); + vm.addAttribute(attribute); } } catch (IllegalArgumentException ex) { // The attribute Name passed back from Network Discovery is not in our enum @@ -300,7 +324,6 @@ public class SpringServiceImpl implements SpringService { for (NdResourcesList ndResourcesList : ndQuery.getNdQuery()) { for (NdResources ndResources : ndResourcesList.getNdResources()) { for (NdResource ndResource : ndResources.getNdResources()) { - // The old_requestId is inherited from ServiceDecomposition. // Before we send a message to NetworkDiscoveryMicroService for each Resource, // we need to generate a new request for identification, based on the old ID. @@ -311,7 +334,7 @@ public class SpringServiceImpl implements SpringService { List<Resource> resourceList = nt.getResources(); for (Resource resource1 : resourceList) { - updateServiceDecompCtx(networkDiscoveryCtx, resource1); + updateNetworkDiscoveryCtx(networkDiscoveryCtx, resource1); } } } @@ -404,6 +427,10 @@ public class SpringServiceImpl implements SpringService { Chainr chainr = Chainr.fromSpec(jsonSpec); Object transObject = chainr.transform(jsonInput); Gson gson = new Gson(); + + log.info("Jolt transformed output: {}", JsonUtils.toJsonString(transObject)); + + return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), NdQuery.class); } diff --git a/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/jolt/TransformationTest.java b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/jolt/TransformationTest.java new file mode 100644 index 0000000..7518591 --- /dev/null +++ b/src/test/java/org/onap/pomba/contextbuilder/networkdiscovery/test/jolt/TransformationTest.java @@ -0,0 +1,69 @@ +/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 Amdocs
+ * ============================================================================
+ * 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.pomba.contextbuilder.networkdiscovery.test.jolt;
+
+import com.bazaarvoice.jolt.Chainr;
+import com.bazaarvoice.jolt.JsonUtils;
+import com.google.gson.Gson;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.pomba.contextbuilder.networkdiscovery.model.NdQuery;
+
+public class TransformationTest {
+
+ private static final String TEST_RESOURCES = "src/test/resources/jolt/";
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+
+ @Test
+ public void testTransformNdQuery() {
+
+ Object sourceObject = JsonUtils.filepathToObject(TEST_RESOURCES + "serviceDecompToNdQuery-input.json");
+ Object sourceObject1 = JsonUtils.jsonToObject(JsonUtils.toJsonString(sourceObject));
+
+ List<Object> chainrSpecJSON = JsonUtils.filepathToList("config/ndQuery.spec");
+ Chainr chainr = Chainr.fromSpec(chainrSpecJSON);
+ Object output = chainr.transform(sourceObject1);
+
+ String resultJson = JsonUtils.toJsonString(output);
+
+ // read the result into the NqQuery class:
+ Gson gson = new Gson();
+ NdQuery ndQuery = gson.fromJson(resultJson, NdQuery.class);
+
+ // convert ndQuery back to json:
+ String ndQueryToJson = gson.toJson(ndQuery);
+
+ // Compare with expected output:
+ Object expectedObject = JsonUtils.filepathToObject(TEST_RESOURCES + "serviceDecompToNdQuery-expected.json");
+
+ Assert.assertEquals("Json transformation result does not match expected content",
+ JsonUtils.toPrettyJsonString(expectedObject),
+ JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(ndQueryToJson)));
+
+ }
+
+}
diff --git a/src/test/resources/jolt/serviceDecompToNdQuery-expected.json b/src/test/resources/jolt/serviceDecompToNdQuery-expected.json new file mode 100644 index 0000000..cfc5a5b --- /dev/null +++ b/src/test/resources/jolt/serviceDecompToNdQuery-expected.json @@ -0,0 +1,16 @@ +{
+ "ndQuery": [
+ {
+ "ndResourcesList": [
+ {
+ "ndResources": [
+ {
+ "resourceId": "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "resourceType": "vserver"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file diff --git a/src/test/resources/jolt/serviceDecompToNdQuery-input.json b/src/test/resources/jolt/serviceDecompToNdQuery-input.json new file mode 100644 index 0000000..2954141 --- /dev/null +++ b/src/test/resources/jolt/serviceDecompToNdQuery-input.json @@ -0,0 +1,260 @@ +{
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "generic-vnf",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001-VNF-id-001",
+ "relationship-key": "generic-vnf.vnf-id"
+ }
+ ],
+ "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/PombaDemoCust_001-VNF-id-001",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-to-property": [
+ {
+ "property-key": "generic-vnf.vnf-name",
+ "property-value": "Firewall-1"
+ }
+ ]
+ },
+ {
+ "related-to": "l3-network",
+ "relationship-data": [
+ {
+ "relationship-value": "2ea02809-7279-4b5e-931a-62b231615497",
+ "relationship-key": "l3-network.network-id"
+ }
+ ],
+ "related-link": "/aai/v13/network/l3-networks/l3-network/2ea02809-7279-4b5e-931a-62b231615497",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-to-property": [
+ {
+ "property-key": "l3-network.network-name",
+ "property-value": "NET_1105"
+ }
+ ]
+ },
+ {
+ "related-to": "pnf",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001-PNF2-id-001",
+ "relationship-key": "pnf.pnf-name"
+ }
+ ],
+ "related-link": "/aai/v13/network/pnfs/pnf/PombaDemoCust_001-PNF2-id-001",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf"
+ },
+ {
+ "related-to": "pnf",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001-PNF-id-001",
+ "relationship-key": "pnf.pnf-name"
+ }
+ ],
+ "related-link": "/aai/v13/network/pnfs/pnf/PombaDemoCust_001-PNF-id-001",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf"
+ },
+ {
+ "related-to": "l3-network",
+ "relationship-data": [
+ {
+ "relationship-value": "01e8d84a-17a6-47b5-a167-6a45d1d56603",
+ "relationship-key": "l3-network.network-id"
+ }
+ ],
+ "related-link": "/aai/v13/network/l3-networks/l3-network/01e8d84a-17a6-47b5-a167-6a45d1d56603",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-to-property": [
+ {
+ "property-key": "l3-network.network-name",
+ "property-value": "NET_1106"
+ }
+ ]
+ }
+ ]
+ },
+ "model-version-id": "e2d52f32-a952-46f5-800c-c250903625d6",
+ "service-instance-id": "PombaDemoCust_001-SerivceInst-001",
+ "resource-version": "1545324562797",
+ "generic-vnfs": [
+ {
+ "nf-role": "",
+ "service-id": "8ea56b0d-459d-4668-b363-c9567432d8b7",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "service-instance",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001",
+ "relationship-key": "customer.global-customer-id"
+ },
+ {
+ "relationship-value": "SDN-ETHERNET-INTERNET",
+ "relationship-key": "service-subscription.service-type"
+ },
+ {
+ "relationship-value": "PombaDemoCust_001-SerivceInst-001",
+ "relationship-key": "service-instance.service-instance-id"
+ }
+ ],
+ "related-link": "/aai/v13/business/customers/customer/PombaDemoCust_001/service-subscriptions/service-subscription/SDN-ETHERNET-INTERNET/service-instances/service-instance/PombaDemoCust_001-SerivceInst-001",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-to-property": [
+ {
+ "property-key": "service-instance.service-instance-name"
+ }
+ ]
+ },
+ {
+ "related-to": "vserver",
+ "relationship-data": [
+ {
+ "relationship-value": "CloudOwner",
+ "relationship-key": "cloud-region.cloud-owner"
+ },
+ {
+ "relationship-value": "PombaRegion001",
+ "relationship-key": "cloud-region.cloud-region-id"
+ },
+ {
+ "relationship-value": "PombaRegion001-tenant-001",
+ "relationship-key": "tenant.tenant-id"
+ },
+ {
+ "relationship-value": "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "relationship-key": "vserver.vserver-id"
+ }
+ ],
+ "related-link": "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/PombaRegion001/tenants/tenant/PombaRegion001-tenant-001/vservers/vserver/a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "relationship-label": "tosca.relationships.HostedOn",
+ "related-to-property": [
+ {
+ "property-key": "vserver.vserver-name",
+ "property-value": "Firewall-001"
+ }
+ ]
+ },
+ {
+ "related-to": "pserver",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001-pserver-id-001",
+ "relationship-key": "pserver.hostname"
+ }
+ ],
+ "related-link": "/aai/v13/cloud-infrastructure/pservers/pserver/PombaDemoCust_001-pserver-id-001",
+ "relationship-label": "tosca.relationships.HostedOn",
+ "related-to-property": [
+ {
+ "property-key": "pserver.pserver-name2",
+ "property-value": "PombaDemoCust_001-pserver-id-001-name2"
+ }
+ ]
+ }
+ ]
+ },
+ "vnf-id": "PombaDemoCust_001-VNF-id-001",
+ "nf-type": "",
+ "prov-status": "PREPROV",
+ "vnf-type": "vFW-vSINK-service/vFWvSINK 0",
+ "orchestration-status": "Created",
+ "nf-naming-code": "",
+ "in-maint": false,
+ "nf-function": "",
+ "model-version-id": "e2d52f32-a952-46f5-800c-c250903625d6",
+ "vservers": [
+ {
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "generic-vnf",
+ "relationship-data": [
+ {
+ "relationship-value": "PombaDemoCust_001-VNF-id-001",
+ "relationship-key": "generic-vnf.vnf-id"
+ }
+ ],
+ "related-link": "/aai/v13/network/generic-vnfs/generic-vnf/PombaDemoCust_001-VNF-id-001",
+ "relationship-label": "tosca.relationships.HostedOn",
+ "related-to-property": [
+ {
+ "property-key": "generic-vnf.vnf-name",
+ "property-value": "Firewall-1"
+ }
+ ]
+ },
+ {
+ "related-to": "flavor",
+ "relationship-data": [
+ {
+ "relationship-value": "CloudOwner",
+ "relationship-key": "cloud-region.cloud-owner"
+ },
+ {
+ "relationship-value": "PombaRegion001",
+ "relationship-key": "cloud-region.cloud-region-id"
+ },
+ {
+ "relationship-value": "PombaRegion001-flavor001",
+ "relationship-key": "flavor.flavor-id"
+ }
+ ],
+ "related-link": "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/PombaRegion001/flavors/flavor/PombaRegion001-flavor001",
+ "relationship-label": "org.onap.relationships.inventory.Uses",
+ "related-to-property": [
+ {
+ "property-key": "flavor.flavor-name",
+ "property-value": "m1.medium"
+ }
+ ]
+ },
+ {
+ "related-to": "image",
+ "relationship-data": [
+ {
+ "relationship-value": "CloudOwner",
+ "relationship-key": "cloud-region.cloud-owner"
+ },
+ {
+ "relationship-value": "PombaRegion001",
+ "relationship-key": "cloud-region.cloud-region-id"
+ },
+ {
+ "relationship-value": "PombaRegion001-image001",
+ "relationship-key": "image.image-id"
+ }
+ ],
+ "related-link": "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/PombaRegion001/images/image/PombaRegion001-image001",
+ "relationship-label": "org.onap.relationships.inventory.Uses",
+ "related-to-property": [
+ {
+ "property-key": "image.image-name",
+ "property-value": "unknown"
+ }
+ ]
+ }
+ ]
+ },
+ "in-maint": false,
+ "resource-version": "1545323228761",
+ "vserver-name": "Firewall-001",
+ "prov-status": "ACTIVE",
+ "vserver-id": "a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "vserver-name2": "Firewall-001",
+ "vserver-selflink": "http://10.12.25.2:8774/v2.1/a6a609e3-967a-48bd-8ce5-41c7ff5c19b9/servers/a6a609e3-967a-48bd-8ce5-41c7ff5c19b9",
+ "is-closed-loop-disabled": false
+ }
+ ],
+ "resource-version": "1545324724996",
+ "model-customization-id": "3b822416-475d-4e1c-aac3-2544b0a0fdfc",
+ "model-invariant-id": "59dd4d63-8f21-406c-98c0-3b057bb86820",
+ "vnf-name": "Firewall-1",
+ "is-closed-loop-disabled": false
+ }
+ ],
+ "model-invariant-id": "59dd4d63-8f21-406c-98c0-3b057bb86820"
+}
\ No newline at end of file |