KVM: Propagating changes on host parameters to the agents (#3491)

This commit is contained in:
Wei Zhou 2020-02-19 14:13:37 +01:00 committed by GitHub
parent 37d2b8537c
commit ac7bcde45b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 100 additions and 27 deletions

View File

@ -152,4 +152,6 @@ public interface AgentManager {
void notifyMonitorsOfHostAboutToBeRemoved(long hostId);
void notifyMonitorsOfRemovedHost(long hostId, long clusterId);
void propagateChangeToAgents();
}

View File

@ -1788,4 +1788,45 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
}
protected Map<Long, List<Long>> getHostsPerZone() {
List<HostVO> allHosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
if (allHosts == null) {
return null;
}
Map<Long, List<Long>> hostsByZone = new HashMap<Long, List<Long>>();
for (HostVO host : allHosts) {
if (host.getHypervisorType() == HypervisorType.KVM || host.getHypervisorType() == HypervisorType.LXC) {
Long zoneId = host.getDataCenterId();
List<Long> hostIds = hostsByZone.get(zoneId);
if (hostIds == null) {
hostIds = new ArrayList<Long>();
}
hostIds.add(host.getId());
hostsByZone.put(zoneId, hostIds);
}
}
return hostsByZone;
}
private void sendCommandToAgents(Map<Long, List<Long>> hostsPerZone, Map<String, String> params) {
SetHostParamsCommand cmds = new SetHostParamsCommand(params);
for (Long zoneId : hostsPerZone.keySet()) {
List<Long> hostIds = hostsPerZone.get(zoneId);
for (Long hostId : hostIds) {
Answer answer = easySend(hostId, cmds);
if (answer == null || !answer.getResult()) {
s_logger.error("Error sending parameters to agent " + hostId);
}
}
}
}
@Override
public void propagateChangeToAgents() {
s_logger.debug("Propagating changes on host parameters to the agents");
Map<Long, List<Long>> hostsPerZone = getHostsPerZone();
Map<String, String> params = new HashMap<String, String>();
params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
sendCommandToAgents(hostsPerZone, params);
}
}

View File

@ -50,4 +50,7 @@ public interface IndirectAgentLB {
* @return returns interval in seconds
*/
Long getLBPreferredHostCheckInterval(Long clusterId);
void propagateMSListToAgents();
}

View File

