aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject aurora git commit: Changing ResourceMapper interface arg type
Date Fri, 06 May 2016 18:22:21 GMT
Repository: aurora
Updated Branches:
  refs/heads/master f25a4b108 -> d702587d2


Changing ResourceMapper interface arg type

Reviewed at https://reviews.apache.org/r/47076/


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

Branch: refs/heads/master
Commit: d702587d29744e86b206cc5fb4b775600b980646
Parents: f25a4b1
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Fri May 6 11:22:05 2016 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Fri May 6 11:22:05 2016 -0700

----------------------------------------------------------------------
 .../scheduler/resources/ResourceManager.java    |  5 +++--
 .../scheduler/resources/ResourceMapper.java     | 16 +++++++-------
 .../aurora/scheduler/state/StateManager.java    |  3 +--
 .../scheduler/state/StateManagerImpl.java       |  4 ++--
 .../aurora/scheduler/state/TaskAssigner.java    |  5 ++---
 .../scheduler/resources/PortMapperTest.java     | 22 ++++++++++----------
 .../resources/ResourceManagerTest.java          | 10 ++++-----
 .../scheduler/state/StateManagerImplTest.java   |  7 ++-----
 .../scheduler/state/TaskAssignerImplTest.java   | 11 ++++++----
 9 files changed, 41 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java b/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
index 1b88fc3..943e8a4 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
@@ -20,6 +20,7 @@ import java.util.stream.StreamSupport;
 
 import com.google.common.collect.Iterables;
 
+import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
 import org.apache.aurora.scheduler.storage.entities.IResource;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
