forked from mtusi2026/mtusi2026lab4
Байты вложения лежат в общем S3, метаданные — в PostgreSQL, поэтому остановка загрузившей реплики не мешает другой отдать тот же файл. Idempotency-Key не даёт повторной отправке создать второе сообщение. Автор / группа: ivanstorozhev, БВТ2304 Целевая оценка (3/4/5): 3 Трек 5, если заявлен: не заявлен Что реализовано и что перенесено: из lab3 перенесены Spring Boot API, PostgreSQL, Redis-кэш сессий, Argon2id, Liquibase через одноразовый сервис migrate, HAProxy без sticky session, две реплики, X-Instance-Id, обязательный Idempotency-Key, scripts/stop-one.sh и scripts/restart.sh. Добавлены приватный SeaweedFS, таблица attachments, связь сообщения с вложениями и скачивание оригинала через API. Ключ объекта назначает сервер, имя файла только отображается. Команды запуска из чистого clone: cp .env.example .env docker compose --env-file .env config --quiet docker compose --env-file .env up -d --build curl -fsS http://127.0.0.1:8080/health/ready make test make test-persistence ACTION_SCRIPT=scripts/restart.sh make test-failover ACTION_SCRIPT=scripts/stop-one.sh docker compose --env-file .env start api Результаты проверок и ссылка на REPORT.md: подробности и числа в REPORT.md make check — PASS: offline skeleton structure, local refs and Python syntax. make test — PASS: lab4 public API scenario. make test-persistence ACTION_SCRIPT=scripts/restart.sh — PASS: persistence preserved confirmed data and existing session. make test-failover ACTION_SCRIPT=scripts/stop-one.sh — PASS: две реплики до отказа, восстановление записи за 1.665 с, 119 успешных записей и 1 ошибка перехода. mvn -q test в backend/ — 16 тестов без ошибок, включая PNG по содержимому, подмену MIME, опасное имя файла и чужое вложение. Анонимный GET объекта в сети стенда — HTTP 403. Ограничения / известные ошибки: трек 5 и полный уровень 4 не делались. Один Docker-хост, единственные PostgreSQL, Redis, SeaweedFS и HAProxy остаются точками отказа. Если процесс умер после PUT и до COMMIT, объект может остаться без строки в БД. Ключ S3 один, с правами Admin. Пик памяти при параллельных загрузках не измерялся. Пока HAProxy не снял backend, часть запросов на останавливаемую реплику завершается ошибкой соединения; повтор с тем же Idempotency-Key безопасен для отправки сообщения. Источники и использование ИИ: контракт contracts/openapi.json и contracts/README.md; код lab3; Spring Boot 4.1.1, Spring Data JPA, spring-security-crypto, Spring Data Redis, Liquibase, Actuator, MapStruct 1.6.3, OpenAPI Generator 7.17.0, AWS SDK for Java 2.31.50, Bouncy Castle, PostgreSQL 16.10, Redis 7.4.6, HAProxy 3.2.6, SeaweedFS 4.52, Testcontainers. Реализация собрана в Cursor. Весь обязательный минимум текущей и предыдущих работ сохранён с объявленными переходами. Контракт и публичные тесты не ослаблены. make check и make test выполнены; приложен реальный вывод. Сценарии отказов своего уровня воспроизведены. Все секреты и приватные ключи находятся вне Git; отчёт не содержит tokens. README задания сохранён, REPORT.md содержит инструкцию именно моего решения.
200 lines
9.6 KiB
XML
200 lines
9.6 KiB
XML
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<modelVersion>4.0.0</modelVersion>
|
|
<parent>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-parent</artifactId>
|
|
<version>4.1.1</version>
|
|
<relativePath/>
|
|
</parent>
|
|
<groupId>ru.mtuci</groupId>
|
|
<artifactId>messenger</artifactId>
|
|
<version>1.0.0-SNAPSHOT</version>
|
|
<name>messenger</name>
|
|
<description>MTUSI messenger lab 4</description>
|
|
<properties>
|
|
<java.version>21</java.version>
|
|
<mapstruct.version>1.6.3</mapstruct.version>
|
|
<openapi-generator.version>7.17.0</openapi-generator.version>
|
|
<swagger-annotations.version>2.2.36</swagger-annotations.version>
|
|
<aws.sdk.version>2.31.50</aws.sdk.version>
|
|
</properties>
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-webmvc</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-validation</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-liquibase</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.security</groupId>
|
|
<artifactId>spring-security-crypto</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.bouncycastle</groupId>
|
|
<artifactId>bcprov-jdk18on</artifactId>
|
|
<version>1.86</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>io.micrometer</groupId>
|
|
<artifactId>micrometer-registry-prometheus</artifactId>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.postgresql</groupId>
|
|
<artifactId>postgresql</artifactId>
|
|
<scope>runtime</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.mapstruct</groupId>
|
|
<artifactId>mapstruct</artifactId>
|
|
<version>${mapstruct.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>io.swagger.core.v3</groupId>
|
|
<artifactId>swagger-annotations-jakarta</artifactId>
|
|
<version>${swagger-annotations.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>software.amazon.awssdk</groupId>
|
|
<artifactId>s3</artifactId>
|
|
<version>${aws.sdk.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>software.amazon.awssdk</groupId>
|
|
<artifactId>apache-client</artifactId>
|
|
<version>${aws.sdk.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-testcontainers</artifactId>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.testcontainers</groupId>
|
|
<artifactId>testcontainers</artifactId>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>org.testcontainers</groupId>
|
|
<artifactId>testcontainers-postgresql</artifactId>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
</dependencies>
|
|
<build>
|
|
<finalName>messenger</finalName>
|
|
<plugins>
|
|
<plugin>
|
|
<groupId>org.openapitools</groupId>
|
|
<artifactId>openapi-generator-maven-plugin</artifactId>
|
|
<version>${openapi-generator.version}</version>
|
|
<executions>
|
|
<execution>
|
|
<goals>
|
|
<goal>generate</goal>
|
|
</goals>
|
|
<configuration>
|
|
<inputSpec>${project.basedir}/../contracts/openapi.json</inputSpec>
|
|
<generatorName>spring</generatorName>
|
|
<output>${project.build.directory}/generated-sources/openapi</output>
|
|
<modelPackage>ru.mtuci.messenger.api.model</modelPackage>
|
|
<apiPackage>ru.mtuci.messenger.api.generated</apiPackage>
|
|
<generateApis>false</generateApis>
|
|
<generateModels>true</generateModels>
|
|
<generateSupportingFiles>false</generateSupportingFiles>
|
|
<typeMappings>
|
|
<typeMapping>set=List</typeMapping>
|
|
</typeMappings>
|
|
<instantiationTypes>
|
|
<instantiationType>set=ArrayList</instantiationType>
|
|
</instantiationTypes>
|
|
<configOptions>
|
|
<useSpringBoot3>true</useSpringBoot3>
|
|
<useJakartaEe>true</useJakartaEe>
|
|
<interfaceOnly>true</interfaceOnly>
|
|
<dateLibrary>java8</dateLibrary>
|
|
<openApiNullable>false</openApiNullable>
|
|
<serializationLibrary>jackson</serializationLibrary>
|
|
<hideGenerationTimestamp>true</hideGenerationTimestamp>
|
|
<additionalModelTypeAnnotations>@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS)</additionalModelTypeAnnotations>
|
|
</configOptions>
|
|
</configuration>
|
|
</execution>
|
|
</executions>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.apache.maven.plugins</groupId>
|
|
<artifactId>maven-antrun-plugin</artifactId>
|
|
<executions>
|
|
<execution>
|
|
<id>jackson3-model-annotations</id>
|
|
<phase>generate-sources</phase>
|
|
<goals>
|
|
<goal>run</goal>
|
|
</goals>
|
|
<configuration>
|
|
<target>
|
|
<replace dir="${project.build.directory}/generated-sources/openapi" token="import com.fasterxml.jackson.databind.annotation.JsonDeserialize;" value="">
|
|
<include name="**/*.java"/>
|
|
</replace>
|
|
<replace dir="${project.build.directory}/generated-sources/openapi" token="@JsonDeserialize(as = LinkedHashSet.class)" value="">
|
|
<include name="**/*.java"/>
|
|
</replace>
|
|
<!-- Generator builds a required-args constructor that drops attachment_ids. Jackson uses it, so copy the list back. -->
|
|
<replace dir="${project.build.directory}/generated-sources/openapi" token="public CreateMessage(String text, Object attachmentIds) {${line.separator} this.text = text;${line.separator} }" value="public CreateMessage(String text, Object attachmentIds) {${line.separator} this.text = text;${line.separator} if (attachmentIds instanceof java.util.List<?> ids) {${line.separator} this.attachmentIds = new java.util.ArrayList<>();${line.separator} for (Object id : ids) {${line.separator} this.attachmentIds.add(java.util.UUID.fromString(String.valueOf(id)));${line.separator} }${line.separator} }${line.separator} }">
|
|
<include name="**/CreateMessage.java"/>
|
|
</replace>
|
|
</target>
|
|
</configuration>
|
|
</execution>
|
|
</executions>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.apache.maven.plugins</groupId>
|
|
<artifactId>maven-compiler-plugin</artifactId>
|
|
<configuration>
|
|
<annotationProcessorPaths>
|
|
<path>
|
|
<groupId>org.mapstruct</groupId>
|
|
<artifactId>mapstruct-processor</artifactId>
|
|
<version>${mapstruct.version}</version>
|
|
</path>
|
|
</annotationProcessorPaths>
|
|
</configuration>
|
|
</plugin>
|
|
</plugins>
|
|
</build>
|
|
</project>
|