-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathVMTemplateVO.java
More file actions
633 lines (511 loc) · 16 KB
/
VMTemplateVO.java
File metadata and controls
633 lines (511 loc) · 16 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.storage;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.TemplateType;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.utils.db.GenericDao;
@Entity
@Table(name = "vm_template")
public class VMTemplateVO implements VirtualMachineTemplate {
@Id
@TableGenerator(name = "vm_template_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "vm_template_seq", allocationSize = 1)
@Column(name = "id", nullable = false)
private long id;
@Column(name = "format")
private Storage.ImageFormat format;
@Column(name = "unique_name")
private String uniqueName;
@Column(name = "name")
private String name = null;
@Column(name = "public")
private boolean publicTemplate = true;
@Column(name = "featured")
private boolean featured;
@Column(name = "type")
private Storage.TemplateType templateType;
@Column(name = "url", length = 2048)
private String url = null;
@Column(name = "hvm")
private boolean requiresHvm;
@Column(name = "bits")
private int bits;
@Temporal(value = TemporalType.TIMESTAMP)
@Column(name = GenericDao.CREATED_COLUMN)
private Date created = null;
@Column(name = GenericDao.REMOVED_COLUMN)
@Temporal(TemporalType.TIMESTAMP)
private Date removed;
@Column(name = "account_id")
private long accountId;
@Column(name = "checksum")
private String checksum;
@Column(name = "display_text", length = 4096)
private String displayText;
@Column(name = "enable_password")
private boolean enablePassword;
@Column(name = "guest_os_id")
private long guestOSId;
@Column(name = "bootable")
private boolean bootable = true;
@Column(name = "prepopulate")
private boolean prepopulate = false;
@Column(name = "cross_zones")
private boolean crossZones = false;
@Column(name = "hypervisor_type")
@Enumerated(value = EnumType.STRING)
private HypervisorType hypervisorType;
@Column(name = "extractable")
private boolean extractable = true;
@Column(name = "source_template_id")
private Long sourceTemplateId;
@Column(name = "state")
@Enumerated(EnumType.STRING)
private State state;
@Column(name = "template_tag")
private String templateTag;
@Column(name = "uuid")
private String uuid;
@Column(name = "sort_key")
private int sortKey;
@Column(name = "enable_sshkey")
private boolean enableSshKey;
@Column(name = "size")
private Long size;
@Column(name = "update_count", updatable = true)
protected long updatedCount;
@Column(name = "updated")
@Temporal(value = TemporalType.TIMESTAMP)
Date updated;
@Transient
Map<String, String> details;
@Column(name = "dynamically_scalable")
protected boolean dynamicallyScalable;
@Column(name = "direct_download")
private boolean directDownload;
@Column(name = "parent_template_id")
private Long parentTemplateId;
@Override
public String getUniqueName() {
return uniqueName;
}
public void setUniqueName(String uniqueName) {
this.uniqueName = uniqueName;
}
public VMTemplateVO() {
uuid = UUID.randomUUID().toString();
}
//FIXME - Remove unwanted constructors.
private VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url,
boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable,
HypervisorType hyperType, Map<String, String> details) {
this(id,
generateUniqueName(id, accountId, name),
name,
format,
isPublic,
featured,
isExtractable,
type,
url,
null,
requiresHvm,
bits,
accountId,
cksum,
displayText,
enablePassword,
guestOSId,
bootable,
hyperType,
details);
uuid = UUID.randomUUID().toString();
}
public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url,
boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable,
HypervisorType hyperType, String templateTag, Map<String, String> details, boolean sshKeyEnabled, boolean isDynamicallyScalable, boolean directDownload) {
this(id,
name,
format,
isPublic,
featured,
isExtractable,
type,
url,
requiresHvm,
bits,
accountId,
cksum,
displayText,
enablePassword,
guestOSId,
bootable,
hyperType,
details);
this.templateTag = templateTag;
uuid = UUID.randomUUID().toString();
enableSshKey = sshKeyEnabled;
dynamicallyScalable = isDynamicallyScalable;
state = State.Active;
this.directDownload = directDownload;
}
public static VMTemplateVO createPreHostIso(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, TemplateType type,
String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId,
boolean bootable, HypervisorType hyperType) {
VMTemplateVO template =
new VMTemplateVO(id, uniqueName, name, format, isPublic, featured, type, url, created, requiresHvm, bits, accountId, cksum, displayText, enablePassword,
guestOSId, bootable, hyperType);
return template;
}
public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, TemplateType type, String url, Date created,
boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable,
HypervisorType hyperType) {
this.id = id;
this.name = name;
publicTemplate = isPublic;
this.featured = featured;
templateType = type;
this.url = url;
this.requiresHvm = requiresHvm;
this.bits = bits;
this.accountId = accountId;
checksum = cksum;
this.uniqueName = uniqueName;
this.displayText = displayText;
this.enablePassword = enablePassword;
this.format = format;
this.created = created;
this.guestOSId = guestOSId;
this.bootable = bootable;
hypervisorType = hyperType;
uuid = UUID.randomUUID().toString();
state = State.Active;
}
//FIXME - Remove unwanted constructors. Made them private for now
private VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type,
String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId,
boolean bootable, HypervisorType hyperType, Map<String, String> details) {
this(id,
uniqueName,
name,
format,
isPublic,
featured,
type,
url,
created,
requiresHvm,
bits,
accountId,
cksum,
displayText,
enablePassword,
guestOSId,
bootable,
hyperType);
extractable = isExtractable;
uuid = UUID.randomUUID().toString();
this.details = details;
state = State.Active;
}
@Override
public boolean isEnablePassword() {
return enablePassword;
}
@Override
public Storage.ImageFormat getFormat() {
return format;
}
public void setEnablePassword(boolean enablePassword) {
this.enablePassword = enablePassword;
}
public void setFormat(ImageFormat format) {
this.format = format;
}
private static String generateUniqueName(long id, long userId, String displayName) {
StringBuilder name = new StringBuilder();
name.append(id);
name.append("-");
name.append(userId);
name.append("-");
name.append(UUID.nameUUIDFromBytes((displayName + System.currentTimeMillis()).getBytes()).toString());
return name.toString();
}
@Override
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
@Override
public long getId() {
return id;
}
@Override
public TemplateType getTemplateType() {
return templateType;
}
public void setTemplateType(TemplateType type) {
templateType = type;
}
public boolean requiresHvm() {
return requiresHvm;
}
@Override
public int getBits() {
return bits;
}
public void setBits(int bits) {
this.bits = bits;
}
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getRemoved() {
return removed;
}
@Override
public boolean isPublicTemplate() {
return publicTemplate;
}
public void setPublicTemplate(boolean publicTemplate) {
this.publicTemplate = publicTemplate;
}
@Override
public boolean isFeatured() {
return featured;
}
public void setFeatured(boolean featured) {
this.featured = featured;
}
@Override
public Date getCreated() {
return created;
}
@Override
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public boolean isRequiresHvm() {
return requiresHvm;
}
public void setRequiresHvm(boolean value) {
requiresHvm = value;
}
@Override
public long getAccountId() {
return accountId;
}
@Override
public String getChecksum() {
return checksum;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
@Override
public String getDisplayText() {
return displayText;
}
public void setDisplayText(String displayText) {
this.displayText = displayText;
}
@Override
public long getGuestOSId() {
return guestOSId;
}
public void setGuestOSId(long guestOSId) {
this.guestOSId = guestOSId;
}
@Override
public boolean isBootable() {
return bootable;
}
public void setBootable(boolean bootable) {
this.bootable = bootable;
}
public void setPrepopulate(boolean prepopulate) {
this.prepopulate = prepopulate;
}
public boolean isPrepopulate() {
return prepopulate;
}
public void setCrossZones(boolean crossZones) {
this.crossZones = crossZones;
}
@Override
public boolean isCrossZones() {
return crossZones;
}
@Override
public HypervisorType getHypervisorType() {
return hypervisorType;
}
public void setHypervisorType(HypervisorType hyperType) {
hypervisorType = hyperType;
}
@Override
public boolean isExtractable() {
return extractable;
}
public void setExtractable(boolean extractable) {
this.extractable = extractable;
}
@Override
public Long getSourceTemplateId() {
return sourceTemplateId;
}
public void setSourceTemplateId(Long sourceTemplateId) {
this.sourceTemplateId = sourceTemplateId;
}
@Override
public String getTemplateTag() {
return templateTag;
}
public void setTemplateTag(String templateTag) {
this.templateTag = templateTag;
}
@Override
public long getDomainId() {
return -1;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
@Override
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
@Override
public Map<String, String> getDetails() {
return details;
}
public void setDetails(Map<String, String> details) {
this.details = details;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (!(that instanceof VMTemplateVO)) {
return false;
}
VMTemplateVO other = (VMTemplateVO)that;
return ((getUniqueName().equals(other.getUniqueName())));
}
@Override
public int hashCode() {
return uniqueName.hashCode();
}
@Transient
String toString;
@Override
public String toString() {
if (toString == null) {
toString = new StringBuilder("Tmpl[").append(id).append("-").append(format).append("-").append(uniqueName).toString();
}
return toString;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public void setSortKey(int key) {
sortKey = key;
}
public int getSortKey() {
return sortKey;
}
public void setDynamicallyScalable(boolean dynamicallyScalable) {
this.dynamicallyScalable = dynamicallyScalable;
}
@Override
public boolean isDynamicallyScalable() {
return dynamicallyScalable;
}
@Override
public boolean isEnableSshKey() {
return enableSshKey;
}
public void setEnableSshKey(boolean enable) {
enableSshKey = enable;
}
public void setSize(Long size) {
this.size = size;
}
public Long getSize() {
return size;
}
@Override
public long getUpdatedCount() {
return updatedCount;
}
@Override
public void incrUpdatedCount() {
updatedCount++;
}
public void decrUpdatedCount() {
updatedCount--;
}
@Override
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
public boolean isDirectDownload() {
return directDownload;
}
@Override
public Class<?> getEntityType() {
return VirtualMachineTemplate.class;
}
@Override
public Long getParentTemplateId() {
return parentTemplateId;
}
public void setParentTemplateId(Long parentTemplateId) {
this.parentTemplateId = parentTemplateId;
}
}