the corus guide · 2015. 9. 18. · y.d added corus 4.1.2 documentation: • new conf merge command...

84
        The Corus Guide            version 4.x

Upload: others

Post on 04-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

        The Corus Guide

           version 4.x

Page 2: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

               www.sapia­oss.org

           (c) 2002­2015

REVISION HISTORYAuthor Description Date Version

Y.D Added   tagging,   remote   property   update,   executionconfigurations, process restart from the CLI, 

10/19/09 1.3.5

Y.D Added Corus 3.0 new features documentation:• Avis support (for discovery without IP multicast)• Alerts• Property includes

05/10/12 3.0

Y.D Added Corus 4.0 documentation:• Repository  functionality:  Corus nodes can act as

either   repository   servers   or   repository   client.   Arepo client  will  synchronize   its  state  with  a  reposerver upon startup.

• Shell   script   deployment   and   execution:   shellscripts   may   be   deployed   to   Corus   nodes   andexecuted remotely through the Corus CLI.

• File deployment: arbitrary files can be deployed toCorus, enabling use of Corus as a file repository.

05/26/2013 4.0

Y.D Added Corus 4.1 documentation:• The ripple command• Cloud integration

08/26/2013 4.1

Y.D Added Corus 4.1.2 documentation:• New  conf merge  command   supported   by   the

CLI.• New  preExec  and  cmd  elements   in   the   Corus

descriptor,  allowing exectution of  CLI  commandson the server­side, prior to process execution.

02/02/2014 4.1.2

Y.D Added Corus 4.2 documentation: support for invoking Antscripts from the CLI.

07/13/14 4.2

Y.D Added Corus 4.5 documentation:• Dynamic domain change• Dynamic repository role change• Property categories• Home directory overrides• REST API reference

01/30/15 4.5

2 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 3: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Y.D Added Corus 4.6 documentation:• Disabling and enabling of execution configurations• Packaged scripts• Rollback functionality (new rollback command)• Archiving

03/17/15 4.6

Y.D Added Corus 4.7 documentation:• Distribution archiving/unarchiving • Hot Config

08/09/15 4.7

Y.D Added Corus 4.8 doc. 09/17/15 4.8

3 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 4: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Table of ContentsIntroduction...................................................................................................................................... 6Licensing..........................................................................................................................................7Source Code.....................................................................................................................................8

Structure .....................................................................................................................................8Building from Source ...................................................................................................................9

Architecture.................................................................................................................................... 10Components...............................................................................................................................10Topology..................................................................................................................................... 10The Corus Server........................................................................................................................11The Command-Line Interface.....................................................................................................12Processes................................................................................................................................... 13

Installation...................................................................................................................................... 15Corus Network Address..............................................................................................................15Testing the Server......................................................................................................................16Installing as a Service................................................................................................................16

Linux...................................................................................................................................... 16Mac........................................................................................................................................ 16Windows................................................................................................................................16

Testing the Client.......................................................................................................................17Testing the Monitor.....................................................................................................................17

Packaging Applications...................................................................................................................18Distributions...............................................................................................................................18Deploying with Magnet: Step-by-Step........................................................................................19

Implement a J2SE Application................................................................................................192) Write the Magnet File.........................................................................................................213) Write the Corus Descriptor................................................................................................224) Package the Distribution in a .zip File................................................................................225) Deploy the Distribution......................................................................................................236) Execute..............................................................................................................................23

Deploying using Standard Java..................................................................................................24Server Configuration and File System Layout.................................................................................26

Corus Server Working Directory.................................................................................................26Corus Distribution Directories....................................................................................................26Configuration Properties............................................................................................................27

Remote Property Update........................................................................................................29Property Includes...............................................................................................................30Home Directory Overrides.................................................................................................30Property Categories...........................................................................................................31

Dynamic Domain Change...........................................................................................................32Distributions and Processes in Detail..............................................................................................33

The Corus Descriptor..................................................................................................................33Profiles....................................................................................................................................... 38Process Properties......................................................................................................................38Process Pre-Execution................................................................................................................39

Typical Use ............................................................................................................................39Using conf merge...................................................................................................................40Invoking Ant...........................................................................................................................40

Process Dependencies...............................................................................................................41Execution Configurations...........................................................................................................42

A Closer Look at the CLI .................................................................................................................43Managing in Batch.....................................................................................................................43

Pattern Matching....................................................................................................................43Aggregate Commands ..........................................................................................................43

4 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 5: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Count.................................................................................................................................43Match................................................................................................................................44

The "all" Shortcut...................................................................................................................44Productivity................................................................................................................................45

Sorting................................................................................................................................... 45Aliases................................................................................................................................... 45Executing Commands at CLI Startup.....................................................................................46

Archiving.................................................................................................................................... 46How it Works..........................................................................................................................46Commands.............................................................................................................................47Distribution Archiving............................................................................................................47Revisions in Detail.................................................................................................................48

Corus Scripts..............................................................................................................................48Using variables..................................................................................................................49Loading properties kept in Corus to use as variables........................................................49

Packaging Scripts with Distributions..........................................................................................50Supported Scripts..................................................................................................................50Call Sequence........................................................................................................................50Script Environment................................................................................................................51

File System Access............................................................................................................51Variables............................................................................................................................51Clustering..........................................................................................................................52

Putting it Together.................................................................................................................52pre-deploy.corus................................................................................................................52post-deploy.corus..............................................................................................................52rollback.corus....................................................................................................................53

Rollback.................................................................................................................................53Advanced Topics ............................................................................................................................54

Tagging...................................................................................................................................... 54Remote Tag Update...............................................................................................................55

Shell Scripts...............................................................................................................................55Deploying a Shell Script.........................................................................................................55Listing the Deployed Shell Scripts.........................................................................................56Executing a Shell Script.........................................................................................................56Undeploying a Shell Script.....................................................................................................56

File Uploads................................................................................................................................56Deploying a File.....................................................................................................................57Listing the Deployed Files......................................................................................................57Undeploying a File.................................................................................................................57

Repository..................................................................................................................................57Rationale................................................................................................................................57Mechanism............................................................................................................................58Configuration.........................................................................................................................58Using the Pull Command........................................................................................................60Dynamic Repository Role Change..........................................................................................60

Discovery with Avis....................................................................................................................60Port Management.......................................................................................................................61REST API..................................................................................................................................... 61Syslog Integration......................................................................................................................62HTTP Extensions.........................................................................................................................62

File System............................................................................................................................62JMX......................................................................................................................................... 63Deployer................................................................................................................................63Processor...............................................................................................................................63

Alerts.......................................................................................................................................... 64

5 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 6: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Java Processes............................................................................................................................64Corus Interoperability Specification in Java...........................................................................64Troubleshooting.....................................................................................................................65Interacting with Corus from Java............................................................................................65

Dependency......................................................................................................................65Triggering a Restart...........................................................................................................65Triggering a Shutdown......................................................................................................65Registering a Shutdown Listener.......................................................................................65Producing Status Data.......................................................................................................66Hot Config.........................................................................................................................66

The “Ripple" Functionality..........................................................................................................67Common Options...................................................................................................................67Ripple with a Single or a Few Commands..............................................................................68Ripple with a Corus Script......................................................................................................68

Cloud Integration.......................................................................................................................69Modifying the JSW Configuration...........................................................................................70Modifying the init.d Script......................................................................................................70

Maven........................................................................................................................................ 71External Discovery.....................................................................................................................72

Consul.................................................................................................................................... 72Service Definition..............................................................................................................72Configuration....................................................................................................................73

Conclusion...................................................................................................................................... 74

6 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 7: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Introduction

Corus   is  an   infrastructure   that   allows   centrally   controlling  application  processes   in   distributedenvironments. In a short list, here are Corus' features:

• Centralized, remote, replicated application deployment/undeployment across multiple hosts.

• Centralized, remote, replicated execution/termination of application processes across multiple hosts.

• Monitoring of running processes to detect crashes (and restart crashed processes automatically).

• Possibility for processes to publish status information at the application level, through the Corusinfrastructure. Status information can then be monitored centrally.

• Possibility for processes to trigger their own restart.

• Replicated, JNDI­compliant naming service: based on Sapia's Ubik distributed computing framework (guaranteeing fail­over and load­balancing), the naming service can be used by deployed Java applications.

• Platform agnostic: potentially allows ANY type of applications to be deployed ­Java, Python, C++ (currently only Java support offered).

• Allows centralized distribution of «standard» Java applications (Java classes with a «main» method), and remote control of corresponding JVMs.

