Skip to content

Commit

Permalink
Merge pull request #363 from mesos/bug/357-ConfigurationNPE
Browse files Browse the repository at this point in the history
Bug/357 configuration npe
  • Loading branch information
Phil Winder committed Oct 20, 2015
2 parents 59d9136 + d147d79 commit 5b99cb8
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 12 deletions.
1 change: 1 addition & 0 deletions scheduler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
compile "org.webjars.bower:highcharts-ng:0.0.8"
compile 'com.jayway.awaitility:awaitility:1.6.3'

testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'joda-time:joda-time:2.3'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public class Configuration {
@Parameter(names = {FRAMEWORK_SECRET_PATH}, description = "The path to the file which contains the secret for the principal (password). Password in file must not have a newline.")
private String frameworkSecretPath = "";
@Parameter(names = {FRAMEWORK_USE_DOCKER}, arity = 1, description = "The framework will use docker if true, or jar files if false. If false, the user must ensure that the scheduler jar is on all slaves.")
private Boolean frameworkUseDocker = true;
private Boolean isFrameworkUseDocker = true;
private InetSocketAddress frameworkFileServerAddress;
@Parameter(names = {JAVA_HOME}, description = "(Only when frameworkUseDocker is false) When starting in jar mode, if java is not on the path, you can specify the path here.", validateWith = CLIValidators.NotEmptyString.class)
@Parameter(names = {JAVA_HOME}, description = "(Only when " + FRAMEWORK_USE_DOCKER + " is false) When starting in jar mode, if java is not on the path, you can specify the path here.", validateWith = CLIValidators.NotEmptyString.class)
private String javaHome = "";
// ****************** Runtime configuration **********************

Expand Down Expand Up @@ -219,12 +219,16 @@ public String getFrameworkPrincipal() {
return frameworkPrincipal;
}

public Boolean frameworkUseDocker() {
return frameworkUseDocker;
public Boolean isFrameworkUseDocker() {
return isFrameworkUseDocker;
}

public String getFrameworkFileServerAddress() {
return "http://" + frameworkFileServerAddress.getHostName() + ":" + frameworkFileServerAddress.getPort();
String result = "";
if (frameworkFileServerAddress != null) {
result = "http://" + frameworkFileServerAddress.getHostName() + ":" + frameworkFileServerAddress.getPort();
}
return result;
}

public void setFrameworkFileServerAddress(InetSocketAddress addr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void run(String[] args) {

configuration = new Configuration(args);

if (!configuration.frameworkUseDocker()) {
if (!configuration.isFrameworkUseDocker()) {
try {
final SimpleFileServer simpleFileServer = new SimpleFileServer();
simpleFileServer.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private Protos.ExecutorInfo.Builder newExecutorInfo(Configuration configuration)
.setFrameworkId(frameworkState.getFrameworkID())
.setName("elasticsearch-executor-" + UUID.randomUUID().toString())
.setCommand(newCommandInfo(configuration));
if (configuration.frameworkUseDocker()) {
if (configuration.isFrameworkUseDocker()) {
executorInfoBuilder.setContainer(Protos.ContainerInfo.newBuilder()
.setType(Protos.ContainerInfo.Type.DOCKER)
.setDocker(Protos.ContainerInfo.DockerInfo.newBuilder().setImage(configuration.getExecutorImage()).setForcePullImage(configuration.getExecutorForcePullImage()))
Expand All @@ -115,7 +115,7 @@ private Protos.CommandInfo.Builder newCommandInfo(Configuration configuration) {
Protos.CommandInfo.Builder commandInfoBuilder = Protos.CommandInfo.newBuilder()
.setEnvironment(Protos.Environment.newBuilder().addAllVariables(executorEnvironmentalVariables.getList()));

if (configuration.frameworkUseDocker()) {
if (configuration.isFrameworkUseDocker()) {
commandInfoBuilder
.setShell(false)
.addAllArguments(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.mesos.elasticsearch.scheduler.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
Expand Down Expand Up @@ -36,7 +35,7 @@ public List<Protos.Environment.Variable> getList() {
* @param configuration
*/
private void populateEnvMap(Configuration configuration) {
if (configuration.frameworkUseDocker()) {
if (configuration.isFrameworkUseDocker()) {
addToList(native_mesos_library_key, native_mesos_library_path);
}
addToList(JAVA_OPTS, getHeapSpaceString(configuration));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void before() {
when(configuration.getElasticsearchClusterName()).thenReturn("cluster-name");
when(configuration.getDataDir()).thenReturn("/var/lib/mesos/slave/elasticsearch");
when(configuration.getFrameworkRole()).thenReturn("some-framework-role");
when(configuration.frameworkUseDocker()).thenReturn(true);
when(configuration.isFrameworkUseDocker()).thenReturn(true);
}

@Test
Expand Down Expand Up @@ -111,7 +111,7 @@ private Protos.Offer getOffer(Protos.FrameworkID frameworkId) {

@Test
public void shouldAddJarInfoAndRemoveContainerInfo() {
when(configuration.frameworkUseDocker()).thenReturn(false);
when(configuration.isFrameworkUseDocker()).thenReturn(false);
String address = "http://localhost:1234";
when(configuration.getFrameworkFileServerAddress()).thenReturn(address);
TaskInfoFactory factory = new TaskInfoFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.apache.mesos.elasticsearch.scheduler.controllers;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertFalse;

/**
* Test Cluster controller.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = TestConfiguration.class)
public class ClusterControllerTest {

@Autowired
private ClusterController clusterController;

@Test
public void shouldNotExceptionWhenGeneratingConfiguration() {
clusterController.clusterInfo();
}

@Test
public void shouldNotHaveErrorInText() {
clusterController.clusterInfo().configuration.values().forEach(v -> {
assertFalse(v.toString().contains("ERROR"));
});
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.apache.mesos.elasticsearch.scheduler.controllers;

import org.apache.http.client.HttpClient;
import org.apache.mesos.elasticsearch.common.cli.ZookeeperCLIParameter;
import org.apache.mesos.elasticsearch.scheduler.ElasticsearchScheduler;
import org.mockito.Mockito;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
* Test configuration for controllers
*/
@EnableAutoConfiguration
@ComponentScan
@Configuration
public class TestConfiguration {

@Bean
public ClusterController getClusterController() {
return new ClusterController();
}

@Bean
public ElasticsearchScheduler getMockScheduler() {
return Mockito.mock(ElasticsearchScheduler.class);
}

@Bean
public org.apache.mesos.elasticsearch.scheduler.Configuration getConfig() {
return new org.apache.mesos.elasticsearch.scheduler.Configuration(ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, "zk://dummy.mesos.master:2181");
}

@Bean
public HttpClient getMockHttpClient() {
return Mockito.mock(HttpClient.class);
}
}

0 comments on commit 5b99cb8

Please sign in to comment.