Enterprise Java

KivaKit deployments

KivaKit applications can be configured using the settings api, but there is an easier way to configure an application for deployment built right into Application. By default, Application looks for the switch -deployment=[deployment-name]. If the switch is present and deployment settings can be found, KivaKit will load all of the settings objects in the named deployment into the global settings store, where they can be accessed with require().

Deployments can be packaged into a shaded jar file, so that usage of the application is very simple for an operations team:

java -jar my-application.jar -deployment=local

To discover what packaged deployments are available, KivaKit looks in the deployments package next to the application class. Each sub-package in the deployments package is then a deployment, where the name of the deployment is the name of the package. A deployment description is contained in a file in the package named Deployment.metadata. The deployment package also contains a set of one or more .properties files. Each settings file describes a settings object, as described in components and settings.

└── MyApplication.java
└── deployments
    ├── local
    │   ├── Deployment.metadata
    │   └── Database.properties
    ├── development
    │   ├── Deployment.metadata
    │   └── Database.properties
    ├── staging
    │   ├── Deployment.metadata
    │   └── Database.properties
    └── production
        ├── Deployment.metadata
        └── Database.properties

It is very convenient to package up settings information in a .jar file in this way. To support external configuration, the KIVAKIT_DEPLOYMENTS_FOLDER system property can also be used to specify a deployment folder to load settings from, as in:

java -jar my-application.jar -DKIVAKIT_DEPLOYMENT_FOLDER=$HOME/my-application/deployments/local

If a deployments package or external folder is found containing deployments, the -deployment switch is required. Failing to select a deployment will produce a usage message similar to:

┏--------- COMMAND LINE ERROR(S) ---------------
┋     ○ Required switch -deployment not found
┗-----------------------------------------------

KivaKit 1.1.0 (beryllium alpaca)

Usage: MyApplication 1.1.0 <switches> <arguments>

This is my application.

Arguments:

  <none>

Switches:

  Required:

  -deployment=Deployment (required) : The deployment configuration to run

    ○ local - Run on localhost
    ○ development - Run on development cluster
    ○ staging - Run on staging cluster
    ○ production - Run in production environment
  
  Optional:

  -port=Integer (optional) : The port to use

If no deployments are available, the -deployment switch is not added to the application command line parser and cannot be used.

Code

The deployment configuration code that we’ve discussed here is available in the kivakit-configuration module in KivaKit.

<dependency>
    <groupId>com.telenav.kivakit</groupId>
    <artifactId>kivakit-configuration</artifactId>
    <version>${kivakit.version}</version>
</dependency>

Published on Java Code Geeks with permission by Jonathan Locke, partner at our JCG program. See the original article here: KivaKit deployments

Opinions expressed by Java Code Geeks contributors are their own.

Jonathan Locke

Jonathan has been working with Java since 1996, and he was a member of the Sun Microsystems Java Team. As an open source author, he is originator of the Apache Wicket web framework (https://wicket.apache.org), as well as KivaKit (https://www.kivakit.org, @OpenKivaKit) and Lexakai (a tool for producing UML diagrams and Markdown indexes from Java source code, available at https://www.lexakai.org, @OpenLexakai). Jonathan works as a Principal Software Architect at Telenav (https://www.telenav.com), and in the future, Telenav will release further toolkit designed and led by Jonathan called MesaKit, focused on map analysis and navigation.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button