Search in sources :

Example 1 with GridClientNodeImpl

use of org.apache.ignite.internal.client.impl.GridClientNodeImpl in project ignite by apache.

the class GridClientNioTcpConnection method nodeBeanToNode.

/**
 * Creates client node instance from message.
 *
 * @param nodeBean Node bean message.
 * @return Created node.
 */
@Nullable
private GridClientNodeImpl nodeBeanToNode(@Nullable GridClientNodeBean nodeBean) {
    if (nodeBean == null)
        return null;
    GridClientNodeImpl.Builder nodeBuilder = GridClientNodeImpl.builder().nodeId(nodeBean.getNodeId()).consistentId(nodeBean.getConsistentId()).tcpAddresses(nodeBean.getTcpAddresses()).tcpPort(nodeBean.getTcpPort()).order(nodeBean.getOrder());
    Map<String, GridClientCacheMode> caches = new HashMap<>();
    if (nodeBean.getCaches() != null) {
        for (GridClientCacheBean cacheBean : nodeBean.getCaches()) {
            try {
                caches.put(cacheBean.getName(), cacheBean.getMode());
            } catch (IllegalArgumentException ignored) {
                log.warning("Invalid cache mode received from remote node (will ignore) [srv=" + serverAddress() + ", cacheName=" + cacheBean.getName() + ", cacheMode=" + cacheBean.getMode() + ']');
            }
        }
    }
    if (!caches.isEmpty())
        nodeBuilder.caches(caches);
    if (nodeBean.getAttributes() != null)
        nodeBuilder.attributes(nodeBean.getAttributes());
    GridClientNodeMetricsBean metricsBean = nodeBean.getMetrics();
    if (metricsBean != null) {
        GridClientNodeMetricsAdapter metrics = new GridClientNodeMetricsAdapter();
        metrics.setStartTime(metricsBean.getStartTime());
        metrics.setAverageActiveJobs(metricsBean.getAverageActiveJobs());
        metrics.setAverageCancelledJobs(metricsBean.getAverageCancelledJobs());
        metrics.setAverageCpuLoad(metricsBean.getAverageCpuLoad());
        metrics.setAverageJobExecuteTime(metricsBean.getAverageJobExecuteTime());
        metrics.setAverageJobWaitTime(metricsBean.getAverageJobWaitTime());
        metrics.setAverageRejectedJobs(metricsBean.getAverageRejectedJobs());
        metrics.setAverageWaitingJobs(metricsBean.getAverageWaitingJobs());
        metrics.setCurrentActiveJobs(metricsBean.getCurrentActiveJobs());
        metrics.setCurrentCancelledJobs(metricsBean.getCurrentCancelledJobs());
        metrics.setCurrentCpuLoad(metricsBean.getCurrentCpuLoad());
        metrics.setCurrentGcCpuLoad(metricsBean.getCurrentGcCpuLoad());
        metrics.setCurrentDaemonThreadCount(metricsBean.getCurrentDaemonThreadCount());
        metrics.setCurrentIdleTime(metricsBean.getCurrentIdleTime());
        metrics.setCurrentJobExecuteTime(metricsBean.getCurrentJobExecuteTime());
        metrics.setCurrentJobWaitTime(metricsBean.getCurrentJobWaitTime());
        metrics.setCurrentRejectedJobs(metricsBean.getCurrentRejectedJobs());
        metrics.setCurrentThreadCount(metricsBean.getCurrentThreadCount());
        metrics.setCurrentWaitingJobs(metricsBean.getCurrentWaitingJobs());
        metrics.setFileSystemFreeSpace(metricsBean.getFileSystemFreeSpace());
        metrics.setFileSystemTotalSpace(metricsBean.getFileSystemTotalSpace());
        metrics.setFileSystemUsableSpace(metricsBean.getFileSystemUsableSpace());
        metrics.setHeapMemoryCommitted(metricsBean.getHeapMemoryCommitted());
        metrics.setHeapMemoryInitialized(metricsBean.getHeapMemoryInitialized());
        metrics.setHeapMemoryMaximum(metricsBean.getHeapMemoryMaximum());
        metrics.setHeapMemoryUsed(metricsBean.getHeapMemoryUsed());
        metrics.setLastDataVersion(metricsBean.getLastDataVersion());
        metrics.setLastUpdateTime(metricsBean.getLastUpdateTime());
        metrics.setMaximumActiveJobs(metricsBean.getMaximumActiveJobs());
        metrics.setMaximumCancelledJobs(metricsBean.getMaximumCancelledJobs());
        metrics.setMaximumJobExecuteTime(metricsBean.getMaximumJobExecuteTime());
        metrics.setMaximumJobWaitTime(metricsBean.getMaximumJobWaitTime());
        metrics.setMaximumRejectedJobs(metricsBean.getMaximumRejectedJobs());
        metrics.setMaximumThreadCount(metricsBean.getMaximumThreadCount());
        metrics.setMaximumWaitingJobs(metricsBean.getMaximumWaitingJobs());
        metrics.setNodeStartTime(metricsBean.getNodeStartTime());
        metrics.setNonHeapMemoryCommitted(metricsBean.getNonHeapMemoryCommitted());
        metrics.setNonHeapMemoryInitialized(metricsBean.getNonHeapMemoryInitialized());
        metrics.setNonHeapMemoryMaximum(metricsBean.getNonHeapMemoryMaximum());
        metrics.setNonHeapMemoryUsed(metricsBean.getNonHeapMemoryUsed());
        metrics.setStartTime(metricsBean.getStartTime());
        metrics.setTotalCancelledJobs(metricsBean.getTotalCancelledJobs());
        metrics.setTotalCpus(metricsBean.getTotalCpus());
        metrics.setTotalExecutedJobs(metricsBean.getTotalExecutedJobs());
        metrics.setTotalIdleTime(metricsBean.getTotalIdleTime());
        metrics.setTotalRejectedJobs(metricsBean.getTotalRejectedJobs());
        metrics.setTotalStartedThreadCount(metricsBean.getTotalStartedThreadCount());
        metrics.setTotalExecutedTasks(metricsBean.getTotalExecutedTasks());
        metrics.setSentMessagesCount(metricsBean.getSentMessagesCount());
        metrics.setSentBytesCount(metricsBean.getSentBytesCount());
        metrics.setReceivedMessagesCount(metricsBean.getReceivedMessagesCount());
        metrics.setReceivedBytesCount(metricsBean.getReceivedBytesCount());
        metrics.setUpTime(metricsBean.getUpTime());
        nodeBuilder.metrics(metrics);
    }
    return nodeBuilder.build();
}
Also used : GridClientNodeMetricsAdapter(org.apache.ignite.internal.client.impl.GridClientNodeMetricsAdapter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GridClientCacheBean(org.apache.ignite.internal.processors.rest.client.message.GridClientCacheBean) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) GridClientCacheMode(org.apache.ignite.internal.client.GridClientCacheMode) GridClientNodeMetricsBean(org.apache.ignite.internal.processors.rest.client.message.GridClientNodeMetricsBean) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GridClientNodeImpl