• Allows multiple Java applications per­JVM, through the use of Magnet (http://www.sapia­oss.org/projects/magnet).

• Integration with the Java Service Wrapper to ensure high­availability of Corus instances (and startup at OS boot time). See the wrapper documentation here: (http://wrapper.tanukisoftware.org/doc/english/introduction.html).

• A REST API (http://www.sapia­oss.org/projects/corus/rest.html) allowing for fine­grained controlfrom automation frameworks and scripts.

• Support for gradual replication of commands across a cluster (allows for   avoiding service degradation when performing application upgrades or performing server restarts).

• Repository functionality: automatic synchronization between Corus nodes so that newly appearing nodes become exact copies of existing ones.

• Alternate node discovery support for use in environments where IP multicast is not supported.

• Free and open source with mixed Apache 2.0 and GPL v3 licenses – see the  Licensing section(next) for more details. 

In short, what Corus gives you is full, centralized control of distributed applications and applicationprocesses. 

7 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 8: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Licensing

The Corus source code has been subdivided into two modules: 

1) A “client" module, released under the Apache 2.0 license, which produces a library (jar file) that can beplaced into the classpath of client applications, allowing these applications to connect to Corus instances anduse the Corus server API directly (a rarely necessary thing, unless one wants to develop his own tools forinteracting with Corus). It also must be placed in the classpath of applications that use Corus' JNDI.

2) A “server" module, released under the GPL, which strictly consists of the server­side Corus classes,which client applications do NOT need in their classpath. This module depends on the client module, for itimplements  some of   the   interfaces   in   it.  Applications  deployed  using  Corus  absolutely  do  NOT need   todepend on the server module in any way. The artifact produced by this server is the actual Corus distribution.

The above means the following: 

1. Client applications linked to the Corus client classes are not bound by the viral effect of the GPL. Theydepend entirely on classes released under the Apache 2.0 license, the most liberal of all open source license.It means that code linked to these classes does not require  its source to be redistributed;  that  it  can beproprietary; it also means that the Corus client .jar can be redistributed without restrictions as part of clientapplications. 

2. For the server part, it means that no one can modify and redistribute Corus without providing their entiremodifications  as  source   to   their  customers;   it   also  means   that   their  modifications  automatically  becomesubjected to the GPL. 

In 99.9% of cases, this licensing scheme has no impact on the projects using Corus: client applications willuse the client classes, which fall  under the Apache 2.0 license, and are therefore shielded from any virallicensing restrictions or obligations. 

Note on third­party LGPL libraries used by Corus

Corus is built  upon Ubik,  Sapia's distributed computing framework.  Ubik uses the  JBoss Serializationlibrary by default, and it can support discovery using  Avis  (which provides an alternative for environmentswhere IP multicast is not supported) – see the Avis router home page for more: http://avis.sourceforge.net/.

Both the JBoss Serialization and Avis client   libraries are released under the LGPL, which ismore permissive than the GPL: it only becomes “viral" if you distribute code that uses modifiedversion of the LGPL'd code. It is very unlikely that you will customize the JBoss Serialization orAvis code, therefore this also should not impact you. 

If the LGPL bothers you, you may then simply remove these libraries from the Corus classpath.In the case of serialization, Corus will then just fall back to the JDK's standard serialization.

For more information about use of these libraries, see the Ubik web site (http://www.sapia­

oss.org/projects/ubik/index.html).

8 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 9: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Source Code

The Corus source code is hosted on Github (https://github.com/sapia­oss), and can be built withMaven.

Structure 

Corus is subdivided into two modules, and the project's structure is given below:

The folder identified as  <corus root>  actually corresponds to the Corus directory that you'vechecked out – see the next section about checking out the source. 

As can be seen, there is a client and a server module. The client module falls under the Apache2.0 license. The server module (which depends on the artifact produced in the context of the clientmodule) is licensed under the GPL  v3. 

The   artifact   produced   by   the   client   module   (sapia_corus_client-<version>.jar)   can

9 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 10: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

therefore  at  no  risk  be used as part  of   third­party  applications,  since   it   is   released  under   thebusiness­friendly   Apache   2.0   license.     The   artifact   contains   all   the   classes   and   interfacesnecessary   to  connect   to  a  Corus  server,  and  to   that  end   the  server  artifact   is  absolutely  notrequired (it is only necessary for running the server itself, and is therefore packaged as part of itsclasspath in the server's distribution). 

Building from Source 

The source code can be checked out anonymously (see  https://github.com/sapia­oss/corus) andbuilt with Maven – you must have Maven installed if you want to build Corus from source. 

To build, just cd into the directory where you've cloned the Corus rezpo, and type: mvn install. 

The Corus server's distributions (which come in the form of zip and tar archives) are generatedunder the modules/server/target directory (more precisely, under the “target" directory of theserver module).

Corus depends on other Sapia projects. The artifacts for these projects are hosted at Bintray. Youshould have these repositories configured in your Maven settings (settings.xml) to be able tobuild Corus, both for “normal" dependencies and for plugins. Here's an example:

… <repositories> <repository> <id>bintray-sapia</id> <url>http://dl.bintray.com/sapiaoss/main</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repositories> <pluginRepositories> <pluginRepository> <id>bintray-sapia-plugin</id> <url>http://dl.bintray.com/sapiaoss/main</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories> …

10 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 11: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Architecture

This section gives a high­level view of the Corus architecture.

Components

From the user's point of view, Corus comes as three components:

• A lightweight Java server that is installed on a host in order to allow remote deployment andremote execution of processes on that host.

• A Java command­line interface (CLI) that gives centralized control over multiple Corus servers.

• A Java monitoring tool that helps users/administrators see what is happening in a remote Corusserver at runtime.

Topology

A Corus server is typically installed on a given host (such hosts are identified in the diagram aboveby the larger green circles with the “Corus" label in them). Corus servers are grouped by domains(or clusters).  A domain of  Corus servers can be centrally  managed through the command­lineinterface   (illustrated   by   the   figure   with   the   “CLI"   label).   Each   Corus   server   monitors/controlsprocesses on the host on which it is installed.

Corus servers discover each other through multicast   (either   IP multicast,  or relying on a TCP­based   multicast   mechanism,   based   on   Avis   –   see  http://avis.sourceforge.net/).   The   followingdescribes how Corus servers are grouped into domains:

• At startup, Corus servers are given a domain name through the command­line, or through theirconfiguration file.

• When a new Corus server appears in the network, it broadcasts an event stating the domain itis part of.

• Existing Corus servers will   trap the event.   If   their  domain name corresponds to  the domainname  that   is  part  of   the  received  event,   they  then  in   turn  broadcast  an event  stating   theirexistence.

11 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 12: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

The newly started Corus server will in turn trap the events coming from existing servers. It will addthese servers (or, rather, their corresponding addresses) in its internal sibling list. A typical Corustopology is illustrated below:

The Corus Server

As was explained, a Corus server is installed on a given host to remotely execute and terminateprocesses  on  that  host,  as well  as  to  deploy/undeploy  distributions   from which  processes  areeventually instantiated. At the core, that is all there is to it.

In fact, at a high­level, a Corus server does no more than a human being: typically, when wantingto use an application, we acquire it (very often, we download a zip or setup.exe file); then we installit; and then we start an instance of it (we «execute»  it). When we're finished, we shut it down. 

Of course, Corus (i.e.: a Corus server) will not download a zip file or an executable on its own. Inthis case, this part is replaced by an administrator deploying the required distribution into Corus,

12 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 13: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

and then starting processes from it.  The big advantage that  Corus  gives us  is pretty  obvious:typically, executing an application means invoking some executable on the machine on which thecorresponding distribution has been installed. With Corus, local execution is handled by a server;the latter will execute processes upon request by «us», the users. Such requests are made withCorus' command­line interface (see next section).

The   remote   execution   scheme   becomes   all   the   more   powerful   when   multiple   Corus   serverscollaborate in a domain: multiple processes on multiple machines can be controlled centrally, fromthe command­line interface.

In   addition,   Corus'   functionalities   do   not   stop   at   deployment/undeployment   of   applicationdistributions, and at process execution/termination. Corus has full control over running processes.Through that control, Corus can offer the following features:

• Executed processes are monitored; those that are deemed crashed or in an unstable state areautomatically terminated (and optionally restarted) by the Corus server that started them.

• When executing processes, Corus acquires their «original» process identifier (or PID) ­ the onethat is assigned by the OS. This identifier is used to eventually agressively kill processes that donot obey the shutdown requests from their Corus server. It can also be used in problem­solvingby system administrators.

• Client applications (running within Corus­executed processes) can publish status information totheir   corresponding   Corus   server.   That   status   information   can   then   be   perused   byadministrators (using the command­line interface – see next section).

The Command­Line Interface

The command­line interface  is used to:

• Deploy  application  distributions   into  Corus  servers   that  are  part  of  a  given  domain   ­  whentargeted   at   more   than   one   Corus   server,   a   deployment   is   replicated   (the   distribution   issimultaneously deployed to all Corus servers).

• Start   processes   from   the   given   distributions.   Process   execution   can   be   replicated   also:processes   corresponding   to   given   deployed   distributions   can   be   started   on   multiple   hostssimultaneously.

• Undeploy applications from a single Corus server, or from multiple Corus servers in a domain.

• Stop running processes at a single Corus server, or at multiple Corus servers in a domain.

• Obtain status information from processes in a domain.

• View what distributions have been deployed.

• View what processes are running.

• Deploy shell scripts and execute them remotely, on the Corus nodes.

To ease its use, the CLI emulates Unix commands (ls  lists deployed distributions,  ps and killrespectively list and stop running processes, etc.).

13 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 14: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

The CLI in addition supports pattern matching operations. The following examples illustrate typicaluse cases:

Command Descriptiondeploy dist/*.zip Deploys all distribution archives ending

with the .zip extension,  under the distdirectory.

exec ­d myapp ­v 1.* ­n echoServer ­ptest

Starts   the   echoServer   processcorresponding   to   all   1.xx   versions   ofthe  myapp   distribution  under   the   testprofile

exec ­d *  ­v * ­n *  ­p test ­cluster Starts the processes corresponding toall versions of all distributions under thetest  profile,  on  all  Corus  hosts   in   thecluster.

kill ­d myapp ­v 1.* ­n echoServer ­ptest

Kill   all   echoServer   processescorresponding   to   all   1.xx   versions   ofthe  myapp   distribution  under   the   testprofile.

kill ­d myapp ­v 1.* ­n *  ­p test Kills all processes corresponding to all1.xx versions of the myapp distributionunder the test profile.

kill ­d * ­v * ­n *  ­p test ­cluster Kills   all   processes   under   the   testprofile, on all Corus hosts in the cluster.

kill all ­p test ­cluster A shortcut   that  amounts   to   the  samething as the above.

Help on the available commands can be obtained through the  man  command in the CLI. Typingman will display all available commands; typing  man <command_name> will display help on thespecified command.

Processes

Process execution occurs upon request of Corus administrators. Concretely:  the exec commandis  typed at   the  CLI     (with   required  command­line arguments),  and a corresponding  commandobject is sent to the Corus server to which the user is connected. If performed in clustered mode (ifthe -cluster switch has been entered at the command­line), the command is replicated to otherCorus servers.

Upon receiving the command, the Corus server will  start   the specified process.  From then on,processes executed by Corus servers are required to poll their respective Corus server, accordingto   the   protocol   explained   by   the  Corus   Interoperability   Specification  (http://www.sapia­

14 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 15: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

oss.org/projects/corus/CorusInterop.pdf).

All   communications   between   Corus­controlled   processes   and   their   server   indeed   follow   thatspecification, which details a SOAP/HTTP­based protocol (where processes are  in fact clients).The following diagram illustrates a Corus server and the processes it controls:

The protocol specifies a series of commands, corresponding to the life­cycle of processes startedby a Corus server. That life­cycle can be summed up as follows:

• Processes are started following an exec command.

• After startup, processes poll their Corus server at a predefined interval to signal that they are upand running. At a predefined interval  also, processes send status information to their server(application­code within the process can take part in status generation).

• When polling, processes eventually get back their list of pending events (the server keeps anobject representation of each process, and within these objects, a queue of pending commandstargeted at the «real» process).

• Processes are eventually killed using the kill command (not the one of the OS, but the oneemulated by  the CLI).  The object  corresponding  to  the kill  command  is sent  to  the desiredCorus   servers.   Internally,   the   servers   introspect   the  kill  command   to   figure   out   whatprocesses must be stopped; the objects representing the processes that must be killed have a«kill» event  queued up in them. At the next poll, that signal is «recuperated» (sent as part of aSOAP response) to polling processes.

• Processes that are shutting down following a «kill» event must confirm their shutdown to theirCorus server. As a matter of precaution, processes that fail doing so are eventually killed usingan «OS» kill by their Corus server.

15 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 16: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

• Processes that do not poll their Corus server within the predefined interval are deemed crashedor  unstable,  and  thus automatically  killed   (and  optionally   restarted,  depending configurationinformation provided at deployment).

The   fact   that   interoperability   between   Corus   servers   and   their   corresponding   processes   isimplemented using SOAP over HTTP means that even if Corus is implemented in Java, potentiallyany  type of application processes can be controlled with   it  (C++,  Python,  Perl,  etc.).  Currentlythough, the only implementation of the Corus Interoperability Specification is in Java.

16 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 17: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Installation

Installing  Corus   is   straightforward.   Concise   instructions  can   be   found  on   the   Corus  web  site(http://www.sapia­oss.org/projects/corus/install.html)   –   you   will   also   find   OS­specific   installationprocedures on the Corus wiki (http://code.google.com/p/sapia/wiki/CorusInstallationProcedure).

We advise that you look at the wiki for the latest instructions. Nevertheless, here is a summary:

Download the latest Corus distribution from Mediafire (https://www.mediafire.com/folder/v55q0gaqvvbda/corus). The distribution comes as a .gzip or .zip file, depending on your target platform.

• On the host  where  Corus  will  be  installed,  create  a  directory  where   the distribution  will  be“unzipped".

Make sure that the full path to the directory you have chose does not contain spaces.

• On Unix/Linux,  create  a user   (by convention,   it   is  named  corus)   that  will  own  the above­created directory.

• Create   the  $CORUS_HOME  environment   variable   on   the   Corus   host;   the   variable   shouldcorrespond to the full path of the directory that has been created in the previous step (underLinux/Unix, you can also define that variable in a file that is loaded when users log in – such asin  /etc/profile on some Linux distributions).

• Add the bin directory under $CORUS_HOME to your PATH environment variable.

That's it. You can start corus by typing corus in a terminal.

Corus Network Address

As mentioned   in  other  sections  of   this  document,  Corus   is  built  upon Sapia's  Ubik  distributedcomputing framework.

A special Ubik property may be used to specify on which network address Corus should listen,That address will also be returned as part of the remote stubs that Corus generates in the courseof communicating with clients (which is the case in the context of JNDI lookups for example, orwhen using the CLI).

The property to set (in the corus.properties file) is as follows:

ubik.rmi.address-pattern=192\\.168\\.\\d+\\.\\d+

The value of the property is expected to be a regexp that will  be matched against the networkinterfaces  that  Corus detects.  Note  the double­backslashes;   the single­backslash  is an escape

17 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 18: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

character in Java, but in this case we want it to be interpreted literally so that it is processed by theregexp evaluation.

Testing the Server

You are ready to start a Corus server. To test your installation, go to the command­line of your OSand type:

corus

Typing the above with  no arguments should  display  the Corus server  help.  Read  it   for  furtherinformation. Typically, to start a Corus server, you provide the name of the domain “under" whichthe server should start, and the port on which it should listen (by default, the port is 33000, and thedomain is simply “default"). Hence:

corus -d mercury -p 33100

Will start the server in the foreground under the “mercury" domain, on port 33100.

Installing as a Service

The Corus wiki contains instructions describing how to install Corus as a service on your targetplatform. See: 

http://code.google.com/p/sapia/wiki/CorusInstallationProcedure.

Also, you may look at the  Corus Configuration Properties  section for more information abouthow to configure Corus, The corus.properties  file under the config directory also containsinstructive comments.

All of the links below appear on the Corus wiki, and might prove more up to date.

Linux

If your Linux flavor does not appear below, you may base yourself on a distribution that supportsCorus as a service through init.d (such as Fedora).

Ubuntu: http://code.google.com/p/sapia/wiki/CorusInstallationProcedure_Ubuntu

Fedora: http://code.google.com/p/sapia/wiki/CorusInstallationProcedure_Fedora

Mandriva: http://code.google.com/p/sapia/wiki/CorusInstallationProcedure_Mandriva

OpenSuse: http://code.google.com/p/sapia/wiki/CorusInstallationProcedure_OpenSUSE

18 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 19: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Mac

We're supporting Mac through launchd. See:

 http://code.google.com/p/sapia/wiki/CorusInstallationProcedure_SnowLeopard.

Windows

XP: http://code.google.com/p/sapia/wiki/CorusInstallationProcedure_WindowsXP

Vista: http://code.google.com/p/sapia/wiki/CorusInstallationProcedure_WindowsVi   sta

Testing the Client

To connect to the above server using the command­line interface, type:

coruscli -h localhost -p 33100

As you might have guessed, the arguments passed at the command­line specify the host of theserver we wish to connect to, as well as the port of that server (for help, type the command withoutany arguments). As for the server, the -h and -p options are optional and will default to localhostand 33000 respectively.

Once you are in the CLI, you can see the list of available commands by typing:

man

Yes, you are right: just like Unix. You should see the list of available commands then. To read helpabout one of them, type:

man <name_of_command>

And off you go: help about the specified command is displayed.

To exist the CLI, type:

exit

Reading the help of every command, as explained above, should give you a pretty clear idea ofwhat you can concretely do with Corus. It is very much recommended doing that before goingfurther.

19 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 20: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Testing the Monitor

The Corus monitor is a nifty utility that displays logging output received from a Corus server, atruntime,   remotely.   It   is   great   to   introspect   what   the   server   is   doing   while   you're   deploying,executing processes, etc. 

To start the Corus monitor, type (of course, a Corus server must be running):

corusmon -h localhost -p 33100

As for   the server,   the  -h  and  -p  options are optional  and will  default   to   localhost  and 33000respectively.

It can be a little while before you see something, but you will, eventually. To exit the monitor, justtype CTRL­C.

Packaging Applications

The deployment unit in Corus is called a “distribution". There are currently two ways to configure adistribution in Corus so that it can be deployed. 

Distributions

With   Corus,   you   deploy   J2SE   applications   (meaning:   Java   classes   with   a  main()  method)packaged in .zip files.

Corus does not force a programming model upon the programmer: learning and using a bloatedAPI (such as EJB) is out of the question. With Corus, you deploy standard Java apps, period.

Corus   complements   the   lightweight­container   approach   very   neatly:   you   can   embed   yourlightweight­container in a main() method and deploy your application within Corus; you can useCorus' JNDI implementation to publish your “lightweight" services on the network, in a scalableand robust manner.

The   .zip   file   that   you   deploy   within   Corus   (dubbed   a   “distribution"   in   Corus'   jargon)   is   onlymandated  to  provide  a Corus  descriptor  under  the  META-INF  directory   (under  the  root  of   thearchive). An example of that file is given below:<distribution name="demo" version="1.0"xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.0.xsd"> <process name="echoServer" maxKillRetry="3" shutdownTimeout="30000" invoke="true">

20 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 21: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

<port name="test" /> <java mainClass="org.sapia.corus.examples.EchoServer" profile="test" vmType="server"> <xoption name="ms" value="16M" /> </magnet> </process> </distribution>

Before delving into the details of the configuration format, we will discuss it at large:

• In Corus, a distribution is the deployment unit. As was mentioned previously, Corus allowsonly managing Java applications for now, and thus a distribution consists of a set of Javaprocess definitions.

• Process  definitions are  in   fact  blue prints   for  Java virtual  machines:   these Java virtualmachines are started up by the Corus server, upon request by the user. 

• The Java virtual machines started by Corus may optionally be configured with Magnet (seehttp://www.sapia­oss.org/projects/magnet).  Magnet   is  simply  a   tool   that   is  used  to startmultiple Java applications (Java classes with a main method) within the same VM; it allowsconfiguring the classpath of each application (and much more) through a convenient XMLformat. Thus, what happens really is that Corus starts a Magnet process, which in turninvokes the main() method of each of its configured Java applications. Each applicationin turn has its own classloader, independent from the classloader of other applications (seeMagnet's documentation for more information).

• Without   the   Java   applications   “knowing"   it,   Magnet   starts   a   lightweight   client   thatimplements the Corus Interoperability Specification. That client polls the Corus server at aregular interval to let Corus know that the process in which it “lives “ is still up and running.This is where Corus' process management functionality kicks in: a Corus server is awareof which processes it has started and will monitor them, making sure that they are pollingat their predefined interval.

Deploying with Magnet: Step­by­Step

Rather then delving further into abstraction, we will go through implementing an application that ismeant to be deployed into Corus (the configuration format will be explained in the next section).Implementing such applications is not much different then implementing them for “normal" use(except for the packaging part). The steps involved are as follows:

• Implement a J2SE application.

• Write the Magnet file for the application.

• Write the Corus descriptor for the application.

• Package  the  application   in  a   .jar   file,  with   the  Corus  descriptor   (named  corus.xml)under the META-INF directory.

• Deploy the distribution (the .jar file) into Corus.

• Execute processes that are defined in the distribution.

21 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 22: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

To better illustrate the above steps, we provide the concrete examples ­ in the next subsections.

Implement a J2SE Application

The applications consists of a naive echo server implementation. As can be seen, itdoes   not   make   use   of   any   special   class   and   does   not   follow   any   predefineddevelopment  model   in  order   to be deployed  into Corus;   it   is  a plain  Java serverstarted from a main() method:

package org.sapia.corus.examples;

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.ServerSocket;import java.net.Socket;import java.util.ArrayList;import java.util.Collections;import java.util.List;

public class EchoServer extends Thread{ private ServerSocket _server; private List _clients = Collections.synchronizedList( new ArrayList()); /** Creates a new instance of EchoServer */ public EchoServer(ServerSocket server) { _server = server; } public void close() throws IOException{ _server.close(); } public void run(){ while(true){ try{ System.out.println("EchoServer::accept..."); Socket client = _server.accept(); System.out.println("EchoServer::client connection"); ClientThread ct = new ClientThread(client, _clients); _clients.add(ct); ct.start(); }catch(Exception e){ e.printStackTrace(); break; } } System.out.println("EchoServer::exiting..."); } public static void main(String[] args){ try{ int port = Integer.parseInt(args[0]); EchoServer server = new EchoServer( new ServerSocket(port)); server.start(); Runtime.getRuntime().addShutdownHook( new Shutdown(server)); }catch(Exception e){ e.printStackTrace(); } } /////////// INNER CLASSES //////////// public static class ClientThread extends Thread{

22 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 23: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Socket _client; private List _queue;

public ClientThread(Socket client, List queue){ _client = client; _queue = queue; } public void run(){

BufferedReader reader; PrintWriter pw; try{ reader = new BufferedReader(new InputStreamReader(_client.getInputStream())); pw = new PrintWriter(_client.getOutputStream(), true); }catch(IOException e){ System.out.println("Client::terminated"); _queue.remove(this); return; } while(true){ try{ String line; while((line = reader.readLine()) != null){ System.out.println("Client::ECHO: " + line); if(System.getProperty(line) != null){ pw.println("ECHO: " + System.getProperty(line)); } else{ pw.println("ECHO: " + line); } pw.flush(); } }catch(IOException e){ e.printStackTrace(); try{ _client.close(); }catch(IOException e2){} break; } } System.out.println("Client::terminated"); _queue.remove(this); } } public static class Shutdown extends Thread{ private EchoServer _server; public Shutdown(EchoServer server){ _server = server; } public void run(){ try{ _server.close(); }catch(Exception e){} } }}

2) Write the Magnet File

Magnet   has   been   originally   written   to   provide   a   multi­platform   way   of   describing   runtimeparameters for Java applications that are typically started with os­specific startup scripts (such as.sh or .bat scripts, for example). In the case of Java applications, runtime parameters generallyconsist of system properties, the name of the Java application class, command­line arguments,and   classpath   information.   Magnet's   powerful   XML   format   allows   specifying   all   of   that   in   aconvenient  and  portable  way   (refer   to  Magnet's  web  site   for  more   information).  Here   is   theMagnet file for our echo server:

23 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 24: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

<magnet xmlns="http://schemas.sapia-oss.org/magnet/core/" name="EchoServer" description="A basic echo server"> <launcher type="java" name="echoServer" mainClass="org.sapia.corus.examples.EchoServer" default="test" isDaemon="false" waitTime="2000" args="5656"> <profile name="test"> <classpath> <path directory="lib"> <include pattern="*.jar" /> </path> </classpath> </profile> </launcher></magnet>

In the above example,   file resources (namely, the libraries that are part of the classpath) areresolved   relatively   to   the   “current  directory",   (available   in  Java  under   the  user.dir  systemproperty). In terms of directory structure, the application is therefore organized in the followingway:

<user.dir>/echoServerMagnet.xml

<user.dir>/lib

The echoServerMagnet.xml file contains the above Magnet configuration. Of course requiredlibraries   (if  any)  would  appear under  the  lib  directory.  At  development   time,   the  user.dirvariable corresponds to the “working" directory of your IDE.

One convenient way to work with Corus is to test the application prior to deploying it. Making surethat   everything   works   properly   prior   to   deployment   allows   sparing   the   dreadful   deploy­test­redeploy cycle that is so common with EJB applications and consumes a lot of development time.In this case, we would invoke Magnet from the command­line (after compiling and generating a.jar for our echo server under the lib directory):

sh magnet.sh -magnetfile echoServer.xml -p test

The   first   command­line   option   consists  of   the  name  of   our   Magnet   configuration   file   (if   notspecified, Magnet expects a  magnet.xml  file under the current directory). The second optionconsists  of  the name of   the profile  under which  the Magnet VM should  be started (for  moreinformation on the concept of profile, have a look at the Magnet web site).

If everything works fine, we are ready to write our Corus descriptor (there is a client   for  theserver as part of Corus but we won't show it here; have a look in the package to see the source ifyou feel like it).

The  great   strength  of  Corus   in   terms  of  application  development   is   the  absence  of  a   rigidprogramming model that forbids starting applications from a simple command­line; it does notforce deployment into a bloated container prior to be able to use and test applications.

3) Write the Corus Descriptor

The Corus descriptor  is expected under the  META-INF  directory of  the the archive that will  begenerated and deployed. In the case of this example, the META-INF directory is created under thecurrent directory (since the distribution will be generated from that directory). The content of thecorus.xml file for the echo server is provided below:

24 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 25: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

<distribution name="demo" version="1.0" xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.0.xsd"> <process name="echoServer" maxKillRetry="3" shutdownTimeout="30000" invoke="true"> <port name="test" /> <magnet magnetFile="echoServerMagnet.xml" vmType="server" profile="test"> <xoption name="ms" value="16M" /> </magnet> </process> </distribution>

One   thing   to   note   is   that   the  corus.xml  file   contains   a  magnet  element.   Since   Corus'architecture   was   thought   to   eventually   allow   different   types   of   processes   to   be   started   (forexample,   Python   or   Perl   applications),   the  magnet  element   is   a   side­   effect   of   that   intent(eventually, a  python  element could be introduced): it is meant to indicate that a Magnet VMshould be invoked; more concretely: a Magnet bridge instantiated within Corus is invoked andtriggers  the execution of  the Magnet  command­line,  consistently with the parameters that areconfigured in the corus.xml file.

As can be noted, the magnetFile attribute indicates which Magnet configuration file should beused; the file's location should be given as a path that is relative to the root of the eventual Corusdistribution (i.e.: the root of the .jar file). This is because as part of the deployment procedure,Magnet distributions are extracted under a predefined directory under Corus; the directory wherea given distribution was extracted is the directory relatively to which Magnet configuration files ofthat distribution are resolved.

Another noticeable detail are the name and version attributes of the distribution element:every distribution deployed into Corus is uniquely identified by the value of its name and version.This also means that you can have multiple distributions with the same name, but that in this casethe versions must differ.

The Corus descriptor will be explained in more details further below.

4) Package the Distribution in a .zip File

