bug 12616: 40 hosts connecting to mgt server, need to set workers > 40 in mgt server.

status 12616: resolved fixed
This commit is contained in:
Edison Su 2012-01-04 21:35:34 -08:00
parent fd758208d9
commit 6ecb0f2b6b
6 changed files with 136 additions and 15 deletions

View File

@ -117,6 +117,8 @@ public class Agent implements HandlerFactory, IAgentControl {
AtomicInteger _inProgress = new AtomicInteger();
StartupTask _startup = null;
long _startupWaitDefault = 180000;
long _startupWait = _startupWaitDefault;
boolean _reconnectAllowed = true;
//For time sentitive task, e.g. PingTask
private ThreadPoolExecutor _ugentTaskPool;
@ -282,7 +284,7 @@ public class Agent implements HandlerFactory, IAgentControl {
s_logger.debug("Adding a watch list");
}
final WatchTask task = new WatchTask(link, request, this);
_timer.schedule(task, delay, period);
_timer.schedule(task, 0, period);
_watchList.add(task);
}
}
@ -315,7 +317,7 @@ public class Agent implements HandlerFactory, IAgentControl {
}
synchronized (this) {
_startup = new StartupTask(link);
_timer.schedule(_startup, 180000);
_timer.schedule(_startup, _startupWait);
}
try {
link.send(request.toBytes());
@ -793,6 +795,7 @@ public class Agent implements HandlerFactory, IAgentControl {
// TimerTask.cancel may fail depends on the calling context
if (!cancelled) {
cancelled = true;
_startupWait = _startupWaitDefault;
s_logger.debug("Startup task cancelled");
return super.cancel();
}
@ -807,6 +810,7 @@ public class Agent implements HandlerFactory, IAgentControl {
}
cancelled = true;
_startup = null;
_startupWait = _startupWaitDefault *2;
reconnect(_link);
}
}

View File

