Have You Tried the MicroProfile Starter Yet?

The SPRING INITIALIZR at https://start.spring.io has been around for a while and is the best way to bootstrap a new Spring Boot application.

So far, there hasn’t been a similar way to bootstrap a new MicroProfile project even if the different vendors have provided starters for their implementations. But the wait is over! The MicroProfile Starter is currently in “Beta”, but works like a charm. Just navigate to https://start.microprofile.io and start generating.

https://start.microprofile.io

Based on which version of MicroProfile you select, you will get the available implementations that supports that particular version. You have the option of generating examples for the specifications included in the selected version. This is an excellent way to learn how the different technologies work.

Amazon Corretto 8

UPDATE! I have updated the option of running Corretto in Docker to using the amazoncorretto Docker image available from Docker Hub.

Amazon Corretto is a production-ready distribution of OpenJDK with long-term support including performance- and security updates provided by Amazon.

Tweet announcing Amazon Coretto 8

Amazon provides installation packages and instructions for Linux, Windows, and macOS, as well as a Docker. The latest installation package is based on OpenJDK version 1.8.0_202:

$ java -version
openjdk version "1.8.0_202"
OpenJDK Runtime Environment Corretto-8.202.08.2 (build 1.8.0_202-b08)
OpenJDK 64-Bit Server VM Corretto-8.202.08.2 (build 25.202-b08, mixed mode)
$

If you don’t want to, or isn’t able to install Corretto on your workstation, t is pretty straightforward to try it out using Docker:

$docker run -it amazoncorretto

bash-4.2# java -version
openjdk version "1.8.0_202"
OpenJDK Runtime Environment Corretto-8.202.08.1 (build 1.8.0_202-b08)
OpenJDK 64-Bit Server VM Corretto-8.202.08.1 (build 25.202-b08, mixed mode)

bash-4.2#

Amazon Corretto is licensed under the same license as OpenJDK (GPLv2 with CPE) and there are no costs associated with using it. Amazon will provide quarterly security updates to Corretto 8 at least until June 2023.

But Java 8 is sooo old!

Relax, Amazon plans to make Corretto 11 available during the first half of 2019. Corretto 11 will be based on OpenJDK 11.

A First Look at Oracle Functions

I am super happy to have gotten the opportunity to test out Oracle Functions through the Cloud Native Limited Availability Program. When I last tried out running serverless functions in Oracle Cloud during the Oracle Groundbreaker APAC Tour last year, there were two options available. Either run my own Fn server in a virtual machine or set it up in a managed Kubernetes cluster. Now, a third option is available!

Oracle Functions is built on Oracle Cloud Infrastructure (OCI) and offer a managed environment for the Fn project. This means that you don’t have to manually manage an Fn cluster yourself. It also means that any function that runs on Oracle Functions will also run on any Fn server, something that offers you full flexibility.

The Fn project supports functions written in Go, Java, Node.js, Python or Ruby. The fn-duke function that I am using in this test is, of course, written in Java.

package eu.agilejava.fn;

public class HelloFunction {

    public String handleRequest(String input) {
        String configuredName = System.getenv("name");
        String name = (input == null || input.isEmpty()) ? configuredName  : input;
        return "Hello, " + name + "\n";
    }
}

Deployment is done by pointing to the Function Application you want your function to be part of.

fn deploy --app FunctionDuke

The function can be configured through the func.yaml file or using the fn CLI tool as shown here:

fn config function FunctionDuke fn-duke name World

The configured property will then be shown in the detail view in your Oracle Cloud Function Dashboard.

Invoking the function can be done by using the Fn CLI Tool

fn invoke FunctionDuke fn-duke

Or by sending a signed request using a convenience script called oci-curl provided by Oracle.

oci-curl "x3vzdahhy3a.us-phoenix-1.functions.oci.oraclecloud.com" get "/t/fn-duke-trigger" -d 'Duke'

Conclusion

Oracle has made a good choice when investing in the Fn project and use it as a basis for the Oracle Functions platform. It integrates extremely well with Fn and no extra tooling is needed to get started.

