Jakarta EE on Microsoft Azure with Cargo Tracker

Open Liberty on AKS

Deploy the minimum viable cluster with the Portal

15min Self-guided. Use the Portal to deploy a sample app.
  1. Visit the Portal https://aka.ms/publicportal.

  2. In the search box, without pressing enter, type “websphere” without the quotes.

  3. In the section of suggested results labeled Marketplace select IBM WebSphere Liberty and Open Liberty on Azure Kubrenets Service.

  4. Select Create.

  5. In Resource group select Create new. In the dialog that appears, enter the next number to the sequence number you entered in setup.sh, followed by the date in mmdd syntax, followed by a brief identifier, such as ol or wls. For example, if you entered ejb01, you would enter ejb020317wls.

  6. In Region enter West Europe.

  7. Read warning box. This is why we had you create the UAMI and assign it the necessary roles.

  8. Select the +Add control.

  9. In the sidebar, select the UAMI created by script. It should be something like ejb010317u.

  10. In the sidebar, select Add. This should dismiss the sidebar and cause the warning box to disappear.

  11. If the UAMI you created is not appearing, sign out of the Portal, sign back in and try again.

  12. Scroll down and note the hyperlinks in the Report issues, get help, and share feedback section. The links will open in a new tab. We especially encourage you to take the survey about Java EE usage. this will help us create better Java EE on Azure offers.

  13. Select Next: Configure cluster.

  14. Leave the values at their defaults, but allow the instructor to talk about what the values do.

  15. Select Next: Configure application.

  16. Next to Deploy an application? select Yes.

  17. In the UI that appears, select The Open Liberty sample image but allow the instructor to explain what the other options are.

  18. Select Review + create.

  19. When the green Validation passed message appears, select Create. This starts deployment.

During deployment, instructor lead training for Open Liberty

After deployment completes

15Min Take a tour of the deployment.
  1. Self-guided. How to find resource groups in the Portal.

    1. Visit the Portal.

    2. Select Resource groups.

    3. In the filter, enter the first three characters of the prefix you used in setup.sh.

    4. Select your resource group.

  2. Self-guided. How to find outputs in a resource group.

    1. In the pane under the Resource group name, in the Settings section, select Deployments.

    2. Select the bottom most deployment in the list.

    3. In the left pane, select Outputs.

  3. Examine the outputs.

  4. How to connect to cluster with kubectl in Cloud Shell.

    1. az aks command reference docs.microsoft.com
  5. Self-guided. How to visit the sample app.

    1. Execute the cmdToGetAppService.

    2. Fashion the EXTERNAL-IP and PORT values into a URL such as http://52.182.209.67:9080/.

    3. Visit the URL in your browser. Explore the sample app.

  6. Examine appDeploymentTemplateYamlEncoded.

    1. Copy the value of that output using the icon.

    2. In the Cloud Shell, execute echo <paste> | base64 -d and press enter.

    3. This is the deployment YAML you can use to update the offer. The pipeline will revisit use this value. You do not need to save it now.

Remove deployment

5min Remove resources to save your subscription cost.

You must remove the deployment to avoid consuming more Azure resources than your pass allows.

  1. In Cloud Shell, enter az aks delete --no-wait --name <your cluster name> --resource-group <your resource group>.

  2. In the Portal, find <your resource group> and select Delete resource group.

  3. Copy past the name of the resource group and select Delete.

Deploy a non-trivial sample app with GitHub Actions Infrastructure as Code

60min Go further and add database an JMS support.