Packaging   a   Corus   distribution   only   requires   putting   in   a   .zip   file   the   required   resources:application libraries, Magnet file(s), Corus descriptor. In the context of your example, we coulduse Ant to package everything that is under the root of the working directory. This would in effectmirror the structure on the file system, and that is one of the main goals: to eliminate disparitiesbetween usage in a local, standalone mode, and deployment on a multi­VM, distributed mode.The application that you implement and use locally on your workstation is the exact same onethat will be deployed into Corus.

Thus, our application archive would have the following structure:

echoServerMagnet.xml

lib/

META-INF/corus.xml

Optionally, a distribution may have scripts packaged with it. These a are Corus scripts (that is,containing Corus commands) that will  be executed on demand, on the server­side.  See  CorusScripts section further below for more details.

25 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 26: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

5) Deploy the Distribution

Since  an  archive  properly  packaged  as  a  Corus­deployable  unit  may  contain  more   than  oneapplication (given as multiple process definitions or as multiple applications in the same Magnetconfiguration or both), that archive is named a “distribution", not an application anymore. That issuch even in the case of our example, where only one application is involved.

Deploying an application into Corus involves calling the following command through   the Coruscommand­line:

deploy <distribution_path>

Where  <distribution_path>  is the path to the Corus distribution that is to be deployed (if arelative, the path is resolved from the directory in which you have invoked the Corus command­lineinterface).

See  the  Installation  section   further  below   for   instructions  on  how  to  use   the  command­lineinterface.

6) Execute

Once   a   distribution   has   been   successfully   deployed,   processes   described   as   part   of   thedistribution can be started. In the case of our example, we would invoke the exec command fromthe Corus client console:

exec -d demo -v 1.0 -n echoServer -p test

The above command will  start  a  Java  virtual  machine  “containing"  anƒ  instance  of  our  echoserver  (more precisely:  a Magnet  VM  is   invoked,  with   the configuration  corresponding  to  theprocess that we want to execute).

In the above case, we are indicating to Corus that we want to start a VM corresponding to thedemo distribution,  version  1.0.  We  indicate   the name of   the process configuration (-n)  sincemany such configurations could be part of a Corus descriptor. The last option tells Corus underwhich profile the process will be started (the notion of profile is fully explained in the Distributionsand Processes in Detail section, later on).

Note that we could also have passed the -cluster option to the command:

exec -d demo -v 1.0 -n echoServer -p test -cluster

This   would   actually   start   the   process   on   all   Corus   servers   in   the   domain   that   have   thecorresponding distributions.

Furthermore,   we   could   have   started   more   than   one   process,   by   specifying   the  -i  option,indicating to Corus how many instances of the processes are to be started:

exec -d demo -v 1.0 -n echoServer -p test -i 3

or 

exec -d demo -v 1.0 -n echoServer -p test -i 3 -cluster

In the latter case, we are requesting the startup of 3 echo servers at all  Corus servers in thedomain (note that this would result in port conflicts, since our echo servers on the same host all

26 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 27: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

listen to the same port).

It is important to understand that processes are executed by a Corus server on the host machineof that Corus server; meaning: a process (a JVM in the case of our example) is started by aCorus server on its own host for each invocation of the exec command it receives.

Deploying using Standard Java

If you find using Magnet unsuitable, you may use a simpler method (in this case, you will  notbenefit from Magnet's powerful multi­application and classpath management features). 

In such a case, you must create a Corus archive that will have the following structure:

classes/

lib/

META-INF/corus.xml

Upon startup, the JVM corresponding to your application will be assigned the classes directoryand all the archives under the lib directory as part of its classpath.

The classes directory is meant to contain resources (Java classes, arbitrary files) that are notpackaged as libraries (in .jar files).  The lib directory, for its part, is meant to hold libraries (.jarfiles).

The content of the lib directory (and subdirectories) must consist of archives witheither the .jar or .zip extension – and supporting the zip format. The archives willbe “inserted" in the classpath in alphabetical order. Corus will include archives insubdirectories, but will  only sort based on the names of the files (excluding thepath). Note also that the content of the classes directory will be inserted intothe classpath first.

The content of the corus.xml file will in this case consist of the following:<distribution name="demo" version="1.0" xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.0.xsd"> <process name="echoServer" maxKillRetry="3" shutdownTimeout="30000" invoke="true"> <port name="test" /> <java mainClass="org.sapia.corus.examples.EchoServer"

profile="test" vmType="server"> <xoption name="ms" value="16M" /> </java> </process> </distribution>

Note that the location of libraries may be chosen to be something else than a lib directory. Thedescriptor   supports   a  libDirs  element   to   that   end,   which   takes   a   semicolon­delimited   ofdirectories (relative to the root of the distribution zip) to include in the classpath. For example:

<distribution name="demo" version="1.0" xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.0.xsd"> <process name="echoServer"

27 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 28: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

maxKillRetry="3" shutdownTimeout="30000" invoke="true"> <port name="test" /> <java mainClass="org.sapia.corus.examples.EchoServer"

profile="test" vmType="server" libDirs="patches/;lib"> <xoption name="ms" value="16M" /> </java> </process> </distribution>

The patches directory given in the above example  ends with a forward­slash: this will havethe effect of adding that directory itself to the classpath (otherwise, Corus attempts finding .jarfiles under the directory, and adds those to the classpath). If you have directories that containresources which must be available to classloading, then use that method.

Again, if a classes directory is present under the root, the file it contains will be inserted in theclasspath, and will have precedence over the library directories.

28 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 29: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Server Configuration and File System Layout

When deploying a distribution to Corus, it is unzipped on the server­side, according to a predefinedlayout.

Corus Server Working Directory

You can start multiple Corus servers on the same hosts if you please, as part of the same domain,or as part of different ones. In any case, each server instance will have its own working directoryunder the Corus home directory. The working directory of a given server instance is identified bythe following pattern:

port_<port_number>

For example,  a Corus server   instance listening on port  33000 would have  port_33000  as  itsworking directory. 

Corus Distribution Directories

As was mentioned previously, when a distribution is deployed into Corus, it is extracted under theserver's  deploy  directory.   More   precisely,   Corus   creates   the   following   structure   under   thedeployment directory:

<distribution_name>

/<version_number>

/common

/processes

The actual distribution archive is extracted under the common directory. When executing a processof that distribution, Corus internally assigns an identifier to that process; it then creates a directoryunder the processes directory that is given the process identifier as a name. For example, if theprocess identifier is 1234567, then the 1234567 is created under the processes directory. 

As is described in the Corus System Properties section further below, processes are passed theabove  information  (their  common  and  process  directories)  as  the  following  system properties,respectively: user.dir and corus.process.dir.

29 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 30: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Configuration Properties

A Corus server takes into account two configuration files (actually, Java property files), both in the$CORUS_HOME/config directory. It also supports remotely overriding the properties in these files:in such cases,   the properties are kept  in Corus'   internal  database ­ see the  Remote PropertyUpdate subsection further below on that topic). These files are:

• $CORUS_HOME/config/corus.properties: holds the server's configuration parameters.

• $CORUS_HOME/config/corus_process.properties: holds properties that are passed to each started process.

Both of these files must respect the Java properties format. The  corus_process.propertiesfile holds arbitratry properties that are passed to executed processes (through the command­line)as Java system properties.  This  means a command­line option respecting  the  format  below  iscreated for every property in the file:

-D<property_name>=<property_value>

For  its part,  as stated, the file  named  corus.properties, contains the server's configurationproperties.   Note that since Corus rests on Sapia's Ubik distributed computing framework, it alsosupports all Ubik properties (which is of interest when wanting to use Avis as a node discoverymechanism).

Additionally, as a convenience when running multiple Corus instances on the same host, additionalfiles can be specified allowing for configuration that is specific to each instance. Such configurationfiles must respect the following naming convention to be loaded at startup:

$CORUS_HOME/config/corus_<port>.properties

Where <port> corresponds to the port of the Corus instance to which this file is destined.

Configuration can also be kept under the HOME directory of the user under which the Corusserver is running. See the Home Directory Overrides subsection below for more details.

The Corus server's configuration properties are described in the table below. The table indicates ifthe current property can be remotely updated ­ the Remote Property Update section, further below,describes the mechanism for storing configuration properties within the Corus server itself. Pleasesee that section for it provides relevant information about where to keep configuration properties:

30 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 31: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Property Description Required Remote Update

corus.server.properties.include.01[corus.server.properties.include.02corus.server.properties.include.N...]

One   ore   more   property   includes,each consisting of the path to oneor  more property   files   that  shouldbe   included   and   are   stored   inarbitrary locationiuin the file system(potentiallly   in   mounted   networkdrives).The   files   in  each  path   should  beseparated by either ':' or ';' ­ withoutthe quotes.  This   mechanism   allows   sharingconfiguration across multiple Corusinstances.

No No

corus.server.domain The   name   of   this   propertycorresponds   to   the   name   of   thedomain to which the Corus serverbelongs.If   the   domain   is   specified   at   thestartup  script   of   the  Corus   server(through   the  -d option),   thisproperty is not taken into account.

No(if not specified in the file,must be given as the -d

option at the Corus serverstartup script).

No

corus.server.port The port on which the Corus servershould listen.If the port is specified at the startupscript of the Corus server (throughthe -p option), this property is nottaken into account.

No (defaults to 33000)

corus.server.tmp.dir The   directory   where   distributionsare   deployed,   pending   theirextraction   under   the  deploydirectory.

No (defaults to<server_dir>/tmp)

Yes

corus.server.deploy.dir The   directory   where   distributionsare extracted and kept.

No (defaults to<server_dir>/deploy)

Yes

corus.server.db.dir The directory where Corus' internaldatabase stores its files.

No (defaults to<server_dir>/db)

Yes

corus.server.uploads.dir The   directory   where   file   uploads(that   is,   files  deployed with   the   ­fswitch in the CLI) are kept.See   the  File  Uploads  subsectionunder   the  Advanced   Issuessection of this document.

No (defaults to<server_dir>/files/

uploads)

Yes

corus.server.scripts.dir The directory where deployed shellscripts   (with   the   ­s   switch   in   theCLI) are kept.See  the  Shell  Scripts  subsectionunder   the  Advanced   Issuessection of this document.

No (defaults to<server_dir>/files/

scripts)

Yes

corus.process.timeout Delay(in   seconds)   after   whichprocesses that have not polled theirCorus   server     are   considered"timed out".

Yes Yes

31 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 32: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Property Description Required Remote Update

corus.process.start-at-boot.enabled Indicates if a processes should bestarted   automatically   at   Corusserver   boot   time,   provided   theseprocesses   have   an   executionconfiguration   that   is   flagged   asstartable   on   boot   –   i.e:   thestartOnBoot flag is set to true. 

No (defaults to true) Yes

corus.process.check-interval Interval(in   seconds)   at   which   theCorus server  checks for timed outprocesses.

Yes Yes

corus.process.kill-interval Interval(in   seconds)   at   which   theCorus     server   attempts   killing   acrashed process.

Yes Yes

corus.process.start-interval Amount of time that Corus will waitfor between process startups, whenmultiple   processes   are   started   atonce by end­users.

No (defaults to 15) Yes

corus.process.restart-interval Amount   of   time   (in   seconds)   aprocess   must   have   been   runningfor  before  it  crashed and  in orderfor   an   automatic   restart   to   beauthorized.

Yes Yes

corus.server.multicast.addresscorus.server.multicast.portorubik.rmi.naming.mcast.addressubik.rmi.naming.mcast.port

Multicast address and port used fordiscovery, respectively.As   of   version   3.0,   Corus   alsosupports the Ubik variants.Note:   the   values   of   theseproperties are by default  made  tocorrespond with the default valuesused   by   Ubik   (the   distributedcomputing   framework   on   whichCorus is based).

Yes Yes

ubik.rmi.address-pattern A   regexp   specifying   on   whichnetwork address the Corus servershould listen.It is preferrable to set that propertyif   the   host   on   which   Corus   isinstalled   has   more   than   onenetwork interface.By default,  Corus will   listen on allnetwork   interfaces.   It   will   alsoattempt   to   return   as   part   of   theremote stubs that  it  generates thefirst network address it finds that isnot localhost – otherwise, localhostwill be used.

No No

corus.server.security.hostPattern.allowcorus.server.security.hostPattern.deny

Each property is expected to hold acomma­delimited list of patterns ofIP addresses from which clients areeither   allowed   or   deniedconnection, respectively. Here are valid patterns:192.168.*.*192.*.*.*192.**192.**.*

No Yes

32 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 33: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Property Description Required Remote Update

corus.server.syslog.protocol The protocol   to use to connect  tothe Syslog daemon ­  value may beudp, tcp.Note:   for  Syslog  integration  to beactivated,   all   properties   undercorus.servder.syslog.* must be set.

No No

corus.server.syslog.host The host of the Syslog daemon. No No

corus.server.syslog.port The port of the Syslog daemon. No No

corus.server.alert.enabled Indicates if email alerting should beenabled. 

No (defaults to false) Yes

corus.server.alert.smtp.host The host of the SMTP relay to useto send alert emails.

Yes (defaults to localhost) Yes

corus.server.alert.smtp.host The port of the SMTP relay to useto send alert emails.

Yes (defaults to 25) Yes

corus.server.alert.smtp.password The SMTP password to use whenconnecting to the SMTP relay uponsending email alerts.

No Yes

corus.server.alert.recipients The   semicolon­delimited   list   ofrecipient   email   addresses   to   usewhen sending alert emails.

Yes Yes

corus.server.alert.sender The   email   address   that   shouldappear   in   the   “from"   field   whensending alert emails.

Yes (if not specified, adefault is built based onthe host of the SMTP

relay)

Yes

Remote Property Update

Corus supports remotely updating server or process properties. In such cases, it is not the actualproperty   files   that  are  modified:   rather,  Corus  adds/removes   the properties   to/from  its   internaldatabase; if specified, the properties will override the corresponding ones in the file. 

The updates are performed using the Corus command line interface. The conf command allowsadding,  deleting,  and   listing  either  server  or  process  properties.  The  command  also  supportsupdating so­called “tags" (explained in the next section). The syntax goes as follows:

1) To add a property, or a list of properties:conf add -s s|p -p name1=value1[,name2=value2[,nameN=valueN[...]]

Where:

• s specifies the scope (indicating if the property is a server (s) or process (p) property – thescope defaults to process when not specified).

• p  consists   of   a   comma­delimited   list   of   name­value   pairs   corresponding   to   actualproperties (there must be no space in the list for it to be parsed properly).

2) To list the properties

