This repository was archived by the owner on Aug 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathAutomationDynamicNode.java
More file actions
238 lines (208 loc) · 7.1 KB
/
AutomationDynamicNode.java
File metadata and controls
238 lines (208 loc) · 7.1 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
/*
* Copyright (C) 2014 RetailMeNot, Inc.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package com.rmn.qa;
import java.util.Calendar;
import java.util.Date;
import org.openqa.selenium.Platform;
/**
* Represents a dynamically started node that is used to run tests
*/
public final class AutomationDynamicNode implements Comparable<AutomationDynamicNode> {
/** <pre>
* RUNNING - node is running and no further action needs to be taken
* EXPIRED - node has passed its expiration date and needs to be terminated. A node will not
* be marked expired if there is sufficient load on the system to require the node resources
* TERMINATED - node has been successfully terminated through the EC2 API
* </pre>
**/
public enum STATUS { RUNNING,EXPIRED,TERMINATED };
// This is used to set how far past the created date that the node will
// be marked for termination
private static final int NODE_INTERVAL_LIFETIME = 55; // 55 minutes
// TODO: Refactor this to be AutomationRunRequest
private final String uuid, instanceId, browser, ipAddress, instanceType;
private final Platform platform;
private Date startDate,endDate;
private final int nodeCapacity;
private STATUS status;
/**
* Constructor to create a new node representing instance
* @param uuid UUID of the test run that created this node
* @param instanceId Instance ID of the instance this node represents
* @param browser Requested browser of the test run that created this node
* @param platform Requested OS of the test run that created this node
* @param startDate Date that this node was started
* @param nodeCapacity Maximum test capacity that this node can run
*/
public AutomationDynamicNode(String uuid,String instanceId,String browser, Platform platform, Date startDate, int nodeCapacity){
this(uuid, instanceId, browser, platform, null, startDate, nodeCapacity);
}
public AutomationDynamicNode(String uuid,String instanceId,String browser, Platform platform, String ipAddress, Date startDate, int nodeCapacity){
this(uuid, instanceId, browser, platform, ipAddress, startDate, nodeCapacity, null);
}
public AutomationDynamicNode(String uuid,String instanceId,String browser, Platform platform, String ipAddress, Date startDate, int nodeCapacity, String instanceType){
this.uuid = uuid;
this.instanceId = instanceId;
this.browser = browser;
this.platform = platform;
this.ipAddress = ipAddress;
this.startDate = startDate;
this.endDate = computeEndDate(startDate);
this.nodeCapacity = nodeCapacity;
this.instanceType = instanceType;
this.status = STATUS.RUNNING;
}
/**
* Updates the status of this node.
* @param status
*/
public void updateStatus(STATUS status) {
this.status = status;
}
/**
* Computes the end date for this node based on the pre configured
* end time
* @param dateStarted
* @return
*/
private Date computeEndDate(Date dateStarted) {
Calendar c = Calendar.getInstance();
c.setTime(dateStarted);
c.add(Calendar.MINUTE, AutomationDynamicNode.NODE_INTERVAL_LIFETIME); // number of days to add
return c.getTime();
}
/**
* Returns the UUID for this node (will be the UUID of the run that
* resulted in this node being started)
* @return
*/
public String getUuid() {
return uuid;
}
/**
* Returns the instance id of this node
* @return
*/
public String getInstanceId() {
return instanceId;
}
/**
* Returns the browser of this node. Will be the browser of the
* run that resulted in this node being started
* @return
*/
public String getBrowser() {
return browser;
}
/**
* Returns the Platform of this node
* @return
*/
public Platform getPlatform() {
return platform;
}
/**
* Returns the private IP address of this node
* @return
*/
public String getIpAddress() {
return ipAddress;
}
/**
* Returns the date that his node was started. This will
* be the time that the node was requested and not necessarily started
* @return
*/
public Date getStartDate() {
return startDate;
}
/**
* Returns the currently scheduled end date of this node. Note
* that this can change as this node end date gets pushed back.
* @return
*/
public Date getEndDate() {
return endDate;
}
/**
* Sets the end date for this node.
* @param endDate Date which will be set for the end date
*/
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
/**
* Increments the end date by an hour. Useful for moving the end date into the next Amazon billing cycle
*/
public void incrementEndDateByOneHour() {
// Add 60 minutes so we're as close to the hour as we can be instead of adding 55 again
setEndDate(AutomationUtils.modifyDate(getEndDate(),60,Calendar.MINUTE));
}
/**
* Returns the total node capacity of this node (total number of browsers
* that can run simultaneously)
* @return
*/
public int getNodeCapacity() {
return nodeCapacity;
}
/**
* Returns the instance type of this node
* @return
*/
public String getInstanceType() {
return instanceType;
}
/**
* Returns the current status of this node.
* @return
*/
public STATUS getStatus(){
return status;
}
@Override
public int compareTo(AutomationDynamicNode o) {
return this.startDate.compareTo(getStartDate());
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AutomationDynamicNode that = (AutomationDynamicNode) o;
if (!instanceId.equals(that.instanceId)) {
return false;
}
if (!uuid.equals(that.uuid)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = uuid.hashCode();
result = 31 * result + instanceId.hashCode();
return result;
}
@Override
public String toString() {
return "AutomationDynamicNode{" +
"uuid='" + uuid + '\'' +
", instanceId='" + instanceId + '\'' +
", startDate=" + startDate +
", ipAddress='" + ipAddress + '\'' +
'}';
}
}