1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | * contributor license agreements. See the NOTICE file distributed with |
4 | * this work for additional information regarding copyright ownership. |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | * (the "License"); you may not use this file except in compliance with |
7 | * the License. You may obtain a copy of the License at |
8 | * |
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
11 | * Unless required by applicable law or agreed to in writing, software |
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | * See the License for the specific language governing permissions and |
15 | * limitations under the License. |
16 | */ |
17 | package org.jclouds.glesys.domain; |
18 | |
19 | import static com.google.common.base.Preconditions.checkNotNull; |
20 | |
21 | import java.beans.ConstructorProperties; |
22 | import java.util.Set; |
23 | |
24 | import com.google.common.base.Objects; |
25 | import com.google.common.base.Objects.ToStringHelper; |
26 | import com.google.common.collect.ImmutableSet; |
27 | |
28 | /** |
29 | * Sets the allowed arguments for some of the functions in this module such as disksize, cpucores etc. |
30 | * |
31 | * @author Adam Lowe |
32 | * @see <a href="https://customer.glesys.com/api.php?a=doc#server_allowedarguments" /> |
33 | */ |
34 | public class AllowedArgumentsForCreateServer { |
35 | |
36 | public static Builder builder() { |
37 | return new Builder(); |
38 | } |
39 | |
40 | public Builder toBuilder() { |
41 | return new Builder().fromAllowedArgumentsForCreateServer(this); |
42 | } |
43 | |
44 | public static class Builder { |
45 | protected AllowedArguments diskSizes; |
46 | protected AllowedArguments memorySizes; |
47 | protected AllowedArguments cpuCores; |
48 | protected Set<String> templates = ImmutableSet.of(); |
49 | protected AllowedArguments transfers; |
50 | protected Set<String> dataCenters = ImmutableSet.of(); |
51 | |
52 | /** |
53 | * @see AllowedArgumentsForCreateServer#getDiskSizesInGB() |
54 | */ |
55 | public Builder diskSizes(AllowedArguments diskSizes) { |
56 | this.diskSizes = checkNotNull(diskSizes, "diskSizesInGB"); |
57 | return this; |
58 | } |
59 | |
60 | |
61 | /** |
62 | * @see AllowedArgumentsForCreateServer#getMemorySizesInMB() |
63 | */ |
64 | public Builder memorySizes(AllowedArguments memorySizes) { |
65 | this.memorySizes = checkNotNull(memorySizes, "memorySizesInMB"); |
66 | return this; |
67 | } |
68 | |
69 | |
70 | /** |
71 | * @see AllowedArgumentsForCreateServer#getCpuCoreOptions() |
72 | */ |
73 | public Builder cpuCores(AllowedArguments cpuCores) { |
74 | this.cpuCores = checkNotNull(cpuCores, "cpuCoreOptions"); |
75 | return this; |
76 | } |
77 | |
78 | |
79 | /** |
80 | * @see AllowedArgumentsForCreateServer#getTemplateNames() |
81 | */ |
82 | public Builder templates(Set<String> templates) { |
83 | this.templates = ImmutableSet.copyOf(checkNotNull(templates, "templateNames")); |
84 | return this; |
85 | } |
86 | |
87 | public Builder templates(String... in) { |
88 | return templates(ImmutableSet.copyOf(in)); |
89 | } |
90 | |
91 | /** |
92 | * @see AllowedArgumentsForCreateServer#getTransfersInGB() |
93 | */ |
94 | public Builder transfers(AllowedArguments transfers) { |
95 | this.transfers = checkNotNull(transfers, "transfersInGB"); |
96 | return this; |
97 | } |
98 | |
99 | /** |
100 | * @see AllowedArgumentsForCreateServer#getDataCenters() |
101 | */ |
102 | public Builder dataCenters(Set<String> dataCenters) { |
103 | this.dataCenters = ImmutableSet.copyOf(checkNotNull(dataCenters, "dataCenters")); |
104 | return this; |
105 | } |
106 | |
107 | public Builder dataCenters(String... in) { |
108 | return dataCenters(ImmutableSet.copyOf(in)); |
109 | } |
110 | |
111 | public AllowedArgumentsForCreateServer build() { |
112 | return new AllowedArgumentsForCreateServer(diskSizes, memorySizes, cpuCores, templates, transfers, dataCenters); |
113 | } |
114 | |
115 | public Builder fromAllowedArgumentsForCreateServer(AllowedArgumentsForCreateServer in) { |
116 | return this |
117 | .diskSizes(in.getDiskSizesInGB()) |
118 | .memorySizes(in.getMemorySizesInMB()) |
119 | .cpuCores(in.getCpuCoreOptions()) |
120 | .templates(in.getTemplateNames()) |
121 | .transfers(in.getTransfersInGB()) |
122 | .dataCenters(in.getDataCenters()); |
123 | } |
124 | } |
125 | |
126 | private final AllowedArguments diskSizesInGB; |
127 | private final AllowedArguments memorySizesInMB; |
128 | private final AllowedArguments cpuCoreOptions; |
129 | private final Set<String> templateNames; |
130 | private final AllowedArguments transfersInGB; |
131 | private final Set<String> dataCenters; |
132 | |
133 | @ConstructorProperties({ |
134 | "disksize", "memorysize", "cpucores", "template", "transfer", "datacenter" |
135 | }) |
136 | protected AllowedArgumentsForCreateServer(AllowedArguments diskSizesInGB, AllowedArguments memorySizesInMB, AllowedArguments cpuCoreOptions, Set<String> templateNames, AllowedArguments transfersInGB, Set<String> dataCenters) { |
137 | this.diskSizesInGB = checkNotNull(diskSizesInGB, "diskSizesInGB"); |
138 | this.memorySizesInMB = checkNotNull(memorySizesInMB, "memorySizesInMB"); |
139 | this.cpuCoreOptions = checkNotNull(cpuCoreOptions, "cpuCoreOptions"); |
140 | this.templateNames = ImmutableSet.copyOf(checkNotNull(templateNames, "templateNames")); |
141 | this.transfersInGB = checkNotNull(transfersInGB, "transfersInGB"); |
142 | this.dataCenters = ImmutableSet.copyOf(checkNotNull(dataCenters, "dataCenters")); |
143 | } |
144 | |
145 | /** |
146 | * @return a list of disk sizes, in GB, that can be used for creating servers on this platform |
147 | * @see org.jclouds.glesys.domain.OSTemplate#getMinDiskSize() |
148 | */ |
149 | public AllowedArguments getDiskSizesInGB() { |
150 | return this.diskSizesInGB; |
151 | } |
152 | |
153 | /** |
154 | * @return a list of memory sizes, in MB, that can be used for creating servers on this platform |
155 | * @see org.jclouds.glesys.domain.OSTemplate#getMinMemSize() |
156 | */ |
157 | public AllowedArguments getMemorySizesInMB() { |
158 | return this.memorySizesInMB; |
159 | } |
160 | |
161 | /** |
162 | * @return a list of which core counts can be used for creating servers on this platform |
163 | */ |
164 | public AllowedArguments getCpuCoreOptions() { |
165 | return this.cpuCoreOptions; |
166 | } |
167 | |
168 | /** |
169 | * @return a list of template names available for creating servers on this platform |
170 | * @see org.jclouds.glesys.domain.OSTemplate#getName() |
171 | */ |
172 | public Set<String> getTemplateNames() { |
173 | return this.templateNames; |
174 | } |
175 | |
176 | /** |
177 | * @return the list of transfer settings available for creating servers on this platform |
178 | */ |
179 | public AllowedArguments getTransfersInGB() { |
180 | return this.transfersInGB; |
181 | } |
182 | |
183 | /** |
184 | * @return the list of datacenters available that support creating servers on this platform |
185 | */ |
186 | public Set<String> getDataCenters() { |
187 | return this.dataCenters; |
188 | } |
189 | |
190 | @Override |
191 | public int hashCode() { |
192 | return Objects.hashCode(diskSizesInGB, memorySizesInMB, cpuCoreOptions, templateNames, transfersInGB, dataCenters); |
193 | } |
194 | |
195 | @Override |
196 | public boolean equals(Object obj) { |
197 | if (this == obj) return true; |
198 | if (obj == null || getClass() != obj.getClass()) return false; |
199 | AllowedArgumentsForCreateServer that = AllowedArgumentsForCreateServer.class.cast(obj); |
200 | return Objects.equal(this.diskSizesInGB, that.diskSizesInGB) |
201 | && Objects.equal(this.memorySizesInMB, that.memorySizesInMB) |
202 | && Objects.equal(this.cpuCoreOptions, that.cpuCoreOptions) |
203 | && Objects.equal(this.templateNames, that.templateNames) |
204 | && Objects.equal(this.transfersInGB, that.transfersInGB) |
205 | && Objects.equal(this.dataCenters, that.dataCenters); |
206 | } |
207 | |
208 | protected ToStringHelper string() { |
209 | return Objects.toStringHelper("").add("diskSizesInGB", diskSizesInGB).add("memorySizesInMB", memorySizesInMB) |
210 | .add("cpuCoreOptions", cpuCoreOptions).add("templateNames", templateNames) |
211 | .add("transfersInGB", transfersInGB).add("dataCenters", dataCenters); |
212 | } |
213 | |
214 | @Override |
215 | public String toString() { |
216 | return string().toString(); |
217 | } |
218 | |
219 | } |