conf ls -s s|p

Where:

33 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 34: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

• s specifies the scope (indicating if the property is a server (s) or process (p) property – thescope defaults to process when not specified).

3) To remove a property

conf del -s s|p -p some.property

conf del -s s|p -p some.*

Where:

• s specifies the scope (indicating if the property is a server or process property)

• p  specifies  the property  to remove (may include wildcards corresponding to a propertyname pattern – in which case all matching properties will be removed

For the properties with the “server" scope, the Corus instance must be restarted for the newvalues to be taken into account.

Property Includes

It may be convenient to share configuration properties across multiple Corus instances.

This is possible through a mechanism dubbed “property includes".  How this works is very simple:you configure includes in the corus.properties file, as follows:

corus.server.properties.include.01=${user.home}/.corus/corus.properties

corus.server.properties.include.02=/opt/corus/corus.properties:/etc/corus/corus.properties

To configure includes, you have to follow the format below for property names:

corus.server.properties.include.<suffix>

This format allows configuring multiple includes on different lines. The suffix can be any string, butyou should design them keeping in mind that Corus will evaluate includes based on the  sort orderof their corresponding suffix. 

On   the   right­hand   side,   the   property   value   is   expected   to   be   a   path   composed   of   multiplesegments, each pointing to a file to include, and where each segment is separated by either acolon (:) or semicolon (;).

As you can see, property values may also contain variables in the following format:

${<name>}

Variables are expected to correspond to JVM properties (such as user.dir,  user.home, etc.).Such variables are evaluated at Corus startup.

Home Directory Overrides

Corus   server   properties   files   can   be   kept   under   the  $HOME/.corus  directory,   where  $HOMEcorresponds   to   the  home directory  of   the  user  under  which   the Corus  server   is   running.  Thefollowing   files  will   be  automatically   loaded  at   startup,  and  will  override   the  ones   found  under$CORUS_HOME/config:

• $HOME/.corus/corus.properties

34 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 35: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

• $HOME/.corus/corus_<port>.properties

In  the above  <port>  stands  for   the port  of  Corus   instance   to which   the given properties  aretargeted.

Property Categories

As of version 4.5, Corus supports so­called property “categories"  ­  for process properties only.Property categories really allow grouping properties so that not necessarily all properties apply toall processes.

To be clearer: when adding process properties to Corus, such properties are “global" by default, inthe sense that they are passed to all processes at startup. This might not be the desired effectwhen deploying unrelated applications to the same Corus instances. In such cases, one may wishto isolate certain sets of properties  so that these are passed to only certain applications.

The  conf  command supports  assigning  categories  to properties.  This   is  done through  the  -coption, as shown by the following example: 

conf add myapp.properties -c server-apps

The  -c  option  allows  passing  a  comma­delimited   list   of   categories   (there  must  be  no  spacebetween the categories):

conf add myapp.properties -c server-apps,admin-apps

Passing the right set of properties to given processes is specified through the Corus descriptor(corus.xml). To sum it up: 

• global process properties (those that are in the $CORUS_HOME/config/corus_process.properties file, and those stored in Corus with no category assigned to them) are always passed to all processes; 

• the properties corresponding to the different categories are passed only if these categoriesare specified in the Corus descriptor, for the given distribution/process. Such properties willoverride global process properties with identical names).

To better undersand the above, let's examine the following Corus descriptor sample:<distribution

xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.0.xsd" name="demo" version="1.0" propertyCategories="myproduct" >

<process name="myServer" ... propertyCategories="server-apps"> <port name="test" /> ... </process> </distribution>

The descriptor shows the propertyCategories attribute defined both on the <distribution>and on the <process> elements. Both support a comma­delimited list of property categories, forwhich order matters: for identically­named properties, the ones whose category came first will beoverridden by the properties of subsequent categories.

Furthermore, property categories defined at the <process> level will override those defined at the<distribution> level, for identically­named properties.

The   CLI's  conf  command   allows   viewing   properties   and   their   categories,   as   welladding/updating/deleting properties, taking categories into account – type man conf in the CLI for

35 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 36: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

more details.

In the end then, the set of properties passed to a process includes (in that order, which also is theorder in which overriding is done):

• The   properties   that   are   created   at   startup   by   Corus   for   a   given   process(corus.process.id, corus.process.dir, etc.).

• The properties defined in the $CORUS_HOME/conf/corus_process.properties.

• The global  process properties stored in Corus (those added with conf add,  and  notassigned to a category).

• The process properties corresponding to the categories specified at the <distribution>level (if any).

• The process properties corresponding to the categories specified atthe <process> level (if any), for the currently starting process.

Dynamic Domain Change

The domain  of  a Corus   instance  (or  of  a  whole  cluster)  can be dynamically  changed,  withoutrestarting Corus, either through the CLI or through the REST API. Here's an example using theCLI:

cluster domain my-new-domain -cluster

When the name of a Corus cluster is changed this way, Corus saves it in a file named .corus-readonly-<corus-server-port>.properties,  under  the  $HOME/.corus  directory (where$HOME corresponds to the home directory of the user under which the Corus server process runs,and  <corus-server-port> to the port of the current Corus instance).

Corus  always   looks   for   the presence  of   that   file  at  startup,  and  the properties   it   contains  willsupplement/override all other server properties.

As its name implies, this file should not be manually edited by system administrators.

36 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 37: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Distributions and Processes in Detail

The Corus Descriptor

The Corus descriptor is the XML file (named  corus.xml) which must be packaged as part ofCorus distributions, under the META-INF directory (which itself must be present under the root ofthe distribution .zip).

Here  is  an elaborate  Corus  descriptor   (all  elements are  formally  explained   in   the  table  furtherbelow) :<distribution

xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.0.xsd" name="demo" version="1.0" tags="someTag" >

<process name="echoServer" maxKillRetry="3" shutdownTimeout="30000" deleteOnKill="false" invoke="true" pollInterval="15" statusInterval="45" tags="someOtherTag" propertyCategories="echoApp"> <port name="test" /> <magnet magnetFile="echoServerMagnet.xml" profile="test" javaCmd="java">

<!-- Alternate standard Java configuration: simpler, but less powerful than Magnet -->

<!-- java mainClass="org.sapia.corus.examples.EchoServer" profile="test" javaCmd="java"> <xoption name="ms" value="16M" /> <dependency dist="testDist" version="1.0"

process="testApp" profile="prod" />

</magnet> </process> </distribution>

The   Corus   descriptor's   XML   schema   can   be   dowloaded   from:    http://www.sapia­oss.org/xsd/corus/distribution­4.0.xsd. The table below provides a description for each element andattribute specified in the schema:

Name Description Attributes / child elements

Name Reqd. Description

distribution The root element  of  all    Corusdescriptors

name Yes The name of the distribution.

37 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 38: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Name Description Attributes / child elements

version Yes The version of the distribution.

tags No A comma­delimited list of tags usedto   determine   if   the   configuredprocesses should be started (basedon   the   tags   of   the   current   Corusserver) – see the Tagging section. 

propertyCategories No A   comma­delimited   list   of   propertycategories,   determining   whichprocess  property  sets   to  use  and  itwhat   order   (the   global,   defaultproperty   set   is   always   used,   andlooked up first).

process (1­*) Holds   process   descriptioninformation.

name Yes The name that identifies the processconfiguration.

38 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 39: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Name Description Attributes / child elements

maxKillRetry  No The number  of   times  Corus  shouldattempt   to   kill   processescorresponding   to   this   processconfiguration that are deemed stalledor “down" (defaults to 3).

shutdownTimeout No The  number  of  milliseconds   that   isgiven   to  processes   to   confirm   theirclean shutdown (defaults to 30000).

deleteOnKill No Indicates if processes correspondingto  this  process  configuration  shouldhave their process directory deletedafter shutdown (defaults to false).

invoke No Indicates if processes correspondingto   this   distribution   will   be   startedautomatically   when   invoking  execfor the distribution without indicatingwhich   process   configuration   tocreate   processes   from   (if   true,   thevalue  of   this  attribute   indicates   thatprocesses   corresponding   to   thisprocess   configuration   must   beinvoked explicitly by passing the  -noption   to   the  exec  command)   –defaults to false.

pollInterval No The   interval   (in   seconds)   at   whichprocesses   corresponding   to   thisconfiguration   are   expected   to   polltheir Corus server (defaults to 10).

statusInterval No The   interval   (in   seconds)   at   whichprocesses   corresponding   to   thisconfiguration   are   expected   toprovided  their   runtime status   to   theCorus server (defaults to 30).

tags No A comma­delimited list of tags usedto determine if the process should bestarted   (based   on   the   tags   of   thecurrent   Corus   server)   –   see   theTagging section.

preExec No A   single   such   element   can   bespecified.

propertyCategories No A   comma­delimited   list   of   propertycategories,   determining   whichprocess property sets to use and inwhat   order   (the   global,   defaultproperty   set   is   always   used,   andlooked   up   first).   The   set   resultingfrom  this   list   is  additive   to   the  onedefined   at   the  <distribution>level.

interpolationPasses No The number of variable interpolationpasses   to   do   when   rendering

39 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 40: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Name Description Attributes / child elements

port (0­*) Used to indicate a network portnumber  that  should  be passedto the insances of the process.

name Yes The   name   of   a   port   range,   asconfigured in the Corus server  (seethe  Port Management  section futheron for more information).

preExec (0­1) Allows specifiying multiple  cmdchild   elements,   eachcorresponding   to   a   Corus   CLIcommand.Each   such   command   will   beexecuted   on   the   server­side(that is, at the Corus node) priorto   the   process   itself   beingexecuted.

cmd Yes Multiple   such   elements   can   bespecified.See   the  Pre­Execution  section,further below, for more information.

cmd (0­*) The element's content is meantto  hold  a Corus  command­linewhich  will  be  executed  on   theserver­side (at the Corus node)

N/A N/A N/A

magnet (0­1) Encapsulates   informationrequired   by   the   underlyingMagnet   launcher  when startingup JVMs.

magnetFile Yes The path to the Magnet configurationfile, relatively to the root of the Corusdistribution archive.

profile Yes The name of the profile under whichprocesses are to be started.

javaHome No Allows specifying usage of a differentJVM by specifiying the home of theJDK or JRE installation directory thatis desired (defaults to the same Javahome as the Corus server by whichprocesses are executed).

javaCmd No Allows   specifying   the   name   of   theJava executable that is to be invokedwhen   starting   JVMs   (defaults   tojava).

vmType No Indicates   the   type  of  VM (­client  or­server for Java Hotspot) that is to bestarted.

java (0­1) Encapsulates   informationrequired     to   launch   astandalone   Java   application   inits own JVM.

mainClass Yes The   name   of   the   application   class(class   with   a   “main"   method)   toinvoke upon JVM startup.

40 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 41: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Name Description Attributes / child elements

profile Yes The name of the profile under whichprocesses are to be started.

javaHome No Allows specifying usage of a differentJVM by specifiying the home of theJDK or JRE installation directory thatis desired (defaults to the same Javahome as the Corus server by whichprocesses are executed).

javaCmd No Allows   specifying   the   name   of   theJava executable that is to be invokedwhen   starting   JVMs   (defaults   tojava).

vmType No Indicates   the   type  of  VM (­client  or­server for Java Hotspot) that is to bestarted.

libDirs No Allows   overridding   the   default  libdirectory   expected   to   contain   thelibraries   with   which   the   JVM'sclasspath will be built.The   value   must   be   a   semicolon­delimited   list   of   directories(interpreted   relatively   to   thedistribution's root – that is, the root ofits .zip file). The libraries (.jar files) inthese directories will then instead beused to build the JVM's classpath.To include directories directly so thattheir   resources  are  available   to   theclassloader,   these  must  end  with  aforward­slash.   See   the  DeployingStandard Java section further abovefor an example.

dependency (0­*)

Used   to   indicate   that   a   givenprocess depends on another

distribution ordist 

No The name of the distribution to whichthe   other   process   belongs.   If   notspecified, the current distribution willbe assumed.

process Yes The name of   the  process  on whichthe current process depends.

version No The   version   of   the   distribution   towhich  the other  process  belongs.   Ifnot   specified,   the   version   of   thecurrent distribution will be assumed.

profile No If   not   specified,   the   profile   of   theparent  magnet  or  java  element   isused.

arg (0­*) Corresponds   to   a   VMargument,   such   as­javaagent.

value Yes The value of the the argument.

41 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 42: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Name Description Attributes / child elements

option (0­*) Corresponds to a   VM option –such as  ­cp or  ­jar  (see thehelp of the java command formore information).

name Yes The name of the option.

value  Yes The value of the option.

property (0­*) Corresponds   to  a    VM systemproperty  that  will  be passed toprocesses   using   the   form:­Dname=value.

name Yes The name of the system property.

value  Yes The value of the system property.

Profiles

Corus supports the concept of “profile".  A profile   is simply a character string that  identifies the“type" of execution of a process. To be more precise, imagine that you have a distribution (in theCorus   sense) containing multiple process configurations corresponding to applications that aredeployed in different  environments,  or used under different  conditions.  For example,  you coulddeploy a distribution to a Corus server in your development environment, and deploy that samedistribution in QA or pre­prod. By the same token, you could connect to some server simulator in adevelopment environment, but to the real one in pre­prod or QA. A common problem is also thedatabase, which could have different addresses across environments, and even be of a differentbrand (HSQLDB, Postgres) in these different environments.

The notion of profile is a simple way to work around the configuration problems that arise whenworking in different environments or using applications under different conditions. Based on theprofile (passed around as a string, remember...) you could use different configuration files. 

Therefore, Corus makes no assumption with regards to the profile; it just passes it to executedprocesses as a system property (the  corus.process.profile  system property).   In addition,the Magnet starter (used by Corus to start Magnet processes) passes the profile to the VM throughthe magnet.profile.name system property (this is because Magnet also supports the notion ofprofile and uses that system property to identify the current profile – having a look at the Magnetweb site will enlighten you).

So from your application, you only need “interpreting" that system property (i.e.: implement codethat acts based on the value of that system property).

42 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 43: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Process Properties

When executing a process, Corus passes to it process properties (in fact, VM system properties assupported in Java). Theses properties consist of all the ones specified as part of:

a) the process configuration in the Corus descriptor (corus.xml); 

b) the corus_process.properties file under $CORUS_HOME/config; 

c)   the  process  properties  stored   in   the  Corus  server,  which  can  be  administered   through  thecommand line – see the Corus Properties section further below. 

In addition, Corus will pass the following properties to new processes:

Name Description Value

corus.process.id The   unique   identifier   of   the   process   that   wasstarted.

A Corus process identifier.

corus.process.name The name of the process that was started. A process name.

corus.server.host The address of the Corus server that started theprocess.

An IP address.

corus.server.host.name The host name of the Corus server that startedthe process.

A host name.

corus.server.port The  port   of   the  Corus  server   that   started   theprocess.

A port.

corus.server.domain The  name  of   the  domain  of   the  Corus  serverthat started the process.

A domain name.

corus.distribution.name The   name   of   the   distribution   to   which   theprocess corresponds.

An   absolute   path   to   adirectory.

corus.process.dir The directory of the process. The   directory   of   theprocess.

corus.process.poll.interval The interval at which the process is expected topoll its Corus server.

A time interval in seconds.

corus.process.status.interval The interval at which the process is expected tosend its status to its Corus server.

A time interval in seconds.

corus.process.profile The name of the profile under which the processwas started.

The name of a profile.

user.dir The “common" directory of all processes of thedistribution of which the process is part.

An   absolute   path   to   adirectory.

43 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 44: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Process Pre­Execution

