/** {@inheritDoc} */ @Override public boolean apply(ClusterNode n) { for (String hostName : n.hostNames()) { if (validHostNames.contains(hostName)) return true; } return false; } }
/** {@inheritDoc} */ @Override public Collection<String> hostNames() { Set<String> res = new HashSet<>(); for (ClusterNode node : nodes()) res.addAll(node.hostNames()); return Collections.unmodifiableSet(res); }
/** * Returns string representation of node addresses. * * @param node Grid node. * @return String representation of addresses. */ public static String addressesAsString(ClusterNode node) { return addressesAsString(node.addresses(), node.hostNames()); }
/** * Groups nodes by host names. * * @param top Topology to group. * @return Map. */ protected static Map<String, Collection<UUID>> groupByHost(Collection<ClusterNode> top) { Map<String, Collection<UUID>> grouped = U.newHashMap(top.size()); for (ClusterNode node : top) { for (String host : node.hostNames()) { Collection<UUID> nodeIds = grouped.get(host); if (nodeIds == null) { // Expecting 1-2 nodes per host. nodeIds = new ArrayList<>(2); grouped.put(host, nodeIds); } nodeIds.add(node.id()); } } return grouped; } }
/** * Returns tha list of resolved inet addresses. First addresses are resolved by host names, * if this attempt fails then the addresses are resolved by ip addresses. * * @param node Grid node. * @return Inet addresses for given addresses and host names. * @throws IgniteCheckedException If non of addresses can be resolved. */ public static Collection<InetAddress> toInetAddresses(ClusterNode node) throws IgniteCheckedException { return toInetAddresses(node.addresses(), node.hostNames()); }
/** * Returns tha list of resolved socket addresses. First addresses are resolved by host names, * if this attempt fails then the addresses are resolved by ip addresses. * * @param node Grid node. * @param port Port. * @return Socket addresses for given addresses and host names. */ public static Collection<InetSocketAddress> toSocketAddresses(ClusterNode node, int port) { return toSocketAddresses(node.addresses(), node.hostNames(), port); }
/** {@inheritDoc} */ @Override public String getCurrentCoordinatorFormatted() { ClusterNode node = ctx.discovery().oldestAliveServerNode(AffinityTopologyVersion.NONE); if (node == null) return ""; return new StringBuilder() .append(node.addresses()) .append(COORDINATOR_PROPERTIES_SEPARATOR) .append(node.id()) .append(COORDINATOR_PROPERTIES_SEPARATOR) .append(node.order()) .append(COORDINATOR_PROPERTIES_SEPARATOR) .append(node.hostNames()) .toString(); }
/** * @param id Id. */ private String composeNodeInfo(final UUID id) { final ClusterNode node = gridKernalCtx.discovery().node(id); if (node == null) return ""; return String.format("%s %s", node.id(), node.hostNames()); }
/** * Create data transfer object for baseline node. * * @param node Baseline node. */ public VisorClusterNode(ClusterNode node) { consistentId = String.valueOf(node.consistentId()); addrs = node.addresses(); hostNames = node.hostNames(); attrs = node.attributes(); }
/** * IMPORTANT! * Only purpose of this constructor is creating node which contains necessary data to store on disc only * @param node to copy data from */ public TcpDiscoveryNode( ClusterNode node ) { this.id = node.id(); this.consistentId = node.consistentId(); this.addrs = node.addresses(); this.hostNames = node.hostNames(); this.order = node.order(); this.ver = node.version(); this.daemon = node.isDaemon(); this.clientRouterNodeId = node.isClient() ? node.id() : null; attrs = Collections.singletonMap(ATTR_NODE_CONSISTENT_ID, consistentId); } }
/** {@inheritDoc} */ @Override public Iterator<Row> getRows(Session ses, SearchRow first, SearchRow last) { List<Row> rows = new ArrayList<>(); Collection<ClusterNode> nodes; SqlSystemViewColumnCondition idCond = conditionForColumn("ID", first, last); if (idCond.isEquality()) { UUID nodeId = uuidFromValue(idCond.valueForEquality()); nodes = nodeId == null ? Collections.emptySet() : Collections.singleton(ctx.discovery().node(nodeId)); } else nodes = F.concat(false, ctx.discovery().allNodes(), ctx.discovery().daemonNodes()); for (ClusterNode node : nodes) { if (node != null) rows.add( createRow( ses, node.id(), node.consistentId(), node.version(), node.isClient(), node.isDaemon(), node.order(), node.addresses(), node.hostNames() ) ); } return rows.iterator(); }
/** * @throws Exception If failed. */ @Test public void testNodeAddresses() throws Exception { startGridsMultiThreaded(3); helper.clientMode(true); startGridsMultiThreaded(3, 3); waitForTopology(6); for (Ignite node : G.allGrids()) { ClusterNode locNode0 = node.cluster().localNode(); assertTrue(!locNode0.addresses().isEmpty()); assertTrue(!locNode0.hostNames().isEmpty()); for (ClusterNode node0 : node.cluster().nodes()) { assertTrue(!node0.addresses().isEmpty()); assertTrue(!node0.hostNames().isEmpty()); } } }
/** * Tests correct MBean interface. * * @throws Exception Thrown if test fails. */ @Test public void testIgniteKernalReturnsValidMBeanInfo() throws Exception { try { IgniteEx igniteCrd = startGrid(0); IgniteMXBean igniteMXBean = (IgniteMXBean)startGrid(1); assertNotNull(igniteMXBean.getUserAttributesFormatted()); assertNotNull(igniteMXBean.getLifecycleBeansFormatted()); String coordinatorFormatted = igniteMXBean.getCurrentCoordinatorFormatted(); assertTrue(coordinatorFormatted.contains(igniteCrd.localNode().addresses().toString())); assertTrue(coordinatorFormatted.contains(igniteCrd.localNode().hostNames().toString())); assertTrue(coordinatorFormatted.contains(Long.toString(igniteCrd.localNode().order()))); assertTrue(coordinatorFormatted.contains(igniteCrd.localNode().id().toString())); } finally { stopAllGrids(); } }
/** * @throws Exception If failed. */ @Test public void testHostNames() throws Exception { Ignite ignite = grid(); Collection<String> locNodeHosts = ignite.cluster().localNode().hostNames(); Collection<String> clusterHosts = ignite.cluster().hostNames(); assertTrue(F.eqNotOrdered(locNodeHosts, clusterHosts)); boolean gotNpe = false; try { clusterHosts.add("valueShouldNotToBeAdded"); } catch (UnsupportedOperationException ignored) { gotNpe = true; } finally { assertTrue(gotNpe); } }
/** {@inheritDoc} */ @Override public void addNode(ClusterNode node) { if (node == null || sentNodes.contains(node.id())) return; // Send node info to the native platform try (PlatformMemory mem0 = mem.allocate()) { PlatformOutputStream out = mem0.output(); BinaryRawWriterEx w = writer(out); w.writeUuid(node.id()); PlatformUtils.writeNodeAttributes(w, node.attributes()); w.writeCollection(node.addresses()); w.writeCollection(node.hostNames()); w.writeLong(node.order()); w.writeBoolean(node.isLocal()); w.writeBoolean(node.isDaemon()); w.writeBoolean(node.isClient()); w.writeObjectDetached(node.consistentId()); writeClusterMetrics(w, node.metrics()); out.synchronize(); gateway().nodeInfo(mem0.pointer()); } sentNodes.add(node.id()); }
/** {@inheritDoc} */ @Override public Collection<String> hostNames() { Set<String> res = new HashSet<>(); for (ClusterNode node : nodes()) res.addAll(node.hostNames()); return Collections.unmodifiableSet(res); }
/** * Returns tha list of resolved inet addresses. First addresses are resolved by host names, * if this attempt fails then the addresses are resolved by ip addresses. * * @param node Grid node. * @return Inet addresses for given addresses and host names. * @throws IgniteCheckedException If non of addresses can be resolved. */ public static Collection<InetAddress> toInetAddresses(ClusterNode node) throws IgniteCheckedException { return toInetAddresses(node.addresses(), node.hostNames()); }
/** * Returns string representation of node addresses. * * @param node Grid node. * @return String representation of addresses. */ public static String addressesAsString(ClusterNode node) { return addressesAsString(node.addresses(), node.hostNames()); }
/** * @param id Id. */ private String composeNodeInfo(final UUID id) { final ClusterNode node = gridKernalCtx.discovery().node(id); if (node == null) return ""; return String.format("%s %s", node.id(), node.hostNames()); }
/** * Create data transfer object for baseline node. * * @param node Baseline node. */ public VisorClusterNode(ClusterNode node) { consistentId = String.valueOf(node.consistentId()); addrs = node.addresses(); hostNames = node.hostNames(); attrs = node.attributes(); }