Prevent a ClassCastException when the answer is not a SetupAnswer (which happends when something goes wrong while connecting)
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/24309f60 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/24309f60 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/24309f60 Branch: refs/heads/ui-restyle Commit: 24309f600157327b5af2cdf2e156d80dea412ff3 Parents: f113984 Author: Hugo Trippaers <htrippa...@schubergphilis.com> Authored: Tue Feb 18 12:37:36 2014 +0100 Committer: Hugo Trippaers <htrippa...@schubergphilis.com> Committed: Tue Feb 18 12:37:36 2014 +0100 ---------------------------------------------------------------------- .../xen/discoverer/XcpServerDiscoverer.java | 35 ++++++++++---------- 1 file changed, 18 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/24309f60/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index 58fe015..fbfd222 100755 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -34,6 +34,13 @@ import javax.persistence.EntityExistsException; import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; +import com.xensource.xenapi.Connection; +import com.xensource.xenapi.Host; +import com.xensource.xenapi.Pool; +import com.xensource.xenapi.Session; +import com.xensource.xenapi.Types.SessionAuthenticationFailed; +import com.xensource.xenapi.Types.XenAPIException; + import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; import com.cloud.agent.api.AgentControlAnswer; @@ -92,12 +99,6 @@ import com.cloud.utils.db.QueryBuilder; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.HypervisorVersionChangedException; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Host; -import com.xensource.xenapi.Pool; -import com.xensource.xenapi.Session; -import com.xensource.xenapi.Types.SessionAuthenticationFailed; -import com.xensource.xenapi.Types.XenAPIException; @Local(value = Discoverer.class) public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter { @@ -157,7 +158,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L @Override public Map<? extends ServerResource, Map<String, String>> - find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException { + find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException { Map<CitrixResourceBase, Map<String, String>> resources = new HashMap<CitrixResourceBase, Map<String, String>>(); Connection conn = null; if (!url.getScheme().equals("http")) { @@ -486,8 +487,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L } String msg = - "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, XenServer 5.6 FP1, XenServer 5.6 SP2, Xenserver 6.0, 6.0.2, 6.1.0, 6.2.0 but this one is " + - prodBrand + " " + prodVersion; + "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, XenServer 5.6 FP1, XenServer 5.6 SP2, Xenserver 6.0, 6.0.2, 6.1.0, 6.2.0 but this one is " + + prodBrand + " " + prodVersion; _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, msg, msg); s_logger.debug(msg); throw new RuntimeException(msg); @@ -574,8 +575,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L if (tmplt == null) { id = _tmpltDao.getNextInSequence(Long.class, "id"); VMTemplateVO template = - VMTemplateVO.createPreHostIso(id, isoName, isoName, ImageFormat.ISO, true, true, TemplateType.PERHOST, null, null, true, 64, Account.ACCOUNT_ID_SYSTEM, - null, "xen-pv-drv-iso", false, 1, false, HypervisorType.XenServer); + VMTemplateVO.createPreHostIso(id, isoName, isoName, ImageFormat.ISO, true, true, TemplateType.PERHOST, null, null, true, 64, Account.ACCOUNT_ID_SYSTEM, + null, "xen-pv-drv-iso", false, 1, false, HypervisorType.XenServer); _tmpltDao.persist(template); } else { id = tmplt.getId(); @@ -646,8 +647,8 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L if (resource == null) { String msg = - "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, 5.6 FP1, 5.6 SP2 and Xenserver 6.0 , 6.0.2, 6.1.0, 6.2.0 but this one is " + - prodBrand + " " + prodVersion; + "Only support XCP 1.0.0, 1.1.0, 1.4.x, 1.5 beta, 1.6.x; XenServer 5.6, 5.6 FP1, 5.6 SP2 and Xenserver 6.0 , 6.0.2, 6.1.0, 6.2.0 but this one is " + + prodBrand + " " + prodVersion; s_logger.debug(msg); throw new RuntimeException(msg); } @@ -674,12 +675,12 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L } try { - SetupAnswer answer = (SetupAnswer)_agentMgr.send(agentId, setup); - if (answer != null && answer.getResult()) { + Answer answer = _agentMgr.send(agentId, setup); + if (answer != null && answer.getResult() && answer instanceof SetupAnswer) { host.setSetup(true); host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60); _hostDao.update(host.getId(), host); - if (answer.needReconnect()) { + if (((SetupAnswer)answer).needReconnect()) { throw new ConnectionException(false, "Reinitialize agent after setup."); } return; @@ -763,7 +764,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L } if (!success) { String msg = - "Unable to eject host " + host.getGuid() + " due to there is no host up in this cluster, please execute xe pool-eject host-uuid=" + host.getGuid() + + "Unable to eject host " + host.getGuid() + " due to there is no host up in this cluster, please execute xe pool-eject host-uuid=" + host.getGuid() + "in this host " + host.getPrivateIpAddress(); s_logger.warn(msg); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Unable to eject host " + host.getGuid(), msg);