2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.model;
23 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
24 import org.onap.vid.asdc.beans.tosca.Input;
25 import org.onap.vid.asdc.beans.tosca.NodeTemplate;
27 import java.util.HashMap;
29 import java.util.Map.Entry;
33 public class Node implements MinimalNode {
34 /** The Constant LOG. */
35 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(Node.class);
40 /** The invariant uuid. */
41 private String invariantUuid;
43 /** The description. */
44 private String description;
50 private String version;
52 /** The model customization uuid. */
53 private String customizationUuid;
56 private Map<String, Input> inputs = new HashMap<>();
58 /** The get_input or other constructs from node template properties. */
59 private Map<String, CommandProperty> commands;
61 /** The get_input or other constructs from node template properties. */
62 private Map<String, String> properties;
64 /** Type from Metadata */
67 * Instantiates a new node.
70 this.commands = new HashMap<>();
71 this.properties = new HashMap<>();
79 public String getUuid() {
84 * Gets the invariant uuid.
86 * @return the invariant uuid
88 public String getInvariantUuid() {
93 * Gets the description.
95 * @return the description
97 public String getDescription() {
106 public String getName() {
113 * @return the version
115 public String getVersion() {
120 * Gets the customization uuid.
122 * @return the model customization uuid
124 public String getCustomizationUuid() {
125 return customizationUuid;
132 public Map<String, Input> getInputs() {
138 * @return the commands
140 public Map<String, CommandProperty> getCommands() {
144 * Gets the properties.
146 * @return the properties
148 public Map<String, String> getProperties() {
154 * @param uuid the new uuid
156 public void setUuid(String uuid) {
161 * Sets the invariant uuid.
163 * @param invariantUuid the new invariant uuid
165 public void setInvariantUuid(String invariantUuid) {
166 this.invariantUuid = invariantUuid;
170 * Sets the description.
172 * @param description the new description
174 public void setDescription(String description) {
175 this.description = description;
181 * @param name the new name
183 public void setName(String name) {
190 * @param version the new version
192 public void setVersion(String version) {
193 this.version = version;
196 * Sets the customization uuid.
198 * @param u the new customization uuid
200 public void setCustomizationUuid(String u) {
201 this.customizationUuid = u;
207 * @param inputs the inputs
209 public void setInputs(Map<String, Input> inputs) {
210 this.inputs = inputs;
215 * @param m the commands
217 public void setCommands( Map<String, CommandProperty>m ) {
221 * Sets the properties.
223 * @param p the properties
225 public void setProperties( Map<String, String>p) {
231 * @return metadata type
233 public String getType() {
240 * @param type e.g. VF/CP/SERVICE_PROXY
242 public void setType(String type) {
249 * @param nodeTemplate the node template
252 public void extractNode (NodeTemplate nodeTemplate) {
254 String methodName = "extractNode";
256 setUuid(nodeTemplate.getMetadata().getUUID());
257 setInvariantUuid(nodeTemplate.getMetadata().getInvariantUUID());
258 setDescription(nodeTemplate.getMetadata().getDescription());
259 setName(nodeTemplate.getMetadata().getName());
260 setVersion(nodeTemplate.getMetadata().getVersion());
261 // add customizationUUID
262 setCustomizationUuid(nodeTemplate.getMetadata().getCustomizationUUID());
265 // nodeTemplate.getProperties() map of String->Object
266 for (Entry<String, Object> entrySet : nodeTemplate.getProperties().entrySet()) {
267 LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " node template property: " + entrySet.getKey());
268 if ( entrySet.getValue() != null ) {
269 readStringAndCommandsProperties(entrySet);
273 catch ( Exception e ) {
274 LOG.error(EELFLoggerDelegate.errorLogger, methodName + " Unable to parse node properties: e=" +
279 private void readStringAndCommandsProperties(Entry<String, Object> entrySet) {
280 String key = entrySet.getKey();
281 String methodName = "readStringAndCommandsProperties";
282 LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " property: " +
283 key + "=" + entrySet.getValue());
284 Class<?> c = entrySet.getValue().getClass();
285 if ( c.getName().equalsIgnoreCase(String.class.getName())) {
286 getProperties().put (key, (String) entrySet.getValue());
289 Class<?>[] interfaces = entrySet.getValue().getClass().getInterfaces();
291 for(Class<?> ifc: interfaces ) {
292 if ( ifc.getName().equalsIgnoreCase(Map.class.getName()) ) {
293 readGetInputAsCommands(entrySet, key);
301 private void readGetInputAsCommands(Entry<String, Object> entrySet, String key) {
302 // only extract get_input for now
303 @SuppressWarnings("unchecked")
304 HashMap<String,String> v = (HashMap<String,String>) entrySet.getValue();
305 for (Entry<String, String> entry : v.entrySet()) {
306 // only include get_input for now
307 if ( ModelConstants.GET_INPUT_TAG.equalsIgnoreCase ( entry.getKey() ) ) {
308 CommandProperty cp = new CommandProperty();
309 cp.setCommand(entry.getKey());
310 cp.setInputName(entry.getValue());
311 cp.setDisplayName(key);
312 getCommands().put(key,cp);