Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 65 additions & 95 deletions README.md

Large diffs are not rendered by default.

86 changes: 73 additions & 13 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,72 @@
services:
discovery-server:
build: infra/discovery-server
container_name: ewm-discovery-server-compose
hostname: discovery-server
ports:
- "8761:8761"
environment:
EUREKA_HOSTNAME: discovery-server
restart: unless-stopped
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost:8761/actuator/health || exit 1" ]
interval: 5s
timeout: 3s
retries: 5
start_period: 5s

config-server:
build: infra/config-server
container_name: config-server
depends_on:
discovery-server:
condition: service_healthy
ports:
- "8888:8888"
restart: unless-stopped
healthcheck:
test: [ "CMD-SHELL", "curl -f http://localhost:8888/actuator/health | grep -q '\"eureka\":.*\"details\":{\"applications\":{\"CONFIG-SERVER\":1}}'" ]
interval: 5s
timeout: 5s
retries: 10
start_period: 10s
environment:
EUREKA_URI: http://discovery-server:8761/eureka/
PORT: 8888

gateway-server:
build: infra/gateway-server
container_name: gateway-server
depends_on:
discovery-server:
condition: service_healthy
config-server:
condition: service_healthy
ports:
- "8080:8080"
restart: unless-stopped
environment:
EUREKA_URI: http://discovery-server:8761/eureka/
PORT: 8080

stats-server:
build: stats-service/stats-server
build: core/stats-service/stats-server
container_name: ewm-stats-server-compose
depends_on:
discovery-server:
condition: service_healthy
config-server:
condition: service_healthy
stats-db:
condition: service_healthy
ports:
- "9090:9090"
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://stats-db:5432/ewm_stats_db
- SPRING_DATASOURCE_USERNAME=stats_user
- SPRING_DATASOURCE_PASSWORD=stats_password
- JAVA_OPTS=-Duser.timezone=UTC
EUREKA_URI: http://discovery-server:8761/eureka/
SPRING_DATASOURCE_URL: jdbc:postgresql://stats-db:5432/ewm_stats_db
SPRING_DATASOURCE_USERNAME: stats_user
SPRING_DATASOURCE_PASSWORD: stats_password
JAVA_OPTS: -Duser.timezone=UTC

stats-db:
image: postgres:16.1
Expand All @@ -24,7 +79,7 @@ services:
POSTGRES_DB: ewm_stats_db
volumes:
- stats_db_data:/var/lib/postgresql/data
- ./stats-service/stats-server/src/main/resources/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
- ./core/stats-service/stats-server/src/main/resources/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB} -p 5432" ]
interval: 10s
Expand All @@ -33,20 +88,25 @@ services:
start_period: 10s

ewm-service:
build: main-service
build: core/main-service
container_name: ewm-main-service-compose
depends_on:
discovery-server:
condition: service_healthy
config-server:
condition: service_healthy
ewm-db:
condition: service_healthy
stats-server:
condition: service_started
ports:
- "8080:8080"
- "8081:8081"
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://ewm-db:5432/ewm_main_db
- SPRING_DATASOURCE_USERNAME=ewm_user
- SPRING_DATASOURCE_PASSWORD=ewm_password
- JAVA_OPTS=-Duser.timezone=UTC
EUREKA_URI: http://discovery-server:8761/eureka/
SPRING_DATASOURCE_URL: jdbc:postgresql://ewm-db:5432/ewm_main_db
SPRING_DATASOURCE_USERNAME: ewm_user
SPRING_DATASOURCE_PASSWORD: ewm_password
JAVA_OPTS: -Duser.timezone=UTC

ewm-db:
image: postgres:16.1
Expand All @@ -59,7 +119,7 @@ services:
POSTGRES_DB: ewm_main_db
volumes:
- main_db_data:/var/lib/postgresql/data
- ./main-service/src/main/resources/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
- ./core/main-service/src/main/resources/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB} -p 5432" ]
interval: 10s
Expand Down
2 changes: 1 addition & 1 deletion ewm-common/pom.xml → core/ewm-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
File renamed without changes.
20 changes: 19 additions & 1 deletion main-service/pom.xml → core/main-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>main-service</artifactId>
Expand All @@ -17,10 +18,27 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stats-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stats-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import ru.practicum.explorewithme.stats.client.config.StatsClientModuleConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@Import(StatsClientModuleConfiguration.class)
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "ru.practicum.explorewithme.stats.client")
public class MainServiceApplication {
public static void main(String[] args) {
SpringApplication.run(MainServiceApplication.class, args);
Expand Down
25 changes: 25 additions & 0 deletions core/main-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
spring:
application:
name: main-service
profiles:
active: postgres
config:
import: "configserver:"
cloud:
config:
discovery:
enabled: true
serviceId: config-server
fail-fast: true
retry:
max-attempts: 10
initial-interval: 1000
useRandomPolicy: true

eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka/}
instance:
instance-id: "${spring.application.name}:${random.value}"
leaseRenewalIntervalInSeconds: 10
15 changes: 15 additions & 0 deletions core/main-service/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring:
cloud:
config:
enabled: false
discovery:
enabled: false
sql:
init:
mode: always
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
eureka:
client:
enabled: false
27 changes: 27 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>core</artifactId>
<packaging>pom</packaging>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
<module>main-service</module>
<module>stats-service</module>
<module>ewm-common</module>
</modules>

</project>
2 changes: 1 addition & 1 deletion stats-service/pom.xml → core/stats-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.practicum</groupId>
<artifactId>explore-with-me</artifactId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@
<artifactId>ewm-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.practicum.explorewithme.stats.client;

import static ru.practicum.explorewithme.common.constants.DateTimeConstants.DATE_TIME_FORMAT_PATTERN;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import ru.practicum.explorewithme.stats.dto.EndpointHitDto;
import ru.practicum.explorewithme.stats.dto.ViewStatsDto;

import java.time.LocalDateTime;
import java.util.List;

@FeignClient(name = "stats-server")
public interface StatsClient {

@PostMapping("/hit")
void saveHit(@RequestBody EndpointHitDto endpointHitDto);

@GetMapping("/stats")
List<ViewStatsDto> getStats(
@RequestParam @DateTimeFormat(pattern = DATE_TIME_FORMAT_PATTERN) LocalDateTime start,
@RequestParam @DateTimeFormat(pattern = DATE_TIME_FORMAT_PATTERN) LocalDateTime end,
@RequestParam(value = "uris", required = false) List<String> uris,
@RequestParam(value = "unique", defaultValue = "false") Boolean unique);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@
</parent>

<artifactId>stats-server</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -59,13 +68,19 @@
<dependency>
<groupId>ru.practicum</groupId>
<artifactId>ewm-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
</dependency>
<dependency>
<groupId>ru.practicum</groupId>
<artifactId>stats-client</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@SpringBootApplication
@EnableDiscoveryClient
public class StatsServerApplication {

public static void main(String[] args) {
Expand Down
Loading