-
Notifications
You must be signed in to change notification settings - Fork 68
accept offers for default role * in addition to the specified mesosRole #124
Changes from 5 commits
4ecf73d
7fc5196
dc6da7e
8c9edd1
ea4b2a2
72c1ca9
8518e4d
c252cdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,25 @@ | |
package io.mesosphere.mesos.util; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.base.Optional; | ||
import com.google.common.base.Predicate; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableListMultimap; | ||
import io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos; | ||
import io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.*; | ||
|
||
import org.apache.mesos.Protos; | ||
import org.apache.mesos.Protos.Resource; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
|
||
import static com.google.common.collect.FluentIterable.from; | ||
import static com.google.common.collect.Lists.newArrayList; | ||
import static io.mesosphere.mesos.util.ProtoUtils.*; | ||
|
||
public final class CassandraFrameworkProtosUtils { | ||
|
||
|
@@ -172,6 +180,83 @@ public static CassandraNode.Builder removeTask(@NotNull final CassandraNode cass | |
return builder; | ||
} | ||
|
||
@NotNull | ||
public static Function<Resource, TreeSet<Long>> resourceToPortSet() { | ||
return new Function<Resource, TreeSet<Long>>() { | ||
@Override | ||
@NotNull | ||
public TreeSet<Long> apply(@Nullable Resource resource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
return resourceValueRange(Optional.fromNullable(resource)); | ||
} | ||
}; | ||
} | ||
|
||
public static Predicate<Resource> containsPorts(final Iterable<Long> ports) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please annotate |
||
return new Predicate<Resource>() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make a private static final inner class of this predicate with a single constructor argument of the passed in See https://github.com/mesosphere/cassandra-mesos/blob/master/cassandra-mesos-model/src/main/java/io/mesosphere/mesos/util/CassandraFrameworkProtosUtils.java#L236-L248 for an example of how this had been done previously. |
||
@Override | ||
public boolean apply(Resource resource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
TreeSet<Long> portsInResource = resourceValueRange(Optional.fromNullable(resource)); | ||
return portsInResource.containsAll(newArrayList(ports)); | ||
} | ||
}; | ||
} | ||
|
||
public static ImmutableListMultimap<String, Resource> resourcesForRoleAndOffer(String role, Protos.Offer offer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
return from(offer.getResourcesList()) | ||
.filter(resourceHasExpectedRole(role)) | ||
.index(resourceToName()); | ||
} | ||
|
||
public static Predicate<Resource> scalarValueAtLeast(final long v) { | ||
return new Predicate<Resource>() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make a private static final inner class of this predicate with a single constructor argument of the passed in See https://github.com/mesosphere/cassandra-mesos/blob/master/cassandra-mesos-model/src/main/java/io/mesosphere/mesos/util/CassandraFrameworkProtosUtils.java#L236-L248 for an example of how this had been done previously. |
||
@Override | ||
public boolean apply(Resource resource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
return resource.getType() == Protos.Value.Type.SCALAR && | ||
resource.getScalar().getValue() > v; | ||
} | ||
}; | ||
} | ||
|
||
public static Function<Resource, Double> toDoubleResourceValue() { | ||
return new Function<Resource, Double>() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make a private static final inner class of this function with a singleton instance returned by this method. See https://github.com/mesosphere/cassandra-mesos/blob/master/cassandra-mesos-model/src/main/java/io/mesosphere/mesos/util/CassandraFrameworkProtosUtils.java#L176 for an example of how this had been done previously. |
||
@Override | ||
public Double apply(@Nullable Resource resource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
return resourceValueDouble(Optional.fromNullable(resource)).or(0.0); | ||
} | ||
}; | ||
} | ||
|
||
public static Function<Resource, Long> toLongResourceValue() { | ||
return new Function<Resource, Long>() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make a private static final inner class of this function with a singleton instance returned by this method. See https://github.com/mesosphere/cassandra-mesos/blob/master/cassandra-mesos-model/src/main/java/io/mesosphere/mesos/util/CassandraFrameworkProtosUtils.java#L176 for an example of how this had been done previously. |
||
@Override | ||
public Long apply(@Nullable Resource resource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
return resourceValueLong(Optional.fromNullable(resource)).or(0l); | ||
} | ||
}; | ||
} | ||
|
||
public static Optional<Double> maxResourceValueDouble(List<Resource> resource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
ImmutableList<Double> values = from(resource) | ||
.transform(toDoubleResourceValue()) | ||
.toList(); | ||
if (values.isEmpty()) { | ||
return Optional.absent(); | ||
} else { | ||
return Optional.of(Collections.max(values)); | ||
} | ||
} | ||
|
||
public static Optional<Long> maxResourceValueLong(List<Resource> resource) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
ImmutableList<Long> values = from(resource) | ||
.transform(toLongResourceValue()) | ||
.toList(); | ||
if (values.isEmpty()) { | ||
return Optional.absent(); | ||
} else { | ||
return Optional.of(Collections.max(values)); | ||
} | ||
} | ||
|
||
private static final class CassandraNodeToIp implements Function<CassandraNode, String> { | ||
private static final CassandraNodeToIp INSTANCE = new CassandraNodeToIp(); | ||
|
||
|
@@ -299,7 +384,8 @@ public ResourceHasExpectedRole(@NotNull final String role) { | |
|
||
@Override | ||
public boolean apply(final Resource item) { | ||
return item.getRole().equals(role); | ||
String givenRole = item.getRole(); | ||
return givenRole.equals(role) || givenRole.equals("*"); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -971,6 +971,7 @@ protected Protos.TaskInfo[] threeNodeClusterPost() throws InvalidProtocolBufferE | |
return executorMetadata; | ||
} | ||
|
||
|
||
protected void executorTaskError(final Protos.TaskInfo taskInfo) { | ||
scheduler.statusUpdate(driver, Protos.TaskStatus.newBuilder() | ||
.setExecutorId(executorId(taskInfo)) | ||
|
@@ -1150,15 +1151,19 @@ protected void noopOnOfferAll() { | |
} | ||
} | ||
|
||
protected void cleanState() { | ||
super.cleanState(); | ||
protected void cleanState(String mesosRole) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
super.cleanState(mesosRole); | ||
|
||
scheduler = new CassandraScheduler(configuration, cluster, clock); | ||
|
||
driver = new MockSchedulerDriver(scheduler); | ||
driver.callRegistered(Protos.FrameworkID.newBuilder().setValue(UUID.randomUUID().toString()).build()); | ||
} | ||
|
||
protected void cleanState() { | ||
cleanState("*"); | ||
} | ||
|
||
protected static String executorIdValue(final Protos.TaskInfo executorMetadata) { | ||
return executorId(executorMetadata).getValue(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ public abstract class AbstractSchedulerTest { | |
}; | ||
protected PersistedCassandraClusterHealthCheckHistory healthCheckHistory; | ||
|
||
protected void cleanState() { | ||
protected void cleanState(String mesosRole) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please mark |
||
// start with clean state | ||
state = new InMemoryState(); | ||
|
||
|
@@ -59,7 +59,7 @@ protected void cleanState() { | |
"2.1.4", | ||
2, 4096, 4096, 0, | ||
3, 2, | ||
"*", | ||
mesosRole, | ||
".", | ||
true, | ||
false, | ||
|
@@ -81,7 +81,12 @@ protected void cleanState() { | |
clusterState = cluster.getClusterState(); | ||
} | ||
|
||
protected Protos.Offer createOffer(final Tuple2<Protos.SlaveID, String> slave) { | ||
protected void cleanState() { | ||
cleanState("*"); | ||
} | ||
|
||
|
||
protected Protos.Offer createOffer(final Tuple2<Protos.SlaveID, String> slave) { | ||
final Protos.Offer.Builder builder = Protos.Offer.newBuilder() | ||
.setFrameworkId(frameworkId) | ||
.setHostname(slave._2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make a private static final inner class of this function with a singleton instance returned by this method.
See https://github.com/mesosphere/cassandra-mesos/blob/master/cassandra-mesos-model/src/main/java/io/mesosphere/mesos/util/CassandraFrameworkProtosUtils.java#L176 for an example of how this had been done previously.