Search in sources :

Example 1 with ConnectionException

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

the class VirtualNetworkApplianceManagerImpl method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    final List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(host.getId());
    for (DomainRouterVO router : routers) {
        if (router.isStopPending()) {
            s_logger.info("Stopping router " + router.getInstanceName() + " due to stop pending flag found!");
            final VirtualMachine.State state = router.getState();
            if (state != VirtualMachine.State.Stopped && state != VirtualMachine.State.Destroyed) {
                try {
                    stopRouter(router.getId(), false);
                } catch (final ResourceUnavailableException e) {
                    s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
                    throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
                } catch (final ConcurrentOperationException e) {
                    s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
                    throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
                }
            }
            router.setStopPending(false);
            router = _routerDao.persist(router);
        }
    }
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) DomainRouterVO(com.cloud.vm.DomainRouterVO) ConnectionException(com.cloud.exception.ConnectionException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 2 with ConnectionException

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

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

the class HypervServerDiscoverer method processConnect.

@Override
public final void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    // Limit the commands we can process
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    // assert
    if (startup.getHypervisorType() != HypervisorType.Hyperv) {
        s_logger.debug("Not Hyper-V hypervisor, so moving on.");
        return;
    }
    long agentId = agent.getId();
    HostVO host = _hostDao.findById(agentId);
    // Our Hyper-V machines are not participating in pools, and the pool id
    // we provide them is not persisted.
    // This means the pool id can vary.
    ClusterVO cluster = _clusterDao.findById(host.getClusterId());
    if (cluster.getGuid() == null) {
        cluster.setGuid(startup.getPool());
        _clusterDao.update(cluster.getId(), cluster);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting up host " + agentId);
    }
    HostEnvironment env = new HostEnvironment();
    SetupCommand setup = new SetupCommand(env);
    if (!host.isSetup()) {
        setup.setNeedSetup(true);
    }
    try {
        SetupAnswer answer = (SetupAnswer) _agentMgr.send(agentId, setup);
        if (answer != null && answer.getResult()) {
            host.setSetup(true);
            // TODO: clean up magic numbers below
            host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
            _hostDao.update(host.getId(), host);
            if (answer.needReconnect()) {
                throw new ConnectionException(false, "Reinitialize agent after setup.");
            }
            return;
        } else {
            String reason = answer.getDetails();
            if (reason == null) {
                reason = " details were null";
            }
            s_logger.warn("Unable to setup agent " + agentId + " due to " + reason);
        }
    // Error handling borrowed from XcpServerDiscoverer, may need to be
    // updated.
    } 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) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) ConnectionException(com.cloud.exception.ConnectionException) SetupAnswer(com.cloud.agent.api.SetupAnswer)

Example 4 with ConnectionException

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

the class StorageManagerImpl method createLocalStorage.

@DB
@Override
public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws ConnectionException {
    DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    if (dc == null) {
        return null;
    }
    boolean useLocalStorageForSystemVM = false;
    Boolean isLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dc.getId());
    if (isLocal != null) {
        useLocalStorageForSystemVM = isLocal.booleanValue();
    }
    if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
        return null;
    }
    DataStore store;
    try {
        String hostAddress = pInfo.getHost();
        if (host.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
            hostAddress = "VMFS datastore: " + pInfo.getHostPath();
        }
        StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, pInfo.getHostPath(), pInfo.getUuid());
        if (pool == null && host.getHypervisorType() == HypervisorType.VMware) {
            // need to perform runtime upgrade here
            if (pInfo.getHostPath().length() > 0) {
                pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, "", pInfo.getUuid());
            }
        }
        if (pool == null) {
            //the path can be different, but if they have the same uuid, assume they are the same storage
            pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, null, pInfo.getUuid());
            if (pool != null) {
                s_logger.debug("Found a storage pool: " + pInfo.getUuid() + ", but with different hostpath " + pInfo.getHostPath() + ", still treat it as the same pool");
            }
        }
        DataStoreProvider provider = _dataStoreProviderMgr.getDefaultPrimaryDataStoreProvider();
        DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
        if (pool == null) {
            Map<String, Object> params = new HashMap<String, Object>();
            String name = (host.getName() + " Local Storage");
            params.put("zoneId", host.getDataCenterId());
            params.put("clusterId", host.getClusterId());
            params.put("podId", host.getPodId());
            params.put("url", pInfo.getPoolType().toString() + "://" + pInfo.getHost() + "/" + pInfo.getHostPath());
            params.put("name", name);
            params.put("localStorage", true);
            params.put("details", pInfo.getDetails());
            params.put("uuid", pInfo.getUuid());
            params.put("providerName", provider.getName());
            store = lifeCycle.initialize(params);
        } else {
            store = _dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
        }
        pool = _storagePoolDao.findById(store.getId());
        if (pool.getStatus() != StoragePoolStatus.Maintenance && pool.getStatus() != StoragePoolStatus.Removed) {
            HostScope scope = new HostScope(host.getId(), host.getClusterId(), host.getDataCenterId());
            lifeCycle.attachHost(store, scope, pInfo);
        }
    } catch (Exception e) {
        s_logger.warn("Unable to setup the local storage pool for " + host, e);
        throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e);
    }
    return _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) HostScope(org.apache.cloudstack.engine.subsystem.api.storage.HostScope) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) StorageConflictException(com.cloud.exception.StorageConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ConnectionException(com.cloud.exception.ConnectionException) DB(com.cloud.utils.db.DB)

Example 5 with ConnectionException

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

the class StoragePoolMonitor method processConnect.

@Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
    if (cmd instanceof StartupRoutingCommand) {
        StartupRoutingCommand scCmd = (StartupRoutingCommand) cmd;
        if (scCmd.getHypervisorType() == HypervisorType.XenServer || scCmd.getHypervisorType() == HypervisorType.KVM || scCmd.getHypervisorType() == HypervisorType.VMware || scCmd.getHypervisorType() == HypervisorType.Simulator || scCmd.getHypervisorType() == HypervisorType.Ovm || scCmd.getHypervisorType() == HypervisorType.Hyperv || scCmd.getHypervisorType() == HypervisorType.LXC || scCmd.getHypervisorType() == HypervisorType.Ovm3) {
            List<StoragePoolVO> pools = _poolDao.listBy(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER);
            List<StoragePoolVO> zoneStoragePoolsByTags = _poolDao.findZoneWideStoragePoolsByTags(host.getDataCenterId(), null);
            List<StoragePoolVO> zoneStoragePoolsByHypervisor = _poolDao.findZoneWideStoragePoolsByHypervisor(host.getDataCenterId(), scCmd.getHypervisorType());
            zoneStoragePoolsByTags.retainAll(zoneStoragePoolsByHypervisor);
            pools.addAll(zoneStoragePoolsByTags);
            List<StoragePoolVO> zoneStoragePoolsByAnyHypervisor = _poolDao.findZoneWideStoragePoolsByHypervisor(host.getDataCenterId(), HypervisorType.Any);
            pools.addAll(zoneStoragePoolsByAnyHypervisor);
            for (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());
                }
                Long hostId = host.getId();
                if (s_logger.isDebugEnabled()) {
                    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 (Exception e) {
                    throw new ConnectionException(true, "Unable to connect host " + hostId + " to storage pool id " + pool.getId() + " due to " + e.toString(), e);
                }
            }
        }
    }
}
Also used : StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException) ConnectionException(com.cloud.exception.ConnectionException)

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