добавлена MongoDB для хранения данных об артефактах

see #3
This commit is contained in:
2022-05-09 16:17:46 +03:00
parent 420c62f885
commit 1b48647c39
9 changed files with 135 additions and 9 deletions

View File

@@ -1,12 +1,20 @@
package ru.di9.mirror.web.config;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import io.minio.MinioClient;
import okhttp3.OkHttpClient;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.di9.mirror.core.handler.IndexOfHandler;
import ru.di9.mirror.core.handler.MavenHandler;
import ru.di9.mirror.core.repository.ArtifactRepository;
import ru.di9.mirror.core.service.ExternalMavenService;
import ru.di9.mirror.core.service.MinioService;
@@ -17,8 +25,9 @@ public class WebConfig {
@Bean
public MavenHandler mavenHandler(MinioService minioService,
List<ExternalMavenService> externalMavenServices) {
return new MavenHandler(minioService, externalMavenServices);
List<ExternalMavenService> externalMavenServices,
ArtifactRepository artifactRepository) {
return new MavenHandler(minioService, externalMavenServices, artifactRepository);
}
@Bean
@@ -54,4 +63,26 @@ public class WebConfig {
return new OkHttpClient();
}
@Bean
public MongoClient mongoClient(@Value("${mongodb.host}") String host, @Value("${mongodb.port}") int port) {
return MongoClients.create(MongoClientSettings.builder()
.applyToClusterSettings(builder -> builder.hosts(List.of(new ServerAddress(host, port))))
.build());
}
@Bean
public MongoDatabase mongoDatabase(MongoClient mongoClient,
@Value("${mongodb.database}") String database) {
return mongoClient.getDatabase(database);
}
@Bean
public MongoCollection<Document> artifactCollection(MongoDatabase database) {
return database.getCollection("artifacts");
}
@Bean
public ArtifactRepository artifactRepository(MongoCollection<Document> artifactCollection) {
return new ArtifactRepository(artifactCollection);
}
}

View File

@@ -24,5 +24,21 @@
"name": "maven-mirrors.list",
"type": "java.util.List<ru.di9.mirror.web.config.MavenMirrorsProperties.MirrorData>",
"sourceType": "java.util.List<ru.di9.mirror.web.config.MavenMirrorsProperties.MirrorData>"
}
] }
},
{
"name": "mongodb.host",
"type": "java.lang.String",
"description": "MongoDB host."
},
{
"name": "mongodb.port",
"type": "java.lang.Integer",
"description": "MongoDB port."
},
{
"name": "mongodb.database",
"type": "java.lang.String",
"description": "MongoDB database name."
}
]
}

View File

@@ -15,6 +15,11 @@ minio:
secretKey: 'mirror123'
bucket: 'mirror'
mongodb:
host: 'dev.di9.ru'
port: 27017
database: 'mirror'
maven-mirrors:
list:
- id: 'maven_central'