diff --git a/api-gateway-service/.gitignore b/api-gateway-service/.gitignore
deleted file mode 100644
index 2af7cef..0000000
--- a/api-gateway-service/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-target/
-!.mvn/wrapper/maven-wrapper.jar
-
-### STS ###
-.apt_generated
-.classpath
-.factorypath
-.project
-.settings
-.springBeans
-
-### IntelliJ IDEA ###
-.idea
-*.iws
-*.iml
-*.ipr
-
-### NetBeans ###
-nbproject/private/
-build/
-nbbuild/
-dist/
-nbdist/
-.nb-gradle/
\ No newline at end of file
diff --git a/api-gateway-service/pom.xml b/api-gateway-service/pom.xml
index 9a6df66..d91da73 100644
--- a/api-gateway-service/pom.xml
+++ b/api-gateway-service/pom.xml
@@ -23,14 +23,18 @@
UTF-8
1.8
Dalston.RELEASE
+ ${basedir}/src/main/docker
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
org.springframework.cloud
spring-cloud-starter-zuul
-
org.springframework.cloud
spring-cloud-starter-eureka
@@ -61,8 +65,48 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
+
+ com.spotify
+ docker-maven-plugin
+ 1.0.0
+
+
+ build-image
+ install
+
+ build
+
+
+
+
+ ${project.artifactId}
+ ${docker.baseDir}
+
+
+ /
+ ${project.build.directory}
+ ${project.artifactId}.jar
+
+
+
+
-
-
diff --git a/api-gateway-service/src/main/docker/Dockerfile b/api-gateway-service/src/main/docker/Dockerfile
new file mode 100644
index 0000000..46c7064
--- /dev/null
+++ b/api-gateway-service/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD api-gateway-service.jar api-gateway-service.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./api-gateway-service.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/api-gateway-service/src/main/docker/wrapper.sh b/api-gateway-service/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..ff22074
--- /dev/null
+++ b/api-gateway-service/src/main/docker/wrapper.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting api-gateway server immediately"
+ java -jar ./api-gateway-service.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+REALTOR_SERVICE=${REALTOR_SERVICE:='realtor-service'}
+echo "Trying to get '${REALTOR_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${REALTOR_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+CLIENT_SERVICE=${CLIENT_SERVICE:='client-service'}
+echo "Trying to get '${CLIENT_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CLIENT_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+echo "Starting api-gateway server"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./api-gateway-service.jar
diff --git a/api-gateway-service/src/main/java/com/lohika/jclub/ApiGatewayServiceApplication.java b/api-gateway-service/src/main/java/com/lohika/jclub/gateway/ApiGatewayServiceApplication.java
similarity index 93%
rename from api-gateway-service/src/main/java/com/lohika/jclub/ApiGatewayServiceApplication.java
rename to api-gateway-service/src/main/java/com/lohika/jclub/gateway/ApiGatewayServiceApplication.java
index c6fc518..0fcd3bc 100644
--- a/api-gateway-service/src/main/java/com/lohika/jclub/ApiGatewayServiceApplication.java
+++ b/api-gateway-service/src/main/java/com/lohika/jclub/gateway/ApiGatewayServiceApplication.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/api-gateway-service/src/main/resources/application.properties b/api-gateway-service/src/main/resources/application.properties
index be41be7..b08c729 100644
--- a/api-gateway-service/src/main/resources/application.properties
+++ b/api-gateway-service/src/main/resources/application.properties
@@ -1,2 +1,14 @@
spring.application.name=api-gateway-service
-server.port=8090
\ No newline at end of file
+server.port=8090
+
+eureka.instance.preferIpAddress=true
+
+feign.hystrix.enabled=true
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Api gateway service
diff --git a/api-gateway-service/src/test/java/com/lohika/jclub/ApiGatewayServiceApplicationTests.java b/api-gateway-service/src/test/java/com/lohika/jclub/gateway/ApiGatewayServiceApplicationTests.java
similarity index 90%
rename from api-gateway-service/src/test/java/com/lohika/jclub/ApiGatewayServiceApplicationTests.java
rename to api-gateway-service/src/test/java/com/lohika/jclub/gateway/ApiGatewayServiceApplicationTests.java
index fcc36bd..9bc4c69 100644
--- a/api-gateway-service/src/test/java/com/lohika/jclub/ApiGatewayServiceApplicationTests.java
+++ b/api-gateway-service/src/test/java/com/lohika/jclub/gateway/ApiGatewayServiceApplicationTests.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.gateway;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/api-gateway-service/src/test/resources/application.properties b/api-gateway-service/src/test/resources/application.properties
new file mode 100644
index 0000000..45cb06e
--- /dev/null
+++ b/api-gateway-service/src/test/resources/application.properties
@@ -0,0 +1 @@
+eureka.client.enabled=false
diff --git a/api-gateway-service/src/test/resources/banner.txt b/api-gateway-service/src/test/resources/banner.txt
new file mode 100644
index 0000000..0678e6b
--- /dev/null
+++ b/api-gateway-service/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ ___ _ __ _
+ /_ __/ ____/ ___/_ __/ / | ____ (_) ____ _____ _/ /____ _ ______ ___ __ ________ ______ __(_)_______
+ / / / __/ \__ \ / / / /| | / __ \/ / / __ `/ __ `/ __/ _ \ | /| / / __ `/ / / / / ___/ _ \/ ___/ | / / / ___/ _ \
+ / / / /___ ___/ // / / ___ |/ /_/ / / / /_/ / /_/ / /_/ __/ |/ |/ / /_/ / /_/ / (__ ) __/ / | |/ / / /__/ __/
+/_/ /_____//____//_/ /_/ |_/ .___/_/ \__, /\__,_/\__/\___/|__/|__/\__,_/\__, / /____/\___/_/ |___/_/\___/\___/
+ /_/ /____/ /____/
diff --git a/api-gateway-service/src/test/resources/logback-test.xml b/api-gateway-service/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/api-gateway-service/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client-service/pom.xml b/client-service/pom.xml
index 3864989..777186b 100644
--- a/client-service/pom.xml
+++ b/client-service/pom.xml
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -23,9 +23,21 @@
UTF-8
1.8
Dalston.RELEASE
+ springio
+ ${basedir}/src/main/docker
+
+ com.lohika.jclub.storage
+ storage-service-client
+ 0.0.1-SNAPSHOT
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
org.springframework.cloud
spring-cloud-starter-eureka
@@ -34,30 +46,25 @@
org.springframework.boot
spring-boot-starter-web
-
- org.springframework.boot
- spring-boot-starter-test
- test
+ org.springframework.cloud
+ spring-cloud-starter-feign
+
org.projectlombok
lombok
- 1.16.12
-
-
- org.springframework.cloud
- spring-cloud-starter-feign
+
- com.lohika.jclub.storage.client
- storage-service-client
- 0.0.1-SNAPSHOT
+ org.springframework.boot
+ spring-boot-starter-test
+ test
org.testcontainers
testcontainers
- 1.3.0
+ 1.4.2
test
@@ -80,6 +87,23 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
com.spotify
docker-maven-plugin
@@ -94,18 +118,17 @@
- client-service
- java
- ["java", "-jar", "/${project.build.finalName}.jar"]
+ ${project.artifactId}
+ ${docker.baseDir}
/
${project.build.directory}
- ${project.build.finalName}.jar
+ ${project.artifactId}.jar
-
\ No newline at end of file
+
diff --git a/client-service/src/main/docker/Dockerfile b/client-service/src/main/docker/Dockerfile
new file mode 100644
index 0000000..53d173c
--- /dev/null
+++ b/client-service/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD client-service.jar client-service.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./client-service.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/client-service/src/main/docker/wrapper.sh b/client-service/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..8a3b12a
--- /dev/null
+++ b/client-service/src/main/docker/wrapper.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting config server immediately"
+ java -jar ./client-service.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'}
+echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+echo "Starting client service"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./client-service.jar
diff --git a/client-service/src/main/java/com/lohika/jclub/client/ClientController.java b/client-service/src/main/java/com/lohika/jclub/client/ClientController.java
index f52eeed..da51de1 100644
--- a/client-service/src/main/java/com/lohika/jclub/client/ClientController.java
+++ b/client-service/src/main/java/com/lohika/jclub/client/ClientController.java
@@ -5,11 +5,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.PagedResources;
+import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
+import javax.annotation.PostConstruct;
+
@Slf4j
@RestController
public class ClientController {
@@ -17,10 +20,14 @@ public class ClientController {
@Autowired
private StorageServiceClient storageServiceClient;
- @GetMapping("/apartments")
+ @PostConstruct
+ public void warmUp() {
+ storageServiceClient.list();
+ }
+
+ @GetMapping(value = "/apartments", produces = MediaType.APPLICATION_JSON_VALUE)
public PagedResources getApartments() {
PagedResources list = storageServiceClient.list();
return new PagedResources<>(list.getContent(), list.getMetadata());
}
-
-}
\ No newline at end of file
+}
diff --git a/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java b/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java
index 55a2b86..86cd567 100644
--- a/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java
+++ b/client-service/src/main/java/com/lohika/jclub/client/ClientServiceApplication.java
@@ -1,15 +1,17 @@
package com.lohika.jclub.client;
import com.lohika.jclub.storage.client.EnableStorageServiceClient;
+import com.lohika.jclub.storage.client.StorageServiceClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.loadbalancer.LoadBalanced;
-import org.springframework.context.annotation.Bean;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
-@SpringBootApplication
+@EnableDiscoveryClient
@EnableStorageServiceClient
+@EnableFeignClients(clients = {StorageServiceClient.class})
+@SpringBootApplication
public class ClientServiceApplication {
public static void main(String[] args) {
diff --git a/client-service/src/main/resources/application.properties b/client-service/src/main/resources/application.properties
index 60ea3d6..b327fe7 100644
--- a/client-service/src/main/resources/application.properties
+++ b/client-service/src/main/resources/application.properties
@@ -1,3 +1,12 @@
spring.application.name=client-service
server.port=8083
-eureka.instance.prefer-ip-address=true
\ No newline at end of file
+
+eureka.instance.prefer-ip-address=true
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Client service
diff --git a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java
index 2e878f6..92d97f4 100644
--- a/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java
+++ b/client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java
@@ -4,8 +4,6 @@
import com.lohika.jclub.storage.client.StorageServiceClient;
import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,11 +19,10 @@
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.LogMessageWaitStrategy;
-import java.time.Duration;
-
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
-@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ClientServiceApplication.class)
@ContextConfiguration(initializers = ClientServiceTest.Initializer.class)
@@ -33,16 +30,9 @@
public class ClientServiceTest {
@ClassRule
- public static GenericContainer discoveryService = new GenericContainer("discovery-service:latest")
- .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started EurekaServerApplication in.*\\s"))
- .withExposedPorts(8761);
-
- @Rule
- public GenericContainer storageService = new GenericContainer("storage-service:latest")
- .withExposedPorts(8091)
- .withEnv("eureka.client.serviceUrl.defaultZone", "http://" + discoveryService.getContainerIpAddress() + ":" + discoveryService.getMappedPort(8761) + "/eureka")
- .withEnv("eureka.instance.preferIpAddress", "true")
- .waitingFor(new LogMessageWaitStrategy().withRegEx(".*DiscoveryClient_STORAGE-SERVICE.*registration status: 204.*\\s"));
+ public static GenericContainer storageService = new GenericContainer("storage-service:latest")
+ .withExposedPorts(8091)
+ .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started StorageServiceApplication in.*\\s"));
@Autowired
private StorageServiceClient storageServiceClient;
@@ -50,16 +40,6 @@ public class ClientServiceTest {
@Autowired
private MockMvc mockMvc;
- public static class Initializer implements ApplicationContextInitializer {
- @Override
- public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
- EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
- "eureka.client.serviceUrl.defaultZone=http://" + discoveryService.getContainerIpAddress() +
- ":" + discoveryService.getMappedPort(8761) + "/eureka",
- "storage-service.ribbon.servers=http://");
- }
- }
-
@Test
public void testGetApartments() throws Exception {
// Given
@@ -73,6 +53,9 @@ public void testGetApartments() throws Exception {
.sqft(55)
.build());
+ assertThat(lviv, notNullValue());
+ assertThat(lviv.getId(), notNullValue());
+
// When
mockMvc.perform(MockMvcRequestBuilders.get("/apartments"))
.andDo(print());
@@ -81,4 +64,15 @@ public void testGetApartments() throws Exception {
//TODO storageServiceClient does not creating the records.
// fallback is working with 0 paging
}
+
+ public static class Initializer implements ApplicationContextInitializer {
+ @Override
+ public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
+
+ EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
+ "storage-service.ribbon.servers=http://" + storageService.getContainerIpAddress() + ":"
+ + storageService.getMappedPort(8091) + "/"
+ );
+ }
+ }
}
diff --git a/client-service/src/test/resources/application.properties b/client-service/src/test/resources/application.properties
index ffb7b0f..c67637e 100644
--- a/client-service/src/test/resources/application.properties
+++ b/client-service/src/test/resources/application.properties
@@ -1 +1,2 @@
-feign.hystrix.enabled=true
\ No newline at end of file
+eureka.client.enabled=false
+feign.hystrix.enabled=true
diff --git a/client-service/src/test/resources/banner.txt b/client-service/src/test/resources/banner.txt
new file mode 100644
index 0000000..140d107
--- /dev/null
+++ b/client-service/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ _________ __ _
+ /_ __/ ____/ ___/_ __/ / ____/ (_)__ ____ / /_ ________ ______ __(_)_______
+ / / / __/ \__ \ / / / / / / / _ \/ __ \/ __/ / ___/ _ \/ ___/ | / / / ___/ _ \
+ / / / /___ ___/ // / / /___/ / / __/ / / / /_ (__ ) __/ / | |/ / / /__/ __/
+/_/ /_____//____//_/ \____/_/_/\___/_/ /_/\__/ /____/\___/_/ |___/_/\___/\___/
+
diff --git a/config-server/pom.xml b/config-server/pom.xml
index d49e884..22fd59d 100644
--- a/config-server/pom.xml
+++ b/config-server/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub
+ com.lohika.jclub.config
config-server
0.0.1-SNAPSHOT
jar
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -23,6 +23,7 @@
UTF-8
1.8
Dalston.RELEASE
+ ${basedir}/src/main/docker
@@ -30,22 +31,20 @@
org.springframework.boot
spring-boot-starter-actuator
-
org.springframework.cloud
spring-cloud-config-server
+
+ org.springframework.cloud
+ spring-cloud-starter-eureka
+
org.springframework.boot
spring-boot-starter-test
test
-
-
- org.springframework.cloud
- spring-cloud-starter-eureka
-
@@ -66,8 +65,48 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
+
+ com.spotify
+ docker-maven-plugin
+ 1.0.0
+
+
+ build-image
+ install
+
+ build
+
+
+
+
+ ${project.artifactId}
+ ${docker.baseDir}
+
+
+ /
+ ${project.build.directory}
+ ${project.artifactId}.jar
+
+
+
+
-
-
diff --git a/config-server/src/main/docker/Dockerfile b/config-server/src/main/docker/Dockerfile
new file mode 100644
index 0000000..2533832
--- /dev/null
+++ b/config-server/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD config-server.jar config-server.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./config-server.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/config-server/src/main/docker/wrapper.sh b/config-server/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..30c451d
--- /dev/null
+++ b/config-server/src/main/docker/wrapper.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting config server immediately"
+ java -jar ./config-server.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+sleep 15
+echo "Starting config server"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./config-server.jar
diff --git a/config-server/src/main/java/com/lohika/jclub/ConfigServerApplication.java b/config-server/src/main/java/com/lohika/jclub/config/server/ConfigServerApplication.java
similarity index 92%
rename from config-server/src/main/java/com/lohika/jclub/ConfigServerApplication.java
rename to config-server/src/main/java/com/lohika/jclub/config/server/ConfigServerApplication.java
index 14a0d57..ce41796 100644
--- a/config-server/src/main/java/com/lohika/jclub/ConfigServerApplication.java
+++ b/config-server/src/main/java/com/lohika/jclub/config/server/ConfigServerApplication.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.config.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/config-server/src/main/resources/application.properties b/config-server/src/main/resources/application.properties
index 4cf2381..a7f854e 100644
--- a/config-server/src/main/resources/application.properties
+++ b/config-server/src/main/resources/application.properties
@@ -5,3 +5,13 @@ spring.cloud.config.discovery.enabled=true
spring.application.name=config-server
server.port=8888
+
+eureka.instance.preferIpAddress=true
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Config server
diff --git a/config-server/src/test/java/com/lohika/jclub/ConfigServerApplicationTests.java b/config-server/src/test/java/com/lohika/jclub/config/server/ConfigServerApplicationTests.java
similarity index 88%
rename from config-server/src/test/java/com/lohika/jclub/ConfigServerApplicationTests.java
rename to config-server/src/test/java/com/lohika/jclub/config/server/ConfigServerApplicationTests.java
index f38b62a..7609dcc 100644
--- a/config-server/src/test/java/com/lohika/jclub/ConfigServerApplicationTests.java
+++ b/config-server/src/test/java/com/lohika/jclub/config/server/ConfigServerApplicationTests.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.config.server;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/config-server/src/test/resources/application.properties b/config-server/src/test/resources/application.properties
new file mode 100644
index 0000000..ba18ddd
--- /dev/null
+++ b/config-server/src/test/resources/application.properties
@@ -0,0 +1,3 @@
+spring.cloud.config.server.git.uri=${JAVA_CLUB_SRC_HOME}/spring-cloud
+eureka.client.enabled=false
+spring.cloud.config.discovery.enabled=false
diff --git a/config-server/src/test/resources/banner.txt b/config-server/src/test/resources/banner.txt
new file mode 100644
index 0000000..afa28aa
--- /dev/null
+++ b/config-server/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ ______ _____
+ /_ __/ ____/ ___/_ __/ / ____/___ ____ / __(_)___ _ ________ ______ _____ _____
+ / / / __/ \__ \ / / / / / __ \/ __ \/ /_/ / __ `/ / ___/ _ \/ ___/ | / / _ \/ ___/
+ / / / /___ ___/ // / / /___/ /_/ / / / / __/ / /_/ / (__ ) __/ / | |/ / __/ /
+/_/ /_____//____//_/ \____/\____/_/ /_/_/ /_/\__, / /____/\___/_/ |___/\___/_/
+ /____/
diff --git a/config-server/src/test/resources/logback-test.xml b/config-server/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/config-server/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/discovery-server/pom.xml b/discovery-server/pom.xml
index 1107e2c..3eb086f 100644
--- a/discovery-server/pom.xml
+++ b/discovery-server/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub
+ com.lohika.jclub.discovery
discovery-server
0.0.1-SNAPSHOT
jar
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -23,9 +23,14 @@
UTF-8
1.8
Dalston.RELEASE
+ ${basedir}/src/main/docker
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
org.springframework.cloud
spring-cloud-starter-eureka-server
@@ -56,6 +61,23 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
com.spotify
docker-maven-plugin
@@ -70,20 +92,17 @@
- discovery-service
- java
- ["java", "-jar", "/${project.build.finalName}.jar"]
+ ${project.artifactId}
+ ${docker.baseDir}
/
${project.build.directory}
- ${project.build.finalName}.jar
+ ${project.artifactId}.jar
-
-
diff --git a/discovery-server/src/main/docker/Dockerfile b/discovery-server/src/main/docker/Dockerfile
new file mode 100644
index 0000000..bd2406e
--- /dev/null
+++ b/discovery-server/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD discovery-server.jar discovery-server.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./discovery-server.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/discovery-server/src/main/docker/wrapper.sh b/discovery-server/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..367e86f
--- /dev/null
+++ b/discovery-server/src/main/docker/wrapper.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+java -jar ./discovery-server.jar
diff --git a/discovery-server/src/main/java/com/lohika/jclub/EurekaServerApplication.java b/discovery-server/src/main/java/com/lohika/jclub/discovery/server/EurekaServerApplication.java
similarity index 90%
rename from discovery-server/src/main/java/com/lohika/jclub/EurekaServerApplication.java
rename to discovery-server/src/main/java/com/lohika/jclub/discovery/server/EurekaServerApplication.java
index 54c5952..858b42c 100644
--- a/discovery-server/src/main/java/com/lohika/jclub/EurekaServerApplication.java
+++ b/discovery-server/src/main/java/com/lohika/jclub/discovery/server/EurekaServerApplication.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.discovery.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/discovery-server/src/main/resources/application.properties b/discovery-server/src/main/resources/application.properties
index bac323d..ff0b0ef 100644
--- a/discovery-server/src/main/resources/application.properties
+++ b/discovery-server/src/main/resources/application.properties
@@ -1,5 +1,13 @@
-spring.application.name=eureka-server
+spring.application.name=discovery-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Discovery server
diff --git a/discovery-server/src/test/java/com/lohika/jclub/EurekaServerApplicationTests.java b/discovery-server/src/test/java/com/lohika/jclub/discovery/server/EurekaServerApplicationTests.java
similarity index 87%
rename from discovery-server/src/test/java/com/lohika/jclub/EurekaServerApplicationTests.java
rename to discovery-server/src/test/java/com/lohika/jclub/discovery/server/EurekaServerApplicationTests.java
index b26359b..2eb3f2b 100644
--- a/discovery-server/src/test/java/com/lohika/jclub/EurekaServerApplicationTests.java
+++ b/discovery-server/src/test/java/com/lohika/jclub/discovery/server/EurekaServerApplicationTests.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.discovery.server;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/discovery-server/src/test/resources/banner.txt b/discovery-server/src/test/resources/banner.txt
new file mode 100644
index 0000000..01249a8
--- /dev/null
+++ b/discovery-server/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ ____ _
+ /_ __/ ____/ ___/_ __/ / __ \(_)_____________ _ _____ _______ __ ________ ______ _____ _____
+ / / / __/ \__ \ / / / / / / / ___/ ___/ __ \ | / / _ \/ ___/ / / / / ___/ _ \/ ___/ | / / _ \/ ___/
+ / / / /___ ___/ // / / /_/ / (__ ) /__/ /_/ / |/ / __/ / / /_/ / (__ ) __/ / | |/ / __/ /
+/_/ /_____//____//_/ /_____/_/____/\___/\____/|___/\___/_/ \__, / /____/\___/_/ |___/\___/_/
+ /____/
diff --git a/discovery-server/src/test/resources/logback-test.xml b/discovery-server/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/discovery-server/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dsl/pom.xml b/dsl-core/pom.xml
similarity index 90%
rename from dsl/pom.xml
rename to dsl-core/pom.xml
index a8c8164..5dce9d0 100644
--- a/dsl/pom.xml
+++ b/dsl-core/pom.xml
@@ -4,12 +4,12 @@
4.0.0
com.lohika.jclub.dsl
- dsl
+ dsl-core
0.0.1-SNAPSHOT
jar
- DSL
- DSL
+ DSL Core
+ DSL core
UTF-8
@@ -25,6 +25,7 @@
org.apache.maven.plugins
maven-compiler-plugin
+ 3.6.1
groovy-eclipse-compiler
@@ -53,12 +54,12 @@
${groovy.version}
- com.lohika.jclub.storage.client
+ com.lohika.jclub.storage
storage-service-client
0.0.1-SNAPSHOT
- com.lohika.jclub.rating.client
+ com.lohika.jclub.rating
rating-service-client
0.0.1-SNAPSHOT
diff --git a/dsl/src/main/groovy/com/lohika/jclub/dsl/ApartmentDsl.groovy b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/ApartmentDsl.groovy
similarity index 93%
rename from dsl/src/main/groovy/com/lohika/jclub/dsl/ApartmentDsl.groovy
rename to dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/ApartmentDsl.groovy
index 6edcb53..0e51d14 100644
--- a/dsl/src/main/groovy/com/lohika/jclub/dsl/ApartmentDsl.groovy
+++ b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/ApartmentDsl.groovy
@@ -1,4 +1,4 @@
-package com.lohika.jclub.dsl
+package com.lohika.jclub.dsl.core
import com.lohika.jclub.storage.client.Apartment
import groovy.transform.builder.Builder
diff --git a/dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/MyDsl.groovy
similarity index 97%
rename from dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy
rename to dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/MyDsl.groovy
index b5ea678..ed8ba84 100644
--- a/dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy
+++ b/dsl-core/src/main/groovy/com/lohika/jclub/dsl/core/MyDsl.groovy
@@ -1,4 +1,4 @@
-package com.lohika.jclub.dsl
+package com.lohika.jclub.dsl.core
import com.lohika.jclub.rating.client.Apartment
import com.lohika.jclub.rating.client.RatingServiceClient
diff --git a/dsl/src/main/java/package-info.java b/dsl-core/src/main/java/package-info.java
similarity index 100%
rename from dsl/src/main/java/package-info.java
rename to dsl-core/src/main/java/package-info.java
diff --git a/dsl/src/main/resources/idea.gdsl b/dsl-core/src/main/resources/idea.gdsl
similarity index 100%
rename from dsl/src/main/resources/idea.gdsl
rename to dsl-core/src/main/resources/idea.gdsl
diff --git a/dsl-executor-service/pom.xml b/dsl-executor-service/pom.xml
index bff61af..e7e0e76 100644
--- a/dsl-executor-service/pom.xml
+++ b/dsl-executor-service/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub.dsl.service
+ com.lohika.jclub.dsl
dsl-executor-service
0.0.1-SNAPSHOT
jar
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -23,22 +23,28 @@
UTF-8
1.8
Dalston.RELEASE
+ ${basedir}/src/main/docker
- com.lohika.jclub.storage.client
+ com.lohika.jclub.dsl
+ dsl-core
+ 0.0.1-SNAPSHOT
+
+
+ com.lohika.jclub.storage
storage-service-client
0.0.1-SNAPSHOT
- com.lohika.jclub.rating.client
+ com.lohika.jclub.rating
rating-service-client
0.0.1-SNAPSHOT
- com.lohika.jclub.dsl
- dsl
+ com.lohika.jclub.hackster
+ hackster-service-client
0.0.1-SNAPSHOT
@@ -60,6 +66,12 @@
groovy
2.4.11
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
@@ -74,4 +86,54 @@
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
+
+ com.spotify
+ docker-maven-plugin
+ 1.0.0
+
+
+ build-image
+ install
+
+ build
+
+
+
+
+ ${project.artifactId}
+ ${docker.baseDir}
+
+
+ /
+ ${project.build.directory}
+ ${project.artifactId}.jar
+
+
+
+
+
+
diff --git a/dsl-executor-service/src/main/docker/Dockerfile b/dsl-executor-service/src/main/docker/Dockerfile
new file mode 100644
index 0000000..65b90b5
--- /dev/null
+++ b/dsl-executor-service/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD dsl-executor-service.jar dsl-executor-service.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./dsl-executor-service.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/dsl-executor-service/src/main/docker/wrapper.sh b/dsl-executor-service/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..9931c0a
--- /dev/null
+++ b/dsl-executor-service/src/main/docker/wrapper.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting dsl-executor server immediately"
+ java -jar ./dsl-executor-service.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'}
+echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+RATING_SERVICE=${RATING_SERVICE:='rating-service'}
+echo "Trying to get '${RATING_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${RATING_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+HACKSTER_SERVICE=${HACKSTER_SERVICE:='hackster-service'}
+echo "Trying to get '${HACKSTER_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${HACKSTER_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+echo "Starting dsl-executor server"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./dsl-executor-service.jar
diff --git a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java
index 0ffaf89..4ce0531 100644
--- a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java
+++ b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java
@@ -1,9 +1,8 @@
package com.lohika.jclub.dsl.service;
-import com.lohika.jclub.dsl.MyDsl;
+import com.lohika.jclub.dsl.core.MyDsl;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,9 +14,6 @@
@RequestMapping(path = "/dsl")
public class DslController {
- @Value("${dsl.basepath}")
- private String basepath;
-
@Autowired
private DslService dslService;
diff --git a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java
index 52a54ee..1953e1f 100644
--- a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java
+++ b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java
@@ -3,7 +3,7 @@
import groovy.lang.GroovyShell;
import groovy.util.DelegatingScript;
-import com.lohika.jclub.dsl.MyDsl;
+import com.lohika.jclub.dsl.core.MyDsl;
import com.lohika.jclub.rating.client.RatingServiceClient;
import com.lohika.jclub.storage.client.StorageServiceClient;
@@ -17,6 +17,8 @@
import java.nio.file.Files;
import java.nio.file.Paths;
+import javax.annotation.PostConstruct;
+
@Service
public class DslService {
private static final String DSL_EXTENSION = ".mydsl";
@@ -30,6 +32,11 @@ public class DslService {
@Autowired
private RatingServiceClient ratingServiceClient;
+ @PostConstruct
+ public void warmUp() {
+ storageServiceClient.list();
+ }
+
public MyDsl runScript(String scriptName) throws IOException {
String script = getScriptByName(scriptName);
return run(script);
diff --git a/dsl-executor-service/src/main/resources/application.properties b/dsl-executor-service/src/main/resources/application.properties
index 31769f9..6aa6ec6 100644
--- a/dsl-executor-service/src/main/resources/application.properties
+++ b/dsl-executor-service/src/main/resources/application.properties
@@ -7,6 +7,8 @@ eureka.instance.preferIpAddress=true
feign.hystrix.enabled=true
+management.security.enabled=false
+
endpoints.info.id=info
endpoints.info.sensitive=false
endpoints.info.enabled=true
diff --git a/dsl-executor-service/src/test/java/com/lohika/jclub/dsl/service/DslServiceApplicationTests.java b/dsl-executor-service/src/test/java/com/lohika/jclub/dsl/service/DslServiceApplicationTests.java
new file mode 100644
index 0000000..215e745
--- /dev/null
+++ b/dsl-executor-service/src/test/java/com/lohika/jclub/dsl/service/DslServiceApplicationTests.java
@@ -0,0 +1,32 @@
+package com.lohika.jclub.dsl.service;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.util.EnvironmentTestUtils;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@ContextConfiguration(initializers = DslServiceApplicationTests.Initializer.class)
+public class DslServiceApplicationTests {
+
+ @Test
+ public void testContextLoad() {
+ }
+
+ public static class Initializer implements ApplicationContextInitializer {
+ @Override
+ public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
+
+ EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
+ "storage-service.ribbon.servers=http://not-existing-url/",
+ "rating-service.ribbon.servers=http://not-existing-url/",
+ "hackster-service.ribbon.servers=http://not-existing-url/"
+ );
+ }
+ }
+}
diff --git a/dsl-executor-service/src/test/resources/application.properties b/dsl-executor-service/src/test/resources/application.properties
new file mode 100644
index 0000000..3da79e9
--- /dev/null
+++ b/dsl-executor-service/src/test/resources/application.properties
@@ -0,0 +1,3 @@
+eureka.client.enabled=false
+feign.hystrix.enabled=true
+dsl.basepath=dsl-scripts/
diff --git a/dsl-executor-service/src/test/resources/banner.txt b/dsl-executor-service/src/test/resources/banner.txt
new file mode 100644
index 0000000..5776224
--- /dev/null
+++ b/dsl-executor-service/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ ____ __ __ _
+ /_ __/ ____/ ___/_ __/ / __ \_____/ / ___ _ _____ _______ __/ /_____ _____ ________ ______ __(_)_______
+ / / / __/ \__ \ / / / / / / ___/ / / _ \| |/_/ _ \/ ___/ / / / __/ __ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \
+ / / / /___ ___/ // / / /_/ (__ ) / / __/> __/ /__/ /_/ / /_/ /_/ / / (__ ) __/ / | |/ / / /__/ __/
+/_/ /_____//____//_/ /_____/____/_/ \___/_/|_|\___/\___/\__,_/\__/\____/_/ /____/\___/_/ |___/_/\___/\___/
+
diff --git a/dsl-executor-service/src/test/resources/logback-test.xml b/dsl-executor-service/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/dsl-executor-service/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/hackster-service-client/pom.xml b/hackster-service-client/pom.xml
index 8583e63..0c8c334 100644
--- a/hackster-service-client/pom.xml
+++ b/hackster-service-client/pom.xml
@@ -4,12 +4,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub.hackster.client
+ com.lohika.jclub.hackster
hackster-service-client
0.0.1-SNAPSHOT
jar
- hackster-service-client
+ Hackster service client
Client library for Hackster Service
@@ -50,13 +50,19 @@
true
+
+ com.lohika.jclub.hackster
+ hackster-service
+ 0.0.1-SNAPSHOT
+ test
+
org.springframework.boot
spring-boot-starter-test
test
- com.lohika.jclub
+ com.lohika.jclub.discovery
discovery-server
0.0.1-SNAPSHOT
test
@@ -64,13 +70,7 @@
org.testcontainers
testcontainers
- 1.3.0
- test
-
-
- com.lohika.jclub
- hackster-service
- 0.0.1-SNAPSHOT
+ 1.4.2
test
diff --git a/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java b/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java
index e651856..2b2b3ce 100644
--- a/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java
+++ b/hackster-service-client/src/main/java/com/lohika/jclub/hackster/client/EnableHacksterServiceClient.java
@@ -1,9 +1,7 @@
package com.lohika.jclub.hackster.client;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Import;
-import org.springframework.hateoas.config.EnableHypermediaSupport;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@@ -15,9 +13,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Documented
-@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
@EnableFeignClients(clients = {HacksterServiceClient.class})
@Import({FeignMappingDefaultConfiguration.class, HacksterServiceClientConfiguration.class})
-@EnableDiscoveryClient
public @interface EnableHacksterServiceClient {
}
diff --git a/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java b/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java
index a581699..869d43c 100644
--- a/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java
+++ b/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTestApplication.java
@@ -2,8 +2,10 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
@EnableHacksterServiceClient
+@EnableFeignClients(clients = {HacksterServiceClient.class})
@SpringBootApplication
public class HacksterServiceClientTestApplication {
diff --git a/hackster-service-client/src/test/resources/application.properties b/hackster-service-client/src/test/resources/application.properties
index 6be9bb7..cc29534 100644
--- a/hackster-service-client/src/test/resources/application.properties
+++ b/hackster-service-client/src/test/resources/application.properties
@@ -1,4 +1,2 @@
spring.application.name=hackster-service-client-testing
-feign.hystrix.enabled=true
-hackster-service.ribbon.servers=http://localhost:6666/
eureka.client.enabled=false
diff --git a/hackster-service-client/src/test/resources/banner.txt b/hackster-service-client/src/test/resources/banner.txt
index 56cd009..f3f3f23 100644
--- a/hackster-service-client/src/test/resources/banner.txt
+++ b/hackster-service-client/src/test/resources/banner.txt
@@ -1,5 +1,6 @@
- _______________________
- /_ __/ ____/ ___/_ __/
- / / / __/ \__ \ / /
- / / / /___ ___/ // /
-/_/ /_____//____//_/
+ _______________________ __ __ __ __ _ ___ __
+ /_ __/ ____/ ___/_ __/ / / / /___ ______/ /_______/ /____ _____ ________ ______ __(_)_______ _____/ (_)__ ____ / /_
+ / / / __/ \__ \ / / / /_/ / __ `/ ___/ //_/ ___/ __/ _ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/
+ / / / /___ ___/ // / / __ / /_/ / /__/ ,< (__ ) /_/ __/ / (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_
+/_/ /_____//____//_/ /_/ /_/\__,_/\___/_/|_/____/\__/\___/_/ /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/
+
diff --git a/hackster-service/pom.xml b/hackster-service/pom.xml
index 4b21f6c..5d22536 100644
--- a/hackster-service/pom.xml
+++ b/hackster-service/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub
+ com.lohika.jclub.hackster
hackster-service
0.0.1-SNAPSHOT
jar
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -23,6 +23,7 @@
UTF-8
1.8
Dalston.RELEASE
+ ${basedir}/src/main/docker
@@ -34,17 +35,14 @@
org.springframework.boot
spring-boot-starter-web
-
org.springframework.boot
spring-boot-starter-data-jpa
-
org.springframework.cloud
spring-cloud-starter-eureka
-
org.springframework.cloud
spring-cloud-starter-config
@@ -60,6 +58,7 @@
lombok
true
+
org.springframework.boot
spring-boot-starter-test
@@ -85,6 +84,23 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
com.spotify
docker-maven-plugin
@@ -99,20 +115,17 @@
- hackster-service
- java
- ["java", "-jar", "/${project.build.finalName}.jar"]
+ ${project.artifactId}
+ ${docker.baseDir}
/
${project.build.directory}
- ${project.build.finalName}.jar
+ ${project.artifactId}.jar
-
-
diff --git a/hackster-service/src/main/docker/Dockerfile b/hackster-service/src/main/docker/Dockerfile
new file mode 100644
index 0000000..048cda4
--- /dev/null
+++ b/hackster-service/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD hackster-service.jar hackster-service.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./hackster-service.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/hackster-service/src/main/docker/wrapper.sh b/hackster-service/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..fb60bab
--- /dev/null
+++ b/hackster-service/src/main/docker/wrapper.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting hackster service immediately"
+ java -jar ./hackster-service.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+CONFIG_SERVER=${CONFIG_SERVER:='config-server'}
+echo "Trying to get '${CONFIG_SERVER}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CONFIG_SERVER}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+echo "Starting hackster service"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./hackster-service.jar
diff --git a/hackster-service/src/main/java/com/lohika/jclub/Hackster.java b/hackster-service/src/main/java/com/lohika/jclub/service/Hackster.java
similarity index 92%
rename from hackster-service/src/main/java/com/lohika/jclub/Hackster.java
rename to hackster-service/src/main/java/com/lohika/jclub/service/Hackster.java
index f8f7c1e..28a3eb9 100644
--- a/hackster-service/src/main/java/com/lohika/jclub/Hackster.java
+++ b/hackster-service/src/main/java/com/lohika/jclub/service/Hackster.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.service;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterController.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterController.java
similarity index 95%
rename from hackster-service/src/main/java/com/lohika/jclub/HacksterController.java
rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterController.java
index ba03389..df4ca73 100644
--- a/hackster-service/src/main/java/com/lohika/jclub/HacksterController.java
+++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterController.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterRepository.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterRepository.java
similarity index 86%
rename from hackster-service/src/main/java/com/lohika/jclub/HacksterRepository.java
rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterRepository.java
index af26b26..63ea1f4 100644
--- a/hackster-service/src/main/java/com/lohika/jclub/HacksterRepository.java
+++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterRepository.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.service;
import org.springframework.data.jpa.repository.JpaRepository;
diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterService.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterService.java
similarity index 97%
rename from hackster-service/src/main/java/com/lohika/jclub/HacksterService.java
rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterService.java
index b574184..ba10336 100644
--- a/hackster-service/src/main/java/com/lohika/jclub/HacksterService.java
+++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterService.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
diff --git a/hackster-service/src/main/java/com/lohika/jclub/HacksterServiceApplication.java b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterServiceApplication.java
similarity index 92%
rename from hackster-service/src/main/java/com/lohika/jclub/HacksterServiceApplication.java
rename to hackster-service/src/main/java/com/lohika/jclub/service/HacksterServiceApplication.java
index 6b3bcf2..b66e144 100644
--- a/hackster-service/src/main/java/com/lohika/jclub/HacksterServiceApplication.java
+++ b/hackster-service/src/main/java/com/lohika/jclub/service/HacksterServiceApplication.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/hackster-service/src/main/resources/application.properties b/hackster-service/src/main/resources/application.properties
index c908936..20edbde 100644
--- a/hackster-service/src/main/resources/application.properties
+++ b/hackster-service/src/main/resources/application.properties
@@ -1,2 +1,12 @@
server.port=8082
-spring.application.name=hackster-service
\ No newline at end of file
+spring.application.name=hackster-service
+
+eureka.instance.preferIpAddress=true
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Hackster service
diff --git a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceApplicationTests.java
similarity index 80%
rename from hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java
rename to hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceApplicationTests.java
index d5a3b33..2150eac 100644
--- a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceApplicationTests.java
+++ b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceApplicationTests.java
@@ -1,9 +1,8 @@
-package com.lohika.jclub;
+package com.lohika.jclub.service;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@@ -11,7 +10,6 @@
@RunWith(SpringRunner.class)
@SpringBootTest
-@AutoConfigureMockMvc
public class HacksterServiceApplicationTests {
@Autowired
private HacksterService hacksterService;
diff --git a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceTests.java b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceTests.java
similarity index 97%
rename from hackster-service/src/test/java/com/lohika/jclub/HacksterServiceTests.java
rename to hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceTests.java
index 469e89c..7fc2df0 100644
--- a/hackster-service/src/test/java/com/lohika/jclub/HacksterServiceTests.java
+++ b/hackster-service/src/test/java/com/lohika/jclub/service/HacksterServiceTests.java
@@ -1,4 +1,4 @@
-package com.lohika.jclub;
+package com.lohika.jclub.service;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/hackster-service/src/test/resources/banner.txt b/hackster-service/src/test/resources/banner.txt
new file mode 100644
index 0000000..151fd06
--- /dev/null
+++ b/hackster-service/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ __ __ __ __ _
+ /_ __/ ____/ ___/_ __/ / / / /___ ______/ /_______/ /____ _____ ________ ______ __(_)_______
+ / / / __/ \__ \ / / / /_/ / __ `/ ___/ //_/ ___/ __/ _ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \
+ / / / /___ ___/ // / / __ / /_/ / /__/ ,< (__ ) /_/ __/ / (__ ) __/ / | |/ / / /__/ __/
+/_/ /_____//____//_/ /_/ /_/\__,_/\___/_/|_/____/\__/\___/_/ /____/\___/_/ |___/_/\___/\___/
+
diff --git a/hackster-service/src/test/resources/logback-test.xml b/hackster-service/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/hackster-service/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/integration-test/pom.xml b/integration-test/pom.xml
new file mode 100644
index 0000000..95f1ac4
--- /dev/null
+++ b/integration-test/pom.xml
@@ -0,0 +1,109 @@
+
+
+ 4.0.0
+
+ com.lohika.jclub.integration
+ ent-to-ent-integration-test
+
+ Integration test
+ Ent-to-ent integration test
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.5.4.RELEASE
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ Dalston.RELEASE
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-eureka
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+ com.lohika.jclub.gateway
+ api-gateway-service
+ 0.0.1-SNAPSHOT
+ test
+
+
+ com.lohika.jclub.storage
+ storage-service-client
+ 0.0.1-SNAPSHOT
+ test
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ org.testcontainers
+ testcontainers
+ 1.4.2
+ test
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/*.java
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+
+ end-to-end-tests
+
+ integration-test
+ verify
+
+
+
+ **/*EntToEndIntegrationTestSuite.java
+
+
+
+
+
+
+
+
diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java
new file mode 100644
index 0000000..aabed60
--- /dev/null
+++ b/integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java
@@ -0,0 +1,87 @@
+package com.lohika.jclub.integration;
+
+import lombok.extern.log4j.Log4j;
+
+import com.lohika.jclub.storage.client.StorageServiceClient;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.util.EnvironmentTestUtils;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.IOException;
+
+import javax.annotation.PostConstruct;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Log4j
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = IntegrationTestApplication.class)
+@ContextConfiguration(initializers = BaseIntegrationTest.Initializer.class)
+public abstract class BaseIntegrationTest {
+
+ protected static final String DSL_EXECUTOR_SERVICE = "DSL-EXECUTOR-SERVICE";
+ protected static final String API_GATEWAY_SERVICE = "API-GATEWAY-SERVICE";
+
+ private static final String DISCOVERY_SERVER = "localhost";
+ private static final int DISCOVERY_SERVER_PORT = 8761;
+ private static final int SLEEP = 5000;
+
+ @Autowired
+ protected StorageServiceClient storageServiceClient;
+
+ @BeforeClass
+ public static void init() {
+ assertThat(EntToEndIntegrationTestSuite.environment, notNullValue());
+ }
+
+ @Before
+ public void warmUp() {
+ storageServiceClient.list();
+ }
+
+ @Before
+ public void cleanUp() {
+ storageServiceClient.list().getContent()
+ .forEach(apartment -> storageServiceClient.delete(apartment.getId()));
+ }
+
+ public static void waitFor(String service) throws InterruptedException {
+ HttpClient client = HttpClientBuilder.create().build();
+ String gateway = "http://" + DISCOVERY_SERVER + ":" + DISCOVERY_SERVER_PORT + "/eureka/apps/" + service;
+ HttpGet httpGet = new HttpGet(gateway);
+
+ log.info("Wait for :" + service);
+ HttpResponse httpResponse = null;
+ do {
+ Thread.sleep(SLEEP);
+ try {
+ httpResponse = client.execute(httpGet);
+ } catch (IOException ignored) {
+ }
+ } while (httpResponse == null || httpResponse.getStatusLine().getStatusCode() != 200);
+ Thread.sleep(SLEEP);
+ }
+
+ public static class Initializer implements ApplicationContextInitializer {
+ @Override
+ public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
+ EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
+ "eureka.client.serviceUrl.defaultZone=http://" + DISCOVERY_SERVER + ":" + DISCOVERY_SERVER_PORT + "/eureka"
+ );
+ }
+ }
+}
diff --git a/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java b/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java
new file mode 100644
index 0000000..ad6f7bd
--- /dev/null
+++ b/integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java
@@ -0,0 +1,67 @@
+package com.lohika.jclub.integration;
+
+import com.lohika.jclub.storage.client.Apartment;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Collection;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+
+public class DslIntegrationTest extends BaseIntegrationTest {
+ private static final String SIMPLE_DSL_EXECUTE = "http://" + DSL_EXECUTOR_SERVICE + "/dsl/end-to-end";
+ private static final String GET_APARTMENTS = "http://" + API_GATEWAY_SERVICE + "/api/client-service/apartments";
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @BeforeClass
+ public static void setUpTests() throws InterruptedException {
+ waitFor(API_GATEWAY_SERVICE);
+ waitFor(DSL_EXECUTOR_SERVICE);
+ }
+
+ @Test
+ public void apartmentShouldBeAvailableAfterDslExecution() {
+ /* GIVEN */
+
+ /* WHEN */
+ ResponseEntity
- com.lohika.jclub
+ com.lohika.jclub.discovery
discovery-server
0.0.1-SNAPSHOT
test
@@ -57,11 +57,11 @@
org.testcontainers
testcontainers
- 1.3.0
+ 1.4.2
test
- com.lohika.jclub.rating.service
+ com.lohika.jclub.rating
rating-service
0.0.1-SNAPSHOT
test
diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java
index 32d4be2..66d779c 100644
--- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java
+++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientFallbackTest.java
@@ -4,6 +4,10 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.util.EnvironmentTestUtils;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.hamcrest.Matchers.nullValue;
@@ -11,6 +15,7 @@
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RatingServiceClientTestApplication.class)
+@ContextConfiguration(initializers = RatingServiceClientFallbackTest.Initializer.class)
public class RatingServiceClientFallbackTest {
@Autowired
@@ -29,4 +34,14 @@ public void getRating() {
assertThat(actual, nullValue());
}
+
+ public static class Initializer implements ApplicationContextInitializer {
+ @Override
+ public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
+
+ EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
+ "rating-service.ribbon.servers=http://not-existing-url/"
+ );
+ }
+ }
}
diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java
index 6ad55ae..23d6c51 100644
--- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java
+++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java
@@ -27,6 +27,8 @@ public class RatingServiceClientTest {
@ClassRule
public static GenericContainer RatingService = new GenericContainer("rating-service:latest")
.withExposedPorts(8081)
+ .withEnv("spring.cloud.config.fail-fast", "false")
+ .withEnv("spring.cloud.config.discovery.enabled", "false")
.withEnv("rate", "100")
.withEnv("spring.cloud.config.discovery.enabled", "false")
.withEnv("spring.cloud.config.fail-fast", "false")
diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java
index 63e5ae9..ccdb620 100644
--- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java
+++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java
@@ -2,10 +2,8 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
-@EnableDiscoveryClient
@EnableRatingServiceClient
@EnableFeignClients(clients = {RatingServiceClient.class})
@SpringBootApplication
diff --git a/rating-service-client/src/test/resources/application.properties b/rating-service-client/src/test/resources/application.properties
index 788b4c2..fccaf41 100644
--- a/rating-service-client/src/test/resources/application.properties
+++ b/rating-service-client/src/test/resources/application.properties
@@ -1,3 +1,3 @@
spring.application.name=rating-service-client-testing
feign.hystrix.enabled=true
-rating-service.ribbon.servers=http://localhost:6666/
+eureka.client.enabled=false
diff --git a/rating-service-client/src/test/resources/banner.txt b/rating-service-client/src/test/resources/banner.txt
index 56cd009..795c250 100644
--- a/rating-service-client/src/test/resources/banner.txt
+++ b/rating-service-client/src/test/resources/banner.txt
@@ -1,5 +1,6 @@
- _______________________
- /_ __/ ____/ ___/_ __/
- / / / __/ \__ \ / /
- / / / /___ ___/ // /
-/_/ /_____//____//_/
+ _______________________ ____ __ _ _ ___ __
+ /_ __/ ____/ ___/_ __/ / __ \____ _/ /_(_)___ ____ _ ________ ______ __(_)_______ _____/ (_)__ ____ / /_
+ / / / __/ \__ \ / / / /_/ / __ `/ __/ / __ \/ __ `/ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/
+ / / / /___ ___/ // / / _, _/ /_/ / /_/ / / / / /_/ / (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_
+/_/ /_____//____//_/ /_/ |_|\__,_/\__/_/_/ /_/\__, / /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/
+ /____/
diff --git a/rating-service-client/src/test/resources/bootstrap.properties b/rating-service-client/src/test/resources/bootstrap.properties
new file mode 100644
index 0000000..2c48307
--- /dev/null
+++ b/rating-service-client/src/test/resources/bootstrap.properties
@@ -0,0 +1 @@
+spring.cloud.config.discovery.enabled=false
diff --git a/rating-service/pom.xml b/rating-service/pom.xml
index 25862a6..2514355 100644
--- a/rating-service/pom.xml
+++ b/rating-service/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub.rating.service
+ com.lohika.jclub.rating
rating-service
0.0.1-SNAPSHOT
jar
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -23,6 +23,7 @@
UTF-8
1.8
Dalston.RELEASE
+ ${basedir}/src/main/docker
@@ -42,11 +43,13 @@
org.springframework.cloud
spring-cloud-starter-eureka
+
org.projectlombok
lombok
- 1.16.16
+
+
org.springframework.boot
spring-boot-starter-test
@@ -72,6 +75,23 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
com.spotify
docker-maven-plugin
@@ -86,14 +106,13 @@
- rating-service
- java
- ["java", "-jar", "/${project.build.finalName}.jar"]
+ ${project.artifactId}
+ ${docker.baseDir}
/
${project.build.directory}
- ${project.build.finalName}.jar
+ ${project.artifactId}.jar
diff --git a/rating-service/src/main/docker/Dockerfile b/rating-service/src/main/docker/Dockerfile
new file mode 100644
index 0000000..180d61a
--- /dev/null
+++ b/rating-service/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD rating-service.jar rating-service.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./rating-service.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/rating-service/src/main/docker/wrapper.sh b/rating-service/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..a72a599
--- /dev/null
+++ b/rating-service/src/main/docker/wrapper.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting rating service immediately"
+ java -jar ./rating-service.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+CONFIG_SERVER=${CONFIG_SERVER:='config-server'}
+echo "Trying to get '${CONFIG_SERVER}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${CONFIG_SERVER}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+echo "Starting rating service"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./rating-service.jar
diff --git a/rating-service/src/main/resources/application.properties b/rating-service/src/main/resources/application.properties
index fc1c858..7a1beaa 100644
--- a/rating-service/src/main/resources/application.properties
+++ b/rating-service/src/main/resources/application.properties
@@ -1,2 +1,12 @@
server.port=8081
spring.application.name=rating-service
+
+eureka.instance.preferIpAddress=true
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Rating service
diff --git a/rating-service/src/test/resources/application.properties b/rating-service/src/test/resources/application.properties
index f3f2ed0..5cafea3 100644
--- a/rating-service/src/test/resources/application.properties
+++ b/rating-service/src/test/resources/application.properties
@@ -1 +1,2 @@
rate=100
+eureka.client.enabled=false
diff --git a/rating-service/src/test/resources/banner.txt b/rating-service/src/test/resources/banner.txt
new file mode 100644
index 0000000..62e4743
--- /dev/null
+++ b/rating-service/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ ____ __ _ _
+ /_ __/ ____/ ___/_ __/ / __ \____ _/ /_(_)___ ____ _ ________ ______ __(_)_______
+ / / / __/ \__ \ / / / /_/ / __ `/ __/ / __ \/ __ `/ / ___/ _ \/ ___/ | / / / ___/ _ \
+ / / / /___ ___/ // / / _, _/ /_/ / /_/ / / / / /_/ / (__ ) __/ / | |/ / / /__/ __/
+/_/ /_____//____//_/ /_/ |_|\__,_/\__/_/_/ /_/\__, / /____/\___/_/ |___/_/\___/\___/
+ /____/
diff --git a/rating-service/src/test/resources/logback-test.xml b/rating-service/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/rating-service/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/realtor-service/pom.xml b/realtor-service/pom.xml
index 4673e03..4673c32 100644
--- a/realtor-service/pom.xml
+++ b/realtor-service/pom.xml
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -23,9 +23,20 @@
UTF-8
1.8
Dalston.RELEASE
+ ${basedir}/src/main/docker
+
+ com.lohika.jclub.storage
+ storage-service-client
+ 0.0.1-SNAPSHOT
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
org.springframework.cloud
spring-cloud-starter-eureka
@@ -34,25 +45,27 @@
org.springframework.boot
spring-boot-starter-web
-
- org.springframework.boot
- spring-boot-starter-test
- test
+ org.springframework.cloud
+ spring-cloud-starter-feign
+
org.projectlombok
lombok
1.16.12
+
- org.springframework.cloud
- spring-cloud-starter-feign
+ org.testcontainers
+ testcontainers
+ 1.4.2
+ test
- com.lohika.jclub.storage.client
- storage-service-client
- 0.0.1-SNAPSHOT
+ org.springframework.boot
+ spring-boot-starter-test
+ test
@@ -74,8 +87,48 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
+
+ com.spotify
+ docker-maven-plugin
+ 1.0.0
+
+
+ build-image
+ install
+
+ build
+
+
+
+
+ ${project.artifactId}
+ ${docker.baseDir}
+
+
+ /
+ ${project.build.directory}
+ ${project.artifactId}.jar
+
+
+
+
-
-
diff --git a/realtor-service/src/main/docker/Dockerfile b/realtor-service/src/main/docker/Dockerfile
new file mode 100644
index 0000000..beab733
--- /dev/null
+++ b/realtor-service/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD realtor-service.jar realtor-service.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./realtor-service.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/realtor-service/src/main/docker/wrapper.sh b/realtor-service/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..bde66f0
--- /dev/null
+++ b/realtor-service/src/main/docker/wrapper.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting realtor service immediately"
+ java -jar ./realtor-service.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+STORAGE_SERVICE=${STORAGE_SERVICE:='storage-service'}
+echo "Trying to get '${STORAGE_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${STORAGE_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+RATING_SERVICE=${RATING_SERVICE:='rating-service'}
+echo "Trying to get '${RATING_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${RATING_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+HACKSTER_SERVICE=${HACKSTER_SERVICE:='hackster-service'}
+echo "Trying to get '${HACKSTER_SERVICE}' from ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka/apps/${HACKSTER_SERVICE}"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+echo "Starting realtor service"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./realtor-service.jar
diff --git a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java
index 055072a..7334d72 100644
--- a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java
+++ b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java
@@ -15,6 +15,8 @@
import java.util.List;
+import javax.annotation.PostConstruct;
+
@Slf4j
@RestController
public class RealtorController {
@@ -28,6 +30,11 @@ public class RealtorController {
@Autowired
private StorageServiceClient storageServiceClient;
+ @PostConstruct
+ public void warmUp() {
+ storageServiceClient.list();
+ }
+
@PostMapping("/apartments")
public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
ResponseEntity isHackster =
@@ -37,7 +44,8 @@ public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
}
@PostMapping("/storeApartments")
- public void storeApartment(@RequestBody ApartmentRecord apartmentRecord) {
+ @ResponseBody
+ public Apartment storeApartment(@RequestBody ApartmentRecord apartmentRecord) {
Apartment newApartment = Apartment.builder()
.location(apartmentRecord.getLocation())
@@ -53,6 +61,7 @@ public void storeApartment(@RequestBody ApartmentRecord apartmentRecord) {
.decoder(new JacksonDecoder()).target(ApartmentRecordClient.class, "http://storage-service");
apartmentRecordClient.storeApartment(apartmentRecord);*/
log.info("Stored, {}", apartment);
+ return apartment;
}
@RequestMapping("/service-instances/{applicationName}")
diff --git a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java
index e3fb957..a736cef 100644
--- a/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java
+++ b/realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorServiceApplication.java
@@ -1,15 +1,19 @@
package com.lohika.jclub.realtor;
-
import com.lohika.jclub.storage.client.EnableStorageServiceClient;
+import com.lohika.jclub.storage.client.StorageServiceClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
+@EnableDiscoveryClient
@EnableStorageServiceClient
+@EnableFeignClients(clients = {StorageServiceClient.class})
@SpringBootApplication
public class RealtorServiceApplication {
diff --git a/realtor-service/src/main/resources/application.properties b/realtor-service/src/main/resources/application.properties
index a58c307..d3d918d 100644
--- a/realtor-service/src/main/resources/application.properties
+++ b/realtor-service/src/main/resources/application.properties
@@ -1,2 +1,12 @@
spring.application.name=realtor-service
-feign.hystrix.enabled=true
\ No newline at end of file
+feign.hystrix.enabled=true
+
+eureka.instance.preferIpAddress=true
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Realtor service
diff --git a/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java b/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java
index ae082e5..1487163 100644
--- a/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java
+++ b/realtor-service/src/test/java/com/lohika/jclub/realtor/RealtorServiceApplicationTests.java
@@ -2,16 +2,23 @@
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.util.EnvironmentTestUtils;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.LogMessageWaitStrategy;
import javax.ws.rs.core.MediaType;
@@ -20,7 +27,22 @@
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
+@ContextConfiguration(initializers = RealtorServiceApplicationTests.Initializer.class)
public class RealtorServiceApplicationTests {
+ private static final int MAX_ALLOWED_APARTMENTS_PER_REALTOR = 4;
+
+ @ClassRule
+ public static GenericContainer storageService = new GenericContainer("storage-service:latest")
+ .withExposedPorts(8091)
+ .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started StorageServiceApplication in.*\\s"));
+
+ @ClassRule
+ public static GenericContainer HacksterService = new GenericContainer("hackster-service:latest")
+ .withExposedPorts(8082)
+ .withEnv("maxAllowedApartmentsPerRealtor", Integer.toString(MAX_ALLOWED_APARTMENTS_PER_REALTOR))
+ .withEnv("spring.cloud.config.discovery.enabled", "false")
+ .withEnv("spring.cloud.config.fail-fast", "false")
+ .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started HacksterServiceApplication in.*\\s"));
@Autowired
private MockMvc mockMvc;
@@ -30,20 +52,33 @@ public void contextLoads() throws Exception {
}
@Test
- @Ignore
public void apartments() throws Exception {
ApartmentRecord apartmentRecord = ApartmentRecord.builder()
.phone("123")
.realtorName("Anna Realtor")
.sqft(44)
.price(100)
+ .mail("mail")
.location("Lviv").build();
mockMvc.perform(MockMvcRequestBuilders
- .post("/apartments")
+ .post("/storeApartments")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsBytes(apartmentRecord)))
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk());
}
+
+ public static class Initializer implements ApplicationContextInitializer {
+ @Override
+ public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
+
+ EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
+ "storage-service.ribbon.servers=http://" + storageService.getContainerIpAddress() + ":"
+ + storageService.getMappedPort(8091) + "/",
+ "hackster-service.ribbon.servers=http://" + HacksterService.getContainerIpAddress() + ":"
+ + HacksterService.getMappedPort(8082) + "/"
+ );
+ }
+ }
}
diff --git a/realtor-service/src/test/resources/application.properties b/realtor-service/src/test/resources/application.properties
new file mode 100644
index 0000000..c67637e
--- /dev/null
+++ b/realtor-service/src/test/resources/application.properties
@@ -0,0 +1,2 @@
+eureka.client.enabled=false
+feign.hystrix.enabled=true
diff --git a/realtor-service/src/test/resources/banner.txt b/realtor-service/src/test/resources/banner.txt
new file mode 100644
index 0000000..f9717fa
--- /dev/null
+++ b/realtor-service/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ ____ ____ _
+ /_ __/ ____/ ___/_ __/ / __ \___ ____ _/ / /_____ _____ ________ ______ __(_)_______
+ / / / __/ \__ \ / / / /_/ / _ \/ __ `/ / __/ __ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \
+ / / / /___ ___/ // / / _, _/ __/ /_/ / / /_/ /_/ / / (__ ) __/ / | |/ / / /__/ __/
+/_/ /_____//____//_/ /_/ |_|\___/\__,_/_/\__/\____/_/ /____/\___/_/ |___/_/\___/\___/
+
diff --git a/realtor-service/src/test/resources/logback-test.xml b/realtor-service/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/realtor-service/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/storage-service-client/pom.xml b/storage-service-client/pom.xml
index f849642..ec05e52 100644
--- a/storage-service-client/pom.xml
+++ b/storage-service-client/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub.storage.client
+ com.lohika.jclub.storage
storage-service-client
0.0.1-SNAPSHOT
jar
@@ -38,32 +38,33 @@
org.springframework.boot
spring-boot-starter-hateoas
+
com.netflix.hystrix
hystrix-javanica
- org.projectlombok
- lombok
- true
-
-
- com.lohika.jclub
+ com.lohika.jclub.discovery
discovery-server
0.0.1-SNAPSHOT
test
- org.testcontainers
- testcontainers
- 1.3.0
+ com.lohika.jclub.storage
+ storage-service
+ 0.0.1-SNAPSHOT
test
- com.lohika.jclub.storage.service
- storage-service
- 0.0.1-SNAPSHOT
+ org.projectlombok
+ lombok
+ true
+
+
+ org.testcontainers
+ testcontainers
+ 1.4.2
test
diff --git a/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java b/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java
index 5e388ba..d1b7164 100644
--- a/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java
+++ b/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientFallbackTest.java
@@ -4,7 +4,11 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.util.EnvironmentTestUtils;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.hateoas.PagedResources;
+import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.hamcrest.Matchers.hasSize;
@@ -14,6 +18,7 @@
@RunWith(SpringRunner.class)
@SpringBootTest(classes = StorageServiceClientTestApplication.class)
+@ContextConfiguration(initializers = StorageServiceClientFallbackTest.Initializer.class)
public class StorageServiceClientFallbackTest {
@Autowired
@@ -63,4 +68,14 @@ public void update() {
public void delete() {
storageServiceClient.delete("not-existing-id");
}
+
+ public static class Initializer implements ApplicationContextInitializer {
+ @Override
+ public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
+
+ EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
+ "storage-service.ribbon.servers=http://not-existing-url/"
+ );
+ }
+ }
}
diff --git a/storage-service-client/src/test/resources/application.properties b/storage-service-client/src/test/resources/application.properties
index 9d4c8b6..c67637e 100644
--- a/storage-service-client/src/test/resources/application.properties
+++ b/storage-service-client/src/test/resources/application.properties
@@ -1,3 +1,2 @@
-spring.application.name=storage-service-client-testing
+eureka.client.enabled=false
feign.hystrix.enabled=true
-storage-service.ribbon.servers=http://localhost:6666/
diff --git a/storage-service-client/src/test/resources/banner.txt b/storage-service-client/src/test/resources/banner.txt
index 30c2015..32a8c06 100644
--- a/storage-service-client/src/test/resources/banner.txt
+++ b/storage-service-client/src/test/resources/banner.txt
@@ -1,6 +1,6 @@
- _______________________ _____ __ _ ___ __
- /_ __/ ____/ ___/_ __/ / ___// /_____ _________ _____ ____ ________ ______ __(_)_______ _____/ (_)__ ____ / /_
- / / / __/ \__ \ / / \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/
- / / / /___ ___/ // / ___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_
-/_/ /_____//____//_/ /____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/
- /____/
+ _______________________ _____ __ _ ___ __
+ /_ __/ ____/ ___/_ __/ / ___// /_____ _________ _____ ____ ________ ______ __(_)_______ _____/ (_)__ ____ / /_
+ / / / __/ \__ \ / / \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \ / ___/ / / _ \/ __ \/ __/
+ / / / /___ ___/ // / ___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/ / /__/ / / __/ / / / /_
+/_/ /_____//____//_/ /____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/ \___/_/_/\___/_/ /_/\__/
+ /____/
diff --git a/storage-service/pom.xml b/storage-service/pom.xml
index 230df06..a6f9f10 100644
--- a/storage-service/pom.xml
+++ b/storage-service/pom.xml
@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- com.lohika.jclub.storage.service
+ com.lohika.jclub.storage
storage-service
0.0.1-SNAPSHOT
jar
@@ -14,7 +14,7 @@
org.springframework.boot
spring-boot-starter-parent
- 1.5.3.RELEASE
+ 1.5.4.RELEASE
@@ -24,9 +24,14 @@
1.8
Dalston.RELEASE
springio
+ ${basedir}/src/main/docker
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
org.springframework.cloud
spring-cloud-starter-eureka
@@ -50,6 +55,7 @@
lombok
true
+
org.springframework.boot
spring-boot-starter-test
@@ -75,34 +81,48 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ maven-antrun-plugin
+
+
+
+
+
+
+
+ install
+
+ run
+
+
+
+
com.spotify
docker-maven-plugin
1.0.0
-
- build-image
- install
-
- build
-
-
+
+ build-image
+ install
+
+ build
+
+
- storage-service
- java
- ["java", "-jar", "/${project.build.finalName}.jar"]
+ ${project.artifactId}
+ ${docker.baseDir}
/
${project.build.directory}
- ${project.build.finalName}.jar
+ ${project.artifactId}.jar
-
-
diff --git a/storage-service/src/main/docker/Dockerfile b/storage-service/src/main/docker/Dockerfile
new file mode 100644
index 0000000..4264e79
--- /dev/null
+++ b/storage-service/src/main/docker/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+
+RUN mkdir -p /opt/spring-cloud
+WORKDIR /opt/spring-cloud
+
+ADD storage-service.jar storage-service.jar
+ADD wrapper.sh wrapper.sh
+
+RUN bash -c 'chmod +x ./wrapper.sh'
+RUN bash -c 'touch ./storage-service.jar'
+
+ENTRYPOINT ["/bin/bash", "./wrapper.sh"]
diff --git a/storage-service/src/main/docker/wrapper.sh b/storage-service/src/main/docker/wrapper.sh
new file mode 100644
index 0000000..ca84638
--- /dev/null
+++ b/storage-service/src/main/docker/wrapper.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+WAITING_FOR_DEPENDENCE=${WAITING_FOR_DEPENDENCE:='false'}
+
+if [ "$WAITING_FOR_DEPENDENCE" != "true" ]; then
+ echo "Starting storage server immediately"
+ java -jar ./storage-service.jar
+ exit 0
+fi
+
+DISCOVERY_SERVER_HOST=${DISCOVERY_SERVER_HOST:='discovery-server'}
+DISCOVERY_SERVER_PORT=${DISCOVERY_SERVER_PORT:=8761}
+
+echo "Trying to connect to discovery server on ${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}"
+until $(curl --output /dev/null --silent --head --fail "http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/info"); do
+ echo -e ".\c"
+ sleep 1
+done
+echo
+
+sleep 15
+echo "Starting storage server"
+echo "Setting eureka.client.serviceUrl.defaultZone to http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka"
+echo
+env "eureka.client.serviceUrl.defaultZone=http://${DISCOVERY_SERVER_HOST}:${DISCOVERY_SERVER_PORT}/eureka" \
+ java -jar ./storage-service.jar
diff --git a/storage-service/src/main/resources/application.properties b/storage-service/src/main/resources/application.properties
index 8554b7f..8fda022 100644
--- a/storage-service/src/main/resources/application.properties
+++ b/storage-service/src/main/resources/application.properties
@@ -2,3 +2,13 @@ spring.application.name=storage-service
server.port=8091
spring.data.rest.return-body-on-create=true
spring.data.rest.return-body-on-update=true
+
+eureka.instance.preferIpAddress=true
+
+management.security.enabled=false
+
+endpoints.info.id=info
+endpoints.info.sensitive=false
+endpoints.info.enabled=true
+
+info.app.name=Storage service
diff --git a/storage-service/src/test/resources/application.properties b/storage-service/src/test/resources/application.properties
new file mode 100644
index 0000000..45cb06e
--- /dev/null
+++ b/storage-service/src/test/resources/application.properties
@@ -0,0 +1 @@
+eureka.client.enabled=false
diff --git a/storage-service/src/test/resources/banner.txt b/storage-service/src/test/resources/banner.txt
new file mode 100644
index 0000000..a0253c5
--- /dev/null
+++ b/storage-service/src/test/resources/banner.txt
@@ -0,0 +1,6 @@
+ _______________________ _____ __ _
+ /_ __/ ____/ ___/_ __/ / ___// /_____ _________ _____ ____ ________ ______ __(_)_______
+ / / / __/ \__ \ / / \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \
+ / / / /___ ___/ // / ___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/
+/_/ /_____//____//_/ /____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/
+ /____/
diff --git a/storage-service/src/test/resources/logback-test.xml b/storage-service/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..d654c6e
--- /dev/null
+++ b/storage-service/src/test/resources/logback-test.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file