use of org.apache.ignite.internal.client.impl.GridClientNodeImpl in project ignite by apache.

the class GridClientNioTcpConnection method node.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public GridClientFuture<GridClientNode> node(String ipAddr, boolean inclAttrs, boolean includeMetrics, UUID destNodeId) throws GridClientConnectionResetException, GridClientClosedException {
    GridClientTopologyRequest msg = new GridClientTopologyRequest();
    TcpClientFuture fut = new TcpClientFuture() {

        @Override
        public void onDone(Object res) {
            GridClientNodeImpl node = nodeBeanToNode((GridClientNodeBean) res);
            if (node != null)
                super.onDone(top.updateNode(node));
            else
                super.onDone(node);
        }
    };
    msg.nodeIp(ipAddr);
    setupMessage(inclAttrs, includeMetrics, destNodeId, msg);
    return makeRequest(msg, fut);
}
Also used : GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)

Example 3 with GridClientNodeImpl

use of org.apache.ignite.internal.client.impl.GridClientNodeImpl in project ignite by apache.

the class GridClientNioTcpConnection method topology.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public GridClientFuture<List<GridClientNode>> topology(boolean inclAttrs, boolean inclMetrics, UUID destNodeId) throws GridClientConnectionResetException, GridClientClosedException {
    GridClientTopologyRequest msg = new GridClientTopologyRequest();
    TcpClientFuture fut = new TcpClientFuture() {

        @Override
        public void onDone(Object res) {
            Collection<GridClientNodeBean> beans = (Collection<GridClientNodeBean>) res;
            Collection<GridClientNodeImpl> nodes = new ArrayList<>(beans.size());
            for (GridClientNodeBean bean : beans) nodes.add(nodeBeanToNode(bean));
            super.onDone(top.updateTopology(nodes));
        }
    };
    setupMessage(inclAttrs, inclMetrics, destNodeId, msg);
    return makeRequest(msg, fut);
}
Also used : GridClientNodeBean(org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) ArrayList(java.util.ArrayList) Collection(java.util.Collection) GridClientTopologyRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)

