use of com.cloud.agent.api.SetupAnswer in project cloudstack by apache.
the class HypervServerDiscoverer method processConnect.
@Override
public final void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
// Limit the commands we can process
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
// assert
if (startup.getHypervisorType() != HypervisorType.Hyperv) {
s_logger.debug("Not Hyper-V hypervisor, so moving on.");
return;
}
long agentId = agent.getId();
HostVO host = _hostDao.findById(agentId);
// Our Hyper-V machines are not participating in pools, and the pool id
// we provide them is not persisted.
// This means the pool id can vary.
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
_clusterDao.update(cluster.getId(), cluster);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
HostEnvironment env = new HostEnvironment();
SetupCommand setup = new SetupCommand(env);
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
SetupAnswer answer = (SetupAnswer) _agentMgr.send(agentId, setup);
if (answer != null && answer.getResult()) {
host.setSetup(true);
// TODO: clean up magic numbers below
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
_hostDao.update(host.getId(), host);
if (answer.needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
String reason = answer.getDetails();
if (reason == null) {
reason = " details were null";
}
s_logger.warn("Unable to setup agent " + agentId + " due to " + reason);
}
// Error handling borrowed from XcpServerDiscoverer, may need to be
// updated.
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
use of com.cloud.agent.api.SetupAnswer in project cloudstack by apache.
the class XcpServerDiscoverer method processConnect.
@Override
public void processConnect(com.cloud.host.Host agent, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
long agentId = agent.getId();
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
if (startup.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Not XenServer so moving on.");
return;
}
HostVO host = _hostDao.findById(agentId);
ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
_clusterDao.update(cluster.getId(), cluster);
} else if (!cluster.getGuid().equals(startup.getPool())) {
String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
Map<String, String> details = startup.getHostDetails();
String prodBrand = details.get("product_brand").trim();
String prodVersion = details.get("product_version").trim();
String hotfix = details.get(XenserverConfigs.XS620HotFix);
String prodVersionTextShort = details.get("product_version_text_short");
String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
if (!resource.equals(host.getResource())) {
String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
s_logger.debug(msg);
host.setResource(resource);
host.setSetup(false);
_hostDao.update(agentId, host);
throw new HypervisorVersionChangedException(msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
HostEnvironment env = new HostEnvironment();
SetupCommand setup = new SetupCommand(env);
if (_setupMultipath) {
setup.setMultipathOn();
}
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
Answer answer = _agentMgr.send(agentId, setup);
if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
host.setSetup(true);
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
host.setHypervisorVersion(prodVersion);
_hostDao.update(host.getId(), host);
if (((SetupAnswer) answer).needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
}
} catch (AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
use of com.cloud.agent.api.SetupAnswer in project cloudstack by apache.
the class CitrixSetupCommandWrapper method execute.
@Override
public Answer execute(final SetupCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
if (poolRecs.size() != 1) {
throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + citrixResourceBase.getHost().getUuid());
}
final Host master = poolRecs.values().iterator().next().master;
citrixResourceBase.setupServer(conn, master);
final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
citrixResourceBase.setupServer(conn, host);
if (!citrixResourceBase.setIptables(conn)) {
s_logger.warn("set xenserver Iptable failed");
return null;
}
if (citrixResourceBase.isSecurityGroupEnabled()) {
final boolean canBridgeFirewall = citrixResourceBase.canBridgeFirewall(conn);
citrixResourceBase.setCanBridgeFirewall(canBridgeFirewall);
if (!canBridgeFirewall) {
final String msg = "Failed to configure brige firewall";
s_logger.warn(msg);
s_logger.warn("Check host " + citrixResourceBase.getHost().getIp() + " for CSP is installed or not and check network mode for bridge");
return new SetupAnswer(command, msg);
}
}
final boolean r = citrixResourceBase.launchHeartBeat(conn);
if (!r) {
return null;
}
citrixResourceBase.cleanupTemplateSR(conn);
try {
if (command.useMultipath()) {
// the config value is set to true
host.addToOtherConfig(conn, "multipathing", "true");
host.addToOtherConfig(conn, "multipathhandle", "dmp");
}
} catch (final Types.MapDuplicateKey e) {
s_logger.debug("multipath is already set");
}
if (command.needSetup()) {
final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "setup_iscsi", "uuid", citrixResourceBase.getHost().getUuid());
if (!result.contains("> DONE <")) {
s_logger.warn("Unable to setup iscsi: " + result);
return new SetupAnswer(command, result);
}
Pair<PIF, PIF.Record> mgmtPif = null;
final Set<PIF> hostPifs = host.getPIFs(conn);
for (final PIF pif : hostPifs) {
final PIF.Record rec = pif.getRecord(conn);
if (rec.management) {
if (rec.VLAN != null && rec.VLAN != -1) {
final String msg = new StringBuilder("Unsupported configuration. Management network is on a VLAN. host=").append(citrixResourceBase.getHost().getUuid()).append("; pif=").append(rec.uuid).append("; vlan=").append(rec.VLAN).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Management network is on pif=" + rec.uuid);
}
mgmtPif = new Pair<PIF, PIF.Record>(pif, rec);
break;
}
}
if (mgmtPif == null) {
final String msg = "Unable to find management network for " + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
final Map<Network, Network.Record> networks = Network.getAllRecords(conn);
if (networks == null) {
final String msg = "Unable to setup as there are no networks in the host: " + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
for (final Network.Record network : networks.values()) {
if (network.nameLabel.equals("cloud-private")) {
for (final PIF pif : network.PIFs) {
final PIF.Record pr = pif.getRecord(conn);
if (citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found a network called cloud-private. host=" + citrixResourceBase.getHost().getUuid() + "; Network=" + network.uuid + "; pif=" + pr.uuid);
}
if (pr.VLAN != null && pr.VLAN != -1) {
final String msg = new StringBuilder("Unsupported configuration. Network cloud-private is on a VLAN. Network=").append(network.uuid).append(" ; pif=").append(pr.uuid).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
if (!pr.management && pr.bondMasterOf != null && pr.bondMasterOf.size() > 0) {
if (pr.bondMasterOf.size() > 1) {
final String msg = new StringBuilder("Unsupported configuration. Network cloud-private has more than one bond. Network=").append(network.uuid).append("; pif=").append(pr.uuid).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
final Bond bond = pr.bondMasterOf.iterator().next();
final Set<PIF> slaves = bond.getSlaves(conn);
for (final PIF slave : slaves) {
final PIF.Record spr = slave.getRecord(conn);
if (spr.management) {
if (!citrixResourceBase.transferManagementNetwork(conn, host, slave, spr, pif)) {
final String msg = new StringBuilder("Unable to transfer management network. slave=" + spr.uuid + "; master=" + pr.uuid + "; host=" + citrixResourceBase.getHost().getUuid()).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
break;
}
}
}
}
}
}
}
}
return new SetupAnswer(command, false);
} catch (final XmlRpcException e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
} catch (final XenAPIException e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
} catch (final Exception e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
}
}
use of com.cloud.agent.api.SetupAnswer in project cosmic by MissionCriticalCloud.
the class XcpServerDiscoverer method processConnect.
@Override
public void processConnect(final com.cloud.host.Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
if (!(cmd instanceof StartupRoutingCommand)) {
return;
}
final long agentId = agent.getId();
final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
if (startup.getHypervisorType() != HypervisorType.XenServer) {
s_logger.debug("Not XenServer so moving on.");
return;
}
final HostVO host = _hostDao.findById(agentId);
final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
if (cluster.getGuid() == null) {
cluster.setGuid(startup.getPool());
_clusterDao.update(cluster.getId(), cluster);
} else if (!cluster.getGuid().equals(startup.getPool())) {
final String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
final Map<String, String> details = startup.getHostDetails();
final String prodBrand = details.get("product_brand").trim();
final String prodVersion = details.get("product_version").trim();
final String hotfix = details.get(XenserverConfigs.XS620HotFix);
final String prodVersionTextShort = details.get("product_version_text_short");
final String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
if (!resource.equals(host.getResource())) {
final String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
s_logger.debug(msg);
host.setResource(resource);
host.setSetup(false);
_hostDao.update(agentId, host);
throw new HypervisorVersionChangedException(msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Setting up host " + agentId);
}
final HostEnvironment env = new HostEnvironment();
final SetupCommand setup = new SetupCommand(env);
if (_setupMultipath) {
setup.setMultipathOn();
}
if (!host.isSetup()) {
setup.setNeedSetup(true);
}
try {
final Answer answer = _agentMgr.send(agentId, setup);
if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
host.setSetup(true);
host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
host.setHypervisorVersion(prodVersion);
_hostDao.update(host.getId(), host);
if (((SetupAnswer) answer).needReconnect()) {
throw new ConnectionException(false, "Reinitialize agent after setup.");
}
return;
} else {
s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
}
} catch (final AgentUnavailableException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
} catch (final OperationTimedoutException e) {
s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
}
throw new ConnectionException(true, "Reinitialize agent after setup.");
}
use of com.cloud.agent.api.SetupAnswer in project cosmic by MissionCriticalCloud.
the class CitrixSetupCommandWrapper method execute.
@Override
public Answer execute(final SetupCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
if (poolRecs.size() != 1) {
throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + citrixResourceBase.getHost().getUuid());
}
final Host master = poolRecs.values().iterator().next().master;
citrixResourceBase.setupServer(conn, master);
final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
citrixResourceBase.setupServer(conn, host);
if (!citrixResourceBase.setIptables(conn)) {
s_logger.warn("set xenserver Iptable failed");
return null;
}
final boolean r = citrixResourceBase.launchHeartBeat(conn);
if (!r) {
return null;
}
citrixResourceBase.cleanupTemplateSR(conn);
try {
if (command.useMultipath()) {
// the config value is set to true
host.addToOtherConfig(conn, "multipathing", "true");
host.addToOtherConfig(conn, "multipathhandle", "dmp");
}
} catch (final Types.MapDuplicateKey e) {
s_logger.debug("multipath is already set");
}
if (command.needSetup()) {
final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "setup_iscsi", "uuid", citrixResourceBase.getHost().getUuid());
if (!result.contains("> DONE <")) {
s_logger.warn("Unable to setup iscsi: " + result);
return new SetupAnswer(command, result);
}
Pair<PIF, PIF.Record> mgmtPif = null;
final Set<PIF> hostPifs = host.getPIFs(conn);
for (final PIF pif : hostPifs) {
final PIF.Record rec = pif.getRecord(conn);
if (rec.management) {
if (rec.VLAN != null && rec.VLAN != -1) {
final String msg = new StringBuilder("Unsupported configuration. Management network is on a VLAN. host=").append(citrixResourceBase.getHost().getUuid()).append("; pif=").append(rec.uuid).append("; vlan=").append(rec.VLAN).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Management network is on pif=" + rec.uuid);
}
mgmtPif = new Pair<>(pif, rec);
break;
}
}
if (mgmtPif == null) {
final String msg = "Unable to find management network for " + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
final Map<Network, Network.Record> networks = Network.getAllRecords(conn);
if (networks == null) {
final String msg = "Unable to setup as there are no networks in the host: " + citrixResourceBase.getHost().getUuid();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
for (final Network.Record network : networks.values()) {
if (network.nameLabel.equals("cloud-private")) {
for (final PIF pif : network.PIFs) {
final PIF.Record pr = pif.getRecord(conn);
if (citrixResourceBase.getHost().getUuid().equals(pr.host.getUuid(conn))) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found a network called cloud-private. host=" + citrixResourceBase.getHost().getUuid() + "; Network=" + network.uuid + "; " + "pif=" + pr.uuid);
}
if (pr.VLAN != null && pr.VLAN != -1) {
final String msg = new StringBuilder("Unsupported configuration. Network cloud-private is on a VLAN. Network=").append(network.uuid).append(" ; pif=").append(pr.uuid).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
if (!pr.management && pr.bondMasterOf != null && pr.bondMasterOf.size() > 0) {
if (pr.bondMasterOf.size() > 1) {
final String msg = new StringBuilder("Unsupported configuration. Network cloud-private has more than one bond. Network=").append(network.uuid).append("; pif=").append(pr.uuid).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
final Bond bond = pr.bondMasterOf.iterator().next();
final Set<PIF> slaves = bond.getSlaves(conn);
for (final PIF slave : slaves) {
final PIF.Record spr = slave.getRecord(conn);
if (spr.management) {
if (!citrixResourceBase.transferManagementNetwork(conn, host, slave, spr, pif)) {
final String msg = new StringBuilder("Unable to transfer management network. slave=" + spr.uuid + "; master=" + pr.uuid + "; host=" + citrixResourceBase.getHost().getUuid()).toString();
s_logger.warn(msg);
return new SetupAnswer(command, msg);
}
break;
}
}
}
}
}
}
}
}
return new SetupAnswer(command, false);
} catch (final XmlRpcException e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
} catch (final XenAPIException e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
} catch (final Exception e) {
s_logger.warn("Unable to setup", e);
return new SetupAnswer(command, e.getMessage());
}
}
Aggregations