It is possible to have Corus commands executed prior to the execution of a process. Commandsexecuted  in  this manner are processed by a command interpreter  embedded within   the Corusinstance: their execution is meant to be strictly in­VM, the  -cluster  option is not supported intheir case; and some commands make no sense in embedded mode, their use having potentiallyunpredictable effects (such as deploy, for example). 

Typical Use 

Such commands (the same ones that are typically typed in the Corus CLI) are specified int thepreExec element of the Corus descriptor (which is itself under the process element). A preExecelement can have any number of cmd elements as children. The snippet below illustrates such anelement.<process ...> <preExec> <cmd>conf export -f ${corus.process.dir}/conf/app.properties</cmd> </preExec> <java ... libDirs="${corus.process.dir}/conf/;lib"> ... </java></process>

In   the   above,   prior   to   execution,   Corus   process   properties   are   exported   to   the   given   file   (${corus.process.dir}/conf/app.properties).

Then, in the libDirs attribute of the java element, the directory containing that file is inserted inthe classpath (note that the ending with a forward­slash is required if the whole directory is to beincluded in the classpath. If the directory does not end with a forward­slash, Corus will look for .jarfiles in that directory,  and these will  be added to the classpath – the  Corus Descriptor  section,further above, has a note to that effect).

The intent above is to make process properties available to the application being deployed, whichcan then load the properties file through its classloader.

It   is   recommended   to   export   properties   in   a   process­specific   directory,   so   that   differentprocesses do not overwrite each other's properties. The best guarantee then is to store suchfiles under the folder corresponding to the one created specifically for the process – to which thecorus.process.dir property is mapped.

Using conf merge

A more advanced use could be the following:<process ...> <preExec> <cmd>conf merge -r -b ${user.dir}/conf/apps.properties -f ${corus.process.dir}/conf/app.properties</cmd> </preExec> <java ... libDirs="${corus.process.dir}/conf/;lib"> ...

44 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 45: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

</java></process>

The above uses the conf merge command, which proceeds as follows:

1. Loads the properties specified by the -b option (the properties are considered the “base"). 

2. Adds  the  Corus  process  properties   to  properties   thus   loaded   in  memory   (the  processproperties will override any identically­named properties in the base properties)

3. Saves the resulting properties to the file (know as the “target") specified by the -f option.

The -r option triggers the replacement of variables in the propertie loaded from the base file, usingthe process properties (in a bit more, as explained just below) for looking up their correspondingvalue. Meaning: given such a property in the base properties:  app.environment=${env}, andthe   following   process   property:  env=qa,   then   the   resulting   property   will   beapp.environment=qa.

The process properties are used for variable values, but the properties passed to the  process byCorus (corus.process.id,  corus.process.dir, etc.) and Corus' own system properties aswell. The lookup order is as follows:

1. The   properties   that   are   dynamically   created   and   passed   to   the   process   by   Corus(corus.process.id...).

2. The process properties stored in Corus.

3. Corus' own system properties.

If some variables cannot be replaced (due to having no match in terms of their name in neither ofthe above­define properties),   then they are  left  as  is  and will  be saved in    this manner  in  theresulting target file.

The same variable resolution rules apply when processing the command­lines specified by the cmdelement in the descriptor.

Invoking Ant

Ant scripts may be invoked from the CLI, through the ant command. The following illustrates suchan invocation (type man ant in the CLI for more details):<process ...> <preExec> <cmd>ant -f ${user.dir}/scripts/copy_files.xml</cmd> </preExec> <java ... libDirs="${corus.process.dir}/conf/;lib"> ... </java></process>

Say the content of copy_files.xml is as follows:<project name="copy_files" default="run"> <target name="run"> <mkdir dir="${corus.process.dir}/conf" /> <copy todir="${corus.process.dir}/conf"> <fileset dir="${user.dir}/${corus.process.profile}"> <include name="**/*.properties"/> </fileset> </copy> </target> </project>

45 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 46: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

In the above example, a set of Java properties files is copied from a sub­directory under the root ofthe current Corus distribution. For the sake of the example, that directory is made to correspond to the current process' profile (note that the root directory of the Corus distribution is available throughthe user.dir property). The destination directory here corresponds to the directory assigned by Corus to the process (through the corus.process.dir property).

This example illustrates that an Ant script invoked this way has access to all the variables passed to a process at runtime.

Process Dependencies

It   may   occur   that   some   processes   depend   on   other   processes,   and   that   these   processesthemselves  depend on other  ones,  and  so  on.  The  Corus  descriptor  supports  declaring  suchdependencies, through dependency elements. 

When such dependencies are detected, Corus will process them so that processes are started inthe   appropriate   order.   This   will   startup   multiple   processes   consecutively,   in   such   a   case   thecorus.process.start-interval     property should be set properly in order to not bottleneckthe CPU while applications complete their initialization phase.

The excerpt below (corresponding to a Corus descriptor) shows a dependencies can be declaredon a per­process basis:<distribution xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.0.xsd"

name="demo" version="1.0"> <process name="echoServer" maxKillRetry="3" shutdownTimeout="30000" invoke="true"> <java mainClass="org.sapia.corus.examples.EchoServer" profile="test" vmType="server"> <xoption name="ms" value="16M" /> <dependency dist="demo" version="1.0" process="configurator" /> </java> </process> </distribution>

Dependencies (processes on which other processes depend) are executed first, inthe  order   in  which   they  are  declared:   if  process  A  depends  on  process  B,  andprocess B depends on process C, the execution order will be as such: C, B, A.

Execution Configurations

It may become tedious to start multiple processes manually. The process dependency feature mayhelp work around this hassle, but what if some processes have no other processes that depend onthem ? In such a case, if not started explicitly, they will never execute.

46 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 47: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Corus allows defining so­called “execution configuration". These configurations consist of XML filesthat are uploaded (through the  deploy  command) to a Corus server (or to multiple servers, incluster mode). 

An example process configuration is given below:<exec xmlns="http://www.sapia-oss.org/xsd/corus/exec-3.0.xsd" name="test" startOnBoot="true"> <process dist="web" version="1.0" name="httpServer" profile="prod" instances="1"/> </exec>

The exec element takes the following attributes:

• name (mandatory): an arbitrary name used to refer to the configuration later on.

• startOnBoot (defaults to false): indicates if the configured processes are to be started when the Corus server itself boots up.

In   addition,   the  exec  element   contains   one   to   many   process   elements,   eachindicating   which   processes   should   be   started.   Each   process   element   takes   thefollowing attributes:

• dist (mandatory): the distribution to which the process belongs.• version (mandatory): the distribution's version.• name (mandatory): the name of the process.• profile (mandatory): the profile under which to start the process.• instances (defaults to 1): the number of process instances that should be

started.

Execution  configurations  can  be  deployed,   listed,  undeployed,  and  “executed",  all   through   thecommand  line.  The  following  shows example  commands – see  the command  line help  of   theappropriate command for more information.

1) To deploy

deploy -e myTestConfig.xml

2) To list the currently deployed execution configurations

ls -e

3) To undeploy

undeploy -e test

4) To execute

exec -e test

The processes corresponding to an execution configuration are treated the same way as if theyhad been started manually: process dependencies are resolved, and processed are started inthe appropriate order. Thus, if all dependencies are declared appropriately, there is no need tospecify processes on which other process depends as part of execution configurations: thesewill be started through the normal dependency resolution mechanisms.

47 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 48: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

A Closer Look at the CLI 

The command­line   interface   is   the primary  means  of   interaction  with  Corus.  Examples  of  CLIusage are given throughout this guide. This section provides specific tips around CLI usage.

Managing in Batch

If you are handling a relatively large number of processes/distributions/hosts, you have an interestin using features of the CLI that allow for batch manipulation.

Pattern Matching

Many   commands   support   pattern­matching   (ls,  undeploy,  exec,  ps,   etc.).   Here   are   a   fewexample:

ls -d * -v *

exec -d * -v * -n * -p test 

undeploy -d * -v *

ps -d * -v *

Aggregate Commands 

For lack of a better term, we have classified some commands under the "aggregate" category.These commands are match and count: they work on the results of other commands, performingfiltering and counting, respectively.

Count

The count command is used to count the number of results returned by given commands ­ whichare expected to return lists (such as ls, port ls, conf ls, etc.). The syntax goes as follows:

count <command>

The following all make sense in the context of count:

count hosts

count ls -d * -v * -cluster

48 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 49: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

count ps -d * -v *

The count command also supports the -a option ­ which stands for "assertion". This is used toassert  that the number of items returned by the subsequent command corresponds to the onespecified by the -a option. For example, to assert that the cluster as a certain number of hosts, youcan do the following:

count -a 10 hosts

If the assertion fails, it generates an error and execution aborts. This can be useful in the context ofsanity checks prior to deployment.

Match

When managing large clusters, it can happen that commands listing information (such as ls, confls,  port ls,  ps, and the likes) return too much data at once to be easily viewable by systemadministrators. This is where the match command comes handy (working somehow like grep  inUnix/Linux). In the same manner as count, match takes a subsequent command as an argument,applying  filtering  to  that  command's  output,  based on a specified pattern (Ant­like  patterns aresupported, not regexes).

In addition,  match also can be provided with a Corus script to be executed against the hosts forwhich the matching was successful ­ in this case, the command is actually  match apply. Thesyntax of the command is given below:

match [apply <script_path>] <pattern> <command>

Here are a few examples:

match act. ps -cluster Displays   the   currently   active   processes,cluster­wide.

match 192.**.10* hosts Displays   the   hosts   whose   IP   addresscorresponds to the given pattern.

match apply restart.corus stal* ps -cluster Applies   the  restart.corus  script   to   thehosts returning processes that are stale. 

When using match apply, if a script contains commands with the -cluster option, the valueof the option is  internally "hijacked" so that the commands only target the hosts for which amatch occurred.

Using match in conjunction with count can be quite convenient:

count match stal. ps -cluster

The "all" Shortcut

When performing  undeploy,  kill, etc.,   it  can be annoying to have to provide all   the optionswhen we want to match everything (such as in kill -d * -v * -n *).

As  a  convenience,  many  commands  support   the  all  keyword,  as   illustrated  by   the  following

49 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 50: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

examples:

undeploy all -cluster

kill -all -cluster

restart -all

Productivity

The CLI supports a few productivity features that make using it more convenient.

Sorting

Corus supports sorting the output using predefined so­called flags ­ used in the context of  thesort command.

This section provides an overview of output sorting ­ for a complete list of the sort flags that areavailable, type man sort in the CLI. The following are available in terms sorting features:

• Turning specified sort flags on or off.

• Pushing sort flag configuration to Corus, and clearing such a configuration from Corus.

• Listing the available sort flags.

To sort output by host name and IP address (in that order), type:

sort on hn,hi

Multiple sort flags can be specified, through a comma­delimited list (without spaces). Sorting canbe turned off. For example, to turn off sorting by IP, type:

sort off hi

Sort flag configuration can be pushed to the Corus node to which the CLI is currently connected (orto all nodes in the cluster), as follows:

sort push hn,hi -cluster

Flags pushed to a Corus node are automatically loaded when the CLI connects to that node.  

As a corollary, sort flags can be cleared from the current Corus node, or from the whole cluster:

sort clear -cluster

The sort clear command deletes all flags ­ it does not support clearing only specific flags.

To view the flags that are currently specified, type:

sort ls

50 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 51: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Aliases

It may be convenient to create alias for commands, especially when those are used repetitivelyand take multiple arguments.

The alias  command   is  used  to  create  aliases   for  existing  commands.  These  aliases  are   theninterpreted as "normal" commands by the CLI. The following creates an alias named ka, which willact as a synonym for the kill all -cluster command:

alias -n ka -c "kill all -cluster"

If an alias is specified with no arguments/options, then such arguments and options can be passedto it at invocation time. For example, let's redefine our ka alias:

alias -n ka -c "kill"

It can then be invoked as follows:

ka all -cluster

If both the alias and the aliased command have arguments/options, those of the alias will overridethose passed at the command line.

For example, say we define our ka alias as in our first example:

alias -n ka -c "kill all -cluster"

If we invoke the alias as follows:

ka -d * -v * -n * -cluster

Then the options and arguments passed to the command will be ignored, since the alias has suchoptions   and   arguments   defined   already.   So   these   will   override   the   ones   of   the   command.Therefore, that actually executed command will be kill all -cluster. 

Executing Commands at CLI Startup

Linux/Unix  and other OSes support   loading a user­specific  script   that  sets up the environmentwhen the user launches a terminal session.

Similarly, when the CLI starts up, it searches for a Corus script at:

$HOME/.corus/.profile.corus

The content of the  .profile.corus  script is expected to consist of Corus commands ­ it is aplain­vanilla Corus script, which may hold any command that the user sees fit. It is a convenientplace to define aliases, sorting (see the two previous sections), etc.

Archiving

Corus allows "archiving" its current state, for certain types of objects. This functionality can be used

51 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 52: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

in the context of rollbacks, for example, where we'd then "unarchive" the previous state (which isthe case in the context of a rollback).

The objects that can be archived are the following:

• Process properties.

• Tags.

• Execution configurations.

• Port ranges.

• Distributions.

How it Works

Archiving involves saving the state of objects at a given point in time, so that these objects can  berestored later on, if need be ­ an operation called "unarchiving".

Objects are archived in the context of a so called "revision". The "revision identifier" is provided bythe user. It serves as a reference, which is meant to be used if unarchiving eventually needs beingperformed. 

Commands

The following commands are supported for archiving/unarchiving operations:

• For process properties and tags (respectively):

◦ conf archive -p -rev <rev_id>

◦ conf archive -t -rev <rev_id>

◦ conf unarchive -p -rev <rev_id>

◦ conf unarchive -t -rev <rev_id>

• For port ranges:

◦ port archive -rev <rev_id>

◦ port unarchive -rev <rev_id>

• For execution configurations:

◦ exec archive -e -rev <rev_id>

◦ exec unarchive -e -rev <rev_id>

There are also two commands that bundle all operations above:

archive -rev <rev_id>

unarchive -rev <rev_id>

These do what the previous commands do, in one shot, for archiving and unarchiving respectively(archive  will   trigger   the   archiving   of   process   properties,   tags,   port   ranges,   and   executionconfigurations, while unarchive will do the same for unarchiving).

52 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 53: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Distribution Archiving

In addition to the above­mentioned commands pertaining to the archival of configuration, it is alsopossible to archive distributions. This aims at supporting the following scenario:

• A new distribution version is deployed.

• The current version is undeployed, but in fact kept on the Corus side in case it should berevived due to a rollback.

• Rolling   back   would   involve   (among   others):   undeploying   the   latest   distribution,   andredeploying the previous one.

There   is  no special  command   for  archiving  distributions.  Rather,  archival   is  done   through  theundeploy command, and "unarchival" is performed with deploy. 

The idea is that when undeploying, we'd want to keep a copy of the distribution on the side ofCorus, to make sure we can quickly redeploy the exact same distribution package if need be. Theundeploy command therefore supports the -rev option, for passing in the revision "under" whichthe distribution being undeployed should be archived, as illustrated by the example below:

undeploy -d * -v * -rev previous 

We've chosen "previous" as a revision identifier, to illustrate that relatively to the new distributionversion that will be deployed, the one being undeployed is in fact the previous version. RevisionIDs however are completely arbitrary, and it is up to users to pick the ones they see fit.

Now in the context of a rollback, we would: undeploy the new distribution, redeploy the previousone. That is reflected by the commands below:

undeploy -d * -v *

deploy -rev previous

Note two things: first, the undeploy above is not provided with the -rev option: our intent is indeedto completely remove the new distribution, since at this point it is probably faulty.

Second, we are actually not deploying a distribution package: we're just indicating Corus that itshould deploy the distribution it has archived ­ under the "previous" revision.

Revisions in Detail

When archiving, the current state of objects being archived is kept in a bucket called a "revision".As   was   mentioned   previously,   a   revision   is   tagged   with   a   user­supplied   identifier.   Here's   anexample:

conf -p archive -rev previous

In  this case,  we're  archiving process properties under a revision called "previous" ­   there's noimposed conventions on revision identifiers, other than that they can only contain alpha­numericcharacters, dashes (­), underscores (_) and periods. In our case, using "previous" makes it clearer,when unarchiving, that we're doing the operation to restore the "previous" state, as shown below:

conf unarchive -rev previous 

Also, If an archival is performed using a given revision identifier, and re­archive later on using that

53 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 54: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

same identifier, object state kept as part of the preceding revision is lost, and the new object statetakes over.

For example, consider the following sequence:

1. conf add -t tag1,tag2

2. conf archive -rev previous

3. conf del -t *

4. conf add -t tag3,tag4

5. conf archive -rev previous

6. conf del -t *

7. conf unarchive -rev previous

8. conf ls -t 

