Skip to content

Commit 0d6dd8d

Browse files
committed
KVM: Propagating changes on host parameters to the agents
1 parent 35b9145 commit 0d6dd8d

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4747
import org.apache.cloudstack.framework.jobs.AsyncJob;
4848
import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext;
49+
import org.apache.cloudstack.framework.messagebus.MessageBus;
50+
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
4951
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
5052
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5153
import org.apache.cloudstack.utils.identity.ManagementServerNode;
@@ -83,6 +85,7 @@
8385
import com.cloud.dc.dao.ClusterDao;
8486
import com.cloud.dc.dao.DataCenterDao;
8587
import com.cloud.dc.dao.HostPodDao;
88+
import com.cloud.event.EventTypes;
8689
import com.cloud.exception.AgentUnavailableException;
8790
import com.cloud.exception.ConnectionException;
8891
import com.cloud.exception.OperationTimedoutException;
@@ -189,6 +192,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
189192

190193
@Inject
191194
ManagementServiceConfiguration mgmtServiceConf;
195+
@Inject
196+
MessageBus messageBus;
192197

193198
protected final ConfigKey<Integer> Workers = new ConfigKey<Integer>("Advanced", Integer.class, "workers", "5",
194199
"Number of worker threads handling remote agent connections.", false);
@@ -244,6 +249,8 @@ public boolean configure(final String name, final Map<String, Object> params) th
244249

245250
_monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor"));
246251

252+
initMessageBusListener();
253+
247254
return true;
248255
}
249256

@@ -1803,4 +1810,57 @@ public int getTimeout() {
18031810

18041811
}
18051812

1813+
protected Map<Long, List<Long>> getHostsPerZone() {
1814+
List<HostVO> allHosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
1815+
if (allHosts == null) {
1816+
return null;
1817+
}
1818+
Map<Long, List<Long>> hostsByZone = new HashMap<Long, List<Long>>();
1819+
for (HostVO host : allHosts) {
1820+
if (host.getHypervisorType() == HypervisorType.KVM || host.getHypervisorType() == HypervisorType.LXC) {
1821+
Long zoneId = host.getDataCenterId();
1822+
List<Long> hostIds = hostsByZone.get(zoneId);
1823+
if (hostIds == null) {
1824+
hostIds = new ArrayList<Long>();
1825+
}
1826+
hostIds.add(host.getId());
1827+
hostsByZone.put(zoneId, hostIds);
1828+
}
1829+
}
1830+
return hostsByZone;
1831+
}
1832+
1833+
private void sendCommandToAgents(Map<Long, List<Long>> hostsPerZone, Map<String, String> params) {
1834+
SetHostParamsCommand cmds = new SetHostParamsCommand(params);
1835+
for (Long zoneId : hostsPerZone.keySet()) {
1836+
List<Long> hostIds = hostsPerZone.get(zoneId);
1837+
for (Long hostId : hostIds) {
1838+
Answer answer = easySend(hostId, cmds);
1839+
if (answer == null || !answer.getResult()) {
1840+
s_logger.error("Error sending parameters to agent " + hostId);
1841+
}
1842+
}
1843+
}
1844+
}
1845+
1846+
private void propagateChangeToAgents() {
1847+
s_logger.debug("Propagating changes on host parameters to the agents");
1848+
Map<Long, List<Long>> hostsPerZone = getHostsPerZone();
1849+
Map<String, String> params = new HashMap<String, String>();
1850+
params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
1851+
sendCommandToAgents(hostsPerZone, params);
1852+
}
1853+
1854+
private void initMessageBusListener() {
1855+
messageBus.subscribe(EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, new MessageSubscriber() {
1856+
@Override
1857+
public void onPublishMessage(String serderAddress, String subject, Object args) {
1858+
String globalSettingUpdated = (String)args;
1859+
if (globalSettingUpdated.equals("router.aggregation.command.each.timeout")) {
1860+
propagateChangeToAgents();
1861+
}
1862+
}
1863+
});
1864+
}
1865+
18061866
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import com.cloud.agent.api.to.NfsTO;
103103
import com.cloud.agent.api.to.NicTO;
104104
import com.cloud.agent.api.to.VirtualMachineTO;
105+
import com.cloud.agent.dao.impl.PropertiesStorage;
105106
import com.cloud.agent.resource.virtualnetwork.VRScripts;
106107
import com.cloud.agent.resource.virtualnetwork.VirtualRouterDeployer;
107108
import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
@@ -1066,6 +1067,24 @@ public boolean configure(final String name, final Map<String, Object> params) th
10661067
return true;
10671068
}
10681069

1070+
public boolean configureHostParams(final Map<String, String> params) {
1071+
final File file = PropertiesUtil.findConfigFile("agent.properties");
1072+
if (file == null) {
1073+
s_logger.error("Unable to find the file agent.properties");
1074+
return false;
1075+
}
1076+
// Save configurations in agent.properties
1077+
PropertiesStorage storage = new PropertiesStorage();
1078+
storage.configure("Storage", new HashMap<String, Object>());
1079+
if (params.get("router.aggregation.command.each.timeout") == null) {
1080+
String value = (String)params.get("router.aggregation.command.each.timeout");
1081+
Integer intValue = NumbersUtil.parseInt(value, 10);
1082+
storage.persist("router.aggregation.command.each.timeout", String.valueOf(intValue));
1083+
}
1084+
1085+
return true;
1086+
}
1087+
10691088
protected void configureDiskActivityChecks(final Map<String, Object> params) {
10701089
_diskActivityCheckEnabled = Boolean.parseBoolean((String)params.get("vm.diskactivity.checkenabled"));
10711090
if (_diskActivityCheckEnabled) {

plugins/hypervisors/kvm/src/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");

0 commit comments

Comments
 (0)