SAMZA-922 - Host Affinity - Bug in SamzaContainerRequest causes (recoverable) excepti...
authorJacob Maes <jacob.maes@gmail.com>
Mon, 18 Apr 2016 23:18:36 +0000 (16:18 -0700)
committerNavina Ramesh <nramesh@linkedin.com>
Mon, 18 Apr 2016 23:18:36 +0000 (16:18 -0700)
samza-yarn/src/main/java/org/apache/samza/job/yarn/SamzaContainerRequest.java
samza-yarn/src/test/java/org/apache/samza/job/yarn/TestSamzaContainerRequest.java

index a84e53f..4a04eb6 100644 (file)
@@ -48,7 +48,7 @@ public class SamzaContainerRequest implements Comparable<SamzaContainerRequest>
     this.capability = Resource.newInstance(memoryMb, cpuCores);
     this.priority = Priority.newInstance(priority);
     this.expectedContainerId = expectedContainerId;
-    if (preferredHost == null) {
+    if (preferredHost == null || preferredHost.equals(ANY_HOST)) {
       this.preferredHost = ANY_HOST;
       this.issuedRequest = new AMRMClient.ContainerRequest(capability, null, null, this.priority);
     } else {
@@ -63,8 +63,8 @@ public class SamzaContainerRequest implements Comparable<SamzaContainerRequest>
     this.requestTimestamp = System.currentTimeMillis();
   }
 
-  // Convenience class for unit testing
-  public SamzaContainerRequest(int expectedContainerId, String preferredHost) {
+  // Convenience constructor for unit testing
+  protected SamzaContainerRequest(int expectedContainerId, String preferredHost) {
     this(
         AbstractContainerAllocator.DEFAULT_CONTAINER_MEM,
         AbstractContainerAllocator.DEFAULT_CPU_CORES,
index aefae65..ad0f4d3 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.samza.job.yarn;
 import org.junit.Test;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 public class TestSamzaContainerRequest {
@@ -38,6 +39,14 @@ public class TestSamzaContainerRequest {
     SamzaContainerRequest request1 = new SamzaContainerRequest(1, "abc");
     assertNotNull(request1.getPreferredHost());
     assertTrue(request1.getPreferredHost().equals("abc"));
+  }
+
+  @Test
+  public void testAnyHostIsNotPassedToYarnRequest() {
+    SamzaContainerRequest request = new SamzaContainerRequest(0, null);
+    assertNull(request.getIssuedRequest().getNodes());
 
+    SamzaContainerRequest request1 = new SamzaContainerRequest(1, ANY_HOST);
+    assertNull(request1.getIssuedRequest().getNodes());
   }
 }