@@ -75,8 +76,8 @@ public final class ResourceManager {
    * @param task Task to get resource types from.
    * @return Set of {@link ResourceType} instances representing task resources.
    */
-  public static Set<ResourceType> getTaskResourceTypes(IScheduledTask task) {
-    return EnumSet.copyOf(task.getAssignedTask().getTask().getResources().stream()
+  public static Set<ResourceType> getTaskResourceTypes(IAssignedTask task) {
+    return EnumSet.copyOf(task.getTask().getResources().stream()
         .map(r -> fromResource(r))
         .collect(Collectors.toSet()));
   }

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/main/java/org/apache/aurora/scheduler/resources/ResourceMapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/ResourceMapper.java b/src/main/java/org/apache/aurora/scheduler/resources/ResourceMapper.java
index c06ce8d..c8e11a4 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceMapper.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceMapper.java
@@ -23,8 +23,8 @@ import com.google.common.collect.ContiguousSet;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Range;
 
-import org.apache.aurora.gen.ScheduledTask;
-import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
+import org.apache.aurora.gen.AssignedTask;
+import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
 import org.apache.mesos.Protos.Offer;
 
 import static java.util.stream.StreamSupport.stream;
@@ -46,13 +46,13 @@ public interface ResourceMapper {
    * @param task Task with requested resources.
    * @return A new task with updated mapping.
    */
-  IScheduledTask mapAndAssign(Offer offer, IScheduledTask task);
+  IAssignedTask mapAndAssign(Offer offer, IAssignedTask task);
 
   PortMapper PORT_MAPPER = new PortMapper();
 
   class PortMapper implements ResourceMapper {
     @Override
-    public IScheduledTask mapAndAssign(Offer offer, IScheduledTask task) {
+    public IAssignedTask mapAndAssign(Offer offer, IAssignedTask task) {
       List<Integer> availablePorts =
           stream(ResourceManager.getOfferResources(offer, PORTS).spliterator(), false)
               .flatMap(resource -> resource.getRanges().getRangeList().stream())
@@ -64,7 +64,7 @@ public interface ResourceMapper {
       Collections.shuffle(availablePorts);
 
       List<String> requestedPorts =
-          stream(ResourceManager.getTaskResources(task, PORTS).spliterator(), false)
+          stream(ResourceManager.getTaskResources(task.getTask(), PORTS).spliterator(), false)
             .map(e -> e.getNamedPort())
             .collect(Collectors.toList());
 
@@ -76,9 +76,9 @@ public interface ResourceMapper {
       Map<String, Integer> portMap =
           requestedPorts.stream().collect(Collectors.toMap(key -> key, value -> ports.next()));
 
-      ScheduledTask builder = task.newBuilder();
-      builder.getAssignedTask().setAssignedPorts(ImmutableMap.copyOf(portMap));
-      return IScheduledTask.build(builder);
+      AssignedTask builder = task.newBuilder();
+      builder.setAssignedPorts(ImmutableMap.copyOf(portMap));
+      return IAssignedTask.build(builder);
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/main/java/org/apache/aurora/scheduler/state/StateManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/state/StateManager.java b/src/main/java/org/apache/aurora/scheduler/state/StateManager.java
index 66bfd72..d395104 100644
--- a/src/main/java/org/apache/aurora/scheduler/state/StateManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/state/StateManager.java
@@ -20,7 +20,6 @@ import com.google.common.base.Optional;
 
 import org.apache.aurora.gen.ScheduleStatus;
 import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
-import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.apache.mesos.Protos.SlaveID;
 
@@ -71,7 +70,7 @@ public interface StateManager {
       String taskId,
       String slaveHost,
       SlaveID slaveId,
-      Function<IScheduledTask, IScheduledTask> resourceAssigner);
+      Function<IAssignedTask, IAssignedTask> resourceAssigner);
 
   /**
    * Inserts pending instances using {@code task} as their configuration. Tasks will immediately

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java b/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
index 2b4fac1..ffa9481 100644
--- a/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/state/StateManagerImpl.java
@@ -165,7 +165,7 @@ public class StateManagerImpl implements StateManager {
       String taskId,
       String slaveHost,
       SlaveID slaveId,
-      Function<IScheduledTask, IScheduledTask> resourceAssigner) {
+      Function<IAssignedTask, IAssignedTask> resourceAssigner) {
 
     checkNotBlank(taskId);
     checkNotBlank(slaveHost);
@@ -174,8 +174,8 @@ public class StateManagerImpl implements StateManager {
 
     IScheduledTask mutated = storeProvider.getUnsafeTaskStore().mutateTask(taskId,
         task -> {
-          task = resourceAssigner.apply(task);
           ScheduledTask builder = task.newBuilder();
+          builder.setAssignedTask(resourceAssigner.apply(task.getAssignedTask()).newBuilder());
           builder.getAssignedTask()
               .setSlaveHost(slaveHost)
               .setSlaveId(slaveId.getValue());

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/main/java/org/apache/aurora/scheduler/state/TaskAssigner.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/state/TaskAssigner.java b/src/main/java/org/apache/aurora/scheduler/state/TaskAssigner.java
index 1a3886f..b6e43d7 100644
--- a/src/main/java/org/apache/aurora/scheduler/state/TaskAssigner.java
+++ b/src/main/java/org/apache/aurora/scheduler/state/TaskAssigner.java
@@ -39,7 +39,6 @@ import org.apache.aurora.scheduler.resources.ResourceManager;
 import org.apache.aurora.scheduler.resources.ResourceType;
 import org.apache.aurora.scheduler.resources.Resources;
 import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
-import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.mesos.Protos.TaskInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -104,8 +103,8 @@ public interface TaskAssigner {
     }
 
     @VisibleForTesting
-    IScheduledTask mapAndAssignResources(Offer offer, IScheduledTask task) {
-      IScheduledTask assigned = task;
+    IAssignedTask mapAndAssignResources(Offer offer, IAssignedTask task) {
+      IAssignedTask assigned = task;
       for (ResourceType type : ResourceManager.getTaskResourceTypes(assigned)) {
         if (type.getMapper().isPresent()) {
           assigned = type.getMapper().get().mapAndAssign(offer, assigned);

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/test/java/org/apache/aurora/scheduler/resources/PortMapperTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/PortMapperTest.java b/src/test/java/org/apache/aurora/scheduler/resources/PortMapperTest.java
index c94f7a9..244c9de 100644
--- a/src/test/java/org/apache/aurora/scheduler/resources/PortMapperTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/resources/PortMapperTest.java
@@ -13,8 +13,8 @@
  */
 package org.apache.aurora.scheduler.resources;
 
-import org.apache.aurora.gen.ScheduledTask;
-import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
+import org.apache.aurora.gen.AssignedTask;
+import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
 import org.apache.mesos.Protos;
 import org.junit.Test;
 
@@ -29,17 +29,17 @@ import static org.junit.Assert.assertEquals;
 public class PortMapperTest {
   @Test
   public void testAssignNoPorts() {
-    ScheduledTask builder = makeTask("id", JOB).newBuilder();
-    builder.getAssignedTask().getTask().unsetResources();
-    builder.getAssignedTask().unsetAssignedPorts();
-    IScheduledTask task = IScheduledTask.build(builder);
+    AssignedTask builder = makeTask("id", JOB).newBuilder().getAssignedTask();
+    builder.getTask().unsetResources();
+    builder.unsetAssignedPorts();
+    IAssignedTask task = IAssignedTask.build(builder);
 
     assertEquals(task, PORT_MAPPER.mapAndAssign(offer(), task));
   }
 
   @Test(expected = IllegalStateException.class)
   public void testPortRangeScarcity() {
-    PORT_MAPPER.mapAndAssign(offer(), makeTask("id", JOB));
+    PORT_MAPPER.mapAndAssign(offer(), makeTask("id", JOB).getAssignedTask());
   }
 
   @Test
@@ -47,8 +47,8 @@ public class PortMapperTest {
     Protos.Offer offer = offer(mesosRange(PORTS, 1, 2, 3, 4, 5));
     assertEquals(
         1,
-        PORT_MAPPER.mapAndAssign(offer, makeTask("id", JOB))
-            .getAssignedTask().getAssignedPorts().size());
+        PORT_MAPPER.mapAndAssign(offer, makeTask("id", JOB).getAssignedTask())
+            .getAssignedPorts().size());
   }
 
   @Test
@@ -56,7 +56,7 @@ public class PortMapperTest {
     Protos.Offer offer = offer(mesosRange(PORTS, 1));
     assertEquals(
         1,
-        PORT_MAPPER.mapAndAssign(offer, makeTask("id", JOB))
-            .getAssignedTask().getAssignedPorts().size());
+        PORT_MAPPER.mapAndAssign(offer, makeTask("id", JOB).getAssignedTask())
+            .getAssignedPorts().size());
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
b/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
index c53a21d..914e553 100644
--- a/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
@@ -19,9 +19,9 @@ import java.util.Set;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
-import org.apache.aurora.gen.ScheduledTask;
+import org.apache.aurora.gen.AssignedTask;
+import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
 import org.apache.aurora.scheduler.storage.entities.IResource;
-import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.mesos.Protos;
 import org.apache.mesos.Protos.Offer;
 import org.apache.mesos.Protos.Value.Scalar;
@@ -82,12 +82,12 @@ public class ResourceManagerTest {
 
   @Test
   public void testGetTaskResourceTypes() {
-    ScheduledTask builder = makeTask("id", JOB).newBuilder();
-    builder.getAssignedTask().getTask().addToResources(namedPort("health"));
+    AssignedTask builder = makeTask("id", JOB).newBuilder().getAssignedTask();
+    builder.getTask().addToResources(namedPort("health"));
 
     assertEquals(
         EnumSet.allOf(ResourceType.class),
-        ResourceManager.getTaskResourceTypes(IScheduledTask.build(builder)));
+        ResourceManager.getTaskResourceTypes(IAssignedTask.build(builder)));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java b/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
index 2370178..fbcc400 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
@@ -52,6 +52,7 @@ import org.apache.aurora.scheduler.storage.AttributeStore;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.storage.Storage.MutateWork.NoResult;
 import org.apache.aurora.scheduler.storage.db.DbUtil;
+import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
 import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
@@ -564,10 +565,6 @@ public class StateManagerImplTest extends EasyMockTest {
         taskId,
         host.getHost(),
         SlaveID.newBuilder().setValue(host.getSlaveId()).build(),
-        e -> {
-          ScheduledTask builder = e.newBuilder();
-          builder.getAssignedTask().setAssignedPorts(ports);
-          return IScheduledTask.build(builder);
-        }));
+        e -> IAssignedTask.build(e.newBuilder().setAssignedPorts(ports))));
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/d702587d/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java b/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java
index ca10323..81baa78 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/TaskAssignerImplTest.java
@@ -20,9 +20,9 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
 import org.apache.aurora.common.testing.easymock.EasyMockTest;
+import org.apache.aurora.gen.AssignedTask;
 import org.apache.aurora.gen.HostAttributes;
 import org.apache.aurora.gen.JobKey;
-import org.apache.aurora.gen.ScheduledTask;
 import org.apache.aurora.gen.TaskConfig;
 import org.apache.aurora.scheduler.HostOffer;
 import org.apache.aurora.scheduler.TierManager;
@@ -36,6 +36,7 @@ import org.apache.aurora.scheduler.mesos.MesosTaskFactory;
 import org.apache.aurora.scheduler.offers.OfferManager;
 import org.apache.aurora.scheduler.resources.Resources;
 import org.apache.aurora.scheduler.state.TaskAssigner.TaskAssignerImpl;
+import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
 import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
@@ -293,12 +294,14 @@ public class TaskAssignerImplTest extends EasyMockTest {
 
   @Test
   public void testResourceMapperCallback() {
-    ScheduledTask builder = TASK.newBuilder();
-    builder.getAssignedTask().unsetAssignedPorts();
+    AssignedTask builder = TASK.newBuilder().getAssignedTask();
+    builder.unsetAssignedPorts();
 
     control.replay();
 
-    assertEquals(TASK, assigner.mapAndAssignResources(MESOS_OFFER, IScheduledTask.build(builder)));
+    assertEquals(
+        TASK.getAssignedTask(),
+        assigner.mapAndAssignResources(MESOS_OFFER, IAssignedTask.build(builder)));
   }
 
   private void expectAssignTask(Offer offer) {


Mime
View raw message