Skip to content

Commit 7b719c7

Browse files
committed
Merge pull request #1856 from ustcweizhou/set-kvm-host-params
[4.9] CLOUDSTACK-9569: propagate global configuration router.aggregation.command.each.timeout to KVM agentThe router.aggregation.command.each.timeout in global configuration is only applied on new created KVM host. For existing KVM host, changing the value will not be effective. We need to propagate the configuration to existing host when cloudstack-agent is connected. * pr/1856: CLOUDSTACK-9569: propagate global configuration router.aggregation.command.each.timeout to KVM agent Signed-off-by: Rajani Karuturi <rajani.karuturi@accelerite.com>
2 parents 3e54388 + 7142212 commit 7b719c7

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
import java.util.Map;
23+
24+
public class SetHostParamsCommand extends Command {
25+
26+
Map<String, String> params;
27+
28+
public SetHostParamsCommand(Map<String, String> params) {
29+
this.params = params;
30+
}
31+
32+
public Map<String, String> getParams() {
33+
return params;
34+
}
35+
36+
protected SetHostParamsCommand() {
37+
}
38+
39+
@Override
40+
public boolean executeInSequence() {
41+
return true;
42+
}
43+
}

core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class VirtualRoutingResource {
7575
private int _retry;
7676
private int _port;
7777
private Duration _eachTimeout;
78+
private Map<String, Object> _params;
7879

7980
private String _cfgVersion = "1.0";
8081

@@ -259,8 +260,18 @@ private Answer execute(GetDomRVersionCmd cmd) {
259260
return new GetDomRVersionAnswer(cmd, result.getDetails(), lines[0], lines[1]);
260261
}
261262

263+
public boolean configureHostParams(final Map<String, String> params) {
264+
if (_params.get("router.aggregation.command.each.timeout") == null) {
265+
String value = (String)params.get("router.aggregation.command.each.timeout");
266+
_eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt(value, 10));
267+
}
268+
269+
return true;
270+
}
271+
262272
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
263273
_name = name;
274+
_params = params;
264275

265276
String value = (String)params.get("ssh.sleep");
266277
_sleep = NumbersUtil.parseInt(value, 10) * 1000;

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.cloud.agent.api.PingRoutingCommand;
6262
import com.cloud.agent.api.ReadyAnswer;
6363
import com.cloud.agent.api.ReadyCommand;
64+
import com.cloud.agent.api.SetHostParamsCommand;
6465
import com.cloud.agent.api.ShutdownCommand;
6566
import com.cloud.agent.api.StartupAnswer;
6667
import com.cloud.agent.api.StartupCommand;
@@ -214,6 +215,8 @@ public boolean configure(final String name, final Map<String, Object> params) th
214215

215216
registerForHostEvents(new BehindOnPingListener(), true, true, false);
216217

218+
registerForHostEvents(new SetHostParamsListener(), true, true, false);
219+
217220
_executor = new ThreadPoolExecutor(threads, threads, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentTaskPool"));
218221

219222
_connectExecutor = new ThreadPoolExecutor(100, 500, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentConnectTaskPool"));
@@ -1710,4 +1713,73 @@ public ConfigKey<?>[] getConfigKeys() {
17101713
DirectAgentThreadCap };
17111714
}
17121715

1716+
protected class SetHostParamsListener implements Listener {
1717+
@Override
1718+
public boolean isRecurring() {
1719+
return false;
1720+
}
1721+
1722+
@Override
1723+
public boolean processAnswers(final long agentId, final long seq, final Answer[] answers) {
1724+
return false;
1725+
}
1726+
1727+
@Override
1728+
public boolean processCommands(final long agentId, final long seq, final Command[] commands) {
1729+
return false;
1730+
}
1731+
1732+
@Override
1733+
public AgentControlAnswer processControlCommand(final long agentId, final AgentControlCommand cmd) {
1734+
return null;
1735+
}
1736+
1737+
@Override
1738+
public void processHostAdded(long hostId) {
1739+
}
1740+
1741+
@Override
1742+
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) {
1743+
if (cmd instanceof StartupRoutingCommand) {
1744+
if (((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.LXC) {
1745+
Map<String, String> params = new HashMap<String, String>();
1746+
params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
1747+
1748+
try {
1749+
SetHostParamsCommand cmds = new SetHostParamsCommand(params);
1750+
Commands c = new Commands(cmds);
1751+
send(host.getId(), c, this);
1752+
} catch (AgentUnavailableException e) {
1753+
s_logger.debug("Failed to send host params on host: " + host.getId());
1754+
}
1755+
}
1756+
}
1757+
1758+
}
1759+
1760+
@Override
1761+
public boolean processDisconnect(final long agentId, final Status state) {
1762+
return true;
1763+
}
1764+
1765+
@Override
1766+
public void processHostAboutToBeRemoved(long hostId) {
1767+
}
1768+
1769+
@Override
1770+
public void processHostRemoved(long hostId, long clusterId) {
1771+
}
1772+
1773+
@Override
1774+
public boolean processTimeout(final long agentId, final long seq) {
1775+
return false;
1776+
}
1777+
1778+
@Override
1779+
public int getTimeout() {
1780+
return -1;
1781+
}
1782+
1783+
}
1784+
17131785
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.hypervisor.kvm.resource.wrapper;
21+
22+
import java.util.Map;
23+
24+
import com.cloud.agent.api.Answer;
25+
import com.cloud.agent.api.SetHostParamsCommand;
26+
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
27+
import com.cloud.resource.CommandWrapper;
28+
import com.cloud.resource.ResourceWrapper;
29+
30+
@ResourceWrapper(handles = SetHostParamsCommand.class)
31+
public final class LibvirtSetHostParamsCommandWrapper extends CommandWrapper<SetHostParamsCommand, Answer, LibvirtComputingResource> {
32+
33+
@Override
34+
public Answer execute(final SetHostParamsCommand command, final LibvirtComputingResource libvirtComputingResource) {
35+
36+
final Map<String, String> params = command.getParams();
37+
boolean success = libvirtComputingResource.getVirtRouterResource().configureHostParams(params);
38+
39+
if (!success) {
40+
return new Answer(command, false, "Failed to set host parameters");
41+
} else {
42+
return new Answer(command, true, null);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)