use of com.cloud.agent.api.ReadyCommand in project cloudstack by apache.
the class Agent method processReadyCommand.
public void processReadyCommand(final Command cmd) {
final ReadyCommand ready = (ReadyCommand) cmd;
s_logger.info("Proccess agent ready command, agent id = " + ready.getHostId());
if (ready.getHostId() != null) {
setId(ready.getHostId());
}
s_logger.info("Ready command is processed: agent id = " + getId());
}
use of com.cloud.agent.api.ReadyCommand in project cloudstack by apache.
the class AgentManagerImpl method notifyMonitorsOfConnection.
protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, final StartupCommand[] cmd, final boolean forRebalance) throws ConnectionException {
final long hostId = attache.getId();
final HostVO host = _hostDao.findById(hostId);
for (final Pair<Integer, Listener> monitor : _hostMonitors) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName());
}
for (int i = 0; i < cmd.length; i++) {
try {
monitor.second().processConnect(host, cmd[i], forRebalance);
} catch (final Exception e) {
if (e instanceof ConnectionException) {
final ConnectionException ce = (ConnectionException) e;
if (ce.isSetupError()) {
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw ce;
} else {
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
return attache;
}
} else if (e instanceof HypervisorVersionChangedException) {
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
} else {
s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
}
}
}
}
final Long dcId = host.getDataCenterId();
final ReadyCommand ready = new ReadyCommand(dcId, host.getId());
final Answer answer = easySend(hostId, ready);
if (answer == null || !answer.getResult()) {
// this is tricky part for secondary storage
// make it as disconnected, wait for secondary storage VM to be up
// return the attache instead of null, even it is disconnectede
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
}
agentStatusTransitTo(host, Event.Ready, _nodeId);
attache.ready();
return attache;
}
use of com.cloud.agent.api.ReadyCommand in project cloudstack by apache.
the class VmwareResource method executeRequest.
@Override
public Answer executeRequest(Command cmd) {
if (s_logger.isTraceEnabled())
s_logger.trace("Begin executeRequest(), cmd: " + cmd.getClass().getSimpleName());
Answer answer = null;
NDC.push(getCommandLogTitle(cmd));
try {
long cmdSequence = _cmdSequence++;
Date startTime = DateUtil.currentGMTTime();
PropertyMapDynamicBean mbean = new PropertyMapDynamicBean();
mbean.addProp("StartTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), startTime));
mbean.addProp("Command", _gson.toJson(cmd));
mbean.addProp("Sequence", String.valueOf(cmdSequence));
mbean.addProp("Name", cmd.getClass().getSimpleName());
Class<? extends Command> clz = cmd.getClass();
if (cmd instanceof NetworkElementCommand) {
return _vrResource.executeRequest((NetworkElementCommand) cmd);
} else if (clz == ReadyCommand.class) {
answer = execute((ReadyCommand) cmd);
} else if (clz == GetHostStatsCommand.class) {
answer = execute((GetHostStatsCommand) cmd);
} else if (clz == GetVmStatsCommand.class) {
answer = execute((GetVmStatsCommand) cmd);
} else if (clz == GetVmDiskStatsCommand.class) {
answer = execute((GetVmDiskStatsCommand) cmd);
} else if (clz == CheckHealthCommand.class) {
answer = execute((CheckHealthCommand) cmd);
} else if (clz == StopCommand.class) {
answer = execute((StopCommand) cmd);
} else if (clz == RebootRouterCommand.class) {
answer = execute((RebootRouterCommand) cmd);
} else if (clz == RebootCommand.class) {
answer = execute((RebootCommand) cmd);
} else if (clz == CheckVirtualMachineCommand.class) {
answer = execute((CheckVirtualMachineCommand) cmd);
} else if (clz == PrepareForMigrationCommand.class) {
answer = execute((PrepareForMigrationCommand) cmd);
} else if (clz == MigrateCommand.class) {
answer = execute((MigrateCommand) cmd);
} else if (clz == MigrateWithStorageCommand.class) {
answer = execute((MigrateWithStorageCommand) cmd);
} else if (clz == MigrateVolumeCommand.class) {
answer = execute((MigrateVolumeCommand) cmd);
} else if (clz == DestroyCommand.class) {
answer = execute((DestroyCommand) cmd);
} else if (clz == CreateStoragePoolCommand.class) {
return execute((CreateStoragePoolCommand) cmd);
} else if (clz == ModifyTargetsCommand.class) {
answer = execute((ModifyTargetsCommand) cmd);
} else if (clz == ModifyStoragePoolCommand.class) {
answer = execute((ModifyStoragePoolCommand) cmd);
} else if (clz == DeleteStoragePoolCommand.class) {
answer = execute((DeleteStoragePoolCommand) cmd);
} else if (clz == CopyVolumeCommand.class) {
answer = execute((CopyVolumeCommand) cmd);
} else if (clz == AttachIsoCommand.class) {
answer = execute((AttachIsoCommand) cmd);
} else if (clz == ValidateSnapshotCommand.class) {
answer = execute((ValidateSnapshotCommand) cmd);
} else if (clz == ManageSnapshotCommand.class) {
answer = execute((ManageSnapshotCommand) cmd);
} else if (clz == BackupSnapshotCommand.class) {
answer = execute((BackupSnapshotCommand) cmd);
} else if (clz == CreateVolumeFromSnapshotCommand.class) {
answer = execute((CreateVolumeFromSnapshotCommand) cmd);
} else if (clz == CreatePrivateTemplateFromVolumeCommand.class) {
answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (clz == CreatePrivateTemplateFromSnapshotCommand.class) {
answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (clz == UpgradeSnapshotCommand.class) {
answer = execute((UpgradeSnapshotCommand) cmd);
} else if (clz == GetStorageStatsCommand.class) {
answer = execute((GetStorageStatsCommand) cmd);
} else if (clz == PrimaryStorageDownloadCommand.class) {
answer = execute((PrimaryStorageDownloadCommand) cmd);
} else if (clz == GetVncPortCommand.class) {
answer = execute((GetVncPortCommand) cmd);
} else if (clz == SetupCommand.class) {
answer = execute((SetupCommand) cmd);
} else if (clz == MaintainCommand.class) {
answer = execute((MaintainCommand) cmd);
} else if (clz == PingTestCommand.class) {
answer = execute((PingTestCommand) cmd);
} else if (clz == CheckOnHostCommand.class) {
answer = execute((CheckOnHostCommand) cmd);
} else if (clz == ModifySshKeysCommand.class) {
answer = execute((ModifySshKeysCommand) cmd);
} else if (clz == NetworkUsageCommand.class) {
answer = execute((NetworkUsageCommand) cmd);
} else if (clz == StartCommand.class) {
answer = execute((StartCommand) cmd);
} else if (clz == CheckSshCommand.class) {
answer = execute((CheckSshCommand) cmd);
} else if (clz == CheckNetworkCommand.class) {
answer = execute((CheckNetworkCommand) cmd);
} else if (clz == PlugNicCommand.class) {
answer = execute((PlugNicCommand) cmd);
} else if (clz == UnPlugNicCommand.class) {
answer = execute((UnPlugNicCommand) cmd);
} else if (cmd instanceof CreateVMSnapshotCommand) {
return execute((CreateVMSnapshotCommand) cmd);
} else if (cmd instanceof DeleteVMSnapshotCommand) {
return execute((DeleteVMSnapshotCommand) cmd);
} else if (cmd instanceof RevertToVMSnapshotCommand) {
return execute((RevertToVMSnapshotCommand) cmd);
} else if (clz == ResizeVolumeCommand.class) {
return execute((ResizeVolumeCommand) cmd);
} else if (clz == UnregisterVMCommand.class) {
return execute((UnregisterVMCommand) cmd);
} else if (cmd instanceof StorageSubSystemCommand) {
checkStorageProcessorAndHandlerNfsVersionAttribute((StorageSubSystemCommand) cmd);
return storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
} else if (clz == ScaleVmCommand.class) {
return execute((ScaleVmCommand) cmd);
} else if (clz == PvlanSetupCommand.class) {
return execute((PvlanSetupCommand) cmd);
} else if (clz == GetVmIpAddressCommand.class) {
return execute((GetVmIpAddressCommand) cmd);
} else if (clz == UnregisterNicCommand.class) {
answer = execute((UnregisterNicCommand) cmd);
} else {
answer = Answer.createUnsupportedCommandAnswer(cmd);
}
if (cmd.getContextParam("checkpoint") != null) {
answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
}
Date doneTime = DateUtil.currentGMTTime();
mbean.addProp("DoneTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), doneTime));
mbean.addProp("Answer", _gson.toJson(answer));
synchronized (this) {
try {
JmxUtil.registerMBean("VMware " + _morHyperHost.getValue(), "Command " + cmdSequence + "-" + cmd.getClass().getSimpleName(), mbean);
_cmdMBeans.add(mbean);
if (_cmdMBeans.size() >= MazCmdMBean) {
PropertyMapDynamicBean mbeanToRemove = _cmdMBeans.get(0);
_cmdMBeans.remove(0);
JmxUtil.unregisterMBean("VMware " + _morHyperHost.getValue(), "Command " + mbeanToRemove.getProp("Sequence") + "-" + mbeanToRemove.getProp("Name"));
}
} catch (Exception e) {
if (s_logger.isTraceEnabled())
s_logger.trace("Unable to register JMX monitoring due to exception " + ExceptionUtil.toString(e));
}
}
} finally {
recycleServiceContext();
NDC.pop();
}
if (s_logger.isTraceEnabled())
s_logger.trace("End executeRequest(), cmd: " + cmd.getClass().getSimpleName());
return answer;
}
use of com.cloud.agent.api.ReadyCommand in project cloudstack by apache.
the class HypervServerDiscoverer method find.
// End Listener implementation
// Returns server component used by server manager to operate the plugin.
// Server component is a ServerResource. If a connected agent is used, the
// ServerResource is
// ignored in favour of another created in response to
@Override
public final Map<? extends ServerResource, Map<String, String>> find(final long dcId, final Long podId, final Long clusterId, final URI uri, final String username, final String password, final List<String> hostTags) throws DiscoveryException {
if (s_logger.isInfoEnabled()) {
s_logger.info("Discover host. dc(zone): " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + uri.getHost());
}
// Assertions
if (podId == null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("No pod is assigned, skipping the discovery in" + " Hyperv discoverer");
}
return null;
}
// ClusterVO exists
ClusterVO cluster = _clusterDao.findById(clusterId);
// database
if (cluster == null) {
if (s_logger.isInfoEnabled()) {
s_logger.info("No cluster in database for cluster id " + clusterId);
}
return null;
}
if (cluster.getHypervisorType() != HypervisorType.Hyperv) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Cluster " + clusterId + "is not for Hyperv hypervisors");
}
return null;
}
if (!uri.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of" + " the discovery for this: " + uri;
s_logger.debug(msg);
return null;
}
try {
String hostname = uri.getHost();
InetAddress ia = InetAddress.getByName(hostname);
String agentIp = ia.getHostAddress();
String uuidSeed = agentIp;
String guidWithTail = calcServerResourceGuid(uuidSeed) + "-HypervResource";
if (_resourceMgr.findHostByGuid(guidWithTail) != null) {
s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database.");
return null;
}
s_logger.info("Creating" + HypervDirectConnectResource.class.getName() + " HypervDummyResourceBase for zone/pod/cluster " + dcId + "/" + podId + "/" + clusterId);
// This GUID may change.
if (cluster.getGuid() == null) {
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes(Charset.forName("UTF-8"))).toString());
_clusterDao.update(clusterId, cluster);
}
// Settings required by all server resources managing a hypervisor
Map<String, Object> params = new HashMap<String, Object>();
params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guidWithTail);
params.put("ipaddress", agentIp);
// Hyper-V specific settings
Map<String, String> details = new HashMap<String, String>();
details.put("url", uri.getHost());
details.put("username", username);
details.put("password", password);
details.put("cluster.guid", cluster.getGuid());
params.putAll(details);
params.put("router.aggregation.command.each.timeout", _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
HypervDirectConnectResource resource = new HypervDirectConnectResource();
resource.configure(agentIp, params);
// Assert
// TODO: test by using bogus URL and bogus virtual path in URL
ReadyCommand ping = new ReadyCommand();
Answer pingAns = resource.executeRequest(ping);
if (pingAns == null || !pingAns.getResult()) {
String errMsg = "Agent not running, or no route to agent on at " + uri;
s_logger.debug(errMsg);
throw new DiscoveryException(errMsg);
}
Map<HypervDirectConnectResource, Map<String, String>> resources = new HashMap<HypervDirectConnectResource, Map<String, String>>();
resources.put(resource, details);
// TODO: does the resource have to create a connection?
return resources;
} catch (ConfigurationException e) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage());
s_logger.warn("Unable to instantiate " + uri.getHost(), e);
} catch (UnknownHostException e) {
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage());
s_logger.warn("Unable to instantiate " + uri.getHost(), e);
} catch (Exception e) {
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
s_logger.warn(msg);
}
return null;
}
use of com.cloud.agent.api.ReadyCommand in project cloudstack by apache.
the class NiciraNvpRequestWrapperTest method testReadyCommandWrapper.
@Test
public void testReadyCommandWrapper() {
final ReadyCommand command = new ReadyCommand();
final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, niciraNvpResource);
assertTrue(answer.getResult());
}
Aggregations