Search in sources :

Example 1 with HypervisorVersionChangedException

use of com.cloud.utils.exception.HypervisorVersionChangedException 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.");
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ClusterVO(com.cloud.dc.ClusterVO) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) SetupAnswer(com.cloud.agent.api.SetupAnswer) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) SetupAnswer(com.cloud.agent.api.SetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException)

Example 2 with HypervisorVersionChangedException

use of com.cloud.utils.exception.HypervisorVersionChangedException in project cosmic by MissionCriticalCloud.

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;
}
Also used : Listener(com.cloud.agent.Listener) HostVO(com.cloud.host.HostVO) ConnectionException(com.cloud.exception.ConnectionException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TaskExecutionException(com.cloud.utils.exception.TaskExecutionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClosedChannelException(java.nio.channels.ClosedChannelException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) NioConnectionException(com.cloud.utils.exception.NioConnectionException) UnsupportedVersionException(com.cloud.exception.UnsupportedVersionException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) PingAnswer(com.cloud.agent.api.PingAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) ReadyCommand(com.cloud.agent.api.ReadyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConnectionException(com.cloud.exception.ConnectionException) NioConnectionException(com.cloud.utils.exception.NioConnectionException)

Example 3 with HypervisorVersionChangedException

use of com.cloud.utils.exception.HypervisorVersionChangedException 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.");
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ClusterVO(com.cloud.dc.ClusterVO) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) SetupAnswer(com.cloud.agent.api.SetupAnswer) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) SetupAnswer(com.cloud.agent.api.SetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException)

Example 4 with HypervisorVersionChangedException

use of com.cloud.utils.exception.HypervisorVersionChangedException 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(), NumbersUtil.enableHumanReadableSizes);
    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;
}
Also used : Listener(com.cloud.agent.Listener) HostVO(com.cloud.host.HostVO) ConnectionException(com.cloud.exception.ConnectionException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TaskExecutionException(com.cloud.utils.exception.TaskExecutionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClosedChannelException(java.nio.channels.ClosedChannelException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) NioConnectionException(com.cloud.utils.exception.NioConnectionException) UnsupportedVersionException(com.cloud.exception.UnsupportedVersionException) ConfigurationException(javax.naming.ConfigurationException) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) PingAnswer(com.cloud.agent.api.PingAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) ReadyCommand(com.cloud.agent.api.ReadyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConnectionException(com.cloud.exception.ConnectionException) NioConnectionException(com.cloud.utils.exception.NioConnectionException)

Aggregations

AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)4 Answer (com.cloud.agent.api.Answer)4 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4 ConnectionException (com.cloud.exception.ConnectionException)4 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)4 HostVO (com.cloud.host.HostVO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 HypervisorVersionChangedException (com.cloud.utils.exception.HypervisorVersionChangedException)4 Listener (com.cloud.agent.Listener)2 PingAnswer (com.cloud.agent.api.PingAnswer)2 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)2 ReadyCommand (com.cloud.agent.api.ReadyCommand)2 SetupAnswer (com.cloud.agent.api.SetupAnswer)2 SetupCommand (com.cloud.agent.api.SetupCommand)2 StartupAnswer (com.cloud.agent.api.StartupAnswer)2 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)2 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)2 ClusterVO (com.cloud.dc.ClusterVO)2 UnsupportedVersionException (com.cloud.exception.UnsupportedVersionException)2 HostEnvironment (com.cloud.host.HostEnvironment)2