ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [18/37] incubator-ignite git commit: #IGNITE-857 Added constraint on host. Added test.
Date Thu, 28 May 2015 21:02:16 GMT
#IGNITE-857 Added constraint on host. Added test.


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

Branch: refs/heads/ignite-gg-10369
Commit: 9a951e0ccdd63295632babc48519bc672c0ad0e2
Parents: 9bed1ff
Author: nikolay_tikhonov <ntikhonov@gridgain.com>
Authored: Wed May 27 16:14:55 2015 +0300
Committer: nikolay_tikhonov <ntikhonov@gridgain.com>
Committed: Wed May 27 16:14:55 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/mesos/ClusterProperties.java  | 53 ++++++++++++++++----
 .../apache/ignite/mesos/IgniteScheduler.java    |  5 ++
 .../ignite/mesos/IgniteSchedulerSelfTest.java   | 45 +++++++++++++----
 3 files changed, 85 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9a951e0c/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
index 25216ca..9f0b304 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/ClusterProperties.java
@@ -17,14 +17,20 @@
 
 package org.apache.ignite.mesos;
 
+import org.slf4j.*;
+
 import java.io.*;
 import java.net.*;
 import java.util.*;
+import java.util.regex.*;
 
 /**
  * Cluster settings.
  */
 public class ClusterProperties {
+    /** */
+    private static final Logger log = LoggerFactory.getLogger(ClusterProperties.class);
+
     /** Unlimited. */
     public static final double UNLIMITED = Double.MAX_VALUE;
 
@@ -170,6 +176,12 @@ public class ClusterProperties {
     private String igniteCfgUrl = null;
 
     /** */
+    public static final String IGNITE_HOSTNAME_CONSTRAINT = "IGNITE_HOSTNAME_CONSTRAINT";
+
+    /** Url to ignite config. */
+    private Pattern hostnameConstraint = null;
+
+    /** */
     public ClusterProperties() {
         // No-op.
     }
@@ -184,21 +196,21 @@ public class ClusterProperties {
     /**
      * @return CPU count limit.
      */
-    public double cpus(){
+    public double cpus() {
         return cpu;
     }
 
     /**
      * Set CPU count limit.
      */
-    public void cpus(double cpu){
+    public void cpus(double cpu) {
         this.cpu = cpu;
     }
 
     /**
      * @return CPU count limit.
      */
-    public double cpusPerNode(){
+    public double cpusPerNode() {
         return cpuPerNode;
     }
 
@@ -216,7 +228,6 @@ public class ClusterProperties {
         this.mem = mem;
     }
 
-
     /**
      * @return mem limit.
      */
@@ -262,6 +273,15 @@ public class ClusterProperties {
     }
 
     /**
+     * Sets hostname constraint.
+     *
+     * @param pattern Hostname pattern.
+     */
+    public void hostnameConstraint(Pattern pattern) {
+        this.hostnameConstraint = pattern;
+    }
+
+    /**
      * @return min cpu count per node.
      */
     public double minCpuPerNode() {
@@ -348,6 +368,13 @@ public class ClusterProperties {
     }
 
     /**
+     * @return Host name constraint.
+     */
+    public Pattern hostnameConstraint() {
+        return hostnameConstraint;
+    }
+
+    /**
      * @param config path to config file.
      * @return Cluster configuration.
      */
@@ -396,6 +423,17 @@ public class ClusterProperties {
             prop.igniteCfg = getStringProperty(IGNITE_CONFIG_XML, props, null);
             prop.userLibs = getStringProperty(IGNITE_USERS_LIBS, props, null);
 
+            String pattern = getStringProperty(IGNITE_HOSTNAME_CONSTRAINT, props, null);
+
+            if (pattern != null) {
+                try {
+                    prop.hostnameConstraint = Pattern.compile(pattern);
+                }
+                catch (PatternSyntaxException e) {
+                    log.warn("IGNITE_HOSTNAME_CONSTRAINT has invalid pattern. It will be
ignore.", e);
+                }
+            }
+
             return prop;
         }
         catch (IOException e) {
@@ -440,11 +478,8 @@ public class ClusterProperties {
     /**
      * Finds a local, non-loopback, IPv4 address
      *
-     * @return The first non-loopback IPv4 address found, or
-     *         <code>null</code> if no such addresses found
-     * @throws java.net.SocketException
-     *            If there was a problem querying the network
-     *            interfaces
+     * @return The first non-loopback IPv4 address found, or <code>null</code>
if no such addresses found
+     * @throws java.net.SocketException If there was a problem querying the network interfaces
      */
     public static String getNonLoopbackAddress() throws SocketException {
         Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9a951e0c/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java
index 9041629..9b8553e 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/mesos/IgniteScheduler.java
@@ -203,6 +203,11 @@ public class IgniteScheduler implements Scheduler {
         double mem = -1;
         double disk = -1;
 
+        // Check host name
+        if (clusterProps.hostnameConstraint() != null
+            && clusterProps.hostnameConstraint().matcher(offer.getHostname()).matches())
+            return null;
+
         // Collect resource on slave.
         for (Protos.Resource resource : offer.getResourcesList()) {
             if (resource.getName().equals(CPUS)) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9a951e0c/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
b/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
index 277e0db..337b47c 100644
--- a/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
+++ b/modules/mesos/src/test/java/org/apache/ignite/mesos/IgniteSchedulerSelfTest.java
@@ -22,6 +22,7 @@ import org.apache.ignite.mesos.resource.*;
 import org.apache.mesos.*;
 
 import java.util.*;
+import java.util.regex.*;
 
 /**
  * Scheduler tests.
@@ -63,7 +64,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
 
         DriverMock mock = new DriverMock();
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNotNull(mock.launchedTask);
         assertEquals(1, mock.launchedTask.size());
@@ -87,7 +88,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
 
         scheduler.setClusterProps(clustProp);
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNotNull(mock.launchedTask);
         assertEquals(1, mock.launchedTask.size());
@@ -99,7 +100,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
 
         mock.clear();
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNull(mock.launchedTask);
 
@@ -122,7 +123,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
 
         scheduler.setClusterProps(clustProp);
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNotNull(mock.launchedTask);
         assertEquals(1, mock.launchedTask.size());
@@ -134,7 +135,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
 
         mock.clear();
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNull(mock.launchedTask);
 
@@ -160,7 +161,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
         double totalMem = 0, totalCpu = 0;
 
         for (int i = 0; i < 2; i++) {
-            scheduler.resourceOffers(mock, Arrays.asList(offer));
+            scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
             assertNotNull(mock.launchedTask);
             assertEquals(1, mock.launchedTask.size());
@@ -176,7 +177,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
         assertEquals(2.0, totalCpu);
         assertEquals(2000.0, totalMem);
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNull(mock.launchedTask);
 
@@ -198,7 +199,7 @@ public class IgniteSchedulerSelfTest extends TestCase {
 
         scheduler.setClusterProps(clustProp);
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNotNull(mock.declinedOffer);
 
@@ -218,13 +219,39 @@ public class IgniteSchedulerSelfTest extends TestCase {
 
         scheduler.setClusterProps(clustProp);
 
-        scheduler.resourceOffers(mock, Arrays.asList(offer));
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
 
         assertNotNull(mock.declinedOffer);
 
         assertEquals(offer.getId(), mock.declinedOffer);
     }
 
+    /**
+     * @throws Exception If failed.
+     */
+    public void testHosthameConstraint() throws Exception {
+        Protos.Offer offer = createOffer("hostname", 8, 10240);
+
+        DriverMock mock = new DriverMock();
+
+        ClusterProperties clustProp = new ClusterProperties();
+        clustProp.hostnameConstraint(Pattern.compile("hostname"));
+
+        scheduler.setClusterProps(clustProp);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.declinedOffer);
+
+        assertEquals(offer.getId(), mock.declinedOffer);
+
+        offer = createOffer("hostnameAccept", 8, 10240);
+
+        scheduler.resourceOffers(mock, Collections.singletonList(offer));
+
+        assertNotNull(mock.launchedTask);
+        assertEquals(1, mock.launchedTask.size());
+    }
 
     /**
      * @param resourceType Resource type.


Mime
View raw message