ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [03/38] incubator-ignite git commit: #ignite-857 Added AmazonScheduler.
Date Fri, 29 May 2015 11:46:38 GMT
#ignite-857 Added AmazonScheduler.


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

Branch: refs/heads/ignite-943
Commit: fbdcb70677249ed6aceab5057756e7eb04c89c04
Parents: b896ec8
Author: nikolay tikhonov <ntikhonov@gridgain.com>
Authored: Thu May 14 19:48:05 2015 +0300
Committer: nikolay tikhonov <ntikhonov@gridgain.com>
Committed: Thu May 14 19:48:05 2015 +0300

----------------------------------------------------------------------
 .../ignite/messo/IgniteAmazonScheduler.java     | 81 ++++++++++++++++++++
 .../apache/ignite/messo/IgniteFramework.java    | 27 ++++++-
 .../apache/ignite/messo/IgniteScheduler.java    | 67 ++++++++++------
 3 files changed, 149 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdcb706/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteAmazonScheduler.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteAmazonScheduler.java
b/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteAmazonScheduler.java
new file mode 100644
index 0000000..250fec6
--- /dev/null
+++ b/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteAmazonScheduler.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.messo;
+
+import org.apache.mesos.*;
+
+/**
+ * TODO
+ */
+public class IgniteAmazonScheduler extends IgniteScheduler {
+    /** */
+    public static final String AMAZON = "amazon";
+
+    /** Amazon credential. */
+    private final String accessKey, secretKey;
+
+    /**
+     * Constructor.
+     *
+     * @param accessKey Access key.
+     * @param secretKey Secret key.
+     */
+    public IgniteAmazonScheduler(String accessKey, String secretKey) {
+        assert accessKey != null;
+        assert secretKey != null;
+
+        this.accessKey = accessKey;
+        this.secretKey = secretKey;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Protos.TaskInfo createTask(Protos.Offer offer, Pair<Double, Double>
cpuMem,
+        Protos.TaskID taskId) {
+        // Docker image info.
+        Protos.ContainerInfo.DockerInfo.Builder docker = Protos.ContainerInfo.DockerInfo.newBuilder()
+            .setImage(IMAGE)
+            .setNetwork(Protos.ContainerInfo.DockerInfo.Network.HOST);
+
+        // Container info.
+        Protos.ContainerInfo.Builder cont = Protos.ContainerInfo.newBuilder();
+        cont.setType(Protos.ContainerInfo.Type.DOCKER);
+        cont.setDocker(docker.build());
+
+        return Protos.TaskInfo.newBuilder()
+            .setName("task " + taskId.getValue())
+            .setTaskId(taskId)
+            .setSlaveId(offer.getSlaveId())
+            .addResources(Protos.Resource.newBuilder()
+                .setName(CPUS)
+                .setType(Protos.Value.Type.SCALAR)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpuMem._1)))
+            .addResources(Protos.Resource.newBuilder()
+                .setName(MEM)
+                .setType(Protos.Value.Type.SCALAR)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpuMem._2)))
+            .setContainer(cont)
+            .setCommand(Protos.CommandInfo.newBuilder()
+                .setShell(false)
+                .addArguments(STARTUP_SCRIPT)
+                .addArguments(String.valueOf(cpuMem._2.intValue()))
+                .addArguments(AMAZON)
+                .addArguments(accessKey)
+                .addArguments(secretKey))
+            .build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdcb706/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteFramework.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteFramework.java b/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteFramework.java
index 54d34c1..dfc3eb2 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteFramework.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteFramework.java
@@ -28,6 +28,8 @@ public class IgniteFramework {
      * @param args Args
      */
     public static void main(String[] args) {
+        checkArgs(args);
+
         final int frameworkFailoverTimeout = 0;
 
         Protos.FrameworkInfo.Builder frameworkBuilder = Protos.FrameworkInfo.newBuilder()
@@ -41,7 +43,7 @@ public class IgniteFramework {
         }
 
         // create the scheduler
-        final Scheduler scheduler = new IgniteScheduler();
+        final Scheduler scheduler = createIgniteScheduler(args);
 
         // create the driver
         MesosSchedulerDriver driver;
@@ -80,4 +82,27 @@ public class IgniteFramework {
 
         System.exit(status);
     }
+
+    /**
+     * @param args Arguments.
+     * @return Ignite scheduler.
+     */
+    private static IgniteScheduler createIgniteScheduler(String args[]) {
+        if (args.length >= 3 && args[1].equals(IgniteAmazonScheduler.AMAZON))
+            return new IgniteAmazonScheduler(args[2], args[3]);
+        else
+            return new IgniteScheduler();
+    }
+
+    /**
+     * Check input arguments.
+     *
+     * @param args Arguments.
+     */
+    private static void checkArgs(String[] args) {
+        if (args.length == 0)
+            throw new IllegalArgumentException("Illegal arguments.");
+
+        // TODO: add more
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fbdcb706/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteScheduler.java
----------------------------------------------------------------------
diff --git a/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteScheduler.java b/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteScheduler.java
index 3cb63e6..a029e69 100644
--- a/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteScheduler.java
+++ b/modules/mesos/src/main/java/org/apache/ignite/messo/IgniteScheduler.java
@@ -30,6 +30,9 @@ public class IgniteScheduler implements Scheduler {
     /** Docker image name. */
     public static final String IMAGE = "apacheignite/ignite-docker";
 
+    /** Startup sctipt path. */
+    public static final String STARTUP_SCRIPT = "/home/ignite/startup.sh";
+
     /** Cpus. */
     public static final String CPUS = "cpus";
 
@@ -76,32 +79,8 @@ public class IgniteScheduler implements Scheduler {
 
             log.info("Launching task {}", taskId.getValue());
 
-            // Docker image info.
-            Protos.ContainerInfo.DockerInfo.Builder docker = Protos.ContainerInfo.DockerInfo.newBuilder()
-                .setImage(IMAGE)
-                .setNetwork(Protos.ContainerInfo.DockerInfo.Network.HOST);
-
-            // Container info.
-            Protos.ContainerInfo.Builder cont = Protos.ContainerInfo.newBuilder();
-            cont.setType(Protos.ContainerInfo.Type.DOCKER);
-            cont.setDocker(docker.build());
-
             // Create task to run.
-            Protos.TaskInfo task = Protos.TaskInfo.newBuilder()
-                .setName("task " + taskId.getValue())
-                .setTaskId(taskId)
-                .setSlaveId(offer.getSlaveId())
-                .addResources(Protos.Resource.newBuilder()
-                    .setName(CPUS)
-                    .setType(Protos.Value.Type.SCALAR)
-                    .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpuMem._1)))
-                .addResources(Protos.Resource.newBuilder()
-                    .setName(MEM)
-                    .setType(Protos.Value.Type.SCALAR)
-                    .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpuMem._2)))
-                .setContainer(cont)
-                .setCommand(Protos.CommandInfo.newBuilder().setShell(false))
-                .build();
+            Protos.TaskInfo task = createTask(offer, cpuMem, taskId);
 
             schedulerDriver.launchTasks(Collections.singletonList(offer.getId()),
                 Collections.singletonList(task),
@@ -110,6 +89,44 @@ public class IgniteScheduler implements Scheduler {
     }
 
     /**
+     * Create Task.
+     * @param offer Offer.
+     * @param cpuMem Cpu and mem on slave.
+     * @param taskId Task id.
+     * @return Task.
+     */
+    protected Protos.TaskInfo createTask(Protos.Offer offer, Pair<Double, Double> cpuMem,
Protos.TaskID taskId) {
+        // Docker image info.
+        Protos.ContainerInfo.DockerInfo.Builder docker = Protos.ContainerInfo.DockerInfo.newBuilder()
+                .setImage(IMAGE)
+                .setNetwork(Protos.ContainerInfo.DockerInfo.Network.HOST);
+
+        // Container info.
+        Protos.ContainerInfo.Builder cont = Protos.ContainerInfo.newBuilder();
+        cont.setType(Protos.ContainerInfo.Type.DOCKER);
+        cont.setDocker(docker.build());
+
+        return Protos.TaskInfo.newBuilder()
+            .setName("task " + taskId.getValue())
+            .setTaskId(taskId)
+            .setSlaveId(offer.getSlaveId())
+            .addResources(Protos.Resource.newBuilder()
+                .setName(CPUS)
+                .setType(Protos.Value.Type.SCALAR)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpuMem._1)))
+            .addResources(Protos.Resource.newBuilder()
+                .setName(MEM)
+                .setType(Protos.Value.Type.SCALAR)
+                .setScalar(Protos.Value.Scalar.newBuilder().setValue(cpuMem._2)))
+            .setContainer(cont)
+            .setCommand(Protos.CommandInfo.newBuilder()
+                .setShell(false)
+                .addArguments(STARTUP_SCRIPT)
+                .addArguments(String.valueOf(cpuMem._2.intValue())))
+            .build();
+    }
+
+    /**
      * Check slave resources and return resources infos.
      *
      * @param offer Offer request.


Mime
View raw message