@ -35,6 +35,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.naming.ConfigurationException;
@ -351,7 +352,7 @@ public class AgentShell implements IAgentShell {
if (!developer) {
throw new ConfigurationException("Unable to find the guid");
}
_guid = MacAddress.getMacAddress().toString(":");
_guid = UUID.randomUUID().toString();
}
return true;
@ -529,8 +530,12 @@ public class AgentShell implements IAgentShell {
init(args);
String instance = getProperty(null, "instance");
if (instance == null) {
instance = "";
if (instance == null) {
if (Boolean.parseBoolean(getProperty(null, "developer"))) {
instance = UUID.randomUUID().toString();
} else {
instance = "";
}
} else {
instance += ".";
}

View File

@ -17,7 +17,11 @@
*/
package com.cloud.agent.resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.ejb.Local;
@ -26,9 +30,17 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.StoragePoolInfo;
import com.cloud.agent.api.StartupRoutingCommand.VmState;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Networks.RouterPrivateIpStrategy;
import com.cloud.resource.ServerResource;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.StoragePoolType;
@Local(value={ServerResource.class})
public class DummyResource implements ServerResource {
@ -36,6 +48,7 @@ public class DummyResource implements ServerResource {
Host.Type _type;
boolean _negative;
IAgentControl _agentControl;
private Map<String, Object> _params;
@Override
public void disconnected() {
@ -58,10 +71,98 @@ public class DummyResource implements ServerResource {
public Type getType() {
return _type;
}
protected String getConfiguredProperty(String key, String defaultValue) {
String val = (String)_params.get(key);
return val==null?defaultValue:val;
}
protected Long getConfiguredProperty(String key, Long defaultValue) {
String val = (String)_params.get(key);
if (val != null) {
Long result = Long.parseLong(val);
return result;
}
return defaultValue;
}
protected List<Object> getHostInfo() {
final ArrayList<Object> info = new ArrayList<Object>();
long speed = getConfiguredProperty("cpuspeed", 4000L) ;
long cpus = getConfiguredProperty("cpus", 4L);
long ram = getConfiguredProperty("memory", 16000L*1024L*1024L);
long dom0ram = Math.min(ram/10, 768*1024*1024L);
String cap = getConfiguredProperty("capabilities", "hvm");
info.add((int)cpus);
info.add(speed);
info.add(ram);
info.add(cap);
info.add(dom0ram);
return info;
}
protected void fillNetworkInformation(final StartupCommand cmd) {
cmd.setPrivateIpAddress((String)getConfiguredProperty("private.ip.address", "127.0.0.1"));
cmd.setPrivateMacAddress((String)getConfiguredProperty("private.mac.address", "8A:D2:54:3F:7C:C3"));
cmd.setPrivateNetmask((String)getConfiguredProperty("private.ip.netmask", "255.255.255.0"));
cmd.setStorageIpAddress((String)getConfiguredProperty("private.ip.address", "127.0.0.1"));
cmd.setStorageMacAddress((String)getConfiguredProperty("private.mac.address", "8A:D2:54:3F:7C:C3"));
cmd.setStorageNetmask((String)getConfiguredProperty("private.ip.netmask", "255.255.255.0"));
cmd.setGatewayIpAddress((String)getConfiguredProperty("gateway.ip.address", "127.0.0.1"));
}
private Map<String, String> getVersionStrings() {
Map<String, String> result = new HashMap<String, String>();
String hostOs = (String) _params.get("Host.OS");
String hostOsVer = (String) _params.get("Host.OS.Version");
String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
result.put("Host.OS", hostOs==null?"Fedora":hostOs);
result.put("Host.OS.Version", hostOsVer==null?"14":hostOsVer);
result.put("Host.OS.Kernel.Version", hostOsKernVer==null?"2.6.35.6-45.fc14.x86_64":hostOsKernVer);
return result;
}
protected StoragePoolInfo initializeLocalStorage() {
String hostIp = (String)getConfiguredProperty("private.ip.address", "127.0.0.1");
String localStoragePath = (String)getConfiguredProperty("local.storage.path", "/mnt");
String lh = hostIp + localStoragePath;
String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
String capacity = (String)getConfiguredProperty("local.storage.capacity", "1000000000");
String available = (String)getConfiguredProperty("local.storage.avail", "10000000");
return new StoragePoolInfo(uuid, hostIp, localStoragePath,
localStoragePath, StoragePoolType.Filesystem,
Long.parseLong(capacity), Long.parseLong(available));
}
@Override
public StartupCommand[] initialize() {
return new StartupCommand[] {new StartupCommand(Host.Type.Storage)};
Map<String, VmState> changes = null;
final List<Object> info = getHostInfo();
final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer)info.get(0), (Long)info.get(1), (Long)info.get(2), (Long)info.get(4), (String)info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal, changes);
fillNetworkInformation(cmd);
cmd.getHostDetails().putAll(getVersionStrings());
cmd.setCluster(getConfiguredProperty("cluster", "1"));
StoragePoolInfo pi = initializeLocalStorage();
StartupStorageCommand sscmd = new StartupStorageCommand();
sscmd.setPoolInfo(pi);
sscmd.setGuid(pi.getUuid());
sscmd.setDataCenter((String)_params.get("zone"));
sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
return new StartupCommand[]{cmd, sscmd};
}
@Override
@ -73,9 +174,13 @@ public class DummyResource implements ServerResource {
value = (String)params.get("negative.reply");
_negative = Boolean.parseBoolean(value);
setParams(params);
return true;
}
public void setParams(Map<String, Object> _params) {
this._params = _params;
}
@Override
public String getName() {

View File

@ -1993,8 +1993,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
} catch (ClosedChannelException e) {
s_logger.debug("Failed to send startupanswer: " + e.toString());
return null;
}
}
if (attache == null) {
return null;
}

View File

@ -23,14 +23,18 @@ import java.util.Map;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.ModifySshKeysCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.manager.Commands;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
@ -42,11 +46,11 @@ import com.cloud.network.router.VirtualNetworkApplianceManager;
public class SshKeysDistriMonitor implements Listener {
private static final Logger s_logger = Logger.getLogger(SshKeysDistriMonitor.class);
private final VirtualNetworkApplianceManager _routerMgr;
AgentManager _agentMgr;
private final HostDao _hostDao;
private ConfigurationDao _configDao;
public SshKeysDistriMonitor(VirtualNetworkApplianceManager mgr, HostDao host, ConfigurationDao config) {
this._routerMgr = mgr;
public SshKeysDistriMonitor(AgentManager mgr, HostDao host, ConfigurationDao config) {
this._agentMgr = mgr;
_hostDao = host;
_configDao = config;
}
@ -81,9 +85,13 @@ public class SshKeysDistriMonitor implements Listener {
Map<String, String> configs = _configDao.getConfiguration("management-server", new HashMap<String, Object>());
String pubKey = configs.get("ssh.publickey");
String prvKey = configs.get("ssh.privatekey");
if (!_routerMgr.sendSshKeysToHost(host.getId(), pubKey, prvKey)) {
try {
ModifySshKeysCommand cmds = new ModifySshKeysCommand(pubKey, prvKey);
Commands c = new Commands(cmds);
_agentMgr.send(host.getId(), c, this);
} catch (AgentUnavailableException e) {
s_logger.debug("Failed to send keys to agent: " + host.getId());
throw new ConnectionException(true, "Unable to send keys to the agent");
}
}
}

View File

@ -627,7 +627,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
throw new ConfigurationException("Unable to get " + UserStatisticsDao.class.getName());
}
_agentMgr.registerForHostEvents(new SshKeysDistriMonitor(this, _hostDao, _configDao), true, false, false);
_agentMgr.registerForHostEvents(new SshKeysDistriMonitor(_agentMgr, _hostDao, _configDao), true, false, false);
_itMgr.registerGuru(VirtualMachine.Type.DomainRouter, this);
boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));