Skip to content

Commit f2f07da

Browse files
authored
Reconnect offline agents (#359)
1 parent 5b7e4cf commit f2f07da

5 files changed

Lines changed: 32 additions & 22 deletions

File tree

src/main/java/com/microsoft/azure/vmagent/AzureVMCloudOnceRetentionStrategy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public long check(final AzureVMComputer agentComputer) {
3838
done(agentComputer);
3939
}
4040
}
41+
42+
if (agentComputer.isOffline() && !agentComputer.isConnecting() && agentComputer.isLaunchSupported()) {
43+
agentComputer.tryReconnect();
44+
}
45+
4146
return 1;
4247
}
4348

src/main/java/com/microsoft/azure/vmagent/AzureVMCloudPoolRetentionStrategy.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@ public void run() {
9898
final int currentPoolSize
9999
= ((AzureVMCloudPoolRetentionStrategy) currentTemplate.getRetentionStrategy()).getPoolSize();
100100

101-
Computer.threadPoolForRemoting.submit(new Runnable() {
102-
@Override
103-
public void run() {
104-
checkPoolSizeAndDelete(agentComputer, currentPoolSize);
105-
}
106-
});
101+
Computer.threadPoolForRemoting.submit(() -> checkPoolSizeAndDelete(agentComputer, currentPoolSize));
102+
103+
if (agentComputer.isOffline() && !agentComputer.isConnecting() && agentComputer.isLaunchSupported()) {
104+
agentComputer.tryReconnect();
105+
}
107106

108107
return 1;
109108
}

src/main/java/com/microsoft/azure/vmagent/AzureVMCloudRetensionStrategy.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,38 @@ public long check(@NonNull AzureVMComputer agentNode) {
6161
return check(agentNode, new ExecutionEngine());
6262
}
6363

64-
protected long check(final AzureVMComputer agentNode, ExecutionEngine executionEngine) {
64+
protected long check(final AzureVMComputer agentComputer, ExecutionEngine executionEngine) {
6565
// Determine whether we can recycle this machine.
6666
// The CRS is the way that nodes that are currently operating "correctly"
6767
// can be retained/reclaimed. Any failure modes need to be dealt with through
68-
// the clean up task.
68+
// the cleanup task.
6969

70-
boolean canRecycle = true;
7170
// Node must be idle
72-
canRecycle &= agentNode.isIdle();
71+
boolean canRecycle = agentComputer.isIdle();
7372
// The node must also be online. This also implies not temporarily disconnected
7473
// (like by a user).
75-
canRecycle &= agentNode.isOnline();
74+
canRecycle &= agentComputer.isOnline();
7675
// The configured idle time must be > 0 (which means leave forever)
7776
canRecycle &= idleTerminationMillis > 0;
7877
// The number of ms it's been idle must be greater than the current idle time.
79-
canRecycle &= idleTerminationMillis < (System.currentTimeMillis() - agentNode.getIdleStartMilliseconds());
78+
canRecycle &= idleTerminationMillis < (System.currentTimeMillis() - agentComputer.getIdleStartMilliseconds());
8079

81-
if (agentNode.getNode() == null) {
80+
if (agentComputer.getNode() == null) {
8281
return 1;
8382
}
8483

85-
final AzureVMAgent agent = agentNode.getNode();
84+
final AzureVMAgent agent = agentComputer.getNode();
8685

8786
if (canRecycle) {
8887
LOGGER.log(Level.INFO, "Idle timeout reached for agent: {0}, action: {1}",
89-
new Object[]{agentNode.getName(), agent.isShutdownOnIdle() ? "shutdown" : "delete"});
88+
new Object[]{agentComputer.getName(), agent.isShutdownOnIdle() ? "shutdown" : "delete"});
9089

9190
Callable<Void> task = () -> {
9291
// Block cleanup while we execute so the cleanup task doesn't try to take it
9392
// away (node will go offline). Also blocks cleanup in case of shutdown.
9493
agent.blockCleanUpAction();
9594
if (agent.isShutdownOnIdle()) {
96-
LOGGER.log(Level.INFO, "Going to idleTimeout agent: {0}", agentNode.getName());
95+
LOGGER.log(Level.INFO, "Going to idleTimeout agent: {0}", agentComputer.getName());
9796
agent.shutdown(Messages._Idle_Timeout_Shutdown());
9897
} else {
9998
agent.deprovision(Messages._Idle_Timeout_Delete());
@@ -112,24 +111,31 @@ protected long check(final AzureVMComputer agentNode, ExecutionEngine executionE
112111
defaultTimeoutInSeconds
113112
));
114113
} catch (AzureCloudException ae) {
115-
LOGGER.log(Level.WARNING, String.format("Could not terminate or shutdown %s", agentNode.getName()), ae);
114+
LOGGER.log(Level.WARNING, String.format("Could not terminate or shutdown %s",
115+
agentComputer.getName()), ae);
116116
// If we have an exception, set the agent for deletion.
117117
// It's unlikely we'll be able to shut it down properly ever.
118-
AzureVMAgent node = agentNode.getNode();
118+
AzureVMAgent node = agentComputer.getNode();
119119
if (node != null) {
120120
node.setCleanUpAction(CleanUpAction.DELETE, Messages._Failed_Initial_Shutdown_Or_Delete());
121121
}
122122
} catch (Exception e) {
123123
LOGGER.log(Level.WARNING,
124-
String.format("Exception occurred while calling timeout on node %s", agentNode.getName()), e);
124+
String.format("Exception occurred while calling timeout on node %s",
125+
agentComputer.getName()), e);
125126
// If we have an exception, set the agent for deletion.
126127
// It's unlikely we'll be able to shut it down properly ever.
127-
AzureVMAgent node = agentNode.getNode();
128+
AzureVMAgent node = agentComputer.getNode();
128129
if (node != null) {
129130
node.setCleanUpAction(CleanUpAction.DELETE, Messages._Failed_Initial_Shutdown_Or_Delete());
130131
}
131132
}
132133
}
134+
135+
if (agentComputer.isOffline() && !agentComputer.isConnecting() && agentComputer.isLaunchSupported()) {
136+
agentComputer.tryReconnect();
137+
}
138+
133139
return 1;
134140
}
135141

src/main/resources/scripts/ubuntuInstallMavenScript.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Install Maven
22

3-
MAVEN_VERSION=3.8.4
3+
MAVEN_VERSION=3.8.5
44

55
sudo curl -O https://downloads.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
66
sudo tar zxvf apache-maven-${MAVEN_VERSION}-bin.tar.gz -C /opt/

src/main/webapp/help-initScript.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
sudo apt-get install -y git
1818

1919
# Install Maven
20-
MAVEN_VERSION=3.8.4
20+
MAVEN_VERSION=3.8.5
2121

2222
sudo curl -O https://downloads.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz
2323
sudo tar zxvf apache-maven-${MAVEN_VERSION}-bin.tar.gz -C /opt/

0 commit comments

Comments
 (0)