Embracing the Cloud A Java Developer’s Guide to Jakarta EE on The Cloud - A Real-World Example

BuhakeSindi 40 views 45 slides Jun 14, 2024
Slide 1
Slide 1 of 45
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45

About This Presentation

This talk will focus either on AWS or Azure (depending on the platform of choice).

This talk provides a comprehensive walkthrough of how to package and deploy Jakarta EE applications to be cloud-ready for deployment.

The session begins with an overview of Jakarta EE and the cloud platform, highlig...


Slide Content

Embracing
the Cloud
A Java Developer’s Guide to Jakarta
EE on The Cloud -A Real-World
Example.

●Senior Full Stack Enterprise Java
Developer, Engineer and
Consultant, Sindi Technologies
(Pty) Ltd
○18+ years of Java development
experience.
●Jakarta EE Ambassador
●Tech speaker / Blogger
●Devoxx4Kids South Africa (Non-
Profit Organisation) founder and
event organiser
About Me

Where to find me?
https://linktr.ee/theEliteGentleman
[email protected]
@EliteGentleman
www.sindi.co.za
www.devoxx4kids.org.za
https://jakartaee-ambassadors.io/

To my
parents…
What (is it) exactly do I do for a living?

●Business brings problems that they want solution to make it go
away.
●I scope their problem into a solution.
●-> -> ->
(code) (build) (deploy) (ship)
●Programming language: Java (as in )
●Preferred framework to build business applications using Java:
Jakarta EE (previously known as Java EE). EE -> Enterprise Edition.
I foresee every step of the business lifecycle of the project, from
inception to release.
A glorified work life

Your JakartaEE
application
Configuration settings and
infrastructures
01

●A Health provider medical claim system.
●Written fully in Java
○Mavenised
○JDK 17+
○Jakarta EE 10 (Faces 4, CDI, JPA with JNDI DataSource, Jakarta SOAP
WS –JAX-WS, Jakarta REST –JAX-RS, JavaMail)
○Certificates (HTTP security), static IP addresses for HTTP transport
communication
●Database
○PostgreSQL 16.2 or higher
●Application server
○Any Jakarta EE 10 certified product –OpenLiberty24.0.0.1 or higher
Introducing Kuanza

https://kuanza.southafricanorth.azurecontainer.io:9443/

Getting started
●https://start.jakarta.ee
●For starting your Jakarta EE
journey from scratch.
●Generate MavenizedJakarta
EE projects
●Supported via popular IDEs
oIntelliJ, NetBeans, Eclipse, Visual
Studio Code.

Prepping for
cloud-readiness
02

●Containerization
○Only your application code is bundled, as well as all necessary files,
libraries and Operating System libraries and dependencies required to
run the code are packaged into a single executable (container) that
runs on any infrastructure.
●Benefits
○Portability: A container can run on multiple infrastructure and
environments without changing code.
■Prevent “But it does work on my machine” problem.
○Scalable: Containers are lightweight. Bootup is faster (no OS bootup
needed). Multiple containers can run on a single machine.
○Isolation: Containers doesn’t require knowledge of hardware and OS.
Prepping for cloud-readiness

●Containerized
○Simplified to run on any platform.
■Prevent “But it does work on my machine” problem.
○Containerized PostgreSQL database.
○Containerized OpenLibertyApplication Server.
●Cloud Provider of choice: Azure
○Quick response time to enterprise customer problem.
○Business chose this.
○Not sponsored talk by Microsoft! (No joke!)
For Kuanza
https://www.slideshare.net/BuhakeSindi/dockerizing-
your-java-development-environment

