Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
Merge pull request #62 from ContainerSolutions/refactoring/mesos-clus…
Browse files Browse the repository at this point in the history
…ter-config

Added MesosCluster builder
  • Loading branch information
frankscholten committed Sep 9, 2015
2 parents 6af8cd4 + 051f7b6 commit cc2f134
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Expand Up @@ -2,14 +2,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.2.6] - [6 September 2015]
## [0.2.8] - [9 September 2015]

### Added

- [Print container logs when it fails to start](https://github.com/ContainerSolutions/mini-mesos/pull/54)
- [Allow passing extra environment variables to supervised programs](https://github.com/ContainerSolutions/mini-mesos/pull/61)

## [0.2.8] - [9 September 2015]
## [0.2.6] - [6 September 2015]

### Added

- [Allow passing extra environment variables to supervised programs](https://github.com/ContainerSolutions/mini-mesos/pull/61)
- [Print container logs when it fails to start](https://github.com/ContainerSolutions/mini-mesos/pull/54)
12 changes: 8 additions & 4 deletions src/main/java/org/apache/mesos/mini/MesosCluster.java
Expand Up @@ -19,10 +19,6 @@
import org.json.JSONObject;
import org.junit.rules.ExternalResource;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -49,6 +45,10 @@ public MesosCluster(MesosClusterConfig config) {
this.config = config;
}

public static MesosClusterConfig.Builder builder() {
return MesosClusterConfig.builder();
}

/**
* Starts the Mesos cluster and its containers
*/
Expand Down Expand Up @@ -171,4 +171,8 @@ public List<AbstractContainer> getContainers() {
public DockerClient getInnerDockerClient() {
return this.mesosContainer.getInnerDockerClient();
}

public MesosClusterConfig getConfig() {
return config;
}
}
16 changes: 6 additions & 10 deletions src/main/java/org/apache/mesos/mini/mesos/MesosClusterConfig.java
Expand Up @@ -4,6 +4,7 @@
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.DockerClientConfig;
import org.apache.commons.lang.StringUtils;
import org.apache.mesos.mini.MesosCluster;

import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -94,7 +95,7 @@ public Builder defaultDockerClient() {
return this;
}

public MesosClusterConfig build() {
public MesosCluster build() {

if (numberOfSlaves <= 0) {
throw new IllegalStateException("At least one slave is required to run a mesos cluster");
Expand All @@ -111,16 +112,11 @@ public MesosClusterConfig build() {
}
}

return new MesosClusterConfig(
dockerClient,
numberOfSlaves,
slaveResources,
mesosMasterPort,
privateRegistryPort,
extraEnvironmentVariables
);
return new MesosCluster(new MesosClusterConfig(dockerClient, numberOfSlaves, slaveResources, mesosMasterPort, privateRegistryPort, extraEnvironmentVariables));
}

}

public int getNumberOfSlaves() {
return numberOfSlaves;
}
}
3 changes: 0 additions & 3 deletions src/main/java/org/apache/mesos/mini/mesos/MesosContainer.java
Expand Up @@ -11,13 +11,10 @@
import java.io.IOException;
import java.net.Socket;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.jayway.awaitility.Awaitility.await;

Expand Down
9 changes: 4 additions & 5 deletions src/test/java/org/apache/mesos/mini/ImageInjectionTest.java
Expand Up @@ -5,18 +5,17 @@
import org.junit.Test;

public class ImageInjectionTest {
private static final MesosClusterConfig config = MesosClusterConfig.builder()

@ClassRule
public static final MesosCluster cluster = MesosCluster.builder()
.numberOfSlaves(3)
.privateRegistryPort(16000) // Currently you have to choose an available port by yourself
.slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]", "ports(*):[9201-9201,9301-9301]", "ports(*):[9202-9202,9302-9302]"})
.build();

@ClassRule
public static MesosCluster cluster = new MesosCluster(config);

@Test
public void testInjectImage() {
HelloWorldContainer container = new HelloWorldContainer(config.dockerClient);
HelloWorldContainer container = new HelloWorldContainer(cluster.getConfig().dockerClient);
container.pullImage();

cluster.injectImage("tutum/hello-world");
Expand Down
7 changes: 3 additions & 4 deletions src/test/java/org/apache/mesos/mini/InnerDockerTest.java
Expand Up @@ -5,7 +5,6 @@
import com.github.dockerjava.api.model.Container;
import org.apache.mesos.mini.container.AbstractContainer;
import org.apache.mesos.mini.docker.PrivateDockerRegistry;
import org.apache.mesos.mini.mesos.MesosClusterConfig;
import org.apache.mesos.mini.mesos.MesosContainer;
import org.junit.Test;

Expand All @@ -21,12 +20,12 @@
public class InnerDockerTest {
@Test
public void shouldStart() throws InterruptedException {
MesosClusterConfig config = MesosClusterConfig.builder().defaultDockerClient()
MesosCluster cluster = MesosCluster.builder().defaultDockerClient()
.slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]", "ports(*):[9201-9201,9301-9301]", "ports(*):[9202-9202,9302-9302]"})
.build();
PrivateDockerRegistry registry = new PrivateDockerRegistry(config.dockerClient, config);
PrivateDockerRegistry registry = new PrivateDockerRegistry(cluster.getConfig().dockerClient, cluster.getConfig());
registry.start();
MesosContainer mesosContainer = new MesosContainer(config.dockerClient, config, registry.getContainerId());
MesosContainer mesosContainer = new MesosContainer(cluster.getConfig().dockerClient, cluster.getConfig(), registry.getContainerId());
mesosContainer.start();

HelloWorldNoRemoveContainer helloWorldContainer = new HelloWorldNoRemoveContainer(mesosContainer.getInnerDockerClient());
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/org/apache/mesos/mini/MesosClusterTest.java
Expand Up @@ -12,15 +12,13 @@

public class MesosClusterTest {

private static final MesosClusterConfig config = MesosClusterConfig.builder()
@ClassRule
public static final MesosCluster cluster = MesosClusterConfig.builder()
.numberOfSlaves(3)
.privateRegistryPort(16000) // Currently you have to choose an available port by yourself
.slaveResources(new String[]{"ports(*):[9200-9200,9300-9300]", "ports(*):[9201-9201,9301-9301]", "ports(*):[9202-9202,9302-9302]"})
.build();

@ClassRule
public static MesosCluster cluster = new MesosCluster(config);

@Test
public void mesosClusterStateInfoJSONMatchesSchema() throws UnirestException, JsonParseException, JsonMappingException {
cluster.getStateInfo();
Expand All @@ -45,9 +43,9 @@ public void mesosClusterCanBeStarted2() throws Exception {

@Test
public void testPullAndStartContainer() throws UnirestException {
HelloWorldContainer container = new HelloWorldContainer(config.dockerClient);
HelloWorldContainer container = new HelloWorldContainer(cluster.getConfig().dockerClient);
String containerId = cluster.addAndStartContainer(container);
String ipAddress = config.dockerClient.inspectContainerCmd(containerId).exec().getNetworkSettings().getIpAddress();
String ipAddress = cluster.getConfig().dockerClient.inspectContainerCmd(containerId).exec().getNetworkSettings().getIpAddress();
String url = "http://" + ipAddress + ":80";
Assert.assertEquals(200, Unirest.get(url).asString().getStatus());
}
Expand Down

0 comments on commit cc2f134

Please sign in to comment.