Mesos Chronos and Marathon Client in Java

Java client for communicating with Meossphere Marathon and Chronos

License

License

MIT
Categories

Categories

Java Languages CLI User Interface
GroupId

GroupId

com.github.chen0040
ArtifactId

ArtifactId

java-mesos-client
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Mesos Chronos and Marathon Client in Java
Java client for communicating with Meossphere Marathon and Chronos
Project URL

Project URL

https://github.com/chen0040/java-mesos-client
Source Code Management

Source Code Management

https://github.com/chen0040/java-mesos-client

Download java-mesos-client

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.chen0040/java-mesos-client/ -->
<dependency>
    <groupId>com.github.chen0040</groupId>
    <artifactId>java-mesos-client</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.chen0040/java-mesos-client/
implementation 'com.github.chen0040:java-mesos-client:1.0.1'
// https://jarcasting.com/artifacts/com.github.chen0040/java-mesos-client/
implementation ("com.github.chen0040:java-mesos-client:1.0.1")
'com.github.chen0040:java-mesos-client:jar:1.0.1'
<dependency org="com.github.chen0040" name="java-mesos-client" rev="1.0.1">
  <artifact name="java-mesos-client" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.chen0040', module='java-mesos-client', version='1.0.1')
)
libraryDependencies += "com.github.chen0040" % "java-mesos-client" % "1.0.1"
[com.github.chen0040/java-mesos-client "1.0.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.20
org.slf4j : slf4j-log4j12 jar 1.7.20
org.apache.httpcomponents : httpclient jar 4.5.1
com.alibaba : fastjson jar 1.2.24

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.6

test (10)

Group / Artifact Type Version
org.testng : testng jar 6.9.10
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3
org.assertj : assertj-core jar 3.5.2
org.powermock : powermock-core jar 1.6.5
org.powermock : powermock-api-mockito jar 1.6.5
org.powermock : powermock-module-junit4 jar 1.6.5
org.powermock : powermock-module-testng jar 1.6.5
org.mockito : mockito-core jar 2.0.2-beta
org.mockito : mockito-all jar 2.0.2-beta

Project Modules

There are no modules declared in this project.

java-mesos-client

Mesos client for chronos and marathon job management

Install

Add the following dependency to your pom file:

<dependency>
    <groupId>com.github.chen0040</groupId>
    <artifactId>java-mesos-client</artifactId>
    <version>1.0.1</version>
</dependency>

Usage

Working with Mesos Master

Read states from mesos master:

import com.github.chen0040.mesos.client.core.MesosUtil;

String mesosMasterUrl1 = "http://10.0.0.15:5050";
String json1 =MesosUtil.getStateJson(mesosMasterUrl1);
System.out.println(json1);

Read tasks from mesos master:

import com.github.chen0040.mesos.client.core.MesosUtil;

String mesosMasterUrl1 = "http://10.0.0.15:5050";
String json1 = MesosUtil.getTasks("http://10.0.0.15:5050");
System.out.println(json1);

Working with Chronos

To list jobs in Chronos

String chronosUrl = "http://10.0.0.1:4400";
List<ChronosJobInfo> result = ChronosUtil.listJobs(chronosUrl);

result.stream().forEach(job -> {
 System.out.println("name: " + job.getName());
 System.out.println("command: " + job.getCommand());
});

To get a particular job in Chronos:

String chronosUrl = "http://10.0.0.1:4400";
List<ChronosJobInfo> result = ChronosUtil.listJobs(chronosUrl);

if (!result.isEmpty()) {
 String appId = result.get(0).getName();

 Optional<ChronosJobInfo> jobInfo = ChronosUtil.getJob(chronosUrl, appId);

 System.out.println(JSON.toJSONString(jobInfo.orElseGet(ChronosJobInfo::new)));

 Assert.assertEquals(appId, jobInfo.get().getName());
}

To start a particular job in Chronos:

String chronosUrl = "http://10.0.0.1:4400";
String regressionTestId = "regtest";
String regressionTestCmd = "echo 'Hello Chronos' ; sleep 5";

 if (!ChronosUtil.jobExists(chronosUrl, regressionTestId)) {
 ChronosJobRequest request = new ChronosJobRequest("PT15M");
 request.setCommand(regressionTestCmd);
 request.setName(regressionTestId);
 request.setCpus(0.1);
 request.setMem(100);

 System.out.println(ChronosUtil.startJob(chronosUrl, request));

 try {
    Thread.sleep(5000l);
 }
 catch (InterruptedException e) {
    e.printStackTrace();
 }

 Assert.assertTrue(ChronosUtil.jobExists(chronosUrl, regressionTestId));
}

To kill a particular job in Chronos:

String chronosUrl = "http://10.0.0.1:4400";
String regressionTestId = "regtest";
if (ChronosUtil.jobExists(chronosUrl, regressionTestId)) {
 System.out.println(ChronosUtil.killJob(chronosUrl, regressionTestId));

 try {
    Thread.sleep(5000l);
 }
 catch (InterruptedException e) {
    e.printStackTrace();
 }

 Assert.assertFalse(ChronosUtil.jobExists(chronosUrl, regressionTestId));
}

Marathon

To list jobs in Marathon:

String marathonUrl = "http://10.0.0.2:8080";
MarathonJobInfoList result = MarathonUtil.listJobs(marathonUrl);

result.getApps().stream().forEach(job -> {
 System.out.println("id: " + job.getId());
 System.out.println("cmd: " + job.getCmd());
});

To get a particular job in Marathon:

String marathonUrl = "http://10.0.0.2:8080";
MarathonJobInfoList result = MarathonUtil.listJobs(marathonUrl);

if (!result.getApps().isEmpty()) {
 String appId = result.getApps().get(0).getId();

 MarathonJobInfoList jobInfo = MarathonUtil.listJobs(marathonUrl, appId);

 System.out.println(JSON.toJSONString(jobInfo));

 Assert.assertEquals(appId, jobInfo.getApps().get(0).getId());
}

To start a particular job in Marathon:

String marathonUrl = "http://10.0.0.2:8080";
String regressionTestCmd = "while [ true ] ; do echo 'Hello Marathon' ; sleep 5 ; done";
String regressionTestId = "regtest";
   
if (!MarathonUtil.jobExists(marathonUrl, regressionTestId)) {
 MarathonJobRequest request = new MarathonJobRequest();
 request.setCmd(regressionTestCmd);
 request.setId(regressionTestId);
 System.out.println(MarathonUtil.startJob(marathonUrl, request));

 try {
    Thread.sleep(5000l);
 }
 catch (InterruptedException e) {
    e.printStackTrace();
 }

 Assert.assertTrue(MarathonUtil.jobExists(marathonUrl, regressionTestId));
}

To kill a particular job in Marathon:

String marathonUrl = "http://10.0.0.2:8080";
String regressionTestId = "regtest";

if (MarathonUtil.jobExists(marathonUrl, regressionTestId)) {
 System.out.println(MarathonUtil.killJob(marathonUrl, regressionTestId));

 try {
    Thread.sleep(5000l);
 }
 catch (InterruptedException e) {
    e.printStackTrace();
 }

 Assert.assertFalse(MarathonUtil.jobExists(marathonUrl, regressionTestId));
}

Versions

Version
1.0.1