Search in sources :

Example 1 with ManagementServerHost

use of com.cloud.cluster.ManagementServerHost in project cloudstack by apache.

the class ClusteredAgentManagerImpl method connectToPeer.

public SocketChannel connectToPeer(final String peerName, final SocketChannel prevCh) {
    synchronized (_peers) {
        final SocketChannel ch = _peers.get(peerName);
        SSLEngine sslEngine = null;
        if (prevCh != null) {
            try {
                prevCh.close();
            } catch (final Exception e) {
                s_logger.info("[ignored]" + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage());
            }
        }
        if (ch == null || ch == prevCh) {
            final ManagementServerHost ms = _clusterMgr.getPeer(peerName);
            if (ms == null) {
                s_logger.info("Unable to find peer: " + peerName);
                return null;
            }
            final String ip = ms.getServiceIP();
            InetAddress addr;
            try {
                addr = InetAddress.getByName(ip);
            } catch (final UnknownHostException e) {
                throw new CloudRuntimeException("Unable to resolve " + ip);
            }
            SocketChannel ch1 = null;
            try {
                ch1 = SocketChannel.open(new InetSocketAddress(addr, Port.value()));
                ch1.configureBlocking(false);
                ch1.socket().setKeepAlive(true);
                ch1.socket().setSoTimeout(60 * 1000);
                try {
                    final SSLContext sslContext = Link.initSSLContext(true);
                    sslEngine = sslContext.createSSLEngine(ip, Port.value());
                    sslEngine.setUseClientMode(true);
                    sslEngine.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslEngine.getEnabledProtocols()));
                    sslEngine.beginHandshake();
                    if (!Link.doHandshake(ch1, sslEngine, true)) {
                        ch1.close();
                        throw new IOException("SSL handshake failed!");
                    }
                    s_logger.info("SSL: Handshake done");
                } catch (final Exception e) {
                    ch1.close();
                    throw new IOException("SSL: Fail to init SSL! " + e);
                }
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Connection to peer opened: " + peerName + ", ip: " + ip);
                }
                _peers.put(peerName, ch1);
                _sslEngines.put(peerName, sslEngine);
                return ch1;
            } catch (final IOException e) {
                try {
                    ch1.close();
                } catch (final IOException ex) {
                    s_logger.error("failed to close failed peer socket: " + ex);
                }
                s_logger.warn("Unable to connect to peer management server: " + peerName + ", ip: " + ip + " due to " + e.getMessage(), e);
                return null;
            }
        }
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Found open channel for peer: " + peerName);
        }
        return ch;
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) UnknownHostException(java.net.UnknownHostException) SSLEngine(javax.net.ssl.SSLEngine) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InetSocketAddress(java.net.InetSocketAddress) ManagementServerHost(com.cloud.cluster.ManagementServerHost) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) InetAddress(java.net.InetAddress) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) TaskExecutionException(com.cloud.utils.exception.TaskExecutionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedVersionException(com.cloud.exception.UnsupportedVersionException)

Example 2 with ManagementServerHost

use of com.cloud.cluster.ManagementServerHost in project cloudstack by apache.

the class StorageManagerImpl method onManagementNodeLeft.

@Override
public void onManagementNodeLeft(List<? extends ManagementServerHost> nodeList, long selfNodeId) {
    for (ManagementServerHost vo : nodeList) {
        if (vo.getMsid() == _serverId) {
            s_logger.info("Cleaning up storage maintenance jobs associated with Management server: " + vo.getMsid());
            List<Long> poolIds = _storagePoolWorkDao.searchForPoolIdsForPendingWorkJobs(vo.getMsid());
            if (poolIds.size() > 0) {
                for (Long poolId : poolIds) {
                    StoragePoolVO pool = _storagePoolDao.findById(poolId);
                    // check if pool is in an inconsistent state
                    if (pool != null && (pool.getStatus().equals(StoragePoolStatus.ErrorInMaintenance) || pool.getStatus().equals(StoragePoolStatus.PrepareForMaintenance) || pool.getStatus().equals(StoragePoolStatus.CancelMaintenance))) {
                        _storagePoolWorkDao.removePendingJobsOnMsRestart(vo.getMsid(), poolId);
                        pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
                        _storagePoolDao.update(poolId, pool);
                    }
                }
            }
        }
    }
}
Also used : StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ManagementServerHost(com.cloud.cluster.ManagementServerHost)

Example 3 with ManagementServerHost

use of com.cloud.cluster.ManagementServerHost in project cloudstack by apache.

the class ClusteredAgentManagerImpl method onManagementNodeLeft.

@Override
public void onManagementNodeLeft(final List<? extends ManagementServerHost> nodeList, final long selfNodeId) {
    for (final ManagementServerHost vo : nodeList) {
        s_logger.info("Marking hosts as disconnected on Management server" + vo.getMsid());
        final long lastPing = (System.currentTimeMillis() >> 10) - getTimeout();
        _hostDao.markHostsAsDisconnected(vo.getMsid(), lastPing);
        outOfBandManagementDao.expireOutOfBandManagementOwnershipByServer(vo.getMsid());
        s_logger.info("Deleting entries from op_host_transfer table for Management server " + vo.getMsid());
        cleanupTransferMap(vo.getMsid());
    }
}
Also used : ManagementServerHost(com.cloud.cluster.ManagementServerHost)

Aggregations

ManagementServerHost (com.cloud.cluster.ManagementServerHost)3 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 UnsupportedVersionException (com.cloud.exception.UnsupportedVersionException)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 TaskExecutionException (com.cloud.utils.exception.TaskExecutionException)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 SocketChannel (java.nio.channels.SocketChannel)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ConfigurationException (javax.naming.ConfigurationException)1 SSLContext (javax.net.ssl.SSLContext)1 SSLEngine (javax.net.ssl.SSLEngine)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1