Deploy Database and Storage Account for Cargotracker on Liberty and WLS on AKS

  1. Visit your fork of https://github.com/edburns/javaland-javaee.

  2. Select Actions.

  3. Select DB and Storage Account.

  4. Select Run workflow and Run workflow.

  5. Instructor will walk you through .github/workflows/setupDBandStorage.yml, which you have in your repo. Briefly, this workflow uses the repository secrets you created earlier to create an Azure Database for PostgreSQL instance, Storage Account, and Storage Container, build the cargotracker.war and upload it to the Storage Container.

    1. Azure Database for PostgreSQL documentation

    2. Storage account overview

    3. Azure storage container

  6. Capture values from outputs. You will need these later.

    1. From the Actions tab, select Setup DB and Storage Account, then select the most recent run of that workflow.

    2. Under Jobs on the left, select deploy-db.

    3. In the log pane on the right, expand Set Up Azure Postgresql to Test dbTemplate.

    4. Expand Run azure/CLI. Look in the env section.

    5. Disambiguation prefix. This value is the numeric value in the middle of the value for resourceGroupForDB. It will be something like 19251229631.

    6. Database name. This value is the dbName. It will be something like wlsdb19251229631.

    7. Storage account name. This value is the storageAccountName. It will be something like wlsdsa19251229631.

    8. Storage container within storage account. This value is the storageContainerName. It will be something like wlsdcon19251229631.

Deploy Open Liberty on AKS from workflow

  1. Visit your fork of https://github.com/edburns/javaland-javaee.

  2. Select Actions.

  3. Select Setup OpenLiberty on AKS.

  4. Select Run workflow.

  5. In the drop down:

    1. Enter the disambiguation prefix from above.

    2. Enter your region.

  6. Select Run workflow.

  7. Instructor will walk you through .github/workflows/setupOpenLibertyAks.yml, which you have in your repo. Briefly, this workflow uses the repository secrets you created earlier to execute the same steps you did in the Portal, but uses the underlying GitHub repo for Liberty on AKS to deploy the arm template manually.

    It then uses the cargotracker/cargotracker-liberty version of CargoTracker to create a parameters file that is used to deploy the offer.

    IMPORTANT The deployment of cargotracker is not complete at this point because we have not pushed the docker image to the Azure Container Registry.

  8. Self-guided. After the workflow succeeds, go into the Portal and find the resource group created by the workflow. It will start with ol-aks-<your disambiguation suffix>.

  9. Self-guided. Select Overview. Observe the list of resources in the middle pane.

  10. Self-guided. Capture the Azure Container Registry and create a repository secret with the value.

    1. In the resource group for the AKS cluster, find the Container Registry resource and select it.

    2. In the Settings section, select Access keys.

    3. There are two password entries. Hover the mouse over the Copy icon to the right of the first one and single click.

    4. Paste the value to your saved text file, labeling it accordingly.

    5. In the Cloud Shell, type gh --repo <your github name>/javaland-javaee secret set AZURE_OPEN_LIBERTY_ACR_PASSWORD -b and paste the saved value. Ensure there is no space after -b. Press enter.

      • You should see ✓ Set secret AZURE_OPEN_LIBERTY_ACR_PASSWORD for your github name/javaland-javaee.
  11. Self-guided. In the Portal find the resource group for the AKS cluster.

  12. Self-guided. As you did before, inspect the outputs.

  13. Self-guided. Collect parameters necessary for the next step. Use the Copy icon next to each output.

    1. clusterRGName Name of the resource group into which the AKS cluster is deployed.

    2. clusterName The name of the AKS cluster.

    3. acrName The name of the container registry, but you must append .azurecr.io when you save this value aside.

    4. ACR user name. This is the same as acrName .

Deploy cargotracker on Open Liberty on AKS from the workflow

  1. Visit your fork of https://github.com/edburns/javaland-javaee.

  2. Select Actions.

  3. Select Update Cargo Tracker to OpenLiberty on Aks.

  4. Select Run workflow.

  5. Fill in the values you captured in the preceding step.

  6. For the database, fill in the value you saved earlier.

  7. Select Run workflow.

  8. Instructor will walk you through .github/workflows/updateCargoTrackerToOpenLibertyOnAks.yml, which you have in your repo. Briefly, this workflow does the same steps done above to run cargotracker on liberty locally, but instead of running it locally, it does the following:

    • Checkout cargotracker
    • Build the app
    • Query version string for deployment verification
    • Build image and upload to ACR
    • Connect to AKS cluster
    • Apply deployment files
    • Verify pods are ready
    • Query Application URL
    • Verify that the app is update
  9. Inspect the workflow output and expand the Query Application URL step. Construct a URL using the IP, such as http://20.62.216.80:9080/.

