aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jco...@apache.org
Subject aurora git commit: Expose task tier as a label on TaskInfo proto.
Date Tue, 04 Oct 2016 21:36:22 GMT
Repository: aurora
Updated Branches:
  refs/heads/master ebdaa6b86 -> 251ef5a56


Expose task tier as a label on TaskInfo proto.

This will allow for other consumers of the TaskInfo (e.g. a custom mesos QoS controller) to
alter
their behavior based on a task's tier.

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


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

Branch: refs/heads/master
Commit: 251ef5a56cfd081b4224f3653cd36b544456ba5d
Parents: ebdaa6b
Author: Joshua Cohen <jcohen@apache.org>
Authored: Tue Oct 4 16:36:05 2016 -0500
Committer: Joshua Cohen <jcohen@apache.org>
Committed: Tue Oct 4 16:36:05 2016 -0500

----------------------------------------------------------------------
 RELEASE-NOTES.md                                |  3 ++
 .../scheduler/mesos/MesosTaskFactory.java       | 34 +++++++++++---------
 .../mesos/MesosTaskFactoryImplTest.java         | 17 ++++++++++
 3 files changed, 38 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/251ef5a5/RELEASE-NOTES.md
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 49c03e8..97f05d5 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -1,6 +1,9 @@
 0.17.0 (Not yet released)
 =========================
 
+### New/updated:
+- A task's tier is now mapped to a label on the Mesos `TaskInfo` proto.
+
 ### Deprecations and removals:
 
 - The scheduler flag `-zk_use_curator` has been removed. If you have never set the flag and
are

http://git-wip-us.apache.org/repos/asf/aurora/blob/251ef5a5/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java b/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
index 68830ce..9038c36 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
@@ -15,7 +15,6 @@ package org.apache.aurora.scheduler.mesos;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.stream.Collectors;
 
 import javax.inject.Inject;
@@ -23,11 +22,9 @@ import javax.inject.Inject;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.protobuf.ByteString;
 
-import org.apache.aurora.GuavaUtils;
 import org.apache.aurora.Protobufs;
 import org.apache.aurora.codec.ThriftBinaryCodec;
 import org.apache.aurora.scheduler.TierManager;
@@ -45,7 +42,6 @@ import org.apache.aurora.scheduler.storage.entities.IDockerImage;
 import org.apache.aurora.scheduler.storage.entities.IImage;
 import org.apache.aurora.scheduler.storage.entities.IJobKey;
 import org.apache.aurora.scheduler.storage.entities.IMesosContainer;
-import org.apache.aurora.scheduler.storage.entities.IMetadata;
 import org.apache.aurora.scheduler.storage.entities.IServerInfo;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.apache.mesos.Protos;
