use of com.cloud.agent.api.StartupRoutingCommand in project cloudstack by apache.
the class HypervDirectConnectResource method initialize.
@Override
public final StartupCommand[] initialize() {
// assert
if (!_configureCalled) {
final String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()";
s_logger.error(errMsg);
}
// Create default StartupRoutingCommand, then customise
final StartupRoutingCommand defaultStartRoutCmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.Hyperv, RouterPrivateIpStrategy.HostLocal);
// Identity within the data centre is decided by CloudStack kernel,
// and passed via ServerResource.configure()
defaultStartRoutCmd.setDataCenter(_zoneId);
defaultStartRoutCmd.setPod(_podId);
defaultStartRoutCmd.setCluster(_clusterId);
defaultStartRoutCmd.setGuid(_guid);
defaultStartRoutCmd.setName(_name);
defaultStartRoutCmd.setPrivateIpAddress(_agentIp);
defaultStartRoutCmd.setStorageIpAddress(_agentIp);
defaultStartRoutCmd.setPool(_clusterGuid);
s_logger.debug("Generated StartupRoutingCommand for _agentIp \"" + _agentIp + "\"");
defaultStartRoutCmd.setVersion(this.getClass().getPackage().getImplementationVersion());
// Specifics of the host's resource capacity and network configuration
// comes from the host itself. CloudStack sanity checks network
// configuration
// and uses capacity info for resource allocation.
final Command[] startCmds = requestStartupCommand(new Command[] { defaultStartRoutCmd });
// TODO: may throw, is this okay?
final StartupRoutingCommand startCmd = (StartupRoutingCommand) startCmds[0];
// Assert that host identity is consistent with existing values.
if (startCmd == null) {
final String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
if (!startCmd.getDataCenter().equals(defaultStartRoutCmd.getDataCenter())) {
final String errMsg = String.format("Host %s (IP %s) changed zone/data center. Was " + defaultStartRoutCmd.getDataCenter() + " NOW its " + startCmd.getDataCenter(), _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
if (!startCmd.getPod().equals(defaultStartRoutCmd.getPod())) {
final String errMsg = String.format("Host %s (IP %s) changed pod. Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
if (!startCmd.getCluster().equals(defaultStartRoutCmd.getCluster())) {
final String errMsg = String.format("Host %s (IP %s) changed cluster. Was " + defaultStartRoutCmd.getCluster() + " NOW its " + startCmd.getCluster(), _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
if (!startCmd.getGuid().equals(defaultStartRoutCmd.getGuid())) {
final String errMsg = String.format("Host %s (IP %s) changed guid. Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
if (!startCmd.getPrivateIpAddress().equals(defaultStartRoutCmd.getPrivateIpAddress())) {
final String errMsg = String.format("Host %s (IP %s) IP address. Was " + defaultStartRoutCmd.getPrivateIpAddress() + " NOW its " + startCmd.getPrivateIpAddress(), _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
if (!startCmd.getName().equals(defaultStartRoutCmd.getName())) {
final String errMsg = String.format("Host %s (IP %s) name. Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
// Host will also supply details of an existing StoragePool if it has
// been configured with one.
//
// NB: if the host was configured
// with a local storage pool, CloudStack may not be able to use it
// unless
// it is has service offerings configured to recognise this storage
// type.
StartupStorageCommand storePoolCmd = null;
if (startCmds.length > 1) {
storePoolCmd = (StartupStorageCommand) startCmds[1];
// TODO: is this assertion required?
if (storePoolCmd == null) {
final String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand";
final String errMsg = String.format(frmtStr, _name, _agentIp);
s_logger.error(errMsg);
// TODO: valid to return null, or should we throw?
return null;
}
s_logger.info("Host " + _name + " (IP " + _agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1]));
} else {
s_logger.info("Host " + _name + " (IP " + _agentIp + ") already configured with a storeage pool, details ");
}
return new StartupCommand[] { startCmd, storePoolCmd };
}
use of com.cloud.agent.api.StartupRoutingCommand in project cloudstack by apache.
the class HypervDirectConnectResourceTest method testStartupCommand.
public final void testStartupCommand() {
StartupRoutingCommand defaultStartRoutCmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.Hyperv, RouterPrivateIpStrategy.HostLocal);
// Identity within the data centre is decided by CloudStack kernel,
// and passed via ServerResource.configure()
defaultStartRoutCmd.setDataCenter("1");
defaultStartRoutCmd.setPod("1");
defaultStartRoutCmd.setCluster("1");
defaultStartRoutCmd.setGuid("1");
defaultStartRoutCmd.setName("1");
defaultStartRoutCmd.setPrivateIpAddress("1");
defaultStartRoutCmd.setStorageIpAddress("1");
defaultStartRoutCmd.setCpus(12);
// TODO: does version need to be hard coded.
defaultStartRoutCmd.setVersion("4.2.0");
StartupCommand scmd = defaultStartRoutCmd;
Command[] cmds = { scmd };
String cmdsStr = s_gson.toJson(cmds);
s_logger.debug("Commands[] toJson is " + cmdsStr);
Command[] result = s_gson.fromJson(cmdsStr, Command[].class);
s_logger.debug("Commands[] fromJson is " + s_gson.toJson(result));
s_logger.debug("Commands[] first element has type" + result[0].toString());
}
use of com.cloud.agent.api.StartupRoutingCommand in project cloudstack by apache.
the class VmwareServerDiscoverer 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.VMware) {
return null;
}
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.VMware, details, hostTags);
}
use of com.cloud.agent.api.StartupRoutingCommand in project cloudstack by apache.
the class Ovm3HypervisorResource method initialize.
/*
* configure is called before this, does setup of the connection and
* gets the params.
*
* @see com.cloud.resource.ServerResource#initialize()
*/
@Override
public StartupCommand[] initialize() {
LOGGER.debug("Ovm3 resource intializing");
try {
StartupRoutingCommand srCmd = new StartupRoutingCommand();
StartupStorageCommand ssCmd = new StartupStorageCommand();
/* here stuff gets completed, but where should state live ? */
hypervisorsupport.fillHostInfo(srCmd);
hypervisorsupport.vmStateMapClear();
LOGGER.debug("Ovm3 pool " + ssCmd + " " + srCmd);
return new StartupCommand[] { srCmd, ssCmd };
} catch (Exception e) {
LOGGER.debug("Ovm3 resource initializes failed", e);
return new StartupCommand[] {};
}
}
use of com.cloud.agent.api.StartupRoutingCommand in project cloudstack by apache.
the class Ovm3Discoverer method createHostVOForDirectConnectAgent.
@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
LOGGER.debug("createHostVOForDirectConnectAgent: " + host);
StartupCommand firstCmd = startup[0];
if (!(firstCmd instanceof StartupRoutingCommand)) {
return null;
}
StartupRoutingCommand ssCmd = (StartupRoutingCommand) firstCmd;
if (ssCmd.getHypervisorType() != HypervisorType.Ovm3) {
return null;
}
return resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Ovm3, details, hostTags);
}
Aggregations