diff options
author | pramod.jamkhedkar <pramod@research.att.com> | 2019-08-28 11:39:15 -0400 |
---|---|---|
committer | pramod.jamkhedkar <pramod@research.att.com> | 2019-08-30 11:12:58 -0400 |
commit | 363398bece860e1c055adf812996b1bdfad6f8df (patch) | |
tree | bde76a972bb18ae0c443cf2e64a41a44034130a1 /models-interactions/model-impl/aai/src/main/java | |
parent | a930b0105c2e45a657427cfcb41fc0330d0c2e99 (diff) |
Added VFModule count
Added the function VFModuleCount to AaiCqResponse class. It counts the
number of vf modules. Also changed the same custom query response in
AaiSimulator.
Issue-ID: POLICY-1858
Signed-off-by: pramod.jamkhedkar <pramod@research.att.com>
Change-Id: If08de84f74d2bd9501b501b881cdd761089614dc
Diffstat (limited to 'models-interactions/model-impl/aai/src/main/java')
-rw-r--r-- | models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java | 106 |
1 files changed, 65 insertions, 41 deletions
diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java index dea11d563..ca0c1867f 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java @@ -55,7 +55,6 @@ public class AaiCqResponse { private static JAXBContext jaxbContext; private static Unmarshaller unmarshaller; - // JABX initial stuff static { Map<String, Object> properties = new HashMap<>(); @@ -63,8 +62,12 @@ public class AaiCqResponse { properties.put(JAXBContextProperties.JSON_INCLUDE_ROOT, false); // Define JAXB context try { - jaxbContext = JAXBContextFactory.createContext(new Class[] {Vserver.class, GenericVnf.class, VfModule.class, - CloudRegion.class, ServiceInstance.class, Tenant.class, ModelVer.class}, properties); + jaxbContext = + JAXBContextFactory + .createContext( + new Class[] {Vserver.class, GenericVnf.class, VfModule.class, + CloudRegion.class, ServiceInstance.class, Tenant.class, ModelVer.class}, + properties); unmarshaller = jaxbContext.createUnmarshaller(); } catch (JAXBException e) { LOGGER.error("Could not initialize JAXBContext", e); @@ -75,11 +78,11 @@ public class AaiCqResponse { @SerializedName("results") private List<Object> inventoryResponseItems = new LinkedList<>(); - /** * Constructor creates a custom query response from a valid json string. * - * @param jsonString A&AI Custom Query response JSON string + * @param jsonString + * A&AI Custom Query response JSON string */ public AaiCqResponse(String jsonString) { @@ -95,8 +98,8 @@ public class AaiCqResponse { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( - new StringReader(resultsArray.getJSONObject(i).getJSONObject("vserver").toString())); + StreamSource json = new StreamSource(new StringReader( + resultsArray.getJSONObject(i).getJSONObject("vserver").toString())); // Getting the vserver pojo again from the json Vserver vserver = this.getAaiObject(json, Vserver.class); @@ -107,8 +110,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has(GENERIC_VNF)) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( - new StringReader(resultsArray.getJSONObject(i).getJSONObject(GENERIC_VNF).toString())); + StreamSource json = new StreamSource(new StringReader( + resultsArray.getJSONObject(i).getJSONObject(GENERIC_VNF).toString())); // Getting the generic vnf pojo again from the json GenericVnf genericVnf = this.getAaiObject(json, GenericVnf.class); @@ -121,8 +124,8 @@ public class AaiCqResponse { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( - new StringReader(resultsArray.getJSONObject(i).getJSONObject("service-instance").toString())); + StreamSource json = new StreamSource(new StringReader( + resultsArray.getJSONObject(i).getJSONObject("service-instance").toString())); // Getting the employee pojo again from the json ServiceInstance serviceInstance = this.getAaiObject(json, ServiceInstance.class); @@ -134,8 +137,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has(VF_MODULE)) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( - new StringReader(resultsArray.getJSONObject(i).getJSONObject(VF_MODULE).toString())); + StreamSource json = new StreamSource(new StringReader( + resultsArray.getJSONObject(i).getJSONObject(VF_MODULE).toString())); // Getting the vf module pojo again from the json VfModule vfModule = this.getAaiObject(json, VfModule.class); @@ -147,8 +150,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has("cloud-region")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( - new StringReader(resultsArray.getJSONObject(i).getJSONObject("cloud-region").toString())); + StreamSource json = new StreamSource(new StringReader( + resultsArray.getJSONObject(i).getJSONObject("cloud-region").toString())); // Getting the cloud region pojo again from the json CloudRegion cloudRegion = this.getAaiObject(json, CloudRegion.class); @@ -160,8 +163,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has("tenant")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( - new StringReader(resultsArray.getJSONObject(i).getJSONObject("tenant").toString())); + StreamSource json = new StreamSource(new StringReader( + resultsArray.getJSONObject(i).getJSONObject("tenant").toString())); // Getting the tenant pojo again from the json Tenant tenant = this.getAaiObject(json, Tenant.class); @@ -173,8 +176,8 @@ public class AaiCqResponse { if (resultsArray.getJSONObject(i).has("model-ver")) { // Create the StreamSource by creating StringReader using the // JSON input - StreamSource json = new StreamSource( - new StringReader(resultsArray.getJSONObject(i).getJSONObject("model-ver").toString())); + StreamSource json = new StreamSource(new StringReader( + resultsArray.getJSONObject(i).getJSONObject("model-ver").toString())); // Getting the ModelVer pojo again from the json ModelVer modelVer = this.getAaiObject(json, ModelVer.class); @@ -184,12 +187,8 @@ public class AaiCqResponse { } - - } - - private <T> T getAaiObject(StreamSource json, final Class<T> classOfResponse) { try { return unmarshaller.unmarshal(json, classOfResponse).getValue(); @@ -210,7 +209,8 @@ public class AaiCqResponse { /** * Get list of A&AI objects in the custom query. * - * @param classOfResponse Class of the type of A&AI objects to be returned + * @param classOfResponse + * Class of the type of A&AI objects to be returned * @return List A&AI objects matching the class */ @SuppressWarnings("unchecked") @@ -289,11 +289,11 @@ public class AaiCqResponse { } - /** * Returns a generic Vnf matching vnf name. * - * @param vnfName Name of the vnf to match + * @param vnfName + * Name of the vnf to match * @return generic Vnf */ public GenericVnf getGenericVnfByVnfName(String vnfName) { @@ -318,7 +318,8 @@ public class AaiCqResponse { /** * Returns a generic Vnf matching model invariant ID. * - * @param modelInvariantId Name of the vnf to match + * @param modelInvariantId + * Name of the vnf to match * @return generic Vnf */ public GenericVnf getGenericVnfByModelInvariantId(String modelInvariantId) { @@ -340,11 +341,11 @@ public class AaiCqResponse { } - /** * Returns a generic Vnf of a given VF Module ID. * - * @param vfModuleModelInvariantId of the vf module for which vnf is to be returned + * @param vfModuleModelInvariantId + * of the vf module for which vnf is to be returned * @return generic Vnf */ public GenericVnf getGenericVnfByVfModuleModelInvariantId(String vfModuleModelInvariantId) { @@ -354,7 +355,7 @@ public class AaiCqResponse { // Iterate through all the vfModules of that generic Vnf for (VfModule vfMod : genVnf.getVfModules().getVfModule()) { if (vfMod.getModelInvariantId() != null - && vfMod.getModelInvariantId().equals(vfModuleModelInvariantId)) { + && vfMod.getModelInvariantId().equals(vfModuleModelInvariantId)) { return genVnf; } } @@ -362,8 +363,6 @@ public class AaiCqResponse { return null; } - - /** * Get the generic vnf associated with the vserver in the custom query. * @@ -382,7 +381,8 @@ public class AaiCqResponse { String genericVnfId = ""; List<RelationshipData> relationshipData = null; - // Iterate through the list of relationships and get generic vnf relationship data + // Iterate through the list of relationships and get generic vnf + // relationship data for (Relationship r : relations) { // Get the name of generic-vnf related to this server if (GENERIC_VNF.equals(r.getRelatedTo())) { @@ -410,7 +410,6 @@ public class AaiCqResponse { return genericVnf; } - /** * Get Vf Module associated with the vserver in the custom query. * @@ -430,7 +429,8 @@ public class AaiCqResponse { String vfModuleId = ""; List<RelationshipData> relationshipData = null; - // Iterate through the list of relationships and get vf module relationship data + // Iterate through the list of relationships and get vf module + // relationship data for (Relationship r : relations) { // Get relationship data of vfmodule related to this server if (VF_MODULE.equals(r.getRelatedTo())) { @@ -461,7 +461,6 @@ public class AaiCqResponse { return vfModule; } - /** * Get vf modules in the custom query. * @@ -494,7 +493,6 @@ public class AaiCqResponse { return vfModule; } - /** * Get Vf Module matching a specific VF model invariant ID. * @@ -504,7 +502,8 @@ public class AaiCqResponse { VfModule vfModule = null; for (VfModule vfMod : this.getAllVfModules()) { - if (vfMod.getModelInvariantId() != null && vfModelInvariantId.equals(vfMod.getModelInvariantId())) { + if (vfMod.getModelInvariantId() != null + && vfModelInvariantId.equals(vfMod.getModelInvariantId())) { vfModule = vfMod; } @@ -543,8 +542,6 @@ public class AaiCqResponse { return modelVerList; } - - /** * Get ModelVer matching a specific version id. * @@ -562,5 +559,32 @@ public class AaiCqResponse { return modelVer; } -} + /** + * Get the count of vfModules matching customizationId, InvariantId and + * VersionId. + * + * @param custId + * ModelCustomizationId + * @param invId + * ModelInvariantId + * @param verId + * ModelVersionId + * @return Returns the count of vf modules + */ + public int getVfModuleCount(String custId, String invId, String verId) { + List<VfModule> vfModuleList = this.getAllVfModules(); + int count = 0; + for (VfModule vfModule : vfModuleList) { + if (vfModule.getModelCustomizationId() != null && vfModule.getModelInvariantId() != null + && vfModule.getModelVersionId() != null) { + if (vfModule.getModelCustomizationId().equals(custId) + && vfModule.getModelInvariantId().equals(invId) + && vfModule.getModelVersionId().equals(verId)) { + count = count + 1; + } + } + } + return count; + } +} |