Skip to content

Commit f02d288

Browse files
ustcweizhouggoodrich-ipp
authored andcommitted
KVM: Propagating changes on host parameters to the agents (apache#3491)
1 parent 8c117bd commit f02d288

File tree

9 files changed

+100
-27
lines changed

9 files changed

+100
-27
lines changed

engine/components-api/src/main/java/com/cloud/agent/AgentManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ public enum TapAgentsAction {
152152
void notifyMonitorsOfHostAboutToBeRemoved(long hostId);
153153

154154
void notifyMonitorsOfRemovedHost(long hostId, long clusterId);
155+
156+
void propagateChangeToAgents();
155157
}

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,4 +1790,45 @@ public int getTimeout() {
17901790

17911791
}
17921792

1793+
protected Map<Long, List<Long>> getHostsPerZone() {
1794+
List<HostVO> allHosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
1795+
if (allHosts == null) {
1796+
return null;
1797+
}
1798+
Map<Long, List<Long>> hostsByZone = new HashMap<Long, List<Long>>();
1799+
for (HostVO host : allHosts) {
1800+
if (host.getHypervisorType() == HypervisorType.KVM || host.getHypervisorType() == HypervisorType.LXC) {
1801+
Long zoneId = host.getDataCenterId();
1802+
List<Long> hostIds = hostsByZone.get(zoneId);
1803+
if (hostIds == null) {
1804+
hostIds = new ArrayList<Long>();
1805+
}
1806+
hostIds.add(host.getId());
1807+
hostsByZone.put(zoneId, hostIds);
1808+
}
1809+
}
1810+
return hostsByZone;
1811+
}
1812+
1813+
private void sendCommandToAgents(Map<Long, List<Long>> hostsPerZone, Map<String, String> params) {
1814+
SetHostParamsCommand cmds = new SetHostParamsCommand(params);
1815+
for (Long zoneId : hostsPerZone.keySet()) {
1816+
List<Long> hostIds = hostsPerZone.get(zoneId);
1817+
for (Long hostId : hostIds) {
1818+
Answer answer = easySend(hostId, cmds);
1819+
if (answer == null || !answer.getResult()) {
1820+
s_logger.error("Error sending parameters to agent " + hostId);
1821+
}
1822+
}
1823+
}
1824+
}
1825+
1826+
@Override
1827+
public void propagateChangeToAgents() {
1828+
s_logger.debug("Propagating changes on host parameters to the agents");
1829+
Map<Long, List<Long>> hostsPerZone = getHostsPerZone();
1830+
Map<String, String> params = new HashMap<String, String>();
1831+
params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
1832+
sendCommandToAgents(hostsPerZone, params);
1833+
}
17931834
}

framework/agent-lb/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLB.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ public interface IndirectAgentLB {
5050
* @return returns interval in seconds
5151
*/
5252
Long getLBPreferredHostCheckInterval(Long clusterId);
53-
}
53+
54+
void propagateMSListToAgents();
55+
56+
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
import com.cloud.agent.api.to.NfsTO;
104104
import com.cloud.agent.api.to.NicTO;
105105
import com.cloud.agent.api.to.VirtualMachineTO;
106+
import com.cloud.agent.dao.impl.PropertiesStorage;
106107
import com.cloud.agent.resource.virtualnetwork.VRScripts;
107108
import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
108109
import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
@@ -1102,6 +1103,24 @@ public boolean configure(final String name, final Map<String, Object> params) th
11021103
return true;
11031104
}
11041105