Exercise the Cargo Tracker app

The Cargo Tracker main URL is the URL constructed in the preceding step.

  1. Go to the Cargo Tracker main URL.

    a. On the main page, select Public Tracking Interface in new window.

    1. Enter ABC123 and select Track!

    2. Observe what the next expected activity is.

    b. On the main page, select Administration Interface, then, in the left navigation column select Live in a new window. This opens up a map view.

    1. Mouse over the pins and find the one for ABC123. Take note of the information in the hover window.

    c. On the main page, select Mobile Event Logger. This opens up in a new, small, window.

    d. Drop down the menu and select ABC123. Select Next.

    e. Select the Location using the information in the next expected activity. Select Next.

    f. Select the Event Type using the information in the next expected activity. Select Next.

    g. Select the Voyage using the information in the next expected activity. Select Next.

    h. Set the Completion Date a few days in the future. Select Next.

    i. Review the information and verify it matches the next expected activity. If not, go back and fix it. If so, select Submit.

    j. Back on the Public Tracking Interface select Tracking then enter ABC123 and select Track. Observe that a different. next expected activity is listed.

    k. If desired, go back to Mobile Event Logger and continue performing the next activity.

(Optional) Run the Cargo Tracker app with liberty:dev

60min Use a local or cloud based development environment to run Cargo Tracker

If you want to run cargo tracker locally, you need a fully equipped Java development environment with the following requirements.

Or you could use a cloud based development environment such as GitHub Codespaces or GitPod.

If you choose to use GitHub Codespaces, simply open the repository in Codespaces.

If you choose to use GitPod, please follow the steps from the JBoss EAP afternoon exercise introduction section 1.1 only, but use your fork of the javaland-javaee repository instead of workshop-migrate-jboss-on-app-service as the project name. Introduction section 1.1

Enable access from your development environment to the Azure Database for PostgreSQL

  1. Visit the Portal

  2. Find the resource group for your database deployment. It will be something like wlsd-db-1953611437-2.

  3. Within the resource group, select the resource of type Azure Database for PostgreSQL single server.

  4. In the Settings panel, select Connection security.

  5. In the middle of the page is the Firewall rules section. Select the most secure option you can tolerate.

    1. If the portal has correctly determined IP address of your development environment, as in parenthesis next to + Add current client IP address, select this option.

    2. If you know how to get the IP address of your cloud development environment, you can enter the value in the Start IP and End IP fields.

      1. You can try nslookup. At the time writing, doing nslookup gitpod.io and using the first octet from the IP address for the Start IP and End IP values, followed by .0.0.0 and .255.255.255, respectively, worked.
    3. If there is no more secure option, you can open the database to the entire public Internet by selecting + Add 0.0.0.0 - 255.255.255.254.

  6. Select Save. While the configuration is updating, you may continue to the next step.

Edit the server.xml

