diff options
author | Leigh, Phillip (pl876u) <phillip.leigh@amdocs.com> | 2019-01-09 11:58:46 -0500 |
---|---|---|
committer | Leigh, Phillip (pl876u) <phillip.leigh@amdocs.com> | 2019-01-09 11:59:07 -0500 |
commit | 9b24e98bb37f90c85f27e515945c8ab86807a0fb (patch) | |
tree | 65be559439e5921620cca156ab57dd28ff83e79a /src/main | |
parent | 817a49efcafcbd832ac9e8259f50561a13856c1b (diff) |
Handle PNF in AaiCtxBuilder
Issue-ID: LOG-764
Change-Id: I1af65f604751d7412cc12e7a42f2dc785d39a90c
Signed-off-by: Leigh, Phillip (pl876u) <phillip.leigh@amdocs.com>
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PnfInstance.java | 317 | ||||
-rw-r--r-- | src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java | 204 |
2 files changed, 510 insertions, 11 deletions
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PnfInstance.java b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PnfInstance.java new file mode 100644 index 0000000..f470b78 --- /dev/null +++ b/src/main/java/org/onap/pomba/contextbuilder/aai/datatype/PnfInstance.java @@ -0,0 +1,317 @@ +/* + * ============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.aai.datatype; + + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.onap.pomba.contextbuilder.aai.exception.AuditError; +import org.onap.pomba.contextbuilder.aai.exception.AuditException; + +public class PnfInstance { + + @SerializedName("pnf-id") + @Expose + private String pnfId; + @SerializedName("pnf-name") + @Expose + private String pnfName; + @SerializedName("nf-function") + @Expose + private String nfFunction; + @SerializedName("nf-role") + @Expose + private String nfRole; + @SerializedName("resource-version") + @Expose + private String resourceVersion; + @SerializedName("pnf-name2") + @Expose + private String pnfName2; + @SerializedName("pnf-name2-source") + @Expose + private String pnfName2Source; + @SerializedName("equip-type") + @Expose + private String equipmentType; + @SerializedName("equip-vendor") + @Expose + private String equipmentVendor; + @SerializedName("equip-model") + @Expose + private String equipmentModel; + @SerializedName("management-option") + @Expose + private String managementOptions; + @SerializedName("sw-version") + @Expose + private String swVersion; + @SerializedName("frame-id") + @Expose + private String frameId; + @SerializedName("serial-number") + @Expose + private String serialNumber; + @SerializedName("model-invariant-id") + @Expose + private String modelInvariantId; + @SerializedName("model-version-id") + @Expose + private String modelVersionId; + + public String getModelInvariantId() { + return modelInvariantId; + } + public String getPnfId() { + return pnfId; + } + + public void setPnfId(String pnfId) { + this.pnfId = pnfId; + } + + public String getPnfName() { + return pnfName; + } + + public void setPnfName(String name) { + this.pnfName = name; + } + public String getNfFunction() { + return nfFunction; + } + + public void setNfFunction(String nfFunction) { + this.nfFunction = nfFunction; + } + + public String getNfRole() { + return nfRole; + } + + public void setNfRole(String networkRole) { + this.nfRole = networkRole; + } + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public String getPnfName2() { + return pnfName2; + } + + public void setPnfName2(String name2) { + this.pnfName2 = name2; + } + + public String getPnfName2Source() { + return pnfName2Source; + } + + public void setPnfName2Source(String name2Source) { + this.pnfName2Source = name2Source; + } + + public String getEquipmentType() { + return equipmentType; + } + + public void setEquipmentType(String equipmentType) { + this.equipmentType = equipmentType; + } + + public String getEquipmentVendor() { + return equipmentVendor; + } + + public void setEquipmentVendor(String equipmentVendor) { + this.equipmentVendor = equipmentVendor; + } + + public String getEquipmentModel() { + return equipmentModel; + } + + public void setEquipmentModel(String equipmentModel) { + this.equipmentModel = equipmentModel; + } + + public String getManagementOptions() { + return managementOptions; + } + + public void setManagementOptions(String managementOptions) { + this.managementOptions = managementOptions; + } + + public String getSwVersion() { + return swVersion; + } + + public void setSwVersion(String swVersion) { + this.swVersion = swVersion; + } + + public String getFrameId() { + return frameId; + } + + public void setFrameId(String frameId) { + this.frameId = frameId; + } + + public String getSerialNumber() { + return serialNumber; + } + + public void setSerialNumber(String serialNumber) { + this.serialNumber = serialNumber; + } + + public void setModelInvariantId(String modelInvariantId) { + this.modelInvariantId = modelInvariantId; + } + + public String getModelVersionId() { + return modelVersionId; + } + + public void setModelVersionId(String modelVersionId) { + this.modelVersionId = modelVersionId; + } + + + private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + + public String toJson() { + return gson.toJson(this); + } + + + public static PnfInstance fromJson(String payload) throws AuditException { + try { + if (payload == null || payload.isEmpty()) { + throw new AuditException("Empty Json response"); + } + return gson.fromJson(payload, PnfInstance.class); + } catch (Exception ex) { + throw new AuditException(AuditError.JSON_READER_PARSE_ERROR, ex); + } + } + + /** + * No args constructor for use in serialization + * + */ + public PnfInstance() { + } + + /** + * + * @param uuid + * @param name + * @param networkRole + * @param name2 + * @param name2Source + * @param equipmentType + * @param equipmentVendor + * @param equipmentModel + * @param managementOptions + * @param swVersion + * @param frameId + * @param serialNumber + * @param modelInvariantId + * @param modelVersionId + * + */ + public PnfInstance(String uuid, String name, String networkRole, String name2, String name2Source,String equipmentType,String equipmentVendor,String equipmentModel,String managementOptions,String swVersion, String frameId, String serialNumber, String modelInvariantId, String modelVersionId) { + super(); + this.pnfId = uuid; + this.pnfName = name; + this.nfRole = networkRole; + this.pnfName2 = name2; + this.pnfName2Source = name2Source; + this.equipmentType = equipmentType; + this.equipmentVendor = equipmentVendor; + this.equipmentModel = equipmentModel; + this.managementOptions = managementOptions; + this.swVersion = swVersion; + this.frameId = frameId; + this.serialNumber = serialNumber; + this.modelInvariantId = modelInvariantId; + this.modelVersionId = modelVersionId; + } + + + + /////////// common functions ////////////////////// + @Override + public String toString() { + return new ToStringBuilder(this) + .append("uuid", pnfId) + .append("name", pnfName) + .append("networkRole", nfRole) + .append("name2", pnfName2) + .append("name2Source", pnfName2Source) + .append("equipmentType", equipmentType) + .append("equipmentVendor", equipmentVendor) + .append("equipmentModel", equipmentModel) + .append("managementOptions", managementOptions) + .append("swVersion", swVersion) + .append("frameId", frameId) + .append("serialNumber", serialNumber) + .append("modelInvariantId", modelInvariantId) + .append("modelVersionId", modelVersionId) + .toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(pnfId).append(frameId).append(serialNumber).append(modelInvariantId).append(modelVersionId).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof PnfInstance)) { + return false; + } + PnfInstance rhs = ((PnfInstance) other); + return new EqualsBuilder() + .append(pnfId, rhs.pnfId) + .append(pnfName, rhs.pnfName) + .append(pnfName2, rhs.pnfName2) + .append(equipmentType, rhs.equipmentType) + .append(equipmentModel, rhs.equipmentModel) + .append(frameId, rhs.frameId) + .append(serialNumber, rhs.serialNumber) + .isEquals(); + } +} diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java index 1f34cc6..88f3db4 100644 --- a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java +++ b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java @@ -37,7 +37,8 @@ import org.onap.pomba.common.datatypes.Attribute; import org.onap.pomba.common.datatypes.DataQuality; import org.onap.pomba.common.datatypes.ModelContext; import org.onap.pomba.common.datatypes.Service; -import org.onap.pomba.common.datatypes.VF; +//import org.onap.pomba.common.datatypes.VF; +import org.onap.pomba.common.datatypes.VNF; import org.onap.pomba.common.datatypes.VFModule; import org.onap.pomba.common.datatypes.VM; import org.onap.pomba.common.datatypes.VNFC; @@ -53,7 +54,9 @@ import org.onap.pomba.contextbuilder.aai.exception.AuditError; import org.onap.pomba.contextbuilder.aai.exception.AuditException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import org.onap.pomba.contextbuilder.aai.datatype.PnfInstance; +import org.onap.pomba.common.datatypes.PNF; +import com.bazaarvoice.jolt.JsonUtils; public class RestUtil { @@ -80,6 +83,7 @@ public class RestUtil { private static final String VF_MODULES = "vf-modules"; private static final String VF_MODULE = "vf-module"; + private static final String CATALOG_PNF = "pnf"; // Relationship Json Path private static final String RELATIONSHIP_LIST = "relationship-list"; @@ -100,6 +104,20 @@ public class RestUtil { private static final String HOSTNAME = "hostName"; private static final String IMAGEID = "imageId"; + //Attribute Names for PNF + private static final String PNF_NETWORK_FUNCTION = "networkFunction"; + private static final String PNF_NETWORK_ROLE = "networkRole"; + private static final String PNF_RESOURCE_VERSION = "resourceVersion"; + private static final String PNF_NAME2 = "name2"; + private static final String PNF_NAME2_SOURCE = "name2Source"; + private static final String PNF_EQUIPMENT_TYPE = "equipType"; + private static final String PNF_EQUIPMENT_VENDOR = "equipVendor"; + private static final String PNF_EQUIPMENT_MODEL = "equipModel"; + private static final String PNF_MANAGEMENT_OPTIONS = "managementOptions"; + private static final String PNF_SW_VERSION = "swVersion"; + private static final String PNF_FRAME_ID = "frameId"; + private static final String PNF_SERIAL_NUMBER = "serialNumber"; + /** * Validates the URL parameter. * @@ -183,6 +201,8 @@ public class RestUtil { return null; } + log.info("ResourceLink from AAI:" + resourceLink); + // Build URl to get ServiceInstance Payload String url = baseURL + resourceLink; @@ -196,6 +216,7 @@ public class RestUtil { // Only return the empty Json on the root level. i.e service instance return null; } + log.info("Message from AAI:" + JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(serviceInstancePayload)) ); List<String> genericVNFLinkLst = extractRelatedLink(serviceInstancePayload, CATALOG_GENERIC_VNF); log.info(LogMessages.NUMBER_OF_API_CALLS, "genericVNF", genericVNFLinkLst.size()); @@ -212,6 +233,8 @@ public class RestUtil { if (isEmptyJson(genericVNFPayload)) { log.info(LogMessages.NOT_FOUND, "GenericVNF with url ", genericVNFLink); } else { + log.info("Message from AAI for VNF " + genericVNFURL + ",message body:" + JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(genericVNFPayload)) ); + // Logic to Create the Generic VNF Instance POJO object VnfInstance vnfInstance = VnfInstance.fromJson(genericVNFPayload); vnfLst.add(vnfInstance); @@ -224,8 +247,35 @@ public class RestUtil { } } + + //Obtain PNF (Physical Network Function) + List<String> genericPNFLinkLst = extractRelatedLink(serviceInstancePayload, CATALOG_PNF); + log.info(LogMessages.NUMBER_OF_API_CALLS, "PNF", genericPNFLinkLst.size()); + log.info(LogMessages.API_CALL_LIST, "PNF", printOutAPIList(genericPNFLinkLst)); + + String genericPNFPayload = null; + List<PnfInstance> pnfLst = new ArrayList<PnfInstance>(); // List of the PNF POJO object + + for (String genericPNFLink : genericPNFLinkLst) { + // With latest AAI development, in order to retrieve the both generic PNF + String genericPNFURL = baseURL + genericPNFLink; + // Response from generic PNF API call + genericPNFPayload = + getResource(aaiClient, genericPNFURL, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON)); + + if (isEmptyJson(genericPNFPayload)) { + log.info(LogMessages.NOT_FOUND, "GenericPNF with url ", genericPNFLink); + } else { + log.info("Message from AAI for PNF " + genericPNFLink + ",message body:" + JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(genericPNFPayload)) ); + + // Logic to Create the Generic VNF Instance POJO object + PnfInstance pnfInstance = PnfInstance.fromJson(genericPNFPayload); + pnfLst.add(pnfInstance); + } + } + // Transform to common model and return - return transform(ServiceInstance.fromJson(serviceInstancePayload), vnfLst, vnfcMap, vnf_vfmodule_vserver_Map); + return transform(ServiceInstance.fromJson(serviceInstancePayload), vnfLst, vnfcMap, vnf_vfmodule_vserver_Map, pnfLst); } /* @@ -250,6 +300,7 @@ public class RestUtil { if (isEmptyJson(vnfcPayload)) { log.info(LogMessages.NOT_FOUND, "VNFC with url", vnfcLink); } else { + log.info("Message from AAI for VNFC with url " + vnfcLink + ",message body:" + JsonUtils.toPrettyJsonString(JsonUtils.jsonToObject(vnfcPayload)) ); // Logic to Create the VNFC POJO object VnfcInstance vnfcInstance = VnfcInstance.fromJson(vnfcPayload); vnfcLst.add(vnfcInstance); @@ -322,18 +373,18 @@ public class RestUtil { * Transform AAI Representation to Common Model */ private static ModelContext transform(ServiceInstance svcInstance, List<VnfInstance> vnfLst, - Map<String, List<VnfcInstance>> vnfcMap, Map<String, Map<String, List<Vserver>>> vnf_vfmodule_vserver_Map) { + Map<String, List<VnfcInstance>> vnfcMap, Map<String, Map<String, List<Vserver>>> vnf_vfmodule_vserver_Map, List<PnfInstance> pnfLst_fromAAi) { ModelContext context = new ModelContext(); Service service = new Service(); - service.setInvariantUuid(svcInstance.getModelInvariantId()); + service.setModelInvariantUUID(svcInstance.getModelInvariantId()); service.setName(svcInstance.getServiceInstanceName()); service.setUuid(svcInstance.getServiceInstanceId()); service.setDataQuality(DataQuality.ok()); - List<VF> vfLst = new ArrayList<VF>(); + List<VNF> vfLst = new ArrayList<VNF>(); for (VnfInstance vnf : vnfLst) { - VF vf = new VF(); - vf.setInvariantUuid(vnf.getModelInvariantId()); + VNF vf = new VNF(); + vf.setModelInvariantUUID(vnf.getModelInvariantId()); vf.setName(vnf.getVnfName()); vf.setUuid(vnf.getModelVersionId()); vf.setType(vnf.getVnfType()); @@ -350,7 +401,7 @@ public class RestUtil { for (VnfcInstance vnfc : vnfcInstanceLst) { VNFC vnfcModel = new VNFC(); - vnfcModel.setInvariantUuid(vnfc.getModelInvariantId()); + vnfcModel.setModelInvariantUUID(vnfc.getModelInvariantId()); vnfcModel.setName(vnfc.getVnfcName()); vnfcModel.setUuid(vnfc.getModelVersionId()); vnfcLst.add(vnfcModel); @@ -381,7 +432,7 @@ public class RestUtil { VFModule vfModule = new VFModule(); vfModule.setUuid(modelVersionId); - vfModule.setInvariantUuid(modelInvariantId); + vfModule.setModelInvariantUUID(modelInvariantId); vfModule.setMaxInstances(getMaxInstance(vfmoduleEntry.getKey(), maxInstanceMap)); vfModule.setDataQuality(DataQuality.ok()); @@ -440,11 +491,142 @@ public class RestUtil { } // done the vnfInstance context.setService(service); - context.setVfs(vfLst); + context.setVnfs(vfLst); + //Add PNF info + context.setPnfs(transformPNF(pnfLst_fromAAi)); return context; } + /* + * Transform AAI Representation to Common Model + */ + public static List<PNF> transformPNF(List<PnfInstance> pnfLst_from_AAI) { + if (pnfLst_from_AAI.isEmpty()) { + log.info(LogMessages.API_CALL_LIST, "Nill PNF list"); + return null; + } + List<PNF> pnfLst = new ArrayList<PNF>(); + + for (PnfInstance pnf_from_aai : pnfLst_from_AAI) { + PNF pnf = new PNF(); + pnf.setModelInvariantUUID(pnf_from_aai.getPnfId()); + pnf.setName(pnf_from_aai.getPnfName()); + pnf.setModelVersionID(pnf_from_aai.getModelVersionId()); + pnf.setModelInvariantUUID(pnf_from_aai.getModelInvariantId()); + pnf.setDataQuality(DataQuality.ok()); + List<Attribute> attributeList = new ArrayList<Attribute>(); + pnf.setAttributes(attributeList); + + // Iterate through the ENUM Attribute list + for (Attribute.Name name: Attribute.Name.values()) { + if (name.toString().equals(PNF_NETWORK_FUNCTION )) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.networkFunction); + att.setValue(String.valueOf( pnf_from_aai.getNfFunction())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_NETWORK_ROLE )) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.networkRole); + att.setValue(String.valueOf( pnf_from_aai.getNfRole())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_RESOURCE_VERSION)) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.resourceVersion); + att.setValue(String.valueOf( pnf_from_aai.getResourceVersion())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_NAME2)) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.name2); + att.setValue(String.valueOf( pnf_from_aai.getPnfName2())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_NAME2_SOURCE )) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.name2Source); + att.setValue(String.valueOf( pnf_from_aai.getPnfName2Source())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_EQUIPMENT_TYPE )) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.equipType); + att.setValue(String.valueOf( pnf_from_aai.getEquipmentType())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_EQUIPMENT_VENDOR )) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.equipVendor); + att.setValue(String.valueOf( pnf_from_aai.getEquipmentVendor())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_EQUIPMENT_MODEL)) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.equipModel); + att.setValue(String.valueOf( pnf_from_aai.getEquipmentModel())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_MANAGEMENT_OPTIONS)) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.managementOptions); + att.setValue(String.valueOf( pnf_from_aai.getManagementOptions())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_SW_VERSION)) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.swVersion); + att.setValue(String.valueOf( pnf_from_aai.getManagementOptions())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_FRAME_ID)) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.frameId); + att.setValue(String.valueOf( pnf_from_aai.getFrameId())); + attributeList.add(att); + } + + if (name.toString().equals(PNF_SERIAL_NUMBER)) { + Attribute att = new Attribute(); + att.setDataQuality(DataQuality.ok()); + att.setName(Attribute.Name.serialNumber); + att.setValue(String.valueOf( pnf_from_aai.getSerialNumber())); + attributeList.add(att); + } + + } + + pnf.setAttributes(attributeList); + pnfLst.add(pnf); + + } // done the vnfInstance + + + return pnfLst; + } + /* * Return the Vserver Attribute value by looking through the relationship. i.e. if "related-to" is "pserver", we will get |