Java EE with NetBeans 10

The Apache NetBeans project is really shaping up. Version 10.0 was released on the 27th of December 2018. The main features added since version 9.0 are listed on the download page. For me personally, the most important feature is the JDK 11 Support.

So, what about Java EE then?

Until all the NetBeans sources have been transferred from Oracle to Apache and incorporated into the Apache NetBeans build, an additional step is required in order to get Netbeans set up for Java EE development.

The first thing you need to do is to add the NetBeans 8.2 Distribution Update Center. Select Tools->Plugins in Apache NetBeans 10.0. Then click on the Settings tab and choose Add. Paste in the URL:

http://updates.netbeans.org/netbeans/updates/8.2/uc/final/distribution/catalog.xml.gz

Update Plugin Center Configuration

After saving the configuration, the next step is to select the Available Plugins tab and type java ee in the search field.

Search for Java EE plugins

As a minimum, check the plugin called Java EE Base and click the Install button. Follow the instructions and accept the licenses. NetBeans will need to restart before continuing after the installation.

After this, you are able to set up a Java EE server as shown with GlassFish 5.0 below. Choose Tools->Servers and then click Add Server.

GlassFish 5.0 with NetBeans 10.0

Happy Coding!

Running Eclipse MicroProfile on IBM Cloud

In this post, I am following up on the post series about Running Eclipse MicroProfile applications in Oracle Cloud by showing how to do it in IBM Cloud Foundry, which includes runtimes for Java, Node.js, ASP.NET Core, PHP, Python, Ruby, Swift and Go.

I am using the same simple application called CloudEE Duke as in the previous posts and will show how to deploy it in the Liberty for Java™ runtime. Since the liberty  profile is it is already configured to build using the Liberty Maven Plugin, the only thing you need to do is to activate this profile:

mvn clean package -Pliberty

See the complete pom.xml to see the complete configuration.

Since CloudEE Duke is an Eclipse MicroProfile application, you need to use the packaged server deployment option in order to activate the required features of Liberty. This is done by running the server package  command from the Liberty server directory produced by the Liberty Maven Plugin.

target/liberty/wlp/bin/server package defaultServer --include=usr

The server package  command produces a .zip file that can be pushed to IBM Cloud with the Cloud Foundry CLI as shown here:

cf push cloudee-duke -p target/liberty/wlp/usr/servers/defaultServer/defaultServer.zip

When your application is deployed, you should be able to access the hello endpoint

https://cloudee-duke.eu-gb.mybluemix.net/hello
Duke says Hello!

As ususal, you will also have the health and metrics endpoints provided by the MicroProfile implementation

https://cloudee-duke.eu-gb.mybluemix.net/health
{
outcome: “UP”,
checks: [ ]
}

https://cloudee-duke.eu-gb.mybluemix.net/metrics
# TYPE base:classloader_total_loaded_class_count counter
# HELP base:classloader_total_loaded_class_count Displays the total number of classes that have been loaded since the Java virtual machine has started execution.
base:classloader_total_loaded_class_count 10744
# TYPE base:gc_global_count counter

Run and Debug a WildFly Swarm application from NetBeans

Java EE developers using NetBeans are used to be able to run and debug their thin-war applications in their application server of choice directly from NetBeans. When developing microservices packaged as über-or hollow-jars, you expect the same effortless way of running and debugging. The good news is that you can. In this post, I show step-by-step how to run and debug the WildFly Swarm version of CloudEE Duke in NetBeans.

Run WildFly Swarm application

The easiest way of running CloudEE Duke in NetBeans is to edit the Run project action for the project. Right click on CloudEE Duke, select properties and Actions as shown below.

Configure the Execute Goals to package wildfly-swarm:run, remove all the default properties and your’re all set. Run Project (F6 ) will start the application using the WildFly Swarm Maven Plugin.

Debug WildFly Swarm Appliction

To enable debugging, you follow the same steps as described above, but in this case it is the Debug Project action you select.

