-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServer.java
More file actions
286 lines (242 loc) · 9.12 KB
/
Server.java
File metadata and controls
286 lines (242 loc) · 9.12 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
package dev.tomr.hcloud.resources.server;
import dev.tomr.hcloud.HetznerCloud;
import dev.tomr.hcloud.resources.common.*;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public class Server implements Serializable {
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
private Integer id;
private String backupWindow;
private String created;
private Datacenter datacenter;
private Image image;
private Long includedTraffic;
private Long ingoingTraffic;
private Long outgoingTraffic;
private Iso iso;
private Map<String, String> labels;
private List<Object> loadBalancers; // need to figure this out
private Boolean locked;
private String name;
private PlacementGroup placementGroup;
private Long primaryDiskSize;
//todo change this to an actual class
private List<Object> privateNet;
private Protection protection;
private Object publicNet;
private Boolean rescueEnabled;
private ServerType serverType;
private String status;
private List<Integer> volumes;
/**
* Creates a new {@code Server} to be monitored by the library. If you want to create a new Hetzner Server, don't call this, as it won't 'create' a new instance remotely.
*/
public Server() {
setupPropertyChangeListener();
}
/**
* Creates a new {@code Server} to be monitored by the library. If you want to create a new Hetzner Server, don't call this, as it won't 'create' a new instance remotely.
* @param id Server ID
* @param backupWindow Server backupWindow
* @param created Server created date
* @param datacenter Associated Datacenter
* @param image Associated Image
* @param includedTraffic Included Traffic
* @param ingoingTraffic Ingoing Traffic
* @param outgoingTraffic Outgoing Traffic
* @param iso Associated ISO
* @param labels Associated Labels
* @param loadBalancers Associated Load Balancers
* @param locked Whether the server is locked or not
* @param name Name of the Server
* @param placementGroup Server's placement group
* @param primaryDiskSize Primary Disks' size
* @param privateNet Attached Private Networks
* @param protection Associated Protection
* @param publicNet AAttached Public Networks
* @param rescueEnabled Whether rescue is enabled or not
* @param serverType Associated Server Type
* @param status Status of the Server
* @param volumes Attached Volumes
*/
public Server(Integer id, String backupWindow, String created, Datacenter datacenter, Image image, Long includedTraffic, Long ingoingTraffic, Long outgoingTraffic, Iso iso, Map<String, String> labels, List<Object> loadBalancers, Boolean locked, String name, PlacementGroup placementGroup, Long primaryDiskSize, List<Object> privateNet, Protection protection, Object publicNet, Boolean rescueEnabled, ServerType serverType, String status, List<Integer> volumes) {
this.id = id;
this.backupWindow = backupWindow;
this.created = created;
this.datacenter = datacenter;
this.image = image;
this.includedTraffic = includedTraffic;
this.ingoingTraffic = ingoingTraffic;
this.outgoingTraffic = outgoingTraffic;
this.iso = iso;
this.labels = labels;
this.loadBalancers = loadBalancers;
this.locked = locked;
this.name = name;
this.placementGroup = placementGroup;
this.primaryDiskSize = primaryDiskSize;
this.privateNet = privateNet;
this.protection = protection;
this.publicNet = publicNet;
this.rescueEnabled = rescueEnabled;
this.serverType = serverType;
this.status = status;
this.volumes = volumes;
setupPropertyChangeListener();
}
private void setupPropertyChangeListener() {
propertyChangeSupport.addPropertyChangeListener(HetznerCloud.getInstance().getListenerManager().getServerChangeListener());
}
// The following methods are for calling Actions on the server
/**
* Deletes a Server from Hetzner. Note, this is immediate and destructive. Ensure you want to delete the server before calling.
*/
public void delete() {
propertyChangeSupport.firePropertyChange("delete", null, null);
}
/**
* Sends a Shutdown request to the server by sending an ACPI request, which will instruct the OS to shut it down. Note that if you <b>must</b>> ensure the server is completely offline, you should also call .powerOff() to ensure the 'plug is pulled'.
* The server OS must support ACPI
*/
public void shutdown() {
propertyChangeSupport.firePropertyChange("shutdown", null, null);
}
/**
* Sends a command to Power off the server. This is essentially <b>'pulling the plug'</b> and could be destructive if programs are still running on the server. <b>Only use if absolutely necessary</b>
*/
public void powerOff() {
propertyChangeSupport.firePropertyChange("poweroff", null, null);
}
/**
* Starts the Server by turning its power on
*/
public void powerOn() {
propertyChangeSupport.firePropertyChange("poweron", null, null);
}
/**
* Sends a reboot request to the server by sending an ACPI request. The server OS must support ACPI
*/
public void reboot() {
propertyChangeSupport.firePropertyChange("reboot", null, null);
}
/**
* Cuts power to the server and starts it again. Forcefully stops the server without giving the OS time to shut down. Should only be used if reboot does not work.
*/
public void reset() {
propertyChangeSupport.firePropertyChange("reset", null, null);
}
/**
* Adds the server to a given placement group
* @param placementGroup The Placement group to add the server to
*/
public void addToPlacementGroup(PlacementGroup placementGroup) {
propertyChangeSupport.firePropertyChange("addToPlacementGroup", null, placementGroup.getId());
}
/**
* Removes the server from any placement groups it may be in
*/
public void removeFromPlacementGroup() {
propertyChangeSupport.firePropertyChange("removeFromPlacementGroup", null, null);
}
/**
* Updates the Protection of a Server
* @param protection The protection values to be applied
*/
public void changeServerProtection(Protection protection) {
propertyChangeSupport.firePropertyChange("changeServerProtection", null, protection);
}
// These are the current setters that will send an API request (PUT /servers) when actions begin to be added, they will also likely be triggered by setters
/**
* Get current labels associated with this {@code Server}
* @return {@code Map<String, String>} of the labels
*/
public Map<String, String> getLabels() {
return labels;
}
/**
* Set's the labels to the specified param. Triggers a remote update with Hetzner.
* @param labels New set of labels for this server
*/
public void setLabels(Map<String, String> labels) {
propertyChangeSupport.firePropertyChange("labels", this.labels, labels);
this.labels = labels;
}
/**
* Get the current name of this Server
* @return {@code String} with the server name
*/
public String getName() {
return name;
}
/**
* Set's the name to the specified param. Triggers a remote update with Hetzner.
* @param name New name for this server
*/
public void setName(String name) {
propertyChangeSupport.firePropertyChange("name", this.name, name);
this.name = name;
}
// Getter only (no support to change in API)
public Integer getId() {
return id;
}
public String getBackupWindow() {
return backupWindow;
}
public String getCreated() {
return created;
}
public Datacenter getDatacenter() {
return datacenter;
}
public Image getImage() {
return image;
}
public Long getIncludedTraffic() {
return includedTraffic;
}
public Long getIngoingTraffic() {
return ingoingTraffic;
}
public Long getOutgoingTraffic() {
return outgoingTraffic;
}
public Iso getIso() {
return iso;
}
public List<Object> getLoadBalancers() {
return loadBalancers;
}
public Boolean isLocked() {
return locked;
}
public PlacementGroup getPlacementGroup() {
return placementGroup;
}
public Long getPrimaryDiskSize() {
return primaryDiskSize;
}
public List<Object> getPrivateNet() {
return privateNet;
}
public Protection getProtection() {
return protection;
}
public Object getPublicNet() {
return publicNet;
}
public Boolean isRescueEnabled() {
return rescueEnabled;
}
public ServerType getServerType() {
return serverType;
}
public String getStatus() {
return status;
}
public List<Integer> getVolumes() {
return volumes;
}
}