Example 4 with GridClientNodeImpl

use of org.apache.ignite.internal.client.impl.GridClientNodeImpl in project ignite by apache.

the class GridClientTopology method nodeFailed.

/**
 * Updates topology when node that is expected to be in topology fails.
 *
 * @param nodeId Node id for which node failed to be obtained.
 */
public void nodeFailed(UUID nodeId) {
    lock.writeLock().lock();
    try {
        boolean nodeDeleted = nodes.containsKey(nodeId);
        GridClientNode deleted = null;
        // We update the whole topology if node was not in topology or we cache metrics.
        if (nodeDeleted) {
            Map<UUID, GridClientNodeImpl> updatedTop = new HashMap<>(nodes);
            deleted = updatedTop.remove(nodeId);
            // Change the reference to new topology.
            // So everyone who captured old version will see a consistent snapshot.
            nodes = updatedTop;
        }
        if (nodeDeleted)
            notifyEvents(Collections.singletonList(new TopologyEvent(false, deleted)));
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) HashMap(java.util.HashMap) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) UUID(java.util.UUID)

Example 5 with GridClientNodeImpl

use of org.apache.ignite.internal.client.impl.GridClientNodeImpl in project ignite by apache.

the class GridClientTopology method prepareNode.

/**
 * Updates node properties according to current topology settings.
 * Particularly attributes and metrics caching policies.
 *
 * @param node Node to be processed.
 * @return The same node if cache is enabled or node contains no attributes and metrics,
 *      otherwise will return new node without attributes and metrics.
 */
private GridClientNodeImpl prepareNode(final GridClientNodeImpl node) {
    final boolean noAttrsAndMetrics = (metricsCache && attrCache) || (node.attributes().isEmpty() && node.metrics() == null);
    // Try to bypass object copying.
    if (noAttrsAndMetrics && routerAddrs.isEmpty() && node.connectable())
        return node;
    // Return a new node instance based on the original one.
    GridClientNodeImpl.Builder nodeBuilder = GridClientNodeImpl.builder(node, !attrCache, !metricsCache);
    for (InetSocketAddress addr : node.availableAddresses(prot, true)) {
        boolean router = routerAddrs.isEmpty() || routerAddrs.contains(addr);
        boolean reachable = noAttrsAndMetrics || !addr.getAddress().isLoopbackAddress() || F.containsAny(macsCache, node.<String>attribute(ATTR_MACS).split(", "));
        if (router && reachable) {
            nodeBuilder.connectable(true);
            break;
        }
    }
    return nodeBuilder.build();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl)

Aggregations

GridClientNodeImpl (org.apache.ignite.internal.client.impl.GridClientNodeImpl)10 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 GridClientNode (org.apache.ignite.internal.client.GridClientNode)3 GridClientTopologyRequest (org.apache.ignite.internal.processors.rest.client.message.GridClientTopologyRequest)3 LinkedList (java.util.LinkedList)2 GridClientFutureAdapter (org.apache.ignite.internal.client.impl.GridClientFutureAdapter)2 GridClientNodeBean (org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 GridClientCacheMode (org.apache.ignite.internal.client.GridClientCacheMode)1 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)1 GridClientException (org.apache.ignite.internal.client.GridClientException)1 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)1 GridClientNodeMetricsAdapter (org.apache.ignite.internal.client.impl.GridClientNodeMetricsAdapter)1 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)1 GridClientConnectionManager (org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager)1