Skip to content

Commit 98dc4eb

Browse files
authored
CLOUDSTACK-9782: New Background Polling Task Manager (#2218)
CloudStack has several background polling tasks that are spread across the codebase, the aim of this work is to provide a single manager to handle submission, execution and handling of background tasks. With the framework implemented, existing oobm background task has been refactored to use this manager. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 5397106 commit 98dc4eb

18 files changed

Lines changed: 334 additions & 115 deletions

File tree

api/src/org/apache/cloudstack/api/command/admin/outofbandmanagement/ChangeOutOfBandManagementPasswordCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
7474
CallContext.current().setEventDetails("Host Id: " + host.getId() + " Password: " + getPassword().charAt(0) + "****");
7575
CallContext.current().putContextParameter(Host.class, host.getUuid());
7676

77-
final OutOfBandManagementResponse response = outOfBandManagementService.changeOutOfBandManagementPassword(host, getPassword());
77+
final OutOfBandManagementResponse response = outOfBandManagementService.changePassword(host, getPassword());
7878
response.setResponseName(getCommandName());
7979
setResponseObject(response);
8080
}

api/src/org/apache/cloudstack/api/command/admin/outofbandmanagement/ConfigureOutOfBandManagementCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
8383
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to find host by ID: " + getHostId());
8484
}
8585
CallContext.current().putContextParameter(Host.class, host.getUuid());
86-
final OutOfBandManagementResponse response = outOfBandManagementService.configureOutOfBandManagement(host, getHostPMOptions());
86+
final OutOfBandManagementResponse response = outOfBandManagementService.configure(host, getHostPMOptions());
8787
response.setId(host.getUuid());
8888
response.setResponseName(getCommandName());
8989
setResponseObject(response);

api/src/org/apache/cloudstack/api/command/admin/outofbandmanagement/IssueOutOfBandManagementPowerActionCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
8080
CallContext.current().setEventDetails("Host Id: " + host.getId() + " Action: " + powerOperation.toString());
8181
CallContext.current().putContextParameter(Host.class, host.getUuid());
8282

83-
final OutOfBandManagementResponse response = outOfBandManagementService.executeOutOfBandManagementPowerOperation(host, powerOperation, getActionTimeout());
83+
final OutOfBandManagementResponse response = outOfBandManagementService.executePowerOperation(host, powerOperation, getActionTimeout());
8484
response.setResponseName(getCommandName());
8585
setResponseObject(response);
8686
}

