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.util;
19 import com.google.gson.JsonElement;
20 import com.google.gson.JsonObject;
21 import org.slf4j.Logger;
24 * Collection of utility functions
26 public class CbamUtils {
29 * Separator for multiple keys concatenated into a single string
31 public static final String SEPARATOR = "_";
38 * @param parent the parent JSON object
39 * @param name the name of the child
40 * @return the child JSON object of parent with given name
42 public static JsonObject child(JsonObject parent, String name) {
43 return childElement(parent, name).getAsJsonObject();
47 * @param parent the parent JSON object
48 * @param name the name of the child
49 * @return the child JSON object of parent with given name
51 public static JsonElement childElement(JsonObject parent, String name) {
52 JsonElement child = parent.get(name);
54 throw new OperationMustBeAborted("Missing child " + name);
60 * Logs and returns a runtime exception
62 * @param logger the logger
63 * @param msg the error message
64 * @param e the exception to be wrapped
65 * @return never reached (runtime exception is thrown)
67 public static RuntimeException buildFatalFailure(Logger logger, String msg, Exception e) {
69 return new OperationMustBeAborted(e, msg);
73 * Logs and returns a runtime exception
75 * @param logger the logger
76 * @param msg the error message
77 * @return never reached (runtime exception is thrown)
79 public static RuntimeException buildFatalFailure(Logger logger, String msg) {
81 return new OperationMustBeAborted(msg);
84 private static class OperationMustBeAborted extends RuntimeException {
85 OperationMustBeAborted(String msg) {
89 OperationMustBeAborted(Exception e, String msg) {