diff options
author | Tait,Trevor(rt0435) <rtait@amdocs.com> | 2019-01-14 14:46:41 -0500 |
---|---|---|
committer | Tait,Trevor(rt0435) <rtait@amdocs.com> | 2019-01-14 14:46:55 -0500 |
commit | fbcdb700fdf2bcc469317d19838ecfac075f1729 (patch) | |
tree | 0ab1820ec98f597f5b17fbcc532d79a13e2844dd | |
parent | cecc5554b6214be9e473ccfa7207bb04f079b9ae (diff) |
Upgrade nd-context-builder to audit-common.1.4.0
Issue-ID: LOG-926
Change-Id: I63533764139d143bddbf3c2d3c3921dfd438d365
Signed-off-by: Tait,Trevor(rt0435) <rtait@amdocs.com>
8 files changed, 288 insertions, 120 deletions
diff --git a/config/ndQuery.spec b/config/ndQuery.spec new file mode 100644 index 0000000..20914d2 --- /dev/null +++ b/config/ndQuery.spec @@ -0,0 +1,34 @@ +[
+ // 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
+ "operation": "shift",
+ "spec": {
+ "generic-vnfs": {
+ "*": {
+ "vservers": {
+ "*": {
+ "vserver-id": "ndQuery[&3].ndResourceList[0].ndResource[&1].resourceId",
+ "#vserver": "ndQuery[&3].ndResourceList[0].ndResource[&1].resourceType"
+ }
+ },
+ "l3-networks": {
+ "*": {
+ "network-id": "ndQuery[&3].ndResourceList[1].ndResource[&1].resourceId",
+ "#l3-network": "ndQuery[&3].ndResourceList[1].ndResource[&1].resourceType"
+ }
+ },
+ "vnfcs": {
+ "*": {
+ "vnfc-id": "ndQuery[&3].ndResourceList[2].ndResource[&1].resourceId",
+ "#vnfc": "ndQuery[&3].ndResourceList[2].ndResource[&1].resourceType"
+ }
+ }
+ }
+ }
+ }
+ }
+
+ ]
diff --git a/config/networkdiscovery.spec b/config/networkdiscovery.spec index 8da7a87..2cc882c 100644 --- a/config/networkdiscovery.spec +++ b/config/networkdiscovery.spec @@ -1,39 +1,6 @@ [ // Use https://jolt-demo.appspot.com/#inception to develop/test // any changes to this file - - { - // This sections adds nfNamingCode and dataQuality to the json - // fields returned from service-decomposition that we are - // interested in - "operation": "default", - "spec": { - "generic-vnfs[]": { - "*": { - "vf-modules": { - "vf-module[]": { - "*": {} - } - }, - "vservers[]": { - "*": { - "nfNamingCode": "vserver" - } - }, - "l3-networks[]": { - "*": { - "type": "l3-network" - } - }, - "vnfcList[]": { - "*": { - "type": "vnfc" - } - } - } - } - } - }, { // This section converts the updated json from service-decompostion // to org.onap.pomba.common.datatypes.ModelContext @@ -44,24 +11,21 @@ "*": { "vservers": { "*": { - "vserver-id": "vfList[&3].vfModuleList[0].vmList[&1].uuid", - "nfNamingCode": "vfList[&3].vfModuleList[0].vmList[&1].nfNamingCode" + "vserver-id": "vnfList[&3].vfModuleList[0].vmList[&1].uuid" } }, "l3-networks": { "*": { - "network-id": "vfList[&3].vfModuleList[0].networkList[&1].uuid", - "type": "vfList[&3].vfModuleList[0].networkList[&1].type" - }, - "vnfcs": { - "*": { - "vnfc-id": "vfList[&2].vnfcList[&1].uuid", - "type": "vfList[&2].vfModuleList[0].type" - } + "network-id": "vnfList[&3].vfModuleList[0].networkList[&1].uuid" + } + }, + "vnfcs": { + "*": { + "vnfc-id": "vnfList[&3].vnfcList[&1].uuid" } } } } } - } + } ] @@ -116,7 +116,7 @@ limitations under the License. <dependency> <groupId>org.onap.logging-analytics.pomba</groupId> <artifactId>pomba-audit-common</artifactId> - <version>1.3.1</version> + <version>1.4.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.google.guava</groupId> diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java new file mode 100644 index 0000000..f40af2b --- /dev/null +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java @@ -0,0 +1,45 @@ +/*
+ * ============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.model;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.ArrayList;
+import java.util.List;
+
+@ApiModel(value="NdQuery")
+public class NdQuery {
+
+ @Expose
+ @SerializedName("ndQuery")
+ private List<NdResourcesList> ndQuery = new ArrayList<>();
+
+ @ApiModelProperty(value = "List of NdResource associated with the service instance")
+ public List<NdResourcesList> getNdQuery() {
+ return ndQuery;
+ }
+ public void setNdQuery(List<NdResourcesList> ndQuery) {
+ this.ndQuery = ndQuery;
+ }
+ public void addNdQuery(NdResourcesList ndResourcesList) {
+ this.ndQuery.add(ndResourcesList);
+ }
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java new file mode 100644 index 0000000..a4575b6 --- /dev/null +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java @@ -0,0 +1,51 @@ +/*
+ * ============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.model;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value="NdResource")
+public class NdResource {
+
+ @Expose
+ @SerializedName("resourceId")
+ private String resourceId;
+ @Expose
+ @SerializedName("resourceType")
+ private String resourceType;
+
+ @ApiModelProperty(value = "UUID of Resource for Network Discovery")
+ public String getResourceId() {
+ return resourceId;
+ }
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+ @ApiModelProperty(value = "Type of Resource for Network Discovery")
+ public String getResourceType() {
+ return resourceType;
+ }
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java new file mode 100644 index 0000000..a1592fc --- /dev/null +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java @@ -0,0 +1,46 @@ +/*
+ * ============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.model;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.ArrayList;
+import java.util.List;
+
+@ApiModel(value="NdResources")
+public class NdResources {
+
+ @Expose
+ @SerializedName("ndResources")
+ private List<NdResource> ndResources = new ArrayList<>();
+
+ @ApiModelProperty(value = "List of NdResource associated with the service instance")
+ public List<NdResource> getNdResources() {
+ return ndResources;
+ }
+ public void setNdResources(List<NdResource> ndResources) {
+ this.ndResources = ndResources;
+ }
+ public void addNdResource(NdResource ndResource) {
+ this.ndResources.add(ndResource);
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResourcesList.java b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResourcesList.java new file mode 100644 index 0000000..c7e397f --- /dev/null +++ b/src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResourcesList.java @@ -0,0 +1,45 @@ +/*
+ * ============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.model;
+
+import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.ArrayList;
+import java.util.List;
+
+@ApiModel(value="NdResourcesList")
+public class NdResourcesList {
+
+ @Expose
+ @SerializedName("ndResourcesList")
+ private List<NdResources> ndResourcesList = new ArrayList<>();
+
+ @ApiModelProperty(value = "List of NdResources associated with the service instance")
+ public List<NdResources> getNdResources() {
+ return ndResourcesList;
+ }
+ public void setNdResources(List<NdResources> ndResourcesList) {
+ this.ndResourcesList = ndResourcesList;
+ }
+ public void addNdResource(NdResources ndResources) {
+ this.ndResourcesList.add(ndResources);
+ }
+}
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 933d2ab..e73a132 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,15 +20,12 @@ 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.ArrayList; 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; @@ -36,16 +33,18 @@ 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; import org.onap.pomba.common.datatypes.Network; -import org.onap.pomba.common.datatypes.VF; import org.onap.pomba.common.datatypes.VFModule; import org.onap.pomba.common.datatypes.VM; -import org.onap.pomba.common.datatypes.VNFC; +import org.onap.pomba.common.datatypes.VNF; import org.onap.pomba.contextbuilder.networkdiscovery.exception.DiscoveryException; +import org.onap.pomba.contextbuilder.networkdiscovery.model.NdQuery; +import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResource; +import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResources; +import org.onap.pomba.contextbuilder.networkdiscovery.model.NdResourcesList; import org.onap.pomba.contextbuilder.networkdiscovery.service.rs.RestService; import org.onap.pomba.contextbuilder.networkdiscovery.util.RestUtil; import org.onap.sdnc.apps.pomba.networkdiscovery.datamodel.NetworkDiscoveryNotification; @@ -91,26 +90,6 @@ public class SpringServiceImpl implements SpringService { private static UUID instanceUUID = UUID.randomUUID(); private static final AtomicLong uniqueSeq = new AtomicLong(); - private class NdResource { - - private String resourceType; - private String resourceId; - - public NdResource(String type, String id) { - this.resourceType = type; - this.resourceId = id; - } - - public String getResourceType() { - return this.resourceType; - } - - public String getResourceId() { - return this.resourceId; - } - } - - @Autowired private String serviceDecompositionBaseUrl; @@ -146,9 +125,10 @@ public class SpringServiceImpl implements SpringService { RestUtil.validateServiceInstanceId(serviceInstanceId); RestUtil.validatePartnerName(partnerName); validateBasicAuth(authorization); - ModelContext networkDiscoveryCtx = getServiceDeomposition(serviceInstanceId, partnerName, requestId); - - sendNetworkDiscoveryRequest(networkDiscoveryCtx, requestId, partnerName); + String sdReply = getServiceDeomposition(serviceInstanceId, partnerName, requestId); + ModelContext networkDiscoveryCtx = createModelContextFromSdResonse(sdReply); + NdQuery ndQuery = createNdQueryFromSdResonse(sdReply); + sendNetworkDiscoveryRequest(networkDiscoveryCtx, ndQuery, requestId, partnerName); return networkDiscoveryCtx; } catch (Exception x) { @@ -186,7 +166,7 @@ public class SpringServiceImpl implements SpringService { /** * Given a service instance ID, GET the resources from Service Decomposition. */ - private ModelContext getServiceDeomposition(String serviceInstanceId, String partnerName, String requestId) + private String getServiceDeomposition(String serviceInstanceId, String partnerName, String requestId) throws DiscoveryException { if (serviceInstanceId == null) { return null; @@ -195,7 +175,7 @@ public class SpringServiceImpl implements SpringService { log.info("Querying Service Decomposition for service instance {}", serviceInstanceId); String urlStr = getUrl(serviceInstanceId); - + log.info("Querying Service Decomposition for url {}", urlStr); @@ -222,12 +202,7 @@ public class SpringServiceImpl implements SpringService { serviceInstanceId, reply); } - List<Object> jsonSpec = JsonUtils.filepathToList("config/networkdiscovery.spec"); - Object jsonInput = JsonUtils.jsonToObject(reply); - Chainr chainr = Chainr.fromSpec(jsonSpec); - Object transObject = chainr.transform(jsonInput); - Gson gson = new Gson(); - return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), ModelContext.class); + return reply; } catch (Exception x) { throw new DiscoveryException(x.getMessage(), x); } @@ -260,8 +235,8 @@ public class SpringServiceImpl implements SpringService { } private void updateServiceDecompCtx(ModelContext networkDiscoveryCtx, Resource resource) { - for (VF vf : networkDiscoveryCtx.getVfs()) { - for (VFModule vfModule : vf.getVfModules()) { + for (VNF vnf : networkDiscoveryCtx.getVnfs()) { + for (VFModule vfModule : vnf.getVfModules()) { for (VM vm : vfModule.getVms()) { if (vm.getUuid().equals(resource.getId())) { vm.setDataQuality(resource.getDataQuality()); @@ -318,43 +293,29 @@ public class SpringServiceImpl implements SpringService { /* Return list of requestIds sent to network-discovery microService. */ - private List<String> sendNetworkDiscoveryRequest(ModelContext networkDiscoveryCtx, String parentRequestId, - String partnerName) throws DiscoveryException { - - List<String> relatedRequestIdList = new ArrayList<>(); - List<NdResource> ndresourceList = new ArrayList<>(); - - for (VF vf : networkDiscoveryCtx.getVfs()) { - for (VNFC vnfc : vf.getVnfcs()) { - ndresourceList.add(new NdResource(vnfc.getType(), vnfc.getUuid())); - } - for (VFModule vfModule : vf.getVfModules()) { - for (VM vm : vfModule.getVms() ) { - ndresourceList.add(new NdResource(vm.getNfcNamingCode(), vm.getUuid())); - vm.setNfcNamingCode(null); - } - for (Network network : vfModule.getNetworks()) { - ndresourceList.add(new NdResource(network.getType(), network.getUuid())); + private void sendNetworkDiscoveryRequest(ModelContext networkDiscoveryCtx, + NdQuery ndQuery, + String parentRequestId, + String partnerName) throws DiscoveryException { + 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. + String requestId = parentRequestId + NETWORK_DISCOVERY_RSP_REQUESTID_SPLITTER + uniqueSeq.incrementAndGet(); + + NetworkDiscoveryNotification nt = sendNetworkDiscoveryRequestToSpecificServer(partnerName, parentRequestId, + requestId, ndResource.getResourceId(), ndResource.getResourceType()); + + List<Resource> resourceList = nt.getResources(); + for (Resource resource1 : resourceList) { + updateServiceDecompCtx(networkDiscoveryCtx, resource1); + } } } } - - for (NdResource resource : ndresourceList) { - - // 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. - String requestId = parentRequestId + NETWORK_DISCOVERY_RSP_REQUESTID_SPLITTER + uniqueSeq.incrementAndGet(); - - NetworkDiscoveryNotification nt = sendNetworkDiscoveryRequestToSpecificServer(partnerName, parentRequestId, - requestId, resource.getResourceId(), resource.getResourceType()); - - List<Resource> resourceList = nt.getResources(); - for (Resource resource1 : resourceList) { - updateServiceDecompCtx(networkDiscoveryCtx, resource1); - } - } - return relatedRequestIdList; } private NetworkDiscoveryNotification sendNetworkDiscoveryRequestToSpecificServer(String partnerName, String parentRequestId, @@ -378,14 +339,14 @@ public class SpringServiceImpl implements SpringService { .header(NETWORK_DISCOVERY_FIND_RESOURCE_BY_TYPE_REST_X_ONAP_REQUEST_ID, parentRequestId).get(); String status = Response.Status.fromStatusCode(response.getStatus()) + ",code:" + response.getStatus(); - + if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status); throw new DiscoveryException(response.getStatusInfo().toString(), Response.Status.fromStatusCode(response.getStatus())); } else { MDC.put(MDC_TO_NETWORK_DISCOVERY_MICRO_SERVICE_STATUS, status); - NetworkDiscoveryNotification ndResponse = response.readEntity(NetworkDiscoveryNotification.class); + NetworkDiscoveryNotification ndResponse = response.readEntity(NetworkDiscoveryNotification.class); log.info("Message sent. Response Payload: {}", ndResponse); return ndResponse; } @@ -426,4 +387,26 @@ public class SpringServiceImpl implements SpringService { } } + + private ModelContext createModelContextFromSdResonse(String response) { + List<Object> jsonSpec = JsonUtils.filepathToList("config/networkdiscovery.spec"); + Object jsonInput = JsonUtils.jsonToObject(response); + Chainr chainr = Chainr.fromSpec(jsonSpec); + Object transObject = chainr.transform(jsonInput); + Gson gson = new Gson(); + return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), ModelContext.class); + + } + + private NdQuery createNdQueryFromSdResonse(String response) { + List<Object> jsonSpec = JsonUtils.filepathToList("config/ndQuery.spec"); + Object jsonInput = JsonUtils.jsonToObject(response); + Chainr chainr = Chainr.fromSpec(jsonSpec); + Object transObject = chainr.transform(jsonInput); + Gson gson = new Gson(); + return gson.fromJson(JsonUtils.toPrettyJsonString(transObject), NdQuery.class); + + } + + } |