It’s time to show you how easy it is to write a Mesos scheduler. Suppose you just got a Docker image, but need to add some more complex features to the scheduler that don’t yet exist. This is where mesos-Starter comes in useful.
Utter solidity is introduced
Tansu is a distributed key-value and lock store designed to maintain configuration and other data that requires high availability. It uses Raft Consensus protocol to ensure data synchronization. Tansu, with a simple REST interface that uses the Open API specification (i.e., Swagger), is also capable of passing changes to clients. By default, it uses mDNS clustering, making it easy to form a cluster. Tansu prioritized availability over consensus, with the default follower responding directly to read the request (based on the possibility that each request could be rewritten). Requests are automatically routed to leaders within the cluster for locking, writing, and deleting.
Creating an application
The easiest way to create a new Spring Boot application is by using Spring Initializr. Give your new application a Maven GroupID and an ArtifactID. Using Mesos-starter, you don’t need any other Spring dependencies, but adding actuators is highly encouraged.
Finally, click the Generate Project button to download the pre-configured Maven Project.
Unzip the downloaded file and import it into the IDE.
At this point, you might want to see if it’s actually built, run $./ MVNW Verify. If all goes well, the MVNW command should be able to download Maven and all the specific versions of the project’s dependencies, and eventually run the application’s integration tests. Note that this is a nearly blank application.
Now that we have a working application, add the mesos-starter dependency. It has been published to Maven Central at the time of writing, so you can add Bintray repositories in POM.xml.
<repository>
<id>bintray-containersolutions</id>
<name>bintray</name>
<url>http://dl.bintray.com/containersolutions/maven</url>
</repository>Copy the code
This gives you access to the spring-boot-starter-mesos module.
<dependency> <groupId>com.containersolutions.mesos</groupId> <artifactId>spring-boot-starter-mesos</artifactId> The < version > 0.2.2 < / version > < / dependency >Copy the code
These are on the CLASspath, and the application is now a full-fledged Mesos cluster. Obviously the scheduler needs some configuration. First, in the SRC/main/resources/application. Add the following line configuration name in the properties:
spring.application.name=TansuCopy the code
The name is important because the scheduler needs to be registered with the framework.
Next comes allocating resources. In this case, 0.1 cpus and 64 MB of ram are sufficient. Again configured from the application.properties file,
Mesos. Resources. Cpus = 0.1 mesos. Resources. The mem = 64Copy the code
And the application needs three instances
mesos.resources.count=3Copy the code
The last resource needed is the port for the HTTP interface.
mesos.resources.ports.tansu-http-port.host=ANYCopy the code
This exposes an environment variable named TANSU_HTTP_PORT to the runtime, the actual port being fetched from the Mesos offer.
Now you need to configure the task itself. Tansu already has a Docker image, which can be added in the following way
Mesos. Docker. Image = shortishly/utter solidity: 0.28.0Copy the code
Because Tansu nodes are discovered by MDNS, they need to be on the same network. There are several ways to do this in Mesos. Either use the Overlay network in Docker, or you can change the network adapter in the Docker container to the host adapter.
mesos.docker.network=HOSTCopy the code
Shelly eventually needs to be shut down
mesos.environment.SHELLY_ENABLED=falseCopy the code
Start the scheduler
The application is configured and ready to run and do some tests. The easiest way to do this now is to use Spring-boot :run with some parameters to set Mesos and Zookeeper endpoints.
$MESOS_MASTER=172.16.33.10:5050 \ MESOS_ZOOKEEPER_SERVER=172.16.33.10:2181 \./ MVNW spring-boot:runCopy the code
In this example, Mesos and ZooKeeper are running on 172.16.33.10. Remember that if you are running on a Mac using the Mesos native library functions installed by Homebrew, you should add the following at the end of the previous command:
-Drun.jvmArguments="-Djava.library.path=/usr/local/lib"Copy the code
packaging
There are several ways to package an application, but it basically depends on whether you want to run it in a container or not. This article creates a JAR that can be easily deployed to Marathon.
Due to space constraints, unitTests are disabled in this article. So add the @ignore annotation to the SchedulerApplicationTest class.
This selected Maven target package actually repackages the entire application, also known as the Fat JAR, in the /target directory. I recommend distributing the JAR package through a Maven repository, like internal Nexus, GitHub Release or Bintray. As long as it can be downloaded via an HTTP (S) URL.
This way, you can deploy the framework in the usual way using Marathon or any other preferred method. Use the following command to start the scheduler:
$ java -jar scheduler-0.0.1-SNAPSHOT.jar --mesos.master=master:5050 --mesos.zookeeper.server=zookeeper:2181Copy the code
Another point
Wouldn’t it be nice to have a good-looking Web interface where users could monitor the scheduler and manipulate the application? This can be done using spring-boot-admin on Codecentric. It’s very simple to use. First add a dependency to your Maven build:
< the groupId > DE. Codecentric < / groupId > < artifactId > spring - the boot - admin - server < / artifactId > < version > 1.3.3 < / version > </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> < version > 1.3.3 < / version > < / dependency > < the dependency > < groupId > DE. Codecentric < / groupId > < artifactId > spring - the boot - admin - starter - client < / artifactId > < version > 1.3.3 < / version > < / dependency >Copy the code
Add the @enableadMinServer annotation to the SchedulerApplication class and add the following line to the application.properties file:
spring.boot.admin.url=http://localhost:8080Copy the code
Start the application again and open localhost:8080 in your browser. In the JMX and com. Containersolutions. Mesos. Can be found in the scheduler InstanceCount handle, can be started or shut down.
conclusion
Among container solutions, we believe mesOS-Starter has a lot of potential. In fact, a full-fledged Mesos framework can be developed in a matter of hours. And designing with Spring in mind means there are plenty of community modules available.
That’s why we want more projects to get involved, so we can collect all these Mesos lessons and share them with each other.
This article is a translated version of the original article.