Merge "Reorder modifiers"
[so.git] / adapters / mso-adapters-rest-interface / src / main / java / org / openecomp / mso / openstack / beans / NetworkInfo.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.openecomp.mso.openstack.beans;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.HashMap;
27
28 import com.woorea.openstack.quantum.model.Network;
29 import com.woorea.openstack.quantum.model.Segment;
30
31 /*
32  * This Java bean class relays Network details (including status) to ActiveVOS processes.
33  *
34  * This bean is returned by all Network-specific adapter operations (create, query, delete)
35  */
36 public class NetworkInfo {
37         // Set defaults for everything
38         private String name = "";
39         private String id = "";
40         private NetworkStatus status = NetworkStatus.UNKNOWN;
41         private String provider = "";
42         private List<Integer> vlans = new ArrayList<>();
43         private List<String> subnets = new ArrayList<>();
44
45         static Map<String,NetworkStatus> NetworkStatusMap;
46         static {
47                 NetworkStatusMap = new HashMap<>();
48                 NetworkStatusMap.put("ACTIVE", NetworkStatus.ACTIVE);
49                 NetworkStatusMap.put("DOWN", NetworkStatus.DOWN);
50                 NetworkStatusMap.put("BUILD", NetworkStatus.BUILD);
51                 NetworkStatusMap.put("ERROR", NetworkStatus.ERROR);
52         }
53
54         /**
55          * Capture the data from a Neutron Network object.
56          *
57          * For MSO, there are assumptions regarding all networks.
58          * - Everything will be a provider network
59          * - All provider networks are VLANs
60          * - Multiple VLANs are supported, and indicated by multi-provider segments.
61          *   Each will have the same physical network & network type "vlan".
62          *
63          * @param network
64          */
65         public NetworkInfo(Network network) {
66                 if (network != null) {
67                         initFieldsWithDataFromNetwork(network);
68                 } else {
69                         status = NetworkStatus.NOTFOUND;
70                 }
71         }
72
73         private void initFieldsWithDataFromNetwork(Network network){
74                 name = network.getName();
75                 id = network.getId();
76
77                 if (network.getStatus() != null && NetworkStatusMap.containsKey(network.getStatus())) {
78                         status = NetworkStatusMap.get(network.getStatus());
79                 }
80                 if (network.getProviderPhysicalNetwork() != null) {
81                         provider = network.getProviderPhysicalNetwork();
82                         if ("vlan".equals(network.getProviderNetworkType())) {
83                 vlans.add(network.getProviderSegmentationId());
84             }
85                 }
86                 else if (network.getSegments() != null && !network.getSegments().isEmpty()) {
87                         Segment s = network.getSegments().get(0);
88                         provider = s.getProviderPhysicalNetwork();
89                         if ("vlan".equals(s.getProviderNetworkType())) {
90                                 network.getSegments().forEach(segment -> vlans.add(segment.getProviderSegmentationId()));
91             }
92                 }
93                 subnets = network.getSubnets();
94         }
95
96         public String getName() {
97                 return name;
98         }
99
100         public void setName (String name) {
101                 this.name = name;
102         }
103
104         public String getId() {
105                 return id;
106         }
107
108         public void setId (String id) {
109                 this.id = id;
110         }
111
112         public NetworkStatus getStatus() {
113                 return status;
114         }
115
116         public void setStatus (NetworkStatus status) {
117                 this.status = status;
118         }
119
120         public String getProvider() {
121                 return provider;
122         }
123
124         public void setProvider (String provider) {
125                 this.provider = provider;
126         }
127
128         public List<Integer> getVlans () {
129                 return vlans;
130         }
131
132         public void setVlans (List<Integer> vlans) {
133                 this.vlans = vlans;
134         }
135
136         public List<String> getSubnets () {
137                 return subnets;
138         }
139
140         @Override
141         public String toString() {
142                 return "NetworkInfo{" + "name='" + name + '\'' +
143                         ", id='" + id + '\'' +
144                         ", status=" + status +
145                         ", provider='" + provider + '\'' +
146                         ", vlans=" + vlans +
147                         ", subnets=" + subnets +
148                         '}';
149         }
150 }
151