This library provides a wrapper for odo which is a CLI tool for developers who are writing, building and deploying applications on Openshift. With Odo, developers get an opinionated CLI tool that supports fast, iterative development which abstracts away Kubernetes and OpenShift concepts, thus allowing them to focus on what’s most important to them: code.
Odo-java is composed of a core
module which is the front interface to execute Odo commands.
All integrators should use this interface as its base to call Odo from Java.
For example, Odo Maven Plugin integrates Odo into Maven by using the core
module.
Currently, Odo-Java is released in bintray, so you need to add that repository. This will change in the future.
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-jshiftio-jshift</id>
<name>bintray</name>
<url>https://dl.bintray.com/jshiftio/jshift</url>
</repository>
</repositories>
Core module acts as an interface between Java and Odo.
To install it you need to add next dependency:
<dependency>
<groupId>io.jshift</groupId>
<artifactId>odo-java-core</artifactId>
<version>${project.version}</version>
</dependency>
Odo-java does not assume where Odo tool is installed, so you need to provide the location of Odo home. But you can skip this step if you add next dependency:
<dependency>
<groupId>io.jshift</groupId>
<artifactId>odo-binary</artifactId>
<version>${project.version}</version>
</dependency>
If you do this, Odo will be automatically installed and you’ll be ready to use Odo-java without having to install Odo manually nor setting the Odo home directory. Moreover, adding this dependency you ensure that the version of Odo works with the version of Odo-java and you don’t get any incompatibility problems.
Assuming that you have odo-binary
in classpath.
-
Create Odo instance:
final Odo odo = new Odo();
-
Create application, add a component of type
nodejs
to your application:
odo.create("nodejs").build().execute(projectDirectory);
-
Deploy your application :
odo.push().build().execute(projectDirectory);
-
Expose your application endpoint :
odo.createUrl().withPort(8080).build().execute(projectDirectory);
And the same approach can be used with any other Odo operation like link, storage, …
Tip
|
If you are running Odo-java in the same directory as the project you want to manage, it is not necessary you set the projectDirectory .
|
Odo-java has a module called detectors
which scans a given Java project and apply automatically Odo commands to deploy the application.
Basically detectors work in two directions, in creating a component of our service definition and in starting the required services.
To install it you need to add next dependency:
<dependency>
<groupId>io.jshift</groupId>
<artifactId>detectors</artifactId>
<version>${project.version}</version>
</dependency>
Detectors will scan the current project and create a component with it.
If the project is of type JAR
, then openjdk
image is used.
If the project is of type WAR
, then wildfly
image is used.
Detectors scans dependencies of your project and creates the required services and link them to your component automatically.
Services that are now supported to be auto-detected and started are MySQL and PostgreSQL.
Moreover, it reads database configuration (username, password and database name) and starts the service with give configuration. Configuration files supported are:
-
JPA::
persistence.xml
-
Spring Boot::
application.properties
,application.y[a]ml
-
Quarkus::
application.properties
Odo-java also has a Maven plugin so you can use Odo as a Maven plugin.
To use it you need to register in plugins
section:
<plugin> <groupId>io.jshift.odo</groupId> <artifactId>odo-maven-plugin</artifactId> <version>${project.version}</version> <configuration> </configuration> <dependencies> <dependency> <groupId>io.jshift.odo</groupId> <artifactId>odo-binary</artifactId> <version>${project.version}</version> </dependency> </dependencies> </plugin>
Any command that is available in Odo, is also mapped as Maven goal in the next form, odo:<operation>
.
For example to create a new component, you’d usually do odo create component
, doing the same but in Maven plugin, you’d do mvn odo:create-component
.
And in similar way for creating a link mvn odo:link-component
or to expose a URL mvn odo:create-url
.
Also, every configuration parameter of Odo can be set as plugin configuration.
The first thing to do is put inside configuration
tag, a parent tag identifying the command name, which is the same as component name but in camel case.
For example to configure mvn odo:create-component
call you need to create a parent element called <createComponent>
.
<plugin>
<groupId>io.jshift.odo</groupId>
<artifactId>odo-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<createComponent>
....
</createComponent>
</configuration>
<dependencies>
<dependency>
<groupId>io.jshift.odo</groupId>
<artifactId>odo-binary</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
And parameters name are almost the same as in Odo commands but following Java conventions. The best way to know the real name parameters for each command is inspecting the Java command classes directly: https://github.com/jshiftio/odo-java/tree/master/core/src/main/java/io/jshift/odo/core/commands
For example in case of createComponent
:
<plugin>
<groupId>io.jshift.odo</groupId>
<artifactId>odo-maven-plugin</artifactId>
<version>${project.version}</version>
<configuration>
<createComponent>
<maxMemory>2</maxMemory>
</createComponent>
</configuration>
<dependencies>
<dependency>
<groupId>io.jshift.odo</groupId>
<artifactId>odo-binary</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>