Search in sources :

Example 1 with HypervisorVersionChangedException

use of com.cloud.legacymodel.exceptions.HypervisorVersionChangedException in project cosmic by MissionCriticalCloud.

the class XcpServerDiscoverer method processConnect.

@Override
public void processConnect(final com.cloud.legacymodel.dc.Host agent, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
    for (final StartupCommand startupCommand : startupCommands) {
        if (!(startupCommand instanceof StartupRoutingCommand)) {
            return;
        }
        final long agentId = agent.getId();
        final StartupRoutingCommand startup = (StartupRoutingCommand) startupCommand;
        if (startup.getHypervisorType() != HypervisorType.XenServer) {
            s_logger.debug("Not XenServer so moving on.");
            return;
        }
        final HostVO host = this._hostDao.findById(agentId);
        final ClusterVO cluster = this._clusterDao.findById(host.getClusterId());
        if (cluster.getGuid() == null) {
            cluster.setGuid(startup.getPool());
            this._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);
            this._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 (this._setupMultipath) {
            setup.setMultipathOn();
        }
        if (!host.isSetup()) {
            setup.setNeedSetup(true);
        }
        try {
            final Answer answer = this._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);
                this._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.legacymodel.exceptions.OperationTimedoutException) ClusterVO(com.cloud.dc.ClusterVO) HostEnvironment(com.cloud.legacymodel.dc.HostEnvironment) SetupCommand(com.cloud.legacymodel.communication.command.SetupCommand) HostVO(com.cloud.host.HostVO) SetupAnswer(com.cloud.legacymodel.communication.answer.SetupAnswer) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) HypervisorVersionChangedException(com.cloud.legacymodel.exceptions.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) SetupAnswer(com.cloud.legacymodel.communication.answer.SetupAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException)

Example 2 with HypervisorVersionChangedException

use of com.cloud.legacymodel.exceptions.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 = this._hostDao.findById(hostId);
    for (final Pair<Integer, Listener> monitor : this._hostMonitors) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName());
        }
        try {
            monitor.second().processConnect(host, cmd, 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, this._nodeId);
    attache.ready();
    return attache;
}
Also used : HypervisorVersionChangedException(com.cloud.legacymodel.exceptions.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) PingAnswer(com.cloud.legacymodel.communication.answer.PingAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) Listener(com.cloud.agent.Listener) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) HostVO(com.cloud.host.HostVO) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) UnsupportedVersionException(com.cloud.legacymodel.exceptions.UnsupportedVersionException) HypervisorVersionChangedException(com.cloud.legacymodel.exceptions.HypervisorVersionChangedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ConfigurationException(javax.naming.ConfigurationException) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) TaskExecutionException(com.cloud.legacymodel.exceptions.TaskExecutionException) ClosedChannelException(java.nio.channels.ClosedChannelException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NioConnectionException(com.cloud.legacymodel.exceptions.NioConnectionException) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) NioConnectionException(com.cloud.legacymodel.exceptions.NioConnectionException)

Aggregations

HostVO (com.cloud.host.HostVO)2 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)2 Answer (com.cloud.legacymodel.communication.answer.Answer)2 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)2 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)2 ConnectionException (com.cloud.legacymodel.exceptions.ConnectionException)2 HypervisorVersionChangedException (com.cloud.legacymodel.exceptions.HypervisorVersionChangedException)2 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)2 Listener (com.cloud.agent.Listener)1 ClusterVO (com.cloud.dc.ClusterVO)1 PingAnswer (com.cloud.legacymodel.communication.answer.PingAnswer)1 ReadyAnswer (com.cloud.legacymodel.communication.answer.ReadyAnswer)1 SetupAnswer (com.cloud.legacymodel.communication.answer.SetupAnswer)1 StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)1 UnsupportedAnswer (com.cloud.legacymodel.communication.answer.UnsupportedAnswer)1 ReadyCommand (com.cloud.legacymodel.communication.command.ReadyCommand)1 SetupCommand (com.cloud.legacymodel.communication.command.SetupCommand)1 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)1 StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)1 HostEnvironment (com.cloud.legacymodel.dc.HostEnvironment)1