X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=nokiav2%2Fdriver%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvfc%2Fnfvo%2Fdriver%2Fvnfm%2Fsvnfm%2Fnokia%2Fpackagetransformer%2FOnapVnfdBuilder.java;h=dcac5cdf6313ae1c32f10d9cfb7c1c2db023f02c;hb=refs%2Fchanges%2F59%2F38259%2F4;hp=03c27a83eff0579d4860898f758e02be2681afea;hpb=817338bc7da3127ff01e6736d284a081461f484b;p=vfc%2Fnfvo%2Fdriver%2Fvnfm%2Fsvnfm.git 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 03c27a83..dcac5cdf 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 @@ -21,25 +21,25 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import org.jetbrains.annotations.Nullable; -import org.yaml.snakeyaml.Yaml; - import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.yaml.snakeyaml.Yaml; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.childElement; +import static org.slf4j.LoggerFactory.getLogger; /** * Transforms a CBAM package into an ONAP package */ public class OnapVnfdBuilder { - public static final String DESCRIPTION = "description"; public static final String PROPERTIES = "properties"; public static final String REQUIREMENTS = "requirements"; + private static Logger logger = getLogger(OnapVnfdBuilder.class); @VisibleForTesting static String indent(String content, int prefixSize) { @@ -63,24 +63,18 @@ public class OnapVnfdBuilder { StringBuilder body = new StringBuilder(); for (Map.Entry node : nodeTemplates) { String type = childElement(node.getValue().getAsJsonObject(), "type").getAsString(); - switch (type) { - case "tosca.nodes.nfv.VDU": - body.append(buildVdu(node.getKey(), node.getValue().getAsJsonObject(), nodeTemplates)); - break; - case "tosca.nodes.nfv.VirtualStorage": - body.append(buildVolume(node.getKey(), node.getValue().getAsJsonObject())); - break; - case "tosca.nodes.nfv.VL": - body.append(buildVl(node.getKey())); - break; - case "tosca.nodes.nfv.ICP": - body.append(buildIcp(node.getKey(), node.getValue().getAsJsonObject())); - break; - case "tosca.nodes.nfv.ECP": - body.append(buildEcp(node.getKey(), node.getValue(), nodeTemplates)); - break; - default: - // + if ("tosca.nodes.nfv.VDU".equals(type)) { + body.append(buildVdu(node.getKey(), node.getValue().getAsJsonObject(), nodeTemplates)); + } else if ("tosca.nodes.nfv.VirtualStorage".equals(type)) { + body.append(buildVolume(node.getKey(), node.getValue().getAsJsonObject())); + } else if ("tosca.nodes.nfv.VL".equals(type)) { + body.append(buildVl(node.getKey())); + } else if ("tosca.nodes.nfv.ICP".equals(type)) { + body.append(buildIcp(node.getKey(), node.getValue().getAsJsonObject())); + } else if ("tosca.nodes.nfv.ECP".equals(type)) { + body.append(buildEcp(node.getKey(), node.getValue(), nodeTemplates)); + } else { + logger.warn("The {} type is not converted", type); } } return buildHeader(topologyTemplate) + body.toString(); @@ -157,28 +151,36 @@ public class OnapVnfdBuilder { if (ecp.getAsJsonObject().has(REQUIREMENTS)) { String icpName = getIcpName(ecp.getAsJsonObject().get(REQUIREMENTS).getAsJsonArray()); if (icpName != null) { - return buildIcp(name, icpName, nodes); + return buildEcpInternal(name, icpName, nodes); + } else { + logger.warn("The {} ecp does not have an internal connection point", name); } + } else { + logger.warn("The {} ecp does not have an requirements section", name); } return ""; } - private String buildIcp(String name, String icpName, Set> nodes) { + private String buildEcpInternal(String ecpName, String icpName, Set> nodes) { JsonObject icpNode = get(icpName, nodes).getAsJsonObject(); if (icpNode.has(REQUIREMENTS)) { - String vdu = getVdu(icpNode.getAsJsonObject().get(REQUIREMENTS).getAsJsonArray()); + String vdu = getVduOfIcp(icpNode.getAsJsonObject().get(REQUIREMENTS).getAsJsonArray()); + //internal connection point is bound to VDU if (vdu != null) { - return buildVduCpd(name, vdu, child(icpNode, PROPERTIES)); + return buildVduCpd(ecpName, vdu, child(icpNode, PROPERTIES)); + } else { + logger.warn("The {} internal connection point of the {} ecp does not have a VDU", icpName, ecpName); } + } else { + logger.warn("The {} internal connection point of the {} ecp does not have a requirements section", icpName, ecpName); } return ""; } - @Nullable - private String getVdu(JsonArray requirements) { + private String getVduOfIcp(JsonArray icpRequirements) { String vdu = null; - for (int i = 0; i < requirements.size(); i++) { - JsonElement requirement = requirements.get(i); + 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)) { @@ -188,7 +190,6 @@ public class OnapVnfdBuilder { return vdu; } - @Nullable private String getIcpName(JsonArray requirements) { String icpName = null; for (int i = 0; i < requirements.size(); i++) { @@ -202,18 +203,6 @@ public class OnapVnfdBuilder { return icpName; } - private String buildVduCpd(String name, String vdu, JsonObject properties) { - return indent(name + ":\n" + - " type: tosca.nodes.nfv.VduCpd\n" + - " " + PROPERTIES + ":\n" + - " layer_protocol: " + childElement(properties, "layer_protocol").getAsString() + "\n" + - " role: leaf\n" + - (properties.has(DESCRIPTION) ? - " description: " + childElement(properties, DESCRIPTION).getAsString() + "\n" : "") + - " requirements:\n" + - " - virtual_binding: " + vdu + "\n", 2); - } - private String buildIcp(String name, JsonObject icp) { if (icp.has(REQUIREMENTS)) { JsonArray requirements = icp.get(REQUIREMENTS).getAsJsonArray(); @@ -225,42 +214,59 @@ public class OnapVnfdBuilder { String s = next.getKey(); if ("virtual_binding".equals(s)) { vdu = next.getValue().getAsString(); - } else if ("virtual_link".equals(s)) { vl = next.getValue().getAsString(); } } - if (vdu != null && vl != null) { + if (vdu == null) { + logger.warn("The {} internal connection point does not have a VDU", name); + } else if (vl == null) { + logger.warn("The {} internal connection point does not have a VL", name); + } else { JsonObject properties = child(icp, PROPERTIES); - return " " + name + ":\n" + - " type: tosca.nodes.nfv.VduCpd\n" + - " " + PROPERTIES + ":\n" + - " layer_protocol: " + childElement(properties, "layer_protocol").getAsString() + "\n" + - " role: leaf\n" + (properties.has(DESCRIPTION) ? - " description: " + childElement(properties, DESCRIPTION).getAsString() + "\n" : "") + - " requirements:\n" + - " - virtual_binding: " + vdu + "\n" + - " - virtual_link: " + vl + "\n"; + return indent(name + ":\n" + + " type: tosca.nodes.nfv.VduCpd\n" + + " " + PROPERTIES + ":\n" + + " layer_protocol: " + childElement(properties, "layer_protocol").getAsString() + "\n" + + " role: leaf\n" + (properties.has(DESCRIPTION) ? + " description: " + childElement(properties, DESCRIPTION).getAsString() + "\n" : "") + + " requirements:\n" + + " - virtual_binding: " + vdu + "\n" + + " - virtual_link: " + vl + "\n", 2); } + } else { + logger.warn("The {} internal connection point does not have a requirements section", name); } return ""; } + private String buildVduCpd(String name, String vdu, JsonObject properties) { + return indent(name + ":\n" + + " type: tosca.nodes.nfv.VduCpd\n" + + " " + PROPERTIES + ":\n" + + " layer_protocol: " + childElement(properties, "layer_protocol").getAsString() + "\n" + + " role: leaf\n" + + (properties.has(DESCRIPTION) ? + " description: " + childElement(properties, DESCRIPTION).getAsString() + "\n" : "") + + " requirements:\n" + + " - virtual_binding: " + vdu + "\n", 2); + } + private String buildVolume(String nodeName, JsonObject volume) { - return " " + nodeName + ":\n" + - " type: tosca.nodes.nfv.VDU.VirtualStorage\n" + - " properties:\n" + - " id: " + nodeName + "\n" + - " type_of_storage: volume\n" + - " size_of_storage: " + childElement(child(volume, PROPERTIES), "size_of_storage").getAsString() + "\n"; + return indent(nodeName + ":\n" + + " type: tosca.nodes.nfv.VDU.VirtualStorage\n" + + " properties:\n" + + " id: " + nodeName + "\n" + + " type_of_storage: volume\n" + + " size_of_storage: " + childElement(child(volume, PROPERTIES), "size_of_storage").getAsString() + "\n", 2); } private String buildVl(String name) { - return " " + name + ":\n" + - " type: tosca.nodes.nfv.VnfVirtualLinkDesc\n" + - " properties:\n" + - " vl_flavours:\n" + - " flavours:\n" + - " flavourId: notUsed\n"; + return indent(name + ":\n" + + " type: tosca.nodes.nfv.VnfVirtualLinkDesc\n" + + " properties:\n" + + " vl_flavours:\n" + + " flavours:\n" + + " flavourId: notUsed\n", 2); } }