ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [34/50] incubator-ignite git commit: # ignite-917
Date Fri, 26 Jun 2015 00:07:55 GMT
# ignite-917


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/2ad4fe12
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/2ad4fe12
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/2ad4fe12

Branch: refs/heads/ignite-621
Commit: 2ad4fe121184ce3bb38e899df826208da83c5b0d
Parents: b29ff1c
Author: Atri <atri.jiit@gmail.com>
Authored: Wed Jun 10 15:47:00 2015 +0530
Committer: ashutak <ashutak@gridgain.com>
Committed: Wed Jun 24 16:15:58 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cluster/ClusterGroup.java |  9 +++++
 .../internal/cluster/ClusterGroupAdapter.java   | 42 ++++++++++++++++++++
 .../cluster/IgniteClusterAsyncImpl.java         |  5 +++
 .../ignite/internal/GridProjectionSelfTest.java | 19 +++++++++
 4 files changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2ad4fe12/modules/core/src/main/java/org/apache/ignite/cluster/ClusterGroup.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cluster/ClusterGroup.java b/modules/core/src/main/java/org/apache/ignite/cluster/ClusterGroup.java
index 06854d4..2f43fc6 100644
--- a/modules/core/src/main/java/org/apache/ignite/cluster/ClusterGroup.java
+++ b/modules/core/src/main/java/org/apache/ignite/cluster/ClusterGroup.java
@@ -193,6 +193,15 @@ public interface ClusterGroup {
     public ClusterGroup forHost(ClusterNode node);
 
     /**
+     * Gets cluster group consisting from the nodes running on the hosts specified.
+     *
+     * @param host Host name to get nodes to put in cluster
+     * @param hosts Host names to get nodes to put in cluster.
+     * @return Cluster group for nodes residing on the hosts specified.
+     */
+    public ClusterGroup forHost(String host, String... hosts);
+
+    /**
      * Gets a cluster group consisting from the daemon nodes.
      * <p>
      * Daemon nodes are the usual grid nodes that participate in topology but not

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2ad4fe12/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
index bb82c3b..1831321 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
@@ -577,6 +577,11 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
     }
 
     /** {@inheritDoc} */
+    @Override public final ClusterGroup forHost(String host, String... hosts) {
+	return forPredicate(new HostsFilter(host, hosts));
+    }
+
+    /** {@inheritDoc} */
     @Override public final ClusterGroup forDaemons() {
         return forPredicate(new DaemonFilter());
     }
@@ -762,6 +767,43 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable
{
 
     /**
      */
+    private static class HostsFilter implements IgnitePredicate<ClusterNode> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Hosts Names. */
+        private final HashSet hashInputHostNames;
+
+        /**
+         * @param name  First host name.
+	  * @param names Host names
+         */
+        private HostsFilter(String name, String[] names) {
+            hashInputHostNames = new HashSet();
+
+            if (name != null)
+                hashInputHostNames.add(name);
+
+            if (names != null && (names.length > 0)) {
+                for (String currentInputHostName : names)
+                    hashInputHostNames.add(currentInputHostName);
+	    }
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(ClusterNode n) {
+	    for (String currentHostName : n.hostNames()) {
+                if (hashInputHostNames.contains(currentHostName)) {
+		    return true;
+		}
+            }
+
+            return false;
+        }
+    }
+
+    /**
+     */
     private static class DaemonFilter implements IgnitePredicate<ClusterNode> {
         /** */
         private static final long serialVersionUID = 0L;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2ad4fe12/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java
index 7f67b4f..ca6cf32 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/IgniteClusterAsyncImpl.java
@@ -232,6 +232,11 @@ public class IgniteClusterAsyncImpl extends AsyncSupportAdapter<IgniteCluster>
     }
 
     /** {@inheritDoc} */
+    @Override public ClusterGroup forHost(String host, String... hosts) {
+	return cluster.forHost(host, hosts);
+    }
+
+    /** {@inheritDoc} */
     @Override public ClusterGroup forDaemons() {
         return cluster.forDaemons();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2ad4fe12/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
index 9fbad80..bd625d9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/GridProjectionSelfTest.java
@@ -248,4 +248,23 @@ public class GridProjectionSelfTest extends GridProjectionAbstractTest
{
 
         return even ? cnt - 1 : cnt - 2;
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testForHost() throws Exception {
+        Collection<ClusterNode> allNodes = ignite.cluster().nodes();
+        ClusterNode localNode = ignite.cluster().localNode();
+        ArrayList<String> inputHostNames = new ArrayList<String> ();
+
+        for (ClusterNode currentNode : allNodes)
+            Collections.addAll(inputHostNames, currentNode.hostNames().toArray(new String[0]));
+
+        String[] inputHostNamesArray = inputHostNames.toArray(new String[] {});
+        ClusterGroup resultGroup = ignite.cluster().forHost(inputHostNamesArray[0], inputHostNamesArray);
+	ClusterGroup nullTestGroup = ignite.cluster().forHost(null, null);
+
+        assert((resultGroup.node(localNode.id())) != null);
+        assert((nullTestGroup.node(localNode.id())) == null);
+    }
 }


Mime
View raw message