Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ public enum TapAgentsAction {
void notifyMonitorsOfHostAboutToBeRemoved(long hostId);

void notifyMonitorsOfRemovedHost(long hostId, long clusterId);

void propagateChangeToAgents();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1788,4 +1788,45 @@ public int getTimeout() {

}

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"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about removing this one from here and adding params as parameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nvazquez it is absolutely good.
I will create another PR. this PR has already been merged into 4.13 and 4.14 ...

sendCommandToAgents(hostsPerZone, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ public interface IndirectAgentLB {
* @return returns interval in seconds
*/
Long getLBPreferredHostCheckInterval(Long clusterId);
}

void propagateMSListToAgents();

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
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;
Expand Down Expand Up @@ -1094,6 +1095,24 @@ public boolean configure(final String name, final Map<String, Object> params) th
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public Answer execute(final SetHostParamsCommand command, final LibvirtComputing

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,6 +162,8 @@
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;
Expand All @@ -187,6 +190,7 @@
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;
Expand All @@ -198,6 +202,7 @@
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;
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -404,6 +413,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
populateConfigValuesForValidationSet();
weightBasedParametersForValidation();
overProvisioningFactorsForValidation();
initMessageBusListener();
return true;
}

Expand Down Expand Up @@ -461,6 +471,24 @@ private void overProvisioningFactorsForValidation() {
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can unify both calls as they do basically the same

} else if (globalSettingUpdated.equals(Config.RouterAggregationCommandEachTimeout.toString())) {
_agentManager.propagateChangeToAgents();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^

}
}
});
}

@Override
public boolean start() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
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;
Expand Down Expand Up @@ -68,8 +65,6 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
@Inject
private HostDao hostDao;
@Inject
private MessageBus messageBus;
@Inject
private AgentManager agentManager;

//////////////////////////////////////////////////////
Expand Down Expand Up @@ -208,7 +203,8 @@ private org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm getAgentMSLBAlgo
/////////////// 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<>();
Expand All @@ -227,22 +223,6 @@ private void propagateMSListToAgents() {
}
}

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());
Expand All @@ -258,7 +238,6 @@ private void configureAlgorithmMap() {
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);
configureAlgorithmMap();
configureMessageBusListener();
return true;
}

Expand All @@ -274,4 +253,4 @@ public ConfigKey<?>[] getConfigKeys() {
IndirectAgentLBCheckInterval
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ private void configureMocks() throws NoSuchFieldException, IllegalAccessExceptio
id++;
}
addField(agentMSLB, "hostDao", hostDao);
addField(agentMSLB, "messageBus", messageBus);
addField(agentMSLB, "agentManager", agentManager);

when(hostDao.listAll()).thenReturn(Arrays.asList(host4, host2, host1, host3));
Expand Down Expand Up @@ -205,4 +204,4 @@ public void testGetHostsPerZoneNullHosts() {
when(hostDao.listAll()).thenReturn(null);
Assert.assertTrue(agentMSLB.getOrderedHostIdList(DC_2_ID).size() == 0);
}
}
}
1 change: 1 addition & 0 deletions server/src/test/resources/createNetworkOffering.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>