Search in sources :

Example 1 with GridClientCacheMode

use of org.apache.ignite.internal.client.GridClientCacheMode 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());
    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 GridClientCacheMode

use of org.apache.ignite.internal.client.GridClientCacheMode in project ignite by apache.

the class GridClientImpl method tryInitTopology.

/**
     * Tries to init client topology using configured set of servers or routers.
     *
     * @throws GridClientException If initialisation failed.
     * @throws InterruptedException If initialisation was interrupted.
     */
private void tryInitTopology() throws GridClientException, InterruptedException {
    boolean hasSrvs = routers.isEmpty();
    final Collection<InetSocketAddress> connSrvs = (hasSrvs) ? new LinkedHashSet<>(srvs) : routers;
    if (hasSrvs) {
        // Add REST endpoints for all nodes from previous topology snapshot.
        try {
            for (GridClientNodeImpl node : top.nodes()) {
                Collection<InetSocketAddress> endpoints = node.availableAddresses(cfg.getProtocol(), true);
                List<InetSocketAddress> resolvedEndpoints = new ArrayList<>(endpoints.size());
                for (InetSocketAddress endpoint : endpoints) if (!endpoint.isUnresolved())
                    resolvedEndpoints.add(endpoint);
                boolean sameHost = node.attributes().isEmpty() || F.containsAny(U.allLocalMACs(), node.attribute(ATTR_MACS).toString().split(", "));
                if (sameHost) {
                    Collections.sort(resolvedEndpoints, U.inetAddressesComparator(true));
                    connSrvs.addAll(resolvedEndpoints);
                } else {
                    for (InetSocketAddress endpoint : resolvedEndpoints) if (!endpoint.getAddress().isLoopbackAddress())
                        connSrvs.add(endpoint);
                }
            }
        } catch (GridClientDisconnectedException ignored) {
        // Ignore if latest topology update failed.
        }
    }
    connMgr.init(connSrvs);
    Map<String, GridClientCacheMode> overallCaches = new HashMap<>();
    for (GridClientNodeImpl node : top.nodes()) overallCaches.putAll(node.caches());
    for (Map.Entry<String, GridClientCacheMode> entry : overallCaches.entrySet()) {
        GridClientDataAffinity affinity = affinity(entry.getKey());
        if (affinity instanceof GridClientPartitionAffinity && entry.getValue() != GridClientCacheMode.PARTITIONED)
            log.warning(GridClientPartitionAffinity.class.getSimpleName() + " is used for a cache configured " + "for non-partitioned mode [cacheName=" + entry.getKey() + ", cacheMode=" + entry.getValue() + ']');
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridClientPartitionAffinity(org.apache.ignite.internal.client.GridClientPartitionAffinity) InetSocketAddress(java.net.InetSocketAddress) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) ArrayList(java.util.ArrayList) GridClientDataAffinity(org.apache.ignite.internal.client.GridClientDataAffinity) GridClientCacheMode(org.apache.ignite.internal.client.GridClientCacheMode) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 GridClientCacheMode (org.apache.ignite.internal.client.GridClientCacheMode)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 GridClientDataAffinity (org.apache.ignite.internal.client.GridClientDataAffinity)1 GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)1 GridClientPartitionAffinity (org.apache.ignite.internal.client.GridClientPartitionAffinity)1 GridClientNodeImpl (org.apache.ignite.internal.client.impl.GridClientNodeImpl)1 GridClientNodeMetricsAdapter (org.apache.ignite.internal.client.impl.GridClientNodeMetricsAdapter)1 GridClientCacheBean (org.apache.ignite.internal.processors.rest.client.message.GridClientCacheBean)1 GridClientNodeMetricsBean (org.apache.ignite.internal.processors.rest.client.message.GridClientNodeMetricsBean)1 Nullable (org.jetbrains.annotations.Nullable)1