diff --git a/build.gradle b/build.gradle index dc17e0ad..bb08eea8 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ subprojects { [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' - tasks.withType(JavaCompile) { + compileJava { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } @@ -56,8 +56,8 @@ subprojects { jacocoTestReport { reports { - xml.enabled true - csv.enabled false + xml.enabled false + csv.enabled true } } diff --git a/cli/build.gradle b/cli/build.gradle index 709b9382..0d76f3a2 100644 --- a/cli/build.gradle +++ b/cli/build.gradle @@ -76,5 +76,34 @@ afterEvaluate { project -> } } +sourceSets { + integrationTest { + java { + compileClasspath += main.output + test.output + runtimeClasspath += main.output + test.output + srcDir file('src/integration-test/java') + } + resources.srcDir file('src/integration-test/resources') + } +} + +configurations { + integrationTestCompile.extendsFrom mainCompile + integrationTestCompile.extendsFrom testCompile + integrationTestRuntime.extendsFrom mainRuntime + integrationTestRuntime.extendsFrom testRuntime +} + +task integrationTest(type: Test) { + testClassesDir = sourceSets.integrationTest.output.classesDir + classpath = sourceSets.integrationTest.runtimeClasspath + testLogging { + showStandardStreams = true + } +} + +integrationTest.dependsOn buildDockerImage + project.build.dependsOn buildDockerImage + assemble.dependsOn jar diff --git a/cli/src/test/java/com/containersol/minimesos/main/CommandInitTest.java b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandInitTest.java similarity index 100% rename from cli/src/test/java/com/containersol/minimesos/main/CommandInitTest.java rename to cli/src/integration-test/java/com/containersol/minimesos/main/CommandInitTest.java diff --git a/cli/src/test/java/com/containersol/minimesos/main/CommandPsTest.java b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandPsTest.java similarity index 89% rename from cli/src/test/java/com/containersol/minimesos/main/CommandPsTest.java rename to cli/src/integration-test/java/com/containersol/minimesos/main/CommandPsTest.java index ab3d60cf..7b8e9731 100644 --- a/cli/src/test/java/com/containersol/minimesos/main/CommandPsTest.java +++ b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandPsTest.java @@ -12,6 +12,7 @@ import org.junit.Test; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import static org.junit.Assert.assertEquals; @@ -23,7 +24,7 @@ public class CommandPsTest { private static final String FORMAT = "%-20s %-20s %s\n"; private static final Object[] COLUMNS = { "FRAMEWORK", "TASK", "STATE" }; - private static final Object[] VALUES = { "marathon", "weave-scope", "TASK_RUNNING" }; + private static final Object[] VALUES = {"marathon", "weave-scope", "TASK_RUNNING" }; private ByteArrayOutputStream outputStream; @@ -36,7 +37,7 @@ public void initTest() { } @Test - public void execute() { + public void execute() throws UnsupportedEncodingException { State state = new State(); Framework marathon = new Framework(); marathon.setName("marathon"); @@ -68,7 +69,7 @@ public void execute() { commandPs.execute(); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertEquals(String.format(FORMAT, COLUMNS) + String.format(FORMAT, VALUES), result); } diff --git a/cli/src/test/java/com/containersol/minimesos/main/CommandTest.java b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandTest.java similarity index 80% rename from cli/src/test/java/com/containersol/minimesos/main/CommandTest.java rename to cli/src/integration-test/java/com/containersol/minimesos/main/CommandTest.java index 06c436e4..0f1b2f11 100644 --- a/cli/src/test/java/com/containersol/minimesos/main/CommandTest.java +++ b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandTest.java @@ -13,6 +13,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertFalse; @@ -40,7 +41,7 @@ public void destroyCluster() { @Test public void testUpAndDestroy() { CommandUp commandUp = new CommandUp(); - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.execute(); MesosCluster cluster = commandUp.getCluster(); @@ -59,14 +60,14 @@ public void testUpAndDestroy() { @Test public void testUp_invalidMinimesosFile() throws IOException { - FileUtils.write(repository.getMinimesosFile(), "invalid"); + FileUtils.write(repository.getMinimesosFile(), "invalid", "UTF-8"); CommandUp commandUp = new CommandUp(); - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.execute(); MesosCluster cluster = commandUp.getCluster(); - String fileContent = FileUtils.readFileToString(repository.getMinimesosFile()); + String fileContent = FileUtils.readFileToString(repository.getMinimesosFile(), "UTF-8"); assertEquals("Invalid state file has not been overwritten", cluster.getClusterId(), fileContent); CommandDestroy commandDestroy = new CommandDestroy(); @@ -80,7 +81,7 @@ public void testUp_invalidMinimesosFile() throws IOException { @Test public void testUp_alreadyRunning() { CommandUp commandUp = new CommandUp(); - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.execute(); MesosCluster firstCluster = commandUp.getCluster(); @@ -101,13 +102,13 @@ public void testUp_alreadyRunning() { @Test public void testInfo_runningCluster() throws IOException { CommandUp commandUp = new CommandUp(); - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.execute(); CommandInfo commandInfo = new CommandInfo(ps); commandInfo.execute(); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertTrue(result.contains("Minimesos cluster is running")); assertTrue(result.contains("Mesos version")); @@ -118,21 +119,21 @@ public void testInfo_notRunning() throws IOException { CommandInfo commandInfo = new CommandInfo(ps); commandInfo.execute(); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertTrue("Expected phrase not found in: " + result, result.contains("Cluster ID is not found")); } @Test public void testState() throws IOException { CommandUp commandUp = new CommandUp(); - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.execute(); MesosCluster cluster = commandUp.getCluster(); CommandState commandState = new CommandState(ps); commandState.execute(); - JSONObject state = new JSONObject(outputStream.toString()); + JSONObject state = new JSONObject(outputStream.toString("UTF-8")); assertEquals("master@" + cluster.getMaster().getIpAddress() + ":5050", state.getString("leader")); } @@ -146,11 +147,11 @@ public void testInstallCommandValidation() { @Test public void testInstall() { CommandUp commandUp = new CommandUp(); - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.execute(); CommandInstall install = new CommandInstall(); - install.setMarathonFile("src/test/resources/app.json"); + install.setMarathonFile("src/integration-test/resources/app.json"); install.execute(); } @@ -161,7 +162,7 @@ public void testInstall_alreadyRunning() { commandUp.execute(); CommandInstall install = new CommandInstall(); - install.setMarathonFile("src/test/resources/app.json"); + install.setMarathonFile("src/integration-test/resources/app.json"); install.execute(); install.execute(); @@ -172,17 +173,17 @@ public void testState_notRunning() throws IOException { CommandState commandState = new CommandState(ps); commandState.execute(); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertTrue(result.contains("Minimesos cluster is not running")); } @Test - public void testCompleteInitFile() { + public void testCompleteInitFile() throws UnsupportedEncodingException { CommandUp commandUp = new CommandUp(ps); - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.execute(); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertTrue("Command up output does not contain expected line", result.contains("Minimesos cluster is running")); assertTrue(result.contains("Mesos version")); diff --git a/cli/src/test/java/com/containersol/minimesos/main/CommandUninstallTest.java b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandUninstallTest.java similarity index 85% rename from cli/src/test/java/com/containersol/minimesos/main/CommandUninstallTest.java rename to cli/src/integration-test/java/com/containersol/minimesos/main/CommandUninstallTest.java index d0933ab2..7bf637ef 100644 --- a/cli/src/test/java/com/containersol/minimesos/main/CommandUninstallTest.java +++ b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandUninstallTest.java @@ -13,6 +13,7 @@ import org.mockito.Mockito; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; public class CommandUninstallTest { @@ -43,22 +44,22 @@ public void initTest() { } @Test - public void execute() { + public void execute() throws UnsupportedEncodingException { Mockito.doNothing().when(marathon).deleteApp("app"); commandUninstall.execute(); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); Assert.assertEquals("Deleted app 'app'\n", result); } @Test - public void execute_appDoesNotExist() { + public void execute_appDoesNotExist() throws UnsupportedEncodingException { Mockito.doThrow(new MinimesosException("App does not exist")).when(marathon).deleteApp("app"); commandUninstall.execute(); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); Assert.assertEquals("", result); } } diff --git a/cli/src/test/java/com/containersol/minimesos/main/CommandUpTest.java b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandUpTest.java similarity index 86% rename from cli/src/test/java/com/containersol/minimesos/main/CommandUpTest.java rename to cli/src/integration-test/java/com/containersol/minimesos/main/CommandUpTest.java index 9e2f9ab9..a5ff5b16 100644 --- a/cli/src/test/java/com/containersol/minimesos/main/CommandUpTest.java +++ b/cli/src/integration-test/java/com/containersol/minimesos/main/CommandUpTest.java @@ -43,13 +43,13 @@ public void testExecute_missingMinimesosFile() throws IOException { @Test(expected = MinimesosException.class) public void testExecute_invalidMinimesosFile() throws IOException { - commandUp.setClusterConfigPath("src/test/resources/configFiles/invalid-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/invalid-minimesosFile"); commandUp.execute(); } @Test public void testBasicClusterConfig() throws IOException { - commandUp.setClusterConfigPath("src/test/resources/clusterconfig/basic.groovy"); + commandUp.setClusterConfigPath("src/integration-test/resources/clusterconfig/basic.groovy"); commandUp.execute(); verify(mesosCluster).start(); @@ -57,7 +57,7 @@ public void testBasicClusterConfig() throws IOException { @Test public void testExecute_mapPortsToHost() { - commandUp.setClusterConfigPath("src/test/resources/configFiles/complete-minimesosFile"); + commandUp.setClusterConfigPath("src/integration-test/resources/configFiles/complete-minimesosFile"); commandUp.setMapPortsToHost(true); commandUp.execute(); diff --git a/cli/src/test/resources/app.json b/cli/src/integration-test/resources/app.json similarity index 100% rename from cli/src/test/resources/app.json rename to cli/src/integration-test/resources/app.json diff --git a/cli/src/test/resources/clusterconfig/basic.groovy b/cli/src/integration-test/resources/clusterconfig/basic.groovy similarity index 100% rename from cli/src/test/resources/clusterconfig/basic.groovy rename to cli/src/integration-test/resources/clusterconfig/basic.groovy diff --git a/cli/src/test/resources/clusterconfig/two-agents.groovy b/cli/src/integration-test/resources/clusterconfig/two-agents.groovy similarity index 100% rename from cli/src/test/resources/clusterconfig/two-agents.groovy rename to cli/src/integration-test/resources/clusterconfig/two-agents.groovy diff --git a/cli/src/test/resources/configFiles/complete-minimesosFile b/cli/src/integration-test/resources/configFiles/complete-minimesosFile similarity index 100% rename from cli/src/test/resources/configFiles/complete-minimesosFile rename to cli/src/integration-test/resources/configFiles/complete-minimesosFile diff --git a/cli/src/test/resources/configFiles/invalid-minimesosFile.txt b/cli/src/integration-test/resources/configFiles/invalid-minimesosFile.txt similarity index 100% rename from cli/src/test/resources/configFiles/invalid-minimesosFile.txt rename to cli/src/integration-test/resources/configFiles/invalid-minimesosFile.txt diff --git a/cli/src/test/resources/configFiles/marathonAppConfig-minimesosFile b/cli/src/integration-test/resources/configFiles/marathonAppConfig-minimesosFile similarity index 100% rename from cli/src/test/resources/configFiles/marathonAppConfig-minimesosFile rename to cli/src/integration-test/resources/configFiles/marathonAppConfig-minimesosFile diff --git a/cli/src/test/resources/configFiles/withMarathon-minimesosFile b/cli/src/integration-test/resources/configFiles/withMarathon-minimesosFile similarity index 100% rename from cli/src/test/resources/configFiles/withMarathon-minimesosFile rename to cli/src/integration-test/resources/configFiles/withMarathon-minimesosFile diff --git a/cli/src/test/resources/logback-test.xml b/cli/src/integration-test/resources/logback-test.xml similarity index 100% rename from cli/src/test/resources/logback-test.xml rename to cli/src/integration-test/resources/logback-test.xml diff --git a/cli/src/main/java/com/containersol/minimesos/main/CommandUp.java b/cli/src/main/java/com/containersol/minimesos/main/CommandUp.java index 26555a4f..332cf5ea 100644 --- a/cli/src/main/java/com/containersol/minimesos/main/CommandUp.java +++ b/cli/src/main/java/com/containersol/minimesos/main/CommandUp.java @@ -99,7 +99,7 @@ public ClusterConfig readClusterConfigFromMinimesosFile() { if (clusterConfigFile != null) { ConfigParser configParser = new ConfigParser(); try { - return configParser.parse(IOUtils.toString(clusterConfigFile)); + return configParser.parse(IOUtils.toString(clusterConfigFile, "UTF-8")); } catch (Exception e) { String msg = String.format("Failed to load cluster configuration from %s: %s", getClusterConfigPath(), e.getMessage()); throw new MinimesosException(msg, e); diff --git a/cli/src/test/java/com/containersol/minimesos/main/MainTest.java b/cli/src/test/java/com/containersol/minimesos/main/MainTest.java index 5654184b..fb8e81a0 100644 --- a/cli/src/test/java/com/containersol/minimesos/main/MainTest.java +++ b/cli/src/test/java/com/containersol/minimesos/main/MainTest.java @@ -88,28 +88,28 @@ public void testInstall() throws IOException { @Test public void testUnsupportedCommand() throws IOException { main.run(new String[]{"unsupported"}); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertUsageText(result); } @Test public void testMinusMinusHelp() throws IOException { main.run(new String[]{"--help"}); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertUsageText(result); } @Test public void testInstallNoParameters() throws IOException { main.run(new String[]{"install"}); - String output = outputStream.toString(); + String output = outputStream.toString("UTF-8"); assertTrue(output.contains("Usage: install [options]")); } @Test public void testHelp() throws IOException { main.run(new String[]{"help"}); - String result = outputStream.toString(); + String result = outputStream.toString("UTF-8"); assertUsageText(result); } diff --git a/minimesos/build.gradle b/minimesos/build.gradle index 6f20d782..b927c421 100644 --- a/minimesos/build.gradle +++ b/minimesos/build.gradle @@ -1,5 +1,28 @@ apply plugin: "groovy" +sourceSets { + main { + groovy { + // this makes the groovy-compiler compile groovy- as well as java-files. + // Needed, because java is normally compiled before groovy. + // Since we are using groovy objects from java, we need it the other way round. + srcDirs = ['src/main/groovy', 'src/main/java'] + } + java { + srcDirs = [] // don't compile Java code twice + } + } + + integrationTest { + java { + compileClasspath += main.output + test.output + runtimeClasspath += main.output + test.output + srcDir file('src/integration-test/java') + } + resources.srcDir file('src/integration-test/resources') + } +} + dependencies { compile 'org.codehaus.groovy:groovy-all:2.4.5' compile 'com.github.docker-java:docker-java:3.0.6' @@ -16,19 +39,27 @@ dependencies { testCompile "org.mockito:mockito-core:1.+" // using guru.nidi as maintenanance of the original project is dropped https://github.com/clarkware/jdepend/pull/9 testCompile "guru.nidi:jdepend:2.9.5" + + integrationTestCompile 'junit:junit:4.11' + integrationTestCompile 'com.jayway.awaitility:awaitility:1.6.3' } -sourceSets { - main { - groovy { - // this makes the groovy-compiler compile groovy- as well as java-files. - // Needed, because java is normally compiled before groovy. - // Since we are using groovy objects from java, we need it the other way round. - srcDirs = ['src/main/groovy', 'src/main/java'] - } - java { - srcDirs = [] // don't compile Java code twice - } +compileGroovy { + options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" +} + +configurations { + integrationTestCompile.extendsFrom mainCompile + integrationTestCompile.extendsFrom testCompile + integrationTestRuntime.extendsFrom mainRuntime + integrationTestRuntime.extendsFrom testRuntime +} + +task integrationTest(type: Test) { + testClassesDir = sourceSets.integrationTest.output.classesDir + classpath = sourceSets.integrationTest.runtimeClasspath + testLogging { + showStandardStreams = true } } @@ -36,3 +67,5 @@ task installMinimesosScript(type: Copy) { from "$rootDir/bin/minimesos" into "/usr/local/bin" } + +integrationTest.dependsOn project(":cli").buildDockerImage diff --git a/minimesos/src/test/java/com/containersol/minimesos/DefaultMinimumClusterTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/DefaultMinimumClusterTest.java similarity index 84% rename from minimesos/src/test/java/com/containersol/minimesos/DefaultMinimumClusterTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/DefaultMinimumClusterTest.java index 95f382e7..d93a5b32 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/DefaultMinimumClusterTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/DefaultMinimumClusterTest.java @@ -46,15 +46,15 @@ public void after() { public void mesosClusterCanBeStarted() throws Exception { State state = CLUSTER.getMaster().getState(); - assertEquals(1, state.getActivatedAgents()); + Assert.assertEquals(1, state.getActivatedAgents()); } @Test public void mesosResourcesCorrect() throws Exception { JSONObject stateInfo = CLUSTER.getMaster().getStateInfoJSON(); for (int i = 0; i < 3; i++) { - assertEquals(AgentResourcesConfig.DEFAULT_CPU.getValue(), stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getDouble("cpus"), 0.0001); - assertEquals(256, stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getInt("mem")); + Assert.assertEquals(AgentResourcesConfig.DEFAULT_CPU.getValue(), stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getDouble("cpus"), 0.0001); + Assert.assertEquals(256, stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getInt("mem")); } } @@ -81,8 +81,8 @@ public void testPullAndStartContainer() throws UnirestException { String url = "http://" + ipAddress + ":" + HelloWorldContainer.SERVICE_PORT; HttpResponse response = Unirest.get(url).asString(); - assertEquals(200, response.getStatus()); - assertTrue("Wrong message is received", response.getBody().contains("

Hello world!

")); + Assert.assertEquals(200, response.getStatus()); + Assert.assertTrue("Wrong message is received", response.getBody().contains("

Hello world!

")); } } diff --git a/minimesos/src/test/java/com/containersol/minimesos/DynamicClusterTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/DynamicClusterTest.java similarity index 79% rename from minimesos/src/test/java/com/containersol/minimesos/DynamicClusterTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/DynamicClusterTest.java index 14c76484..3ccfdd85 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/DynamicClusterTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/DynamicClusterTest.java @@ -8,14 +8,12 @@ import com.containersol.minimesos.docker.DockerContainersUtil; import com.containersol.minimesos.junit.MesosClusterTestRule; import com.containersol.minimesos.mesos.MesosAgentContainer; +import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; import java.io.FileNotFoundException; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - public class DynamicClusterTest { @ClassRule @@ -27,7 +25,7 @@ public class DynamicClusterTest { public void noMarathonTest() throws FileNotFoundException { String clusterId = CLUSTER.getClusterId(); - assertNotNull("Cluster ID must be set", clusterId); + Assert.assertNotNull("Cluster ID must be set", clusterId); // this should not throw any exceptions CLUSTER.destroy(RULE.getFactory()); @@ -40,10 +38,10 @@ public void stopWithNewContainerTest() { extraAgent.setZooKeeper(zooKeeper); String containerId = CLUSTER.addAndStartProcess(extraAgent); - assertNotNull("freshly started container is not found", DockerContainersUtil.getContainer(containerId)); + Assert.assertNotNull("freshly started container is not found", DockerContainersUtil.getContainer(containerId)); CLUSTER.destroy(RULE.getFactory()); - assertNull("new container should be stopped too", DockerContainersUtil.getContainer(containerId)); + Assert.assertNull("new container should be stopped too", DockerContainersUtil.getContainer(containerId)); } } diff --git a/minimesos/src/test/java/com/containersol/minimesos/HelloWorldContainer.java b/minimesos/src/integration-test/java/com.containersol.minimesos/HelloWorldContainer.java similarity index 95% rename from minimesos/src/test/java/com/containersol/minimesos/HelloWorldContainer.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/HelloWorldContainer.java index 6ee00dd7..428dff16 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/HelloWorldContainer.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/HelloWorldContainer.java @@ -9,7 +9,7 @@ /** * A container for testing purposes. A small web server on port 80 returns the message "hello world." */ -class HelloWorldContainer extends AbstractContainer { +public class HelloWorldContainer extends AbstractContainer { public static final String SERVICE_NAME = "hello-world-service"; public static final int SERVICE_PORT = 80; public static final String HELLO_WORLD_IMAGE = "tutum/hello-world"; diff --git a/minimesos/src/test/java/com/containersol/minimesos/MesosClusterTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/MesosClusterTest.java similarity index 80% rename from minimesos/src/test/java/com/containersol/minimesos/MesosClusterTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/MesosClusterTest.java index c8e67abf..d4141c5c 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/MesosClusterTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/MesosClusterTest.java @@ -19,10 +19,12 @@ import org.apache.commons.io.output.ByteArrayOutputStream; import org.json.JSONObject; import org.junit.After; +import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -53,7 +55,7 @@ public void testLoadCluster_noContainersFound() { public void mesosAgentStateInfoJSONMatchesSchema() throws UnirestException, JsonParseException, JsonMappingException { String agentId = CLUSTER.getAgents().get(0).getContainerId(); JSONObject state = CLUSTER.getAgentStateInfo(agentId); - assertNotNull(state); + Assert.assertNotNull(state); } @Test @@ -61,23 +63,23 @@ public void mesosClusterCanBeStarted() throws Exception { MesosMaster master = CLUSTER.getMaster(); State state = master.getState(); - assertEquals(3, state.getActivatedAgents()); + Assert.assertEquals(3, state.getActivatedAgents()); } @Test public void mesosResourcesCorrect() throws Exception { JSONObject stateInfo = CLUSTER.getMaster().getStateInfoJSON(); for (int i = 0; i < 3; i++) { - assertEquals((long) 1, stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getLong("cpus")); - assertEquals(256, stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getInt("mem")); + Assert.assertEquals((long) 1, stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getLong("cpus")); + Assert.assertEquals(256, stateInfo.getJSONArray("slaves").getJSONObject(0).getJSONObject("resources").getInt("mem")); } } @Test - public void testAgentStateRetrieval() { + public void testAgentStateRetrieval() throws UnsupportedEncodingException { List agents = CLUSTER.getAgents(); - assertNotNull(agents); - assertTrue(agents.size() > 0); + Assert.assertNotNull(agents); + Assert.assertTrue(agents.size() > 0); MesosAgent agent = agents.get(0); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -87,9 +89,9 @@ public void testAgentStateRetrieval() { CLUSTER.state(ps, cliContainerId); - String state = outputStream.toString(); - assertTrue(state.contains("frameworks")); - assertTrue(state.contains("resources")); + String state = outputStream.toString("UTF-8"); + Assert.assertTrue(state.contains("frameworks")); + Assert.assertTrue(state.contains("resources")); } @Test @@ -101,7 +103,7 @@ public void dockerExposeResourcesPorts() throws Exception { InspectContainerResponse response = DockerClientFactory.build().inspectContainerCmd(container.getContainerId()).exec(); Map bindings = response.getNetworkSettings().getPorts().getBindings(); for (Integer port : ports) { - assertTrue(bindings.containsKey(new ExposedPort(port))); + Assert.assertTrue(bindings.containsKey(new ExposedPort(port))); } } } @@ -112,7 +114,7 @@ public void testPullAndStartContainer() throws UnirestException { String containerId = CLUSTER.addAndStartProcess(container); String ipAddress = DockerContainersUtil.getIpAddress(containerId); String url = "http://" + ipAddress + ":" + HelloWorldContainer.SERVICE_PORT; - assertEquals(200, Unirest.get(url).asString().getStatus()); + Assert.assertEquals(200, Unirest.get(url).asString().getStatus()); } @Test @@ -123,9 +125,9 @@ public void testMasterLinkedToAgents() throws UnirestException { List links = Arrays.asList(exec.getHostConfig().getLinks()); - assertNotNull(links); - assertEquals("link to zookeeper is expected", 1, links.size()); - assertEquals("minimesos-zookeeper", links.get(0).getAlias()); + Assert.assertNotNull(links); + Assert.assertEquals("link to zookeeper is expected", 1, links.size()); + Assert.assertEquals("minimesos-zookeeper", links.get(0).getAlias()); } } diff --git a/minimesos/src/test/java/com/containersol/minimesos/RestoreConfigurationFromRunningClusterTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/RestoreConfigurationFromRunningClusterTest.java similarity index 79% rename from minimesos/src/test/java/com/containersol/minimesos/RestoreConfigurationFromRunningClusterTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/RestoreConfigurationFromRunningClusterTest.java index 54d0bd50..467e893e 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/RestoreConfigurationFromRunningClusterTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/RestoreConfigurationFromRunningClusterTest.java @@ -3,12 +3,10 @@ import com.containersol.minimesos.cluster.MesosCluster; import com.containersol.minimesos.junit.MesosClusterTestRule; import com.containersol.minimesos.mesos.MesosClusterContainersFactory; +import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class RestoreConfigurationFromRunningClusterTest { @ClassRule @@ -21,7 +19,7 @@ public void testMapPortsToHostRestored() { String clusterId = CLUSTER.getClusterId(); MesosCluster cluster = MesosCluster.loadCluster(clusterId, new MesosClusterContainersFactory()); - assertTrue("Deserialize cluster is expected to remember mapPortsToHost setting", cluster.isMapPortsToHost()); + Assert.assertTrue("Deserialize cluster is expected to remember mapPortsToHost setting", cluster.isMapPortsToHost()); } @Test @@ -29,7 +27,7 @@ public void testMesosVersionRestored() { String clusterId = CLUSTER.getClusterId(); MesosCluster cluster = MesosCluster.loadCluster(clusterId, new MesosClusterContainersFactory()); - assertEquals("1.0.0", cluster.getMesosVersion()); + Assert.assertEquals("1.0.0", cluster.getMesosVersion()); } } diff --git a/minimesos/src/test/java/com/containersol/minimesos/RunTaskTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/RunTaskTest.java similarity index 95% rename from minimesos/src/test/java/com/containersol/minimesos/RunTaskTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/RunTaskTest.java index 489624f8..52252c50 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/RunTaskTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/RunTaskTest.java @@ -11,6 +11,7 @@ import com.github.dockerjava.api.command.CreateContainerCmd; import com.github.dockerjava.api.model.Frame; import com.github.dockerjava.core.command.LogContainerResultCallback; +import com.jayway.awaitility.Awaitility; import org.junit.ClassRule; import org.junit.Test; @@ -66,7 +67,7 @@ protected CreateContainerCmd dockerCommand() { String containerId = CLUSTER.addAndStartProcess(mesosAgent); - await("Mesos Execute container did not start responding").atMost(60, TimeUnit.SECONDS).until(() -> { + Awaitility.await("Mesos Execute container did not start responding").atMost(60, TimeUnit.SECONDS).until(() -> { LogContainerTestCallback cb1 = new LogContainerTestCallback(); DockerClientFactory.build().logContainerCmd(mesosAgent.getContainerId()).withContainerId(containerId).withStdOut(true).exec(cb1); cb1.awaitCompletion(); diff --git a/minimesos/src/test/java/com/containersol/minimesos/AuthenticationTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/authentication/AuthenticationTest.java similarity index 70% rename from minimesos/src/test/java/com/containersol/minimesos/AuthenticationTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/authentication/AuthenticationTest.java index 4ea6a03c..14b27d59 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/AuthenticationTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/authentication/AuthenticationTest.java @@ -1,13 +1,12 @@ -package com.containersol.minimesos; +package com.containersol.minimesos.authentication; import com.containersol.minimesos.cluster.MesosCluster; import com.containersol.minimesos.junit.MesosClusterTestRule; import com.mashape.unirest.http.exceptions.UnirestException; +import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class AuthenticationTest { public static final String aclExampleUnknownSyntaxUsedInStateJson = "run_tasks {\n principals {\n values: \"foo\"\n values: \"bar\"\n }\n users {\n values: \"alice\"\n }\n}\n"; @@ -19,7 +18,7 @@ public class AuthenticationTest { @Test public void clusterHasZookeeperUrl() throws UnirestException { - assertEquals("zk://" + CLUSTER.getZooKeeper().getIpAddress() + ":2181/mesos", CLUSTER.getMaster().getState().getFlags().get("zk")); + Assert.assertEquals("zk://" + CLUSTER.getZooKeeper().getIpAddress() + ":2181/mesos", CLUSTER.getMaster().getState().getFlags().get("zk")); } /** @@ -28,8 +27,8 @@ public void clusterHasZookeeperUrl() throws UnirestException { */ @Test public void extraEnvironmentVariablesPassedToMesosMaster() throws UnirestException { - assertEquals("true", CLUSTER.getMaster().getState().getFlags().get("authenticate")); - assertEquals(aclExampleUnknownSyntaxUsedInStateJson, CLUSTER.getMaster().getState().getFlags().get("acls")); + Assert.assertEquals("true", CLUSTER.getMaster().getState().getFlags().get("authenticate")); + Assert.assertEquals(aclExampleUnknownSyntaxUsedInStateJson, CLUSTER.getMaster().getState().getFlags().get("acls")); } } diff --git a/minimesos/src/test/java/com/containersol/minimesos/ConsulRegistrationTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/consul/ConsulRegistrationTest.java similarity index 71% rename from minimesos/src/test/java/com/containersol/minimesos/ConsulRegistrationTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/consul/ConsulRegistrationTest.java index a5bce37e..09a60e92 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/ConsulRegistrationTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/consul/ConsulRegistrationTest.java @@ -1,14 +1,17 @@ -package com.containersol.minimesos; +package com.containersol.minimesos.consul; +import com.containersol.minimesos.HelloWorldContainer; import com.containersol.minimesos.cluster.MesosCluster; import com.containersol.minimesos.config.ConsulConfig; import com.containersol.minimesos.docker.DockerContainersUtil; import com.containersol.minimesos.junit.MesosClusterTestRule; +import com.jayway.awaitility.Awaitility; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; import org.json.JSONArray; import org.json.JSONObject; import org.junit.After; +import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; @@ -40,17 +43,17 @@ public void testRegisterServiceWithConsul() { final JSONArray[] body = new JSONArray[1]; - await("Test container did appear in Registrator").atMost(30, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { + Awaitility.await("Test container did appear in Registrator").atMost(30, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> { try { body[0] = Unirest.get(url).asJson().getBody().getArray(); } catch (UnirestException e) { throw new AssertionError(e); } - assertEquals(1, body[0].length()); + Assert.assertEquals(1, body[0].length()); }); JSONObject service = body[0].getJSONObject(0); - assertEquals(HelloWorldContainer.SERVICE_PORT, service.getInt("ServicePort")); + Assert.assertEquals(HelloWorldContainer.SERVICE_PORT, service.getInt("ServicePort")); } @Test @@ -59,15 +62,15 @@ public void testConsulShouldBeIgnored() throws UnirestException { String url = String.format("http://%s:%d/v1/catalog/services", ipAddress, ConsulConfig.CONSUL_HTTP_PORT); JSONArray body = Unirest.get(url).asJson().getBody().getArray(); - assertEquals(1, body.length()); + Assert.assertEquals(1, body.length()); JSONObject service = body.getJSONObject(0); - assertFalse(service.has("consul-server-8300")); - assertFalse(service.has("consul-server-8301")); - assertFalse(service.has("consul-server-8302")); - assertFalse(service.has("consul-server-8400")); - assertFalse(service.has("consul-server-8500")); - assertFalse(service.has("consul-server-8600")); + Assert.assertFalse(service.has("consul-server-8300")); + Assert.assertFalse(service.has("consul-server-8301")); + Assert.assertFalse(service.has("consul-server-8302")); + Assert.assertFalse(service.has("consul-server-8400")); + Assert.assertFalse(service.has("consul-server-8500")); + Assert.assertFalse(service.has("consul-server-8600")); } } diff --git a/minimesos/src/test/java/com/containersol/minimesos/marathon/MarathonContainerTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/marathon/MarathonContainerTest.java similarity index 100% rename from minimesos/src/test/java/com/containersol/minimesos/marathon/MarathonContainerTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/marathon/MarathonContainerTest.java diff --git a/minimesos/src/test/java/com/containersol/minimesos/mesos/MesosAgentTest.java b/minimesos/src/integration-test/java/com.containersol.minimesos/mesos/MesosAgentTest.java similarity index 81% rename from minimesos/src/test/java/com/containersol/minimesos/mesos/MesosAgentTest.java rename to minimesos/src/integration-test/java/com.containersol.minimesos/mesos/MesosAgentTest.java index aafb7cfe..863b1daa 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/mesos/MesosAgentTest.java +++ b/minimesos/src/integration-test/java/com.containersol.minimesos/mesos/MesosAgentTest.java @@ -4,11 +4,9 @@ import com.containersol.minimesos.cluster.ZooKeeper; import com.containersol.minimesos.config.ClusterConfig; import com.containersol.minimesos.config.MesosAgentConfig; +import org.junit.Assert; import org.junit.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - public class MesosAgentTest { private static final ZooKeeper zooKeeper = new ZooKeeperContainer(); @@ -39,9 +37,9 @@ public void testPullingWrongContainerMessage() { MesosAgentContainer agent = new MesosAgentContainer(config); try { agent.pullImage(); - fail("Pulling non-existing image should result in an exception"); + Assert.fail("Pulling non-existing image should result in an exception"); } catch (MinimesosException mme) { - assertTrue("Name of the image should be in the error message: " + mme.getMessage(), mme.getMessage().contains(imageTag)); + Assert.assertTrue("Name of the image should be in the error message: " + mme.getMessage(), mme.getMessage().contains(imageTag)); } } diff --git a/minimesos/src/main/java/com/containersol/minimesos/cluster/ClusterRepository.java b/minimesos/src/main/java/com/containersol/minimesos/cluster/ClusterRepository.java index 4a8fb64c..33b93903 100644 --- a/minimesos/src/main/java/com/containersol/minimesos/cluster/ClusterRepository.java +++ b/minimesos/src/main/java/com/containersol/minimesos/cluster/ClusterRepository.java @@ -65,7 +65,7 @@ public void deleteClusterFile() { public String readClusterId() { try { File minimesosFile = getMinimesosFile(); - String clusterId = FileUtils.readFileToString(minimesosFile); + String clusterId = FileUtils.readFileToString(minimesosFile, "UTF-8"); LOGGER.debug("Reading cluster ID from " + minimesosFile + ": " + clusterId); return clusterId; } catch (IOException e) { diff --git a/minimesos/src/main/java/com/containersol/minimesos/mesos/MesosClusterContainersFactory.java b/minimesos/src/main/java/com/containersol/minimesos/mesos/MesosClusterContainersFactory.java index 93a7c0e8..53980cab 100644 --- a/minimesos/src/main/java/com/containersol/minimesos/mesos/MesosClusterContainersFactory.java +++ b/minimesos/src/main/java/com/containersol/minimesos/mesos/MesosClusterContainersFactory.java @@ -144,7 +144,7 @@ public MesosCluster createMesosCluster(String path) { public MesosCluster createMesosCluster(InputStream inputStream) { try { - ClusterConfig clusterConfig = new ConfigParser().parse(IOUtils.toString(inputStream)); + ClusterConfig clusterConfig = new ConfigParser().parse(IOUtils.toString(inputStream, "UTF-8")); return createMesosCluster(clusterConfig); } catch (IOException e) { throw new MinimesosException("Could not read minimesos config:" + e.getCause()); diff --git a/minimesos/src/test/java/com/containersol/minimesos/util/EnvironmentBuilderTest.java b/minimesos/src/test/java/com/containersol/minimesos/util/EnvironmentBuilderTest.java index 0ed2f427..81bf21aa 100644 --- a/minimesos/src/test/java/com/containersol/minimesos/util/EnvironmentBuilderTest.java +++ b/minimesos/src/test/java/com/containersol/minimesos/util/EnvironmentBuilderTest.java @@ -12,6 +12,7 @@ public class EnvironmentBuilderTest { @Test + @SuppressWarnings("unchecked") public void mergingSeveralSourcesProducesCorrectMap() { Map source1 = new TreeMap<>(); source1.put("envVar1", "value1"); @@ -32,4 +33,4 @@ public void mergingSeveralSourcesProducesCorrectMap() { is("envVar2=value2"), is("envVar3=value3"), is("envVar4=value4"), is("envVar5=value5"), is("envVar6=value6"), is("envVarX=valueX"))); } -} \ No newline at end of file +} diff --git a/settings.gradle b/settings.gradle index ea472a58..b9350af4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,3 @@ rootProject.name = 'minimesos-project' include "minimesos" -include "test-framework-docker:scheduler" -include "test-framework-docker:executor" -include "test-framework-docker:system-test" include "cli" diff --git a/test-framework-docker/build.gradle b/test-framework-docker/build.gradle deleted file mode 100644 index cdea6a8b..00000000 --- a/test-framework-docker/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage -import com.bmuschko.gradle.docker.tasks.image.DockerPushImage -import com.bmuschko.gradle.docker.tasks.image.DockerTagImage - -subprojects { - - dependencies { - compile "org.apache.mesos:mesos:${mesosVer}" - compile 'com.google.code.gson:gson:2.3' // marshalling between the scheduler and executor - - testCompile 'junit:junit:4.12' - testCompile "org.mockito:mockito-all:1.9.5" - } - - afterEvaluate { project -> - if (new File(project.projectDir, 'Dockerfile').exists()) { - task buildDockerImage(type: DockerBuildImage, dependsOn: [taskCopyFilesForDocker], description: 'build Docker image') { - setInputDir(file(project.projectDir)) - setTag(project.imageName) - } - - project.build.dependsOn buildDockerImage - - for (tag in ['latest', 'version']) { - String uppercasedTag = tag.capitalize() - - task "tagDockerImageWith$uppercasedTag"(type: DockerTagImage, description: 'tag Docker image') { - setImageId(project.imageName) - setTag('version' == tag ? project.version : tag) - setRepository(project.imageName) - setForce(true) - } - - task "publishDockerImageWith$uppercasedTag"(type: DockerPushImage, dependsOn: ["tagDockerImageWith$uppercasedTag"], - description: 'publish Docker image') { - setImageName(project.imageName) - setTag('version' == tag ? project.version : tag) - } - } - } - } -} diff --git a/test-framework-docker/executor/Dockerfile b/test-framework-docker/executor/Dockerfile deleted file mode 100644 index ada21f99..00000000 --- a/test-framework-docker/executor/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM containersol/mesos-agent:1.0.0-0.1.0 - -ADD ./build/docker/mesos-hello-world-executor.jar /tmp/mesos-hello-world-executor.jar -ADD ./build/docker/start-executor.sh /tmp/start-executor.sh - -RUN chmod +x /tmp/start-executor.sh - -ENTRYPOINT ["/tmp/start-executor.sh"] diff --git a/test-framework-docker/executor/build.gradle b/test-framework-docker/executor/build.gradle deleted file mode 100644 index 183d3573..00000000 --- a/test-framework-docker/executor/build.gradle +++ /dev/null @@ -1,40 +0,0 @@ -apply plugin: 'application' - -mainClassName = "com.containersolutions.mesoshelloworld.executor.FrameworkExecutor" -ext { - imageName = repository + '/mesos-hello-world-executor' -} - -jar { - baseName = "mesos-hello-world-executor" - from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } // Include dependencies - manifest { - attributes( - 'Main-Class': mainClassName, - 'Implementation-Version': project.version - ) - } -} - -dependencies { - compile 'org.slf4j:slf4j-api:1.7.12' - compile 'ch.qos.logback:logback-core:1.1.3' - compile 'ch.qos.logback:logback-classic:1.1.3' -} - -task taskCopyFilesForDocker(type: Copy) { - dependsOn "copyShellScript", "copyJar" -} - -task copyJar(type: Copy) { - from "build/libs/mesos-hello-world-executor-${project.version}.jar" - into 'build/docker' - rename { String fileName -> - fileName.replace("-${project.version}", "") - } -} - -task copyShellScript(type: Copy) { - from "start-executor.sh" - into 'build/docker' -} diff --git a/test-framework-docker/executor/src/main/java/com/containersolutions/mesoshelloworld/executor/FrameworkExecutor.java b/test-framework-docker/executor/src/main/java/com/containersolutions/mesoshelloworld/executor/FrameworkExecutor.java deleted file mode 100644 index 9c18176b..00000000 --- a/test-framework-docker/executor/src/main/java/com/containersolutions/mesoshelloworld/executor/FrameworkExecutor.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.containersolutions.mesoshelloworld.executor; - -import org.apache.mesos.Executor; -import org.apache.mesos.ExecutorDriver; -import org.apache.mesos.MesosExecutorDriver; -import org.apache.mesos.Protos.ExecutorInfo; -import org.apache.mesos.Protos.FrameworkInfo; -import org.apache.mesos.Protos.SlaveInfo; -import org.apache.mesos.Protos.Status; -import org.apache.mesos.Protos.TaskID; -import org.apache.mesos.Protos.TaskInfo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Adapted from https://github.com/apache/mesos/blob/0.22.1/src/examples/java/TestExecutor.java - */ -public class FrameworkExecutor implements Executor { - - private static final Logger LOGGER = LoggerFactory.getLogger(FrameworkExecutor.class); - - public static final String RESPONSE_STRING = "Hello world"; - - private Thread thread; - - public static void main(String[] args) throws Exception { - MesosExecutorDriver driver = new MesosExecutorDriver(new FrameworkExecutor()); - if (driver.run() != Status.DRIVER_STOPPED) { - throw new IllegalStateException("Mesos Executor Driver is not stopped"); - } - } - - @Override - public void registered(ExecutorDriver driver, - ExecutorInfo executorInfo, - FrameworkInfo frameworkInfo, - SlaveInfo slaveInfo) { - LOGGER.info("Registered executor on " + slaveInfo.getHostname()); - } - - @Override - public void reregistered(ExecutorDriver driver, SlaveInfo executorInfo) { - LOGGER.info("Not implemented: executor re-registers with a restarted slave"); - } - - @Override - public void disconnected(ExecutorDriver driver) { - LOGGER.info("Not implemented: executor becomes \"disconnected\" from the slave"); - } - - @Override - public void launchTask(final ExecutorDriver driver, final TaskInfo task) { - thread = new FrameworkTask(driver, task); - thread.start(); - } - - @Override - public void killTask(ExecutorDriver driver, TaskID taskId) { - if (thread != null && thread.isAlive()) { - thread.interrupt(); - } - } - - @Override - public void frameworkMessage(ExecutorDriver driver, byte[] data) { - LOGGER.info("Not implemented: framework message has arrived"); - } - - - @Override - public void shutdown(ExecutorDriver driver) { - LOGGER.info("Not implemented: executor should terminate all of it's currently running tasks"); - } - - @Override - public void error(ExecutorDriver driver, String message) { - LOGGER.info("Not implemented: fatal error has occurred with the executor"); - } - -} diff --git a/test-framework-docker/executor/src/main/java/com/containersolutions/mesoshelloworld/executor/FrameworkTask.java b/test-framework-docker/executor/src/main/java/com/containersolutions/mesoshelloworld/executor/FrameworkTask.java deleted file mode 100644 index 78365548..00000000 --- a/test-framework-docker/executor/src/main/java/com/containersolutions/mesoshelloworld/executor/FrameworkTask.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.containersolutions.mesoshelloworld.executor; - -import com.sun.net.httpserver.HttpExchange; //NOSONAR it's acceptable for test framework -import com.sun.net.httpserver.HttpHandler; //NOSONAR it's acceptable for test framework -import com.sun.net.httpserver.HttpServer; //NOSONAR it's acceptable for test framework -import org.apache.mesos.ExecutorDriver; -import org.apache.mesos.Protos; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetSocketAddress; - -import static com.containersolutions.mesoshelloworld.executor.FrameworkExecutor.RESPONSE_STRING; - -public class FrameworkTask extends Thread { - - private static final Logger LOGGER = LoggerFactory.getLogger(FrameworkTask.class); - - private final Protos.TaskInfo task; - private final ExecutorDriver driver; - - public FrameworkTask(ExecutorDriver driver, Protos.TaskInfo task) { - this.driver = driver; - this.task = task; - } - - @Override - public void run() { - try { - Integer port = task.getDiscovery().getPorts().getPorts(0).getNumber(); - LOGGER.info("Starting webserver on port " + port); - startWebServer(port); - - Protos.TaskStatus status = Protos.TaskStatus.newBuilder() - .setTaskId(task.getTaskId()) - .setState(Protos.TaskState.TASK_RUNNING).build(); - - driver.sendStatusUpdate(status); - - LOGGER.info("Running task " + task.getTaskId().getValue()); - } catch (Exception e) { - LOGGER.info("Unable to start webserver:" + e); - - Protos.TaskStatus status = Protos.TaskStatus.newBuilder() - .setTaskId(task.getTaskId()) - .setState(Protos.TaskState.TASK_FINISHED).build(); - - driver.sendStatusUpdate(status); - } - } - - private void startWebServer(Integer port) throws IOException { - HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); - server.createContext("/", new MyHandler()); - server.setExecutor(null); // creates a default executor - server.start(); - } - - private class MyHandler implements HttpHandler { - @Override - public void handle(HttpExchange t) throws IOException { - - t.sendResponseHeaders(200, RESPONSE_STRING.length()); - OutputStream os = t.getResponseBody(); - os.write(RESPONSE_STRING.getBytes()); - os.close(); - } - } - -} diff --git a/test-framework-docker/executor/src/main/resources/logback.xml b/test-framework-docker/executor/src/main/resources/logback.xml deleted file mode 100644 index b604aebc..00000000 --- a/test-framework-docker/executor/src/main/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - System.out - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - diff --git a/test-framework-docker/executor/start-executor.sh b/test-framework-docker/executor/start-executor.sh deleted file mode 100755 index 8a9961fe..00000000 --- a/test-framework-docker/executor/start-executor.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -java $JAVA_OPTS -Djava.library.path=/usr/local/lib -jar /tmp/mesos-hello-world-executor.jar $@ \ No newline at end of file diff --git a/test-framework-docker/scheduler/Dockerfile b/test-framework-docker/scheduler/Dockerfile deleted file mode 100644 index 0a30d9b4..00000000 --- a/test-framework-docker/scheduler/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM containersol/mesos-master:1.0.0-0.1.0 - -ADD ./build/docker/mesos-hello-world-scheduler.jar /tmp/mesos-hello-world-scheduler.jar -ADD ./build/docker/start-scheduler.sh /tmp/start-scheduler.sh - -RUN chmod +x /tmp/start-scheduler.sh - -ENTRYPOINT ["/tmp/start-scheduler.sh"] diff --git a/test-framework-docker/scheduler/build.gradle b/test-framework-docker/scheduler/build.gradle deleted file mode 100644 index f3a49317..00000000 --- a/test-framework-docker/scheduler/build.gradle +++ /dev/null @@ -1,40 +0,0 @@ -apply plugin: 'application' - -mainClassName = "com.containersolutions.mesoshelloworld.scheduler.Main" -ext { - imageName = repository + '/mesos-hello-world-scheduler' -} - -dependencies { - compile "com.beust:jcommander:1.48" - compile 'org.slf4j:slf4j-api:1.7.12' -} - -jar { - baseName = "mesos-hello-world-scheduler" - from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } // Include dependencies - from { project(":test-framework-docker:executor").getTasksByName("copyJar", false)[0].outputs.files[0] } // Include executor, just in case - manifest { - attributes( - 'Main-Class': mainClassName, - 'Implementation-Version': project.version - ) - } -} - -task taskCopyFilesForDocker(type: Copy) { - dependsOn "copyShellScript", "copyJar" -} - -task copyJar(type: Copy) { - from "build/libs/mesos-hello-world-scheduler-${project.version}.jar" - into 'build/docker' - rename { String fileName -> - fileName.replace("-${project.version}", "") - } -} - -task copyShellScript(type: Copy) { - from "start-scheduler.sh" - into 'build/docker' -} diff --git a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/Configuration.java b/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/Configuration.java deleted file mode 100644 index 61c7bc54..00000000 --- a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/Configuration.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.containersolutions.mesoshelloworld.scheduler; - -import com.beust.jcommander.IParameterValidator; -import com.beust.jcommander.JCommander; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.ParameterException; - -/** - */ -public class Configuration { - public static final String MESOS_MASTER = "--mesosMaster"; - public static final String EXECUTOR_IMAGE = "--executorImage"; - public static final String DEFAULT_EXECUTOR_IMAGE = "containersol/mesos-hello-world-executor"; - public static final String EXECUTOR_NUMBER = "--executorNumber"; - public static final String EXECUTOR_FORCE_PULL_IMAGE = "--executorForcePullImage"; - @Parameter(names = {MESOS_MASTER}, description = "The Mesos master IP", validateWith = NotEmptyString.class) - private String mesosMaster = ""; - @Parameter(names = {EXECUTOR_IMAGE}, description = "The docker executor image to use.") - private String executorImage = DEFAULT_EXECUTOR_IMAGE; - @Parameter(names = {EXECUTOR_NUMBER}, description = "Number of executors") - private Integer executorNumber = 3; - @Parameter(names = {EXECUTOR_FORCE_PULL_IMAGE}, arity = 1, description = "Option to force pull the executor image.") - private Boolean executorForcePullImage = false; - - @Parameter(names = {"--frameworkPrincipal"}, description = "The principal to authenticate as") - private String frameworkPrincipal = null; - @Parameter(names = {"--frameworkSecret"}, description = "The secret to authenticate with, if authenticating as a principal") - private String frameworkSecret = null; - - public Configuration(String[] args) { - final JCommander jCommander = new JCommander(); - jCommander.addObject(this); - try { - jCommander.parse(args); // Parse command line args into configuration class. - } catch (com.beust.jcommander.ParameterException ex) { - System.out.println(ex); - jCommander.setProgramName("(Options preceded by an asterisk are required)"); - jCommander.usage(); - throw ex; - } - } - - public String getMesosMaster() { - if (mesosMaster.isEmpty()) { - throw new IllegalArgumentException("You must pass the mesos master IP address"); - } - return mesosMaster; - } - - public String getExecutorImage() { - return executorImage; - } - - public Integer getExecutorNumber() { - return executorNumber; - } - - public Boolean getExecutorForcePullImage() { - return executorForcePullImage; - } - - public String getFrameworkPrincipal() { - return frameworkPrincipal; - } - - public String getFrameworkSecret() { - return frameworkSecret; - } - - /** - * Ensures that the string is not empty. Will strip spaces. - */ - public static class NotEmptyString implements IParameterValidator { - @Override - public void validate(String name, String value) throws ParameterException { - if (value.replace(" ", "").isEmpty()) { - throw new ParameterException("Parameter " + name + " cannot be empty"); - } - } - } -} diff --git a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/FrameworkScheduler.java b/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/FrameworkScheduler.java deleted file mode 100644 index 3e7c0b3c..00000000 --- a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/FrameworkScheduler.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.containersolutions.mesoshelloworld.scheduler; - -import org.apache.mesos.Protos.ExecutorID; -import org.apache.mesos.Protos.FrameworkID; -import org.apache.mesos.Protos.MasterInfo; -import org.apache.mesos.Protos.Offer; -import org.apache.mesos.Protos.OfferID; -import org.apache.mesos.Protos.Resource; -import org.apache.mesos.Protos.SlaveID; -import org.apache.mesos.Protos.Status; -import org.apache.mesos.Protos.TaskInfo; -import org.apache.mesos.Protos.TaskState; -import org.apache.mesos.Protos.TaskStatus; -import org.apache.mesos.Scheduler; -import org.apache.mesos.SchedulerDriver; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Adapted from: https://github.com/apache/mesos/blob/0.22.1/src/examples/java/TestFramework.java - */ -public class FrameworkScheduler implements Scheduler { - - private static final Logger LOGGER = LoggerFactory.getLogger(FrameworkScheduler.class); - - public static final double CPUS_PER_TASK = 0.1; - public static final double MEM_PER_TASK = 128; - - public static final int MAX_OFFERS = 10; - - private final Configuration configuration; - private int acceptedOffers = 0; - - public FrameworkScheduler(Configuration configuration) { - this.configuration = configuration; - } - - @Override - public void resourceOffers(SchedulerDriver driver, List offers) { - - for (Offer offer : offers) { - - ResourceOffer currentOffer = new ResourceOffer(offer.getResourcesList()); - if (currentOffer.isAcceptable() && (acceptedOffers < MAX_OFFERS)) { - - LOGGER.info( - "Received acceptable offer " + offer.getId().getValue() + " with cpus: " + currentOffer.offerCpus + - " and mem: " + currentOffer.offerMem + " with ports: " + currentOffer.offerPorts); - - List newTaskList = new ArrayList<>(); - - while (newTaskList.size() < configuration.getExecutorNumber() && currentOffer.isAcceptable()) { - - TaskInfo task = new TaskInfoFactory(configuration).newTask(offer, currentOffer); - newTaskList.add(task); - - } - - Status status = driver.launchTasks(Collections.singletonList(offer.getId()), newTaskList); - LOGGER.info(String.format("Launched %d tasks. Status is %s", newTaskList.size(), status.toString())); - - acceptedOffers++; - - } else if (!currentOffer.isAcceptable()) { - LOGGER.info( - "Received unacceptable offer " + offer.getId().getValue() + " with cpus: " + currentOffer.offerCpus + - " and mem: " + currentOffer.offerMem + " with ports: " + currentOffer.offerPorts); - } - - } - - } - - @Override - public void offerRescinded(SchedulerDriver driver, OfferID offerId) { - // not supported in tests. It's ok to get task rejected - } - - @Override - public void statusUpdate(SchedulerDriver driver, TaskStatus status) { - - LOGGER.info("Status update: task " + status.getTaskId().getValue() + - " is in state " + status.getState().getValueDescriptor().getName()); - - if (status.getState() == TaskState.TASK_LOST || - status.getState() == TaskState.TASK_KILLED || - status.getState() == TaskState.TASK_FAILED) { - - LOGGER.error("Aborting because task " + status.getTaskId().getValue() + - " is in unexpected state " + - status.getState().getValueDescriptor().getName() + - " with reason '" + - status.getReason().getValueDescriptor().getName() + "'" + - " from source '" + - status.getSource().getValueDescriptor().getName() + "'" + - " with message '" + status.getMessage() + "'"); - } - - } - - @Override - public void frameworkMessage(SchedulerDriver driver, - ExecutorID executorId, - SlaveID slaveId, - byte[] data) { - // not supported in the test framework - } - - @Override - public void slaveLost(SchedulerDriver driver, SlaveID slaveId) { - // not supported in the test framework - } - - @Override - public void executorLost(SchedulerDriver driver, - ExecutorID executorId, - SlaveID slaveId, - int status) { - // not supported in the test framework - } - - @Override - public void registered(SchedulerDriver driver, - FrameworkID frameworkId, - MasterInfo masterInfo) { - LOGGER.info("Registered! ID = " + frameworkId.getValue()); - } - - @Override - public void reregistered(SchedulerDriver driver, MasterInfo masterInfo) { - // not supported in the test framework - } - - @Override - public void disconnected(SchedulerDriver driver) { - // not supported in the test framework - } - - @Override - public void error(SchedulerDriver driver, String message) { - LOGGER.info("Error: " + message); - } - - class ResourceOffer { - - final List offerPorts; - double offerCpus = 0; - double offerMem = 0; - - public ResourceOffer(List resourcesList) { - offerPorts = new ArrayList<>(resourcesList.size()); - for (Resource resource : resourcesList) { - if ("cpus".equals(resource.getName())) { - offerCpus += resource.getScalar().getValue(); - } else if ("mem".equals(resource.getName())) { - offerMem += resource.getScalar().getValue(); - } else if ("ports".equals(resource.getName())) { - for (Long p = resource.getRanges().getRange(0).getBegin(); p <= resource.getRanges().getRange(0).getEnd(); p++) { - offerPorts.add(p); - } - } - } - } - - public boolean isAcceptable() { - return offerCpus >= CPUS_PER_TASK && offerMem >= MEM_PER_TASK && (!offerPorts.isEmpty()); - } - - } -} diff --git a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/Main.java b/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/Main.java deleted file mode 100644 index 5ec8cf70..00000000 --- a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/Main.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.containersolutions.mesoshelloworld.scheduler; - -import org.apache.mesos.MesosSchedulerDriver; -import org.apache.mesos.Protos; - -public class Main { - public static void main(String[] args) throws Exception { - - Configuration configuration = new Configuration(args); - - Protos.FrameworkInfo.Builder frameworkBuilder = Protos.FrameworkInfo.newBuilder() - .setUser("") // Have Mesos fill in the current user. - .setName("Hello world example") - .setCheckpoint(true); - - String principal = configuration.getFrameworkPrincipal(); - if (principal != null) { - frameworkBuilder.setPrincipal(principal); - } - - org.apache.mesos.Scheduler scheduler = new FrameworkScheduler(configuration); - - Protos.FrameworkInfo frameworkInfo = frameworkBuilder.build(); - String mesosMaster = configuration.getMesosMaster(); - - MesosSchedulerDriver driver = - principal != null - ? new MesosSchedulerDriver( - scheduler, - frameworkInfo, - mesosMaster, - Protos.Credential.newBuilder() - .setPrincipal(principal) - .setSecret(configuration.getFrameworkSecret()) - .build() - ) - : new MesosSchedulerDriver( - scheduler, - frameworkInfo, - mesosMaster - ); - - // Ensure that the driver process terminates. - driver.stop(); - - if (driver.run() != Protos.Status.DRIVER_STOPPED) { - throw new RuntimeException("Mesos Scheduler Driver is not stopped"); - } - - } -} diff --git a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/TaskInfoFactory.java b/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/TaskInfoFactory.java deleted file mode 100644 index 07806074..00000000 --- a/test-framework-docker/scheduler/src/main/java/com/containersolutions/mesoshelloworld/scheduler/TaskInfoFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.containersolutions.mesoshelloworld.scheduler; - -import org.apache.mesos.Protos.*; - -import java.util.UUID; - -class TaskInfoFactory { - - private final Configuration configuration; - - TaskInfoFactory(Configuration configuration) { - this.configuration = configuration; - } - - TaskInfo newTask(Offer offer, FrameworkScheduler.ResourceOffer currentOffer) { - - TaskID taskId = TaskID.newBuilder().setValue(UUID.randomUUID().toString()).build(); - Long port = currentOffer.offerPorts.get(0); - - System.out.println("Launching task " + taskId.getValue() + " for port " + port + - " using offer " + offer.getId().getValue()); - - Value.Range singlePortRange = Value.Range.newBuilder().setBegin(port).setEnd(port).build(); - - TaskInfo task = TaskInfo.newBuilder() - .setName("task " + taskId.getValue()) - .setTaskId(taskId) - .setSlaveId(offer.getSlaveId()) - .addResources(Resource.newBuilder() - .setName("cpus") - .setType(Value.Type.SCALAR) - .setScalar(Value.Scalar.newBuilder().setValue(FrameworkScheduler.CPUS_PER_TASK))) - .addResources(Resource.newBuilder() - .setName("mem") - .setType(Value.Type.SCALAR) - .setScalar(Value.Scalar.newBuilder().setValue(FrameworkScheduler.MEM_PER_TASK))) - .addResources(Resource.newBuilder() - .setName("ports") - .setType(Value.Type.RANGES) - .setRanges(Value.Ranges.newBuilder().addRange(singlePortRange)) - .build() - ) - .setExecutor(newExecutorInfo(configuration)) - .setDiscovery(newDiscoveryInfo(port.intValue())) - .build(); - - - currentOffer.offerCpus -= FrameworkScheduler.CPUS_PER_TASK; - currentOffer.offerMem -= FrameworkScheduler.MEM_PER_TASK; - currentOffer.offerPorts.remove(0); - return task; - } - - private DiscoveryInfo.Builder newDiscoveryInfo(Integer port) { - DiscoveryInfo.Builder discovery = DiscoveryInfo.newBuilder(); - Ports.Builder discoveryPorts = Ports.newBuilder(); - discoveryPorts.addPorts(0, Port.newBuilder().setNumber(port).setName("port")); - discovery.setPorts(discoveryPorts); - discovery.setVisibility(DiscoveryInfo.Visibility.EXTERNAL); - return discovery; - } - - private ExecutorInfo.Builder newExecutorInfo(Configuration configuration) { - ContainerInfo.DockerInfo.Builder dockerBuilder = ContainerInfo.DockerInfo.newBuilder() - .setNetwork(ContainerInfo.DockerInfo.Network.BRIDGE) - .setImage(configuration.getExecutorImage()) - .setForcePullImage(configuration.getExecutorForcePullImage()); - - return ExecutorInfo.newBuilder() - .setExecutorId(ExecutorID.newBuilder().setValue(UUID.randomUUID().toString())) - .setName("hello-world-executor-" + UUID.randomUUID().toString()) - .setCommand(CommandInfo.newBuilder().setShell(false)) - .setContainer(ContainerInfo.newBuilder().setType(ContainerInfo.Type.DOCKER).setDocker(dockerBuilder)); - } - -} diff --git a/test-framework-docker/scheduler/start-scheduler.sh b/test-framework-docker/scheduler/start-scheduler.sh deleted file mode 100755 index 9520c3bc..00000000 --- a/test-framework-docker/scheduler/start-scheduler.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -java $JAVA_OPTS -Djava.library.path=/usr/lib -jar /tmp/mesos-hello-world-scheduler.jar $@ \ No newline at end of file diff --git a/test-framework-docker/system-test/build.gradle b/test-framework-docker/system-test/build.gradle deleted file mode 100644 index 30157e98..00000000 --- a/test-framework-docker/system-test/build.gradle +++ /dev/null @@ -1,20 +0,0 @@ -dependencies { - - compile project(':test-framework-docker:scheduler') - compile project(':test-framework-docker:executor') - compile project(':minimesos') - - compile 'com.github.docker-java:docker-java:3.0.6' - compile 'com.jayway.awaitility:awaitility:1.6.3' - - compile 'org.slf4j:jul-to-slf4j:1.7.12' - compile 'org.slf4j:slf4j-api:1.7.12' - -} - -task systemTest(type: Test) { - testClassesDir = sourceSets.test.output.classesDir - classpath = sourceSets.test.runtimeClasspath - outputs.upToDateWhen { false } -} - diff --git a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/DiscoverySystemTest.java b/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/DiscoverySystemTest.java deleted file mode 100644 index 37024972..00000000 --- a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/DiscoverySystemTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.containersolutions.mesoshelloworld.systemtest; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import com.containersol.minimesos.cluster.MesosCluster; -import com.containersol.minimesos.docker.DockerContainersUtil; -import com.containersol.minimesos.junit.MesosClusterTestRule; -import com.containersolutions.mesoshelloworld.scheduler.Configuration; -import com.github.dockerjava.api.model.Container; -import com.jayway.awaitility.Awaitility; -import com.jayway.awaitility.core.ConditionTimeoutException; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.Assert.assertTrue; - -/** - * Tests REST node discovery - */ -public class DiscoverySystemTest { - - public static final Logger LOGGER = LoggerFactory.getLogger(DiscoverySystemTest.class); - - @ClassRule - public static final MesosClusterTestRule RULE = MesosClusterTestRule.fromFile("src/test/resources/configFiles/minimesosFile-discoverySystemTest"); - - public static MesosCluster CLUSTER = RULE.getMesosCluster(); - - public static final long TIMEOUT = 120; - - private static String schedulerContainerId = null; - - @BeforeClass - public static void startScheduler() throws Exception { - String ipAddress = CLUSTER.getMaster().getIpAddress(); - - LOGGER.info("Starting Scheduler, connected to " + ipAddress); - SchedulerContainer scheduler = new SchedulerContainer(ipAddress); - - // Cluster now has responsibility to shut down container - schedulerContainerId = CLUSTER.addAndStartProcess(scheduler); - - LOGGER.info("Started Scheduler on " + scheduler.getIpAddress()); - } - - @Test - public void testNodeDiscoveryRest() { - - final Set ipAddresses = new HashSet<>(); - try { - - Awaitility.await("9 expected executors did not come up").atMost(TIMEOUT, TimeUnit.SECONDS).pollDelay(5, TimeUnit.SECONDS).until(() -> { - ipAddresses.clear(); - ipAddresses.addAll(DockerContainersUtil.getContainers(false).filterByImage(Configuration.DEFAULT_EXECUTOR_IMAGE).getIpAddresses()); - return ipAddresses.size() == 9; - }); - - } catch (ConditionTimeoutException cte) { - for (Container container : DockerContainersUtil.getContainers(true).getContainers()) { - LOGGER.error("Containers:"); - LOGGER.error(String.format(" Container ID:%s, IMAGE:%s, STATUS:%s, NAMES:%s", container.getId(), container.getImage(), container.getStatus(), Arrays.toString(container.getNames()))); - LOGGER.error("Scheduler logs:"); - for (String logLine : DockerContainersUtil.getDockerLogs(schedulerContainerId)) { - LOGGER.error(logLine); - } - } - throw cte; - } - - HelloWorldResponse helloWorldResponse = new HelloWorldResponse(ipAddresses, Arrays.asList(8080, 8081, 8082), TIMEOUT); - assertTrue("Executors did not come up within " + TIMEOUT + " seconds", helloWorldResponse.isDiscoverySuccessful()); - } - - @AfterClass - public static void removeExecutors() { - DockerContainersUtil running = DockerContainersUtil.getContainers(false); - - // stop scheduler, otherwise it keeps on scheduling new executors as soon as they are stopped - running.filterByImage(SchedulerContainer.SCHEDULER_IMAGE).kill().remove(); - - DockerContainersUtil executors = running.filterByImage(Configuration.DEFAULT_EXECUTOR_IMAGE); - LOGGER.info(String.format("Found %d containers to stop and remove", executors.size())); - executors.kill(true).remove(); - } - -} diff --git a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/HelloWorldResponse.java b/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/HelloWorldResponse.java deleted file mode 100644 index 11c07a7e..00000000 --- a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/HelloWorldResponse.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.containersolutions.mesoshelloworld.systemtest; - -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; - -import java.util.*; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; - -import static com.jayway.awaitility.Awaitility.await; - -/** - * Response which waits until endpoint is ready - */ -public class HelloWorldResponse { - - private boolean discoverySuccessful; - - public HelloWorldResponse(Set ipAddresses, List ports, long timeout) { - await("Hello world container did not start responding").atMost(timeout, TimeUnit.SECONDS).until(new TasksCall(ipAddresses, ports)); - } - - public boolean isDiscoverySuccessful() { - return discoverySuccessful; - } - - class TasksCall implements Callable { - - private final Set ipAddresses; - private final List ports; - - public TasksCall(Set ipAddresses, List ports) { - this.ipAddresses = ipAddresses; - this.ports = ports; - } - - @Override - public Boolean call() throws Exception { - - final Set goodHosts = new HashSet<>(ipAddresses.size()); - - ipAddresses.forEach(ip -> { - - if (!goodHosts.contains(ip)) { - ports.forEach(p -> { - - if (!goodHosts.contains(ip)) { - String url = "http://" + ip + ":" + p; - try { - System.out.println(goodHosts.size() + ". " + url + " => " + Unirest.get(url).asString().getBody()); - goodHosts.add(ip); - } catch (UnirestException e) { - // do nothing - } - } - }); - - } - - }); - - discoverySuccessful = (goodHosts.size() == ipAddresses.size()); - return discoverySuccessful; - - } - - } -} diff --git a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/InstallCommandTest.java b/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/InstallCommandTest.java deleted file mode 100644 index b6e1f482..00000000 --- a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/InstallCommandTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.containersolutions.mesoshelloworld.systemtest; - -import com.containersol.minimesos.cluster.MesosCluster; -import com.containersol.minimesos.docker.DockerContainersUtil; -import com.containersol.minimesos.junit.MesosClusterTestRule; -import com.containersolutions.mesoshelloworld.executor.FrameworkExecutor; -import com.containersolutions.mesoshelloworld.scheduler.Configuration; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; -import org.apache.commons.io.IOUtils; -import org.junit.AfterClass; -import org.junit.ClassRule; -import org.junit.Test; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import static com.jayway.awaitility.Awaitility.await; -import static org.junit.Assert.fail; - -public class InstallCommandTest { - - @ClassRule - public static final MesosClusterTestRule RULE = MesosClusterTestRule.fromFile("src/test/resources/configFiles/minimesosFile-install-command-test"); - - public static MesosCluster CLUSTER = RULE.getMesosCluster(); - - @Test - public void testMesosInstall() throws IOException { - deployApp(); - - List ipAddresses = new ArrayList<>(); - await("executors are expected to come up").atMost(60, TimeUnit.SECONDS).until(() -> { - Set runningNow = DockerContainersUtil.getContainers(false).filterByImage(Configuration.DEFAULT_EXECUTOR_IMAGE).getIpAddresses(); - if (runningNow.size() > 0) { - ipAddresses.addAll(runningNow); - } - return ipAddresses.size() > 0; - }); - - String appUrl1 = "http://" + ipAddresses.get(0) + ":8081"; - String appUrl2 = "http://" + ipAddresses.get(0) + ":8082"; - await("The app did not start providing expected output").atMost(60, TimeUnit.SECONDS).until( () -> { - String response1; - try { - response1 = Unirest.get(appUrl1).asString().getBody(); - } catch (UnirestException e) { - response1 = ""; - } - String response2; - try { - response2 = Unirest.get(appUrl2).asString().getBody(); - } catch (UnirestException e) { - response2 = ""; - } - - return response1.equals(FrameworkExecutor.RESPONSE_STRING) || response2.equals(FrameworkExecutor.RESPONSE_STRING); - }); - } - - private void deployApp() throws IOException { - File taskFile = new File("src/test/resources/test-framework-docker.json"); - if (!taskFile.exists()) { - fail("Failed to find task info file " + taskFile.getAbsolutePath()); - } - - try (FileInputStream fis = new FileInputStream(taskFile)) { - String appJson = IOUtils.toString(fis); - CLUSTER.getMarathon().deployApp(appJson); - } - } - - @AfterClass - public static void removeExecutors() { - DockerContainersUtil containers = DockerContainersUtil.getContainers(true); - - // stop container, otherwise it keeps on scheduling new executors as soon as they are stopped - containers.filterByImage(SchedulerContainer.SCHEDULER_IMAGE).kill(true).remove(); - // remove executors - containers.filterByImage(Configuration.DEFAULT_EXECUTOR_IMAGE).kill(true).remove(); - } - -} diff --git a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/SchedulerContainer.java b/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/SchedulerContainer.java deleted file mode 100644 index 853ad965..00000000 --- a/test-framework-docker/system-test/src/test/java/com/containersolutions/mesoshelloworld/systemtest/SchedulerContainer.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.containersolutions.mesoshelloworld.systemtest; - -import com.containersol.minimesos.config.ContainerConfigBlock; -import com.containersol.minimesos.container.AbstractContainer; -import com.containersol.minimesos.docker.DockerClientFactory; -import com.containersolutions.mesoshelloworld.scheduler.Configuration; -import com.github.dockerjava.api.command.CreateContainerCmd; - -import java.util.stream.IntStream; - -/** - * Container for the Scheduler - */ -public class SchedulerContainer extends AbstractContainer { - - public static final String SCHEDULER_IMAGE = "containersol/mesos-hello-world-scheduler"; - public static final String SCHEDULER_NAME = "hello-world-scheduler"; - - private static int containerCount = 0; - - private final String mesosIp; - private final int containerIndex; - - protected SchedulerContainer(String mesosIp) { - super( new ContainerConfigBlock(SCHEDULER_IMAGE, "latest")); - - this.mesosIp = mesosIp; - containerCount++; - containerIndex = containerCount; - - } - - @Override - public String getRole() { - return "helloworld-scheduler"; - } - - @Override - protected CreateContainerCmd dockerCommand() { - return DockerClientFactory.build() - .createContainerCmd(SCHEDULER_IMAGE) - .withName( getName() ) - .withEnv("JAVA_OPTS=-Xms128m -Xmx256m") - .withExtraHosts(IntStream.rangeClosed(1, 3).mapToObj(value -> "slave" + value + ":" + mesosIp).toArray(String[]::new)) - .withCmd(Configuration.MESOS_MASTER, getMesosUrl()); - } - - public String getMesosUrl() { - return mesosIp + ":5050"; - } - - @Override - public String getName() { - return SCHEDULER_NAME + "_" + containerIndex; - } - -} diff --git a/test-framework-docker/system-test/src/test/resources/configFiles/minimesosFile-discoverySystemTest b/test-framework-docker/system-test/src/test/resources/configFiles/minimesosFile-discoverySystemTest deleted file mode 100644 index 51478225..00000000 --- a/test-framework-docker/system-test/src/test/resources/configFiles/minimesosFile-discoverySystemTest +++ /dev/null @@ -1,101 +0,0 @@ -minimesos { - clusterName = "minimesos-test" - mapPortsToHost = false - loggingLevel = "INFO" - mapAgentSandboxVolume = false - mesosVersion = "1.0.0" - timeout = 60 - - agent { - imageName = "containersol/mesos-agent" - portNumber = 5051 - - resources { - - cpu { - role = "*" - value = 8 - } - - disk { - role = "*" - value = 10000 - } - - mem { - role = "*" - value = 1024 - } - - ports { - role = "*" - value = "[8080-8082]" - } - } - } - - agent { - imageName = "containersol/mesos-agent" - portNumber = 5051 - - resources { - - cpu { - role = "*" - value = 8 - } - - disk { - role = "*" - value = 10000 - } - - mem { - role = "*" - value = 1024 - } - - ports { - role = "*" - value = "[8080-8082]" - } - } - } - - agent { - imageName = "containersol/mesos-agent" - portNumber = 5051 - - resources { - - cpu { - role = "*" - value = 8 - } - - disk { - role = "*" - value = 10000 - } - - mem { - role = "*" - value = 1024 - } - - ports { - role = "*" - value = "[8080-8082]" - } - } - } - - master { - imageName = "containersol/mesos-master" - } - - zookeeper { - imageName = "jplock/zookeeper" - imageTag = "3.4.6" - } -} diff --git a/test-framework-docker/system-test/src/test/resources/configFiles/minimesosFile-install-command-test b/test-framework-docker/system-test/src/test/resources/configFiles/minimesosFile-install-command-test deleted file mode 100644 index fb912c2f..00000000 --- a/test-framework-docker/system-test/src/test/resources/configFiles/minimesosFile-install-command-test +++ /dev/null @@ -1,50 +0,0 @@ -minimesos { - clusterName = "install-command-test" - mapPortsToHost = false - loggingLevel = "INFO" - mapAgentSandboxVolume = false - mesosVersion = "1.0.0" - timeout = 60 - - agent { - imageName = "containersol/mesos-agent" - portNumber = 5051 - - resources { - - cpu { - role = "*" - value = 8 - } - - disk { - role = "*" - value = 10000 - } - - mem { - role = "*" - value = 1024 - } - - ports { - role = "*" - value = "[8081-8082]" - } - } - } - - marathon { - imageName = "mesosphere/marathon" - imageTag = "v0.15.3" - } - - master { - imageName = "containersol/mesos-master" - } - - zookeeper { - imageName = "jplock/zookeeper" - imageTag = "3.4.6" - } -} diff --git a/test-framework-docker/system-test/src/test/resources/logback-test.xml b/test-framework-docker/system-test/src/test/resources/logback-test.xml deleted file mode 100644 index 9ca08a9b..00000000 --- a/test-framework-docker/system-test/src/test/resources/logback-test.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - System.out - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36}: %msg%n - - - - - - - - - - diff --git a/test-framework-docker/system-test/src/test/resources/test-framework-docker.json b/test-framework-docker/system-test/src/test/resources/test-framework-docker.json deleted file mode 100644 index af088275..00000000 --- a/test-framework-docker/system-test/src/test/resources/test-framework-docker.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "id": "hello-world-scheduler", - "cmd": "docker run containersol/mesos-hello-world-scheduler --mesosMaster ${MINIMESOS_MASTER_IP}:${MINIMESOS_MASTER_PORT}", - "cpus": 0.2, - "mem": 512.0, - "env": { - "JAVA_OPTS": "-Xms128m -Xmx256m" - }, - "instances": 1 -}