diff --git a/developing-with-spring-pathway.json b/developing-with-spring-pathway.json index 4e85c145d..3080fec40 100644 --- a/developing-with-spring-pathway.json +++ b/developing-with-spring-pathway.json @@ -35,7 +35,7 @@ "pathway_id": "middleware/middleware-spring-boot", "course_id": "microservices-1", "title": "Externalized Configuration", - "description": "Externalized Configuration and Health Checks" + "description": "Externalized Configuration" }, { "external_link": "https://learn.openshift.com/middleware/courses/middleware-spring-boot/monitoring", diff --git a/middleware/middleware-spring-boot-pathway.json b/middleware/middleware-spring-boot-pathway.json index 21a646203..09f5c50fe 100644 --- a/middleware/middleware-spring-boot-pathway.json +++ b/middleware/middleware-spring-boot-pathway.json @@ -31,7 +31,7 @@ "external_link": "https://learn.openshift.com/middleware/courses/middleware-spring-boot/microservices-1", "course_id": "microservices-1", "title": "Externalized Configuration", - "description": "Externalized Configuration and Health Checks" + "description": "Externalized Configuration" }, { "external_link": "https://learn.openshift.com/middleware/courses/middleware-spring-boot/monitoring", diff --git a/middleware/middleware-spring-boot/microservices-1/00-intro.md b/middleware/middleware-spring-boot/microservices-1/00-intro.md index e1030cd94..b7286f00f 100644 --- a/middleware/middleware-spring-boot/microservices-1/00-intro.md +++ b/middleware/middleware-spring-boot/microservices-1/00-intro.md @@ -1 +1 @@ -In this scenario you will learn more about developing Spring Boot Microservices using the [Red Hat OpenShift Application Runtimes](https://developers.redhat.com/products/rhoar) platform. You will learn about Externalized Configurations and how we can use Externalized Configurations to change specific values/variables without having to take down the entire application. +In this scenario you will learn more about developing Spring Boot Microservices using the [Red Hat Runtimes](https://www.redhat.com/en/products/runtimes) platform. You will learn about Externalized Configurations and how we can use Externalized Configurations to change specific values/variables without having to take down the entire application. diff --git a/middleware/middleware-spring-boot/microservices-1/01-review-the-initial-project.md b/middleware/middleware-spring-boot/microservices-1/01-review-the-initial-project.md index d1d1c9085..960174728 100644 --- a/middleware/middleware-spring-boot/microservices-1/01-review-the-initial-project.md +++ b/middleware/middleware-spring-boot/microservices-1/01-review-the-initial-project.md @@ -1,24 +1,23 @@ -# Review the base structure of the application - -For your convenience, this scenario has been created using the OpenShift Launcher found [here](https://launch.openshift.io/launch/filtered-wizard/all). This launcher will automatically generate a zip file of a project that's in a ready-to-deploy state. We've selected the `Externalized Configuration` project and will be using the Spring Boot runtime option. +# Import the code +Let's refresh the code we'll be using. Run the following command to clone the sample project: +`cd /root/projects && rm -rf rhoar-getting-started && git clone https://github.com/openshift-katacoda/rhoar-getting-started && cd rhoar-getting-started/spring/microservices-externalized-config`{{execute}} +# Review the base structure of the application **1. Understanding the Application** -The project is a simple Greeting application, where a user inputs a fruit and is greeted by our service. Opening up our ``greeting-service/src/main/java/io/openshift/booster/service/FruitController.java``{{open}} file we can see the logic used to respond to our user. The interesting part of this logic is right here, where we retrieve the message: +The project is a simple Greeting application, where a user inputs a fruit name and is greeted by our service. Opening up our ``src/main/java/com/example/service/FruitController.java``{{open}} file we can see the logic used to respond to our user. The interesting part of this logic is right here, where we retrieve the message: ```java String message = String.format(properties.getMessage(), name); ``` -If we take a closer look at this `properties` object, we see that it's of type `MessageProperties`. When we look at that file ``greeting-service/src/main/java/io/openshift/booster/service/MessageProperties.java``{{open}} we see an annotation linking to a configuration file, `@ConfigurationProperties("greeting")`, which is pointing to our ``greeting-service/src/main/resources/application-local.properties``{{open}} file. +If we take a closer look at this `properties` object, we see that it's of type `MessageProperties`. When we look at that file ``src/main/java/com/example/service/MessageProperties.java``{{open}} we see an annotation linking to a configuration prefix, `@ConfigurationProperties("greeting")`, which is pointing to our ``src/main/resources/application-local.properties``{{open}} file. Our `application-local.properties` file contains only one property, `greeting.message`. This is the message that we return and display to the user. In order to get an understanding of the flow, let's run the application locally. First cd into the project directory and build the project: -``mvn -f greeting-service spring-boot:run``{{execute}} - -``mvn spring-boot:run``{{execute}} +``mvn spring-boot:run``{{execute}} -When the application finishes building click the **local web browser** or click [here](https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/). You should see the same message that is in the `application-local.properties` file. +When the application finishes building, click the **local web browser** or click [here](https://[[CLIENT_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com). You should see the same message that is in the `application-local.properties` file. Be sure to stop the application with `ctrl-c`. diff --git a/middleware/middleware-spring-boot/microservices-1/02-deploy-to-openshift.md b/middleware/middleware-spring-boot/microservices-1/02-deploy-to-openshift.md index ddd955263..b67fa35ed 100644 --- a/middleware/middleware-spring-boot/microservices-1/02-deploy-to-openshift.md +++ b/middleware/middleware-spring-boot/microservices-1/02-deploy-to-openshift.md @@ -1,12 +1,8 @@ -# Login and Deploy to OpenShift Application Platform +# Deploy to OpenShift Application Platform -**1. Login to the OpenShift Container Platform** +**1. Create a project** -To login, we will use the `oc` command and then specify a username and password like this: - -``oc login [[HOST_SUBDOMAIN]]-8443-[[KATACODA_HOST]].environments.katacoda.com --insecure-skip-tls-verify=true -u developer -p developer``{{execute}} - -Next we create the project that we'll be adding our application to: +Let's first create a new project: ``oc new-project dev --display-name="Dev - Spring Boot App"``{{execute}} @@ -14,31 +10,29 @@ Next we create the project that we'll be adding our application to: Before we deploy the application, we have to make a few changes so our application runs smoothly using External Configurations. -The first step is we're going to assign view access rights to the our deveoper account. We have to do this before deploying the application so that it's able to access the OpenShift API and read the contents of the ConfigMap. We can do that with the following command: +The first step is we're going to assign view access rights to the service account we're logged in as. We have to do this before deploying the application so that it's able to access the OpenShift API and read the contents of the `ConfigMap`. We can do that with the following command: ``oc policy add-role-to-user view -n $(oc project -q) -z default``{{execute}} We should see `role "view" added: "default"` as output. The next step is to create our ConfigMap configuration and deploy it to OpenShift using: -``oc create configmap app-config --from-file=greeting-service/src/main/etc/application.properties``{{execute}} +``oc create configmap spring-boot-configmap-greeting --from-file=src/main/etc/application.properties``{{execute}} -We will talk about ConfigMaps in greater detail in the next section. +We will talk about `ConfigMap`s in greater detail in the next section. ->**NOTE:** The only two parameters this command needs are the name of the ConfigMap to create and the file location. This command is creating a ConfigMap named `app-config`. We're going to be using that name in future commands. If you decide to manually run the command or give the ConfigMap a different name, make sure you modify the other commands accordingly. +>**NOTE:** The only two parameters this command needs are the name of the ConfigMap to create and the file location. This command is creating a `ConfigMap` named `spring-boot-configmap-greeting`, which also happens to be the name of the application we're deploying. We're going to be using that name in future commands. If you decide to manually run the command or give the `ConfigMap` a different name, make sure you modify the other commands and configuration accordingly. Now we're ready to deploy! **3. Deploy the application to OpenShift** -Run the following command to deploy the application to OpenShift +Run the following command to deploy the application to OpenShift: -``mvn package fabric8:deploy -Popenshift``{{execute}} +``mvn oc:deploy -Popenshift``{{execute}} There's a lot that happens here so lets break it down: -The `mvn package` piece of the above command instructs Maven to run the package lifecycle. This builds a Spring Boot JAR file which is a Fat Jar containing all dependencies necessary to run our application. - -For the deployment to OpenShift we are using the [Fabric8](https://fabric8.io/) tool through the `fabric8-maven-plugin` which is configured in our ``pom.xml``{{open}} (found in the `` section). +For the deployment to OpenShift we are using the [JKube](https://www.eclipse.org/jkube/) tool through the [`openshift-maven-plugin`](https://www.eclipse.org/jkube/docs/openshift-maven-plugin), which is configured in our ``pom.xml``{{open}} (found in the `` section). Now that our application is deployed, navigate to our route in the OpenShift Web View or click [here](http://spring-boot-configmap-greeting-dev.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/). We should see the following screen, meaning everything was successful: @@ -46,12 +40,7 @@ Now that our application is deployed, navigate to our route in the OpenShift Web **4. Test functionality** -As the page suggests, we're going to put in a name and let our greeting service reply with a given greeting. Since our default value is `Greetings, you picked %s as your favorite fruit!`, that's what we should see after we fill in the textbox and click the button. - - - +As the page suggests, we're going to put in a name of a fruit and let our greeting service reply with a given greeting. Since our default value in our `ConfigMap` is `Greetings, you picked %s as your favorite fruit!`, that's what we should see after we fill in the textbox and click the button. ## Congratulations diff --git a/middleware/middleware-spring-boot/microservices-1/03-modify-the-configmap.md b/middleware/middleware-spring-boot/microservices-1/03-modify-the-configmap.md index d5b51eccd..b5eaa777d 100644 --- a/middleware/middleware-spring-boot/microservices-1/03-modify-the-configmap.md +++ b/middleware/middleware-spring-boot/microservices-1/03-modify-the-configmap.md @@ -2,11 +2,12 @@ **1. The ConfigMap** -Configs maps are a useful tool for decoupling configuration settings from the code. ConfigMaps can be used to inject configuration data into a container in much the same way that secrets do, though ConfigMaps should not store confidential information. ConfigMap objects hold key-pair values representing all of your configuration data. +`ConfigMap`s are a useful tool for decoupling configuration settings from the code. `ConfigMap`s can be used to inject configuration data into a container in much the same way that secrets do, though `ConfigMap`s should not store confidential information. `ConfigMap` objects hold key-pair values representing all of your configuration data. -Notice the following dependency that was added to our `greeting-service/pom.xml`{{open}}. This allows us to integrate with OpenShift's ConfigMaps. +Notice the following dependency that was added to our `pom.xml`{{open}}. This allows us to integrate with OpenShift's ConfigMaps. -``` +``` + org.springframework.cloud spring-cloud-starter-kubernetes-config @@ -14,7 +15,7 @@ Notice the following dependency that was added to our `greeting-service/pom.xml` **2. Modify the ConfigMap** -Let's modify the greeting that our service is returning to the user. Since we set up the greeting in a properties file, we will not need to make any code change to change the functionality. This means that we won't need to have any downtime for this change, we're able to modify the response through our newly created ConfigMap from the previous step. We can edit our config map in the OpenShift Console. Click the **OpenShift Console** tab, select `Resources > Config Maps`. Then Select our ConfigMap `app-config` +Let's modify the greeting that our service is returning to the user. Since we set up the greeting in a properties file, we will not need to make any code change to change the functionality. This means that we won't need to have any downtime for this change, we're able to modify the response through our newly created `ConfigMap` from the previous step. We can edit our config map in the OpenShift Console. Click the **OpenShift Console** tab, select `Resources > Config Maps`. Then Select our ConfigMap `app-config` ![Greeting Service](/openshift/assets/middleware/rhoar-microservices/configmap.png) @@ -30,15 +31,11 @@ Hit `Save` and that's all there is to it! **3. Test changes** -Now that we've modified the ConfigMap and deployed our changes, let's test the greeting service and see if it's returning our new value. +Now that we've modified the `ConfigMap` and deployed our changes, let's test the greeting service and see if it's returning our new value. Click [here](http://spring-boot-configmap-greeting-dev.[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/) and put in a test value and click the button. Now instead of seeing `Greetings ...`, we should be seeing: `Bonjour, you picked %s as your favorite fruit!` - - This means that we were able to modify our application behavior through External Configuration of the `application.properties` file using a ConfigMap without having to even take down the application. That's pretty powerful! ## Congratulations diff --git a/middleware/middleware-spring-boot/microservices-1/env-init.sh b/middleware/middleware-spring-boot/microservices-1/env-init.sh index 0fa5c1610..ae38bb5c9 100644 --- a/middleware/middleware-spring-boot/microservices-1/env-init.sh +++ b/middleware/middleware-spring-boot/microservices-1/env-init.sh @@ -1,3 +1,2 @@ -ssh root@host01 "git --git-dir=/root/projects/rhoar-getting-started/.git --work-tree=/root/projects/rhoar-getting-started pull" -ssh root@host01 "yum install tree -y" -ssh root@host01 "touch /etc/rhsm/ca/redhat-uep.pem" \ No newline at end of file +mkdir -p /root/projects/rhoar-getting-started/spring/microservices-externalized-config +echo "-w \"\n\"" >> ~/.curlrc \ No newline at end of file diff --git a/middleware/middleware-spring-boot/microservices-1/index.json b/middleware/middleware-spring-boot/microservices-1/index.json index c491e8ea4..5cb74f5a4 100644 --- a/middleware/middleware-spring-boot/microservices-1/index.json +++ b/middleware/middleware-spring-boot/microservices-1/index.json @@ -1,8 +1,8 @@ { "pathwayTitle": "RHOARSpringBoot", - "icon": "fa-openshift", - "title": "Externalized Configuration and Health Checks", - "description": "Externalized Configuration and Health Checks", + "icon": "fa-java", + "title": "Externalized Configuration", + "description": "Externalized Configuration", "difficulty": "beginner", "time": "15 minutes", "details": { @@ -23,16 +23,26 @@ "files": [], "environment": { "showdashboard": true, - "dashboards": [{"name":"Local Web Browser","port":8080},{"name":"OpenShift Console","port":8443}], + "dashboards": [ + { + "name": "Local Web Browser", + "href": "https://[[CLIENT_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com" + }, + { + "name": "OpenShift Console", + "href": "https://console-openshift-console-[[HOST_SUBDOMAIN]]-443-[[KATACODA_HOST]].environments.katacoda.com" + } + ], "uilayout": "editor-terminal", "uisettings": "java", "hideintro": false, + "hideHiddenFiles": true, "uieditorpath": "/root/projects/rhoar-getting-started/spring/microservices-externalized-config", "uimessage1": "\u001b[32mYour Interactive Bash Terminal. A safe place to learn and execute commands.\u001b[m\r\n" }, "backend": { "autoUpgrade": false, - "imageid": "openshift-middleware-3-7", + "imageid": "openshift-4-7", "port": 8443 } } diff --git a/middleware/middleware-spring-boot/microservices-1/set-env.sh b/middleware/middleware-spring-boot/microservices-1/set-env.sh index e8d6e4ac8..f99ead91b 100644 --- a/middleware/middleware-spring-boot/microservices-1/set-env.sh +++ b/middleware/middleware-spring-boot/microservices-1/set-env.sh @@ -1,4 +1,17 @@ #!/bin/bash -cd projects/rhoar-getting-started/spring/microservices-externalized-config -~/.launch.sh +mkdir -p /root/projects/rhoar-getting-started/spring/microservices-externalized-config +cd /root/projects/rhoar-getting-started/spring/microservices-externalized-config + +# Install Java 11 +wget -O /tmp/jdk.tar.gz https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz && \ +pushd /usr/local && \ +tar -xvzf /tmp/jdk.tar.gz && \ +rm -rf /tmp/jdk.tar.gz && \ +export JAVA_HOME="/usr/local/jdk-11.0.10+9" && \ +export PATH=$JAVA_HOME/bin:$PATH && \ +echo "export JAVA_HOME=$JAVA_HOME" >> ~/.bashrc && \ +echo "export PATH=$JAVA_HOME/bin:\$PATH" >> ~/.bashrc && \ +popd + +clear \ No newline at end of file