2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
19 import com.google.common.annotations.VisibleForTesting;
20 import com.google.gson.Gson;
21 import com.google.gson.JsonArray;
22 import com.google.gson.JsonElement;
23 import com.google.gson.JsonObject;
25 import java.util.NoSuchElementException;
27 import java.util.regex.Pattern;
28 import org.slf4j.Logger;
29 import org.yaml.snakeyaml.Yaml;
31 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child;
32 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.childElement;
33 import static org.slf4j.LoggerFactory.getLogger;
36 * Transforms a CBAM package into an ONAP package
38 public class OnapAbstractVnfdBuilder {
39 public static final String DESCRIPTION = "description";
40 public static final String PROPERTIES = "properties";
41 public static final String REQUIREMENTS = "requirements";
42 private static Logger logger = getLogger(OnapAbstractVnfdBuilder.class);
45 static String indent(String content, int prefixSize) {
46 StringBuilder sb = new StringBuilder();
47 for (int i = 0; i < prefixSize; i++) {
50 Pattern pattern = Pattern.compile("^(.*)$", Pattern.MULTILINE);
51 return pattern.matcher(content).replaceAll(sb.toString() + "$1");
54 protected static String getRequirement(JsonArray requirements, String key) {
55 for (int i = 0; i < requirements.size(); i++) {
56 JsonElement requirement = requirements.get(i);
57 Map.Entry<String, JsonElement> next = requirement.getAsJsonObject().entrySet().iterator().next();
58 String s = next.getKey();
60 return next.getValue().getAsString();
66 private JsonElement get(String name, Set<Map.Entry<String, JsonElement>> nodes) {
67 for (Map.Entry<String, JsonElement> node : nodes) {
68 if (name.equals(node.getKey())) {
69 return node.getValue();
72 throw new NoSuchElementException("The VNFD does not have a node called " + name + " but required by an other node");