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