Skip to content

Commit

Permalink
Set the default lib mesos location if it is null, as is the case befo… (
Browse files Browse the repository at this point in the history
#380)

* Set the default lib mesos location if it is null, as is the case before upgrading the scheduler.

* Read default libmesos location from env var instead of hardcoding it

* Revert unrelated change
  • Loading branch information
verma7 authored and nickbp committed Jan 26, 2017
1 parent eb8f34b commit 8770b30
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions cassandra-commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies {
compile 'mesosphere:dcos-commons:0.8.1.1'
compile 'com.google.protobuf:protobuf-java:3.0.0'
compile 'org.apache.cassandra:cassandra-all:2.2.4'
compile "com.github.stefanbirkner:system-rules:1.16.0"
}
protobuf {
generatedFilesBaseDir = "$projectDir/src/generated"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mesosphere.dcos.cassandra.common.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URI;
Expand Down Expand Up @@ -62,6 +63,10 @@ public static ExecutorConfig create(
@JsonProperty("cache_fetched_uris") boolean cacheFetchedUris)
throws URISyntaxException, UnsupportedEncodingException {

// This check is compatibility with upgrades from 1.0.20 in which this configuration property is absent.
if (StringUtils.isEmpty(libmesosLocation)) {
libmesosLocation = System.getenv("EXECUTOR_LIBMESOS_LOCATION");
}
ExecutorConfig config = create(
command,
arguments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.apache.mesos.offer.VolumeRequirement;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.mockito.Mockito;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
Expand All @@ -22,6 +25,9 @@
* This class tests the CassandraDaemonTask class.
*/
public class CassandraDaemonTaskTest {
@ClassRule
public static final EnvironmentVariables ENV_VARS = new EnvironmentVariables();

private static final String TEST_DAEMON_NAME = "test-daemon-task-name";
private static final UUID TEST_CONFIG_ID = UUID.randomUUID();
public static final String TEST_CONFIG_NAME = TEST_CONFIG_ID.toString();
Expand Down Expand Up @@ -289,6 +295,74 @@ public void testUpdateCacheFetchedUris() throws URISyntaxException {
Assert.assertTrue(allUrisAreCacheable(updatedTask.getTaskInfo().getExecutor().getCommand().getUrisList(), true));
}


@Test
public void testUpdateLibmesosLocation() throws URISyntaxException, UnsupportedEncodingException {
// Set the default environment variable to simulate the setting of this variable from parsing scheduler.yml
final String DEFAULT_LIBMESOS_LOCATION = "http://libmesos-default";
ENV_VARS.set("EXECUTOR_LIBMESOS_LOCATION", DEFAULT_LIBMESOS_LOCATION);

// Before the introduction of libmesosLocation variable, the executor config stored in zookeeper has
// null libmesosLocation and should be constructed and deserialized correctly.
ExecutorConfig testExecutorConfig = ExecutorConfig.create(
"test-cmd",
Arrays.asList("arg0"),
1.0,
256,
500,
1000,
"java-home",
"http://jre-location",
"http://executor-location",
"http://cassandra-location",
/* libmesosLocation */ null,
false,
false);

testTaskExecutor = CassandraTaskExecutor.create(
"test-framework-id",
TEST_DAEMON_NAME,
"test-role",
"test-principal",
testExecutorConfig);

CassandraDaemonTask daemonTask = testTaskFactory.create(
TEST_DAEMON_NAME,
TEST_CONFIG_NAME,
testTaskExecutor,
CassandraConfig.DEFAULT);
Assert.assertEquals(4, daemonTask.getExecutor().getURIs().size());
Assert.assertTrue(daemonTask.getExecutor().getURIs().contains(DEFAULT_LIBMESOS_LOCATION));

ExecutorConfig updatedTestExecutorConfig = ExecutorConfig.create(
"test-cmd",
Arrays.asList("arg0"),
1.0,
256,
500,
1000,
"java-home",
"http://jre-location",
"http://executor-location",
"http://cassandra-location",
"http://libmesos-location-new",
false,
false);

testTaskExecutor = CassandraTaskExecutor.create(
"test-framework-id",
TEST_DAEMON_NAME,
"test-role",
"test-principal",
updatedTestExecutorConfig);

CassandraDaemonTask updatedTask = daemonTask.updateConfig(
CassandraConfig.DEFAULT,
updatedTestExecutorConfig,
TEST_CONFIG_ID);
Assert.assertTrue(updatedTask.getExecutor().getURIs().contains("http://libmesos-location-new"));
}

private Protos.TaskInfo normalizeCassandraTaskInfo(CassandraDaemonTask daemonTask) {
Protos.TaskInfo daemonTaskInfo = daemonTask.getTaskInfo();
Protos.ExecutorInfo expectedExecutorInfo = Protos.ExecutorInfo.newBuilder(daemonTaskInfo.getExecutor())
Expand Down

0 comments on commit 8770b30

Please sign in to comment.