Implant vid-app-common org.onap.vid.job (main and test)
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / aaiTree / Vnf.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.vid.model.aaiTree;
22
23 import static org.onap.vid.aai.util.AAITreeConverter.VNF_TYPE;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 public class Vnf extends Node {
29
30     private Map<String, Map<String, VfModule>> vfModules = new HashMap<>();
31     private Map<String, Network> networks = new HashMap<>();
32
33     public Vnf(AAITreeNode node) {
34         super(node);
35         fillCloudConfigurationProperties(this, node.getCloudConfiguration());
36     }
37
38     public Map<String, Map<String, VfModule>> getVfModules() {
39         return vfModules;
40     }
41
42     public void setVfModules(Map<String, Map<String, VfModule>> vfModules) {
43         this.vfModules = vfModules;
44     }
45
46     public Map<String, Network> getNetworks() {
47         return networks;
48     }
49
50     public void setNetworks(Map<String, Network> networks) {
51         this.networks = networks;
52     }
53
54     public static Vnf from(AAITreeNode node) {
55         Vnf vnf = new Vnf(node);
56         if (node.getAdditionalProperties().get(VNF_TYPE) != null) {
57             vnf.setInstanceType(node.getAdditionalProperties().get(VNF_TYPE).toString());
58         }
59
60         node.getChildren().forEach(child -> {
61             if (child.getType() == NodeType.VF_MODULE) {
62                 vnf.getVfModules().putIfAbsent(child.getNodeKey(), new HashMap<>());
63                 vnf.getVfModules().get(child.getNodeKey())
64                         .put(child.getUniqueNodeKey(), VfModule.from(child));
65             } else if (child.getType() == NodeType.NETWORK) {
66                 vnf.getNetworks().put(child.getUniqueNodeKey(), Network.from(child));
67             }
68         });
69
70         return vnf;
71     }
72 }