Execute Goals is configured the same way as for Run, but in the Set Properties, you need to configure a debug port for WildFly Swarm. This is done by setting the swarm.debug.port property, e.g. to 9000.

Debug Project Ctrl-F5 will start the application in debug mode. Note that the execution will halt while waiting for the debugger to attach. See the screenshot below for how it will look in the log.

Select Debug->Attach Debugger from the menu in NetBeans. Change the value for Port to 9000 (or the value you chose in the previous step) and click OK.

To verify the setup, set a breakpoint at line 16 in the class HelloWorldEndpoint.

Then navigate to http://localhost:8080/hello. The execution will stop at the breakpoint at line 16 in HelloWorldEndpoint.

Running Eclipse MicroProfile on Microsoft Azure

In this post, I am following up on the post series about Running Eclipse MicroProfile applications in Oracle Cloud by showing how to do it in Microsoft Azure Web Apps for Containers.

I am using the same simple application called CloudEE Duke as in the previous posts. The only difference is that I now package the applications as Docker Images. In this example, I show how to use the fabric8 Maven Plugin to produce a docker image for WildFly Swarm.

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>${version.docker-maven-plugin}</version>
    <configuration>
        <images>
            <image>
                <alias>${project.artifactid}</alias>
                <name>ivargrimstad/${project.artifactId}:swarm</name>
                <build>
                    <maintainer>Ivar Grimstad (ivar.grimstad@gmail.com)</maintainer>
                    <from>jboss/base-jdk:8</from>
                    <assembly>
                        <basedir>/</basedir>
                        <inline>
                            <files>
                                <file>
                                    <source>${project.build.directory}/${project.build.finalName}-hollow-swarm.jar</source>
                                    <outputDirectory>/opt</outputDirectory>
                                </file>
                                <file>
                                    <source>${project.build.directory}/${project.build.finalName}.war</source>
                                    <outputDirectory>/opt</outputDirectory>
                                </file>
                            </files>
                        </inline>                                   
                    </assembly>       
                    <entryPoint>
                        <arg>java</arg>
                        <arg>-Djava.net.preferIPv4Stack=true</arg>
                        <arg>-jar</arg>
                        <arg>/opt/${project.build.finalName}-hollow-swarm.jar</arg>  
                        <arg>/opt/${project.build.finalName}.war</arg>  
                    </entryPoint>
                </build>
            </image>
        </images>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The configuration is similar for the other Eclipse MicroProfile implementations. See the full pom.xml for examples. To produce the docker image for the WildFly Swarm implementation of CloudEE Duke, use the following command:

mvn clean package docker:build -Pswarm

Once the image is produced, you need to publish it to a container registry. In my case I simply push it to my public Docker Hub.

In order to deploy the CloudEE Duke application in Microsoft Azure, log in to your Azure Portal and create a new Web App for Containers as shown below.

Since WildFly Swarm runs on port 8080 by default (and I am using all defaults here), the port number for the application needs to be configured. This can be done either in the UI, or using Cloud Shell as shown here:

When your application is deployed, you should be able to access the hello endpoint.

https://cloudee-duke-swarm.azurewebsites.net/hello
Duke says Hello!

https://cloudee-duke-swarm.azurewebsites.net/health
{
outcome: “UP”,
checks: [ ]
}

https://cloudee-duke-swarm.azurewebsites.net/metrics
# HELP base:classloader_total_loaded_class_count Displays the total number of classes that have been loaded since the Java virtual machine has started execution.
# TYPE base:classloader_total_loaded_class_count counter
base:classloader_total_loaded_class_count 13697.0

KumuluzEE on Oracle Application Container Cloud

In this blog post, I will describe how to deploy the CloudEE Duke application packaged in a Kumuluz EE über-jar to Oracle Application Container Cloud.

The deployment artifact required for deployment in Oracle Application Container Cloud is a ZIP archive containing the application über-jar and a manifest file (manifest.json). The Kumuluz EE version of the manifest.json for CloudEE Duke is listed below.