The last command (conf ls -t) will return tags tag3 and tag4: even though tag1 and tag2had been previously archived (#2), they have been overwritten by the archiving of tag3 and tag4,(#5) under the same revision identifier.

A   more   comprehensive   picture   of   how   to   use   the   archiving   functionality   is   provided   in   thePackaging Scripts with Distributions section, further below.

Corus Scripts

All the commands provided as part of the Corus command­line interface can also be executed aspart of scripts (which are simply text files containing Corus commands).

There are three ways to execute a script:

1. Through the script command available as part of the Corus CLI. 

2. By specifying the ­s option when invoking the CLI; the option is expected to consist of thepath to the script to execute.

3. Through the Corus Maven plugin (which is the subject of a specific section of this guide).

Here's an example of such a script:

kill all -w -cluster undeploy all -clusterdeloy myapp-*.zip -clusterexec -e myapp -cluster

The content of the script above could be saved in a plain text file and executed from the CLI likethis:

54 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 55: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

coruscli -s <path_to_script>

The kill, exec and restart commands all support a -w option, meaning “wait", which forcesthe command­line to block until the command has completed on the server­side prior to movingon to the next command. This is convenient in the case of scripted deployments.

For example, in the above, it is necessary to wait that the kill has completed prior to invokingundeploy,   since   that   command   will   result   in   an   error   if   processes   corresponding   to   thedistribution to undeploy are still running.

Furthermore, a script can be invoked from another, using the script command (the match andripple command also support invoking scripts):

undeploy allscript deploy.corusecho "deployment completed"

Using variables

Note that scripts can take variables of the form ${<variable_name>}, as shown below: 

undeploy alldeploy ${user.dir}/package/mydistribution.zipecho "deployment completed"

Loading properties kept in Corus to use as variables

As of release 4.5, properties added to Corus with  conf add can be loaded on the client­side inCorus scripts, and used in such scripts to perform variable interpolation.

Imagine that you've pushed a property to Corus, as such:

conf add -p app.env=prod -cluster

In order to be able to use that property has a variable on the client­side (that is, when executingscript from the CLI), you need to use conf load:

conf load conf add ${user.dir}/${app.env}/app.properties

Note our use of the ${app.env} variable, whose value will correspond to the matching propertypreviously loaded from the Corus instance to which the CLI is currently connected.

Commands following conf load can use the properties that were loaded as variable values (thatis,   the   properties   just   loaded   are   immediately   available   in   the   current   script,   for   subsequentcommands).

To load properties corresponding to a given category, use the -c option. Say for example we'veassociated the app.env property with the environment category:

conf add -p app.env=prod -c environment -cluster

We can then load properties corresponding to a given category like so:

conf load -c environment

You can also match properties with a name pattern:

55 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 56: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

conf load -p app.* -c environment

Packaging Scripts with Distributions

As of release 4.6, Corus allows packaging scripts that are executed on the server­side (that is, atthe Corus node) to further automate application lifecycle.

These scripts are expected to have a file name that is predefined, and must be packaged underthe META-INF/scripts directory of the distribution. Each script is meant to be invoked at specificpoints  in  time.  Execution of   these scripts   is  not automatic:   it  must  be  triggered by  the systemadministrator using the CLI ­ or programmatically through the REST API.

Supported Scripts

Three types of scripts are supported. The only one that is mandatory is pre-deploy.corus. 

• pre-deploy.corus:   this   script   is   invoked   by   Corus   prior   to   the   distribution   beingdeployed.   Typically,   such   a   script   is   meant   to   do   archiving,   delete   old   configuration(process properities, etc.), undeploy the current version of an application prior to deployingthe new one, etc. 

• post-deploy.corus: this script is executed after the distribution has been successfullydeployed. Processes corresponding to the "new" distribution would typically be started inthis script.

• rollback.corus: this script is executed if an error occurs at deployment time. It also canbe invoked at any time after deployment, through the rollback command. This script ismeant to allow cleaning up all traces of the current version ­ logic should be present in thescript that allows switching back to the previous version ­ such as unarchiving the previousconfiguration.

The fact that the pre-deploy.corus script is mandatory does not mean one must be presentin all distributions. Only when the execution of such packaged scripts by sysadmins is performedshould the script be there. For a distribution in the context of which that feature is not used, noscript needs being present.

Call Sequence

As was mentioned previously,  execution of the scripts  is not automatic.   It must be triggered atdeployment time, through the CLI or using the REST API. In the CLI, the deploy command takesa -r option, which stands for "run scripts". Here's an example:

deploy mypackage.zip -r -cluster

When   script   execution   is   triggered   this   way,   Corus   will   proceed   to   running   the   scripts   upon

56 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 57: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

receiving the distribution:

• It unzips the distribution as it does normally.

• It loads the pre-deploy.corus script and executes it (that script is mandatory).

◦ If   execution  of   the  pre-deploy.corus  script   fails,  Corus  attempts  executing   therollback.corus  script.   If   the   rollback   script   is   absent,   Corus   does   not   attemptexecuting   it.    At   that  point,   the  deployment  has   failed  and   remediation  by  systemadministrators should ensue.

• It   loads   the  post-deploy.corus  script   (if   present)   and   executes   it.   Again   here,   ifexecution of that script fails, Corus will attempt executing the rollback.corus script.

If deployment proceeds normally (that is, no error occurs), a rollback can always be invoked lateron. To that end, the rollback command is provided, and its syntax is as follows:

rollback -d <distribution_name> -v <distribution_version> -rev <rev_id>

Simply,   this  command will   run  the rollback script   (rollback.corus)  packaged with   the givendistribution. See the Putting It Together section further down for more details.

Script Environment

The pre-deploy.corus, post-deploy.corus, and rollback.corus scripts are expected tobe packaged under the META-INF/scripts directory of the distribution being deployed.

File System Access

When either of the above scripts is executed, it is assigned the directory corresponding to the rootof   the  distribution  as  a  base  directory.   If   the  commands   in   the  scripts  attempt  accessing   fileresources that were packaged in the distribution, they can use relative paths, and assume thatsuch paths will be resolved relatively to the root of the distribution.

For example, say we have the following:

/META-INF /scripts pre-deploy.corus post-deploy.corus rolback.corus/conf /application.properties

Our pre­deploy script can push the application.properties file using the following command:

conf add -p conf/application.properties

Variables

It is common to parametrize scripts with variables. These parameters are available to be used insuch a context:

• user.dir: corresponds to the directory that is the root of the unzipped distribution (the"base directory" assigned to the script, as explained previously).

57 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 58: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

• corus.distribution.name: the name of the distribution being deployed.

• corus.distribution.version: the version of the distribution being deployed.

• Corus' system properties.

• Corus' environment variables.

Clustering

Simply put: command clustering is disabled when scripts are executed within Corus. That is, evenif your use the -cluster option with your commands, it will have no effect.

Putting it Together

To better put things into perspective, here's an example: let's take into consideration an applicationpackaged according to the following structure ­ we're omitting the parts that are non­essential tothis exercise:/META-INF /scripts pre-deploy.corus post-deploy.corus rollback.corus /conf exec.xml

The next sub­sections explain the scripts appearing in the above layout. 

The sources for the samples provided in this section can be found in Github:

https://github.com/sapia­oss/corus/tree/develop/samples/corus_workshop/dist/scripts

pre­deploy.corus

Here's the content of the pre-deploy.corus file:echo "=> Killing current processes..."kill all -w

echo "=> Cleaning up current configs - and archiving for eventual rollback"archive previousport del -n *conf del -p *

echo "=> Undeploying current distribution (archiving previous distribution for eventual rollback)"undeploy all -rev previousundeploy -e *

The   first   command   kills   all   currently   running   processes.   Then,   we're   archiving   the   currentconfiguration  kept   in  Corus  (process  properties,  port   ranges,   tags,  execution  configurations)   incase  we need to do a rollback (which is explained further below).

Also we're undeploying all previous distributions, but leaving the latest as backup, also in case weroll back.

As a last step, we're cleaning the field for the distribution being deployed: we're undeploying allcurrent execution configurations, and deleting the current port ranges, process properties, and tags(remember   these  have been archived,  so  they're  not   lost  and we can unarchive   them  later   if

58 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 59: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

needed).

post­deploy.corus

The post-deploy.corus file goes as follows (these steps could be in the pre­deploy file as well,but we've left the pre­deploy to cleaning up the "previous" distribution):echo "=> Deploying config"port add -n http -min 8100 -max 8105conf add -p app.xms=32mconf add -p app.xmx=128mconf add -p app.xms=64m -c taggedServerconf add -p app.xmx=256m -c taggedServerconf add -p app.gc.log.type=PrintGCDetailsconf add -p app.gc.log.file=${corus.process.dir}/gc.logdeploy -e exec.xmlexec -e serversecho "=> Proceeding to sanity check"http check -p http -m 10 -t 6 -c /ping -cluster ${corus.server.host}:${corus.server.port}

When this script executes, our distribution has already been added to Corus automatically. We'reonly left with pushing our complimentary configuration (process properties, tags, port ranges, andexecution configurations).

As   a   last   step,   we're   triggering   the   startup   of   the   processes   corresponding   to   the   executionconfiguration.

rollback.corus

Now, the content of our rollback.corus file: the goal is to set things to what they were prior todeployment, including starting the processes corresponding to the "previous" distribution.echo "=> Killing processes..."kill all -wecho "removing config"port del -n *conf del -p *undeploy -e *

echo "=> Unarchiving previous state"unarchive previousdeploy -rev previous

echo "=> Starting process(es)"exec -e servers

After having killed the new processes, and undeployed our distribution and execution configuration(corresponding the version being rolled back), we're re­enabling the "previous" configuration (usingthe unarchive command), and executing the "previous" processes.

Note that the  undeploy  command used above, which undeploys the distribution being rolledback, is not necessary: as part of the rollback, Corus will automatically insure that the distributionis removed.

Rollback

The rollback.corus script is executed at deployment time, if a problem occurs deploying thenew distribution. But it can also be invoked at any time after deployment, both through the CLI andthe REST API. Using the CLI, one can invoke the rollback for a given distribution in the following

59 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 60: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

manner:

rollback -d <distribution_name> -v <distribution_version> -rev <rev_id>

If   there's   no   distribution   for   the  given   name  and   version  at   the   node(s)   you're   targeting,   thecommand will result  in an error. As a workaround, you can use rollback in conjunction with thematch command  ­ for example:

match apply trigger_rollback.corus 2.0 ls -d myapp -v 1.0 -cluster

60 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 61: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Advanced Topics 

This section covers miscellaneous "advanced" topics.

Tagging

It might be desirable to start given processes on specific hosts, and not on others. For example,imagine a process that scans a database table periodically, performs an action based on the datathat is retrieved, and then deletes that data. Multiple such processes acting in parallel will pose aconcurrency issue: the action will be performed redundantly. Thus, in such a case, one would wantto make sure that this process is executed on a single host. 

To support this, Corus has a so­called “tagging" feature: a tag is an arbitrary string that is used todetermine if a process can be executed by a given corus instance. Concretely, it works has follows:

1) The   Corus   descriptor   may   be   enriched   with   tags:   both   the   distribution   and   processelements  of   the  descriptor  support  a   tags  attribute:   the  value  of   the  attribute   takes  acomma­delimited  list of tokens, each corresponding to an actual tag.

2) A   Corus   server   itself   may   be   attributed   with   given   tags:   the   conf   command   of   thecommand­line interface may be used to add, list, and remove tags to/from a Corus server.

3) Prior to starting a process, the Corus server will determine if the tags of that process matchthe ones it has configured: if the process and its distribution have no tags, the process isstarted; if all the tags assigned to a process and its distribution are contained in the set oftags  of   the  server,   the  process   is   started;   if  all   the   tags  assign   to  a  process  and   itsdistribution are not contained in the set of tags of the server, the process is NOT started.

The example descriptor below shows how to configure tags: they can be specified as a comma­separated list on the distribution element:<distribution xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.8.xsd" name="id-generator" version="1.0" tags="singleton"> <process name="server" maxKillRetry="3" shutdownTimeout="30000" invoke="true"> <java mainClass="org.myapp.IDGenerator"

profile="test" vmType="server"> <xoption name="ms" value="16M" /> </java> </process> </distribution>

The can also be specified on a per-process basis:

<distribution xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.8.xsd" name="id-generator" version="1.0">

61 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 62: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

<process name="server" maxKillRetry="3" shutdownTimeout="30000" invoke="true" tags="singleton"> <java mainClass="org.myapp.IDGenerator"

profile="test" vmType="server"> <xoption name="ms" value="16M" /> </java> </process> </distribution>

At runtime,   the Corus server  will  determine  the  tags of  a process by merging   the  tags at   theprocess level with the ones at the distribution level: it is thus the union of these tags that is used forvalidating against the server's own tags, according to the previously defined algorithm.

Remote Tag Update

The Corus command­line can be used to add, remove and list the tags of a Corus server. Thefollowing  provides  examples   (see   the  documentation  of   the  conf command  – by   typing  manconf) for more details.

1) Adding tags

conf add -t someTag,someOtherTag

2) Listing tags

conf ls -t

3) Removing tags

conf del -t someTag

conf del -t *

Shell Scripts

The ability to deploy shell scripts into Corus and execute them remotely from the CLI has beenintroduced  as   of   version   4.0.   This   feature   is   meant   to   further  extend   the  centrally   controlledexecution of distributed processes offered by Corus.

Basically, the functionality allows:

• Deploying a shell script into a Corus node (or multiple Corus nodes).

• Triggering   the   execution   of   the   shell   script   from   the   CLI   (either   in   clustered   or   non­clustered mode).

There   is  no   restriction  on  what   the  shell   scripts  do,   their  nature  being   left  entirely   to  systemadministrators. One thing to note though is that the scripts are run under whichever user the Corusinstance is itself being run. So if the scripts require specific permissions, it is important that thesebe granted to the Corus user.

Deployed shell scripts are kept under the $CORUS_HOME/files/scripts directory. This location

62 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 63: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

is  configurable,  by modifying   the  corus.server.scripts.dir  in   the   corus.propertiesconfiguration file (itself under $CORUS_HOME/config directory).

Deploying a Shell Script

A shell script is deployed to a Corus instance using the using the deploy command in the CLI, inconjunction with the following options:

• s: the path to the shell script to deploy.

• a: the script's alias, which is used to refer to the script later on, when executing it.

• d:  the description to associate to the script. That description is used for display purposes –not that this option is optional.

Here's an example:

deploy -s /home/jdoe/restart_memcached.sh -a restart-memcached -d“Restarts memcached"

Of course, as with any Corus command, using the ­cluster option will have the effect of deployingthe shell script across all nodes in the cluster:

deploy -s /home/jdoe/restart_memcached.sh -a restart-memcached -d“Restarts memcached" -cluster

Listing the Deployed Shell Scripts

To view  the currently  deployed  shell  scripts,  use  the  ls  command  in conjunction  with   the  -soption:

ls -s 

Executing a Shell Script

To execute a shell script, type the exec command with the ­s option – the value to assign to theoption should correspond to the alias of the script to execute:

exec -s restart-memcached

Undeploying a Shell Script

To undeploy a shell script, type the undeploy command with the ­s option specifying the alias of thescript to undeploy: 

undeploy -s restart-memcached

You call also use pattern matching to undeploy multiple scripts at once:

undeploy -s restart* -cluster

63 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 64: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

File Uploads

As part of Corus 4.0, the ability to deploy arbitrary files to Corus has been introduced. This featureis meant as a convenience, whereby the distributed management facility of Corus can be used todeploy files across multiple hosts at once.

When When files are deployed in such a manner,  Corus makes no attempt to determine whatthese files are about (it will not attempt, for example, that such a deployed file may consist of aCorus application distribution).

By default, such files are kept under the $CORUS_HOME/files/uploads directory. This locationis configurable,  by modifying   the  corus.server.uploads.dir  in   the   corus.propertiesconfiguration file (itself under $CORUS_HOME/config directory).

Deploying a File

To deploy a file, simply type the deploy command in the CLI, together with the -f option, whosevalue should be set to the path of the file to deploy.

deploy -f myArchive.zip

The -cluster option works its magic for this command also, triggering the deployment of the fileacross all hosts in the cluster.

deploy -f myArchive.zip -cluster

In addition the, the command also takes a -d option. The option can be used to provide a user­defined directory where the file is to be uploaded on the Corus node:

deploy -f myArchive.zip -d /opt/uploads

Listing the Deployed Files

To list the currently deployed files, use the ls command with the -f option:

ls -f -cluster

Note that this will only list the files present under Corus' uploads directory. If you have deployedfiles with the ­d option set to another directory, it will not be magically remembered by Corus.

Undeploying a File

To undeploy, just use undeploy, with the -f option also. Here are examples:

undeploy -f myArchive.zip

undeploy -f myArchive.zip -cluster