@ -106,6 +106,7 @@ import com.cloud.agent.api.to.IpAddressTO;
import com.cloud.agent.api.to.NfsTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.dao.impl.PropertiesStorage;
import com.cloud.agent.resource.virtualnetwork.VRScripts;
import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
@ -1094,6 +1095,24 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return true;
}
public boolean configureHostParams(final Map<String, String> params) {
final File file = PropertiesUtil.findConfigFile("agent.properties");
if (file == null) {
s_logger.error("Unable to find the file agent.properties");
return false;
}
// Save configurations in agent.properties
PropertiesStorage storage = new PropertiesStorage();
storage.configure("Storage", new HashMap<String, Object>());
if (params.get("router.aggregation.command.each.timeout") != null) {
String value = (String)params.get("router.aggregation.command.each.timeout");
Integer intValue = NumbersUtil.parseInt(value, 600);
storage.persist("router.aggregation.command.each.timeout", String.valueOf(intValue));
}
return true;
}
protected void configureDiskActivityChecks(final Map<String, Object> params) {
_diskActivityCheckEnabled = Boolean.parseBoolean((String)params.get("vm.diskactivity.checkenabled"));
if (_diskActivityCheckEnabled) {

View File

@ -35,6 +35,7 @@ public final class LibvirtSetHostParamsCommandWrapper extends CommandWrapper<Set
final Map<String, String> params = command.getParams();
boolean success = libvirtComputingResource.getVirtRouterResource().configureHostParams(params);
success = success && libvirtComputingResource.configureHostParams(params);
if (!success) {
return new Answer(command, false, "Failed to set host parameters");

View File

@ -16,6 +16,7 @@
// under the License.
package com.cloud.configuration;
import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.dao.NetworkOfferingJoinDao;
@ -161,6 +162,8 @@ import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.affinity.AffinityGroup;
import org.apache.cloudstack.affinity.AffinityGroupService;
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
import org.apache.cloudstack.agent.lb.IndirectAgentLB;
import org.apache.cloudstack.agent.lb.IndirectAgentLBServiceImpl;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
@ -187,6 +190,7 @@ import org.apache.cloudstack.api.command.admin.zone.CreateZoneCmd;
import org.apache.cloudstack.api.command.admin.zone.DeleteZoneCmd;
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
import org.apache.cloudstack.config.ApiServiceConfiguration;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@ -198,6 +202,7 @@ import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
import org.apache.cloudstack.framework.messagebus.PublishScope;
import org.apache.cloudstack.region.PortableIp;
import org.apache.cloudstack.region.PortableIpDao;
@ -372,6 +377,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
ImageStoreDetailsDao _imageStoreDetailsDao;
@Inject
MessageBus messageBus;
@Inject
AgentManager _agentManager;
@Inject
IndirectAgentLB _indirectAgentLB;
// FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
@ -404,6 +413,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
populateConfigValuesForValidationSet();
weightBasedParametersForValidation();
overProvisioningFactorsForValidation();
initMessageBusListener();
return true;
}
@ -461,6 +471,24 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
overprovisioningFactorsForValidation.add(CapacityManager.StorageOverprovisioningFactor.key());
}
private void initMessageBusListener() {
messageBus.subscribe(EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, new MessageSubscriber() {
@Override
public void onPublishMessage(String serderAddress, String subject, Object args) {
String globalSettingUpdated = (String) args;
if (Strings.isNullOrEmpty(globalSettingUpdated)) {
return;
}
if (globalSettingUpdated.equals(ApiServiceConfiguration.ManagementServerAddresses.key()) ||
globalSettingUpdated.equals(IndirectAgentLBServiceImpl.IndirectAgentLBAlgorithm.key())) {
_indirectAgentLB.propagateMSListToAgents();
} else if (globalSettingUpdated.equals(Config.RouterAggregationCommandEachTimeout.toString())) {
_agentManager.propagateChangeToAgents();
}
}
});
}
@Override
public boolean start() {

View File

@ -34,13 +34,10 @@ import org.apache.cloudstack.agent.lb.algorithm.IndirectAgentLBStaticAlgorithm;
import org.apache.cloudstack.config.ApiServiceConfiguration;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.event.EventTypes;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
@ -68,8 +65,6 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
@Inject
private HostDao hostDao;
@Inject
private MessageBus messageBus;
@Inject
private AgentManager agentManager;
//////////////////////////////////////////////////////
@ -208,7 +203,8 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
/////////////// Agent MSLB Configuration ///////////////////
////////////////////////////////////////////////////////////
private void propagateMSListToAgents() {
@Override
public void propagateMSListToAgents() {
LOG.debug("Propagating management server list update to agents");
final String lbAlgorithm = getLBAlgorithmName();
final Map<Long, List<Long>> dcOrderedHostsMap = new HashMap<>();
@ -227,22 +223,6 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
}
}
private void configureMessageBusListener() {
messageBus.subscribe(EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, new MessageSubscriber() {
@Override
public void onPublishMessage(final String senderAddress, String subject, Object args) {
final String globalSettingUpdated = (String) args;
if (Strings.isNullOrEmpty(globalSettingUpdated)) {
return;
}
if (globalSettingUpdated.equals(ApiServiceConfiguration.ManagementServerAddresses.key()) ||
globalSettingUpdated.equals(IndirectAgentLBAlgorithm.key())) {
propagateMSListToAgents();
}
}
});
}
private void configureAlgorithmMap() {
final List<org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm> algorithms = new ArrayList<>();
algorithms.add(new IndirectAgentLBStaticAlgorithm());
@ -258,7 +238,6 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
configureAlgorithmMap();
configureMessageBusListener();
return true;
}

View File

@ -95,7 +95,6 @@ public class IndirectAgentLBServiceImplTest {
id++;
}
addField(agentMSLB, "hostDao", hostDao);
addField(agentMSLB, "messageBus", messageBus);
addField(agentMSLB, "agentManager", agentManager);
when(hostDao.listAll()).thenReturn(Arrays.asList(host4, host2, host1, host3));

View File

@ -58,4 +58,5 @@
<bean id="DiskOfferingDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDaoImpl" />
<bean id="networkOfferingJoinDaoImpl" class="com.cloud.api.query.dao.NetworkOfferingJoinDaoImpl" />
<bean id="networkOfferingDetailsDaoImpl" class="com.cloud.offerings.dao.NetworkOfferingDetailsDaoImpl" />
<bean id="indirectAgentLBImpl" class="org.apache.cloudstack.agent.lb.IndirectAgentLBServiceImpl" />
</beans>