{
    "runtime": {
        "majorVersion": "8"
    },
    "command": "java -Dkumuluzee.server.http.port=$PORT -jar cloudee-duke.jar",
    "release": {
        "version": "1.0",
        "build": "1",
        "commit": "123"
    },
    "notes": "Dukes says hello from Kumuluz EE"
}

You need to specify the port for Kumuluz EE in the startup command. This is done by using the $PORT environment variable.

The über-jar is produced by using the Kumuluz Maven Plugin:

<plugin>
    <groupId>com.kumuluz.ee</groupId>
    <artifactId>kumuluzee-maven-plugin</artifactId>
    <version>${version.kumuluz}</version>
    <executions>
        <execution>
            <id>package</id>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

See the complete pom.xml for an example on how to produce the deployable ZIP archive with the maven command:

mvn clean package assembly:single -Pkumuluz

This will produce a file called cloudee-duke-oracle-kumuluz.zip  in the target folder. This is the ZIP archive you will deploy to Oracle Application Container Cloud as shown in the screenshot below.

When your application is deployed, you should be able to access the hello endpoint

https://<dependsonyouraccount>.oraclecloud.com/hello
Duke says Hello!

You will also have the health and metrics endpoints provided by the MicroProfile implementation

https://<dependsonyouraccount>.oraclecloud.com/health
{
outcome: “UP”,
checks: [ ]
}

https://<dependsonyouraccount>.oraclecloud.com/metrics
# TYPE base:gc_ps_mark_sweep_count counter
# HELP base:gc_ps_mark_sweep_count Displays the total number of collections that have occurred. This attribute lists -1 if the collection count is undefined for this collector.
base:gc_ps_mark_sweep_count{serviceVersion=”1.0.0″,environment=”dev”,instanceId=”110cd814-3d12-4198-80eb-694196f58993″,serviceName=”UNKNOWN”} 2
# TYPE base:classloader_total_loaded_class_count counter

Liberty on Oracle Application Container Cloud

In this blog post, I will describe how to deploy the CloudEE Duke application packaged in a Liberty über-jar to Oracle Application Container Cloud.

The deployment artifact required for deployment in Oracle Application Container Cloud is a ZIP archive containing the application über-jar and a manifest file (manifest.json). The Liberty version of the manifest.json for CloudEE Duke is listed below.

{
    "runtime": {
        "majorVersion": "8"
    },
    "command": "java -jar cloudee-duke.jar",
    "release": {
        "version": "1.0",
        "build": "1",
        "commit": "123"
    },
    "notes": "Dukes says hello from Liberty"
}

You need to specify the port for Liberty to use. This cam be done by configuring it in the server.xml using the environment variable ${env.PORT}  as shown here:

<server description="Sample Liberty server">
    <featureManager>
        <feature>microprofile-1.2</feature>
    </featureManager>

    <httpEndpoint  httpPort="${env.PORT}" 
                   httpsPort="9443"
                   id="defaultHttpEndpoint" 
                   host="*" />

    <quickStartSecurity userName="duke" userPassword="duke"/>

    <keyStore id="defaultKeyStore" password="Liberty"/>
</server>

The über-jar is produced by using a combination of the Maven Resources Plugin as well as the Liberty Maven Plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.0.2</version>
    <executions>
        <execution>
            <id>copy-app</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/liberty/wlp/usr/servers/defaultServer/dropins</outputDirectory>
                <resources>
                    <resource>
                        <directory>${project.build.directory}</directory>
                        <includes>
                            <include>${project.build.finalName}.war</include>
                        </includes>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>net.wasdev.wlp.maven.plugins</groupId>
    <artifactId>liberty-maven-plugin</artifactId>
    <version>2.2</version>
    <extensions>true</extensions>
    <configuration>
        <install>
            <type>webProfile7</type>
            <version>2018.+</version>
        </install>
        <configFile>${basedir}/src/main/liberty/config/server.xml</configFile>
        <serverEnv>${basedir}/src/main/liberty/config/server.env</serverEnv>
        <jvmOptionsFile>${basedir}/src/main/liberty/config/jvm.options</jvmOptionsFile>
        <packageFile>${project.build.directory}/${project.build.finalName}.jar</packageFile>
        <include>runnable</include>
    </configuration>     
    <executions>
        <execution>
            <id>install-liberty</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>install-server</goal>
            </goals>
        </execution>
        <execution>
            <id>package-app</id>
            <phase>package</phase>
            <goals>
                <goal>package-server</goal>
            </goals>
        </execution>
    </executions>               
