This is the fourth of a series of experiments about how Apache Sling can be made more devops-friendly.
Continuing from the Crankstart-based instance starting mechanism demonstrated in the previous vol3 experiment, we configure the Orchestrator to monitor a crank file in a Git repository and start new Sling instances for each new version of this file (representing a new Sling configuration). This essentially puts the cluster controller in charge of the running instances.
The tentative test scenario is as follows:
- Start the demo with the Git repository URL of the crank file.
- The Orchestrator watches that file in Git for new versions.
- Once a new version
V
is found (or the initial version, when starting), the Orchestrator starts* N Sling instances with that version. - The crankstart file has a few variables: Sling HTTP port number, MongoDB URL, ZooKeeper URL, etc.
- The Sling instances announce themselves to the Orchestrator when ready.
- Orchestrator has a target version
V
that it wants to expose via the HTTP front-end. Once N Sling instances have announced themselves with that target version, the Orchestrator activates them atomically on the front-end. - When old Sling instances are not needed anymore, they are killed*.
(*) For the first demo, starting/stopping instances can just be a console message saying "please do this manually" - we can look at automating this later.
The main difference with the previous prototype is the introduction of a Git repository monitoring mechanism. This is achieved via the use of the JGit library.
The Orchestrator monitors a crank file in the repository, and, when a new version of it is available, downloads it into the <SLING-HOME>/devops
directory. The filename (and the corresponding Sling config) are based on the commit timestamp. The next step is to start Minions from this crank file: in this prototype, this step must still be done manually; the Orchestrator simply prints what needs to be done.
Before running this prototype, it is necessary to prepare your local Maven repository as follows:
mvn clean install
this project.- Build the Sling snapshot bundles.
- Checkout Sling trunk at revision 1601574.
- Apply patch from SLING-3648 to it.
mvn clean install
the following paths: 1.contrib/crankstart
2.bundles/jcr/contentloader
3.bundles/jcr/jackrabbit-server
4.bundles/jcr/oak-server
5.bundles/extensions/fsresource
6.bundles/extensions/groovy
7.contrib/launchpad/karaf
- Navigate to the
sample-bundle
directory and build two versions of the sample bundle: mvn -P1 clean install
mvn -P2 clean install
The easiest way to run the prototype is using Vagrant.
The current configuration creates five virtual machines running Ubuntu 12.04:
- 1 Orchestrator machine,
orchestrator
at 10.10.10.10, which also has the ZooKeeper server, the MongoDB server, the web server (httpd front-end), and the Git repository - 2 Minion machines running the first config,
minion-C1-1
at 10.10.10.11 andminion-C1-2
at 10.10.10.12 - 2 Minion machines running the second config,
minion-C2-1
at 10.10.10.21 andminion-C2-2
at 10.10.10.22
Machines are set up by copying up the Crankstart Launcher JAR and crankstarting the Sling instances. orchestrator
in addition is set up by configuring ZooKeeper, MongoDB, httpd, and Git.
The first Minion crank file is committed to the Git repository during setup of the orchestrator
, the second during setup of each C2 minion
.
The following is necessary to run the prototype with Vagrant:
- Navigate to the
vagrant
directory. - Change
CRANKSTART_LAUNCHER_PATH
variable on line 123 ofVagrantfile
to point to the Crankstart Launcher JAR built above. - If your local Maven repository is not under
~/.m2/repository
, change the variableMAVEN_REPO_PATH
on line 124 accordingly.
Then, bring up the Orchestrator and the two Minion C1 machines:
vagrant up --provision orchestrator minion-C1-1 minion-C1-2
If everything goes well, after Vagrant is done, Sling with the first config should be at http://10.10.10.10/, and the output of the test script at http://10.10.10.10/mynode.test.
Afterwards, bring up the two Minion C2 machines:
vagrant up --provision minion-C2-1 minion-C2-2
Eventually http://10.10.10.10/mynode.test should switch to the second config.
Note: to re-provision machines that are already up, vagrant provision
should be used instead of vagrant up --provision
. Please vagrant halt
the Minions before re-provisioning the Orchestrator.
Finally, machines can be brought down using
vagrant halt
or forever destroyed using
vagrant destroy
Vagrant machines can be ssh
ed to using vagrant ssh <machine>
. Crankstart keeps its log in the ~/crankstart-launcher.out
file (also printed by Vagrant during provisioning), and Sling keeps its log in the ~/<sling-home>/logs/error.log
file where <sling-home>
is sling-{orch|Cx-1|Cx-2}-crankstart
.
- If the
orchestrator
did not initialize properly, re-provision all machines. - If one of the
minion
s did not initialize properly, re-provision it. - If
orchestrator
is running and10.10.10.10
is not pingable, try resetting thevboxnet0
network interface on the host (ifconfig vboxnet0 down
followed byifconfig vboxnet0 up
).
To verify that the switch between the Sling configs is atomic (from the client point of view), the HttpResourceMonitor tool from the tools
directory can be used. This tool sends an HTTP request over and over in a single thread and logs changes in responses.
Usage:
HttpResourceMonitor [host [resource]]
To monitor the output of our test script while running the prototype with Vagrant:
java -cp target/org.apache.sling.devops.tools-0.0.1-SNAPSHOT.jar org.apache.sling.devops.tools.HttpResourceMonitor 10.10.10.10 /mynode.test