PostgreSQL Compose
FROMopen-liberty:full-java17-openj9
COPY--chown=1001:0 src/main/liberty-
docker/postgresql-42.7.3.jar
/opt/ol/wlp/lib/postgresql-42.7.3.jar
COPY--chown=1001:0 src/main/liberty-
docker/config/server.xml
/config/server.xml
COPY--chown=1001:0 src/main/liberty-
docker/config/ccert.medikredit.co.za.p12
/output/resources/security/key.p12
COPY--chown=1001:0 target/*.war
/config/apps/
ENVSEC_TLS_TRUSTDEFAULTCERTS=true
ARGTLS=true
RUNconfigure.sh
OpenLibertyDockerfile

Let’s hack with
Azure
Get your DevOps hat ready!
03

●Azure subscription.
○Get an Azure account, get a subscription ID.
○Get an Azure region location for your region group.
●Install Azure CLI
●Basic knowledge of Linux
○Commands such as: chown, wget, curl, cat, etc.
○Windows: Use WSL (Windows Subsystem for Linux), notGit Bash
●Basic knowledge of Docker scripting (Dockerfileand/or Docker
compose)
Requirements

https://www.digitalocean.com/community/tutorials/linux -
commands

●Azure Resource Group (cluster everything in 1 resource group)
●Azure for PostreSQLSingle Server *
○* Soon to be replaced with Azure PostgreSQL Flexible Server
(single server will be decommissioned in 2025 by Microsoft)
●Azure Container Registry (Private Docker Registry)
●Azure Container Instance (containerapp)
●Azure Kubernetes Service (AKS) –should you need advanced
metrics that Kubernetes provides.
○Not used for this presentation.
Azure services

●https://portal.azure.com/
○View the progress of your services that you create.
○Useful for monitoring of your services to make decisions such as scaling.
Azure Portal

●Login to your Azure cloud using Azure CLI
○Grab the subscription ID once you’ve successfully logged in.
○Command: azlogin
1. Login to Azure

●Command: azaccount set
2. Set subscription, if necessary

●Command: azaccount list-locations -o table
3. Select a region

●A resource group contains all your services (resources) which you
create.
○Useful for managing all your resources as a group.
●Command: azgroup create
4. Create a Resource Group

●Azure for PostgreSQL Database is a relational database service based on
open-source Postgres database engine. It is fully managed database-as-a-
service offering which is available with 2 different offerings: Single Server and
Flexible Server.
○For this presentation, we’ve used Single Server offering.
○Documentation:
■Flexible Server: https://learn.microsoft.com/en-us/azure/postgresql/
■Single Server: https://learn.microsoft.com/en-us/azure/postgresql/single-
server/concepts-servers
●Command: azpostresserver create
5a. Install PostgreSQL on Azure

5. Install PostgreSQL on Azure

5. Install PostgreSQL on Azure

●Once your server has been created, the fully qualified domain name of your
PostgreSQL server should be in the format:
[AZURE_POSTGRES_SERVER_NAME].postgres.database.azure.com
●This can be retrieved from the JSON response value of
fullyQualifiedDomainName
●Command: azpostgresserver show
5b. Verifying PostgreSQL on Azure

5b. Verifying PostgreSQL on Azure

●Azure PostgreSQL server is secured by default. It doesn’t accept
incoming connection.
○1. Get IP address from your IP address. For WSL users, use cat
/etc/resolve.confto get IP address.
6. Setup Azure Firewall Rule for PostgreSQL Server

●From Azure Portal (under Connection security in my database)
6. Setup Azure Firewall Rule for PostgreSQL Server

●The PostgreSQL server that you created earlier is empty. We need
to create a new database.
●Command: azpostgresdbcreate
Create PostgreSQL Database

●Login to your empty database (with admin credentials) and run the following
script.
Create non-admin (superuser) user and grant

●The default Azure JDBC URL for the PostgreSQL Server is of the format:
jdbc:postgresql://{AZURE_POSTGRES_SERVER_NAME}.postgres.database.azure.com:5432
/{AZURE_POSTGRES_SERVER_DATABASE_NAME}?user={DATABASE_USER}@{AZURE_PO
STGRES_SERVER_NAME}?&password={DATABASE_PASSWORD}&sslmode=require
●On OpenLiberty(inside your server.xml):
<properties.postgresqlURL="jdbc:postgresql://kuanza-
db.postgres.database.azure.com:5432/kuanza_db?user=kuanza_root@kuanz
a-
db&amp;password={PASSWORD}& amp;sslmode=require&amp;stringtype=u
nspecified" />
JDBC URL

●Azure Container Registry is a managed, private Docker Registry
service to store and manage your Docker container images (based
on Open-source Docker Registry 2.0)
●There are 4 SKU available when creating your ACR: Basic, Classic,
Premium, Standard.
●Our Jakarta EE Application Docker image will be stored here.
●Command: azacrcreate
7a. Setup Azure Container Private Registry

●Login to ACR to get the ACR server name
○ACR server name is of format [ACR_NAME].azurecr.io
●Command: azacrlogin
●Command: azacrshow
7a. Login to Azure Container Private Registry

●Build your Jakarta EE project into a WAR file
○Command: mvnclean package
●Build the Docker Image and push it to the Azure Container
Registry.
8. Build and push the image to Azure Container
Registry

●Azure Container Instances allows you to run a container in Azure
without having to manage any VMs and/or adopt any higher -level
services.
●We are now ready to deploy our Jakarta EE application to Azure
Container Instances. When deploying to ACI, you need to specify a
custom DNS name.
9. Deploy the application to Azure Container Instances

●We will need the password for Azure Container Registry
●Command: azacrcredential show
9. Deploy the application to Azure Container Instances

●Create the container with the password provided previously
●Command: azcontainer create
9. Deploy the application to Azure Container Instances

●Result is default JSON format
9. Deploy the application to Azure Container Instances

●http(s)://[DNS_NAME_LABEL].[AZURE_LOCATION].azurecontainer.i
o[:PORT]/
●For Kuanza:
https://kuanza.southafricanorth.azurecontainer.io:9443/
Result

Further
improvement…
04

●Automated Deployment
○CI/CD build tools (Jenkins, BitBucket)
●Monitoring of resources
○For up/down scaling of resources as needed, over time.
●Automation of Cloud Infrastructure
○Terraform
●Applying custom domain to resources.

Thank you!

Demo!

Questions?