use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.
the class BareMetalDiscoverer method createHostVOForDirectConnectAgent.
@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
StartupCommand firstCmd = startup[0];
if (!(firstCmd instanceof StartupRoutingCommand)) {
return null;
}
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
if (ssCmd.getHypervisorType() != HypervisorType.BareMetal) {
return null;
}
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.BareMetal, details, hostTags);
}
use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.
the class HypervDirectConnectResource method requestStartupCommand.
// TODO: Is it valid to return NULL, or should we throw on error?
// Returns StartupCommand with fields revised with values known only to the
// host
public final Command[] requestStartupCommand(final Command[] cmd) {
// Set HTTP POST destination URI
// Using java.net.URI, see
// http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URI.html
URI agentUri = null;
try {
final String cmdName = StartupCommand.class.getName();
agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) {
// TODO add proper logging
final String errMsg = "Could not generate URI for Hyper-V agent";
s_logger.error(errMsg, e);
return null;
}
final String incomingCmd = postHttpRequest(s_gson.toJson(cmd), agentUri);
if (incomingCmd == null) {
return null;
}
Command[] result = null;
try {
result = s_gson.fromJson(incomingCmd, Command[].class);
} catch (final Exception ex) {
final String errMsg = "Failed to deserialize Command[] " + incomingCmd;
s_logger.error(errMsg, ex);
}
s_logger.debug("requestStartupCommand received response " + s_gson.toJson(result));
if (result.length > 0) {
return result;
}
return null;
}
use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.
the class XenServerResourceNewBase method initialize.
@Override
public StartupCommand[] initialize() throws IllegalArgumentException {
final StartupCommand[] cmds = super.initialize();
final Connection conn = getConnection();
Pool pool;
try {
pool = Pool.getByUuid(conn, _host.getPool());
final Pool.Record poolr = pool.getRecord(conn);
final Host.Record masterRecord = poolr.master.getRecord(conn);
if (_host.getUuid().equals(masterRecord.uuid)) {
_listener = new VmEventListener(true);
//
// TODO disable event listener for now. Wait until everything else is ready
//
// _listener.start();
} else {
_listener = new VmEventListener(false);
}
} catch (final XenAPIException e) {
throw new CloudRuntimeException("Unable to determine who is the master", e);
} catch (final XmlRpcException e) {
throw new CloudRuntimeException("Unable to determine who is the master", e);
}
return cmds;
}
use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.
the class DummyHostServerResource method initialize.
@Override
public StartupCommand[] initialize() {
StartupRoutingCommand cmd = new StartupRoutingCommand();
cmd.setCpus(1);
cmd.setSpeed(1000L);
cmd.setMemory(1000000L);
cmd.setDom0MinMemory(256L);
cmd.setCaps("hvm");
cmd.setGuid(_guid);
cmd.setDataCenter(_zone);
cmd.setPod(_pod);
cmd.setHypervisorType(HypervisorType.None);
cmd.setAgentTag("vmops-simulator");
cmd.setName(_url);
cmd.setPrivateIpAddress(this.getHostPrivateIp());
cmd.setPrivateMacAddress(this.getHostMacAddress().toString());
cmd.setPrivateNetmask("255.255.0.0");
cmd.setIqn("iqn:" + _url);
cmd.setStorageIpAddress(getHostStoragePrivateIp());
cmd.setStorageMacAddress(getHostStorageMacAddress().toString());
cmd.setStorageIpAddressDeux(getHostStoragePrivateIp2());
cmd.setStorageMacAddressDeux(getHostStorageMacAddress2().toString());
cmd.setPublicIpAddress(getHostStoragePrivateIp());
cmd.setPublicMacAddress(getHostStorageMacAddress().toString());
cmd.setPublicNetmask("255.255.0.0");
cmd.setVersion(DummyHostServerResource.class.getPackage().getImplementationVersion());
return new StartupCommand[] { cmd };
}
use of com.cloud.agent.api.StartupCommand in project cloudstack by apache.
the class ResourceManagerImpl method createHostAndAgentDeferred.
private Host createHostAndAgentDeferred(final ServerResource resource, final Map<String, String> details, final boolean old, final List<String> hostTags, final boolean forRebalance) {
HostVO host = null;
StartupCommand[] cmds = null;
boolean hostExists = false;
boolean deferAgentCreation = true;
boolean created = false;
try {
cmds = resource.initialize();
if (cmds == null) {
s_logger.info("Unable to fully initialize the agent because no StartupCommands are returned");
return null;
}
/* Generate a random version in a dev setup situation */
if (this.getClass().getPackage().getImplementationVersion() == null) {
for (final StartupCommand cmd : cmds) {
if (cmd.getVersion() == null) {
cmd.setVersion(Long.toString(System.currentTimeMillis()));
}
}
}
if (s_logger.isDebugEnabled()) {
new Request(-1l, -1l, cmds, true, false).logD("Startup request from directly connected host: ", true);
}
if (old) {
final StartupCommand firstCmd = cmds[0];
host = findHostByGuid(firstCmd.getGuid());
if (host == null) {
host = findHostByGuid(firstCmd.getGuidWithoutResource());
}
if (host != null && host.getRemoved() == null) {
// host already
// added, no
// need to add
// again
s_logger.debug("Found the host " + host.getId() + " by guid: " + firstCmd.getGuid() + ", old host reconnected as new");
// ensures that host status is left
hostExists = true;
// again
return null;
}
}
host = null;
boolean newHost = false;
final GlobalLock addHostLock = GlobalLock.getInternLock("AddHostLock");
try {
if (addHostLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
// to safely determine first host in cluster in multi-MS scenario
try {
// find out if the host we want to connect to is new (so we can send an event)
newHost = getNewHost(cmds) == null;
host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT);
if (host != null) {
// if first host in cluster no need to defer agent creation
deferAgentCreation = !isFirstHostInCluster(host);
}
} finally {
addHostLock.unlock();
}
}
} finally {
addHostLock.releaseRef();
}
if (host != null) {
if (!deferAgentCreation) {
// if first host in cluster then
created = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance, newHost);
// reload
host = _hostDao.findById(host.getId());
} else {
// reload
host = _hostDao.findById(host.getId());
// force host status to 'Alert' so that it is loaded for
// connection during next scan task
_agentMgr.agentStatusTransitTo(host, Status.Event.AgentDisconnected, _nodeId);
// reload
host = _hostDao.findById(host.getId());
// so that scan task can pick it up
host.setLastPinged(0);
_hostDao.update(host.getId(), host);
}
}
} catch (final Exception e) {
s_logger.warn("Unable to connect due to ", e);
} finally {
if (hostExists) {
if (cmds != null) {
resource.disconnected();
}
} else {
if (!deferAgentCreation && !created) {
if (cmds != null) {
resource.disconnected();
}
markHostAsDisconnected(host, cmds);
}
}
}
return host;
}
Aggregations