api/src/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementService.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public interface OutOfBandManagementService {
3030
ConfigKey<Long> ActionTimeout = new ConfigKey<Long>("Advanced", Long.class, "outofbandmanagement.action.timeout", "60",
3131
"The out of band management action timeout in seconds, configurable by cluster", true, ConfigKey.Scope.Cluster);
3232

33-
ConfigKey<Long> SyncThreadInterval = new ConfigKey<Long>("Advanced", Long.class, "outofbandmanagement.sync.interval", "300000",
34-
"The interval (in milliseconds) when the out-of-band management background sync are retrieved", true, ConfigKey.Scope.Global);
35-
3633
ConfigKey<Integer> SyncThreadPoolSize = new ConfigKey<Integer>("Advanced", Integer.class, "outofbandmanagement.sync.poolsize", "50",
3734
"The out of band management background sync thread pool size", true, ConfigKey.Scope.Global);
3835

@@ -49,7 +46,7 @@ public interface OutOfBandManagementService {
4946
OutOfBandManagementResponse disableOutOfBandManagement(Cluster cluster);
5047
OutOfBandManagementResponse disableOutOfBandManagement(Host host);
5148

52-
OutOfBandManagementResponse configureOutOfBandManagement(Host host, ImmutableMap<OutOfBandManagement.Option, String> options);
53-
OutOfBandManagementResponse executeOutOfBandManagementPowerOperation(Host host, OutOfBandManagement.PowerOperation operation, Long timeout);
54-
OutOfBandManagementResponse changeOutOfBandManagementPassword(Host host, String password);
49+
OutOfBandManagementResponse configure(Host host, ImmutableMap<OutOfBandManagement.Option, String> options);
50+
OutOfBandManagementResponse executePowerOperation(Host host, OutOfBandManagement.PowerOperation operation, Long timeout);
51+
OutOfBandManagementResponse changePassword(Host host, String password);
5552
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.poll;
19+
20+
public interface BackgroundPollManager {
21+
/**
22+
* Submits a background poll task that need to run continuously in the background
23+
* to poll external resources, update states, trigger actions etc.
24+
* Tasks must be submitted by a manager in configure-phase, the list of submitted tasks
25+
* are then submitted to the internal executor service during start-phase.
26+
* @param task periodic background task
27+
* @since 4.11
28+
*/
29+
void submitTask(final BackgroundPollTask task);
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.poll;
19+
20+
public interface BackgroundPollTask extends Runnable {
21+
}

developer/developer-prefill.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ INSERT INTO `cloud`.`configuration` (category, instance, component, name, value)
114114
VALUES ('Advanced', 'DEFAULT', 'management-server',
115115
'ping.timeout', '1.5');
116116

117-
INSERT INTO `cloud`.`configuration` (category, instance, component, name, value)
118-
VALUES ('Advanced', 'DEFAULT', 'management-server',
119-
'outofbandmanagement.sync.interval', '1000');
120-
121117
-- Enable dynamic RBAC by default for fresh deployments
122118
INSERT INTO `cloud`.`configuration` (category, instance, component, name, value)
123119
VALUES ('Advanced', 'DEFAULT', 'RoleService',

engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
5050
import org.apache.cloudstack.utils.identity.ManagementServerNode;
5151
import org.apache.cloudstack.utils.security.SSLUtils;
52+
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5253
import org.apache.log4j.Logger;
5354

5455
import com.cloud.agent.api.Answer;
@@ -120,6 +121,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
120121
ConfigurationDao _configDao;
121122
@Inject
122123
ConfigDepot _configDepot;
124+
@Inject
125+
private OutOfBandManagementDao outOfBandManagementDao;
123126

124127
protected ClusteredAgentManagerImpl() {
125128
super();
@@ -736,7 +739,7 @@ public void onManagementNodeLeft(final List<? extends ManagementServerHost> node
736739
s_logger.info("Marking hosts as disconnected on Management server" + vo.getMsid());
737740
final long lastPing = (System.currentTimeMillis() >> 10) - getTimeout();
738741
_hostDao.markHostsAsDisconnected(vo.getMsid(), lastPing);
739-
outOfBandManagementDao.expireOutOfBandManagementOwnershipByServer(vo.getMsid());
742+
outOfBandManagementDao.expireServerOwnership(vo.getMsid());
740743
s_logger.info("Deleting entries from op_host_transfer table for Management server " + vo.getMsid());
741744
cleanupTransferMap(vo.getMsid());
742745
}

engine/schema/src/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
public interface OutOfBandManagementDao extends GenericDao<OutOfBandManagementVO, Long>, StateDao<OutOfBandManagement.PowerState, OutOfBandManagement.PowerState.Event, OutOfBandManagement> {
2828
OutOfBandManagement findByHost(long hostId);
2929
List<OutOfBandManagementVO> findAllByManagementServer(long serverId);
30-
void expireOutOfBandManagementOwnershipByServer(long serverId);
30+
void expireServerOwnership(long serverId);
3131
}

engine/schema/src/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
110110
}
111111

112112
@Override
113-
public void expireOutOfBandManagementOwnershipByServer(long serverId) {
113+
public void expireServerOwnership(long serverId) {
114114
final String resetOwnerSql = "UPDATE oobm set mgmt_server_id=NULL, power_state=NULL where mgmt_server_id=?";
115115
executeExpireOwnershipSql(resetOwnerSql, serverId);
116116
if (LOG.isDebugEnabled()) {

0 commit comments

Comments
 (0)