Skip to content

Commit 65f4d53

Browse files
committed
KVM: Propagating changes on host parameters to the agents
1 parent 0cb2db6 commit 65f4d53

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4646
import org.apache.cloudstack.framework.jobs.AsyncJob;
4747
import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext;
48+
import org.apache.cloudstack.framework.messagebus.MessageBus;
49+
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
4850
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
4951
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5052
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;
@@ -187,6 +190,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
187190
ResourceManager _resourceMgr;
188191
@Inject
189192
ManagementServiceConfiguration mgmtServiceConf;
193+
@Inject
194+
MessageBus messageBus;
190195

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

238243
_monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor"));
239244

245+
initMessageBusListener();
246+
240247
return true;
241248
}
242249

@@ -1790,4 +1797,57 @@ public int getTimeout() {
17901797

17911798
}
17921799

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

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;
@@ -1097,6 +1098,24 @@ public boolean configure(final String name, final Map<String, Object> params) th
10971098
return true;
10981099
}
10991100

1101+
public boolean configureHostParams(final Map<String, String> params) {
1102+
final File file = PropertiesUtil.findConfigFile("agent.properties");
1103+
if (file == null) {
1104+
s_logger.error("Unable to find the file agent.properties");
1105+
return false;
1106+
}
1107+
// Save configurations in agent.properties
1108+
PropertiesStorage storage = new PropertiesStorage();
1109+
storage.configure("Storage", new HashMap<String, Object>());
1110+
if (params.get("router.aggregation.command.each.timeout") == null) {
1111+
String value = (String)params.get("router.aggregation.command.each.timeout");
1112+
Integer intValue = NumbersUtil.parseInt(value, 10);
1113+
storage.persist("router.aggregation.command.each.timeout", String.valueOf(intValue));
1114+
}
1115+
1116+
return true;
1117+
}
1118+
11001119
protected void configureDiskActivityChecks(final Map<String, Object> params) {
11011120
_diskActivityCheckEnabled = Boolean.parseBoolean((String)params.get("vm.diskactivity.checkenabled"));
11021121
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");

0 commit comments

Comments
 (0)