| 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.trmk.vcloud_0_8.domain; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkArgument; |
| 22 | |
| 23 | import java.util.List; |
| 24 | |
| 25 | import org.jclouds.util.Preconditions2; |
| 26 | |
| 27 | import com.google.common.collect.Lists; |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @author Adrian Cole |
| 32 | * |
| 33 | */ |
| 34 | public class VAppConfiguration { |
| 35 | private String name = null; |
| 36 | private Integer processorCount = null; |
| 37 | private Long memory = null; |
| 38 | private List<Long> disks = Lists.newArrayList(); |
| 39 | private List<Integer> disksToDelete = Lists.newArrayList(); |
| 40 | |
| 41 | /** |
| 42 | * The vApp name |
| 43 | * |
| 44 | */ |
| 45 | public VAppConfiguration changeNameTo(String name) { |
| 46 | Preconditions2.checkNotEmpty(name, "name must be specified"); |
| 47 | this.name = name; |
| 48 | return this; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * the number of virtual CPUs. |
| 53 | */ |
| 54 | public VAppConfiguration changeProcessorCountTo(int cpus) { |
| 55 | checkArgument(cpus >= 1, "cpu count must be positive"); |
| 56 | this.processorCount = cpus; |
| 57 | return this; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * number of MB of memory. |
| 62 | */ |
| 63 | public VAppConfiguration changeMemoryTo(long megabytes) { |
| 64 | checkArgument(megabytes >= 1, "megabytes must be positive"); |
| 65 | this.memory = megabytes; |
| 66 | return this; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * To define a new disk, all you need to define is the size of the disk. The allowed values are a |
| 71 | * multiple of 1048576. |
| 72 | */ |
| 73 | public VAppConfiguration addDisk(long kilobytes) { |
| 74 | checkArgument(kilobytes > 0, "kilobytes must be positive"); |
| 75 | checkArgument(kilobytes % 1048576 == 0, "disk must be an interval of 1048576"); |
| 76 | this.disks.add(kilobytes); |
| 77 | return this; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * To remove a disk, you specify its addressOnParent. |
| 82 | * |
| 83 | * Ex. |
| 84 | * |
| 85 | * <pre> |
| 86 | * Set<ResourceAllocation> disks = Sets.newLinkedHashSet(vApp.getResourceAllocationByType().get( |
| 87 | * ResourceType.DISK_DRIVE)); |
| 88 | * ResourceAllocation lastDisk = disks.last(); |
| 89 | * VAppConfiguration config = deleteDiskWithAddressOnParent(lastDisk.getAddressOnParent()); |
| 90 | * </pre> |
| 91 | */ |
| 92 | public VAppConfiguration deleteDiskWithAddressOnParent(int addressOnParent) { |
| 93 | checkArgument(addressOnParent > 0, "you cannot delete the system disk"); |
| 94 | disksToDelete.add(addressOnParent); |
| 95 | return this; |
| 96 | } |
| 97 | |
| 98 | public static class Builder { |
| 99 | |
| 100 | /** |
| 101 | * @see VAppConfiguration#changeNameTo(String) |
| 102 | */ |
| 103 | public static VAppConfiguration changeNameTo(String name) { |
| 104 | VAppConfiguration options = new VAppConfiguration(); |
| 105 | return options.changeNameTo(name); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @see VAppConfiguration#changeProcessorCountTo(int) |
| 110 | */ |
| 111 | public static VAppConfiguration changeProcessorCountTo(int cpus) { |
| 112 | VAppConfiguration options = new VAppConfiguration(); |
| 113 | return options.changeProcessorCountTo(cpus); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @see VAppConfiguration#changeMemoryTo(long) |
| 118 | */ |
| 119 | public static VAppConfiguration changeMemoryTo(long megabytes) { |
| 120 | VAppConfiguration options = new VAppConfiguration(); |
| 121 | return options.changeMemoryTo(megabytes); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @see VAppConfiguration#addDisk(long) |
| 126 | */ |
| 127 | public static VAppConfiguration addDisk(long kilobytes) { |
| 128 | VAppConfiguration options = new VAppConfiguration(); |
| 129 | return options.addDisk(kilobytes); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @see VAppConfiguration#deleteDiskWithAddressOnParent(int) |
| 134 | */ |
| 135 | public static VAppConfiguration deleteDiskWithAddressOnParent(int addressOnParent) { |
| 136 | VAppConfiguration options = new VAppConfiguration(); |
| 137 | return options.deleteDiskWithAddressOnParent(addressOnParent); |
| 138 | } |
| 139 | |
| 140 | } |
| 141 | |
| 142 | public Integer getProcessorCount() { |
| 143 | return processorCount; |
| 144 | } |
| 145 | |
| 146 | public Long getMemory() { |
| 147 | return memory; |
| 148 | } |
| 149 | |
| 150 | public List<Long> getDisks() { |
| 151 | return disks; |
| 152 | } |
| 153 | |
| 154 | public String getName() { |
| 155 | return name; |
| 156 | } |
| 157 | |
| 158 | public List<Integer> getDisksToDelete() { |
| 159 | return disksToDelete; |
| 160 | } |
| 161 | } |