From fbcdb700fdf2bcc469317d19838ecfac075f1729 Mon Sep 17 00:00:00 2001 From: "Tait,Trevor(rt0435)" Date: Mon, 14 Jan 2019 14:46:41 -0500 Subject: Upgrade nd-context-builder to audit-common.1.4.0 Issue-ID: LOG-926 Change-Id: I63533764139d143bddbf3c2d3c3921dfd438d365 Signed-off-by: Tait,Trevor(rt0435) --- config/ndQuery.spec | 34 ++++++ config/networkdiscovery.spec | 52 ++------ pom.xml | 2 +- .../networkdiscovery/model/NdQuery.java | 45 +++++++ .../networkdiscovery/model/NdResource.java | 51 ++++++++ .../networkdiscovery/model/NdResources.java | 46 +++++++ .../networkdiscovery/model/NdResourcesList.java | 45 +++++++ .../service/SpringServiceImpl.java | 133 +++++++++------------ 8 files changed, 288 insertions(+), 120 deletions(-) create mode 100644 config/ndQuery.spec create mode 100644 src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdQuery.java create mode 100644 src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResource.java create mode 100644 src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResources.java create mode 100644 src/main/java/org/onap/pomba/contextbuilder/networkdiscovery/model/NdResourcesList.java 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" } } } } } - } + } ] diff --git a/pom.xml b/pom.xml index bfc80cf..3f41974 100644 --- a/pom.xml +++ b/pom.xml @@ -116,7 +116,7 @@ limitations under the License. org.onap.logging-analytics.pomba pomba-audit-common - 1.3.1 + 1.4.0-SNAPSHOT com.google.guava 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 ndQuery = new ArrayList<>(); + + @ApiModelProperty(value = "List of NdResource associated with the service instance") + public List getNdQuery() { + return ndQuery; + } + public void setNdQuery(List 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 ndResources = new ArrayList<>(); + + @ApiModelProperty(value = "List of NdResource associated with the service instance") + public List getNdResources() { + return ndResources; + } + public void setNdResources(List 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 ndResourcesList = new ArrayList<>(); + + @ApiModelProperty(value = "List of NdResources associated with the service instance") + public List getNdResources() { + return ndResourcesList; + } + public void setNdResources(List 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 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 sendNetworkDiscoveryRequest(ModelContext networkDiscoveryCtx, String parentRequestId, - String partnerName) throws DiscoveryException { - - List relatedRequestIdList = new ArrayList<>(); - List 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 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 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 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 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); + + } + + } -- cgit 1.2.3-korg