/** * @param n Node. * @return Replicas. */ private int replicas(GridNode n) { Integer nodeReplicas = n.attribute(attrName); if (nodeReplicas == null) nodeReplicas = replicas; return nodeReplicas; }
/** {@inheritDoc} */ @Override public boolean apply(GridNode n) { return val == null ? n.attributes().containsKey(name) : val.equals(n.attribute(name)); } }
/** * Get node attribute by specified attribute name. * * @param node Node to get attribute for. * @param attrName Attribute name. * @param dfltVal Default result for case when node attribute resolved into {@code null}. * @return Attribute value or default result if requested attribute resolved into {@code null}. */ private <T> T attribute(GridNode node, String attrName, T dfltVal) { T attr = node.attribute(attrName); return attr == null ? dfltVal : attr; }
/** * Gets cache attributes for the node. * * @param n Node to get cache attributes for. * @return Array of cache attributes for the node. */ public static GridCacheAttributes[] cacheAttributes(GridNode n) { return n.attribute(ATTR_CACHE); }
/** * @param loc Local node. * @param rmt Remote node. * @return Whether given nodes have the same macs. */ public static boolean sameMacs(GridNode loc, GridNode rmt) { assert loc != null; assert rmt != null; String locMacs = loc.attribute(GridNodeAttributes.ATTR_MACS); String rmtMacs = rmt.attribute(GridNodeAttributes.ATTR_MACS); return locMacs != null && locMacs.equals(rmtMacs); }
/** * Checks if given node is a daemon node. * * @param n Node. * @return Whether node is daemon. */ private boolean daemon(GridNode n) { return "true".equalsIgnoreCase(n.<String>attribute(ATTR_DAEMON)); }
/** * Gets node product version based on node attributes. * * @param node Node to get version from. * @return Version object. */ public static GridProductVersion productVersion(GridNode node) { String verStr = node.attribute(ATTR_BUILD_VER); String buildDate = node.attribute(ATTR_BUILD_DATE); if (buildDate != null) verStr += '-' + buildDate; return GridProductVersion.fromString(verStr); }
/** * Gets cache interceptor class name from node attributes. * * @param node Node. * @param cacheName Cache name. * @return Interceptor class name. */ @Nullable private String interceptor(GridNode node, @Nullable String cacheName) { Map<String, String> map = node.attribute(ATTR_CACHE_INTERCEPTORS); return map != null ? map.get(cacheName) : null; }
/** * Gets portable enabled flag from the given node for the given cache name. * * @param n Node. * @param cacheName Cache name. * @return Portable enabled flag. */ @Nullable public static Boolean portableEnabled(GridNode n, @Nullable String cacheName) { Map<String, Boolean> map = n.attribute(ATTR_CACHE_PORTABLE); return map == null ? null : map.get(cacheName); }
/** * Returns one representative node for each JVM. * * @param nodes Nodes. * @return Collection which contains only one representative node for each JVM. */ private static Iterable<GridNode> nodesPerJvm(Iterable<GridNode> nodes) { Map<String, GridNode> grpMap = new HashMap<>(); // Group by mac addresses and pid. for (GridNode node : nodes) { String grpId = node.attribute(ATTR_MACS) + "|" + node.attribute(ATTR_JVM_PID); if (!grpMap.containsKey(grpId)) grpMap.put(grpId, node); } return grpMap.values(); }
/** * Checks if given node has specified cache started. * * @param cacheName Cache name. * @param node Node to check. * @return {@code True} if given node has specified cache started. */ public static boolean cacheNode(String cacheName, GridNode node) { return cacheNode(cacheName, (GridCacheAttributes[])node.attribute(ATTR_CACHE)); }
/** * @param node Node to get weight for. * @return Node weight */ private int getWeight(GridNode node) { Integer weight = (Integer)node.attribute(createSpiAttributeName(NODE_WEIGHT_ATTR_NAME)); if (weight != null && weight == 0) throw new IllegalStateException("Node weight cannot be zero: " + node); return weight == null ? DFLT_NODE_WEIGHT : weight; }
/** * @param nodes Nodes. * @return Total CPUs. */ private static int cpus(Collection<GridNode> nodes) { Collection<String> macSet = new HashSet<>(nodes.size(), 1.0f); int cpus = 0; for (GridNode n : nodes) { String macs = n.attribute(ATTR_MACS); if (macSet.add(macs)) cpus += n.metrics().getTotalCpus(); } return cpus; }
/** {@inheritDoc} */ @Override public final GridProjection forHost(GridNode node) { A.notNull(node, "node"); String macs = node.attribute(ATTR_MACS); assert macs != null; return forAttribute(ATTR_MACS, macs); }
/** * Checks if given node has specified cache started. * * @param n Node to check. * @param cacheName Cache name to check. * @return {@code True} if given node has specified cache started. */ public static boolean hasCache(GridNode n, @Nullable String cacheName) { assert n != null; GridCacheAttributes[] caches = n.attribute(ATTR_CACHE); if (caches != null) for (GridCacheAttributes attrs : caches) if (F.eq(cacheName, attrs.cacheName())) return true; return false; }
/** * Gets view on all cache names started on the node. * * @param n Node to get cache names for. * @return Cache names for the node. */ public static Collection<String> cacheNames(GridNode n) { return F.viewReadOnly( F.asList(n.<GridCacheAttributes[]>attribute(ATTR_CACHE)), new C1<GridCacheAttributes, String>() { @Override public String apply(GridCacheAttributes attrs) { return attrs.cacheName(); } }); }
/** * Checks that node has specified attribute and prints warning if it does not. * * @param node Node to check. * @param attrName Name of the attribute. */ private void checkAttributePresence(GridNode node, String attrName) { if (node.attribute(attrName) == null) U.warn(log, "Remote node has inconsistent configuration (required attribute was not found) " + "[attrName=" + attrName + ", nodeId=" + node.id() + "spiCls=" + U.getSimpleName(GridTcpCommunicationSpi.class) + ']'); }
/** * Checks if given node is a GGFS node. * * @param node Node to check. * @return {@code True} if node has GGFS with this name, {@code false} otherwise. */ public boolean ggfsNode(GridNode node) { assert node != null; GridGgfsAttributes[] ggfs = node.attribute(ATTR_GGFS); if (ggfs != null) for (GridGgfsAttributes attrs : ggfs) if (F.eq(cfg.getName(), attrs.ggfsName())) return true; return false; }
/** * Checks if given node is a GGFS node. * * @param node Node to check. * @return {@code True} if node has GGFS with this name, {@code false} otherwise. */ public boolean ggfsNode(GridNode node) { assert node != null; GridGgfsAttributes[] ggfs = node.attribute(ATTR_GGFS); if (ggfs != null) for (GridGgfsAttributes attrs : ggfs) if (F.eq(cfg.getName(), attrs.ggfsName())) return true; return false; }
/** * Checks if given node has near cache enabled for the specified * partitioned cache. * * @param n Node. * @param cacheName Cache name. * @return {@code true} if given node has near cache enabled for the * specified partitioned cache. */ public static boolean hasNearCache(GridNode n, String cacheName) { GridCacheAttributes[] caches = n.attribute(ATTR_CACHE); if (caches != null) for (GridCacheAttributes attrs : caches) if (F.eq(cacheName, attrs.cacheName())) return attrs.nearCacheEnabled(); return false; }