This section uses the liberty:dev to run Open Liberty in a JVM in your development environment. For an introduction to liberty:dev see Open Liberty development mode. For complete reference material see the reference documentation.

  1. In you development environment, open the server.xml file. This file is located at cargotracker-liberty/src/main/liberty/config/server.xml in your forked repository.

  2. find the section with the xml element <properties.postgresql>.

  3. Make the edits as shown in this diff, hard coding the values using the parameters collected previously.

    --- a/cargotracker-liberty/src/main/liberty/config/server.xml
    +++ b/cargotracker-liberty/src/main/liberty/config/server.xml
    @@ -34,11 +34,11 @@
         <dataSource id="CargoTrackerDB" jndiName="jdbc/CargoTrackerDB">
             <jdbcDriver libraryRef="driver-library" />
             <properties.postgresql
    -            serverName="${db.server.name}"
    -            portNumber="${db.port.number}"
    -            databaseName="${db.name}"
    -            user="${db.user}"
    -            password="${db.password}"
    +            serverName="wlsdb19536114372.postgres.database.azure.com"
    +            portNumber="5432"
    +            databaseName="postgres"
    +            user="weblogic@wlsdb19536114372"
    +            password="Secret123!"
                 ssl="${db.ssl}" />
         </dataSource>
         <variable name="db.ssl" defaultValue="false"/>
    

Run the Liberty Maven Plugin in dev mode

  1. In the terminal of your development environment, run cd cargotracker-liberty.

  2. mvn -PopenLibertyOnAks clean package

  3. mvn -PopenLibertyOnAks liberty:dev

    If you are running in a cloud development environment, you may see a pop up about port 9080, and it might give you the option to make this port public. You must say yes to this option. If you do not see this option, you will need to use your cloud development environment steps to make this port public.

    When you see this output text, you know the server is running successfully.

    [INFO] *******************************************************************
    [INFO] *** WARNING: Apache MyFaces-2 is running in DEVELOPMENT mode.   ***
    [INFO] ***                                         ^^^^^^^^^^^         ***
    [INFO] *** Do NOT deploy to your live server(s) without changing this. ***
    [INFO] *** See Application#getProjectStage() for more information.     ***
    [INFO] *******************************************************************
    [INFO] 
    [INFO] [AUDIT   ] CWWKZ0003I: The application cargo-tracker updated in 2.720 seconds.
    
  4. Notice the mention about Apache MyFaces-2. Know that your instructor lead the team that developed the specification for MyFaces.

  5. Obtain the URL for the cargotracker from your development environment.

    1. If you are running locally, the url is simply http://localhost:9080/.

    2. If you are running in a cloud development environment, the instructions vary depending on your environment.

      For GitPod, the following was known to work at the time of this writing.

      1. In the lower right hand corner of the browser window is a list of ports. Select this list.

      2. The Ports tab should open.

      3. Hover the mouse over 9080 and options should appear. One option looks like a globe. Select the globe. A new tab should open on that URL.

      4. If you see the Open Liberty start page, append a / to the URL.

Exercise the Cargo Tracker app

The Cargo Tracker main URL is the URL constructed in the preceding step.

  1. Go to the Cargo Tracker main URL.

    a. On the main page, select Public Tracking Interface in new window.

    1. Enter ABC123 and select Track!

    2. Observe what the next expected activity is.

    b. On the main page, select Administration Interface, then, in the left navigation column select Live in a new window. This opens up a map view.

    1. Mouse over the pins and find the one for ABC123. Take note of the information in the hover window.

    c. On the main page, select Mobile Event Logger. This opens up in a new, small, window.

    d. Drop down the menu and select ABC123. Select Next.

    e. Select the Location using the information in the next expected activity. Select Next.

    f. Select the Event Type using the information in the next expected activity. Select Next.

    g. Select the Voyage using the information in the next expected activity. Select Next.

    h. Set the Completion Date a few days in the future. Select Next.

    i. Review the information and verify it matches the next expected activity. If not, go back and fix it. If so, select Submit.

    j. Back on the Public Tracking Interface select Tracking then enter ABC123 and select Track. Observe that a different. next expected activity is listed.

    k. If desired, go back to Mobile Event Logger and continue performing the next activity.

Restore database security

Follow the same steps as in the section where you enabled access to the database from your development environment, but remove the firewall rule that allowed the access.

Remember to select Save.

Clean up your development environment

In the terminal for your development environment, cd to the top level of your cloned repository and run git reset --hard.

home