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