</plugin>

See the complete pom.xml for an example on how to produce the deployable ZIP archive with the maven command:

mvn clean package assembly:single -Pliberty

This will produce a file called cloudee-duke-oracle-liberty.zip  in the target folder. This is the ZIP archive you will deploy to Oracle Application Container Cloud as shown in the screenshot below.

When your application is deployed, you should be able to access the hello endpoint

https://<dependsonyouraccount>.oraclecloud.com/hello
Duke says Hello!

You will also have the health and metrics endpoints provided by the MicroProfile implementation

https://<dependsonyouraccount>.oraclecloud.com/health
{
outcome: “UP”,
checks: [ ]
}

https://<dependsonyouraccount>.oraclecloud.com/metrics
# TYPE base:classloader_total_loaded_class_count counter
# HELP base:classloader_total_loaded_class_count Displays the total number of classes that have been loaded since the Java virtual machine has started execution.
base:classloader_total_loaded_class_count 9430
# TYPE base:cpu_system_load_average gauge

 

Payara Micro on Oracle Application Container Cloud

In this blog post, I will describe how to deploy the CloudEE Duke application packaged in a Payara Micro über-jar to Oracle Application Container Cloud.

The deployment artifact required for deployment in Oracle Application Container Cloud is a ZIP archive containing the application über-jar and a manifest file (manifest.json). The Payara Micro version of the manifest.json for CloudEE Duke is listed below.

{
    "runtime": {
        "majorVersion": "8"
    },
    "command": "java -jar cloudee-duke-microbundle.jar --port $PORT",
    "release": {
        "version": "1.0",
        "build": "1",
        "commit": "123"
    },
    "notes": "Dukes says hello from Payara"
}

You need to specify the port for Payara Micro in the startup command. This is done by using the $PORT environment variable.

The über-jar is produced by using the Payara Micro Maven Plugin:

<plugin>
    <groupId>fish.payara.maven.plugins</groupId>
    <artifactId>payara-micro-maven-plugin</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <executions>
        <execution>
            <goals>
                <goal>bundle</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <payaraVersion>${version.payara.micro}</payaraVersion>
        <autoDeployEmptyContextRoot>true</autoDeployEmptyContextRoot>
    </configuration>
</plugin>                

See the complete pom.xml for an example on how to produce the deployable ZIP archive with the maven command:

mvn clean package payara-micro:bundle assembly:single -Ppayara

This will produce a file called cloudee-duke-oracle-payara.zip  in the target folder. This is the ZIP archive you will deploy to Oracle Application Container Cloud as shown in the screenshot below.

When your application is deployed, you should be able to access the hello endpoint

https://<dependsonyouraccount>.oraclecloud.com/hello
Duke says Hello!

You will also have the health and metrics endpoints provided by the MicroProfile implementation

https://<dependsonyouraccount>.oraclecloud.com/health
{
outcome: “UP”,
checks: [ ]
}

https://<dependsonyouraccount>.oraclecloud.com/metrics
# TYPE vendor:system_cpu_load gauge
# HELP vendor:system_cpu_load Display the “recent cpu usage” for the whole system. This value is a double in the [0.0,1.0] interval. A value of 0.0 means that all CPUs were idle during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running 100% of the time during the recent period being observed. All values betweens 0.0 and 1.0 are possible depending of the activities going on in the system. If the system recent cpu usage is not available, the method returns a negative value.
vendor:system_cpu_load 0.005405405405405406