1 | /** |
2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
3 | * contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. jclouds licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | package org.jclouds.cim; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import java.net.URI; |
24 | import java.util.Date; |
25 | import java.util.Map; |
26 | import java.util.Set; |
27 | |
28 | import com.google.common.base.Function; |
29 | import com.google.common.collect.ImmutableSet; |
30 | import com.google.common.collect.Maps; |
31 | import com.google.common.collect.Sets; |
32 | |
33 | /** |
34 | * |
35 | * CIM_VirtualSystemSettingData defines the virtual aspects of a virtual system through a set of |
36 | * virtualization specific properties. CIM_VirtualSystemSettingData is also used as the top level |
37 | * class of virtual system configurations. Virtual system configurations model configuration |
38 | * information about virtual systems and their components. A virtual system configuration consists |
39 | * of one top-level instance of class CIM_VirtualSystemSettingData that aggregates a number of |
40 | * instances of class CIM_ResourceAllocationSettingData, using association CIM_ConcreteComponent. |
41 | * Virtual system configurations may for example be used to reflect configurations of - virtual |
42 | * systems that are defined at a virtualization platform, - virtual systems that are currently |
43 | * active, - input requests to create new virtual systems, - input requests to modify existing |
44 | * virtual systems, or - snapshots of virtual systems. |
45 | * |
46 | * @author Adrian Cole |
47 | * @see <a |
48 | * href="http://dmtf.org/sites/default/files/cim/cim_schema_v2280/cim_schema_2.28.0Final-Doc.zip" |
49 | * /> |
50 | * |
51 | */ |
52 | public class VirtualSystemSettingData extends ManagedElement { |
53 | |
54 | public static Builder builder() { |
55 | return new Builder(); |
56 | } |
57 | |
58 | /** |
59 | * {@inheritDoc} |
60 | */ |
61 | @Override |
62 | public Builder toBuilder() { |
63 | return builder().fromVirtualSystemSettingData(this); |
64 | } |
65 | |
66 | public static class Builder extends ManagedElement.Builder { |
67 | private AutomaticRecoveryAction automaticRecoveryAction; |
68 | private AutomaticShutdownAction automaticShutdownAction; |
69 | private AutomaticStartupAction automaticStartupAction; |
70 | private Long automaticStartupActionDelay; |
71 | private Integer automaticStartupActionSequenceNumber; |
72 | private URI configurationDataRoot; |
73 | private URI configurationFile; |
74 | private String configurationID; |
75 | private Date creationTime; |
76 | private URI logDataRoot; |
77 | private URI recoveryFile; |
78 | private URI snapshotDataRoot; |
79 | private URI suspendDataRoot; |
80 | private URI swapFileDataRoot; |
81 | private String virtualSystemIdentifier; |
82 | private Set<String> virtualSystemTypes = Sets.newLinkedHashSet(); |
83 | private String notes; |
84 | |
85 | public Builder automaticRecoveryAction(AutomaticRecoveryAction automaticRecoveryAction) { |
86 | this.automaticRecoveryAction = automaticRecoveryAction; |
87 | return this; |
88 | } |
89 | |
90 | public Builder automaticShutdownAction(AutomaticShutdownAction automaticShutdownAction) { |
91 | this.automaticShutdownAction = automaticShutdownAction; |
92 | return this; |
93 | } |
94 | |
95 | public Builder automaticStartupAction(AutomaticStartupAction automaticStartupAction) { |
96 | this.automaticStartupAction = automaticStartupAction; |
97 | return this; |
98 | } |
99 | |
100 | public Builder automaticStartupActionDelay(Long automaticStartupActionDelay) { |
101 | this.automaticStartupActionDelay = automaticStartupActionDelay; |
102 | return this; |
103 | } |
104 | |
105 | public Builder automaticStartupActionSequenceNumber(Integer automaticStartupActionSequenceNumber) { |
106 | this.automaticStartupActionSequenceNumber = automaticStartupActionSequenceNumber; |
107 | return this; |
108 | } |
109 | |
110 | public Builder configurationDataRoot(URI configurationDataRoot) { |
111 | this.configurationDataRoot = configurationDataRoot; |
112 | return this; |
113 | } |
114 | |
115 | public Builder configurationFile(URI configurationFile) { |
116 | this.configurationFile = configurationFile; |
117 | return this; |
118 | } |
119 | |
120 | public Builder configurationID(String configurationID) { |
121 | this.configurationID = configurationID; |
122 | return this; |
123 | } |
124 | |
125 | public Builder creationTime(Date creationTime) { |
126 | this.creationTime = creationTime; |
127 | return this; |
128 | } |
129 | |
130 | public Builder logDataRoot(URI logDataRoot) { |
131 | this.logDataRoot = logDataRoot; |
132 | return this; |
133 | } |
134 | |
135 | public Builder recoveryFile(URI recoveryFile) { |
136 | this.recoveryFile = recoveryFile; |
137 | return this; |
138 | } |
139 | |
140 | public Builder snapshotDataRoot(URI snapshotDataRoot) { |
141 | this.snapshotDataRoot = snapshotDataRoot; |
142 | return this; |
143 | } |
144 | |
145 | public Builder suspendDataRoot(URI suspendDataRoot) { |
146 | this.suspendDataRoot = suspendDataRoot; |
147 | return this; |
148 | } |
149 | |
150 | public Builder swapFileDataRoot(URI swapFileDataRoot) { |
151 | this.swapFileDataRoot = swapFileDataRoot; |
152 | return this; |
153 | } |
154 | |
155 | public Builder virtualSystemIdentifier(String virtualSystemIdentifier) { |
156 | this.virtualSystemIdentifier = virtualSystemIdentifier; |
157 | return this; |
158 | } |
159 | |
160 | public Builder virtualSystemTypes(Iterable<String> virtualSystemTypes) { |
161 | this.virtualSystemTypes = ImmutableSet.copyOf(checkNotNull(virtualSystemTypes, "virtualSystemTypes")); |
162 | return this; |
163 | } |
164 | |
165 | public Builder virtualSystemType(String virtualSystemType) { |
166 | this.virtualSystemTypes.add(checkNotNull(virtualSystemType, "virtualSystemType")); |
167 | return this; |
168 | } |
169 | |
170 | public Builder notes(String notes) { |
171 | this.notes = notes; |
172 | return this; |
173 | } |
174 | |
175 | public VirtualSystemSettingData build() { |
176 | return new VirtualSystemSettingData(elementName, instanceID, caption, description, automaticRecoveryAction, |
177 | automaticShutdownAction, automaticStartupAction, automaticStartupActionDelay, |
178 | automaticStartupActionSequenceNumber, configurationDataRoot, configurationFile, configurationID, |
179 | creationTime, logDataRoot, recoveryFile, snapshotDataRoot, suspendDataRoot, swapFileDataRoot, |
180 | virtualSystemIdentifier, virtualSystemTypes, notes); |
181 | } |
182 | |
183 | public Builder fromVirtualSystemSettingData(VirtualSystemSettingData in) { |
184 | return fromManagedElement(in).automaticRecoveryAction(in.getAutomaticRecoveryAction()) |
185 | .automaticShutdownAction(in.getAutomaticShutdownAction()).automaticStartupAction( |
186 | in.getAutomaticStartupAction()).automaticStartupActionDelay( |
187 | in.getAutomaticStartupActionDelay()).automaticStartupActionSequenceNumber( |
188 | in.getAutomaticStartupActionSequenceNumber()).configurationDataRoot( |
189 | in.getConfigurationDataRoot()).configurationFile(in.getConfigurationFile()).configurationID( |
190 | in.getConfigurationID()).creationTime(in.getCreationTime()).logDataRoot(in.getLogDataRoot()) |
191 | .recoveryFile(in.getRecoveryFile()).snapshotDataRoot(in.getSnapshotDataRoot()).suspendDataRoot( |
192 | in.getSuspendDataRoot()).swapFileDataRoot(in.getSwapFileDataRoot()).virtualSystemIdentifier( |
193 | in.getVirtualSystemIdentifier()).virtualSystemTypes(in.getVirtualSystemTypes()).notes( |
194 | in.getNotes()); |
195 | } |
196 | |
197 | /** |
198 | * {@inheritDoc} |
199 | */ |
200 | @Override |
201 | public Builder fromManagedElement(ManagedElement in) { |
202 | return Builder.class.cast(super.fromManagedElement(in)); |
203 | } |
204 | |
205 | /** |
206 | * {@inheritDoc} |
207 | */ |
208 | @Override |
209 | public Builder caption(String caption) { |
210 | return Builder.class.cast(super.caption(caption)); |
211 | } |
212 | |
213 | /** |
214 | * {@inheritDoc} |
215 | */ |
216 | @Override |
217 | public Builder description(String description) { |
218 | return Builder.class.cast(super.description(description)); |
219 | } |
220 | |
221 | /** |
222 | * {@inheritDoc} |
223 | */ |
224 | @Override |
225 | public Builder elementName(String elementName) { |
226 | return Builder.class.cast(super.elementName(elementName)); |
227 | } |
228 | |
229 | /** |
230 | * {@inheritDoc} |
231 | */ |
232 | @Override |
233 | public Builder instanceID(String instanceID) { |
234 | return Builder.class.cast(super.instanceID(instanceID)); |
235 | } |
236 | |
237 | } |
238 | |
239 | /** |
240 | * Action to take for the virtual system when the software executed by the virtual system fails. |
241 | * Failures in this case means a failure that is detectable by the host platform, such as a |
242 | * non-interuptable wait state condition. |
243 | */ |
244 | public static enum AutomaticRecoveryAction { |
245 | |
246 | NONE(2), |
247 | |
248 | RESTART(3), |
249 | |
250 | REVERT_TO_SNAPSHOT(4); |
251 | |
252 | protected final int code; |
253 | |
254 | AutomaticRecoveryAction(int code) { |
255 | this.code = code; |
256 | } |
257 | |
258 | public String value() { |
259 | return code + ""; |
260 | } |
261 | |
262 | protected final static Map<Integer, AutomaticRecoveryAction> AUTOMATIC_RECOVERY_ACTION_BY_ID = Maps.uniqueIndex( |
263 | ImmutableSet.copyOf(AutomaticRecoveryAction.values()), new Function<AutomaticRecoveryAction, Integer>() { |
264 | |
265 | @Override |
266 | public Integer apply(AutomaticRecoveryAction input) { |
267 | return input.code; |
268 | } |
269 | |
270 | }); |
271 | |
272 | public static AutomaticRecoveryAction fromValue(String automaticRecoveryAction) { |
273 | return AUTOMATIC_RECOVERY_ACTION_BY_ID.get(new Integer(checkNotNull(automaticRecoveryAction, |
274 | "automaticRecoveryAction"))); |
275 | } |
276 | } |
277 | |
278 | /** |
279 | * Action to take for the virtual system when the host is shut down. |
280 | */ |
281 | public static enum AutomaticShutdownAction { |
282 | |
283 | TURN_OFF(2), |
284 | |
285 | SAVE_STATE(3), |
286 | |
287 | SHUTDOWN(4); |
288 | |
289 | protected final int code; |
290 | |
291 | AutomaticShutdownAction(int code) { |
292 | this.code = code; |
293 | } |
294 | |
295 | public String value() { |
296 | return code + ""; |
297 | } |
298 | |
299 | protected final static Map<Integer, AutomaticShutdownAction> AUTOMATIC_SHUTDOWN_ACTION_BY_ID = Maps.uniqueIndex( |
300 | ImmutableSet.copyOf(AutomaticShutdownAction.values()), new Function<AutomaticShutdownAction, Integer>() { |
301 | |
302 | @Override |
303 | public Integer apply(AutomaticShutdownAction input) { |
304 | return input.code; |
305 | } |
306 | |
307 | }); |
308 | |
309 | public static AutomaticShutdownAction fromValue(String automaticShutdownAction) { |
310 | return AUTOMATIC_SHUTDOWN_ACTION_BY_ID.get(new Integer(checkNotNull(automaticShutdownAction, |
311 | "automaticShutdownAction"))); |
312 | } |
313 | } |
314 | |
315 | /** |
316 | * Action to take for the virtual system when the host is started. |
317 | */ |
318 | public static enum AutomaticStartupAction { |
319 | |
320 | NONE(2), |
321 | |
322 | RESTART_IF_PREVIOUSLY_ACTIVE(3), |
323 | |
324 | ALWAYS_STARTUP(4); |
325 | |
326 | protected final int code; |
327 | |
328 | AutomaticStartupAction(int code) { |
329 | this.code = code; |
330 | } |
331 | |
332 | public String value() { |
333 | return code + ""; |
334 | } |
335 | |
336 | protected final static Map<Integer, AutomaticStartupAction> AUTOMATIC_STARTUP_ACTION_BY_ID = Maps.uniqueIndex( |
337 | ImmutableSet.copyOf(AutomaticStartupAction.values()), new Function<AutomaticStartupAction, Integer>() { |
338 | |
339 | @Override |
340 | public Integer apply(AutomaticStartupAction input) { |
341 | return input.code; |
342 | } |
343 | |
344 | }); |
345 | |
346 | public static AutomaticStartupAction fromValue(String automaticStartupAction) { |
347 | return AUTOMATIC_STARTUP_ACTION_BY_ID.get(new Integer(checkNotNull(automaticStartupAction, |
348 | "automaticStartupAction"))); |
349 | } |
350 | } |
351 | |
352 | private final AutomaticRecoveryAction automaticRecoveryAction; |
353 | private final AutomaticShutdownAction automaticShutdownAction; |
354 | private final AutomaticStartupAction automaticStartupAction; |
355 | private final Long automaticStartupActionDelay; |
356 | private final Integer automaticStartupActionSequenceNumber; |
357 | private final URI configurationDataRoot; |
358 | private final URI configurationFile; |
359 | private final String configurationID; |
360 | private final Date creationTime; |
361 | private final URI logDataRoot; |
362 | private final URI recoveryFile; |
363 | private final URI snapshotDataRoot; |
364 | private final URI suspendDataRoot; |
365 | private final URI swapFileDataRoot; |
366 | private final String virtualSystemIdentifier; |
367 | private final Set<String> virtualSystemTypes; |
368 | private final String notes; |
369 | |
370 | public VirtualSystemSettingData(String elementName, String instanceID, String caption, String description, |
371 | AutomaticRecoveryAction automaticRecoveryAction, AutomaticShutdownAction automaticShutdownAction, |
372 | AutomaticStartupAction automaticStartupAction, Long automaticStartupActionDelay, |
373 | Integer automaticStartupActionSequenceNumber, URI configurationDataRoot, URI configurationFile, |
374 | String configurationID, Date creationTime, URI logDataRoot, URI recoveryFile, URI snapshotDataRoot, |
375 | URI suspendDataRoot, URI swapFileDataRoot, String virtualSystemIdentifier, |
376 | Iterable<String> virtualSystemTypes, String notes) { |
377 | super(elementName, instanceID, caption, description); |
378 | this.automaticRecoveryAction = automaticRecoveryAction; |
379 | this.automaticShutdownAction = automaticShutdownAction; |
380 | this.automaticStartupAction = automaticStartupAction; |
381 | this.automaticStartupActionDelay = automaticStartupActionDelay; |
382 | this.automaticStartupActionSequenceNumber = automaticStartupActionSequenceNumber; |
383 | this.configurationDataRoot = configurationDataRoot; |
384 | this.configurationFile = configurationFile; |
385 | this.configurationID = configurationID; |
386 | this.creationTime = creationTime; |
387 | this.logDataRoot = logDataRoot; |
388 | this.recoveryFile = recoveryFile; |
389 | this.snapshotDataRoot = snapshotDataRoot; |
390 | this.suspendDataRoot = suspendDataRoot; |
391 | this.swapFileDataRoot = swapFileDataRoot; |
392 | this.virtualSystemIdentifier = virtualSystemIdentifier; |
393 | this.virtualSystemTypes = ImmutableSet.copyOf(checkNotNull(virtualSystemTypes, "virtualSystemTypes")); |
394 | this.notes = notes; |
395 | } |
396 | |
397 | /** |
398 | * Action to take for the virtual system when the software executed by the virtual system fails. |
399 | * Failures in this case means a failure that is detectable by the host platform, such as a |
400 | * non-interuptable wait state condition. |
401 | */ |
402 | public AutomaticRecoveryAction getAutomaticRecoveryAction() { |
403 | return automaticRecoveryAction; |
404 | } |
405 | |
406 | /** |
407 | * Action to take for the virtual system when the host is shut down. |
408 | */ |
409 | public AutomaticShutdownAction getAutomaticShutdownAction() { |
410 | return automaticShutdownAction; |
411 | } |
412 | |
413 | /** |
414 | * Action to take for the virtual system when the host is started. |
415 | */ |
416 | public AutomaticStartupAction getAutomaticStartupAction() { |
417 | return automaticStartupAction; |
418 | } |
419 | |
420 | /** |
421 | * Delay applicable to startup action. The value shall be in the interval variant of the datetime |
422 | * datatype. |
423 | */ |
424 | public Long getAutomaticStartupActionDelay() { |
425 | return automaticStartupActionDelay; |
426 | } |
427 | |
428 | /** |
429 | * Number indicating the relative sequence of virtual system activation when the host system is |
430 | * started. A lower number indicates earlier activation. If one or more configurations show the |
431 | * same value, the sequence is implementation dependent. A value of 0 indicates that the sequence |
432 | * is implementation dependent. |
433 | */ |
434 | public Integer getAutomaticStartupActionSequenceNumber() { |
435 | return automaticStartupActionSequenceNumber; |
436 | } |
437 | |
438 | /** |
439 | * Filepath of a directory where information about the virtual system configuration is |
440 | * stored.Format shall be URI based on RFC 2079. |
441 | */ |
442 | public URI getConfigurationDataRoot() { |
443 | return configurationDataRoot; |
444 | } |
445 | |
446 | /** |
447 | * Filepath of a file where information about the virtual system configuration is stored. A |
448 | * relative path appends to the value of the ConfigurationDataRoot property.Format shall be URI |
449 | * based on RFC 2079. |
450 | */ |
451 | public URI getConfigurationFile() { |
452 | return configurationFile; |
453 | } |
454 | |
455 | /** |
456 | * Unique id of the virtual system configuration. Note that the ConfigurationID is different from |
457 | * the InstanceID as it is assigned by the implementation to a virtual system or a virtual system |
458 | * configuration. It is not a key, and the same value may occur within more than one instance. |
459 | */ |
460 | public String getConfigurationID() { |
461 | return configurationID; |
462 | } |
463 | |
464 | /** |
465 | * Time when the virtual system configuration was created. |
466 | */ |
467 | public Date getCreationTime() { |
468 | return creationTime; |
469 | } |
470 | |
471 | /** |
472 | * Filepath of a directory where log information about the virtual system is stored. A relative |
473 | * path appends to the value of the ConfigurationDataRoot property.Format shall be URI based on |
474 | * RFC 2079. |
475 | */ |
476 | public URI getLogDataRoot() { |
477 | return logDataRoot; |
478 | } |
479 | |
480 | /** |
481 | * Filepath of a file where recovery relateded information of the virtual system is stored.Format |
482 | * shall be URI based on RFC 2079. |
483 | */ |
484 | public URI getRecoveryFile() { |
485 | return recoveryFile; |
486 | } |
487 | |
488 | /** |
489 | * Filepath of a directory where information about virtual system snapshots is stored. A relative |
490 | * path appends to the value of the ConfigurationDataRoot property.Format shall be URI based on |
491 | * RFC 2079. |
492 | */ |
493 | public URI getSnapshotDataRoot() { |
494 | return snapshotDataRoot; |
495 | } |
496 | |
497 | /** |
498 | * Filepath of a directory where suspend related information about the virtual system is stored. |
499 | * A relative path appends to the value of the ConfigurationDataRoot property.Format shall be URI |
500 | * based on RFC 2079. |
501 | */ |
502 | public URI getSuspendDataRoot() { |
503 | return suspendDataRoot; |
504 | } |
505 | |
506 | /** |
507 | * Filepath of a directory where swapfiles of the virtual system are stored. A relative path |
508 | * appends to the value of the ConfigurationDataRoot property.Format shall be URI based on RFC |
509 | * 2079. |
510 | */ |
511 | public URI getSwapFileDataRoot() { |
512 | return swapFileDataRoot; |
513 | } |
514 | |
515 | /** |
516 | * VirtualSystemIdentifier shall reflect a unique name for the system as it is used within the |
517 | * virtualization platform. Note that the VirtualSystemIdentifier is not the hostname assigned to |
518 | * the operating system instance running within the virtual system, nor is it an IP address or |
519 | * MAC address assigned to any of its network ports. On create requests VirtualSystemIdentifier |
520 | * may contain implementation specific rules (like simple patterns or regular expresssion) that |
521 | * may be interpreted by the implementation when assigning a VirtualSystemIdentifier. |
522 | */ |
523 | public String getVirtualSystemIdentifier() { |
524 | return virtualSystemIdentifier; |
525 | } |
526 | |
527 | /** |
528 | * VirtualSystemType shall reflect a particular type of virtual system. |
529 | */ |
530 | public Set<String> getVirtualSystemTypes() { |
531 | return virtualSystemTypes; |
532 | } |
533 | |
534 | /** |
535 | * End-user supplied notes that are related to the virtual system. |
536 | */ |
537 | public String getNotes() { |
538 | return notes; |
539 | } |
540 | |
541 | @Override |
542 | public int hashCode() { |
543 | final int prime = 31; |
544 | int result = super.hashCode(); |
545 | result = prime * result + ((virtualSystemIdentifier == null) ? 0 : virtualSystemIdentifier.hashCode()); |
546 | return result; |
547 | } |
548 | |
549 | @Override |
550 | public boolean equals(Object obj) { |
551 | if (this == obj) |
552 | return true; |
553 | if (!super.equals(obj)) |
554 | return false; |
555 | if (getClass() != obj.getClass()) |
556 | return false; |
557 | VirtualSystemSettingData other = (VirtualSystemSettingData) obj; |
558 | if (virtualSystemIdentifier == null) { |
559 | if (other.virtualSystemIdentifier != null) |
560 | return false; |
561 | } else if (!virtualSystemIdentifier.equals(other.virtualSystemIdentifier)) |
562 | return false; |
563 | return true; |
564 | } |
565 | |
566 | @Override |
567 | public String toString() { |
568 | return String |
569 | .format( |
570 | "[elementName=%s, instanceID=%s, caption=%s, description=%s, automaticRecoveryAction=%s, automaticShutdownAction=%s, automaticStartupAction=%s, automaticStartupActionDelay=%s, automaticStartupActionSequenceNumber=%s, configurationDataRoot=%s, configurationFile=%s, configurationID=%s, creationTime=%s, logDataRoot=%s, notes=%s, recoveryFile=%s, snapshotDataRoot=%s, suspendDataRoot=%s, swapFileDataRoot=%s, virtualSystemIdentifier=%s, virtualSystemTypes=%s]", |
571 | elementName, instanceID, caption, description, automaticRecoveryAction, |
572 | automaticShutdownAction, automaticStartupAction, automaticStartupActionDelay, |
573 | automaticStartupActionSequenceNumber, configurationDataRoot, configurationFile, |
574 | configurationID, creationTime, logDataRoot, notes, recoveryFile, snapshotDataRoot, |
575 | suspendDataRoot, swapFileDataRoot, virtualSystemIdentifier, virtualSystemTypes); |
576 | } |
577 | |
578 | } |