@Override public Object apply(BaselineNode node) { return node.consistentId(); } };
/** * Create data transfer object for baseline node. * * @param node Baseline node. */ public VisorBaselineNode(BaselineNode node) { consistentId = String.valueOf(node.consistentId()); attrs = node.attributes(); }
/** * @param nodes Nodes. */ private long calculateTopologyHash(Collection<? extends BaselineNode> nodes) { long res = 0; Set<Object> bltConsIds = nodeMap.keySet(); for (BaselineNode node : nodes) { if (bltConsIds.contains(node.consistentId())) res += (long) node.consistentId().hashCode(); } return res; }
/** * @param nodes Nodes. * @param id ID of BaselineTopology to build. * @return Baseline topology consisting of given nodes. */ @Nullable public static BaselineTopology build(Collection<? extends BaselineNode> nodes, int id) { if (nodes == null) return null; Map<Object, Map<String, Object>> nodeMap = new HashMap<>(); for (BaselineNode node : nodes) nodeMap.put(node.consistentId(), node.attributes()); return new BaselineTopology(nodeMap, id); }
/** */ private Collection<Object> getConsistentIds(Collection<? extends BaselineNode> nodes) { ArrayList<Object> res = new ArrayList<>(nodes.size()); for (BaselineNode n : nodes) res.add(n.consistentId()); return res; }
/** {@inheritDoc} */ @Override public void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException { switch (type) { case OP_GET_IGNITE_CONFIGURATION: { PlatformConfigurationUtils.writeIgniteConfiguration(writer, ignite().configuration(), CURRENT_VER); return; } case OP_GET_CACHE_NAMES: { Collection<String> names = ignite().cacheNames(); writer.writeInt(names.size()); for (String name : names) writer.writeString(name); return; } case OP_GET_BASELINE_TOPOLOGY: { Collection<BaselineNode> blt = ignite().cluster().currentBaselineTopology(); writer.writeInt(blt.size()); for (BaselineNode n : blt) { writer.writeObjectDetached(n.consistentId()); PlatformUtils.writeNodeAttributes(writer, n.attributes()); } return; } } PlatformAbstractTarget.throwUnsupported(type); }
/** * @param nodes Nodes to process. * @return Collection of consistentIds. */ private static Collection<String> consistentIds(Collection<? extends BaselineNode> nodes) { return nodes.stream().map(n -> String.valueOf(n.consistentId())).collect(toList()); }
/** * Create data transfer object for baseline node. * * @param node Baseline node. */ public VisorBaselineNode(BaselineNode node) { consistentId = String.valueOf(node.consistentId()); attrs = node.attributes(); }
/** * Filter passed nodes by consistent IDs. * * @param nodes Collection of nodes. * @param consistentIds Collection of consistent IDs. * @throws IllegalStateException In case of some consistent ID not found in nodes collection. */ private Collection<BaselineNode> filterNodesByConsId(Collection<? extends BaselineNode> nodes, List<Object> consistentIds) { Map<Object, BaselineNode> nodeMap = nodes.stream().collect(toMap(n -> n.consistentId().toString(), identity())); Collection<BaselineNode> filtered = new ArrayList<>(consistentIds.size()); for (Object consistentId : consistentIds) { BaselineNode node = nodeMap.get(consistentId); if (node == null) throw new IllegalStateException("Node not found for consistent ID: " + consistentId); filtered.add(node); } return filtered; }
/** * @param nodes Nodes. * @param id ID of BaselineTopology to build. * @return Baseline topology consisting of given nodes. */ @Nullable public static BaselineTopology build(Collection<? extends BaselineNode> nodes, int id) { if (nodes == null) return null; Map<Object, Map<String, Object>> nodeMap = new HashMap<>(); for (BaselineNode node : nodes) nodeMap.put(node.consistentId(), node.attributes()); return new BaselineTopology(nodeMap, id); }
/** * @return Current baseline. */ private Map<String, BaselineNode> currentBaseLine() { Map<String, BaselineNode> nodes = new HashMap<>(); Collection<BaselineNode> baseline = ignite.cluster().currentBaselineTopology(); if (!F.isEmpty(baseline)) { for (BaselineNode node : baseline) nodes.put(node.consistentId().toString(), node); } return nodes; }
/** {@inheritDoc} */ @Override public void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException { switch (type) { case OP_GET_IGNITE_CONFIGURATION: { PlatformConfigurationUtils.writeIgniteConfiguration(writer, ignite().configuration(), CURRENT_VER); return; } case OP_GET_CACHE_NAMES: { Collection<String> names = ignite().cacheNames(); writer.writeInt(names.size()); for (String name : names) writer.writeString(name); return; } case OP_GET_BASELINE_TOPOLOGY: { Collection<BaselineNode> blt = ignite().cluster().currentBaselineTopology(); writer.writeInt(blt.size()); for (BaselineNode n : blt) { writer.writeObjectDetached(n.consistentId()); PlatformUtils.writeNodeAttributes(writer, n.attributes()); } return; } } PlatformAbstractTarget.throwUnsupported(type); }
/** {@inheritDoc} */ @Override public int getActiveBaselineNodes() { Collection<BaselineNode> baselineNodes = cluster.ignite().cluster().currentBaselineTopology(); if (baselineNodes != null && !baselineNodes.isEmpty()) { Set<Object> bltIds = new HashSet<>(baselineNodes.size()); for (BaselineNode baselineNode : baselineNodes) bltIds.add(baselineNode.consistentId()); int count = 0; for (ClusterNode node : cluster.forServers().nodes()) if (bltIds.contains(node.consistentId())) count++; return count; } return 0; }
/** * @param nodes Collection of grid nodes. * @return Collection of node consistent IDs for given collection of grid nodes. */ private static Collection<String> nodeConsistentIds(@Nullable Collection<? extends BaselineNode> nodes) { if (nodes == null || nodes.isEmpty()) return Collections.emptyList(); return F.viewReadOnly(nodes, n -> String.valueOf(n.consistentId())); }
/** {@inheritDoc} */ @Override public int getTotalBaselineNodes() { if (!node.isClient() && !node.isDaemon()) { List<? extends BaselineNode> baselineNodes = discoMgr.baselineNodes(discoMgr.topologyVersionEx()); if (baselineNodes != null) for (BaselineNode baselineNode : baselineNodes) if (baselineNode.consistentId().equals(node.consistentId())) return 1; } return 0; }
boolean inBaseline = baseline.stream().anyMatch(n -> consistentId.equals(n.consistentId()));
/** * @throws Exception If failed. */ @Test public void testBaselineSet() throws Exception { int sz = gridCount(); assertBaseline(content(null, GridRestCommand.BASELINE_CURRENT_STATE), sz, sz); startGrid(sz); assertBaseline(content(null, GridRestCommand.BASELINE_CURRENT_STATE), sz, sz + 1); assertBaseline(content(null, GridRestCommand.BASELINE_SET, "topVer", String.valueOf(grid(0).cluster().topologyVersion())), sz + 1, sz + 1); stopGrid(sz); assertBaseline(content(null, GridRestCommand.BASELINE_CURRENT_STATE), sz + 1, sz); assertBaseline(content(null, GridRestCommand.BASELINE_SET, "topVer", String.valueOf(grid(0).cluster().topologyVersion())), sz, sz); startGrid(sz); assertBaseline(content(null, GridRestCommand.BASELINE_CURRENT_STATE), sz, sz + 1); ArrayList<String> params = new ArrayList<>(); int i = 1; for (BaselineNode n : grid(0).cluster().nodes()) { params.add("consistentId" + i++); params.add(String.valueOf(n.consistentId())); } assertBaseline(content(null, GridRestCommand.BASELINE_SET, params.toArray(new String[0])), sz + 1, sz + 1); stopGrid(sz); }
@Override public Object apply(BaselineNode node) { return node.consistentId(); } };
/** * @param nodes Nodes. */ private long calculateTopologyHash(Collection<? extends BaselineNode> nodes) { long res = 0; Set<Object> bltConsIds = nodeMap.keySet(); for (BaselineNode node : nodes) { if (bltConsIds.contains(node.consistentId())) res += (long) node.consistentId().hashCode(); } return res; }
/** */ private Collection<Object> getConsistentIds(Collection<? extends BaselineNode> nodes) { ArrayList<Object> res = new ArrayList<>(nodes.size()); for (BaselineNode n : nodes) res.add(n.consistentId()); return res; }