From ce16741b481dbaae3a3447f84efb2b4ce5dffc82 Mon Sep 17 00:00:00 2001 From: Denes Nemeth Date: Wed, 30 May 2018 22:07:40 +0200 Subject: Fix template generator for R2 Change-Id: Ib686f1d29b659b64cb30f702c62ffd0ca4cd3f8b Signed-off-by: Denes Nemeth Issue-ID: VFC-728 --- .../nokia/packagetransformer/OnapVnfdBuilder.java | 60 +++++++--------------- 1 file changed, 18 insertions(+), 42 deletions(-) (limited to 'nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java') diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java index 406f0033..b5dd9616 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfdBuilder.java @@ -56,6 +56,18 @@ public class OnapVnfdBuilder { return data.trim().replaceAll("[^0-9]", ""); } + public static String getRequirement(JsonArray requirements, String key) { + for (int i = 0; i < requirements.size(); i++) { + JsonElement requirement = requirements.get(i); + Map.Entry next = requirement.getAsJsonObject().entrySet().iterator().next(); + String s = next.getKey(); + if (key.equals(s)) { + return next.getValue().getAsString(); + } + } + return null; + } + /** * @param cbamVnfd the CBAM VNFD * @return the converted ONAP VNFD @@ -104,8 +116,8 @@ public class OnapVnfdBuilder { "topology_template:\n" + " inputs:\n" + " etsi_config:\n" + - " type: string\n"+ - " description: The ETSI configuration\n"+ + " type: string\n" + + " description: The ETSI configuration\n" + " node_templates:\n"; } @@ -157,7 +169,7 @@ public class OnapVnfdBuilder { private String buildEcp(String name, JsonElement ecp, Set> nodes) { if (ecp.getAsJsonObject().has(REQUIREMENTS)) { - String icpName = getIcpName(ecp.getAsJsonObject().get(REQUIREMENTS).getAsJsonArray()); + String icpName = getRequirement(ecp.getAsJsonObject().get(REQUIREMENTS).getAsJsonArray(), "internal_connection_point"); if (icpName != null) { return buildEcpInternal(name, icpName, nodes); } else { @@ -172,7 +184,7 @@ public class OnapVnfdBuilder { private String buildEcpInternal(String ecpName, String icpName, Set> nodes) { JsonObject icpNode = get(icpName, nodes).getAsJsonObject(); if (icpNode.has(REQUIREMENTS)) { - String vdu = getVduOfIcp(icpNode.getAsJsonObject().get(REQUIREMENTS).getAsJsonArray()); + String vdu = getRequirement(icpNode.getAsJsonObject().get(REQUIREMENTS).getAsJsonArray(), "virtual_binding"); //internal connection point is bound to VDU if (vdu != null) { return buildVduCpd(ecpName, vdu, child(icpNode, PROPERTIES)); @@ -185,47 +197,11 @@ public class OnapVnfdBuilder { return ""; } - private String getVduOfIcp(JsonArray icpRequirements) { - String vdu = null; - for (int i = 0; i < icpRequirements.size(); i++) { - JsonElement requirement = icpRequirements.get(i); - Map.Entry next = requirement.getAsJsonObject().entrySet().iterator().next(); - String s = next.getKey(); - if ("virtual_binding".equals(s)) { - vdu = next.getValue().getAsString(); - } - } - return vdu; - } - - private String getIcpName(JsonArray requirements) { - String icpName = null; - for (int i = 0; i < requirements.size(); i++) { - JsonElement requirement = requirements.get(i); - Map.Entry next = requirement.getAsJsonObject().entrySet().iterator().next(); - String s = next.getKey(); - if ("internal_connection_point".equals(s)) { - icpName = next.getValue().getAsString(); - } - } - return icpName; - } - private String buildIcp(String name, JsonObject icp) { if (icp.has(REQUIREMENTS)) { JsonArray requirements = icp.get(REQUIREMENTS).getAsJsonArray(); - String vdu = null; - String vl = null; - for (int i = 0; i < requirements.size(); i++) { - JsonElement requirement = requirements.get(i); - Map.Entry next = requirement.getAsJsonObject().entrySet().iterator().next(); - String s = next.getKey(); - if ("virtual_binding".equals(s)) { - vdu = next.getValue().getAsString(); - } else if ("virtual_link".equals(s)) { - vl = next.getValue().getAsString(); - } - } + String vdu = getRequirement(requirements, "virtual_binding"); + String vl = getRequirement(requirements, "virtual_link"); if (vdu == null) { logger.warn("The {} internal connection point does not have a VDU", name); } else if (vl == null) { -- cgit 1.2.3-korg