c8955a0c63805cf0181624ee1a40dfd539851767
[vfc/nfvo/catalog.git] /
1 /**
2  *     Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
3  *
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
7  *
8  *             http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.openo.orchestrator.nfv.catalog.model.externalservice.entity.containerEntity;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlAttribute;
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlElementWrapper;
26 import javax.xml.bind.annotation.XmlRootElement;
27
28 import org.openo.orchestrator.nfv.catalog.common.ToolUtil;
29
30
31 @XmlRootElement
32 @XmlAccessorType(XmlAccessType.NONE)
33 public class ContainerServiceNodeTemplate {
34
35     @XmlAttribute(name = "nodetemplateid")
36     private String id;
37
38     @XmlAttribute(name = "nodetemplatename")
39     private String name;
40
41     @XmlAttribute
42     private String type;
43
44     @XmlElementWrapper(name = "properties")
45     @XmlElement(name = "property")
46     private List<ContainerServiceCommonParam> properties;
47
48     @XmlElementWrapper(name = "relationshipInfos")
49     @XmlElement(name = "relationship")
50     private List<ContainerServiceRelationShip> relationShips;
51
52     @XmlElement(name = "Capabilities")
53     private ContainerServiceNodeTemplate.Capablitiies capabilities;
54
55     public ContainerServiceNodeTemplate.Capablitiies getCapabilities() {
56         return capabilities;
57     }
58
59     public void setCapabilities(
60             ContainerServiceNodeTemplate.Capablitiies capabilities) {
61         this.capabilities = capabilities;
62     }
63
64     public String getId() {
65         return id;
66     }
67
68     public void setId(String id) {
69         this.id = id;
70     }
71
72     public String getName() {
73         return name;
74     }
75
76     public void setName(String name) {
77         this.name = name;
78     }
79
80     public String getType() {
81         return type;
82     }
83
84     public void setType(String type) {
85         this.type = type;
86     }
87
88     public List<ContainerServiceCommonParam> getProperties() {
89         return properties;
90     }
91
92     public void setProperties(List<ContainerServiceCommonParam> properties) {
93         this.properties = properties;
94     }
95
96     public List<ContainerServiceRelationShip> getRelationShips() {
97         return relationShips;
98     }
99
100     public void setRelationShips(
101             List<ContainerServiceRelationShip> relationShips) {
102         this.relationShips = relationShips;
103     }
104
105     @XmlRootElement
106     @XmlAccessorType(XmlAccessType.NONE)
107     public static class Capablitiies {
108         @XmlElement(name = "Capability")
109         private List<ContainerServiceNodeTemplate.Capability> capabilityList;
110
111         public List<ContainerServiceNodeTemplate.Capability> getCapabilityList() {
112             return capabilityList;
113         }
114
115         public void setCapabilityList(
116                 List<ContainerServiceNodeTemplate.Capability> capabilityList) {
117             this.capabilityList = capabilityList;
118         }
119     }
120
121     @XmlRootElement
122     @XmlAccessorType(XmlAccessType.NONE)
123     public static class Capability {
124         @XmlAttribute(name = "id")
125         private String flavorName;
126
127         @XmlElement(name = "Properties")
128         private ContainerServiceNodeTemplate.CapabilityProperties properties;
129
130         public String getFlavorName() {
131             return flavorName;
132         }
133
134         public void setFlavorName(String flavorName) {
135             this.flavorName = flavorName;
136         }
137
138         public ContainerServiceNodeTemplate.CapabilityProperties getProperties() {
139             return properties;
140         }
141
142         public void setProperties(
143                 ContainerServiceNodeTemplate.CapabilityProperties properties) {
144             this.properties = properties;
145         }
146
147     }
148
149     @XmlRootElement
150     @XmlAccessorType(XmlAccessType.NONE)
151     public static class CapabilityProperties {
152         @XmlElement(name = "Properties")
153         private ContainerServiceNodeTemplate.CapabilityProperty property;
154
155         public ContainerServiceNodeTemplate.CapabilityProperty getProperty() {
156             return property;
157         }
158
159         public void setProperty(
160                 ContainerServiceNodeTemplate.CapabilityProperty property) {
161             this.property = property;
162         }
163     }
164
165     @XmlRootElement
166     @XmlAccessorType(XmlAccessType.FIELD)
167     public static class CapabilityProperty {
168         @XmlElement
169         private String vCPU;
170
171         @XmlElement
172         private String vRAM;
173
174         @XmlElement
175         private String rootDisk;
176
177         @XmlElement
178         private String swapDisk;
179
180         @XmlElement
181         private String tempDisk;
182
183         public String getvCPU() {
184             return vCPU;
185         }
186
187         public void setvCPU(String vCPU) {
188             this.vCPU = vCPU;
189         }
190
191         public String getvRAM() {
192             return vRAM;
193         }
194
195         public void setvRAM(String vRAM) {
196             this.vRAM = vRAM;
197         }
198
199         public String getRootDisk() {
200             return rootDisk;
201         }
202
203         public void setRootDisk(String rootDisk) {
204             this.rootDisk = rootDisk;
205         }
206
207         public String getSwapDisk() {
208             return swapDisk;
209         }
210
211         public void setSwapDisk(String swapDisk) {
212             this.swapDisk = swapDisk;
213         }
214
215         public String getTempDisk() {
216             return tempDisk;
217         }
218
219         public void setTempDisk(String tempDisk) {
220             this.tempDisk = tempDisk;
221         }
222     }
223
224     public class NTFlavor {
225         private String flavorName;
226
227         private String vCPU;
228
229         private String vRAM;
230
231         private String rootDisk;
232
233         private String swapDisk;
234
235         private String tempDisk;
236
237         public String getFlavorName() {
238             return flavorName;
239         }
240
241         public void setFlavorName(String flavorName) {
242             this.flavorName = flavorName;
243         }
244
245         public String getvCPU() {
246             return vCPU;
247         }
248
249         public void setvCPU(String vCPU) {
250             this.vCPU = vCPU;
251         }
252
253         public String getvRAM() {
254             return vRAM;
255         }
256
257         public void setvRAM(String vRAM) {
258             this.vRAM = vRAM;
259         }
260
261         public String getRootDisk() {
262             return rootDisk;
263         }
264
265         public void setRootDisk(String rootDisk) {
266             this.rootDisk = rootDisk;
267         }
268
269         public String getSwapDisk() {
270             return swapDisk;
271         }
272
273         public void setSwapDisk(String swapDisk) {
274             this.swapDisk = swapDisk;
275         }
276
277         public String getTempDisk() {
278             return tempDisk;
279         }
280
281         public void setTempDisk(String tempDisk) {
282             this.tempDisk = tempDisk;
283         }
284
285     }
286
287     public List<NTFlavor> getNTFlavorList() {
288         if (null == this.capabilities
289                 || ToolUtil.isEmptyCollection(capabilities.getCapabilityList())) {
290             return null;
291         }
292
293         List<NTFlavor> ntFlavors = new ArrayList<NTFlavor>();
294         List<Capability> capabilityList = capabilities.getCapabilityList();
295         for (Capability capabilty : capabilityList) {
296             NTFlavor ntFlavor = convertCap2Flavor(capabilty);
297             ntFlavors.add(ntFlavor);
298         }
299
300         return ntFlavors;
301     }
302
303     private NTFlavor convertCap2Flavor(Capability capabilty) {
304         NTFlavor ntFlavor = new NTFlavor();
305         ntFlavor.setFlavorName(capabilty.getFlavorName());
306         if (null != capabilty.getProperties()
307                 && null != capabilty.getProperties().getProperty()) {
308             CapabilityProperty property = capabilty.getProperties()
309                     .getProperty();
310             ntFlavor.setRootDisk(property.getRootDisk());
311             ntFlavor.setSwapDisk(property.getSwapDisk());
312             ntFlavor.setTempDisk(property.getTempDisk());
313             ntFlavor.setvCPU(property.getvCPU());
314             ntFlavor.setvRAM(property.getvRAM());
315         }
316
317         return ntFlavor;
318     }
319
320 }