undeploy -f *.zip

64 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 65: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Similarly to the  ls  command, the files deployed to user­defined directories will  not be seen byCorus, and thus you will not be able to undeploy files from under such directories.

Repository

As of release 4.0, Corus has been enriched with a repository functionality: this allows some Corusnodes (configured as “repository clients") to synchronize their state with other nodes (which arethemselves configured as “repository servers"). 

Rationale

The functionality has been introduced in order to facilitate installation of new Corus nodes: newlyinstalled   nodes   configured   as   repository   clients   will   automatically   end   up   having   the   samedistributions, execution configurations, shell scripts, file uploads, port ranges, process properties,and tags, as the repository servers with which they synchronize themselves. 

In addition, the functionality proves handy when running Corus in the cloud: new Corus instancesconfigured as repo clients have their distributions automatically copied to them, and the applicationprocesses configured as part of these distributions may then be automatically launched.

Mechanism

The synchronization between repository clients and servers occurs when a repository client nodestarts up: upon appearing in the domain, it will detect which nodes in the domain act as repositoryservers. The repo client node will then notify the repo servers it has discovered that it wishes tosynchronize its state with them. 

Exchanges follow between the repo client and the repo servers, in the context of which the lattersend to the repo client their distributions, execution configurations, shell scripts, file uploads, portranges, process properties, and tags. Upon completion of this synchronization, a repo client nodeends up having the same state as the whole of its repo servers.

Synchronization is restricted to the domain (or cluster). That is: repo clients will not “see" reposervers outside of their own domain. For a given domain, it is recommended to have one reposerver node at the most, to make things simpler.

In addition to the synchronization of state, any execution configuration that has its startOnBootproperty   set   to  true  will   have   the   corresponding  processes   automatically   started  uponcompletion of the synchronization phase.

The   synchronization   mechanism   has   been   optimized   to   avoid   redundant   transfers   betweenrepository servers and clients: a client will request from the repo servers that it discovers whichartifacts (distributions, shell scripts, etc.) these have. It will compare these artifacts with the ones italready has, and only request from the  repo servers the artifacts it does not already have.

65 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 66: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Configuration

Enabling   the   repository   functionality,   is   done   through   configuration.   The       property   to   set   iscorus.server.repository.node.type  in   the  corus.properties  file   –   under   the$CORUS_HOME/config. It is by default set to none, meaning that the Corus instance will act asneither  a   respository   client  or   server  –  and   thus   that  will  will  not   take  part   in  any   repositoryinteraction. This is the default value.

To configure a Corus instance as a repo client, the value of the above property should be set toclient. To configure it as a server, it should be set to server.

Also,   in addition,  by default,   the push of  state   from servers   to clients  applies  by default   to allsynchronizable elements, that is: 

• distributions and execution configurations

• shell scripts

• file uploads

• port ranges

• process properties

• tags

• application keys

• security roles

It is possible to fine­tune both the push of synchronizable elements from servers to clients, and thepull of such elements by clients from servers.

Such   customization   as   been   introduced   in   order   to   guarantee   maximum   control   oversynchronization behavior. For example, it might be desirable to configure a repo client as havingthe pull of tags disabled, because one wishes to only run certain types of processes on that node.In this case then, one wants to make sure that only the tags for these processes will be set on thatnode, and none other.

Property  Description Defaultcorus.server.repository.node.type Indicates   the   repository   role   of   the   Corus

instance:• none: means that the Corus node will

not take part in repository operations.• client: means that the Corus node will

act as a repository client. • server: means that this Corus node will

act as a repository server. 

none

corus.server.repository.tags.push.enabled Indicates   if   the   push   of   tags   from   the   Corusinstance  is  enabled  (this  property   is   taken  intoaccount only if the Corus instance is configuredas a repository server).

true

corus.server.repository.properties.push.enabled Indicates if the push of process properties fromthe Corus  instance  is  enabled  (this  property   istaken into account only if  the Corus instance isconfigured as a repository server).

true

66 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 67: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

corus.server.repository.uploads.push.enabled Indicates   if   the   push   of   file   uploads   from   theCorus instance is enabled (this property is takeninto   account   only   if   the   Corus   instance   isconfigured as a repository server).

true

corus.server.repository.scripts.push.enabled Indicates   if   the   push   of   shell   scripts   from   theCorus instance is enabled (this property is takeninto   account   only   if   the   Corus   instance   isconfigured as a repository server).

true

corus.server.repository.port-ranges.push.enabled Indicates   if   the   push   of   port   ranges   from   theCorus instance is enabled (this property is takeninto   account   only   if   the   Corus   instance   isconfigured as a repository server).

true

corus.server.repository.security.push.enabled Indicates   if   the   push   of   security   roles   andapplication   keys   from   the   Corus   instance   isenabled (this property is taken into account only ifthe Corus instance is configured as a repositoryserver).

true

corus.server.repository.tags.pull.enabled Indicates if the pull of tags by the Corus instanceis  enabled   (this  property   is   taken   into  accountonly   if   the   Corus   instance   is   configured   as   arepository client).

true

corus.server.repository.properties.pull.enabled Indicates if the pull of process properties by theCorus instance is enabled (this property is takeninto   account   only   if   the   Corus   instance   isconfigured as a repository client).

true

corus.server.repository.uploads.pull.enabled Indicates if the pull of file uploads by the Corusinstance  is  enabled  (this  property   is   taken  intoaccount only if the Corus instance is configuredas a repository client).

true

corus.server.repository.scripts.pull.enabled Indicates if the pull of shell scripts by the Corusinstance  is  enabled  (this  property   is   taken  intoaccount only if the Corus instance is configuredas a repository client).

true

corus.server.repository.port-ranges.pull.enabled Indicates if the pull of port ranges by the Corusinstance  is  enabled  (this  property   is   taken  intoaccount only if the Corus instance is configuredas a repository client).

true

corus.server.repository.security.pull.enabled Indicates   if   the   pull   of   security   roles   andapplication   keys   from   the   Corus   instance   isenabled (this property is taken into account only ifthe Corus instance is configured as a repositoryclient).

true

Using the Pull Command

The  pull  command may be used to trigger the synchronization mechanism – automatic pull isdone at Corus startup only, and it must be explicitly triggered at other times. The pull command isonly executed by Corus nodes configured as repo clients (it will simply be ignored by others).

You can invoke the command from the Corus CLI. Just type:

pull

Or: 

67 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 68: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

pull -cluster

The command is used to force the synchronization of repo client nodes post startup.

Dynamic Repository Role Change

The repository role of a Corus instance (or of a whole cluster) can be dynamically modified, withouthaving to restart Corus. Here's an example:

cluster repo my-new-role -cluster

When the repository role of a Corus cluster is changed this way, Corus saves it in a file named.corus-readonly-<corus-server-port>.properties, under the $HOME/.corus directory(where  $HOME  corresponds   to   the   home  directory  of   the   user  under   which   the  Corus   serverprocess runs, and  <corus-server-port> to the port of the current Corus instance).

Corus  always   looks   for   the presence  of   that   file  at  startup,  and  the properties   it   contains  willsupplement/override all other server properties.

As its name implies, this file should not be manually edited by system administrators.

Discovery with Avis

If your network does not support IP multicast, then you may use Avis (http://avis.sourceforge.net/)as a discovery mechanism. This means you must setup an Avis router (or multiple federated ones),and configure your Corus instances as clients of this router.

The properties you have to configure to enable Avis­based discovery are the following:

ubik.rmi.naming.broadcast.provider=ubik.rmi.naming.broadcast.avis

ubik.rmi.naming.broadcast.avis.url=elvin://<host>:<port>

As indicated, in the last property, you must provide the host and port of the Avis router to which toconnect. 

Please consult   the Avis  documentation   for  more  details  about  setting up Avis  and the URLformat it mandates.

Port Management

Corus   has   a   port   management   feature   allowing   the   specification   of   so­called   “port   ranges".Network ports belonging to these ranges are leased to started processes and “recuperated" upon

68 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 69: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

process termination – in order to be leased to other processes.

This  feature was  implemented as a workaround that  can pose a configuration challenge whendealing with distributed applications that must run on a well­known port (a port known by the client,not a dynamic one that is abstracted by a naming service).

Since ports on a given host  cannot be shared, applications using static ports must  have themexplicitly   configured,   which   quickly   becomes   burdensome   when   dealing   with   multiple   runninginstances of applications performing the same service.

Hence the Corus port management feature, which works as follows:

• The administrator  creates port   ranges (with  a minimum and a maximum port)   that  aregiven a unique name.

• As part of the corus.xml file, if a process requires a port, then a corresponding port XMLelement should appear for that process' configuration. The element takes a name attributewhose value must correspond to the name of  a configured port range.

• Upon process start­up,   the Corus server  remove an available  port   from the range thatmatches the port specified as part of the process configuration (Corus keeps a an internallist of leased and available ports for every configured port range).

• The acquire port is “passed" to the process as a system property (through the command­line that starts the process). The system property format is given below:

-Dcorus.process.port.<range_name>=<port>

• That property can then be recuperated by the started process from application code.

The   port   manager   built   within   Corus   can   be   administered   through   the   Corus   command­lineinterface (type man ports at the command­line for more information).

The configuration snippet below shows how a port is configured; of course multiple port elementscan be configured for each process element.

<distribution xmlns="http://www.sapia-oss.org/xsd/corus/distribution-4.8.xsd" name="demo" version="1.0">

<process name="echoServer" maxKillRetry="3" shutdownTimeout="30000" invoke="true">

<port name="test" /> <magnet magnetFile="echoServerMagnet.xml" profile="test" vmType="server"> <xoption name="ms" value="16M" /> </magnet> </process> </distribution>

REST API

As of version 4.5, Corus offers a rich REST API, allowing for fine­grained automation.As a convenience, the API documentation can be found online: http://www.sapia­oss.org/projects/corus/rest.html.

69 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 70: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Syslog Integration

It is possible to redirect the Corus server's internal task manager output to a Syslog daemon (theSyslog4j library is used to that end – see http://syslog4j.org/).

To   activate   integration   with   Syslog,   the   following   properties   must   be   confured   in   the$CORUS_HOME/config/corus.properties  file   (see   the  Corus   Configuration   Propertiessection):

• corus.server.syslog.protocol

• corus.server.syslog.host 

• corus.server.syslog.port

Here is an example configuration:

corus.server.syslog.protocol=udp

corus.server.syslog.host=localhost

corus.server.syslog.port=5555

HTTP Extensions

Corus provides a mechanism dubbed “HTTP extensions" that allows various internal services toprovide remote access over  HTTP.  The extensions are accessed through HTTP,  at predefinedURIs (each extension as an exclusive context path). The URL format to have access to a HTTPextension is as follows:http://<corus_server_host>:<corus_server_port>/<extension_context_path>/...

Corus currenlty supports many convenient extensions, of which certain provide XML output, andare meant first and foremost for integration into monitoring infrastructures. The Corus home pageis available at the following URL:http://<corus_server_host>:<corus_server_port>/

This displays a HTML page describing the various extensions, and their respective URIs. Theseextensions explained in the next sub­sections.

File System

The file system extension is bound under the files context path. This extension simply serves thefiles  under  $CORUS_HOME  over  HTTP  (meaning   that   the  Corus  home directory  serves  as   thedocument root).

The extension is accessed as follows:

70 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 71: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

http://<corus_server_host>:<corus_server_port>/files/

Any additional data after the context path (excluding the query string) is interpreted as the path to afile or directory under the document root.

Note that the trailing slash character (/) at the end of the URI is mandatory for proper access todirectories.

JMX

The JMX extension (available under the  jmx  context path) provides status information gatheredfrom the plattorm MBeans of the Corus VM. The resulting XML output is provided as follows:<vmStatus> <attribute name="runtime.startTime" value="1180649263641"/> <attribute name="runtime.startDate" value="Thu May 31 18:07:43 EDT 2007"/> <attribute name="runtime.upTime" value="7961"/></vmStatus>

Of  course  more  data   than   illustrated  above   is  provided.  The   format  can  easily  be  parsed  bymonitoring scripts. The goal of the JMX extension is indeed to allow remote monitoring by systemadministrators.

The JMX extension is accessed as follows:

http://<corus_server_host>:<corus_server_port>/jmx

Deployer

The Deployer is the internal module that manages the distributions deployed in Corus. It offers anextension that displays the currenlty deployed distributions (such as when using the ls commandin the CLI). It can be accessed through the following:http://<corus_server_host>:<corus_server_port>/deployer/ls

In addition, query string parameters can be used to filter the result (the parameters correspond tothe options available for the ls command in the CLI), as the examples below illustrate:http://<corus_server_host>:<corus_server_port>/deployer/ls?d=demo

http://<corus_server_host>:<corus_server_port>/deployer/ls?d=demo&v=1.0

http://<corus_server_host>:<corus_server_port>/deployer/ls?d=demo&v=1.*

As showed in the last URL, pattern matching is supported.

Processor

The Processor is the internal module that manages the processes that have been started throughCorus. It provides an extension that allows viewing these processes and their respective status,mirroring the functionality of the ps and status command in the CLI. Two URIs are supported bythe deployer extension, one displaying running processes, the other displaying their status. TheseURIs are the following, respectively:

71 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 72: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

http://<corus_server_host>:<corus_server_port>/processor/ps

http://<corus_server_host>:<corus_server_port>/processor/status

Both of these URIs support query string parameters corresponding to the options available throughthe ps and status commands in the CLI.http://<corus_server_host>:<corus_server_port>/processor/ps?d=demo&v=1.0&p=prod

http://<corus_server_host>:<corus_server_port>/processor/ps?d=demo&v=1.*&p=prod

http://<corus_server_host>:<corus_server_port>/processor/status?i=1178989398

As can be observed, pattern matching is supported.

Alerts

Corus can be configured to send email alerts in three situations:

1. When it restarts an unresponsive process.

2. When a new distribution is deployed.

3. When a distribution is undeployed.

For this feature to be enabled, the following must be configured (in the corus.properties file):

• The corus.server.alert.enabled property must be set to true.

• The  corus.server.alert.recipients  property must correspond to list of recipients(email addresses) separated by a semicolon.

In addition, you should make sure that the following properties are properly configured (defaultsare used which may be unsuitable for your setup):

• corus.server.alert.smtp.host: defaults to localhost.

• corus.server.alert.smtp.port: defaults to 25.

• corus.server.alert.smtp.password: empty by default.

• corus.server.alert.sender: a default one is constructed using the SMTP host.

The corus.properties file that comes with Corus has complementary explanations regardingthose properties.

Java Processes

As was mentioned earlier,  Corus allows starting any type of process (provided it   interacts withCorus   according   to   the   Corus   interoperability   specification   –  http://www.sapia­

72 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 73: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

oss.org/projects/corus/CorusInterop.pdf). As far as Java processes are concerned, there are a fewthings to know...

Corus Interoperability Specification in Java

The Corus   interop  spec   implementation   in  Java   is  another  Sapia  project.  The   implementationconsists   of   a   small   .jar   file   named  sapia_corus_iop.jar.  That   library   consists  of  a   smallXML/HTTP client (as required by the spec).

When executing Java VMs from Corus, that library is “placed" in Magnet's classpath.   The libraryis made “invisible" to your applications since it is not placed at the level of the system classloader,but at the level of a classloader that is a child of the system classloader.  

The Java interop implementation detects that it has been started by a Corus server by looking upthe system properties; if it finds a value for the corus.process.id property, then it determinesthat it should poll the corresponding Corus server. In order to do so, it needs the host/port on whichthe   Corus   server   is   listening,   which   it   acquires   through   the  corus.server.host  andcorus.server.port system properties. Using the values specified through these properties, theCorus interop instance connects to the Corus server and starts the polling process.

Troubleshooting

In order to facilitate troubleshooting, the Java interop client creates the following files under theprocess directory:

• stdout.txt

• stderr.txt

These   files   hold   the   output   resulting   from   the   redirection   of   the  java.lang.System.out  andjava.lang.System.err output streams.

In addition, when a Corus server starts a process, it logs that process' initial output to the givenprocess' directory, in the following file:

• process.out

In the case of Java processes, this allows tracking errors that have occurred before the Magnetruntime could be loaded.

Interacting with Corus from Java

Java applications can interact with Corus to:

• Request a process restart or shutdown.

• Be notified upon shutdown.

• Transmit status information.

• Receive process configuration updates from the Corus server (a functionality dubbed "hotconfig").

73 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 74: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Dependency

In   all   cases,   to   interact   with   Corus   from   your   applications,   you   will   need   thesapia_corus_iop_api.jar  library   in   your   classpath.   This   library   can   be   configured   as   adependency, as part of your Maven build, as such:<dependency> <groupId>org.sapia</groupId> <artifactId>sapia_corus_iop_api</artifactId> <version>2.8.2</version> </dependency>

The API provided by the library allows you to hook your application to the lifecycle of the JVM, asit's managed by Corus.

Triggering a Restart

An application can request a JVM restart with code such as the following:import org.sapia.corus.interop.api.InteropLink;InteropLink.getImpl().restart();

Triggering a Shutdown

An application can request a JVM shutdown as follows:import org.sapia.corus.interop.api.InteropLink;InteropLink.getImpl().shutdown();

Registering a Shutdown Listener

You   can   register   a  org.sapia.corus.interop.api.ShutdownListener  in   order   to   benotified of a JVM shutdown originating from Corus:import org.sapia.corus.interop.api.InteropLink;import org.sapia.corus.interop.api.ShutdownListener;

public class MyListener implements ShutdownListener {

public void onShutdown() { ... }

}

ShutdownListener listener = new MyListener();InteropLink.getImpl().addShutdownListener(listener);

Note that ShutdownListeners are internally kept as java.lang.ref.SoftReference instances, soit is important that you keep a hard reference on any such listener in your application.

Producing Status Data

It is possible for applications to publish status information through Corus. That information will beviewable   through   Corus'  status  command,   or   through   the   status   HTTP   Extension   (see   thesection on HTTP extensions for more details about that specific extension).

In order to publish status information, you must register a StatusRequestListener:import org.sapia.corus.interop.api.InteropLink;import org.sapia.corus.interop.Status;import org.sapia.corus.interop.api.StatusRequestListener;

public class MyListener implements StatusRequestListener {

74 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 75: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

public void onStatus(Status status) { ... }

}

StatusRequestListener listener = new MyListener();InteropLink.getImpl().addStatusRequestListener(listener);

Since listeners are kept as SoftRerences, you must keep a hard reference on them in your code.

The listener will  be invoked periodically (at the interval at which the process will  poll the Corusserver). It will be passed a Status instance, to which the listener can then add status information,as follows:public void onStatus(Status status) { Context context = new Context("org.sapia.corus.sample.jetty"); context.addParam(createParam("dispatched", stats.getDispatched())); context.addParam(createParam("dispatchedActive", stats.getDispatchedActive())); context.addParam(createParam("dispatchedActiveMax", stats.getDispatchedActiveMax())); context.addParam(createParam("dispatchedTimeMax", stats.getDispatchedTimeMax())); context.addParam(createParam("dispatchedTimeTotal", stats.getDispatchedTimeTotal())); context.addParam(createParam("dispatchedTimeMean", stats.getDispatchedTimeMean())); context.addParam(createParam("requests", stats.getRequests())); context.addParam(createParam("requestsActive", stats.getRequestsActive())); context.addParam(createParam("requestsActiveMax", stats.getRequestsActiveMax())); context.addParam(createParam("requestsTimeMax", stats.getRequestTimeMax())); context.addParam(createParam("requestsTimeMean", stats.getRequestTimeMean())); context.addParam(createParam("requestsTimeTotal", stats.getRequestTimeTotal())); context.addParam(createParam("suspends", stats.getSuspends())); context.addParam(createParam("suspendsActive", stats.getSuspendsActive())); context.addParam(createParam("suspendsActiveMax", stats.getSuspendsActiveMax())); status.addContext(context); }

In the above code, the listener creates a Context instance, adding status parameters to it. Lastly,the Context is added to the Status instance that's passed in. 

Hot Config

It is possible for applications to be notified of configuration changes that occur on the Corus serverside,  more  precisely:  when process  properties  are updated/added/removed,  either   through  theCLI's conf add command, or through the REST API.

For Java applications, the interop client allows registering a  ConfigurationChangeListenerfor intercepting so­called "configuration events". The interface's signature is as follows:public interface ConfigurationChangeListener { public void onConfigurationChange(ConfigurationEvent event);

}

