From 6e57953cdcd6d4da269b4bf5c9c9a96fa9ad07ca Mon Sep 17 00:00:00 2001 From: Dan K Date: Tue, 16 Jul 2019 07:13:48 -0400 Subject: [PATCH 1/6] WIP:feat(ch9s6): add initial code for GE The "mvn fabric8:deploy" command still does not work, mostly because it seems that the deployed "service" contains selectors for labels that are not present on the associated Pod. --- micro-java/pom.xml | 102 ++++++++++++++++++ .../openshift/hello/HelloResource.java | 27 +++++ .../openshift/hello/JaxRsActivator.java | 8 ++ 3 files changed, 137 insertions(+) create mode 100644 micro-java/pom.xml create mode 100644 micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java create mode 100644 micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java diff --git a/micro-java/pom.xml b/micro-java/pom.xml new file mode 100644 index 0000000..79154c6 --- /dev/null +++ b/micro-java/pom.xml @@ -0,0 +1,102 @@ + + + + 4.0.0 + + com.redhat.training.openshift + micro-java + 1.0 + war + Red Hat Training Hello Java app + Hello microservice using Thorntail + + + + + UTF-8 + false + + + 2.4.0.Final + + + 3.1 + 2.16 + 2.5 + + 4.1.0 + + + 1.8 + 1.8 + + + + + + + + io.thorntail + bom-all + ${version.thorntail} + import + pom + + + + + + + io.thorntail + cdi + + + io.thorntail + jaxrs + + + + + + + hello + + + + + io.thorntail + thorntail-maven-plugin + ${version.thorntail} + + + + package + + + + + + io.fabric8 + fabric8-maven-plugin + ${version.fabric8.plugin} + + + fmp + + resource + build + + + + + + + + diff --git a/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java new file mode 100644 index 0000000..3db3118 --- /dev/null +++ b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java @@ -0,0 +1,27 @@ +package com.redhat.training.openshift.hello; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +@Path("/") +public class HelloResource { + + @GET + @Path("/hello") + @Produces("text/plain") + public String hello() { + String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown"); + String message = System.getenv().getOrDefault("APP_MSG", null); + String response = ""; + + if (message == null) + response = "Hello world from host "+hostname+"\n"; + else + response = "Hello world from host ["+hostname+"]."; + response += "Message received = "+message+"\n"; + + return response; + } +} diff --git a/micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java b/micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java new file mode 100644 index 0000000..7a6a14a --- /dev/null +++ b/micro-java/src/main/java/com/redhat/training/openshift/hello/JaxRsActivator.java @@ -0,0 +1,8 @@ +package com.redhat.training.openshift.hello; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("/api") +public class JaxRsActivator extends Application { +} From 698457ac05ca34aff02b1e7fc83c542540e3f9f2 Mon Sep 17 00:00:00 2001 From: Dan K Date: Tue, 16 Jul 2019 14:31:01 -0400 Subject: [PATCH 2/6] WIP(ch9s6): update current code --- micro-java/pom.xml | 3 +- micro-java/src/main/fabric8/deployment.yml | 61 ++++++++++++++++++++++ micro-java/src/main/fabric8/route.yml | 19 +++++++ micro-java/src/main/fabric8/svc.yml | 26 +++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 micro-java/src/main/fabric8/deployment.yml create mode 100644 micro-java/src/main/fabric8/route.yml create mode 100644 micro-java/src/main/fabric8/svc.yml diff --git a/micro-java/pom.xml b/micro-java/pom.xml index 79154c6..edaa9bf 100644 --- a/micro-java/pom.xml +++ b/micro-java/pom.xml @@ -28,10 +28,11 @@ 2.5 + 4.1.0 - 1.8 1.8 diff --git a/micro-java/src/main/fabric8/deployment.yml b/micro-java/src/main/fabric8/deployment.yml new file mode 100644 index 0000000..57d2f01 --- /dev/null +++ b/micro-java/src/main/fabric8/deployment.yml @@ -0,0 +1,61 @@ +--- +apiVersion: "v1" +kind: "DeploymentConfig" +metadata: + annotations: + fabric8.io/iconUrl: "img/icons/camel.svg" + labels: + provider: "fabric8" + project: "${env.RHT_OCP4_DEV_USER}-${project.artifactId}" + version: "1.0" + group: "com.redhat.training" + name: "${project.artifactId}" +spec: + replicas: 1 + selector: + project: "${env.RHT_OCP4_DEV_USER}-${project.artifactId}" + provider: "fabric8" + group: "com.redhat.training" + strategy: + rollingParams: + timeoutSeconds: 10800 + type: "Rolling" + template: + metadata: + annotations: + fabric8.io/iconUrl: "img/icons/camel.svg" + labels: + provider: "fabric8" + project: "${env.RHT_OCP4_DEV_USER}-${project.artifactId}" + version: "1.0" + group: "com.redhat.training" + spec: + containers: + - image: "${project.artifactId}:1.0" + imagePullPolicy: "IfNotPresent" + name: "spring-boot" + ports: + - containerPort: 8080 + name: "http" + protocol: "TCP" + #- containerPort: 9081 + # name: "rest" + # protocol: "TCP" + securityContext: + privileged: false + #readinessProbe: + # httpGet: + # path: "/hello/health" + # port: 9081 + # initialDelaySeconds: 20 + triggers: + - type: "ConfigChange" + - imageChangeParams: + automatic: true + containerNames: + - "spring-boot" + from: + kind: "ImageStreamTag" + name: "${project.artifactId}:1.0" + type: "ImageChange" + diff --git a/micro-java/src/main/fabric8/route.yml b/micro-java/src/main/fabric8/route.yml new file mode 100644 index 0000000..1861f0e --- /dev/null +++ b/micro-java/src/main/fabric8/route.yml @@ -0,0 +1,19 @@ +--- +apiVersion: v1 +kind: Route +metadata: + labels: + expose: "true" + app: ${project.artifactId} + provider: fabric8 + version: "1.0" + group: com.redhat.training + name: ${project.artifactId} +spec: +# host: ${hostname} + port: + targetPort: 8080 + to: + kind: Service + name: ${project.artifactId} + diff --git a/micro-java/src/main/fabric8/svc.yml b/micro-java/src/main/fabric8/svc.yml new file mode 100644 index 0000000..8dbcfce --- /dev/null +++ b/micro-java/src/main/fabric8/svc.yml @@ -0,0 +1,26 @@ +--- +apiVersion: v1 +kind: Service +metadata: +# annotations: +# fabric8.io/iconUrl: img/icons/camel.svg + labels: + expose: "true" + app: ${project.artifactId} + provider: fabric8 + version: "1.0" + group: com.redhat.training + name: ${project.artifactId} +spec: + ports: + - name: http-tomcat + port: 8080 + protocol: TCP + targetPort: 8080 +# - name: rest +# port: ${rest-port} +# protocol: TCP +# targetPort: ${rest-port} + selector: + deploymentconfig: ${project.artifactId} + From 4fcb06042fc64f09921c92cb63161de450867f6a Mon Sep 17 00:00:00 2001 From: Dan K Date: Tue, 16 Jul 2019 15:24:45 -0400 Subject: [PATCH 3/6] WIP:feat(ch9s6): remove YAML fragments The YAML fragments are wrong, and are causing issues when deployed. The "Zero Config" option with fabric8 works well. --- micro-java/src/main/fabric8/deployment.yml | 61 ---------------------- micro-java/src/main/fabric8/route.yml | 19 ------- micro-java/src/main/fabric8/svc.yml | 26 --------- 3 files changed, 106 deletions(-) delete mode 100644 micro-java/src/main/fabric8/deployment.yml delete mode 100644 micro-java/src/main/fabric8/route.yml delete mode 100644 micro-java/src/main/fabric8/svc.yml diff --git a/micro-java/src/main/fabric8/deployment.yml b/micro-java/src/main/fabric8/deployment.yml deleted file mode 100644 index 57d2f01..0000000 --- a/micro-java/src/main/fabric8/deployment.yml +++ /dev/null @@ -1,61 +0,0 @@ ---- -apiVersion: "v1" -kind: "DeploymentConfig" -metadata: - annotations: - fabric8.io/iconUrl: "img/icons/camel.svg" - labels: - provider: "fabric8" - project: "${env.RHT_OCP4_DEV_USER}-${project.artifactId}" - version: "1.0" - group: "com.redhat.training" - name: "${project.artifactId}" -spec: - replicas: 1 - selector: - project: "${env.RHT_OCP4_DEV_USER}-${project.artifactId}" - provider: "fabric8" - group: "com.redhat.training" - strategy: - rollingParams: - timeoutSeconds: 10800 - type: "Rolling" - template: - metadata: - annotations: - fabric8.io/iconUrl: "img/icons/camel.svg" - labels: - provider: "fabric8" - project: "${env.RHT_OCP4_DEV_USER}-${project.artifactId}" - version: "1.0" - group: "com.redhat.training" - spec: - containers: - - image: "${project.artifactId}:1.0" - imagePullPolicy: "IfNotPresent" - name: "spring-boot" - ports: - - containerPort: 8080 - name: "http" - protocol: "TCP" - #- containerPort: 9081 - # name: "rest" - # protocol: "TCP" - securityContext: - privileged: false - #readinessProbe: - # httpGet: - # path: "/hello/health" - # port: 9081 - # initialDelaySeconds: 20 - triggers: - - type: "ConfigChange" - - imageChangeParams: - automatic: true - containerNames: - - "spring-boot" - from: - kind: "ImageStreamTag" - name: "${project.artifactId}:1.0" - type: "ImageChange" - diff --git a/micro-java/src/main/fabric8/route.yml b/micro-java/src/main/fabric8/route.yml deleted file mode 100644 index 1861f0e..0000000 --- a/micro-java/src/main/fabric8/route.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -apiVersion: v1 -kind: Route -metadata: - labels: - expose: "true" - app: ${project.artifactId} - provider: fabric8 - version: "1.0" - group: com.redhat.training - name: ${project.artifactId} -spec: -# host: ${hostname} - port: - targetPort: 8080 - to: - kind: Service - name: ${project.artifactId} - diff --git a/micro-java/src/main/fabric8/svc.yml b/micro-java/src/main/fabric8/svc.yml deleted file mode 100644 index 8dbcfce..0000000 --- a/micro-java/src/main/fabric8/svc.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: -# annotations: -# fabric8.io/iconUrl: img/icons/camel.svg - labels: - expose: "true" - app: ${project.artifactId} - provider: fabric8 - version: "1.0" - group: com.redhat.training - name: ${project.artifactId} -spec: - ports: - - name: http-tomcat - port: 8080 - protocol: TCP - targetPort: 8080 -# - name: rest -# port: ${rest-port} -# protocol: TCP -# targetPort: ${rest-port} - selector: - deploymentconfig: ${project.artifactId} - From eaf20b0fe63d0edae705cc260524c13044e66301 Mon Sep 17 00:00:00 2001 From: Dan K Date: Tue, 16 Jul 2019 15:46:12 -0400 Subject: [PATCH 4/6] WIP:fix(ch9s6): add braces for if block --- .../com/redhat/training/openshift/hello/HelloResource.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java index 3db3118..7b39d65 100644 --- a/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java +++ b/micro-java/src/main/java/com/redhat/training/openshift/hello/HelloResource.java @@ -16,12 +16,12 @@ public class HelloResource { String message = System.getenv().getOrDefault("APP_MSG", null); String response = ""; - if (message == null) + if (message == null) { response = "Hello world from host "+hostname+"\n"; - else + } else { response = "Hello world from host ["+hostname+"]."; response += "Message received = "+message+"\n"; - + } return response; } } From 213f25767057aeb33fa6d900e69f26c6675e1bd3 Mon Sep 17 00:00:00 2001 From: Dan K Date: Tue, 16 Jul 2019 16:34:24 -0400 Subject: [PATCH 5/6] WIP:feat(ch9s6): add custom dc and cm resources Use the fabric8 plugin to add a custom deployment config and config map as part of the deployment to OpenShift. --- micro-java/src/main/fabric8/cm.yml | 7 +++++++ micro-java/src/main/fabric8/deployment.yml | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 micro-java/src/main/fabric8/cm.yml create mode 100644 micro-java/src/main/fabric8/deployment.yml diff --git a/micro-java/src/main/fabric8/cm.yml b/micro-java/src/main/fabric8/cm.yml new file mode 100644 index 0000000..a6763d0 --- /dev/null +++ b/micro-java/src/main/fabric8/cm.yml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: env-config +data: + APP_MSG: + diff --git a/micro-java/src/main/fabric8/deployment.yml b/micro-java/src/main/fabric8/deployment.yml new file mode 100644 index 0000000..941530b --- /dev/null +++ b/micro-java/src/main/fabric8/deployment.yml @@ -0,0 +1,11 @@ + + +spec: + template: + spec: + containers: + - envFrom: + - configMapRef: + name: env-config + + From 9963c0bd49817821ec545e3cb1d936f70552ee88 Mon Sep 17 00:00:00 2001 From: Dan K Date: Fri, 19 Jul 2019 10:00:48 -0400 Subject: [PATCH 6/6] style(micro-java): fix pom.xml whitespace --- micro-java/pom.xml | 97 +++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 52 deletions(-) diff --git a/micro-java/pom.xml b/micro-java/pom.xml index edaa9bf..9c8b9cd 100644 --- a/micro-java/pom.xml +++ b/micro-java/pom.xml @@ -1,46 +1,40 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 - com.redhat.training.openshift - micro-java - 1.0 - war - Red Hat Training Hello Java app - Hello microservice using Thorntail + com.redhat.training.openshift + hello + 1.0 + war + Red Hat Training Hello Java app + Hello microservice using Thorntail - - - - UTF-8 - false + + + + UTF-8 + false - - 2.4.0.Final + + 2.4.0.Final - - 3.1 - 2.16 - 2.5 - - - 4.1.0 - - 1.8 - 1.8 + + 3.1 + 2.16 + 2.5 + 4.1.0 - + + 1.8 + 1.8 + - + io.thorntail @@ -52,26 +46,25 @@ - - - io.thorntail - cdi - - - io.thorntail - jaxrs - + + + io.thorntail + cdi + + + io.thorntail + jaxrs + + - - - - - hello - - - - + + + hello + + + + io.thorntail thorntail-maven-plugin ${version.thorntail}