Skip to content

Commit

Permalink
Bump up srping data and mongo driver to support serverless Atlass
Browse files Browse the repository at this point in the history
  • Loading branch information
Aziz Namazov committed Dec 23, 2021
1 parent fc61122 commit 203c627
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 39 deletions.
1 change: 1 addition & 0 deletions api/src/main/resources/quack.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mongo.replicaSet=localhost:27017
mongo.dbname=test
mongo.username=
mongo.password=
mongo.uri=

#Authentication
whoru.auth.provider=ru.greatbit.whoru.auth.providers.StubAuthProvider
Expand Down
1 change: 1 addition & 0 deletions assembly/quack.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mongo.replicaSet=mongod:27017
mongo.dbname=test
mongo.username=
mongo.password=
mongo.uri=
#Authentication
whoru.auth.provider=ru.greatbit.whoru.auth.providers.StubAuthProvider
jira.ui.endpoint=http://jira.quack.com
Expand Down
6 changes: 5 additions & 1 deletion beans/src/main/java/com/testquack/beans/LaunchStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LaunchStats {
protected int total;

@XmlElement(required = true)
private final Map<LaunchStatus, Integer> statusCounters;
private Map<LaunchStatus, Integer> statusCounters;

public LaunchStats() {
statusCounters = new HashMap<>();
Expand All @@ -32,4 +32,8 @@ public int getTotal() {
public void setTotal(int total) {
this.total = total;
}

public void setStatusCounters(Map<LaunchStatus, Integer> statusCounters) {
this.statusCounters = statusCounters;
}
}
6 changes: 5 additions & 1 deletion beans/src/main/java/com/testquack/beans/LauncherConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class LauncherConfig extends LauncherConfigBase {
@XmlElement(required = true)
private final Map<String, String> properties = new HashMap<>();
private Map<String, String> properties = new HashMap<>();

@Override
public Object createNewInstance() {
Expand All @@ -16,4 +16,8 @@ public Object createNewInstance() {
public Map<String, String> getProperties() {
return properties;
}

public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
}
10 changes: 8 additions & 2 deletions dal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@
</dependency>

<!-- MongoDB -->
<!-- <dependency>-->
<!-- <groupId>org.mongodb</groupId>-->
<!-- <artifactId>mongo-java-driver</artifactId>-->
<!-- <version>3.12.10</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.9</version>
<!-- <artifactId>mongodb-driver-legacy</artifactId>-->
<artifactId>mongodb-driver-sync</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.embed</groupId>
Expand Down
52 changes: 34 additions & 18 deletions dal/src/main/java/com/testquack/dal/MongoConfig.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.testquack.dal;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.mongodb.ServerApi;
import com.mongodb.ServerApiVersion;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -16,7 +20,7 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;

@Configuration
public class MongoConfig extends AbstractMongoConfiguration {
public class MongoConfig extends AbstractMongoClientConfiguration {

@Value("${mongo.replicaSet}")
String replicaSet;
Expand All @@ -30,15 +34,14 @@ public class MongoConfig extends AbstractMongoConfiguration {
@Value("${mongo.password}")
String password;

@Value("${mongo.uri}")
String uri;

@Override
public MongoClient mongoClient() {
MongoClientOptions clientOptions =
MongoClientOptions.builder().
connectionsPerHost(40).
threadsAllowedToBlockForConnectionMultiplier(1000).
connectTimeout(15000).
socketTimeout(60000).
build();
if(!isEmpty(uri)){
return getClientByUri();
}

List<ServerAddress> addresses = Stream.of(replicaSet.split(",")).
map(String::trim).
Expand All @@ -51,14 +54,27 @@ public MongoClient mongoClient() {
}).
collect(Collectors.toList());

if (isEmpty(username)){
return new MongoClient(addresses, clientOptions);
MongoClientSettings.Builder settingsBuilder = MongoClientSettings.builder()
.applyToClusterSettings(builder ->
builder.hosts(addresses)
);

if (!isEmpty(username)){
settingsBuilder.credential(createCredential(username, dbname, password.toCharArray()));
}
return new MongoClient(
addresses,
createCredential(username, dbname, password.toCharArray()),
clientOptions
);

return MongoClients.create(settingsBuilder.build());
}

private MongoClient getClientByUri(){
ConnectionString connectionString = new ConnectionString(uri);
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.serverApi(ServerApi.builder()
.version(ServerApiVersion.V1)
.build())
.build();
return MongoClients.create(settings);
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions dal/src/main/java/com/testquack/dal/impl/DBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -85,8 +84,8 @@ public static Query getQuery(Class entityClass, Filter filter) {
// Add ordering
if (!isEmpty(filter.getSortField())) {
Sort sort = filter.getOrder() != null && filter.getOrder().equals(Order.DESC) ?
new Sort(Sort.Direction.DESC, filter.getSortField()) :
new Sort(Sort.Direction.ASC, filter.getSortField());
Sort.by(Sort.Direction.DESC, filter.getSortField()) :
Sort.by(Sort.Direction.ASC, filter.getSortField());
query.with(sort);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ProjectRepositoryCustomImpl extends CommonRepositoryImpl<Project>

@Override
public List<Project> findByOrganizationId(String id) {
Query query = new Query().with(new Sort(Sort.Direction.ASC, "id"));
Query query = new Query().with(Sort.by(Sort.Direction.ASC, "id"));
query.addCriteria(Criteria.where("organizationId").in(id));
return mongoOperations.find(query, Project.class);
}
Expand Down
4 changes: 2 additions & 2 deletions dal/src/main/resources/dal-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
<mongo:repositories base-package="com.testquack.dal" repository-impl-postfix="CustomImpl"/>

<!-- Grid FS -->
<mongo:mapping-converter id="converter" />
<mongo:mapping-converter id="mappingMongoConverter" />
<bean name="gridFsTemplate"
class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
<constructor-arg ref="mongoDbFactory" />
<constructor-arg ref="converter" />
<constructor-arg ref="mappingMongoConverter" />
</bean>


Expand Down
3 changes: 2 additions & 1 deletion dal/src/main/resources/quack.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mongo.replicaSet=localhost:37017
mongo.dbname=test
mongo.username=
mongo.password=
mongo.password=
mongo.uri=
3 changes: 2 additions & 1 deletion dal/src/test/resources/quack-dal-test.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mongo.replicaSet=localhost:37027
mongo.dbname=test
mongo.username=
mongo.password=
mongo.password=
mongo.uri=
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler>1.8</maven.compiler>
<jersey.version>2.25.1</jersey.version>
<spring.version>5.0.9.RELEASE</spring.version>
<spring.data.version>2.0.10.RELEASE</spring.data.version>
<spring.version>5.3.14</spring.version>
<spring.data.version>3.3.0</spring.data.version>
<httpclient.version>4.5.2</httpclient.version>
<jackson.version>2.8.5</jackson.version>
<jetty.port>9999</jetty.port>
Expand Down Expand Up @@ -192,11 +192,11 @@
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${spring.data.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.data</groupId>-->
<!-- <artifactId>spring-data-commons</artifactId>-->
<!-- <version>${spring.data.version}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mongodb.client.gridfs.GridFSBuckets;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
Expand All @@ -23,7 +24,7 @@ public class MongoStorage implements Storage {
private GridFsTemplate gridOperations;

@Autowired
private MongoDbFactory mongoDbFactory;
private MongoDatabaseFactory mongoDbFactory;

@Override
public Attachment upload(InputStream uploadedInputStream, String fileName, long size) throws IOException {
Expand Down Expand Up @@ -56,7 +57,7 @@ public InputStream get(Attachment attachment) throws IOException {
}
}
private GridFSBucket getGridFs() {
MongoDatabase db = mongoDbFactory.getDb();
MongoDatabase db = mongoDbFactory.getMongoDatabase();
return GridFSBuckets.create(db);
}
}
1 change: 1 addition & 0 deletions services/src/test/resources/quack-service-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mongo.replicaSet=localhost:37017
mongo.dbname=test
mongo.username=
mongo.password=
mongo.uri=

#Authentication
whoru.auth.provider=ru.greatbit.whoru.auth.providers.StubAuthProvider
Expand Down

0 comments on commit 203c627

Please sign in to comment.