A ConfigurationEvent encapsulates  Param objects, each in fact corresponding to a processproperty   that's   been   either   added   or   removed.   The   event   also   has   a  getType()  method,indicating   the type of operation (add, update, delete) that caused the event. The return value ofthe method can be one of the following:

• "update": indicates that the property has been added to Corus, or updated.

• "delete": indicates that the property has been removed from Corus.

To register your listener, proceed as follows:InteropLink.getImpl().add(new ConfigurationChangeListener() {

75 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 76: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

public void onConfigurationChange(ConfigurationEvent event) { log.debug("Received config change: {}", event.getType()); Map<String, String> properties = event.toMap() // you can also iterate through the Params: for(Param p : event.getParams()) { if (event.getType().equals(ConfigurationEvent.TYPE_UPDATE)) { log.debug("Property {} was added/modified", p.getName()); } else { log.debug("Property {} was deleted", p.getName()); } } }});

The “Ripple" Functionality

When domains (or clusters) have many hosts, it may be impractical to perform some operations onall these hosts at once. We're thinking about the restart of   processes, or the deployment of newdistributions,   for  example:   in  such  cases,   it   involves  performing  a  shutdown  of  all  applicationprocesses at the same time, which is something that obviously should be avoided in the context of24/7 live traffic operations: losing the processing power of, say, 10 hosts at once is probably notdesirable.

As of the 4.1 release, there exists a feature in Corus which allows applying commands gradually toa whole cluster. The feature as been dubbed “rippling",     for it implies a kind of ripple effect, ascommands are applied to successive cluster subsets, until the whole cluster has been touched.

The feature is supported through the ripple command, which allows:

• Applying a single (or “a few") command to the cluster, to a given number of nodes at atime;

• applying multiple commands (specified in a Corus script), to a given number of nodes at atime.

Common Options

The command takes options that are common to both usage types:

• b:   the batch  size  –   that   is,   the number  of  nodes at  a   time   to  which   rippling   is   to  beperformed.

• m: the minimum number of nodes required in the cluster for the specified batch size to beapplied (defaults to 1).

The ­m option is provided in order to ensure that the specified batch size will not defeat the intent ofthe command: say for example you have a cluster of 3 nodes, and you specify a batch size of 3: allnodes will then be impacted at the same time.

76 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 77: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Ripple with a Single or a Few Commands

The command allows rippling one or a few commands, which must be specified with the ­c option,as shown below:

ripple -b 2 –c "restart all -w | pause 45"

The commands must be enclosed in quotes.  In the above example, the restart is applied to thewhole cluster 2 nodes at a time. 

As the example above shows, the option allows specifying multiple successive commands: in thiscase, these must be separated by the pipe (“|") character.

In the above example, it makes sense to pause for a given amount of seconds prior to moving onto   the   next   batch   of   nodes:   the   intent   is   obviously   to   give   time   to   the   applications   to   bootcompletely.

Ripple with a Corus Script

Typically, a deployment procedure involves many steps, and therefore many commands. It is moreconvenient, in such contexts, to use a script. The ripple command supports a  ­s  option, whosevalue must correspond to the path of the script to execute.

Here's an example of such a script:kill all -w -clusterundeploy all -clusterdeloy myapp-*.zip -clusterexec -e myapp -w -clusterpause 45

As you can see, the script is not different than one you would normally write in a non­ripple context.The only difference here is that when the -cluster option is specified, clustering will be targetedto the batch of hosts as currently determined by the ripple logic: the -cluster option is “hijacked"by the ripple command and made to correspond to the current batch of nodes that are targeted.

Here's how invocation of the command would look like:

ripple -s deployment.txt -b 2 

So the above means that the deployment script would be executed on 2 nodes at a time. Given thescript's contents, a pause of 45 seconds would be observed at the end of each script invocation(giving time to the applications to start up). Of course, the given pause is completely arbitrary andhas been provided for the sake of  providing a concise example.

Cloud Integration

As of 4.1, Corus supports “cloud integration", that is: a Corus instance can be configured through

77 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 78: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

“user data", which makes it easy to start Corus nodes and assign to them configuration parametersdynamically.

Namely, what will need per­instance configuration are typically the following:

• The domain name of the Corus node being started.

• The  group  configuration  parameters   (since   IP  multicast   is  usually  not  available   in   theCloud, usage of Avis must be configured – see the  Discovery with Avis section for moredetails).

A preferred way to deploy Corus in the cloud is to configure an instance as a repository server (seethe  Repository  section for more details),  and the others as repository clients: newly appearingrepo clients will thus automatically synchronize themselves with the repo server instance at startup(repo client instances could be “elastic" ones, automatically launched by the cloud provider).

The advantage of using Corus in the cloud in such  a manner is that you only need configuring asingle machine image with a Corus installation, and decide thereafter, through custom user dataconfiguration, what their actual startup parameters will be.

Corus expects user data to be available at a predefined URL. In the case of AWS for example,user data can be fetched from the following:

http://169.254.169.254/latest/user-data

The content that is available at that endpoint is configurable through the AWS admin tools.

Corus, for its part, expects a JSON document corresponding to the following structure:{ "corus": { "server": { "properties": [ { "name": "corus.server.domain", "value": "prod-01" }, { "name": "ubik.rmi.naming.broadcast.provider", "value": "ubik.rmi.naming.broadcast.avis " }, { "name": "ubik.rmi.naming.broadcast.avis.url", "value": "elvin://10.0.1.11" }, ], "tags": [ "scheduler", "read-write"] }, "processes" : {

"properties": [ { "name": "jdbc.connections.max", "value": "50" } ] } } }

78 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 79: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

The above shows that the following can be configured:

• Corus server configuration properties

• Corus server tags

• Process properties

In order for the fetching of user data to be enabled, the ­u option must be specified as part of theCorus server command­line. If you start Corus as a daemon process, this involves either modifyingthe Corus configuration for the Java Service Wrapper, or the Corus  init.d script (if you're notusing the Java Service Wrapper).

Note that the -u option does not have to have a value. In such a case, Corus will  attempt fetchthe user data JSON document from the following endpoints by default (in the specified order):

http://169.254.169.254/latest/user-datahttp://169.254.169.254/openstack/latest/user-data

The first endpoint corresponds to AWS' user data endpoint, the second to Open Stack's.

Modifying the JSW Configuration

If   you're   starting   Corus   with   the   Java   Service   Wrapper,   you   have   to   modify   yourcorus.service.wrapper.properties  file. The file  holds configuration parameters  that areused  to  configure  command­line  arguments  and  options   that  are  passed   to   the  Corus  servercommand­line. Look for the section corresponding to the following parameters:wrapper.app.parameter.1=-c wrapper.app.parameter.2=%CORUS_CONFIG_FILE% wrapper.app.parameter.3=-v wrapper.app.parameter.4=INFO wrapper.app.parameter.5=-f

Add the following parameter:wrapper.app.parameter.6=-u

If   you  want   to  explicitly  specify   the  enpoint   from which   to   fetch  user  data,  add   it  as  anotherparameter. For example:wrapper.app.parameter.6=-uwrapper.app.parameter.7=http://169.254.169.254/latest/user-data

Modifying the init.d Script

If you're not using the Java Service Wrapper, but are rather using the plain­vanilla init.d script that'sprovided as part of the Corus distribution, then modify it by adding the -u option to the javaArgsparameter:javaArgs="-Dcorus_instance=$javaCommandLineKeyword $CORUS_OPTS -cp $CLASSPATH org.sapia.corus.core.CorusServer -p $CORUS_PORT -v $CORUS_LOG_LEVEL -f $serviceLogDir -u"

79 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 80: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Or if you want to specify the URL explicitly:javaArgs="-Dcorus_instance=$javaCommandLineKeyword $CORUS_OPTS -cp $CLASSPATH org.sapia.corus.core.CorusServer -p $CORUS_PORT -v $CORUS_LOG_LEVEL -f $serviceLogDir -u http://169.254.169.254/latest/user-data"

Maven

Corus comes with a Maven plugin, which allows running Corus scripts as part of Maven builds.Here's a sample configuration:<plugin> <groupId>org.sapia</groupId> <artifactId>sapia_corus_mvn_plugin</artifactId> <version>4.1</version> <executions> <execution> <id>deploy-to-dev</id> <goals> <goal>run</goal> </goals> <configuration> <scriptProperties> <env>dev</env> </scriptProperties> <host>172.31.1.2</host> <port>33000</port> <scriptFile>${project.basedir}/scripts/deploy-V1.txt</scriptFile> </configuration> </execution> </executions> </plugin>

The plugin takes the following configuration elements:

• scriptProperties: optional key/value pairs that are passed to scripts in the context ofvariable substitution.

• host:   the   host   of   the   Corus   daemon   against   which   the   script   should   be   executed(Mandatory).

• port: the port of the Corus daemon against which the script should be executed (Optional:defaults to 33000).

Corus scripts  are passed the properties  that  are  optionally  specified as a)  part  of   the plugin'sscriptProperties  element;  b)   those of  your  Maven build  (defined  in  properties  elementeither in your POM or in your Maven settings; and c) the following Maven project properties: 

• project.id        

• project.description 

• project.name        

• project.groupId 

• project.artifactId 

• project.version 

• project.inceptionYear 

80 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 81: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

• project.basedir or project.baseDir 

• project.build.finalName          

• project.build.directory 

• project.build.sourceDirectory 

• project.build.scriptSourceDirectory

Scripts executed from the plugin have access to all the properties mentioned above (as well assystem properties) using the following notation: 

${<property_name>}

For example, here's a script that would correspond to usage of the sample plugin configurationabove: kill -d * -v * -p ${dev} -w undeploy -d * -v * deploy ${project.build.directory}/*-${project.version}.zip

External Discovery

External discovery is about third­party party applications being able to discover Corus instancespresent on the network, and potentially act remotely on them ­ through the REST API for example.This becomes handy in the context of large scale deployments: statically hard­coding the addressof Corus nodes in configuration files for some monitoring application to consume (for example) issimply not practical.

Consul

As of release 4.6, Corus supports publishing its presence to Consul as a service (http://www.consul.io/docs/agent/services.html), using Consul's REST API (see: http://www.consul.io/docs/agent/http.html). 

The topology typically goes as follows: a Consul agent (a separate process) runs on each machine, and receives service registrations from processes on that machine. The agent is hooked to a set of centralized Consul servers, which in turn makes service information available to applications.

Service Definition

Given the above, a Consul agent would run on each machine where Corus itself runs, and each Corus instance would publish its service description to its "local" Consul agent . The service definition registered with Consul for a Corus instance has the following format:{

"ID", "corus-<corus_host_name>:<corus_port>",

81 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 82: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

"Name": "Corus",

"Tags": [ "<corus_domain>" ],

"Address": "<corus_ip_address>",

"Port": "33000",

"Checks": [

{

"id": "check-corus-<corus_host_name>:<corus_port>",

"name": "Health check for Corus node at: <corus_host_name>:<corus_port>",

"ttl" : <ttl_seconds>

}

]

}

The placeholders between angled brackets correspond to values that are set contextually. Theyare described below:

• corus_host_name: the host name of the Corus instance.

• corus_port: the port of the Corus instance.

• corus_domain: the domain to which the Corus instance corresponds.

• corus_ip_address: the IP address of the Corus instance.

• ttl_seconds: the number of seconds for which to keep the service definition before it isdiscarded   (this   value   is   configured   in  corus.properties,   as   explained   in   the   nextsubsection).

Configuration

There are different configuration properties to define in $CORUS_HOME/config/corus.properties for activating the integration with Consul.

It   is   important   to  note  that  a Corus   instance   is   responsible   for   refreshing   its  service  definitionperiodically, since that definition must be assigned a time­to­live ­ Consul will remove all definitionsthat have not been refreshed within that given time­to­live.

The following properties are used to define how Corus interacts with Consul:

Property Description

corus.server.pub.consul.enabled Enables or disables Consul integration (false by default).

corus.server.pub.consul.agent-url The URL of   the  Consul  agent   to  connect   to   (in  a  standardsetup, on the same machine as the Corus instance (defaultsto: http://localhost:8500).

corus.server.pub.consul.interval The   interval   at   which   the   Corus   instance   republishes   itsservice definition to Consul (defaults to 30 seconds).

corus.server.pub.consul.ttl The time­to­live assigned to the service definition (defaults to45 seconds). That value should be greater than the publicationinterval (set by the above property).

82 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 83: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

83 / 84                                                                                                                          © sapia­oss.org 2002­2015

Page 84: The Corus Guide · 2015. 9. 18. · Y.D Added Corus 4.1.2 documentation: • New conf merge command supported by the CLI. • New preExec and cmd elements in the Corus descriptor,

Conclusion

Corus is an infrastructure that allows centrally managing application processes collectively, acrossmultiple nodes. It offers a low­cost, non­intrusive way to distribute applications on a large scale.

For   additional   and   complementary   information,   see   the   Corus   web   site   (http://www.sapia­oss.org/projects/corus/index.html),

84 / 84                                                                                                                          © sapia­oss.org 2002­2015