You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/06/26 17:58:05 UTC

incubator-reef git commit: [REEF-409] Pass the rackName from the runtime to the top of REEF stack

Repository: incubator-reef
Updated Branches:
  refs/heads/master c491e6f5f -> d5baddfdd


[REEF-409] Pass the rackName from the runtime to the top of REEF stack

This work bubbles up the rack information from the runtime (after the
resource is allocated) towards the evaluators allocation handlers.
The ResourceAllocationEvent interface now includes an optional rack
name, which is populated by the respective runtimes when the resource
is allocated.

The ProcessContainer is created with a null rack for now, it ends up
using the default one. Added a unit test that tests the whole cycle,
checking if the set rack is the one retrieved.

JIRA:
  [REEF-409] (https://issues.apache.org/jira/browse/REEF-409)

Pull Request:
  This closes  #244


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

Branch: refs/heads/master
Commit: d5baddfdd50ef640a36c18b3d871d34c55ca62a0
Parents: c491e6f
Author: Ignacio Cano <na...@gmail.com>
Authored: Thu Jun 25 09:39:39 2015 -0700
Committer: Markus Weimer <we...@apache.org>
Committed: Fri Jun 26 08:55:24 2015 -0700

----------------------------------------------------------------------
 .../ResourceAllocationEvent.java                |   6 +
 .../ResourceAllocationEventImpl.java            |  18 +++
 .../client/DriverConfigurationProvider.java     |  18 ++-
 .../local/client/LocalRuntimeConfiguration.java |   7 +-
 .../local/client/parameters/RackNames.java      |  33 ++++++
 .../reef/runtime/local/driver/Container.java    |   6 +
 .../runtime/local/driver/ContainerManager.java  |  18 ++-
 .../local/driver/LocalDriverConfiguration.java  |   7 ++
 .../runtime/local/driver/ProcessContainer.java  |  11 +-
 .../runtime/local/driver/ResourceManager.java   |   1 +
 .../tests/rack/awareness/RackNameParameter.java |  27 +++++
 .../org/apache/reef/tests/TestEnvironment.java  |   1 +
 .../rack/awareness/RackAwareEvaluatorTest.java  | 109 +++++++++++++++++++
 .../awareness/RackAwareEvaluatorTestDriver.java |  58 ++++++++++
 .../reef/tests/rack/awareness/package-info.java |  22 ++++
 15 files changed, 333 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEvent.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEvent.java
index fd9ad1d..e507d90 100644
--- a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEvent.java
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEvent.java
@@ -51,4 +51,10 @@ public interface ResourceAllocationEvent {
    * @return Number of virtual CPU cores on the resource
    */
   Optional<Integer> getVirtualCores();
+
+  /**
+   * @return Rack name of the resource
+   */
+  Optional<String> getRackName();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEventImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEventImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEventImpl.java
index 85df55a..f8c5ade 100644
--- a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEventImpl.java
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationEventImpl.java
@@ -30,12 +30,15 @@ public final class ResourceAllocationEventImpl implements ResourceAllocationEven
   private final int resourceMemory;
   private final String nodeId;
   private final Optional<Integer> virtualCores;
+  private final Optional<String> rackName;
+
 
   private ResourceAllocationEventImpl(final Builder builder) {
     this.identifier = BuilderUtils.notNull(builder.identifier);
     this.resourceMemory = BuilderUtils.notNull(builder.resourceMemory);
     this.nodeId = BuilderUtils.notNull(builder.nodeId);
     this.virtualCores = Optional.ofNullable(builder.virtualCores);
+    this.rackName = Optional.ofNullable(builder.rackName);
   }
 
   @Override
@@ -58,6 +61,11 @@ public final class ResourceAllocationEventImpl implements ResourceAllocationEven
     return virtualCores;
   }
 
+  @Override
+  public Optional<String> getRackName() {
+    return rackName;
+  }
+
   public static Builder newBuilder() {
     return new Builder();
   }
@@ -70,6 +78,8 @@ public final class ResourceAllocationEventImpl implements ResourceAllocationEven
     private Integer resourceMemory;
     private String nodeId;
     private Integer virtualCores;
+    private String rackName;
+
 
     /**
      * @see ResourceAllocationEvent#getIdentifier()
@@ -103,6 +113,14 @@ public final class ResourceAllocationEventImpl implements ResourceAllocationEven
       return this;
     }
 
+    /**
+     * @see ResourceAllocationEvent#getRackName()
+     */
+    public Builder setRackName(final String rackName) {
+      this.rackName = rackName;
+      return this;
+    }
+
     @Override
     public ResourceAllocationEvent build() {
       return new ResourceAllocationEventImpl(this);

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverConfigurationProvider.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverConfigurationProvider.java
index 321ff86..a2c2fd9 100644
--- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverConfigurationProvider.java
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverConfigurationProvider.java
@@ -20,13 +20,17 @@ package org.apache.reef.runtime.local.client;
 
 import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
 import org.apache.reef.runtime.local.client.parameters.MaxNumberOfEvaluators;
+import org.apache.reef.runtime.local.client.parameters.RackNames;
 import org.apache.reef.runtime.local.driver.LocalDriverConfiguration;
 import org.apache.reef.tang.Configuration;
 import org.apache.reef.tang.Configurations;
 import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
 
 import javax.inject.Inject;
+
 import java.io.File;
+import java.util.Set;
 
 /**
  * Helper class that assembles the driver configuration when run on the local runtime.
@@ -35,24 +39,30 @@ public final class DriverConfigurationProvider {
 
   private final int maxEvaluators;
   private final double jvmHeapSlack;
+  private final Set<String> rackNames;
 
   @Inject
   DriverConfigurationProvider(@Parameter(MaxNumberOfEvaluators.class) final int maxEvaluators,
-                              @Parameter(JVMHeapSlack.class) final double jvmHeapSlack) {
+                              @Parameter(JVMHeapSlack.class) final double jvmHeapSlack,
+                              @Parameter(RackNames.class) final Set<String> rackNames) {
     this.maxEvaluators = maxEvaluators;
     this.jvmHeapSlack = jvmHeapSlack;
+    this.rackNames = rackNames;
   }
 
   private Configuration getDriverConfiguration(final File jobFolder,
                                                final String clientRemoteId,
                                                final String jobId) {
-    return LocalDriverConfiguration.CONF
+    ConfigurationModule configModule = LocalDriverConfiguration.CONF
         .set(LocalDriverConfiguration.MAX_NUMBER_OF_EVALUATORS, this.maxEvaluators)
         .set(LocalDriverConfiguration.ROOT_FOLDER, jobFolder.getAbsolutePath())
         .set(LocalDriverConfiguration.JVM_HEAP_SLACK, this.jvmHeapSlack)
         .set(LocalDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, clientRemoteId)
-        .set(LocalDriverConfiguration.JOB_IDENTIFIER, jobId)
-        .build();
+        .set(LocalDriverConfiguration.JOB_IDENTIFIER, jobId);
+    for (final String rackName : rackNames) {
+      configModule = configModule.set(LocalDriverConfiguration.RACK_NAMES, rackName);
+    }
+    return configModule.build();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java
index 57ae932..0e62836 100644
--- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java
@@ -25,6 +25,7 @@ import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
 import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
 import org.apache.reef.runtime.local.LocalClasspathProvider;
 import org.apache.reef.runtime.local.client.parameters.MaxNumberOfEvaluators;
+import org.apache.reef.runtime.local.client.parameters.RackNames;
 import org.apache.reef.runtime.local.client.parameters.RootFolder;
 import org.apache.reef.tang.ConfigurationProvider;
 import org.apache.reef.tang.formats.ConfigurationModule;
@@ -65,7 +66,10 @@ public class LocalRuntimeConfiguration extends ConfigurationModuleBuilder {
    */
   public static final OptionalImpl<ConfigurationProvider> DRIVER_CONFIGURATION_PROVIDERS = new OptionalImpl<>();
 
-
+  /**
+   * The rack names that will be available in the local runtime
+   */
+  public static final OptionalParameter<String> RACK_NAMES = new OptionalParameter<>();
 
 
   /**
@@ -82,6 +86,7 @@ public class LocalRuntimeConfiguration extends ConfigurationModuleBuilder {
       .bindNamedParameter(RootFolder.class, RUNTIME_ROOT_FOLDER)
       .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
       .bindSetEntry(DriverConfigurationProviders.class, DRIVER_CONFIGURATION_PROVIDERS)
+      .bindSetEntry(RackNames.class, RACK_NAMES)
       .build();
 
 

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RackNames.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RackNames.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RackNames.java
new file mode 100644
index 0000000..e070d58
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RackNames.java
@@ -0,0 +1,33 @@
+/*
+ * 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.reef.runtime.local.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * The name of the default racks available in the local runtime.
+ */
+@NamedParameter(short_name = "racks", doc = "The name of the racks the containers will be placed on", default_values = {RackNames.DEFAULT_RACK_NAME})
+public final class RackNames implements Name<Set<String>> {
+    private RackNames() {}
+    public static final String DEFAULT_RACK_NAME = "/default-rack";
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java
index 5b77b26..ac36d1e 100644
--- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java
@@ -82,4 +82,10 @@ interface Container extends AutoCloseable {
    */
   @Override
   void close();
+
+  /**
+   * @return the rack name where this container is located
+   */
+  String getRackName();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java
index cc13327..49b4242 100644
--- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java
@@ -28,6 +28,7 @@ import org.apache.reef.runtime.common.driver.resourcemanager.NodeDescriptorEvent
 import org.apache.reef.runtime.common.files.REEFFileNames;
 import org.apache.reef.runtime.common.utils.RemoteManager;
 import org.apache.reef.runtime.local.client.parameters.MaxNumberOfEvaluators;
+import org.apache.reef.runtime.local.client.parameters.RackNames;
 import org.apache.reef.runtime.local.client.parameters.RootFolder;
 import org.apache.reef.runtime.local.process.ReefRunnableProcessObserver;
 import org.apache.reef.tang.annotations.Parameter;
@@ -40,11 +41,13 @@ import org.apache.reef.wake.time.runtime.event.RuntimeStart;
 import org.apache.reef.wake.time.runtime.event.RuntimeStop;
 
 import javax.inject.Inject;
+
 import java.io.File;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -74,6 +77,9 @@ final class ContainerManager implements AutoCloseable {
   private final REEFFileNames fileNames;
   private final ReefRunnableProcessObserver processObserver;
   private final String localAddress;
+  // for now is a single rack, it will be a set in the next commit
+  private final String availableRack;
+
 
   @Inject
   ContainerManager(
@@ -82,8 +88,9 @@ final class ContainerManager implements AutoCloseable {
       final REEFFileNames fileNames,
       @Parameter(MaxNumberOfEvaluators.class) final int capacity,
       @Parameter(RootFolder.class) final String rootFolderName,
-      @Parameter(RuntimeParameters.NodeDescriptorHandler.class) final 
+      @Parameter(RuntimeParameters.NodeDescriptorHandler.class) final
       EventHandler<NodeDescriptorEvent> nodeDescriptorHandler,
+      @Parameter(RackNames.class) final Set<String> rackNames,
       final ReefRunnableProcessObserver processObserver,
       final LocalAddressProvider localAddressProvider) {
     this.capacity = capacity;
@@ -93,6 +100,10 @@ final class ContainerManager implements AutoCloseable {
     this.nodeDescriptorHandler = nodeDescriptorHandler;
     this.rootFolder = new File(rootFolderName);
     this.localAddress = localAddressProvider.getLocalAddress();
+    // this is safe, we are guaranteed that this is not empty (default value)
+    // we will just 1 rack for now, the next commit will include creating
+    // containers in different racks.
+    this.availableRack = rackNames.iterator().next();
 
     LOG.log(Level.FINEST, "Initializing Container Manager with {0} containers", capacity);
 
@@ -133,7 +144,7 @@ final class ContainerManager implements AutoCloseable {
       this.freeNodeList.add(id);
       nodeDescriptorHandler.onNext(NodeDescriptorEventImpl.newBuilder()
           .setIdentifier(id)
-          .setRackName("/default-rack")
+          .setRackName(availableRack)
           .setHostName(this.localAddress)
           .setPort(i)
           .setMemorySize(512) // TODO: Find the actual system memory on this machine.
@@ -151,8 +162,9 @@ final class ContainerManager implements AutoCloseable {
       final String processID = nodeId + "-" + String.valueOf(System.currentTimeMillis());
       final File processFolder = new File(this.rootFolder, processID);
       processFolder.mkdirs();
+      // setting rackName to null for now, will end up using the default one
       final ProcessContainer container = new ProcessContainer(
-          this.errorHandlerRID, nodeId, processID, processFolder, megaBytes, numberOfCores, this.fileNames, this.processObserver);
+          this.errorHandlerRID, nodeId, processID, processFolder, megaBytes, numberOfCores, availableRack, this.fileNames, this.processObserver);
       this.containers.put(container.getContainerID(), container);
       LOG.log(Level.FINE, "Allocated {0}", container.getContainerID());
       return container;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java
index f3cb6bf..8cbcc5f 100644
--- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java
@@ -27,6 +27,7 @@ import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
 import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
 import org.apache.reef.runtime.local.LocalClasspathProvider;
 import org.apache.reef.runtime.local.client.parameters.MaxNumberOfEvaluators;
+import org.apache.reef.runtime.local.client.parameters.RackNames;
 import org.apache.reef.runtime.local.client.parameters.RootFolder;
 import org.apache.reef.tang.formats.ConfigurationModule;
 import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
@@ -52,6 +53,11 @@ public class LocalDriverConfiguration extends ConfigurationModuleBuilder {
   public static final OptionalParameter<Double> JVM_HEAP_SLACK = new OptionalParameter<>();
 
   /**
+  * The rack names that will be available in the local runtime
+  */
+  public static final OptionalParameter<String> RACK_NAMES = new OptionalParameter<>();
+
+  /**
    * The remote identifier to use for communications back to the client.
    */
   public static final OptionalParameter<String> CLIENT_REMOTE_IDENTIFIER = new OptionalParameter<>();
@@ -70,6 +76,7 @@ public class LocalDriverConfiguration extends ConfigurationModuleBuilder {
       .bindNamedParameter(MaxNumberOfEvaluators.class, MAX_NUMBER_OF_EVALUATORS)
       .bindNamedParameter(RootFolder.class, ROOT_FOLDER)
       .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+      .bindSetEntry(RackNames.class, RACK_NAMES)
       .bindImplementation(RuntimeClasspathProvider.class, LocalClasspathProvider.class)
       .build();
 }

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java
index da5d157..fe7f19c 100644
--- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java
@@ -49,6 +49,7 @@ final class ProcessContainer implements Container {
   private final String containedID;
   private final int megaBytes;
   private final int numberOfCores;
+  private final String rackName;
   private final REEFFileNames fileNames;
   private final File reefFolder;
   private final File localFolder;
@@ -69,6 +70,7 @@ final class ProcessContainer implements Container {
                    final File folder,
                    final int megaBytes,
                    final int numberOfCores,
+                   final String rackName,
                    final REEFFileNames fileNames,
                    final ReefRunnableProcessObserver processObserver) {
     this.errorHandlerRID = errorHandlerRID;
@@ -77,6 +79,7 @@ final class ProcessContainer implements Container {
     this.folder = folder;
     this.megaBytes = megaBytes;
     this.numberOfCores = numberOfCores;
+    this.rackName = rackName;
     this.fileNames = fileNames;
     this.processObserver = processObserver;
     this.reefFolder = new File(folder, fileNames.getREEFFolderName());
@@ -144,6 +147,11 @@ final class ProcessContainer implements Container {
   }
 
   @Override
+  public String getRackName() {
+    return this.rackName;
+  }
+
+  @Override
   public File getFolder() {
     return this.folder;
   }
@@ -172,7 +180,8 @@ final class ProcessContainer implements Container {
         "containedID='" + containedID + '\'' +
         ", nodeID='" + nodeID + '\'' +
         ", errorHandlerRID='" + errorHandlerRID + '\'' +
-        ", folder=" + folder +
+        ", folder=" + folder + '\'' +
+        ", rack=" + rackName +
         '}';
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java
index ace6c6a..557428e 100644
--- a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java
@@ -221,6 +221,7 @@ public final class ResourceManager {
               .setNodeId(container.getNodeID())
               .setResourceMemory(container.getMemory())
               .setVirtualCores(container.getNumberOfCores())
+              .setRackName(container.getRackName())
               .build();
 
       LOG.log(Level.FINEST, "Allocating container: {0}", container);

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-tests/src/main/java/org/apache/reef/tests/rack/awareness/RackNameParameter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/rack/awareness/RackNameParameter.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/rack/awareness/RackNameParameter.java
new file mode 100644
index 0000000..e6504cd
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/rack/awareness/RackNameParameter.java
@@ -0,0 +1,27 @@
+/*
+ * 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.reef.tests.rack.awareness;
+import org.apache.reef.runtime.local.client.parameters.RackNames;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(default_value = RackNames.DEFAULT_RACK_NAME, short_name = "rack")
+public class RackNameParameter implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
index 8dddcdf..5522d4e 100644
--- a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
@@ -55,4 +55,5 @@ public interface TestEnvironment {
   int getTestTimeout();
 
   LauncherStatus run(final Configuration driverConfiguration);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTest.java
new file mode 100644
index 0000000..b9a7bd6
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.reef.tests.rack.awareness;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.parameters.RackNames;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.LocalTestEnvironment;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether an Evaluator receives its rack information.
+ * The available racks can be configured in the local runtime.
+ */
+public final class RackAwareEvaluatorTest {
+
+  private static final String RACK1 = "rack1";
+  // runs on the local runtime
+  private final TestEnvironment testEnvironment = new LocalTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  /**
+  * Tests whether the runtime passes the rack information to the driver
+  * The success scenario is if it receives the default rack, fails otherwise
+  */
+  @Test
+  public void testRackAwareEvaluatorRunningOnDefaultRack() {
+    //Given
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_RackAwareEvaluator")
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(RackAwareEvaluatorTestDriver.class))
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, RackAwareEvaluatorTestDriver.EvaluatorAllocatedHandler.class)
+        .build();
+
+    // When
+    final LauncherStatus status = this.testEnvironment.run(driverConfiguration);
+    // Then
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+  /**
+   * Test whether the runtime passes the rack information to the driver
+   * The success scenario is if it receives rack1, fails otherwise
+   */
+  @Test
+  public void testRackAwareEvaluatorRunningOnRack1() throws InjectionException {
+    //Given
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_RackAwareEvaluator")
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(RackAwareEvaluatorTestDriver.class))
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, RackAwareEvaluatorTestDriver.EvaluatorAllocatedHandler.class)
+        .build();
+
+    // update the drive config with the rack to assert on
+    final Configuration testDriverConfig = Tang.Factory.getTang().newConfigurationBuilder(driverConfiguration)
+        .bindNamedParameter(RackNameParameter.class, RACK1).build();
+
+    // update the runtime config with the rack available using the config module
+    final Configuration testRuntimeConfig = Tang.Factory.getTang()
+        .newConfigurationBuilder(this.testEnvironment.getRuntimeConfiguration()).bindSetEntry(RackNames.class, RACK1)
+        .build();
+
+    // When
+    final LauncherStatus status = DriverLauncher.getLauncher(testRuntimeConfig)
+                                              .run(testDriverConfig, this.testEnvironment.getTestTimeout());
+    // Then
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTestDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTestDriver.java
new file mode 100644
index 0000000..cdf1be8
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/RackAwareEvaluatorTestDriver.java
@@ -0,0 +1,58 @@
+/*
+ * 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.reef.tests.rack.awareness;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import javax.inject.Inject;
+
+@Unit
+final class RackAwareEvaluatorTestDriver {
+
+
+
+  private final String expectedRackName;
+
+  @Inject
+  RackAwareEvaluatorTestDriver(@Parameter(RackNameParameter.class) final String rackName) {
+    this.expectedRackName = rackName;
+  }
+
+  /**
+   * Verifies whether the rack received is the default rack
+   */
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+
+      final String actual = allocatedEvaluator.getEvaluatorDescriptor().getNodeDescriptor().getRackDescriptor().getName();
+      if (!expectedRackName.equals(actual)) {
+        throw new DriverSideFailure("The rack received is different that the expected one, received " + actual
+            + " expected " + expectedRackName);
+      }
+      allocatedEvaluator.close();
+    }
+  }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/d5baddfd/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/package-info.java
new file mode 100644
index 0000000..2cbd7dc
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/rack/awareness/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+/**
+ * Tests whether the rack information is correctly carried from the runtime to the Driver
+ */
+package org.apache.reef.tests.rack.awareness;