1106+
public boolean configureHostParams(final Map<String, String> params) {
1107+
final File file = PropertiesUtil.findConfigFile("agent.properties");
1108+
if (file == null) {
1109+
s_logger.error("Unable to find the file agent.properties");
1110+
return false;
1111+
}
1112+
// Save configurations in agent.properties
1113+
PropertiesStorage storage = new PropertiesStorage();
1114+
storage.configure("Storage", new HashMap<String, Object>());
1115+
if (params.get("router.aggregation.command.each.timeout") != null) {
1116+
String value = (String)params.get("router.aggregation.command.each.timeout");
1117+
Integer intValue = NumbersUtil.parseInt(value, 600);
1118+
storage.persist("router.aggregation.command.each.timeout", String.valueOf(intValue));
1119+
}
1120+
1121+
return true;
1122+
}
1123+
11051124
protected void configureDiskActivityChecks(final Map<String, Object> params) {
11061125
_diskActivityCheckEnabled = Boolean.parseBoolean((String)params.get("vm.diskactivity.checkenabled"));
11071126
if (_diskActivityCheckEnabled) {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetHostParamsCommandWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public Answer execute(final SetHostParamsCommand command, final LibvirtComputing
3535

3636
final Map<String, String> params = command.getParams();
3737
boolean success = libvirtComputingResource.getVirtRouterResource().configureHostParams(params);
38+
success = success && libvirtComputingResource.configureHostParams(params);
3839

3940
if (!success) {
4041
return new Answer(command, false, "Failed to set host parameters");

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.configuration;
1818

19+
import com.cloud.agent.AgentManager;
1920
import com.cloud.alert.AlertManager;
2021
import com.cloud.api.ApiDBUtils;
2122
import com.cloud.api.query.dao.NetworkOfferingJoinDao;
@@ -161,6 +162,8 @@
161162
import org.apache.cloudstack.affinity.AffinityGroup;
162163
import org.apache.cloudstack.affinity.AffinityGroupService;
163164
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
165+
import org.apache.cloudstack.agent.lb.IndirectAgentLB;
166+
import org.apache.cloudstack.agent.lb.IndirectAgentLBServiceImpl;
164167
import org.apache.cloudstack.api.ApiConstants;
165168
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
166169
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
@@ -187,6 +190,7 @@
187190
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
188191
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
189192
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
193+
import org.apache.cloudstack.config.ApiServiceConfiguration;
190194
import org.apache.cloudstack.config.Configuration;
191195
import org.apache.cloudstack.context.CallContext;
192196
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@@ -198,6 +202,7 @@
198202
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
199203
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
200204
import org.apache.cloudstack.framework.messagebus.MessageBus;
205+
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
201206
import org.apache.cloudstack.framework.messagebus.PublishScope;
202207
import org.apache.cloudstack.region.PortableIp;
203208
import org.apache.cloudstack.region.PortableIpDao;
@@ -372,6 +377,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
372377
ImageStoreDetailsDao _imageStoreDetailsDao;
373378
@Inject
374379
MessageBus messageBus;
380+
@Inject
381+
AgentManager _agentManager;
382+
@Inject
383+
IndirectAgentLB _indirectAgentLB;
375384

376385

377386
// FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
@@ -404,6 +413,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
404413
populateConfigValuesForValidationSet();
405414
weightBasedParametersForValidation();
406415
overProvisioningFactorsForValidation();
416+
initMessageBusListener();
407417
return true;
408418
}
409419

@@ -461,6 +471,24 @@ private void overProvisioningFactorsForValidation() {
461471
overprovisioningFactorsForValidation.add(CapacityManager.StorageOverprovisioningFactor.key());
462472
}
463473

474+
private void initMessageBusListener() {
475+
messageBus.subscribe(EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, new MessageSubscriber() {
476+
@Override
477+
public void onPublishMessage(String serderAddress, String subject, Object args) {
478+
String globalSettingUpdated = (String) args;
479+
if (Strings.isNullOrEmpty(globalSettingUpdated)) {
480+
return;
481+
}
482+
if (globalSettingUpdated.equals(ApiServiceConfiguration.ManagementServerAddresses.key()) ||
483+
globalSettingUpdated.equals(IndirectAgentLBServiceImpl.IndirectAgentLBAlgorithm.key())) {
484+
_indirectAgentLB.propagateMSListToAgents();
485+
} else if (globalSettingUpdated.equals(Config.RouterAggregationCommandEachTimeout.toString())) {
486+
_agentManager.propagateChangeToAgents();
487+
}
488+
}
489+
});
490+
}
491+
464492
@Override
465493
public boolean start() {
466494

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@
3434
import org.apache.cloudstack.config.ApiServiceConfiguration;
3535
import org.apache.cloudstack.framework.config.ConfigKey;
3636
import org.apache.cloudstack.framework.config.Configurable;
37-
import org.apache.cloudstack.framework.messagebus.MessageBus;
38-
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
3937
import org.apache.log4j.Logger;
4038

4139
import com.cloud.agent.AgentManager;
4240
import com.cloud.agent.api.Answer;
43-
import com.cloud.event.EventTypes;
4441
import com.cloud.host.Host;
4542
import com.cloud.host.HostVO;
4643
import com.cloud.host.dao.HostDao;
@@ -68,8 +65,6 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
6865
@Inject
6966
private HostDao hostDao;
7067
@Inject
71-
private MessageBus messageBus;
72-
@Inject
7368
private AgentManager agentManager;
7469

7570
//////////////////////////////////////////////////////
@@ -208,7 +203,8 @@ private org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm getAgentMSLBAlgo
208203
/////////////// Agent MSLB Configuration ///////////////////
209204
////////////////////////////////////////////////////////////
210205

211-
private void propagateMSListToAgents() {
206+
@Override
207+
public void propagateMSListToAgents() {
212208
LOG.debug("Propagating management server list update to agents");
213209
final String lbAlgorithm = getLBAlgorithmName();
214210
final Map<Long, List<Long>> dcOrderedHostsMap = new HashMap<>();
@@ -227,22 +223,6 @@ private void propagateMSListToAgents() {
227223
}
228224
}
229225

230-
private void configureMessageBusListener() {
231-
messageBus.subscribe(EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, new MessageSubscriber() {
232-
@Override
233-
public void onPublishMessage(final String senderAddress, String subject, Object args) {
234-
final String globalSettingUpdated = (String) args;
235-
if (Strings.isNullOrEmpty(globalSettingUpdated)) {
236-
return;
237-
}
238-
if (globalSettingUpdated.equals(ApiServiceConfiguration.ManagementServerAddresses.key()) ||
239-
globalSettingUpdated.equals(IndirectAgentLBAlgorithm.key())) {
240-
propagateMSListToAgents();
241-
}
242-
}
243-
});
244-
}
245-
246226
private void configureAlgorithmMap() {
247227
final List<org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm> algorithms = new ArrayList<>();
248228
algorithms.add(new IndirectAgentLBStaticAlgorithm());
@@ -258,7 +238,6 @@ private void configureAlgorithmMap() {
258238
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
259239
super.configure(name, params);
260240
configureAlgorithmMap();
261-
configureMessageBusListener();
262241
return true;
263242
}
264243

@@ -274,4 +253,4 @@ public ConfigKey<?>[] getConfigKeys() {
274253
IndirectAgentLBCheckInterval
275254
};
276255
}
277-
}
256+
}

server/src/test/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImplTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ private void configureMocks() throws NoSuchFieldException, IllegalAccessExceptio
9595
id++;
9696
}
9797
addField(agentMSLB, "hostDao", hostDao);
98-
addField(agentMSLB, "messageBus", messageBus);
9998
addField(agentMSLB, "agentManager", agentManager);
10099

101100
when(hostDao.listAll()).thenReturn(Arrays.asList(host4, host2, host1, host3));
@@ -205,4 +204,4 @@ public void testGetHostsPerZoneNullHosts() {
205204
when(hostDao.listAll()).thenReturn(null);
206205
Assert.assertTrue(agentMSLB.getOrderedHostIdList(DC_2_ID).size() == 0);
207206
}
208-
}
207+
}

server/src/test/resources/createNetworkOffering.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@
5858
<bean id="DiskOfferingDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDaoImpl" />
5959
<bean id="networkOfferingJoinDaoImpl" class="com.cloud.api.query.dao.NetworkOfferingJoinDaoImpl" />
6060
<bean id="networkOfferingDetailsDaoImpl" class="com.cloud.offerings.dao.NetworkOfferingDetailsDaoImpl" />
61+
<bean id="indirectAgentLBImpl" class="org.apache.cloudstack.agent.lb.IndirectAgentLBServiceImpl" />
6162
</beans>

0 commit comments

Comments
 (0)