Repository: ContainerSolutions/mini-mesos Branch: master Commit: 016f15443f4f Files: 155 Total size: 335.0 KB Directory structure: gitextract_yszckrba/ ├── .editorconfig ├── .gitignore ├── .pullapprove.yml ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── bin/ │ ├── install │ ├── install-version │ └── minimesos ├── build.gradle ├── cli/ │ ├── Dockerfile │ ├── build.gradle │ └── src/ │ ├── integration-test/ │ │ ├── java/ │ │ │ └── com/ │ │ │ └── containersol/ │ │ │ └── minimesos/ │ │ │ └── main/ │ │ │ ├── CommandInitTest.java │ │ │ ├── CommandLogsTest.java │ │ │ ├── CommandPsTest.java │ │ │ ├── CommandTest.java │ │ │ ├── CommandUninstallTest.java │ │ │ └── CommandUpTest.java │ │ └── resources/ │ │ ├── app.json │ │ ├── clusterconfig/ │ │ │ ├── basic.groovy │ │ │ └── two-agents.groovy │ │ ├── configFiles/ │ │ │ ├── complete-minimesosFile │ │ │ ├── invalid-minimesosFile.txt │ │ │ ├── marathonAppConfig-minimesosFile │ │ │ └── withMarathon-minimesosFile │ │ └── logback-test.xml │ ├── main/ │ │ └── java/ │ │ └── com/ │ │ └── containersol/ │ │ └── minimesos/ │ │ └── main/ │ │ ├── Command.java │ │ ├── CommandDestroy.java │ │ ├── CommandHelp.java │ │ ├── CommandInfo.java │ │ ├── CommandInit.java │ │ ├── CommandInstall.java │ │ ├── CommandLogs.java │ │ ├── CommandPs.java │ │ ├── CommandState.java │ │ ├── CommandUninstall.java │ │ ├── CommandUp.java │ │ ├── CommandVersion.java │ │ └── Main.java │ └── test/ │ ├── java/ │ │ └── com/ │ │ └── containersol/ │ │ └── minimesos/ │ │ └── main/ │ │ ├── CommandInstallTest.java │ │ └── MainTest.java │ └── resources/ │ ├── app.json │ └── group.json ├── docs/ │ └── index.md ├── gradle/ │ ├── quality.gradle │ ├── spock.gradle │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── minimesos/ │ ├── build.gradle │ └── src/ │ ├── integration-test/ │ │ └── java/ │ │ └── com.containersol.minimesos/ │ │ └── integrationtest/ │ │ ├── AuthenticationTest.java │ │ ├── MesosClusterTest.java │ │ └── container/ │ │ ├── HelloWorldContainer.java │ │ └── MesosExecuteContainer.java │ ├── main/ │ │ ├── groovy/ │ │ │ └── com/ │ │ │ └── containersol/ │ │ │ └── minimesos/ │ │ │ └── config/ │ │ │ ├── AgentResourcesConfig.groovy │ │ │ ├── AppConfig.groovy │ │ │ ├── ClusterConfig.groovy │ │ │ ├── ConfigParser.groovy │ │ │ ├── ConsulConfig.groovy │ │ │ ├── ContainerConfig.groovy │ │ │ ├── ContainerConfigBlock.groovy │ │ │ ├── GroovyBlock.groovy │ │ │ ├── GroupConfig.groovy │ │ │ ├── MarathonConfig.groovy │ │ │ ├── MesosAgentConfig.groovy │ │ │ ├── MesosContainerConfig.groovy │ │ │ ├── MesosDNSConfig.groovy │ │ │ ├── MesosMasterConfig.groovy │ │ │ ├── RegistratorConfig.groovy │ │ │ ├── ResourceDef.groovy │ │ │ ├── ResourceDefRanges.groovy │ │ │ ├── ResourceDefScalar.groovy │ │ │ └── ZooKeeperConfig.groovy │ │ ├── java/ │ │ │ └── com/ │ │ │ └── containersol/ │ │ │ └── minimesos/ │ │ │ ├── MinimesosException.java │ │ │ ├── cluster/ │ │ │ │ ├── ClusterProcess.java │ │ │ │ ├── ClusterRepository.java │ │ │ │ ├── ClusterUtil.java │ │ │ │ ├── Consul.java │ │ │ │ ├── Filter.java │ │ │ │ ├── Marathon.java │ │ │ │ ├── MesosAgent.java │ │ │ │ ├── MesosCluster.java │ │ │ │ ├── MesosClusterFactory.java │ │ │ │ ├── MesosContainer.java │ │ │ │ ├── MesosDns.java │ │ │ │ ├── MesosMaster.java │ │ │ │ ├── Registrator.java │ │ │ │ └── ZooKeeper.java │ │ │ ├── docker/ │ │ │ │ ├── DockerClientFactory.java │ │ │ │ └── DockerContainersUtil.java │ │ │ ├── integrationtest/ │ │ │ │ └── container/ │ │ │ │ ├── AbstractContainer.java │ │ │ │ └── ContainerName.java │ │ │ ├── junit/ │ │ │ │ └── MesosClusterTestRule.java │ │ │ ├── marathon/ │ │ │ │ └── MarathonContainer.java │ │ │ ├── mesos/ │ │ │ │ ├── ClusterContainers.java │ │ │ │ ├── ConsulContainer.java │ │ │ │ ├── MesosAgentContainer.java │ │ │ │ ├── MesosClusterContainersFactory.java │ │ │ │ ├── MesosContainerImpl.java │ │ │ │ ├── MesosDnsContainer.java │ │ │ │ ├── MesosMasterContainer.java │ │ │ │ ├── RegistratorContainer.java │ │ │ │ └── ZooKeeperContainer.java │ │ │ ├── state/ │ │ │ │ ├── Discovery.java │ │ │ │ ├── Executor.java │ │ │ │ ├── Framework.java │ │ │ │ ├── Port.java │ │ │ │ ├── Ports.java │ │ │ │ ├── State.java │ │ │ │ └── Task.java │ │ │ └── util/ │ │ │ ├── CollectionsUtils.java │ │ │ ├── Downloader.java │ │ │ ├── Environment.java │ │ │ ├── EnvironmentBuilder.java │ │ │ ├── Predicate.java │ │ │ └── ResourceUtil.java │ │ └── resources/ │ │ ├── logback.xml │ │ └── marathon/ │ │ ├── elasticsearch.json │ │ └── mesos-consul.json │ └── test/ │ ├── groovy/ │ │ └── com/ │ │ └── containersol/ │ │ └── minimesos/ │ │ └── config/ │ │ ├── AgentResourcesConfigTest.groovy │ │ ├── ConfigParserTest.groovy │ │ ├── ConfigWriterTest.groovy │ │ └── ResourceDefScalarTest.groovy │ ├── java/ │ │ └── com/ │ │ └── containersol/ │ │ └── minimesos/ │ │ ├── ClusterBuilderTest.java │ │ ├── ParseStateJSONTest.java │ │ ├── factory/ │ │ │ └── MesosClusterContainersFactoryTest.java │ │ ├── integrationtest/ │ │ │ └── container/ │ │ │ ├── ContainerNameTest.java │ │ │ └── MesosAgentTest.java │ │ ├── jdepend/ │ │ │ └── JDependCyclesTest.java │ │ ├── mesos/ │ │ │ ├── ClusterContainersTest.java │ │ │ └── ClusterUtilTest.java │ │ └── util/ │ │ ├── CollectionsUtilsTest.java │ │ ├── EnvironmentBuilderTest.java │ │ └── ResourceUtilTest.java │ └── resources/ │ ├── configFiles/ │ │ ├── minimesosFile-authenticationTest │ │ └── minimesosFile-mesosClusterTest │ └── logback-test.xml ├── opt/ │ ├── apps/ │ │ └── weave-scope.json │ ├── sonar/ │ │ ├── DockerFile │ │ ├── certificate.yaml │ │ ├── setup.md │ │ ├── sonar-deployment.yaml │ │ ├── sonar-plugins/ │ │ │ ├── sonar-github-plugin-1.1.jar │ │ │ ├── sonar-java-plugin-3.7.1.jar │ │ │ ├── sonar-scm-git-plugin-1.0.jar │ │ │ └── sonar-scm-svn-plugin-1.2.jar │ │ ├── sonar-postgres-deployment.yaml │ │ ├── sonar-postgres-service.yaml │ │ └── sonar-service.yaml │ └── vagrant/ │ └── debian/ │ └── jessie64/ │ ├── Vagrantfile │ └── provision.sh ├── settings.gradle └── travis.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ root = true [*] end_of_line = lf insert_final_newline = true charset = utf-8 trim_trailing_whitespace = true [*.java] indent_style = space indent_size = 4 ================================================ FILE: .gitignore ================================================ minimesosFile .minimesos/* *.class .gradle/ build/ # Vagrant working files .vagrant # Build system .gradle/ build/ # IDEA files *.i?? out/ .idea/ # Maven /target # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.war *.ear # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* # private docker registry images .registry ================================================ FILE: .pullapprove.yml ================================================ approve_by_comment: true approve_regex: ^(Approved|LGTM|:\+1:) author_approval: ignored reject_regex: ^Rejected reset_on_push: false reviewers: members: - frankscholten - mwl - sadovnikov - philwinder - lguminski - adam-sandor name: default required: 1 ================================================ FILE: .travis.yml ================================================ language: java jdk: - oraclejdk8 sudo: required install: # one liner installation of docker 1.9.1 below did not work (see https://github.com/moul/travis-docker/issues/38). # - curl -sLo - http://j.mp/install-travis-docker | sh -xe # Therefore installing it through a script - sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-precise main" > /etc/apt/sources.list.d/docker.list' - sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D - sudo apt-get update - sudo apt-key update - sudo apt-get -qqy install docker-engine=1.9.1-0~precise # Has to run this script with sudo because custom installation does not allow $USER to use docker and it's not possible to relogin - sudo make deps # Has to run the build script with sudo because custom installation does not allow $USER to use docker and it's not possible to relogin script: chmod +x travis.sh && sudo ./travis.sh notifications: email: true # see details on https://docs.travis-ci.com/user/notifications slack: secure: RWUEmM8nef6hH9+AmVaBWVxcjUt5hVPdbw02x+iBdTqAxPC2wxq3Ya/vlWDwhyyXdUgMujfWTJxks3A15qHAzPH22/mVsmAoz8Duspj/C3x8dp/7IncnkbX5AI1fEJy+z+D8uL4J6ALM90y8kUm2QKoddOq1+xO65xZyzvXoxFJDZ9eIlSVsDv7q7qqkaHnWH8nW+DqtGFPlhu5K/luaw56gy7lChUX/KvAy+8fzaUFNPKdJTVu+GpdgJZrqKeQS8+gY00k0AaAS6fOHxTeAUmyC6eDTL1FgBueS5auBha321qU84sQTCQSTHxl0J8YSQzzrBEiGn506DMKFjZLQZWmR4DxxGSc8jd4sdbVXBoWEBQvNI8jZoAzagFnNig1NKPtRAXIuip28FJUhsvK3WOs1H/XsnkRxKZ52jRrDg0yYi48HsqIr7af6nSzAkAK5JEL58Yc1nYvALa0vXjVWuyuo8um0sFNvEDRE/eDi5o6iul0I4CPOM0j+6d8ymVuD6oJ8eeGjYSFVk7XgdCBp1Gcl8NHLgiVjnygcT0U07kszDV7q8ab0iAfjMoTJwFTjPGkwFWJnlD5dciliO7ncWORl//A3JOQqRh5kMp/96995Ia9G4pVnEkh6tQI6G84/qMU0blDrOtTWIO6NjDV4UiGAYtaixr8BGKQWji9K+eY= ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: Makefile ================================================ default: build .PHONY: setup deps test build setup: sudo route delete 172.17.0.0/16; sudo route -n add 172.17.0.0/16 $(shell docker-machine ip ${shell DOCKER_MACHINE_NAME}) deps: docker pull containersol/mesos-agent:1.0.0-0.1.0 docker pull containersol/mesos-master:1.0.0-0.1.0 docker pull gliderlabs/registrator:v6 docker pull consul:0.7.1 docker pull xebia/mesos-dns:0.0.5 docker pull mesosphere/marathon:v1.3.5 docker pull jplock/zookeeper:3.4.6 docker pull containersol/alpine3.3-java8-jre:v1 docker pull tutum/hello-world:latest clean: ./gradlew clean -docker rmi containersol/minimesos-cli:latest build: ./gradlew build --info --stacktrace build-no-tests: ./gradlew build --info --stacktrace -x test test: ./gradlew test --info --stacktrace ================================================ FILE: README.md ================================================ # minimesos [](https://travis-ci.org/ContainerSolutions/minimesos) The experimentation and testing tool for Apache Mesos NOTE: NO LONGER MAINTAINED!
true if you expect containers might be stopped by this time
*/
public DockerContainersUtil kill(boolean ignoreFailure) {
if (containers != null) {
for (Container container : containers) {
try {
DockerClientFactory.build().killContainerCmd(container.getId()).exec();
} catch (DockerException failure) {
if (!ignoreFailure) {
throw failure;
}
}
}
}
return this;
}
/**
* @return IP addresses of containers
*/
public Setcontainer.getNames()
* @param clusterId cluster to check
* @param role role to check
* @return true if container has the role
*/
public static boolean hasRoleInCluster(String[] dockerNames, String clusterId, String role) {
String name = getFromDockerNames(dockerNames);
return hasRoleInCluster(name, clusterId, role);
}
/**
* @return true, if container with this name belongs to the cluster
*/
public static boolean belongsToCluster(String containerName, String clusterId) {
String pattern = getContainerNamePattern(clusterId);
return containerName.matches(pattern);
}
/**
* @return true, if container with these docker names belongs to the cluster
*/
public static boolean belongsToCluster(String[] dockerNames, String clusterId) {
String name = getFromDockerNames(dockerNames);
return belongsToCluster(name, clusterId);
}
/**
* Docker supports multiple names for a single container, when the container is linked from others.
* This method selects the original name of the container and removes leading "/"
*
* @param dockerNames names, as they returned by container.getNames()
* @return name of the container, which is not inherited from link
*/
public static String getFromDockerNames(String[] dockerNames) {
String name = null;
for (String dockerName : dockerNames) {
String slashLess = dockerName;
if (dockerName.startsWith("/")) {
slashLess = dockerName.substring(1);
}
if (!slashLess.contains("/")) {
name = slashLess;
break;
}
}
return name;
}
}
================================================
FILE: minimesos/src/main/java/com/containersol/minimesos/junit/MesosClusterTestRule.java
================================================
package com.containersol.minimesos.junit;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import com.containersol.minimesos.MinimesosException;
import com.containersol.minimesos.cluster.MesosCluster;
import com.containersol.minimesos.cluster.MesosClusterFactory;
import com.containersol.minimesos.mesos.MesosClusterContainersFactory;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* JUnit Rule extension of Mesos Cluster to use in JUnit.
*/
public class MesosClusterTestRule implements TestRule {
private MesosClusterFactory factory = new MesosClusterContainersFactory();
private MesosCluster mesosCluster;
public static MesosClusterTestRule fromClassPath(String path) {
try (InputStream is = MesosClusterTestRule.class.getResourceAsStream(path)) {
MesosCluster cluster = new MesosClusterContainersFactory().createMesosCluster(is);
return new MesosClusterTestRule(cluster);
} catch (IOException e) {
throw new MinimesosException("Could not read minimesosFile on classpath " + path, e);
}
}
public static MesosClusterTestRule fromFile(String minimesosFilePath) {
try {
MesosCluster cluster = new MesosClusterContainersFactory().createMesosCluster(new FileInputStream(minimesosFilePath));
return new MesosClusterTestRule(cluster);
} catch (FileNotFoundException e) {
throw new MinimesosException("Could not read minimesosFile at " + minimesosFilePath, e);
}
}
private MesosClusterTestRule(MesosCluster mesosCluster) {
this.mesosCluster = mesosCluster;
}
/**
* Modifies the method-running {@link Statement} to implement this test-running rule.
*
* @param base The {@link Statement} to be modified
* @param description A {@link Description} of the test implemented in {@code base}
* @return a new statement, which may be the same as {@code base}, a wrapper around {@code base}, or a completely new Statement.
*/
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
before();
try {
base.evaluate();
} finally {
after();
}
}
};
}
/**
* Execute before the test
*/
protected void before() {
mesosCluster.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
factory.destroyRunningCluster(mesosCluster.getClusterId());
}
});
}
/**
* Execute after the test
*/
protected void after() {
stop();
}
/**
* Destroys cluster using docker based factory of cluster members
*/
public void stop() {
mesosCluster.destroy(factory);
}
public MesosCluster getMesosCluster() {
return mesosCluster;
}
public MesosClusterFactory getFactory() {
return factory;
}
}
================================================
FILE: minimesos/src/main/java/com/containersol/minimesos/marathon/MarathonContainer.java
================================================
package com.containersol.minimesos.marathon;
import com.containersol.minimesos.MinimesosException;
import com.containersol.minimesos.cluster.ClusterProcess;
import com.containersol.minimesos.cluster.ClusterUtil;
import com.containersol.minimesos.cluster.Marathon;
import com.containersol.minimesos.cluster.MesosCluster;
import com.containersol.minimesos.cluster.ZooKeeper;
import com.containersol.minimesos.config.AppConfig;
import com.containersol.minimesos.config.GroupConfig;
import com.containersol.minimesos.config.MarathonConfig;
import com.containersol.minimesos.integrationtest.container.AbstractContainer;
import com.containersol.minimesos.docker.DockerClientFactory;
import com.containersol.minimesos.docker.DockerContainersUtil;
import com.containersol.minimesos.util.Environment;
import com.containersol.minimesos.util.CollectionsUtils;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.Ports;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import mesosphere.marathon.client.model.v2.Group;
import mesosphere.marathon.client.model.v2.Result;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import mesosphere.marathon.client.model.v2.App;
import mesosphere.marathon.client.MarathonClient;
import mesosphere.marathon.client.utils.MarathonException;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import static com.containersol.minimesos.config.MarathonConfig.*;
import static com.jayway.awaitility.Awaitility.await;
import static java.lang.String.format;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
/**
* Marathon is a cluster-wide init and control system for services. See https://mesosphere.github.io/marathon/docs/
*/
public class MarathonContainer extends AbstractContainer implements Marathon {
private static final Logger LOGGER = LoggerFactory.getLogger(MarathonContainer.class);
private static final String TOKEN_HOST_DIR = "MINIMESOS_HOST_DIR";
private static final String APPS_ENDPOINT = "/v2/apps";
private static final String HEADER_ACCEPT = "accept";
private final MarathonConfig config;
private ZooKeeper zooKeeper;
public MarathonContainer(MarathonConfig config) {
super(config);
this.config = config;
}
public MarathonContainer(MesosCluster cluster, String uuid, String containerId) {
this(cluster, uuid, containerId, new MarathonConfig());
}
private MarathonContainer(MesosCluster cluster, String uuid, String containerId, MarathonConfig config) {
super(cluster, uuid, containerId, config);
this.config = config;
}
@Override
public String getRole() {
return "marathon";
}
@Override
public void setZooKeeper(ZooKeeper zooKeeper) {
this.zooKeeper = zooKeeper;
}
@Override
public URI getServiceUrl() {
URI serviceUri = null;
String protocol = getServiceProtocol();
String host;
if (Environment.isRunningInJvmOnMacOsX()) {
host = "localhost";
} else {
host = getIpAddress();
}
int port = getServicePort();
String path = getServicePath();
if (StringUtils.isNotEmpty(host)) {
try {
serviceUri = new URI(protocol, null, host, port, path, null, null);
} catch (URISyntaxException e) {
throw new MinimesosException("Failed to form service URL for " + getName(), e);
}
}
return serviceUri;
}
@Override
protected CreateContainerCmd dockerCommand() {
ExposedPort exposedPort = ExposedPort.tcp(MARATHON_PORT);
Ports portBindings = new Ports();
if (getCluster().isMapPortsToHost()) {
portBindings.bind(exposedPort, Ports.Binding.bindPort(MARATHON_PORT));
}
return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag())
.withName(getName())
.withExtraHosts("minimesos-zookeeper:" + this.zooKeeper.getIpAddress())
.withCmd(CollectionsUtils.splitCmd(config.getCmd()))
.withExposedPorts(exposedPort)
.withPortBindings(portBindings);
}
/**
* Returns a Marathon endpoint
*
* @return String endpoint
*/
private String getMarathonEndpoint() {
return getServiceUrl().toString();
}
/**
* Deploys a Marathon app by JSON string
*
* @param marathonJson JSON string
*/
@Override
public void deployApp(String marathonJson) {
mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
try {
marathon.createApp(constructApp(marathonJson));
} catch (MarathonException e) {
throw new MinimesosException("Marathon did not accept the app, error: " + e.toString());
}
LOGGER.debug(format("Installed app at '%s'", getMarathonEndpoint()));
}
@Override
public Result deleteApp(String appId) {
mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
try {
Result result = marathon.deleteApp(appId);
LOGGER.debug(format("Deleted app '%s' at '%s'", appId, getMarathonEndpoint()));
return result;
} catch (MarathonException e) {
throw new MinimesosException("Could not delete app '" + appId + "'. " + e.getMessage());
}
}
@Override
public void deployGroup(String groupJson) {
mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
try {
Group group = constructGroup(groupJson);
marathon.createGroup(group);
} catch (Exception e) {
throw new MinimesosException("Marathon did not accept the app, error: " + e.toString(), e);
}
LOGGER.debug(format("Installing group at %s", getMarathonEndpoint()));
}
@Override
public Result deleteGroup(String groupId) {
mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
try {
Result result = marathon.deleteGroup(groupId);
LOGGER.debug(format("Deleted app '%s' at '%s'", groupId, getMarathonEndpoint()));
return result;
} catch (MarathonException e) {
throw new MinimesosException("Could not delete group '" + groupId + "'. " + e.getMessage());
}
}
/**
* Updates a Marathon app by JSON string
*
* @param marathonJson JSON string
*/
@Override
public void updateApp(String marathonJson) {
mesosphere.marathon.client.Marathon marathon = MarathonClient.getInstance(getMarathonEndpoint());
try {
App app = constructApp(marathonJson);
marathon.updateApp(app.getId(), app, true);
} catch (MarathonException e) {
throw new MinimesosException("Marathon could not update the app, error: " + e.toString());
}
LOGGER.debug(format("Installing an app on marathon %s", getMarathonEndpoint()));
}
private Group constructGroup(String groupJson) {
Gson gson = new Gson();
return gson.fromJson(replaceTokens(groupJson), Group.class);
}
private App constructApp(String appJson) {
Gson gson = new Gson();
return gson.fromJson(replaceTokens(appJson), App.class);
}
/**
* Replaces ${MINIMESOS_[ROLE]}, ${MINIMESOS_[ROLE]_IP} and ${MINIMESOS_[ROLE]_PORT} tokens in the given string with actual values.
* Also supports ${NETWORK_GATEWAY}
*
* @param source string to replace values in
* @return updated string
*/
public String replaceTokens(String source) {
MesosCluster cluster = getCluster();
// received JSON might contain tokens, which should be replaced before the installation
List
* Example: 'ports(*):[31000-32000],;cpus(*):0.2; mem(*):256; disk(*):200' returns [31000, 32000]
*
* @param mesosResourceString Mesos resource string
* @return list of ports if any
* @throws MinimesosException if resource string is incorrect
*/
public static ArrayList