Corus in 2 Minutes

Corus has been designed as an alternative to the monolithic programming and deployment model imposed by JEE, which has been thus far the only one available under the JVM for scaling applications.

With Corus, you deploy plain-vanilla Java apps (that is, Java classes with a main() method).

In addition, as of version 5, Corus supports cluster-wide deployment of Docker images and execution of Docker containers, through the same mechanisms that it offers for JVM-based applications.

Write a Descriptor

Corus will start the JVMs "containing" your applications based on a descriptor that you provide. The descriptor defines the classes with a main() method for which JVMs will be started:

<distribution name="myapp" version="1.0" xmlns="http://www.sapia-oss.org/xsd/corus/distribution-5.0.xsd">
  <process  name="myapp-web" 
            maxKillRetry="3" 
            shutdownTimeout="30000" 
            invoke="true">
    <java mainClass="org.me.myapp.WebServer"
          profile="dev" vmType="server">
      <xoption  name="ms" value="128M" />
    </java>
    <java mainClass="org.me.myapp.WebServer"
          profile="prod" vmType="server">
      <xoption  name="ms" value="1024M" />
    </java>
  </process> 
</distribution>

The deployment unit in Corus is the distribution. One distribution can define one to many processes, each corresponding to an actual application bootstrapped by a main() method. Each process can define one or multiple profiles, each consisting of different startup parameters - such as JVM options or properties. The descriptor supports variable substitution.

Package your App

The next thing is to package your application in a .zip file. The Corus descriptor is expected under the META-INF directory. It must be named corus.xml.

META-INF/
    corus.xml
lib/
    <your libraries here> 
    (this location may be changed - 
     configurable in the descriptor)

Deploy

You interact with Corus through a command-line interface (the Corus CLI). Using the CLI, you execute commands against a single Corus instance, or the whole cluster. You use the CLI to deploy your application to the cluster:

deploy myapp-1.0.zip -cluster

The -cluster switch replicates commands across the cluster, to all Corus nodes.

Execute

You start your application across a cluster of Corus instances with the following:

exec -d myapp -v 1.0 -n myapp-web -p dev -cluster

Do it more with sparingly with wildcards:

exec -d * -v * -n * -p dev -cluster

With the -i switch, start multiples instances per Corus node:

exec -d * -v * -n * -p dev -i 2 -cluster

Corus will take it from here, monitoring your JVMs, automatically restarting them if they become unresponsive.

Automate

You have a new version of your app. You want to undeploy the current version, and deploy a new version. Let's do it efficiently through a script. Save the following to a file - say, myapp-2.0.txt:

kill all -w -cluster
undeploy all -cluster
deploy myapp-2.0.zip
exec -d * -v * -n * -p dev -cluster

Now execute the script with the script command from within the CLI:

script etc/scripts/myapp-2.0.txt

You can also launch the script directly with CLI, without entering prompt mode:

coruscli -s etc/scripts/myapp-2.0.txt

You can also use the Maven plugin:

<plugin>
  <groupId>org.sapia</groupId>
  <artifactId>sapia_corus_mvn_plugin</artifactId>
  <version>develop</version>
  <executions>
    <execution>
      <id>deploy-to-dev</id>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <host>172.31.1.2</host>
        <port>33000</port>
        <scriptFile>${project.basedir}/etc/scripts/myapp-2.0.txt</scriptFile>
      </configuration>
    </execution>
  </executions>
</plugin>

And Much More

The above is just an insight, you can do much more:

  • Start on boot: have your JVMs start at Corus boot time (convenient if the machine on which Corus runs is itself rebooted).
  • Use Linux-like commands to manage distributed JVMs collectively, as one: restart all -cluster, kill all -cluster, undeploy all -cluster, etc.
  • Fully configure your JVMs using the usual options: -Xms, etc.
  • Configure process dependencies to ensure that some JVMs are started prior to others.
  • Automate startup: invoking exec for each process that you want to start can become tedious. Rather, you can use execution configurations to automate process startup.
  • Automate assignment of network ports, through the built-in port management feature.
  • Store JVM properties in Corus - they will be passed at runtime to your JVMs through -D options.
  • Trigger JVM restart from your application.
  • Have newly deployed Corus nodes in a cluster automatically download distributions from existing nodes and execute the corresponding processes.
  • Manage Docker images and containers through Corus.
  • etc.