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();
}
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);
}
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);
}
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();
}
}
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();
}
Aggregations