Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RedHatTraining/DO288-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
richardallred committed Jul 24, 2019
2 parents 8b6479a + 137aecb commit a0872a3
Show file tree
Hide file tree
Showing 25 changed files with 770 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.redhat.training.example.javaserverhost.rest;


import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import java.net.InetAddress;


@Path("/")
public class ServerHostEndPoint {

@GET
@Produces("text/plain")
public Response doGet() {
String host = "";
try {
host = InetAddress.getLocalHost().getHostName();
}
catch (Exception e) {
e.printStackTrace();
}
return Response.ok("I am running on server "+host+" Version 1.0 \n").build();
}
@GET
@Produces("text/plain")
public Response doGet() {
String host = "";
try {
host = InetAddress.getLocalHost().getHostName();
}
catch (Exception e) {
e.printStackTrace();
}
String msg = "I am running on server "+host+" Version 1.0 \n";
return Response.ok(msg).build();
}
}

96 changes: 96 additions & 0 deletions micro-java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.redhat.training.openshift</groupId>
<artifactId>hello</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>Red Hat Training Hello Java app</name>
<description>Hello microservice using Thorntail</description>

<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>

<!-- Thorntail dependency versions -->
<version.thorntail>2.4.0.Final</version.thorntail>

<!-- other plugin versions -->
<version.compiler.plugin>3.1</version.compiler.plugin>
<version.surefire.plugin>2.16</version.surefire.plugin>
<version.war.plugin>2.5</version.war.plugin>
<version.fabric8.plugin>4.1.0</version.fabric8.plugin>

<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom-all</artifactId>
<version>${version.thorntail}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
</dependencies>

<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>hello</finalName>
<plugins>
<!-- The Thorntail Maven plugin creates an uber jar -->
<!-- To use, run: mvn thorntail:run -->
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>${version.fabric8.plugin}</version>
<executions>
<execution>
<id>fmp</id>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Empty file.
Original file line number Diff line number Diff line change
@@ -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+"].\n";
response += "Message received = "+message+"\n";
}
return response;
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
126 changes: 126 additions & 0 deletions todo-api-micro/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.redhat.training.example</groupId>
<artifactId>todo-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>ToDo API Thorntail Example</name>
<description>ToDo API microservice using Thorntail</description>

<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>

<!-- Thorntail dependency versions -->
<version.thorntail>2.4.0.Final</version.thorntail>

<!-- MySQL JDBC Connector -->
<version.mysql>8.0.16</version.mysql>

<!-- other plugin versions -->
<version.compiler.plugin>3.1</version.compiler.plugin>
<version.surefire.plugin>2.16</version.surefire.plugin>
<version.war.plugin>2.5</version.war.plugin>
<version.fabric8.plugin>4.1.0</version.fabric8.plugin>

<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>


<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom-all</artifactId>
<version>${version.thorntail}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs-jsonp</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jpa</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>ejb</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>datasources</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>cdi</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${version.mysql}</version>
</dependency>
</dependencies>

<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>hello</finalName>
<plugins>
<!-- The Thorntail Maven plugin creates an uber jar -->
<!-- To use, run: mvn thorntail:run -->
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>${version.fabric8.plugin}</version>
<executions>
<execution>
<id>fmp</id>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
21 changes: 21 additions & 0 deletions todo-api-micro/src/main/fabric8/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
spec:
template:
spec:
containers:
-
resources:
requests:
cpu: "0.2"
# memory: 256Mi
limits:
cpu: "1.0"
# memory: 256Mi
env:
- name: DATABASE_USER
value: '${database.user}'
- name: DATABASE_PASSWORD
value: '${database.password}'
- name: DATABASE_SVC_HOSTNAME
value: '${database.svc.hostname}'
- name: DATABASE_NAME
value: '${database.name}'
18 changes: 18 additions & 0 deletions todo-api-micro/src/main/fabric8/route.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
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: ${service-port}
to:
kind: Service
name: ${project.artifactId}
21 changes: 21 additions & 0 deletions todo-api-micro/src/main/fabric8/svc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
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
port: ${service-port}
protocol: TCP
targetPort: ${service-port}
selector:
deploymentconfig: ${project.artifactId}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.redhat.training.example.todoapi.rest;


import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;


@Path("/hello")
public class HelloWorldEndpoint {

@GET
@Produces("text/plain")
public Response doGet() {
return Response.ok("Hello World!").build();

}
}
Loading

0 comments on commit a0872a3

Please sign in to comment.