Skip to content

Commit

Permalink
#13. Adding NODE_OPTIONS environment variable; making docker image na…
Browse files Browse the repository at this point in the history
…me configurable
  • Loading branch information
sadovnikov committed Feb 3, 2016
1 parent be922fa commit 3fa3c18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ java -jar /path-to/kibana.jar
```
-zk -zookeeper Mesos Zookeeper URL. (Required)
-p -port The TCP port for the webservice. (Default: 9001)
-di -dockerimage Name of docker image to use. (Default: kibana)
-v -version Version of Kibana docker image to use. (Default: latest)
-mem -requiredMem The amount of memory (in MB) to allocate to a single Kibana instance. (Default: 128)
-cpu -requiredCpu The amount of CPUs to allocate to a single Kibana instance. (Default: 0.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class SchedulerConfiguration {

private static final String FRAMEWORK_NAME = "kibana"; // the name of this Mesos framework
private static final String DEFAULT_KIBANA_VERSION = "latest"; // version of Kibana (and its image) to use
private static final String DOCKER_IMAGE_NAME = "kibana"; // the name of Kibana Docker image to use when starting a task
private static final String DEFAULT_DOCKER_IMAGE = "kibana"; // the name of Kibana Docker image to use when starting a task
private static final double REQUIRED_PORT_COUNT = 1D; // the amount of ports a task needs

private static final Options OPTIONS = new Options() {{ // launch options for the KibanaFramework
addOption("zk", "zookeeper", true, "Zookeeper URL (zk://host:port/mesos)");
addOption("es", "elasticsearch", true, "ElasticSearch URLs (http://host:port;http://host:port)");
addOption("di", "dockerimage", true, "Name of docker image to use. Defaults to 'kibana'");
addOption("v", "version", true, "Version of Kibana docker image to use");
addOption("cpu", "requiredCpu", true, "Amount of CPUs given to a Kibana instance (0.1)");
addOption("mem", "requiredMem", true, "Amount of memory (MB) given to a Kibana instance (128)");
Expand All @@ -42,7 +43,9 @@ public class SchedulerConfiguration {
private double requiredCpu = 0.1D; // the amount of CPUs a task needs
private double requiredMem = 128D; // the amount of memory a task needs
private double requiredDisk = 25D; // the amount of disk space a task needs

private String kibanaVersion = DEFAULT_KIBANA_VERSION;
private String kibanaImage = DEFAULT_DOCKER_IMAGE;

/**
* Returns the name of the framework
Expand All @@ -59,7 +62,7 @@ public static String getFrameworkName() {
* @return the name of the Kibana Docker image
*/
public String getDockerImageName() {
return String.format("%s:%s", DOCKER_IMAGE_NAME, kibanaVersion);
return String.format("%s:%s", kibanaImage, kibanaVersion);
}

/**
Expand Down Expand Up @@ -360,6 +363,11 @@ public void parseLaunchArguments(String[] args) throws ParseException {
setKibanaVersion(version);
}

String image = commandLine.getOptionValue("di");
if (image != null) {
setKibanaImage(image);
}

}

/**
Expand All @@ -380,4 +388,8 @@ public void setKibanaVersion(String kibanaVersion) {
this.kibanaVersion = kibanaVersion;
}

public void setKibanaImage(String kibanaImage) {
this.kibanaImage = kibanaImage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.mesos.Protos.ContainerInfo.DockerInfo;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -32,8 +31,10 @@ public class TaskInfoFactory {
public static TaskInfo buildTask(Map.Entry<String, Integer> requirement, Offer offer, SchedulerConfiguration configuration) {
TaskID taskId = generateTaskId();
long port = configuration.pickAndRegisterPortNumber(taskId, offer);
double memReq = configuration.getRequiredMem();
ContainerInfo container = buildContainerInfo(configuration, port);
Environment environment = buildEnvironment(requirement.getKey());
// based on https://github.com/elastic/kibana/issues/5170#issuecomment-163042525
Environment environment = buildEnvironment(requirement.getKey(), (int) (memReq - 100));
CommandInfo command = buildCommandInfo(environment);
List<Resource> resources = buildResources(configuration, port); //DCOS-06 Scheduler MUST only use the necessary fraction of an offer.
return buildTaskInfo(taskId, offer, container, command, resources);
Expand Down Expand Up @@ -67,12 +68,18 @@ private static CommandInfo buildCommandInfo(Environment environment) {
* @param elasticSearchUrl the elasticSearchUrl to set
* @return the Environment
*/
private static Environment buildEnvironment(String elasticSearchUrl) {
private static Environment buildEnvironment(String elasticSearchUrl, int nodeOptionsSpace ) {

Environment.Variable.Builder esUrlVariableBuilder = Environment.Variable.newBuilder();
esUrlVariableBuilder.setName("ELASTICSEARCH_URL");
esUrlVariableBuilder.setValue(elasticSearchUrl);

List<Environment.Variable> variables = Collections.singletonList(esUrlVariableBuilder.build());
// based on https://github.com/elastic/kibana/issues/5170#issuecomment-163042525
Environment.Variable.Builder nodeOptionsBuilder = Environment.Variable.newBuilder();
nodeOptionsBuilder.setName("NODE_OPTIONS");
nodeOptionsBuilder.setValue("--max-old-space-size=" + nodeOptionsSpace);

List<Environment.Variable> variables = Arrays.asList( esUrlVariableBuilder.build(), nodeOptionsBuilder.build() );

Environment.Builder environmentBuilder = Environment.newBuilder();
environmentBuilder.addAllVariables(variables);
Expand Down Expand Up @@ -100,6 +107,7 @@ private static ContainerInfo buildContainerInfo(SchedulerConfiguration configura
ContainerInfo.Builder containerInfo = ContainerInfo.newBuilder();
containerInfo.setType(ContainerInfo.Type.DOCKER);
containerInfo.setDocker(dockerInfo);

return containerInfo.build();
}

Expand Down

0 comments on commit 3fa3c18

Please sign in to comment.