mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
KVM: Propagating changes on host parameters to the agents (#3491)
This commit is contained in:
parent
37d2b8537c
commit
ac7bcde45b
@ -152,4 +152,6 @@ public interface AgentManager {
|
|||||||
void notifyMonitorsOfHostAboutToBeRemoved(long hostId);
|
void notifyMonitorsOfHostAboutToBeRemoved(long hostId);
|
||||||
|
|
||||||
void notifyMonitorsOfRemovedHost(long hostId, long clusterId);
|
void notifyMonitorsOfRemovedHost(long hostId, long clusterId);
|
||||||
|
|
||||||
|
void propagateChangeToAgents();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,4 +50,7 @@ public interface IndirectAgentLB {
|
|||||||
* @return returns interval in seconds
|
* @return returns interval in seconds
|
||||||
*/
|
*/
|
||||||
Long getLBPreferredHostCheckInterval(Long clusterId);
|
Long getLBPreferredHostCheckInterval(Long clusterId);
|
||||||
|
|
||||||
|
void propagateMSListToAgents();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -106,6 +106,7 @@ import com.cloud.agent.api.to.IpAddressTO;
|
|||||||
import com.cloud.agent.api.to.NfsTO;
|
import com.cloud.agent.api.to.NfsTO;
|
||||||
import com.cloud.agent.api.to.NicTO;
|
import com.cloud.agent.api.to.NicTO;
|
||||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
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.VRScripts;
|
||||||
import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
|
import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
|
||||||
import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
|
import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
|
||||||
@ -1094,6 +1095,24 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
|||||||
return true;
|
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) {
|
protected void configureDiskActivityChecks(final Map<String, Object> params) {
|
||||||
_diskActivityCheckEnabled = Boolean.parseBoolean((String)params.get("vm.diskactivity.checkenabled"));
|
_diskActivityCheckEnabled = Boolean.parseBoolean((String)params.get("vm.diskactivity.checkenabled"));
|
||||||
if (_diskActivityCheckEnabled) {
|
if (_diskActivityCheckEnabled) {
|
||||||
|
|||||||
@ -35,6 +35,7 @@ public final class LibvirtSetHostParamsCommandWrapper extends CommandWrapper<Set
|
|||||||
|
|
||||||
final Map<String, String> params = command.getParams();
|
final Map<String, String> params = command.getParams();
|
||||||
boolean success = libvirtComputingResource.getVirtRouterResource().configureHostParams(params);
|
boolean success = libvirtComputingResource.getVirtRouterResource().configureHostParams(params);
|
||||||
|
success = success && libvirtComputingResource.configureHostParams(params);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return new Answer(command, false, "Failed to set host parameters");
|
return new Answer(command, false, "Failed to set host parameters");
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
package com.cloud.configuration;
|
package com.cloud.configuration;
|
||||||
|
|
||||||
|
import com.cloud.agent.AgentManager;
|
||||||
import com.cloud.alert.AlertManager;
|
import com.cloud.alert.AlertManager;
|
||||||
import com.cloud.api.ApiDBUtils;
|
import com.cloud.api.ApiDBUtils;
|
||||||
import com.cloud.api.query.dao.NetworkOfferingJoinDao;
|
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.AffinityGroup;
|
||||||
import org.apache.cloudstack.affinity.AffinityGroupService;
|
import org.apache.cloudstack.affinity.AffinityGroupService;
|
||||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
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.ApiConstants;
|
||||||
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
|
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
|
||||||
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
|
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.DeleteZoneCmd;
|
||||||
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
|
import org.apache.cloudstack.api.command.admin.zone.UpdateZoneCmd;
|
||||||
import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
|
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.config.Configuration;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
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.dao.ConfigurationDao;
|
||||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||||
import org.apache.cloudstack.framework.messagebus.MessageBus;
|
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.framework.messagebus.PublishScope;
|
||||||
import org.apache.cloudstack.region.PortableIp;
|
import org.apache.cloudstack.region.PortableIp;
|
||||||
import org.apache.cloudstack.region.PortableIpDao;
|
import org.apache.cloudstack.region.PortableIpDao;
|
||||||
@ -372,6 +377,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||||||
ImageStoreDetailsDao _imageStoreDetailsDao;
|
ImageStoreDetailsDao _imageStoreDetailsDao;
|
||||||
@Inject
|
@Inject
|
||||||
MessageBus messageBus;
|
MessageBus messageBus;
|
||||||
|
@Inject
|
||||||
|
AgentManager _agentManager;
|
||||||
|
@Inject
|
||||||
|
IndirectAgentLB _indirectAgentLB;
|
||||||
|
|
||||||
|
|
||||||
// FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
|
// FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao?
|
||||||
@ -404,6 +413,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||||||
populateConfigValuesForValidationSet();
|
populateConfigValuesForValidationSet();
|
||||||
weightBasedParametersForValidation();
|
weightBasedParametersForValidation();
|
||||||
overProvisioningFactorsForValidation();
|
overProvisioningFactorsForValidation();
|
||||||
|
initMessageBusListener();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,6 +471,24 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||||||
overprovisioningFactorsForValidation.add(CapacityManager.StorageOverprovisioningFactor.key());
|
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
|
@Override
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
|
|
||||||
|
|||||||
@ -34,13 +34,10 @@ import org.apache.cloudstack.agent.lb.algorithm.IndirectAgentLBStaticAlgorithm;
|
|||||||
import org.apache.cloudstack.config.ApiServiceConfiguration;
|
import org.apache.cloudstack.config.ApiServiceConfiguration;
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.cloudstack.framework.config.Configurable;
|
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 org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.agent.AgentManager;
|
import com.cloud.agent.AgentManager;
|
||||||
import com.cloud.agent.api.Answer;
|
import com.cloud.agent.api.Answer;
|
||||||
import com.cloud.event.EventTypes;
|
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
import com.cloud.host.dao.HostDao;
|
import com.cloud.host.dao.HostDao;
|
||||||
@ -68,8 +65,6 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
|
|||||||
@Inject
|
@Inject
|
||||||
private HostDao hostDao;
|
private HostDao hostDao;
|
||||||
@Inject
|
@Inject
|
||||||
private MessageBus messageBus;
|
|
||||||
@Inject
|
|
||||||
private AgentManager agentManager;
|
private AgentManager agentManager;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
@ -208,7 +203,8 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
|
|||||||
/////////////// Agent MSLB Configuration ///////////////////
|
/////////////// Agent MSLB Configuration ///////////////////
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void propagateMSListToAgents() {
|
@Override
|
||||||
|
public void propagateMSListToAgents() {
|
||||||
LOG.debug("Propagating management server list update to agents");
|
LOG.debug("Propagating management server list update to agents");
|
||||||
final String lbAlgorithm = getLBAlgorithmName();
|
final String lbAlgorithm = getLBAlgorithmName();
|
||||||
final Map<Long, List<Long>> dcOrderedHostsMap = new HashMap<>();
|
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() {
|
private void configureAlgorithmMap() {
|
||||||
final List<org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm> algorithms = new ArrayList<>();
|
final List<org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm> algorithms = new ArrayList<>();
|
||||||
algorithms.add(new IndirectAgentLBStaticAlgorithm());
|
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 {
|
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||||
super.configure(name, params);
|
super.configure(name, params);
|
||||||
configureAlgorithmMap();
|
configureAlgorithmMap();
|
||||||
configureMessageBusListener();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -95,7 +95,6 @@ public class IndirectAgentLBServiceImplTest {
|
|||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
addField(agentMSLB, "hostDao", hostDao);
|
addField(agentMSLB, "hostDao", hostDao);
|
||||||
addField(agentMSLB, "messageBus", messageBus);
|
|
||||||
addField(agentMSLB, "agentManager", agentManager);
|
addField(agentMSLB, "agentManager", agentManager);
|
||||||
|
|
||||||
when(hostDao.listAll()).thenReturn(Arrays.asList(host4, host2, host1, host3));
|
when(hostDao.listAll()).thenReturn(Arrays.asList(host4, host2, host1, host3));
|
||||||
|
|||||||
@ -58,4 +58,5 @@
|
|||||||
<bean id="DiskOfferingDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDaoImpl" />
|
<bean id="DiskOfferingDetailsDaoImpl" class="org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDaoImpl" />
|
||||||
<bean id="networkOfferingJoinDaoImpl" class="com.cloud.api.query.dao.NetworkOfferingJoinDaoImpl" />
|
<bean id="networkOfferingJoinDaoImpl" class="com.cloud.api.query.dao.NetworkOfferingJoinDaoImpl" />
|
||||||
<bean id="networkOfferingDetailsDaoImpl" class="com.cloud.offerings.dao.NetworkOfferingDetailsDaoImpl" />
|
<bean id="networkOfferingDetailsDaoImpl" class="com.cloud.offerings.dao.NetworkOfferingDetailsDaoImpl" />
|
||||||
|
<bean id="indirectAgentLBImpl" class="org.apache.cloudstack.agent.lb.IndirectAgentLBServiceImpl" />
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user