- public static String getRequirement(JsonArray requirements, String key) {
- for (int i = 0; i < requirements.size(); i++) {
- JsonElement requirement = requirements.get(i);
- Map.Entry<String, JsonElement> 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
- */
- public String toOnapVnfd(String cbamVnfd) {
- JsonObject root = new Gson().toJsonTree(new Yaml().load(cbamVnfd)).getAsJsonObject();
- JsonObject topologyTemplate = child(root, "topology_template");
- if (topologyTemplate.has("node_templates")) {
- Set<Map.Entry<String, JsonElement>> nodeTemplates = child(topologyTemplate, "node_templates").entrySet();
- StringBuilder body = new StringBuilder();
- for (Map.Entry<String, JsonElement> node : nodeTemplates) {
- String type = childElement(node.getValue().getAsJsonObject(), "type").getAsString();
- 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();
- }
- return buildHeader(topologyTemplate);
- }
-
- private String buildHeader(JsonObject toplogyTemplate) {