Skip to content

Commit 7124922

Browse files
Shutdown MS maintenance jobs when finished (#11330)
1 parent 70468a6 commit 7124922

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

agent/src/main/java/com/cloud/agent/Agent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,11 @@ private Answer migrateAgentToOtherMS(final MigrateAgentConnectionCommand cmd) {
968968
if (CollectionUtils.isNotEmpty(cmd.getMsList())) {
969969
processManagementServerList(cmd.getMsList(), cmd.getAvoidMsList(), cmd.getLbAlgorithm(), cmd.getLbCheckInterval(), false);
970970
}
971-
Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("MigrateAgentConnection-Job")).schedule(() -> {
971+
ScheduledExecutorService migrateAgentConnectionService = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("MigrateAgentConnection-Job"));
972+
migrateAgentConnectionService.schedule(() -> {
972973
migrateAgentConnection(cmd.getAvoidMsList());
973974
}, 3, TimeUnit.SECONDS);
975+
migrateAgentConnectionService.shutdown();
974976
} catch (Exception e) {
975977
String errMsg = "Migrate agent connection failed, due to " + e.getMessage();
976978
logger.debug(errMsg, e);

plugins/maintenance/src/main/java/org/apache/cloudstack/maintenance/ManagementServerMaintenanceManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ protected void runInContext() {
622622
ManagementServerHostVO msHost = msHostDao.findByMsid(ManagementServerNode.getManagementServerId());
623623
if (msHost == null) {
624624
logger.warn("Unable to find the management server, invalid node id");
625+
managementServerMaintenanceManager.cancelWaitForPendingJobs();
625626
return;
626627
}
627628
msHostDao.updateState(msHost.getId(), State.Maintenance);
@@ -658,6 +659,7 @@ protected void runInContext() {
658659
ManagementServerHostVO msHost = msHostDao.findByMsid(ManagementServerNode.getManagementServerId());
659660
if (msHost == null) {
660661
logger.warn("Unable to find the management server, invalid node id");
662+
managementServerMaintenanceManager.cancelWaitForPendingJobs();
661663
return;
662664
}
663665
if (totalAgents == 0) {
@@ -693,6 +695,7 @@ protected void runInContext() {
693695
ManagementServerHostVO msHost = msHostDao.findByMsid(ManagementServerNode.getManagementServerId());
694696
if (msHost == null) {
695697
logger.warn("Unable to find the management server, invalid node id");
698+
managementServerMaintenanceManager.cancelWaitForPendingJobs();
696699
return;
697700
}
698701
msHostDao.updateState(msHost.getId(), State.ReadyToShutDown);

0 commit comments

Comments
 (0)