1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.cim;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import java.util.List;
24 import java.util.Map;
25
26 import com.google.common.base.Function;
27 import com.google.common.collect.ImmutableList;
28 import com.google.common.collect.ImmutableSet;
29 import com.google.common.collect.Lists;
30 import com.google.common.collect.Maps;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class ResourceAllocationSettingData extends ManagedElement {
50
51 public static Builder builder() {
52 return new Builder();
53 }
54
55
56
57
58 @Override
59 public Builder toBuilder() {
60 return builder().fromResourceAllocationSettingData(this);
61 }
62
63 public static class Builder extends ManagedElement.Builder {
64
65 protected String address;
66 protected String addressOnParent;
67 protected String allocationUnits;
68 protected Boolean automaticAllocation;
69 protected Boolean automaticDeallocation;
70 protected ConsumerVisibility consumerVisibility;
71 protected Long limit;
72 protected MappingBehavior mappingBehavior;
73 protected String otherResourceType;
74 protected String parent;
75 protected String poolID;
76 protected Long reservation;
77 protected String resourceSubType;
78 protected ResourceType resourceType;
79 protected Long virtualQuantity;
80 protected String virtualQuantityUnits;
81 protected Integer weight;
82 protected List<String> connections = Lists.newArrayList();
83 protected List<String> hostResources = Lists.newArrayList();
84
85
86
87
88 public Builder address(String address) {
89 this.address = address;
90 return this;
91 }
92
93
94
95
96 public Builder addressOnParent(String addressOnParent) {
97 this.addressOnParent = addressOnParent;
98 return this;
99 }
100
101
102
103
104 public Builder allocationUnits(String allocationUnits) {
105 this.allocationUnits = allocationUnits;
106 return this;
107 }
108
109
110
111
112 public Builder automaticAllocation(Boolean automaticAllocation) {
113 this.automaticAllocation = automaticAllocation;
114 return this;
115 }
116
117
118
119
120 public Builder automaticDeallocation(Boolean automaticDeallocation) {
121 this.automaticDeallocation = automaticDeallocation;
122 return this;
123 }
124
125
126
127
128 public Builder consumerVisibility(ConsumerVisibility consumerVisibility) {
129 this.consumerVisibility = consumerVisibility;
130 return this;
131 }
132
133
134
135
136 public Builder limit(Long limit) {
137 this.limit = limit;
138 return this;
139 }
140
141
142
143
144 public Builder mappingBehavior(MappingBehavior mappingBehavior) {
145 this.mappingBehavior = mappingBehavior;
146 return this;
147 }
148
149
150
151
152 public Builder otherResourceType(String otherResourceType) {
153 this.otherResourceType = otherResourceType;
154 return this;
155 }
156
157
158
159
160 public Builder parent(String parent) {
161 this.parent = parent;
162 return this;
163 }
164
165
166
167
168 public Builder poolID(String poolID) {
169 this.poolID = poolID;
170 return this;
171 }
172
173
174
175
176 public Builder reservation(Long reservation) {
177 this.reservation = reservation;
178 return this;
179 }
180
181
182
183
184 public Builder resourceSubType(String resourceSubType) {
185 this.resourceSubType = resourceSubType;
186 return this;
187 }
188
189
190
191
192 public Builder resourceType(ResourceType resourceType) {
193 this.resourceType = resourceType;
194 return this;
195 }
196
197
198
199
200 public Builder virtualQuantity(Long virtualQuantity) {
201 this.virtualQuantity = virtualQuantity;
202 return this;
203 }
204
205
206
207
208 public Builder virtualQuantityUnits(String virtualQuantityUnits) {
209 this.virtualQuantityUnits = virtualQuantityUnits;
210 return this;
211 }
212
213
214
215
216 public Builder weight(Integer weight) {
217 this.weight = weight;
218 return this;
219 }
220
221
222
223
224 public Builder connection(String connection) {
225 this.connections.add(checkNotNull(connection, "connection"));
226 return this;
227 }
228
229
230
231
232 public Builder hostResource(String hostResource) {
233 this.hostResources.add(checkNotNull(hostResource, "hostResource"));
234 return this;
235 }
236
237
238
239
240 public Builder connections(List<String> connections) {
241 this.connections.addAll(checkNotNull(connections, "connections"));
242 return this;
243 }
244
245
246
247
248 public Builder hostResources(List<String> hostResources) {
249 this.hostResources.addAll(checkNotNull(hostResources, "hostResources"));
250 return this;
251 }
252
253 public ResourceAllocationSettingData build() {
254 return new ResourceAllocationSettingData(elementName, instanceID, caption, description, address,
255 addressOnParent, allocationUnits, automaticAllocation, automaticDeallocation, consumerVisibility, limit,
256 mappingBehavior, otherResourceType, parent, poolID, reservation, resourceSubType, resourceType,
257 virtualQuantity, virtualQuantityUnits, weight, connections, hostResources);
258 }
259
260 public Builder fromResourceAllocationSettingData(ResourceAllocationSettingData in) {
261 return fromManagedElement(in).address(in.getAddress()).addressOnParent(in.getAddressOnParent())
262 .allocationUnits(in.getAllocationUnits()).automaticAllocation(in.isAutomaticAllocation())
263 .automaticDeallocation(in.isAutomaticDeallocation()).consumerVisibility(in.getConsumerVisibility())
264 .limit(in.getLimit()).mappingBehavior(in.getMappingBehavior())
265 .otherResourceType(in.getOtherResourceType()).parent(in.getParent()).poolID(in.getPoolID())
266 .reservation(in.getReservation()).resourceSubType(in.getResourceSubType())
267 .resourceType(in.getResourceType()).virtualQuantity(in.getVirtualQuantity())
268 .virtualQuantityUnits(in.getVirtualQuantityUnits()).weight(in.getWeight())
269 .connections(in.getConnections()).hostResources(in.getHostResources());
270 }
271
272
273
274
275 @Override
276 public Builder fromManagedElement(ManagedElement in) {
277 return Builder.class.cast(super.fromManagedElement(in));
278 }
279
280
281
282
283 @Override
284 public Builder caption(String caption) {
285 return Builder.class.cast(super.caption(caption));
286 }
287
288
289
290
291 @Override
292 public Builder description(String description) {
293 return Builder.class.cast(super.description(description));
294 }
295
296
297
298
299 @Override
300 public Builder elementName(String elementName) {
301 return Builder.class.cast(super.elementName(elementName));
302 }
303
304
305
306
307 @Override
308 public Builder instanceID(String instanceID) {
309 return Builder.class.cast(super.instanceID(instanceID));
310 }
311
312 }
313
314
315
316
317 public static enum ResourceType {
318
319 OTHER(1), COMPUTER_SYSTEM(2), PROCESSOR(3), MEMORY(4), IDE_CONTROLLER(5), PARALLEL_SCSI_HBA(6), FC_HBA(7), ISCSI_HBA(
320 8), IB_HCA(9), ETHERNET_ADAPTER(10), OTHER_NETWORK_ADAPTER(11), IO_SLOT(12), IO_DEVICE(13), FLOPPY_DRIVE(14), CD_DRIVE(
321 15), DVD_DRIVE(16), DISK_DRIVE(17), TAPE_DRIVE(18), STORAGE_EXTENT(19), OTHER_STORAGE_DEVICE(20), SERIAL_PORT(
322 21), PARALLEL_PORT(22), USB_CONTROLLER(23), GRAPHICS_CONTROLLER(24), IEEE_1394_CONTROLLER(25), PARTITIONABLE_UNIT(
323 26), BASE_PARTITIONABLE_UNIT(27), POWER(28), COOLING_CAPACITY(29), ETHERNET_SWITCH_PORT(30), LOGICAL_DISK(
324 31), STORAGE_VOLUME(32), ETHERNET_CONNECTION(33), DMTF_RESERVED(Integer.valueOf("8000", 16)), VENDOR_RESERVED(
325 Integer.valueOf("FFFF", 16));
326
327 protected final int code;
328
329 ResourceType(int code) {
330 this.code = code;
331 }
332
333 public String value() {
334 return code + "";
335 }
336
337 protected final static Map<Integer, ResourceType> RESOURCE_TYPE_BY_ID = Maps.uniqueIndex(
338 ImmutableSet.copyOf(ResourceType.values()), new Function<ResourceType, Integer>() {
339
340 @Override
341 public Integer apply(ResourceType input) {
342 return input.code;
343 }
344
345 });
346
347 public static ResourceType fromValue(String type) {
348 return RESOURCE_TYPE_BY_ID.get(new Integer(checkNotNull(type, "type")));
349 }
350 }
351
352
353
354
355 public static enum ConsumerVisibility {
356 UNKNOWN(0),
357
358
359
360
361
362 PASSED_THROUGH(2),
363
364
365
366
367
368
369 VIRTUALIZED(3),
370
371
372
373
374 NOT_REPRESENTED(4), DMTF_RESERVED(32767), VENDOR_RESERVED(65535);
375
376 protected final int code;
377
378 ConsumerVisibility(int code) {
379 this.code = code;
380 }
381
382 public String value() {
383 return code + "";
384 }
385
386 protected final static Map<Integer, ConsumerVisibility> MAPPING_BEHAVIOR_BY_ID = Maps.uniqueIndex(
387 ImmutableSet.copyOf(ConsumerVisibility.values()), new Function<ConsumerVisibility, Integer>() {
388
389 @Override
390 public Integer apply(ConsumerVisibility input) {
391 return input.code;
392 }
393
394 });
395
396 public static ConsumerVisibility fromValue(String behavior) {
397 return MAPPING_BEHAVIOR_BY_ID.get(new Integer(checkNotNull(behavior, "behavior")));
398 }
399 }
400
401
402
403
404
405
406 public static enum MappingBehavior {
407 UNKNOWN(0), NOT_SUPPORTED(2), DEDICATED(3), SOFT_AFFINITY(4), HARD_AFFINITY(5), DMTF_RESERVED(32767), VENDOR_RESERVED(
408 65535);
409
410 protected final int code;
411
412 MappingBehavior(int code) {
413 this.code = code;
414 }
415
416 public String value() {
417 return code + "";
418 }
419
420 protected final static Map<Integer, MappingBehavior> MAPPING_BEHAVIOR_BY_ID = Maps.uniqueIndex(
421 ImmutableSet.copyOf(MappingBehavior.values()), new Function<MappingBehavior, Integer>() {
422
423 @Override
424 public Integer apply(MappingBehavior input) {
425 return input.code;
426 }
427
428 });
429
430 public static MappingBehavior fromValue(String behavior) {
431 return MAPPING_BEHAVIOR_BY_ID.get(new Integer(checkNotNull(behavior, "behavior")));
432 }
433 }
434
435 protected final String address;
436 protected final String addressOnParent;
437 protected final String allocationUnits;
438 protected final Boolean automaticAllocation;
439 protected final Boolean automaticDeallocation;
440 protected final ConsumerVisibility consumerVisibility;
441 protected final Long limit;
442 protected final MappingBehavior mappingBehavior;
443 protected final String otherResourceType;
444 protected final String parent;
445 protected final String poolID;
446 protected final Long reservation;
447 protected final String resourceSubType;
448 protected final ResourceType resourceType;
449 protected final Long virtualQuantity;
450 protected final String virtualQuantityUnits;
451 protected final Integer weight;
452 protected final List<String> connections;
453 protected final List<String> hostResources;
454
455 public ResourceAllocationSettingData(String elementName, String instanceID, String caption, String description,
456 String address, String addressOnParent, String allocationUnits, Boolean automaticAllocation,
457 Boolean automaticDeallocation, ConsumerVisibility consumerVisibility, Long limit,
458 MappingBehavior mappingBehavior, String otherResourceType, String parent, String poolID, Long reservation,
459 String resourceSubType, ResourceType resourceType, Long virtualQuantity, String virtualQuantityUnits,
460 Integer weight, List<String> connections, List<String> hostResources) {
461 super(elementName, instanceID, caption, description);
462 this.address = address;
463 this.addressOnParent = addressOnParent;
464 this.allocationUnits = allocationUnits;
465 this.automaticAllocation = automaticAllocation;
466 this.automaticDeallocation = automaticDeallocation;
467 this.consumerVisibility = consumerVisibility;
468 this.limit = limit;
469 this.mappingBehavior = mappingBehavior;
470 this.otherResourceType = otherResourceType;
471 this.parent = parent;
472 this.poolID = poolID;
473 this.reservation = reservation;
474 this.resourceSubType = resourceSubType;
475 this.resourceType = resourceType;
476 this.virtualQuantity = virtualQuantity;
477 this.virtualQuantityUnits = virtualQuantityUnits;
478 this.weight = weight;
479 this.connections = ImmutableList.copyOf(connections);
480 this.hostResources = ImmutableList.copyOf(hostResources);
481 }
482
483
484
485
486
487 public String getAddress() {
488 return address;
489 }
490
491
492
493
494
495
496
497
498 public String getAddressOnParent() {
499 return addressOnParent;
500 }
501
502
503
504
505
506
507
508
509
510
511
512 public String getAllocationUnits() {
513 return allocationUnits;
514 }
515
516
517
518
519
520
521
522
523
524
525 public Boolean isAutomaticAllocation() {
526 return automaticAllocation;
527 }
528
529
530
531
532
533
534
535
536 public Boolean isAutomaticDeallocation() {
537 return automaticDeallocation;
538 }
539
540
541
542
543 public ConsumerVisibility getConsumerVisibility() {
544 return consumerVisibility;
545 }
546
547
548
549
550
551
552
553
554
555 public Long getLimit() {
556 return limit;
557 }
558
559
560
561
562
563
564 public MappingBehavior getMappingBehavior() {
565 return mappingBehavior;
566 }
567
568
569
570
571
572 public String getOtherResourceType() {
573 return otherResourceType;
574 }
575
576
577
578
579
580 public String getParent() {
581 return parent;
582 }
583
584
585
586
587
588
589 public String getPoolID() {
590 return poolID;
591 }
592
593
594
595
596
597
598
599
600
601 public Long getReservation() {
602 return reservation;
603 }
604
605
606
607
608
609 public String getResourceSubType() {
610 return resourceSubType;
611 }
612
613
614
615
616 public ResourceType getResourceType() {
617 return resourceType;
618 }
619
620
621
622
623
624
625
626
627
628
629 public Long getVirtualQuantity() {
630 return virtualQuantity;
631 }
632
633
634
635
636
637
638
639
640
641
642
643
644
645 public String getVirtualQuantityUnits() {
646 return virtualQuantityUnits;
647 }
648
649
650
651
652
653
654
655 public Integer getWeight() {
656 return weight;
657 }
658
659
660
661
662
663 public List<String> getConnections() {
664 return connections;
665 }
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685 public List<String> getHostResources() {
686 return hostResources;
687 }
688
689 @Override
690 public String toString() {
691 return String
692 .format(
693 "[elementName=%s, instanceID=%s, caption=%s, description=%s, address=%s, addressOnParent=%s, allocationUnits=%s, automaticAllocation=%s, automaticDeallocation=%s, connections=%s, consumerVisibility=%s, hostResources=%s, limit=%s, mappingBehavior=%s, otherResourceType=%s, parent=%s, poolID=%s, reservation=%s, resourceSubType=%s, resourceType=%s, virtualQuantity=%s, virtualQuantityUnits=%s, weight=%s]",
694 elementName, instanceID, caption, description, address, addressOnParent, allocationUnits,
695 automaticAllocation, automaticDeallocation, connections, consumerVisibility, hostResources, limit,
696 mappingBehavior, otherResourceType, parent, poolID, reservation, resourceSubType, resourceType,
697 virtualQuantity, virtualQuantityUnits, weight);
698 }
699
700 @Override
701 public int hashCode() {
702 final int prime = 31;
703 int result = super.hashCode();
704 result = prime * result + ((address == null) ? 0 : address.hashCode());
705 result = prime * result + ((addressOnParent == null) ? 0 : addressOnParent.hashCode());
706 result = prime * result + ((resourceSubType == null) ? 0 : resourceSubType.hashCode());
707 result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
708 return result;
709 }
710
711 @Override
712 public boolean equals(Object obj) {
713 if (this == obj)
714 return true;
715 if (!super.equals(obj))
716 return false;
717 if (getClass() != obj.getClass())
718 return false;
719 ResourceAllocationSettingData other = (ResourceAllocationSettingData) obj;
720 if (address == null) {
721 if (other.address != null)
722 return false;
723 } else if (!address.equals(other.address))
724 return false;
725 if (addressOnParent == null) {
726 if (other.addressOnParent != null)
727 return false;
728 } else if (!addressOnParent.equals(other.addressOnParent))
729 return false;
730 if (resourceSubType == null) {
731 if (other.resourceSubType != null)
732 return false;
733 } else if (!resourceSubType.equals(other.resourceSubType))
734 return false;
735 if (resourceType == null) {
736 if (other.resourceType != null)
737 return false;
738 } else if (!resourceType.equals(other.resourceType))
739 return false;
740 return true;
741 }
742
743 }