checkins for problems.

This commit is contained in:
Alex Huang 2010-10-26 09:34:40 -07:00
parent 29a5b796d4
commit 2bc938c3f8
23 changed files with 85 additions and 80 deletions

View File

@ -17,6 +17,7 @@
*/
package com.cloud.exception;
import com.cloud.utils.SerialVersionUID;
import com.cloud.utils.exception.CloudRuntimeException;
/**
@ -25,7 +26,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
*/
public class PermissionDeniedException extends CloudRuntimeException {
private static final long serialVersionUID = -4631412831814398074L;
private static final long serialVersionUID = SerialVersionUID.PermissionDeniedException;
public PermissionDeniedException(String message) {
super(message);

View File

@ -33,7 +33,7 @@ updateResourceLimit=com.cloud.api.commands.UpdateResourceLimitCmd;3
listResourceLimits=com.cloud.api.commands.ListResourceLimitsCmd;15
#### VM commands
deployVirtualMachine=com.cloud.api.commands.DeployVm2Cmd;11
deployVirtualMachine=com.cloud.api.commands.DeployVMCmd;11
destroyVirtualMachine=com.cloud.api.commands.DestroyVMCmd;15
rebootVirtualMachine=com.cloud.api.commands.RebootVMCmd;15
startVirtualMachine=com.cloud.api.commands.StartVMCmd;15

View File

@ -22,6 +22,7 @@ import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.exception.ConnectionException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
@ -73,8 +74,9 @@ public interface Listener {
* been registered for host events.
* @param agentId id of the agent
* @param cmd command sent by the agent to the server on startup.
* @throws ConnectionException if host has problems and needs to put into maintenance state.
*/
boolean processConnect(HostVO host, StartupCommand cmd);
void processConnect(HostVO host, StartupCommand cmd) throws ConnectionException;
/**
* This method is called by AgentManager when an agent disconnects

View File

@ -96,6 +96,7 @@ import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.event.dao.EventDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.OperationTimedoutException;
@ -1050,11 +1051,18 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
s_logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName());
}
for (int i = 0; i < cmd.length; i++) {
if (!monitor.second().processConnect(host, cmd[i])) {
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId);
handleDisconnect(attache, Event.AgentDisconnected, false);
return attache;
}
try {
monitor.second().processConnect(host, cmd[i]);
} catch (ConnectionException e) {
if (e.isSetupError()) {
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnect(attache, Event.AgentDisconnected, false);
} else {
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnect(attache, Event.ShutdownRequested, false);
}
return null;
}
}
}

View File

@ -195,9 +195,8 @@ public class AgentMonitor extends Thread implements Listener {
}
@Override
public boolean processConnect(HostVO host, StartupCommand cmd) {
public void processConnect(HostVO host, StartupCommand cmd) {
s_logger.debug("Registering agent monitor for " + host.getId());
return true;
}
@Override

View File

@ -80,8 +80,7 @@ public class SynchronousListener implements Listener {
}
@Override
public boolean processConnect(HostVO agent, StartupCommand cmd) {
return false;
public void processConnect(HostVO agent, StartupCommand cmd) {
}
@Override

View File

@ -50,6 +50,7 @@ public class VMOperationListener implements Listener {
_cookie = cookie;
}
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
Answer answer = null;
if(answers != null)
@ -61,33 +62,40 @@ public class VMOperationListener implements Listener {
return true;
}
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
return true;
}
@Override
public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
return null;
}
public boolean processConnect(HostVO agent, StartupCommand cmd) {
return true;
@Override
public void processConnect(HostVO agent, StartupCommand cmd) {
// return true;
}
@Override
public boolean processDisconnect(long agentId, Status state) {
if(_vm.getHostId() == agentId)
_executor.processDisconnect(this, agentId);
return true;
}
@Override
public boolean isRecurring() {
return false;
}
@Override
public int getTimeout() {
// TODO : no time out support for now as underlying support does not work as expected
return -1;
}
@Override
public boolean processTimeout(long agentId, long seq) {
if(s_logger.isDebugEnabled())
s_logger.debug("Process time out for " + agentId + "-" + seq);

View File

@ -52,6 +52,7 @@ public class VolumeOperationListener implements Listener {
_cookie = cookie;
}
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
Answer answer = null;
if(answers != null)
@ -64,33 +65,39 @@ public class VolumeOperationListener implements Listener {
return true;
}
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
return true;
}
@Override
public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
return null;
}
public boolean processConnect(HostVO agent, StartupCommand cmd) {
return true;
@Override
public void processConnect(HostVO agent, StartupCommand cmd) {
}
@Override
public boolean processDisconnect(long agentId, Status state) {
if(_vm.getHostId() == agentId)
_executor.processDisconnect(this, agentId);
return true;
}
@Override
public boolean isRecurring() {
return false;
}
@Override
public int getTimeout() {
// TODO : no time out support for now as underlying support does not work as expected
return -1;
}
@Override
public boolean processTimeout(long agentId, long seq) {
if(s_logger.isDebugEnabled())
s_logger.debug("Process time out for " + agentId + "-" + seq);

View File

@ -64,9 +64,8 @@ public class ConsoleProxyListener implements Listener {
}
@Override
public boolean processConnect(HostVO host, StartupCommand cmd) {
public void processConnect(HostVO host, StartupCommand cmd) {
_proxyMgr.onAgentConnect(host, cmd);
return true;
}
@Override

View File

@ -33,6 +33,8 @@ import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.manager.Commands;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
@ -119,9 +121,9 @@ public class VmSyncListener implements Listener {
}
@Override
public boolean processConnect(HostVO agent, StartupCommand cmd) {
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
if (!(cmd instanceof StartupRoutingCommand)) {
return true;
return;
}
long agentId = agent.getId();
@ -135,12 +137,13 @@ public class VmSyncListener implements Listener {
Commands cmds = new Commands(OnError.Continue);
cmds.addCommands(commands);
try {
_agentMgr.send(agentId, cmds, this);
Answer[] answers = _agentMgr.send(agentId, cmds);
} catch (final AgentUnavailableException e) {
s_logger.warn("Agent is unavailable now", e);
throw new ConnectionException(true, "Unable to sync", e);
} catch (final OperationTimedoutException e) {
throw new ConnectionException(true, "Unable to sync", e);
}
}
return true;
}
}

View File

@ -71,9 +71,7 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
}
@Override
public boolean processConnect(HostVO host, StartupCommand cmd) {
// TODO Auto-generated method stub
return false;
public void processConnect(HostVO host, StartupCommand cmd) {
}
@Override

View File

@ -45,6 +45,7 @@ import com.cloud.alert.AlertManager;
import com.cloud.configuration.Config;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.DiscoveryException;
import com.cloud.host.HostInfo;
import com.cloud.host.HostVO;
@ -521,12 +522,10 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L
}
@Override
public boolean processConnect(HostVO agent, StartupCommand cmd) {
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
if (cmd instanceof StartupStorageCommand) {
createPVTemplate(agent.getId(), (StartupStorageCommand)cmd);
return true;
}
return true;
}
@Override

View File

@ -31,6 +31,7 @@ import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.exception.ConnectionException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
@ -71,10 +72,10 @@ public class SshKeysDistriMonitor implements Listener {
}
@Override
public boolean processConnect(HostVO host, StartupCommand cmd) {
public void processConnect(HostVO host, StartupCommand cmd) throws ConnectionException {
if (cmd instanceof StartupRoutingCommand) {
if (((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.KVM ||
((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.XenServer) {
((StartupRoutingCommand) cmd).getHypervisorType() == HypervisorType.XenServer) {
/*TODO: Get the private/public keys here*/
Map<String, String> configs = _configDao.getConfiguration("management-server", new HashMap<String, Object>());
@ -82,11 +83,10 @@ public class SshKeysDistriMonitor implements Listener {
String prvKey = configs.get("ssh.privatekey");
if (!_routerMgr.sendSshKeysToHost(host.getId(), pubKey, prvKey)) {
s_logger.debug("Failed to send keys to agent: " + host.getId());
return false;
throw new ConnectionException(true, "Unable to send keys to the agent");
}
}
}
return true;
}
@Override

View File

@ -111,9 +111,7 @@ public class NetworkGroupListener implements Listener {
@Override
public boolean processConnect(HostVO host, StartupCommand cmd) {
return true;
public void processConnect(HostVO host, StartupCommand cmd) {
}

View File

@ -27,9 +27,9 @@ import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.StoragePoolInfo;
import com.cloud.exception.ConnectionException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.storage.Storage.StorageResourceType;
import com.cloud.storage.dao.StoragePoolDao;
import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.utils.component.Inject;
@ -65,20 +65,20 @@ public class LocalStoragePoolListener implements Listener {
@Override
@DB
public boolean processConnect(HostVO host, StartupCommand cmd) {
public void processConnect(HostVO host, StartupCommand cmd) throws ConnectionException {
if (!(cmd instanceof StartupStorageCommand)) {
return true;
return;
}
StartupStorageCommand ssCmd = (StartupStorageCommand)cmd;
if (ssCmd.getResourceType() != Storage.StorageResourceType.STORAGE_POOL) {
return true;
return;
}
StoragePoolInfo pInfo = ssCmd.getPoolInfo();
if (pInfo == null) {
return true;
return;
}
try {
@ -114,9 +114,8 @@ public class LocalStoragePoolListener implements Listener {
}
} catch (Exception e) {
s_logger.warn("Unable to setup the local storage pool for " + host, e);
return false;
throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
}
return true;
}

View File

@ -39,6 +39,7 @@ import com.cloud.agent.api.storage.DownloadProgressCommand;
import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.event.EventTypes;
import com.cloud.event.EventVO;
import com.cloud.exception.ConnectionException;
import com.cloud.host.HostVO;
import com.cloud.storage.Storage;
import com.cloud.storage.VMTemplateHostVO;
@ -274,13 +275,13 @@ public class DownloadListener implements Listener {
}
@Override
public boolean processConnect(HostVO agent, StartupCommand cmd) {
public void processConnect(HostVO agent, StartupCommand cmd) throws ConnectionException {
if (!(cmd instanceof StartupStorageCommand)) {
return true;
return;
}
if (cmd.getGuid().startsWith("iso:")) {
//FIXME: do not download template for ISO secondary
return true;
return;
}
long agentId = agent.getId();
@ -294,8 +295,6 @@ public class DownloadListener implements Listener {
//downloadMonitor.handlePoolTemplateSync(storage.getPoolInfo(), storage.getTemplateInfo());
//no need to do anything. The storagepoolmonitor will initiate template sync.
}
return true;
}
public void setCommand(DownloadCommand _cmd) {

View File

@ -66,7 +66,7 @@ public class StoragePoolMonitor implements Listener {
}
@Override
public boolean processConnect(HostVO host, StartupCommand cmd) {
public void processConnect(HostVO host, StartupCommand cmd) {
if (cmd instanceof StartupRoutingCommand) {
StartupRoutingCommand scCmd = (StartupRoutingCommand)cmd;
if (scCmd.getHypervisorType() == HypervisorType.XenServer || scCmd.getHypervisorType() == HypervisorType.KVM ||
@ -81,7 +81,6 @@ public class StoragePoolMonitor implements Listener {
}
}
}
return true;
}

View File

@ -52,8 +52,7 @@ public class StorageSyncListener implements Listener {
}
@Override
public boolean processConnect(HostVO agent, StartupCommand cmd) {
return false;
public void processConnect(HostVO agent, StartupCommand cmd) {
}
@Override

View File

@ -29,7 +29,6 @@ import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.StorageResourceType;
public class SecondaryStorageListener implements Listener {
private final static Logger s_logger = Logger.getLogger(SecondaryStorageListener.class);
@ -76,11 +75,10 @@ public class SecondaryStorageListener implements Listener {
}
@Override
public boolean processConnect(HostVO agent, StartupCommand cmd) {
if(s_logger.isInfoEnabled())
s_logger.info("Received a host startup notification");
public void processConnect(HostVO agent, StartupCommand cmd) {
if (cmd instanceof StartupStorageCommand) {
if(s_logger.isInfoEnabled())
s_logger.info("Received a host startup notification");
StartupStorageCommand ss = (StartupStorageCommand)cmd;
if (ss.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE) {
@ -89,8 +87,6 @@ public class SecondaryStorageListener implements Listener {
_ssVmMgr.generateSetupCommand(agent.getDataCenterId());
}
}
return true;
}
@Override

View File

@ -24,15 +24,13 @@ import com.cloud.agent.api.storage.UploadProgressCommand.RequestType;
import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobResult;
import com.cloud.async.executor.ExtractJobResultObject;
import com.cloud.event.EventTypes;
import com.cloud.event.EventVO;
import com.cloud.host.HostVO;
import com.cloud.storage.Storage;
import com.cloud.storage.UploadVO;
import com.cloud.storage.dao.UploadDao;
import com.cloud.storage.Upload.Status;
import com.cloud.storage.Upload.Type;
import com.cloud.storage.upload.UploadMonitorImpl;
import com.cloud.storage.UploadVO;
import com.cloud.storage.dao.UploadDao;
import com.cloud.storage.upload.UploadState.UploadEvent;
import com.cloud.utils.exception.CloudRuntimeException;
@ -210,9 +208,9 @@ public class UploadListener implements Listener {
}
@Override
public boolean processConnect(HostVO agent, StartupCommand cmd) {
public void processConnect(HostVO agent, StartupCommand cmd) {
if (!(cmd instanceof StartupStorageCommand)) {
return true;
return;
}
long agentId = agent.getId();
@ -223,7 +221,6 @@ public class UploadListener implements Listener {
{
uploadMonitor.handleUploadSync(agentId);
}
return true;
}
@Override

View File

@ -63,7 +63,6 @@ import com.cloud.agent.api.VmStatsEntry;
import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
import com.cloud.agent.manager.Commands;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
import com.cloud.api.commands.AttachVolumeCmd;
@ -3804,18 +3803,18 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
public UserVm createVirtualMachine(DeployVm2Cmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException {
Account caller = UserContext.current().getAccount();
Domain domain = _domainDao.findById(cmd.getDomainId());
AccountVO owner = _accountDao.findById(cmd.getAccountId());
if (owner == null || owner.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find account: " + cmd.getAccountId());
}
Domain domain = _domainDao.findById(owner.getDomainId());
if (domain == null || domain.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find domain: " + cmd.getDomainId());
}
_accountMgr.checkAccess(caller, domain);
AccountVO owner = _accountDao.findById(cmd.getAccountId());
if (owner == null || owner.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find account: " + cmd.getAccountId());
}
DataCenterVO dc = _dcDao.findById(cmd.getZoneId());
if (dc == null) {
throw new InvalidParameterValueException("Unable to find zone: " + cmd.getZoneId());

View File

@ -32,12 +32,6 @@ public interface SerialVersionUID {
public static final long CloudRuntimeException = Base | 0x2;
public static final long CloudStartupServlet = Base | 0x3;
public static final long CloudServiceImpl = Base | 0x4;
public static final long UserRemote = Base | 0x5;
public static final long ServiceOfferingRemote = Base | 0x6;
public static final long VMTemplateRemote = Base | 0x7;
public static final long VMInstanceRemote = Base | 0x8;
public static final long IPAddressRemote = Base | 0x9;
public static final long IPForwardingRemote = Base | 0xa;
public static final long UnsupportedVersionException = Base | 0xb;
public static final long DataCenterIpAddressPK = Base | 0xc;
public static final long UnableToExecuteException = Base | 0xd;
@ -59,4 +53,6 @@ public interface SerialVersionUID {
public static final long CloudAuthenticationException = Base | 0x1d;
public static final long AsyncCommandQueued = Base | 0x1e;
public static final long ResourceUnavailableException = Base | 0x1f;
public static final long ConnectionException = Base | 0x20;
public static final long PermissionDeniedException = Base | 0x21;
}

View File

@ -803,7 +803,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
protected T findById(ID id, boolean removed, Boolean lock) {
StringBuilder sql = new StringBuilder(_selectByIdSql);
if (!removed) {
if (!removed && _removed != null) {
sql.append(" AND ").append(_removed.first());
}
if (lock != null) {