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
| import java.util.Arrays;
public class VirtualMachine {
// 10 required fields: CloudProvider, Region, AvailabilityZone, ImageId, InstanceClass, vpc, Subnet, SecurityGroup, and PublicKey, and publicIP.
private String cloudProvider;
private String region;
private String availabilityZone;
private String imageId;
private String instanceClass;
private String vpc;
private String subnet;
private String securityGroup;
private String publicKey;
private String publicIP;
// 7 optional fields: Ports, PrivateIP, PlacementGroup, Architecture, Hypervisor, Storage, and Tags.
private String[] ports;
private String privateIP;
private String placementGroup;
private String architecture;
private String hypervisor;
private String storage;
private String[] tags;
// This creates a VirtualMachine instance with all required fields
private VirtualMachine(VMBuilder builder) {
this.cloudProvider = builder.cloudProvider;
this.region = builder.region;
this.availabilityZone = builder.availabilityZone;
this.imageId = builder.imageId;
this.instanceClass = builder.instanceClass;
this.vpc = builder.vpc;
this.subnet = builder.subnet;
this.securityGroup = builder.securityGroup;
this.publicKey = builder.publicKey;
this.publicIP = builder.publicIP;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("VirtualMachine{" +
"cloudProvider='" + cloudProvider + '\'' +
", region='" + region + '\'' +
", availabilityZone='" + availabilityZone + '\'' +
", imageId='" + imageId + '\'' +
", instanceClass='" + instanceClass + '\'' +
", vpc='" + vpc + '\'' +
", subnet='" + subnet + '\'' +
", securityGroup='" + securityGroup + '\'' +
", publicKey='" + publicKey + '\'' +
", publicIP='" + publicIP + '\'');
if (ports != null) {
sb.append(", ports=" + Arrays.toString(ports));
}
if (privateIP != null) {
sb.append(", privateIP='" + privateIP + '\'');
}
if (placementGroup != null) {
sb.append(", placementGroup='" + placementGroup + '\'');
}
if (architecture != null) {
sb.append(", architecture='" + architecture + '\'');
}
if (hypervisor != null) {
sb.append(", hypervisor='" + hypervisor + '\'');
}
if (storage != null) {
sb.append(", storage='" + storage + '\'');
}
if (tags != null) {
sb.append(", tags=" + Arrays.toString(tags));
}
sb.append("}");
return sb.toString();
}
public static class VMBuilder {
// 10 required fields: CloudProvider, Region, AvailabilityZone, ImageId, InstanceClass, vpc, Subnet, SecurityGroup, and PublicKey, and publicIP.
private String cloudProvider;
private String region;
private String availabilityZone;
private String imageId;
private String instanceClass;
private String vpc;
private String subnet;
private String securityGroup;
private String publicKey;
private String publicIP;
// 7 optional fields: Ports, PrivateIP, PlacementGroup, Architecture, Hypervisor, Storage, and Tags.
private String[] ports;
private String privateIP;
private String placementGroup;
private String architecture;
private String hypervisor;
private String storage;
private String[] tags;
public VMBuilder(String cloudProvider, String region, String availabilityZone, String imageId,
String instanceClass, String vpc, String subnet, String securityGroup,
String publicKey, String publicIP) {
this.cloudProvider = cloudProvider;
this.region = region;
this.availabilityZone = availabilityZone;
this.imageId = imageId;
this.instanceClass = instanceClass;
this.vpc = vpc;
this.subnet = subnet;
this.securityGroup = securityGroup;
this.publicKey = publicKey;
this.publicIP = publicIP;
}
public VMBuilder withPorts(String[] ports) {
this.ports = ports;
return this;
}
public VMBuilder withPrivateIP(String privateIP) {
this.privateIP = privateIP;
return this;
}
public VMBuilder withPlacementGroup(String placementGroup) {
this.placementGroup = placementGroup;
return this;
}
public VMBuilder withArchitecture(String architecture) {
this.architecture = architecture;
return this;
}
public VMBuilder withHypervisor(String hypervisor) {
this.hypervisor = hypervisor;
return this;
}
public VMBuilder withStorage(String storage) {
this.storage = storage;
return this;
}
public VMBuilder withTags(String[] tags) {
this.tags = tags;
return this;
}
public VirtualMachine build(){
return new VirtualMachine(this);
}
}
}
|