-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing/354 jar system test #398
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be4dcb0
Bug with java home.
825ceae
Working jar system test. Exposes 31000 on localhost and hacks hostnam…
c7473b2
Removed unnecessary code.
7e543ad
Fixed gradle check errors.
60ffc7a
Merge remote-tracking branch 'origin/master' into testing/354-JarSyst…
b1e6d13
PMD fix.
b343344
Update to latest minimesos master with new API.
e0104ff
Attempt to fix intermittent system test failure on executor system te…
da59211
Fix issues after peer review. Added documentation,
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
...est/src/systemTest/java/org/apache/mesos/elasticsearch/systemtest/RunAsJarSystemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package org.apache.mesos.elasticsearch.systemtest; | ||
|
||
import com.containersol.minimesos.MesosCluster; | ||
import com.containersol.minimesos.container.AbstractContainer; | ||
import com.containersol.minimesos.mesos.*; | ||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.api.command.CreateContainerCmd; | ||
import com.github.dockerjava.api.model.ExposedPort; | ||
import com.github.dockerjava.api.model.Link; | ||
import com.github.dockerjava.api.model.Ports; | ||
import org.apache.mesos.elasticsearch.common.cli.ElasticsearchCLIParameter; | ||
import org.apache.mesos.elasticsearch.common.cli.ZookeeperCLIParameter; | ||
import org.apache.mesos.elasticsearch.scheduler.Configuration; | ||
import org.apache.mesos.elasticsearch.systemtest.callbacks.ElasticsearchNodesResponse; | ||
import org.apache.mesos.elasticsearch.systemtest.util.DockerUtil; | ||
import org.junit.*; | ||
import org.junit.rules.TestWatcher; | ||
import org.junit.runner.Description; | ||
|
||
import java.io.IOException; | ||
import java.security.SecureRandom; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.apache.mesos.elasticsearch.systemtest.Configuration.getDocker0AdaptorIpAddress; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* A system test to ensure that the framework can run as a JAR, not using docker. | ||
* <p> | ||
* <b>Test method</b> | ||
* <p> | ||
* The goal is to start the framework in jar mode, and ensure that the system can still be discovered. | ||
* We still start the scheduler in the container (but with jar mode enabled) because the system running the system | ||
* test may not have Java 8 installed. But this is no issue; the test is exactly the same. | ||
* </p><p> | ||
* Next, a custom MesosSlave is provided so that it can resolve the IP address of the scheduler (which is hosting | ||
* the executor jar). Its own hostname is set to "hostnamehack" so that it can be resolved on the scheduler side. | ||
* The ES port (31000 in this case) is bound to the host, where the host is the VM or linux OS. This will allow us | ||
* to curl the ES endpoint without knowing the IP address of the slave container. | ||
* </p><p> | ||
* The scheduler has an extra host called "hostnamehack" that resolves to the docker0 adaptor address. This is | ||
* equivalent to the VM/linux localhost, is known ahead of time and is system independent. I.e. both Mac's and linux | ||
* boxes will be able to resolve this address. The port is the same. | ||
* </p><p> | ||
* So finally, the ES system tests can cary on as normal and resolve the ES hosts. Nice! | ||
* </p> | ||
*/ | ||
@SuppressWarnings({"PMD.TooManyMethods"}) | ||
public class RunAsJarSystemTest { | ||
protected static final org.apache.mesos.elasticsearch.systemtest.Configuration TEST_CONFIG = new org.apache.mesos.elasticsearch.systemtest.Configuration(); | ||
private static final int NUMBER_OF_TEST_TASKS = 1; | ||
|
||
// Need full control over the cluster, so need to do all the lifecycle stuff. | ||
private MesosCluster cluster; | ||
private static DockerClient dockerClient = DockerClientFactory.build(); | ||
private JarScheduler scheduler; | ||
|
||
@BeforeClass | ||
public static void prepareCleanDockerEnvironment() { | ||
new DockerUtil(dockerClient).killAllSchedulers(); | ||
new DockerUtil(dockerClient).killAllExecutors(); | ||
} | ||
|
||
@Rule | ||
public final TestWatcher WATCHER = new TestWatcher() { | ||
@Override | ||
protected void failed(Throwable e, Description description) { | ||
cluster.stop(); | ||
} | ||
}; | ||
|
||
@Before | ||
public void before() { | ||
ClusterArchitecture.Builder builder = new ClusterArchitecture.Builder() | ||
.withZooKeeper() | ||
.withMaster() | ||
.withSlave() // Have to have a slave before we build. Bit of a minimesos bug. This offer wont get accepted. | ||
.withContainer(zkContainer -> new JarScheduler(dockerClient, zkContainer), ClusterContainers.Filter.zooKeeper()); | ||
scheduler = (JarScheduler) builder.build().getClusterContainers().getOne(container -> container instanceof JarScheduler).get(); | ||
IntStream.range(0, NUMBER_OF_TEST_TASKS).forEach(dummy -> | ||
builder.withSlave(zooKeeper -> new MesosSlaveWithSchedulerLink(dockerClient, zooKeeper, scheduler)) | ||
); | ||
cluster = new MesosCluster(builder.build()); | ||
|
||
cluster.start(); | ||
} | ||
|
||
@After | ||
public void stopContainer() { | ||
cluster.stop(); | ||
} | ||
|
||
@AfterClass | ||
public static void killAllContainers() { | ||
new DockerUtil(dockerClient).killAllSchedulers(); | ||
new DockerUtil(dockerClient).killAllExecutors(); | ||
} | ||
|
||
@Test | ||
public void shouldStartScheduler() throws IOException, InterruptedException { | ||
ESTasks esTasks = new ESTasks(TEST_CONFIG, scheduler.getIpAddress()); | ||
new TasksResponse(esTasks, NUMBER_OF_TEST_TASKS); | ||
|
||
ElasticsearchNodesResponse nodesResponse = new ElasticsearchNodesResponse(esTasks, NUMBER_OF_TEST_TASKS); | ||
assertTrue("Elasticsearch nodes did not discover each other within 5 minutes", nodesResponse.isDiscoverySuccessful()); | ||
} | ||
|
||
private static class JarScheduler extends AbstractContainer { | ||
private final ZooKeeper zooKeeperContainer; | ||
private String docker0AdaptorIpAddress; | ||
|
||
protected JarScheduler(DockerClient dockerClient, ZooKeeper zooKeeperContainer) { | ||
super(dockerClient); | ||
this.zooKeeperContainer = zooKeeperContainer; | ||
docker0AdaptorIpAddress = getDocker0AdaptorIpAddress(dockerClient); | ||
} | ||
|
||
@Override | ||
public void pullImage() { | ||
dockerClient.pullImageCmd(TEST_CONFIG.getSchedulerImageName()); | ||
} | ||
|
||
@Override | ||
protected CreateContainerCmd dockerCommand() { | ||
return dockerClient | ||
.createContainerCmd(TEST_CONFIG.getSchedulerImageName()) | ||
.withName(TEST_CONFIG.getSchedulerName() + "_" + MesosCluster.getClusterId() + "_" + new SecureRandom().nextInt()) | ||
.withEnv("JAVA_OPTS=-Xms128m -Xmx256m") | ||
.withExtraHosts("hostnamehack:" + docker0AdaptorIpAddress) // Will redirect hostnamehack to host IP address (where ports are bound) | ||
.withCmd( | ||
ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, getZookeeperMesosUrl(), | ||
Configuration.FRAMEWORK_USE_DOCKER, "false", | ||
ElasticsearchCLIParameter.ELASTICSEARCH_NODES, String.valueOf(NUMBER_OF_TEST_TASKS), | ||
Configuration.ELASTICSEARCH_CPU, "0.1", | ||
Configuration.ELASTICSEARCH_RAM, "128", | ||
Configuration.ELASTICSEARCH_DISK, "10", | ||
Configuration.JAVA_HOME, "/usr/bin" | ||
); | ||
} | ||
public String getZookeeperMesosUrl() { | ||
return "zk://" + zooKeeperContainer.getIpAddress() + ":2181/mesos"; | ||
} | ||
} | ||
|
||
private static class MesosSlaveWithSchedulerLink extends MesosSlave { | ||
|
||
private final JarScheduler scheduler; | ||
|
||
protected MesosSlaveWithSchedulerLink(DockerClient dockerClient, ZooKeeper zooKeeperContainer, JarScheduler scheduler) { | ||
super(dockerClient, zooKeeperContainer); | ||
this.scheduler = scheduler; | ||
} | ||
|
||
@Override | ||
protected CreateContainerCmd dockerCommand() { | ||
CreateContainerCmd createContainerCmd = super.dockerCommand(); | ||
|
||
Ports ports = new Ports(); | ||
ports.bind(ExposedPort.tcp(31000), Ports.Binding(31000)); | ||
createContainerCmd | ||
.withHostName("hostnamehack") // Hack to get past offer refusal | ||
.withLinks(new Link(scheduler.getContainerId(), scheduler.getContainerId())) | ||
.withExposedPorts(new ExposedPort(31000), new ExposedPort(5051)) | ||
.withPortBindings(ports) | ||
; | ||
return createContainerCmd; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe sort the
@BeforeClass
,@Before
,@Rule
,@After
,@AfterClass
in the order they're being executed?