Search in sources :

Example 6 with ConnectionException

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

the class StoragePoolMonitor method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand[] startupCommands, final boolean forRebalance) throws ConnectionException {
    for (final StartupCommand startupCommand : startupCommands) {
        if (startupCommand instanceof StartupRoutingCommand) {
            final StartupRoutingCommand scCmd = (StartupRoutingCommand) startupCommand;
            if (scCmd.getHypervisorType() == HypervisorType.XenServer || scCmd.getHypervisorType() == HypervisorType.KVM) {
                final List<StoragePoolVO> pools = _poolDao.listBy(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER);
                final List<StoragePoolVO> zoneStoragePoolsByTags = _poolDao.findZoneWideStoragePoolsByTags(host.getDataCenterId(), null);
                final List<StoragePoolVO> zoneStoragePoolsByHypervisor = _poolDao.findZoneWideStoragePoolsByHypervisor(host.getDataCenterId(), scCmd.getHypervisorType());
                zoneStoragePoolsByTags.retainAll(zoneStoragePoolsByHypervisor);
                pools.addAll(zoneStoragePoolsByTags);
                final List<StoragePoolVO> zoneStoragePoolsByAnyHypervisor = _poolDao.findZoneWideStoragePoolsByHypervisor(host.getDataCenterId(), HypervisorType.Any);
                pools.addAll(zoneStoragePoolsByAnyHypervisor);
                for (final StoragePoolVO pool : pools) {
                    if (pool.getStatus() != StoragePoolStatus.Up) {
                        continue;
                    }
                    if (!pool.isShared()) {
                        continue;
                    }
                    if (pool.getPoolType() == StoragePoolType.OCFS2 && !_ocfs2Mgr.prepareNodes(pool.getClusterId())) {
                        throw new ConnectionException(true, "Unable to prepare OCFS2 nodes for pool " + pool.getId());
                    }
                    final Long hostId = host.getId();
                    s_logger.debug("Host " + hostId + " connected, connecting host to shared pool id " + pool.getId() + " and sending storage pool information ...");
                    try {
                        _storageManager.connectHostToSharedPool(hostId, pool.getId());
                        _storageManager.createCapacityEntry(pool.getId());
                    } catch (final Exception e) {
                        throw new ConnectionException(true, "Unable to connect host " + hostId + " to storage pool id " + pool.getId() + " due to " + e.toString(), e);
                    }
                }
            }
        }
    }
}
Also used : StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException)

Example 7 with ConnectionException

use of com.cloud.legacymodel.exceptions.ConnectionException 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

ConnectionException (com.cloud.legacymodel.exceptions.ConnectionException)7 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)3 StartupRoutingCommand (com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand)3 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)3 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)3 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)3 HostVO (com.cloud.host.HostVO)2 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)2 Answer (com.cloud.legacymodel.communication.answer.Answer)2 HypervisorVersionChangedException (com.cloud.legacymodel.exceptions.HypervisorVersionChangedException)2 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)2 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)2 ConfigurationException (javax.naming.ConfigurationException)2 Listener (com.cloud.agent.Listener)1 Zone (com.cloud.db.model.Zone)1 ClusterVO (com.cloud.dc.ClusterVO)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)1 DataStoreLifeCycle (com.cloud.engine.subsystem.api.storage.DataStoreLifeCycle)1 DataStoreProvider (com.cloud.engine.subsystem.api.storage.DataStoreProvider)1