Search in sources :

Example 1 with ManagementServerHost

use of org.apache.cloudstack.management.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;
            int port = Port.value();
            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));
                ch1.configureBlocking(false);
                ch1.socket().setKeepAlive(true);
                ch1.socket().setSoTimeout(60 * 1000);
                try {
                    SSLContext sslContext = Link.initManagementSSLContext(caService);
                    sslEngine = sslContext.createSSLEngine(ip, port);
                    sslEngine.setUseClientMode(true);
                    sslEngine.setEnabledProtocols(SSLUtils.getSupportedProtocols(sslEngine.getEnabledProtocols()));
                    sslEngine.beginHandshake();
                    if (!Link.doHandshake(ch1, sslEngine)) {
                        ch1.close();
                        throw new IOException(String.format("SSL: Handshake failed with peer management server '%s' on %s:%d ", peerName, ip, port));
                    }
                    s_logger.info(String.format("SSL: Handshake done with peer management server '%s' on %s:%d ", peerName, ip, port));
                } 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) {
                if (ch1 != null) {
                    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(org.apache.cloudstack.management.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 org.apache.cloudstack.management.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(org.apache.cloudstack.management.ManagementServerHost)

Example 3 with ManagementServerHost

use of org.apache.cloudstack.management.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) - mgmtServiceConf.getTimeout();
        _hostDao.markHostsAsDisconnected(vo.getMsid(), lastPing);
        outOfBandManagementDao.expireServerOwnership(vo.getMsid());
        haConfigDao.expireServerOwnership(vo.getMsid());
        s_logger.info("Deleting entries from op_host_transfer table for Management server " + vo.getMsid());
        cleanupTransferMap(vo.getMsid());
    }
}
Also used : ManagementServerHost(org.apache.cloudstack.management.ManagementServerHost)

Aggregations

ManagementServerHost (org.apache.cloudstack.management.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