Skip to content

Commit 3473708

Browse files
committed
initial source drop
Signed-off-by: Toby Corbin <[email protected]>
1 parent fe691c0 commit 3473708

File tree

13 files changed

+406
-1
lines changed

13 files changed

+406
-1
lines changed

Diff for: .cw-settings

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"contextRoot": "/api/hello/you",
3+
"internalPort": "9000",
4+
"healthCheck": "",
5+
"watchedFiles": {
6+
"includeFiles": [
7+
""
8+
],
9+
"excludeFiles": [
10+
""
11+
]
12+
}
13+
}

Diff for: Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM maven:3.5.4-jdk-8-alpine AS builder
2+
COPY pom.xml .
3+
COPY hello-api hello-api/
4+
COPY hello-impl hello-impl/
5+
RUN mvn install -DskipTests
6+
7+
FROM fabric8/java-alpine-openjdk8-jre
8+
RUN apk add --no-cache nss
9+
ENV AB_OFF=1 JAVA_MAIN_CLASS=play.core.server.ProdServerStart JAVA_APP_JAR=hello-impl-1.0-SNAPSHOT.jar
10+
LABEL com.lightbend.rp.endpoints.1.protocol="tcp" com.lightbend.rp.endpoints.0.name="hello" com.lightbend.rp.app-version="1.0" com.lightbend.rp.app-name="hello-impl" com.lightbend.rp.config-resource="rp-application.conf" com.lightbend.rp.endpoints.0.ingress.0.paths.0="/api/hello/" com.lightbend.rp.endpoints.0.ingress.0.ingress-ports.0="80" com.lightbend.rp.app-type="lagom" com.lightbend.rp.endpoints.0.protocol="http" com.lightbend.rp.endpoints.0.ingress.0.ingress-ports.1="443" com.lightbend.rp.endpoints.1.name="akka-remote" com.lightbend.rp.reactive-maven-app-version="0.3.1-SNAPSHOT" com.lightbend.rp.modules.status.enabled="true" com.lightbend.rp.modules.common.enabled="true" com.lightbend.rp.modules.akka-management.enabled="true" com.lightbend.rp.modules.service-discovery.enabled="true" com.lightbend.rp.applications.0.name="default" com.lightbend.rp.applications.0.arguments.0="deployments/run-java.sh" com.lightbend.rp.modules.akka-cluster-bootstrap.enabled="true" com.lightbend.rp.modules.play-http-binding.enabled="true" com.lightbend.rp.endpoints.2.name="akka-mgmt-http" com.lightbend.rp.endpoints.2.protocol="tcp" com.lightbend.rp.endpoints.0.ingress.0.type="http"
11+
COPY --from=builder hello-api ./
12+
COPY --from=builder hello-impl ./
13+
COPY --from=builder hello-impl/target/alternateLocation /deployments/
14+
EXPOSE 9000
15+
CMD ["java", "-cp", "/deployments/*", "play.core.server.ProdServerStart"]

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# lagomJavaTemplate
1+
Template for Java Lagom microservice with Maven

Diff for: check.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
test_name="hello-impl"
4+
source ../../../bin/test-common.sh
5+
dockerfile="${test_name}/target/docker/${test_name}/1.0/build/Dockerfile"
6+
7+
if [ -f $dockerfile ]; then
8+
check $dockerfile 'com.lightbend.rp.app-name="hello-impl"'
9+
check $dockerfile 'com.lightbend.rp.app-type="lagom"'
10+
check $dockerfile 'com.lightbend.rp.modules.common.enabled="true"'
11+
check $dockerfile 'com.lightbend.rp.modules.akka-management.enabled="true"'
12+
check $dockerfile 'com.lightbend.rp.modules.service-discovery.enabled="true"'
13+
check $dockerfile 'com.lightbend.rp.modules.akka-cluster-bootstrap.enabled="true"'
14+
15+
check $dockerfile 'com.lightbend.rp.endpoints.0.protocol="http"'
16+
check $dockerfile 'com.lightbend.rp.endpoints.0.ingress.0.type="http"'
17+
check $dockerfile 'com.lightbend.rp.endpoints.0.ingress.0.paths.0="/api/hello/"'
18+
check $dockerfile 'com.lightbend.rp.endpoints.0.ingress.0.ingress-ports.0="80"'
19+
check $dockerfile 'com.lightbend.rp.endpoints.0.ingress.0.ingress-ports.1="443"'
20+
check $dockerfile 'com.lightbend.rp.endpoints.1.name="akka-remote"'
21+
check $dockerfile 'com.lightbend.rp.endpoints.1.protocol="tcp"'
22+
check $dockerfile 'com.lightbend.rp.endpoints.2.name="akka-mgmt-http"'
23+
check $dockerfile 'com.lightbend.rp.endpoints.2.protocol="tcp"'
24+
25+
else
26+
echo "File $dockerfile not found"
27+
exit 1
28+
fi

