CLOUDSTACK-10108: ConfigKey based approach for reading 'ping' configuaration (#2292)

In CLOUDSTACK-9886, we are reading ping.interval and ping.timeout using configdao which involves direct reading of DB. So, replaced it with ConfigKey based approach.
This commit is contained in:
mrunalinikankariya 2018-01-05 11:23:42 +05:30 committed by Rohit Yadav
parent 8eca04e1f6
commit ebb7a5279d
9 changed files with 106 additions and 44 deletions

View File

@ -59,6 +59,7 @@
</bean> </bean>
<bean id="clusteredAgentManagerImpl" class="com.cloud.agent.manager.ClusteredAgentManagerImpl" /> <bean id="clusteredAgentManagerImpl" class="com.cloud.agent.manager.ClusteredAgentManagerImpl" />
<bean id="managementServiceConfigurationImpl" class="com.cloud.configuration.ManagementServiceConfigurationImpl" />
<bean id="cloudOrchestrator" <bean id="cloudOrchestrator"
class="org.apache.cloudstack.engine.orchestration.CloudOrchestrator" /> class="org.apache.cloudstack.engine.orchestration.CloudOrchestrator" />

View File

@ -38,6 +38,7 @@ import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.cloudstack.ca.CAManager; import org.apache.cloudstack.ca.CAManager;
import com.cloud.configuration.ManagementServiceConfiguration;
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.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@ -180,13 +181,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Inject @Inject
ResourceManager _resourceMgr; ResourceManager _resourceMgr;
@Inject
ManagementServiceConfiguration mgmtServiceConf;
protected final ConfigKey<Integer> Workers = new ConfigKey<Integer>("Advanced", Integer.class, "workers", "5", protected final ConfigKey<Integer> Workers = new ConfigKey<Integer>("Advanced", Integer.class, "workers", "5",
"Number of worker threads handling remote agent connections.", false); "Number of worker threads handling remote agent connections.", false);
protected final ConfigKey<Integer> Port = new ConfigKey<Integer>("Advanced", Integer.class, "port", "8250", "Port to listen on for remote agent connections.", false); protected final ConfigKey<Integer> Port = new ConfigKey<Integer>("Advanced", Integer.class, "port", "8250", "Port to listen on for remote agent connections.", false);
protected final ConfigKey<Integer> PingInterval = new ConfigKey<Integer>("Advanced", Integer.class, "ping.interval", "60",
"Interval to send application level pings to make sure the connection is still working", false);
protected final ConfigKey<Float> PingTimeout = new ConfigKey<Float>("Advanced", Float.class, "ping.timeout", "2.5",
"Multiplier to ping.interval before announcing an agent has timed out", true);
protected final ConfigKey<Integer> AlertWait = new ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800", protected final ConfigKey<Integer> AlertWait = new ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800",
"Seconds to wait before alerting on a disconnected agent", true); "Seconds to wait before alerting on a disconnected agent", true);
protected final ConfigKey<Integer> DirectAgentLoadSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16", protected final ConfigKey<Integer> DirectAgentLoadSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16",
@ -206,14 +206,14 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Override @Override
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 {
s_logger.info("Ping Timeout is " + PingTimeout.value()); s_logger.info("Ping Timeout is " + mgmtServiceConf.getPingTimeout());
final int threads = DirectAgentLoadSize.value(); final int threads = DirectAgentLoadSize.value();
_nodeId = ManagementServerNode.getManagementServerId(); _nodeId = ManagementServerNode.getManagementServerId();
s_logger.info("Configuring AgentManagerImpl. management server node id(msid): " + _nodeId); s_logger.info("Configuring AgentManagerImpl. management server node id(msid): " + _nodeId);
final long lastPing = (System.currentTimeMillis() >> 10) - getTimeout(); final long lastPing = (System.currentTimeMillis() >> 10) - mgmtServiceConf.getTimeout();
_hostDao.markHostsAsDisconnected(_nodeId, lastPing); _hostDao.markHostsAsDisconnected(_nodeId, lastPing);
registerForHostEvents(new BehindOnPingListener(), true, true, false); registerForHostEvents(new BehindOnPingListener(), true, true, false);
@ -241,13 +241,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
return true; return true;
} }
protected int getPingInterval() {
return PingInterval.value();
}
protected long getTimeout() {
return (long) (Math.ceil(PingTimeout.value() * PingInterval.value()));
}
@Override @Override
public Task create(final Task.Type type, final Link link, final byte[] data) { public Task create(final Task.Type type, final Link link, final byte[] data) {
@ -623,7 +616,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} }
} }
_monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), getPingInterval(), getPingInterval(), TimeUnit.SECONDS); _monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), mgmtServiceConf.getPingInterval(), mgmtServiceConf.getPingInterval(), TimeUnit.SECONDS);
return true; return true;
} }
@ -1192,7 +1185,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
cmd = cmds[i]; cmd = cmds[i];
if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand || if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand ||
cmd instanceof StartupStorageCommand) { cmd instanceof StartupStorageCommand) {
answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, getPingInterval()); answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, mgmtServiceConf.getPingInterval());
break; break;
} }
} }
@ -1252,16 +1245,16 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
try { try {
if (cmd instanceof StartupRoutingCommand) { if (cmd instanceof StartupRoutingCommand) {
final StartupRoutingCommand startup = (StartupRoutingCommand) cmd; final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
answer = new StartupAnswer(startup, attache.getId(), getPingInterval()); answer = new StartupAnswer(startup, attache.getId(), mgmtServiceConf.getPingInterval());
} else if (cmd instanceof StartupProxyCommand) { } else if (cmd instanceof StartupProxyCommand) {
final StartupProxyCommand startup = (StartupProxyCommand) cmd; final StartupProxyCommand startup = (StartupProxyCommand) cmd;
answer = new StartupAnswer(startup, attache.getId(), getPingInterval()); answer = new StartupAnswer(startup, attache.getId(), mgmtServiceConf.getPingInterval());
} else if (cmd instanceof StartupSecondaryStorageCommand) { } else if (cmd instanceof StartupSecondaryStorageCommand) {
final StartupSecondaryStorageCommand startup = (StartupSecondaryStorageCommand) cmd; final StartupSecondaryStorageCommand startup = (StartupSecondaryStorageCommand) cmd;
answer = new StartupAnswer(startup, attache.getId(), getPingInterval()); answer = new StartupAnswer(startup, attache.getId(), mgmtServiceConf.getPingInterval());
} else if (cmd instanceof StartupStorageCommand) { } else if (cmd instanceof StartupStorageCommand) {
final StartupStorageCommand startup = (StartupStorageCommand) cmd; final StartupStorageCommand startup = (StartupStorageCommand) cmd;
answer = new StartupAnswer(startup, attache.getId(), getPingInterval()); answer = new StartupAnswer(startup, attache.getId(), mgmtServiceConf.getPingInterval());
} else if (cmd instanceof ShutdownCommand) { } else if (cmd instanceof ShutdownCommand) {
final ShutdownCommand shutdown = (ShutdownCommand) cmd; final ShutdownCommand shutdown = (ShutdownCommand) cmd;
final String reason = shutdown.getReason(); final String reason = shutdown.getReason();
@ -1515,7 +1508,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
attache = createAttacheForDirectConnect(host, resource); attache = createAttacheForDirectConnect(host, resource);
final StartupAnswer[] answers = new StartupAnswer[cmds.length]; final StartupAnswer[] answers = new StartupAnswer[cmds.length];
for (int i = 0; i < answers.length; i++) { for (int i = 0; i < answers.length; i++) {
answers[i] = new StartupAnswer(cmds[i], attache.getId(), getPingInterval()); answers[i] = new StartupAnswer(cmds[i], attache.getId(), mgmtServiceConf.getPingInterval());
} }
attache.process(answers); attache.process(answers);
@ -1625,7 +1618,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
protected List<Long> findAgentsBehindOnPing() { protected List<Long> findAgentsBehindOnPing() {
final List<Long> agentsBehind = new ArrayList<Long>(); final List<Long> agentsBehind = new ArrayList<Long>();
final long cutoffTime = InaccurateClock.getTimeInSeconds() - getTimeout(); final long cutoffTime = InaccurateClock.getTimeInSeconds() - mgmtServiceConf.getTimeout();
for (final Map.Entry<Long, Long> entry : _pingMap.entrySet()) { for (final Map.Entry<Long, Long> entry : _pingMap.entrySet()) {
if (entry.getValue() < cutoffTime) { if (entry.getValue() < cutoffTime) {
agentsBehind.add(entry.getKey()); agentsBehind.add(entry.getKey());
@ -1714,7 +1707,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
@Override @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, PingInterval, PingTimeout, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize, return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize,
DirectAgentThreadCap }; DirectAgentThreadCap };
} }

View File

@ -198,7 +198,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
} }
// for agents that are self-managed, threshold to be considered as disconnected after pingtimeout // for agents that are self-managed, threshold to be considered as disconnected after pingtimeout
final long cutSeconds = (System.currentTimeMillis() >> 10) - getTimeout(); final long cutSeconds = (System.currentTimeMillis() >> 10) - mgmtServiceConf.getTimeout();
final List<HostVO> hosts = _hostDao.findAndUpdateDirectAgentToLoad(cutSeconds, LoadSize.value().longValue(), _nodeId); final List<HostVO> hosts = _hostDao.findAndUpdateDirectAgentToLoad(cutSeconds, LoadSize.value().longValue(), _nodeId);
final List<HostVO> appliances = _hostDao.findAndUpdateApplianceToLoad(cutSeconds, _nodeId); final List<HostVO> appliances = _hostDao.findAndUpdateApplianceToLoad(cutSeconds, _nodeId);
@ -747,7 +747,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
public void onManagementNodeLeft(final List<? extends ManagementServerHost> nodeList, final long selfNodeId) { public void onManagementNodeLeft(final List<? extends ManagementServerHost> nodeList, final long selfNodeId) {
for (final ManagementServerHost vo : nodeList) { for (final ManagementServerHost vo : nodeList) {
s_logger.info("Marking hosts as disconnected on Management server" + vo.getMsid()); s_logger.info("Marking hosts as disconnected on Management server" + vo.getMsid());
final long lastPing = (System.currentTimeMillis() >> 10) - getTimeout(); final long lastPing = (System.currentTimeMillis() >> 10) - mgmtServiceConf.getTimeout();
_hostDao.markHostsAsDisconnected(vo.getMsid(), lastPing); _hostDao.markHostsAsDisconnected(vo.getMsid(), lastPing);
outOfBandManagementDao.expireServerOwnership(vo.getMsid()); outOfBandManagementDao.expireServerOwnership(vo.getMsid());
haConfigDao.expireServerOwnership(vo.getMsid()); haConfigDao.expireServerOwnership(vo.getMsid());

View File

@ -24,7 +24,7 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.framework.config.ConfigKey; import com.cloud.configuration.ManagementServiceConfiguration;
import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.PublishScope; import org.apache.cloudstack.framework.messagebus.PublishScope;
@ -39,9 +39,7 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat
@Inject MessageBus _messageBus; @Inject MessageBus _messageBus;
@Inject VMInstanceDao _instanceDao; @Inject VMInstanceDao _instanceDao;
@Inject VirtualMachineManager _vmMgr; @Inject VirtualMachineManager _vmMgr;
@Inject ManagementServiceConfiguration mgmtServiceConf;
protected final ConfigKey<Integer> PingInterval = new ConfigKey<Integer>(Integer.class, "ping.interval", "Advanced", "60",
"Interval to send application level pings to make sure the connection is still working", false);
public VirtualMachinePowerStateSyncImpl() { public VirtualMachinePowerStateSyncImpl() {
} }
@ -107,7 +105,7 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat
s_logger.debug("Run missing VM report. current time: " + currentTime.getTime()); s_logger.debug("Run missing VM report. current time: " + currentTime.getTime());
// 2 times of sync-update interval for graceful period // 2 times of sync-update interval for graceful period
long milliSecondsGracefullPeriod = PingInterval.value() * 2000L; long milliSecondsGracefullPeriod = mgmtServiceConf.getPingInterval() * 2000L;
for (VMInstanceVO instance : vmsThatAreMissingReport) { for (VMInstanceVO instance : vmsThatAreMissingReport) {

View File

@ -0,0 +1,30 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.configuration;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
public interface ManagementServiceConfiguration extends Configurable {
ConfigKey<Integer> PingInterval = new ConfigKey<Integer>("Advanced", Integer.class, "ping.interval", "60",
"Interval to send application level pings to make sure the connection is still working", false);
ConfigKey<Float> PingTimeout = new ConfigKey<Float>("Advanced", Float.class, "ping.timeout", "2.5",
"Multiplier to ping.interval before announcing an agent has timed out", true);
public int getPingInterval();
public float getPingTimeout();
public long getTimeout();
}

View File

@ -0,0 +1,46 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.configuration;
import org.apache.cloudstack.framework.config.ConfigKey;
public class ManagementServiceConfigurationImpl implements ManagementServiceConfiguration {
@Override
public String getConfigComponentName() {
return ManagementServiceConfiguration.class.getSimpleName();
}
@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {PingInterval, PingTimeout};
}
@Override
public int getPingInterval() {
return ManagementServiceConfiguration.PingInterval.value();
}
@Override
public float getPingTimeout() {
return ManagementServiceConfiguration.PingTimeout.value();
}
@Override
public long getTimeout() {
return (long) (PingTimeout.value() * PingInterval.value());
}
}

View File

@ -30,8 +30,7 @@ import javax.annotation.PostConstruct;
import javax.inject.Inject; import javax.inject.Inject;
import javax.persistence.TableGenerator; import javax.persistence.TableGenerator;
import com.cloud.utils.NumbersUtil; import com.cloud.configuration.ManagementServiceConfiguration;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -79,6 +78,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join host_tags on host.id = host_tags.host_id and host_tags.tag = ?"; private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join host_tags on host.id = host_tags.host_id and host_tags.tag = ?";
protected SearchBuilder<HostVO> TypePodDcStatusSearch; protected SearchBuilder<HostVO> TypePodDcStatusSearch;
protected SearchBuilder<HostVO> IdStatusSearch; protected SearchBuilder<HostVO> IdStatusSearch;
@ -145,7 +145,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
@Inject @Inject
protected ClusterDao _clusterDao; protected ClusterDao _clusterDao;
@Inject @Inject
private ConfigurationDao _configDao; ManagementServiceConfiguration mgmtServiceConf;
public HostDaoImpl() { public HostDaoImpl() {
super(); super();
@ -993,9 +993,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
} }
} }
if (event.equals(Event.ManagementServerDown)) { if (event.equals(Event.ManagementServerDown)) {
Float pingTimeout = NumbersUtil.parseFloat(_configDao.getValue("ping.timeout"), 2.5f); ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - mgmtServiceConf.getTimeout()));
Integer pingInterval = NumbersUtil.parseInt(_configDao.getValue("ping.interval"), 60);
ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (long)(pingTimeout * pingInterval)));
} }
int result = update(ub, sc, null); int result = update(ub, sc, null);
assert result <= 1 : "How can this update " + result + " rows? "; assert result <= 1 : "How can this update " + result + " rows? ";

View File

@ -41,7 +41,7 @@
<bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl"> <bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
<property name="name" value="ConfigurationManager"/> <property name="name" value="ConfigurationManager"/>
</bean> </bean>
<bean id="managementServiceConfigurationImpl" class="com.cloud.configuration.ManagementServiceConfigurationImpl" />
<bean class="org.apache.cloudstack.networkoffering.ChildTestConfiguration" /> <bean class="org.apache.cloudstack.networkoffering.ChildTestConfiguration" />
<bean id="UservmDetailsDaoImpl" class="com.cloud.vm.dao.UserVmDetailsDaoImpl" /> <bean id="UservmDetailsDaoImpl" class="com.cloud.vm.dao.UserVmDetailsDaoImpl" />
<bean id="hostGpuGroupsDaoImpl" class="com.cloud.gpu.dao.HostGpuGroupsDaoImpl" /> <bean id="hostGpuGroupsDaoImpl" class="com.cloud.gpu.dao.HostGpuGroupsDaoImpl" />

View File

@ -98,9 +98,6 @@ class TestHostHA(cloudstackTestCase):
return return
def checkHostDown(self, fromHostIp, testHostIp): def checkHostDown(self, fromHostIp, testHostIp):
try: try:
ssh = SshClient(fromHostIp, 22, "root", "password") ssh = SshClient(fromHostIp, 22, "root", "password")
@ -165,9 +162,9 @@ class TestHostHA(cloudstackTestCase):
""" Restart management """ Restart management
server and usage server """ server and usage server """
sshClient = SshClient(self.mgtSvrDetails["mgtSvrIp"], sshClient = SshClient(self.mgtSvrDetails["mgtSvrIp"],
22, 22,
self.mgtSvrDetails["user"], self.mgtSvrDetails["user"],
self.mgtSvrDetails["passwd"] self.mgtSvrDetails["passwd"]
) )
command = "service cloudstack-management restart" command = "service cloudstack-management restart"
sshClient.execute(command) sshClient.execute(command)
@ -197,8 +194,7 @@ class TestHostHA(cloudstackTestCase):
hostToTest = listHost[0] hostToTest = listHost[0]
hostUpInCloudstack = wait_until(10, 10, self.checkHostUp, hostToTest.ipaddress, hostToTest.ipaddress) hostUpInCloudstack = wait_until(40, 10, self.checkHostStateInCloudstack, "Up", hostToTest.id)
#hostUpInCloudstack = wait_until(40, 10, self.checkHostStateInCloudstack, "Up", hostToTest.id)
if not(hostUpInCloudstack): if not(hostUpInCloudstack):
raise self.fail("Host is not up %s, in cloudstack so failing test " % (hostToTest.ipaddress)) raise self.fail("Host is not up %s, in cloudstack so failing test " % (hostToTest.ipaddress))