Search in sources :

Example 6 with ConnectionException

use of com.cloud.exception.ConnectionException 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());
    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 7 with ConnectionException

use of com.cloud.exception.ConnectionException in project cloudstack by apache.

the class NetworkOrchestrator method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    final long hostId = host.getId();
    final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    final String dataCenter = startup.getDataCenter();
    long dcId = -1;
    DataCenterVO dc = _dcDao.findByName(dataCenter);
    if (dc == null) {
        try {
            dcId = Long.parseLong(dataCenter);
            dc = _dcDao.findById(dcId);
        } catch (final NumberFormatException e) {
        }
    }
    if (dc == null) {
        throw new IllegalArgumentException("Host " + startup.getPrivateIpAddress() + " sent incorrect data center: " + dataCenter);
    }
    dcId = dc.getId();
    final HypervisorType hypervisorType = startup.getHypervisorType();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Host's hypervisorType is: " + hypervisorType);
    }
    final List<PhysicalNetworkSetupInfo> networkInfoList = new ArrayList<PhysicalNetworkSetupInfo>();
    // list all physicalnetworks in the zone & for each get the network names
    final List<PhysicalNetworkVO> physicalNtwkList = _physicalNetworkDao.listByZone(dcId);
    for (final PhysicalNetworkVO pNtwk : physicalNtwkList) {
        final String publicName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Public, hypervisorType);
        final String privateName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Management, hypervisorType);
        final String guestName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Guest, hypervisorType);
        final String storageName = _pNTrafficTypeDao.getNetworkTag(pNtwk.getId(), TrafficType.Storage, hypervisorType);
        // String controlName = _pNTrafficTypeDao._networkModel.getNetworkTag(pNtwk.getId(), TrafficType.Control, hypervisorType);
        final PhysicalNetworkSetupInfo info = new PhysicalNetworkSetupInfo();
        info.setPhysicalNetworkId(pNtwk.getId());
        info.setGuestNetworkName(guestName);
        info.setPrivateNetworkName(privateName);
        info.setPublicNetworkName(publicName);
        info.setStorageNetworkName(storageName);
        final PhysicalNetworkTrafficTypeVO mgmtTraffic = _pNTrafficTypeDao.findBy(pNtwk.getId(), TrafficType.Management);
        if (mgmtTraffic != null) {
            final String vlan = mgmtTraffic.getVlan();
            info.setMgmtVlan(vlan);
        }
        networkInfoList.add(info);
    }
    // send the names to the agent
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Sending CheckNetworkCommand to check the Network is setup correctly on Agent");
    }
    final CheckNetworkCommand nwCmd = new CheckNetworkCommand(networkInfoList);
    final CheckNetworkAnswer answer = (CheckNetworkAnswer) _agentMgr.easySend(hostId, nwCmd);
    if (answer == null) {
        s_logger.warn("Unable to get an answer to the CheckNetworkCommand from agent:" + host.getId());
        throw new ConnectionException(true, "Unable to get an answer to the CheckNetworkCommand from agent: " + host.getId());
    }
    if (!answer.getResult()) {
        s_logger.warn("Unable to setup agent " + hostId + " due to " + answer.getDetails());
        final String msg = "Incorrect Network setup on agent, Reinitialize agent after network names are setup, details : " + answer.getDetails();
        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, host.getPodId(), msg, msg);
        throw new ConnectionException(true, msg);
    } else {
        if (answer.needReconnect()) {
            throw new ConnectionException(false, "Reinitialize agent after network setup.");
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Network setup is correct on Agent");
        }
        return;
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException) PhysicalNetworkSetupInfo(com.cloud.network.PhysicalNetworkSetupInfo)

Example 8 with ConnectionException

use of com.cloud.exception.ConnectionException in project cloudstack by apache.

the class AgentManagerImplTest method testNotifyMonitorsOfConnectionWhenStoragePoolConnectionHostFailure.

@Test
public void testNotifyMonitorsOfConnectionWhenStoragePoolConnectionHostFailure() throws ConnectionException {
    ConnectionException connectionException = new ConnectionException(true, "storage pool could not be connected on host");
    Mockito.when(hostDao.findById(Mockito.anyLong())).thenReturn(host);
    Mockito.doThrow(connectionException).when(storagePoolMonitor).processConnect(Mockito.eq(host), Mockito.eq(cmds[0]), Mockito.eq(false));
    Mockito.doReturn(true).when(mgr).handleDisconnectWithoutInvestigation(Mockito.any(attache.getClass()), Mockito.any(Status.Event.class), Mockito.anyBoolean(), Mockito.anyBoolean());
    try {
        mgr.notifyMonitorsOfConnection(attache, cmds, false);
        Assert.fail("Connection Exception was expected");
    } catch (ConnectionException e) {
        Assert.assertEquals(e.getMessage(), connectionException.getMessage());
    }
    Mockito.verify(mgr, Mockito.times(1)).handleDisconnectWithoutInvestigation(Mockito.any(attache.getClass()), Mockito.eq(Status.Event.AgentDisconnected), Mockito.eq(true), Mockito.eq(true));
}
Also used : ConnectionException(com.cloud.exception.ConnectionException) Test(org.junit.Test)

Example 9 with ConnectionException

use of com.cloud.exception.ConnectionException in project cloudstack by apache.

the class DownloadListener method processConnect.

@Override
public void processConnect(Host agent, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
    if (cmd instanceof StartupRoutingCommand) {
        List<HypervisorType> hypers = _resourceMgr.listAvailHypervisorInZone(agent.getId(), agent.getDataCenterId());
        HypervisorType hostHyper = agent.getHypervisorType();
        if (hypers.contains(hostHyper)) {
            return;
        }
        _imageSrv.handleSysTemplateDownload(hostHyper, agent.getDataCenterId());
        // update template_zone_ref for cross-zone templates
        _imageSrv.associateCrosszoneTemplatesToZone(agent.getDataCenterId());
    } else /* This can be removed
        else if ( cmd instanceof StartupStorageCommand) {
            StartupStorageCommand storage = (StartupStorageCommand)cmd;
            if( storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE ||
                    storage.getResourceType() == Storage.StorageResourceType.LOCAL_SECONDARY_STORAGE  ) {
                downloadMonitor.addSystemVMTemplatesToHost(agent, storage.getTemplateInfo());
                downloadMonitor.handleTemplateSync(agent);
                downloadMonitor.handleVolumeSync(agent);
            }
        }*/
    if (cmd instanceof StartupSecondaryStorageCommand) {
        try {
            List<DataStore> imageStores = _storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId()));
            for (DataStore store : imageStores) {
                _volumeSrv.handleVolumeSync(store);
                _imageSrv.handleTemplateSync(store);
            }
        } catch (Exception e) {
            s_logger.error("Caught exception while doing template/volume sync ", e);
        }
    }
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) List(java.util.List) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

ConnectionException (com.cloud.exception.ConnectionException)9 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)5 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 HostVO (com.cloud.host.HostVO)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 Answer (com.cloud.agent.api.Answer)2 SetupAnswer (com.cloud.agent.api.SetupAnswer)2 SetupCommand (com.cloud.agent.api.SetupCommand)2 ClusterVO (com.cloud.dc.ClusterVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 HostEnvironment (com.cloud.host.HostEnvironment)2 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)2 HypervisorVersionChangedException (com.cloud.utils.exception.HypervisorVersionChangedException)2 ConfigurationException (javax.naming.ConfigurationException)2 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)2 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)2 Listener (com.cloud.agent.Listener)1