Diff for: hello-api/pom.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>microclimate.test.lagomendpoints</groupId>
6+
<artifactId>hello</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>hello-api</artifactId>
11+
12+
<packaging>jar</packaging>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.lightbend.lagom</groupId>
17+
<artifactId>lagom-javadsl-api_${scala.binary.version}</artifactId>
18+
</dependency>
19+
</dependencies>
20+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.rp.test.lagomendpoints.api;
2+
3+
import static com.lightbend.lagom.javadsl.api.Service.*;
4+
import akka.NotUsed;
5+
import com.lightbend.lagom.javadsl.api.Descriptor;
6+
import com.lightbend.lagom.javadsl.api.Service;
7+
import com.lightbend.lagom.javadsl.api.ServiceCall;
8+
public interface HelloService extends Service {
9+
ServiceCall<NotUsed, String> hello(String id);
10+
@Override
11+
default Descriptor descriptor() {
12+
// @formatter:off
13+
return named("hello").withCalls(
14+
pathCall("/api/hello/:id", this::hello)
15+
).withAutoAcl(true);
16+
// @formatter:off
17+
}
18+
}

Diff for: hello-impl/pom.xml

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>microclimate.test.lagomendpoints</groupId>
6+
<artifactId>hello</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>hello-impl</artifactId>
10+
<packaging>jar</packaging>
11+
<properties>
12+
<mainClass>play.core.server.ProdServerStart</mainClass>
13+
</properties>
14+
<dependencies>
15+
<dependency>
16+
<groupId>${project.groupId}</groupId>
17+
<artifactId>hello-api</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>com.lightbend.lagom</groupId>
22+
<artifactId>lagom-javadsl-server_${scala.binary.version}</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.lightbend.lagom</groupId>
26+
<artifactId>lagom-logback_${scala.binary.version}</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.lightbend.lagom</groupId>
30+
<artifactId>api-tools_${scala.binary.version}</artifactId>
31+
<version>${lagom.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.typesafe.play</groupId>
35+
<artifactId>play-akka-http-server_${scala.binary.version}</artifactId>
36+
</dependency>
37+
<!-- Service Locator Provider -->
38+
<dependency>
39+
<groupId>com.lightbend.rp</groupId>
40+
<artifactId>reactive-lib-service-discovery-lagom14-java_${scala.binary.version}</artifactId>
41+
<version>0.9.0</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.lightbend.rp</groupId>
45+
<artifactId>reactive-lib-akka-cluster-bootstrap_${scala.binary.version}</artifactId>
46+
<version>0.9.0</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.lightbend.rp</groupId>
50+
<artifactId>reactive-lib-play-http-binding_${scala.binary.version}</artifactId>
51+
<version>0.9.0</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.lightbend.lagom</groupId>
55+
<artifactId>lagom-javadsl-testkit_${scala.binary.version}</artifactId>
56+
<version>${lagom.version}</version>
57+
<scope>test</scope>
58+
</dependency>
59+
</dependencies>
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>com.lightbend.lagom</groupId>
64+
<artifactId>lagom-maven-plugin</artifactId>
65+
<configuration>
66+
<lagomService>true</lagomService>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-dependency-plugin</artifactId>
72+
<executions>
73+
<execution>
74+
<id>copy-dependencies</id>
75+
<phase>package</phase>
76+
<goals>
77+
<goal>copy-dependencies</goal>
78+
</goals>
79+
<configuration>
80+
<includeScope>runtime</includeScope>
81+
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
82+
</configuration>
83+
</execution>
84+
<execution>
85+
<id>copy-installed</id>
86+
<phase>install</phase>
87+
<goals>
88+
<goal>copy</goal>
89+
</goals>
90+
<configuration>
91+
<artifactItems>
92+
<artifactItem>
93+
<groupId>${project.groupId}</groupId>
94+
<artifactId>${project.artifactId}</artifactId>
95+
<version>${project.version}</version>
96+
<type>${project.packaging}</type>
97+
</artifactItem>
98+
</artifactItems>
99+
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
100+
</configuration>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.rp.test.lagomendpoints.impl;
2+
3+
import com.google.inject.AbstractModule;
4+
import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport;
5+
import com.example.rp.test.lagomendpoints.api.HelloService;
6+
7+
/**
8+
* The module that binds the HelloService so that it can be served.
9+
*/
10+
public class HelloModule extends AbstractModule implements ServiceGuiceSupport {
11+
@Override
12+
protected void configure() {
13+
bindService(HelloService.class, HelloServiceImpl.class);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.rp.test.lagomendpoints.impl;
2+
3+
import com.example.rp.test.lagomendpoints.api.HelloService;
4+
import com.lightbend.lagom.javadsl.api.ServiceCall;
5+
import akka.NotUsed;
6+
import java.util.concurrent.CompletableFuture;
7+
8+
public class HelloServiceImpl implements HelloService {
9+
@Override
10+
public ServiceCall<NotUsed, String> hello(String id) {
11+
return request -> CompletableFuture.completedFuture("hello: " + id);
12+
}
13+
}

Diff for: hello-impl/src/main/resources/application.conf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
play.modules.enabled += com.example.rp.test.lagomendpoints.impl.HelloModule
2+
play.crypto.secret = whatever
3+
4+
lagom.services {
5+
hello-impl = "http://localhost:9000"
6+
}
7+
8+
play.modules.enabled +=
9+
"com.lightbend.rp.servicediscovery.lagom.javadsl.ServiceLocatorModule"
10+
11+
play.filters.disabled+=play.filters.hosts.AllowedHostsFilter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.example.rp.test.lagomendpoints.impl;
2+
3+
import org.junit.Test;
4+
5+
import com.example.rp.test.lagomendpoints.api.HelloService;
6+
7+
import static com.lightbend.lagom.javadsl.testkit.ServiceTest.defaultSetup;
8+
import static com.lightbend.lagom.javadsl.testkit.ServiceTest.withServer;
9+
import static java.util.concurrent.TimeUnit.SECONDS;
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class HelloServiceTest {
13+
@Test
14+
public void shouldGreet() {
15+
withServer(defaultSetup(), server -> {
16+
HelloService service = server.client(HelloService.class);
17+
18+
String msg1 = service.hello("Alice").invoke().toCompletableFuture().get(5, SECONDS);
19+
assertEquals("hello: Alice", msg1);
20+
});
21+
}
22+
}

Diff for: hello-impl/src/test/resources/logback.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<conversionRule conversionWord="coloredLevel" converterClass="com.lightbend.lagom.internal.logback.ColoredLevel" />
5+
6+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
7+
<encoder>
8+
<pattern>%date{"HH:mm:ss.SSS"} %coloredLevel %logger - %msg%n</pattern>
9+
</encoder>
10+
</appender>
11+
12+
<logger name="org.apache.cassandra" level="ERROR" />
13+
<logger name="com.datastax.driver" level="WARN" />
14+
15+
<logger name="akka" level="WARN" />
16+
17+
<root level="INFO">
18+
<appender-ref ref="STDOUT" />
19+
</root>
20+
21+
</configuration>

0 commit comments

Comments
 (0)