forked from jenkinsci/azure-vm-agents-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAzureVMTemplateFluent.java
313 lines (233 loc) · 8.07 KB
/
AzureVMTemplateFluent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package com.microsoft.azure.vmagent.builders;
import com.microsoft.azure.vmagent.AzureVMCloudBaseRetentionStrategy;
import com.microsoft.azure.vmagent.AzureVMCloudPoolRetentionStrategy;
import com.microsoft.azure.vmagent.AzureVMCloudRetensionStrategy;
import com.microsoft.azure.vmagent.util.Constants;
public class AzureVMTemplateFluent<T extends AzureVMTemplateFluent<T>> {
private String name;
private String description;
private String workspace;
private String labels;
private String location;
private Availability availability;
private String virtualMachineSize;
private String storageAccountType;
private String storageAccountNameReferenceType;
private String diskType;
private boolean ephemeralOSDisk;
private int osDiskSize;
private String newStorageAccountName;
private String existingStorageAccountName;
private AzureVMCloudBaseRetentionStrategy retentionStrategy;
private boolean shutdownOnIdle;
private String usageMode;
private String imageTopLevelType;
private BuiltInImage builtInImage;
private AdvancedImage advancedImage;
private String credentialsId;
public AzureVMTemplateFluent() {
location = "Japan West";
virtualMachineSize = "Standard_A0";
storageAccountType = "Standard_LRS";
storageAccountNameReferenceType = "new";
diskType = Constants.DISK_MANAGED;
osDiskSize = 0;
retentionStrategy = new AzureVMCloudRetensionStrategy(Constants.DEFAULT_IDLE_RETENTION_TIME);
shutdownOnIdle = false;
usageMode = "Use this node as much as possible";
imageTopLevelType = Constants.IMAGE_TOP_LEVEL_BASIC;
availability = new AvailabilityBuilder().build();
builtInImage = new BuiltInImageBuilder().build();
advancedImage = new AdvancedImageBuilder().build();
}
//CHECKSTYLE:OFF
public T withName(String name) {
this.name = name;
return (T) this;
}
public T withDescription(String description) {
this.description = description;
return (T) this;
}
public T withWorkspace(String workspace) {
this.workspace = workspace;
return (T) this;
}
public T withLabels(String labels) {
this.labels = labels;
return (T) this;
}
public T withLocation(String location) {
this.location = location;
return (T) this;
}
public T withAvailability(Availability availability) {
this.availability = availability;
return (T) this;
}
public T withVirtualMachineSize(String virtualMachineSize) {
this.virtualMachineSize = virtualMachineSize;
return (T) this;
}
public T withStorageAccountType(String storageAccountType) {
this.storageAccountType = storageAccountType;
return (T) this;
}
public T withNewStorageAccount(String storageAccountName) {
this.storageAccountNameReferenceType = "new";
this.newStorageAccountName = storageAccountName;
return (T) this;
}
public T withExistingStorageAccount(String storageAccountName) {
this.storageAccountNameReferenceType = "existing";
this.existingStorageAccountName = storageAccountName;
return (T) this;
}
public T withDiskType(String diskType) {
this.diskType = diskType;
return (T) this;
}
public T withEphemeralOSDisk(boolean isEphemeral) {
this.ephemeralOSDisk = isEphemeral;
return (T) this;
}
public T withOsDiskSize(int osDiskSize) {
this.osDiskSize = osDiskSize;
return (T) this;
}
public T withRetentionStrategy(AzureVMCloudBaseRetentionStrategy retentionStrategy) {
this.retentionStrategy = retentionStrategy;
return (T) this;
}
public T addNewIdleRetentionStrategy(String retentionTime) {
this.retentionStrategy = new AzureVMCloudRetensionStrategy(Integer.parseInt(retentionTime));
return (T) this;
}
public T addNewPoolRetentionStrategy(String retentionTime, String poolSize) {
this.retentionStrategy = new AzureVMCloudPoolRetentionStrategy(Integer.parseInt(retentionTime),
Integer.parseInt(poolSize));
return (T) this;
}
public T withShutdownOnIdle(boolean isShutdown) {
this.shutdownOnIdle = isShutdown;
return (T) this;
}
public T withUsageMode(String usageMode) {
this.usageMode = usageMode;
return (T) this;
}
public T withBuiltInImage(BuiltInImage builtInImage) {
this.imageTopLevelType = Constants.IMAGE_TOP_LEVEL_BASIC;
this.builtInImage = builtInImage;
return (T) this;
}
public BuiltInImageNested addNewBuiltInImage() {
return new BuiltInImageNested();
}
public BuiltInImageNested addNewBuiltInImageLike(BuiltInImage image) {
return new BuiltInImageNested(image);
}
public T withAdvancedImage(AdvancedImage advancedImage) {
this.imageTopLevelType = Constants.IMAGE_TOP_LEVEL_ADVANCED;
this.advancedImage = advancedImage;
return (T) this;
}
public AdvancedImageNested addNewAdvancedImage() {
return new AdvancedImageNested();
}
public AdvancedImageNested addNewAdvancedImageLike(AdvancedImage image) {
return new AdvancedImageNested(image);
}
public T withAdminCredential(String credentialsId) {
this.credentialsId = credentialsId;
return (T) this;
}
//CHECKSTYLE:ON
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getWorkspace() {
return workspace;
}
public String getLabels() {
return labels;
}
public String getLocation() {
return location;
}
public Availability getAvailability() {
return availability;
}
public String getVirtualMachineSize() {
return virtualMachineSize;
}
public String getStorageAccountType() {
return storageAccountType;
}
public String getStorageAccountNameReferenceType() {
return storageAccountNameReferenceType;
}
public String getDiskType() {
return diskType;
}
public boolean isEphemeralOSDisk() {
return ephemeralOSDisk;
}
public int getOsDiskSize() {
return osDiskSize;
}
public String getNewStorageAccountName() {
return newStorageAccountName;
}
public String getExistingStorageAccountName() {
return existingStorageAccountName;
}
public AzureVMCloudBaseRetentionStrategy getRetentionStrategy() {
return retentionStrategy;
}
public boolean isShutdownOnIdle() {
return shutdownOnIdle;
}
public String getUsageMode() {
return usageMode;
}
public String getImageTopLevelType() {
return imageTopLevelType;
}
public BuiltInImage getBuiltInImage() {
return builtInImage;
}
public AdvancedImage getAdvancedImage() {
return advancedImage;
}
public String getCredentialsId() {
return credentialsId;
}
public class BuiltInImageNested extends BuiltInImageFluent<BuiltInImageNested> {
private final BuiltInImageBuilder builder;
BuiltInImageNested() {
this.builder = new BuiltInImageBuilder(this);
}
BuiltInImageNested(BuiltInImage image) {
this.builder = new BuiltInImageBuilder(this, image);
}
public T endBuiltInImage() {
return AzureVMTemplateFluent.this.withBuiltInImage(builder.build());
}
}
public class AdvancedImageNested extends AdvancedImageFluent<AdvancedImageNested> {
private final AdvancedImageBuilder builder;
AdvancedImageNested() {
this.builder = new AdvancedImageBuilder(this);
}
AdvancedImageNested(AdvancedImage image) {
this.builder = new AdvancedImageBuilder(this, image);
}
public T endAdvancedImage() {
return AzureVMTemplateFluent.this.withAdvancedImage(builder.build());
}
}
}