@@ -87,15 +83,22 @@ public interface MesosTaskFactory {
   class MesosTaskFactoryImpl implements MesosTaskFactory {
     private static final Logger LOG = LoggerFactory.getLogger(MesosTaskFactoryImpl.class);
 
+    private static final String AURORA_LABEL_PREFIX = "org.apache.aurora";
+
     @VisibleForTesting
-    static final String METADATA_LABEL_PREFIX = "org.apache.aurora.metadata.";
+    static final String METADATA_LABEL_PREFIX = AURORA_LABEL_PREFIX + ".metadata.";
 
     @VisibleForTesting
     static final String DEFAULT_PORT_PROTOCOL = "TCP";
 
+    // N.B. We intentionally do not prefix this label. It was added when the explicit source
field
+    // was removed from the ExecutorInfo proto and named "source" per guidance from Mesos
devs.
     @VisibleForTesting
     static final String SOURCE_LABEL = "source";
 
+    @VisibleForTesting
+    static final String TIER_LABEL = AURORA_LABEL_PREFIX + ".tier";
+
     private final ExecutorSettings executorSettings;
     private final TierManager tierManager;
     private final IServerInfo serverInfo;
@@ -184,7 +187,7 @@ public interface MesosTaskFactory {
           .setSlaveId(offer.getSlaveId())
           .addAllResources(resources);
 
-      configureTaskLabels(config.getMetadata(), taskBuilder);
+      configureTaskLabels(config, taskBuilder);
 
       if (executorSettings.shouldPopulateDiscoverInfo()) {
         configureDiscoveryInfos(task, taskBuilder);
@@ -330,17 +333,16 @@ public interface MesosTaskFactory {
       return builder;
     }
 
-    private void configureTaskLabels(Set<IMetadata> metadata, TaskInfo.Builder taskBuilder)
{
-      ImmutableSet<Label> labels = metadata.stream()
-          .map(m -> Label.newBuilder()
-              .setKey(METADATA_LABEL_PREFIX + m.getKey())
-              .setValue(m.getValue())
-              .build())
-          .collect(GuavaUtils.toImmutableSet());
+    private void configureTaskLabels(ITaskConfig config, TaskInfo.Builder taskBuilder) {
+      Labels.Builder labelsBuilder = Labels.newBuilder();
+      labelsBuilder.addLabels(Label.newBuilder().setKey(TIER_LABEL).setValue(config.getTier()));
 
-      if (!labels.isEmpty()) {
-        taskBuilder.setLabels(Labels.newBuilder().addAllLabels(labels));
-      }
+      config.getMetadata().stream().forEach(m -> labelsBuilder.addLabels(Label.newBuilder()
+          .setKey(METADATA_LABEL_PREFIX + m.getKey())
+          .setValue(m.getValue())
+          .build()));
+
+      taskBuilder.setLabels(labelsBuilder);
     }
 
     private void configureDiscoveryInfos(IAssignedTask task, TaskInfo.Builder taskBuilder)
{

http://git-wip-us.apache.org/repos/asf/aurora/blob/251ef5a5/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
b/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
index b5575a7..bd052ab 100644
--- a/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
@@ -63,10 +63,13 @@ import org.junit.Test;
 
 import static org.apache.aurora.gen.apiConstants.TASK_FILESYSTEM_MOUNT_POINT;
 import static org.apache.aurora.scheduler.base.TaskTestUtil.DEV_TIER;
+import static org.apache.aurora.scheduler.base.TaskTestUtil.PREFERRED_TIER;
+import static org.apache.aurora.scheduler.base.TaskTestUtil.PROD_TIER_NAME;
 import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
 import static org.apache.aurora.scheduler.mesos.MesosTaskFactory.MesosTaskFactoryImpl.DEFAULT_PORT_PROTOCOL;
 import static org.apache.aurora.scheduler.mesos.MesosTaskFactory.MesosTaskFactoryImpl.METADATA_LABEL_PREFIX;
 import static org.apache.aurora.scheduler.mesos.MesosTaskFactory.MesosTaskFactoryImpl.SOURCE_LABEL;
+import static org.apache.aurora.scheduler.mesos.MesosTaskFactory.MesosTaskFactoryImpl.TIER_LABEL;
 import static org.apache.aurora.scheduler.mesos.MesosTaskFactory.MesosTaskFactoryImpl.getInstanceSourceName;
 import static org.apache.aurora.scheduler.mesos.MesosTaskFactory.MesosTaskFactoryImpl.getInverseJobSourceName;
 import static org.apache.aurora.scheduler.mesos.TaskExecutors.NO_OVERHEAD_EXECUTOR;
@@ -375,6 +378,7 @@ public class MesosTaskFactoryImplTest extends EasyMockTest {
 
     TaskInfo task = taskFactory.createFrom(TASK, OFFER_THERMOS_EXECUTOR);
     ImmutableSet<String> labels = task.getLabels().getLabelsList().stream()
+        .filter(l -> l.getKey().startsWith(METADATA_LABEL_PREFIX))
         .map(l -> l.getKey() + l.getValue())
         .collect(GuavaUtils.toImmutableSet());
 
@@ -387,6 +391,19 @@ public class MesosTaskFactoryImplTest extends EasyMockTest {
   }
 
   @Test
+  public void testTierLabel() {
+    expect(tierManager.getTier(TASK.getTask())).andReturn(PREFERRED_TIER);
+    taskFactory = new MesosTaskFactoryImpl(config, tierManager, SERVER_INFO);
+
+    control.replay();
+
+    TaskInfo task = taskFactory.createFrom(TASK, OFFER_THERMOS_EXECUTOR);
+
+    assertTrue(task.getLabels().getLabelsList().stream().anyMatch(
+        l -> l.getKey().equals(TIER_LABEL) && l.getValue().equals(PROD_TIER_NAME)));
+  }
+
+  @Test
   public void testDockerTaskWithoutExecutor() {
     AssignedTask builder = TASK.newBuilder();
     builder.getTask()


Mime
View raw message