adjusted all MongoDB 4.3.1 incompatibilities from a compilation perspective; see what Hudson says...

This commit is contained in:
Axel Uhl
2021-08-25 22:08:32 +02:00
parent 0bd21957a8
commit c311bc8ba2
16 changed files with 59 additions and 58 deletions
@@ -4,7 +4,7 @@ import org.bson.Document;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sailing.domain.igtimiadapter.persistence.MongoObjectFactory;
public class MongoObjectFactoryImpl implements MongoObjectFactory {
@@ -23,7 +23,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
@Override
public void storeAccessToken(String creatorName, String accessToken) {
final Document basicDBObject = getAccessTokenDBQuery(creatorName, accessToken);
db.getCollection(CollectionNames.IGTIMI_ACCESS_TOKENS.name()).withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(basicDBObject, basicDBObject, new UpdateOptions().upsert(true));
db.getCollection(CollectionNames.IGTIMI_ACCESS_TOKENS.name()).withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(basicDBObject, basicDBObject, new ReplaceOptions().upsert(true));
}
private Document getAccessTokenDBQuery(String creatorName, String accessToken) {
@@ -1013,7 +1013,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
windFixesToMigrate.add(new MongoObjectFactoryImpl(database).storeWindTrackEntry(race, regattaName,
wind.getB(), wind.getA()));
}
final long size = windTracks.count(queryByName);
final long size = windTracks.countDocuments(queryByName);
logger.info("Migrating " + size + " wind fixes of regatta " + regattaName
+ " and race " + race.getName() + " to ID-based keys");
windTracks.insertMany(windFixesToMigrate);
@@ -2719,7 +2719,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
// there is a corner case where tests can create just one competitor without boat
// before we migrate we need to check if this case
if (competitorsCollectionExist && !boatsCollectionCollectionExist) {
long competitorCount = orginalCompetitorCollection.count();
long competitorCount = orginalCompetitorCollection.estimatedDocumentCount();
if (competitorCount > 0) {
Document oneCompetitorDbObject = orginalCompetitorCollection.find().first();
Object boatObject = oneCompetitorDbObject.get(CompetitorJsonConstants.FIELD_BOAT);
@@ -3016,7 +3016,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
final MongoCollection<Document> collection = database
.getCollection(CollectionNames.CONNECTIVITY_PARAMS_FOR_RACES_TO_BE_RESTORED.name());
final FindIterable<Document> cursor = collection.find();
final long count = collection.count();
final long count = collection.countDocuments();
logger.info("Restoring " + count + " races");
final List<Document> restoreParameters = new ArrayList<>();
// consume all elements quickly to avoid cursor/DB timeouts while restoring many races;
@@ -30,6 +30,7 @@ import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.result.DeleteResult;
import com.sap.sailing.domain.abstractlog.AbstractLogEventAuthor;
@@ -373,7 +374,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
storeColumnFactors(leaderboard, dbLeaderboard);
storeLeaderboardCorrectionsAndDiscards(leaderboard, dbLeaderboard);
}
leaderboardCollection.replaceOne(query, dbLeaderboard, new UpdateOptions().upsert(true));
leaderboardCollection.replaceOne(query, dbLeaderboard, new ReplaceOptions().upsert(true));
}
private void storeColumnFactors(Leaderboard leaderboard, Document dbLeaderboard) {
@@ -544,7 +545,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
dbLeaderboardIds.add(dbLeaderboardId);
}
dbLeaderboardGroup.put(FieldNames.LEADERBOARD_GROUP_LEADERBOARDS.name(), dbLeaderboardIds);
leaderboardGroupCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbLeaderboardGroup, new UpdateOptions().upsert(true));
leaderboardGroupCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbLeaderboardGroup, new ReplaceOptions().upsert(true));
}
@Override
@@ -570,7 +571,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Document currentServerConfig = serverCollection.find().first();
if (currentServerConfig != null) {
serverCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(
currentServerConfig, newServerConfig, new UpdateOptions().upsert(true));
currentServerConfig, newServerConfig, new ReplaceOptions().upsert(true));
} else {
serverCollection.insertOne(newServerConfig);
}
@@ -587,7 +588,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
serverDBObject.put(FieldNames.SERVER_URL.name(), server.getURL().toExternalForm());
serverDBObject.put(FieldNames.INCLUDE.name(), server.isInclude());
serverDBObject.put(FieldNames.SELECTED_EVENT_IDS.name(), server.getSelectedEventIds());
serverCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, serverDBObject, new UpdateOptions().upsert(true));
serverCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, serverDBObject, new ReplaceOptions().upsert(true));
}
@Override
@@ -600,7 +601,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
serverDBObject.put(FieldNames.INCLUDE.name(), include);
serverDBObject.put(FieldNames.SELECTED_EVENT_IDS.name(), selectedEventIds);
serverCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, serverDBObject,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
}
@Override
@@ -653,7 +654,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
sailorsInfoWebsiteURLs.add(sailorsInfoWebsiteObject);
}
eventDBObject.put(FieldNames.EVENT_SAILORS_INFO_WEBSITES.name(), sailorsInfoWebsiteURLs);
eventCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, eventDBObject, new UpdateOptions().upsert(true));
eventCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, eventDBObject, new ReplaceOptions().upsert(true));
// now store the links to the leaderboard groups
MongoCollection<Document> linksCollection = database.getCollection(CollectionNames.LEADERBOARD_GROUP_LINKS_FOR_EVENTS.name());
linksCollection.createIndex(new Document(FieldNames.EVENT_ID.name(), 1));
@@ -664,7 +665,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Document dbLinks = new Document();
dbLinks.put(FieldNames.EVENT_ID.name(), event.getId());
dbLinks.put(FieldNames.LEADERBOARD_GROUP_UUID.name(), lgUUIDs);
linksCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbLinks, new UpdateOptions().upsert(true));
linksCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbLinks, new ReplaceOptions().upsert(true));
}
@Override
@@ -747,7 +748,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
final int MAX_TRIES = 3;
for (int i=0; i<MAX_TRIES && !success; i++) {
try {
regattasCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbRegatta, new UpdateOptions().upsert(true));
regattasCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbRegatta, new ReplaceOptions().upsert(true));
success = true;
} catch (DuplicateKeyException e) {
if (i+1==MAX_TRIES) {
@@ -826,7 +827,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Document query = new Document(FieldNames.RACE_ID_AS_STRING.name(), raceIDAsString);
Document entry = new Document(FieldNames.RACE_ID_AS_STRING.name(), raceIDAsString);
entry.put(FieldNames.REGATTA_NAME.name(), regatta.getName());
regattaForRaceIDCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new UpdateOptions().upsert(true));
regattaForRaceIDCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new ReplaceOptions().upsert(true));
}
@Override
@@ -1495,7 +1496,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
JSONObject json = competitorSerializer.serialize(competitor);
Document query = Document.parse(CompetitorJsonSerializer.getCompetitorIdQuery(competitor).toJSONString());
Document entry = Document.parse(json.toJSONString());
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new UpdateOptions().upsert(true));
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new ReplaceOptions().upsert(true));
}
private void storeCompetitorWithBoat(CompetitorWithBoat competitor) {
@@ -1503,7 +1504,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
JSONObject json = competitorWithBoatRefSerializer.serialize(competitor);
Document query = Document.parse(CompetitorJsonSerializer.getCompetitorIdQuery(competitor).toString());
Document entry = Document.parse(json.toString());
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new UpdateOptions().upsert(true));
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new ReplaceOptions().upsert(true));
}
@Override
@@ -1570,7 +1571,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
JSONObject json = boatSerializer.serialize(boat);
Document query = Document.parse(BoatJsonSerializer.getBoatIdQuery(boat).toString());
Document entry = Document.parse(json.toString());
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new UpdateOptions().upsert(true));
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new ReplaceOptions().upsert(true));
}
@Override
@@ -1614,7 +1615,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
configDocument.put(FieldNames.CONFIGURATION_ID_AS_STRING.name(), configuration.getId().toString());
Document query = new Document();
query.put(FieldNames.CONFIGURATION_ID_AS_STRING.name(), configuration.getId().toString());
configurationsCollections.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, configDocument, new UpdateOptions().upsert(true));
configurationsCollections.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, configDocument, new ReplaceOptions().upsert(true));
}
private Document createDeviceConfigurationObject(DeviceConfiguration configuration) {
@@ -1665,7 +1666,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Document query = new Document(FieldNames.RESULT_PROVIDERNAME.name(), resultProviderName);
Document entry = new Document(FieldNames.RESULT_PROVIDERNAME.name(), resultProviderName);
entry.put(FieldNames.RESULT_URL.name(), url.toString());
resultUrlsCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new UpdateOptions().upsert(true));
resultUrlsCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry, new ReplaceOptions().upsert(true));
}
@Override
@@ -1889,7 +1890,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
key.putAll(paramsPersistenceService.getKey(params));
Document dbObject = new Document();
dbObject.putAll(paramsPersistenceService.mapFrom(params));
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(key, dbObject, new UpdateOptions().upsert(true));
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(key, dbObject, new ReplaceOptions().upsert(true));
} catch (NoCorrespondingServiceRegisteredException e) {
logger.log(Level.WARNING, "Couldn't find a persistence service for connectivity parameters of type "+typeIdentifier+
". Couldn't store race "+params.getTrackerID()+" for restoring.", e);
@@ -1928,7 +1929,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
final URL remoteUrl = raceInfo.getRemoteUrl();
newValue.append(FieldNames.REMOTE_URL.name(), remoteUrl == null ? null : remoteUrl.toExternalForm());
newValue.append(FieldNames.ANNIVERSARY_TYPE.name(), anniversary.getValue().getB().toString());
anniversarysStored.replaceOne(currentProxy, newValue, new UpdateOptions().upsert(true));
anniversarysStored.replaceOne(currentProxy, newValue, new ReplaceOptions().upsert(true));
}
} catch (Exception e) {
e.printStackTrace();
@@ -141,7 +141,7 @@ public class MediaDBImpl implements MediaDB {
@Override
public List<MediaTrack> loadAllMediaTracks() {
MongoCursor<Document> cursor = getVideoCollection().find().sort(sortByStartTimeAndTitle).iterator();
List<MediaTrack> result = new ArrayList<>((int) getVideoCollection().count());
List<MediaTrack> result = new ArrayList<>((int) getVideoCollection().estimatedDocumentCount());
while (cursor.hasNext()) {
result.add(createMediaTrackFromDb(cursor.next()));
}
@@ -10,7 +10,7 @@ import org.bson.Document;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sailing.domain.swisstimingadapter.SwissTimingArchiveConfiguration;
import com.sap.sailing.domain.swisstimingadapter.SwissTimingConfiguration;
import com.sap.sailing.domain.swisstimingadapter.SwissTimingFactory;
@@ -152,7 +152,7 @@ public class SwissTimingAdapterPersistenceImpl implements SwissTimingAdapterPers
.getCollection(CollectionNames.SWISSTIMING_ARCHIVE_CONFIGURATIONS.name());
Document result = storeSwissTimingArchiveConfiguration(config);
stArchiveConfigCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(result, result,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
}
private Document storeSwissTimingArchiveConfiguration(SwissTimingArchiveConfiguration config) {
@@ -185,11 +185,9 @@ public class SwissTimingAdapterPersistenceImpl implements SwissTimingAdapterPers
MongoCollection<org.bson.Document> stConfigCollection = database
.getCollection(CollectionNames.SWISSTIMING_CONFIGURATIONS.name());
Document result = storeSwissTimingConfiguration(config);
Document updateQuery = new Document(FieldNames.ST_CONFIG_JSON_URL.name(), config.getJsonURL());
updateQuery.put(FieldNames.ST_CONFIG_CREATOR_NAME.name(), config.getCreatorName());
stConfigCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(updateQuery, result,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
}
}
@@ -5,7 +5,7 @@ import org.bson.Document;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sailing.domain.tractracadapter.TracTracConfiguration;
import com.sap.sailing.domain.tractracadapter.persistence.MongoObjectFactory;
@@ -40,7 +40,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
tracTracConfiguration.getJSONURL());
updateQuery.put(FieldNames.TT_CONFIG_CREATOR_NAME.name(), tracTracConfiguration.getCreatorName());
ttConfigCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(updateQuery, result,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
}
private Document storeTracTracConfiguration(TracTracConfiguration tracTracConfiguration) {
@@ -11,7 +11,7 @@ import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sailing.expeditionconnector.ExpeditionDeviceConfiguration;
import com.sap.sailing.expeditionconnector.persistence.MongoObjectFactory;
@@ -43,7 +43,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Exception lastException = null;
while (attempt < 5 && !success) {
try {
expeditionDeviceConfigurationsCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(key, expeditionDeviceConfigurationDBObject, new UpdateOptions().upsert(true));
expeditionDeviceConfigurationsCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(key, expeditionDeviceConfigurationDBObject, new ReplaceOptions().upsert(true));
success = true;
attempt++;
} catch (Exception e) {
@@ -14,7 +14,7 @@ import com.mongodb.BasicDBObject;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sailing.domain.common.DeviceIdentifier;
import com.sap.sailing.domain.common.PassingInstruction;
import com.sap.sailing.domain.common.Position;
@@ -67,7 +67,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
try {
Document entry = storeMarkPropertiesToDocument(deviceIdentifierServiceFinder, markProperties);
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
} catch (TransformationException | NoCorrespondingServiceRegisteredException e) {
logger.log(Level.WARNING, "Could not load mark properties because device identifier could not be stored.", e);
}
@@ -173,7 +173,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
final Document entry = storeMarkTemplateToDocument(markTemplate);
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
}
private Document storeMarkTemplateToDocument(MarkTemplate markTemplate) {
@@ -196,7 +196,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
final Document query = new Document(FieldNames.MARK_ROLE_ID.name(), markRole.getId().toString());
final Document entry = storeMarkRoleToDocument(markRole);
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
}
private Document storeMarkRoleToDocument(MarkRole markRole) {
@@ -220,7 +220,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
final Document query = new Document(FieldNames.COURSE_TEMPLATE_ID.name(), courseTemplate.getId().toString());
final Document entry = storeCourseTemplateToDocument(courseTemplate);
collection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, entry,
new UpdateOptions().upsert(true));
new ReplaceOptions().upsert(true));
}
private Document storeCourseTemplateToDocument(CourseTemplate courseTemplate) {
@@ -59,7 +59,7 @@ public abstract class AbstractPersistenceManager<T> implements PersistenceManage
}
public long countElements(Document query) {
return getCollection().count(query);
return getCollection().countDocuments(query);
}
public long countElements(String query) {
@@ -9,7 +9,7 @@ import org.bson.Document;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sse.filestorage.FileStorageServicePropertyStore;
import com.sap.sse.mongodb.MongoDBService;
@@ -60,7 +60,7 @@ public class MongoFileStorageServicePropertyStoreImpl implements FileStorageServ
.append(FieldNames.PROPERTY_VALUE.name(), propertyValue);
Document query = new Document().append(FieldNames.SERVICE_NAME.name(), serviceName)
.append(FieldNames.PROPERTY_NAME.name(), propertyName);
propertiesCollection.replaceOne(query, obj, new UpdateOptions().upsert(true));
propertiesCollection.replaceOne(query, obj, new ReplaceOptions().upsert(true));
}
@Override
@@ -76,6 +76,6 @@ public class MongoFileStorageServicePropertyStoreImpl implements FileStorageServ
public void writeActiveService(String serviceName) {
Document obj = new Document(FieldNames.SERVICE_NAME.name(), serviceName);
Document query = new Document();
activeServiceCollection.replaceOne(query, obj, new UpdateOptions().upsert(true));
activeServiceCollection.replaceOne(query, obj, new ReplaceOptions().upsert(true));
}
}
@@ -4,7 +4,7 @@ import org.bson.Document;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sse.landscape.aws.persistence.MongoObjectFactory;
import com.sap.sse.landscape.ssh.SSHKeyPair;
@@ -29,7 +29,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
keyPairDocument.put(FieldNames.SSH_KEY_PAIR_PUBLIC_KEY.name(), keyPair.getPublicKey());
keyPairDocument.put(FieldNames.SSH_KEY_PAIR_ENCRYPTED_PRIVATE_KEY.name(), keyPair.getEncryptedPrivateKey());
db.getCollection(CollectionNames.SSH_KEY_PAIRS.name()).withWriteConcern(WriteConcern.ACKNOWLEDGED)
.replaceOne(query, keyPairDocument, new UpdateOptions().upsert(true));
.replaceOne(query, keyPairDocument, new ReplaceOptions().upsert(true));
}
private Document getSSHKeyPairDBQuery(String regionId, String keyName) {
@@ -13,6 +13,7 @@ import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.connection.ClusterConnectionMode;
import com.mongodb.session.ClientSession;
import com.sap.sse.common.Duration;
import com.sap.sse.common.Util;
@@ -42,7 +43,7 @@ public abstract class MongoEndpointImpl implements MongoEndpoint {
final MongoCollection<Document> sourceCollection = from.getCollection(collectionName);
targetDatabase.createCollection(collectionName); // if we found it on the exporting side and it's empty it's important still to create it for equal hashes
final MongoCollection<Document> targetCollection = targetDatabase.getCollection(collectionName);
logger.info("...importing "+sourceCollection.count()+" documents from collection "+collectionName+" from "+from+" into "+this);
logger.info("...importing "+sourceCollection.estimatedDocumentCount()+" documents from collection "+collectionName+" from "+from+" into "+this);
List<Document> documentsToInsert = new ArrayList<>(BATCH_SIZE);
int i=0;
for (final Document document : sourceCollection.find()) {
@@ -63,7 +64,7 @@ public abstract class MongoEndpointImpl implements MongoEndpoint {
@Override
public boolean isInReplicaSet() throws URISyntaxException {
return getClient().getReplicaSetStatus() != null;
return getClient().getClusterDescription().getConnectionMode() != ClusterConnectionMode.SINGLE;
}
@Override
@@ -2,6 +2,7 @@ package com.sap.sse.landscape.mongodb.impl;
import java.net.URISyntaxException;
import com.mongodb.connection.ClusterConnectionMode;
import com.sap.sse.landscape.Host;
import com.sap.sse.landscape.mongodb.MongoProcessInReplicaSet;
import com.sap.sse.landscape.mongodb.MongoReplicaSet;
@@ -26,6 +27,6 @@ public class MongoProcessInReplicaSetImpl extends MongoProcessImpl implements Mo
@Override
public boolean isInReplicaSet() throws URISyntaxException {
return getReplicaSet().getClient().getReplicaSetStatus() != null;
return getReplicaSet().getClient().getClusterDescription().getConnectionMode() != ClusterConnectionMode.SINGLE;
}
}
@@ -7,7 +7,7 @@ import org.bson.Document;
import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sse.replication.ReplicaDescriptor;
import com.sap.sse.replication.persistence.MongoObjectFactory;
@@ -36,7 +36,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Arrays.asList(replicaDescriptor.getReplicableIdsAsStrings()));
replicaDescriptorDoc.put(FieldNames.REPLICA_PORT.name(), replicaDescriptor.getPort());
getReplicaDescriptorCollection().withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(replicaDescriptorDoc,
replicaDescriptorDoc, new UpdateOptions().upsert(true));
replicaDescriptorDoc, new ReplaceOptions().upsert(true));
}
@Override
@@ -12,7 +12,7 @@ import org.bson.Document;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sse.security.persistence.MongoObjectFactory;
public class MongoObjectFactoryImpl implements MongoObjectFactory {
@@ -66,7 +66,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
}
sessionAsDocument.append(FieldNames.SESSION_ATTRIBUTES.name(), sessionAttributes);
final Document key = getKey(cacheName, session);
sessionCollection.replaceOne(key, sessionAsDocument, new UpdateOptions().upsert(true));
sessionCollection.replaceOne(key, sessionAsDocument, new ReplaceOptions().upsert(true));
}
private List<Document> storePrincipalCollection(PrincipalCollection principalCollection) {
@@ -15,7 +15,7 @@ import com.mongodb.WriteConcern;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.IndexOptions;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.ReplaceOptions;
import com.sap.sse.security.interfaces.Social;
import com.sap.sse.security.shared.AccessControlListAnnotation;
import com.sap.sse.security.shared.Account;
@@ -85,7 +85,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
permissionMap.add(permissionMapEntry);
}
dbACL.put(FieldNames.AccessControlList.PERMISSION_MAP.name(), permissionMap);
aclCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbACL, new UpdateOptions().upsert(true));
aclCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbACL, new ReplaceOptions().upsert(true));
}
@Override
@@ -113,7 +113,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
dbOwnership.put(FieldNames.Ownership.OWNER_USERNAME.name(), owner.getAnnotation().getUserOwner()==null?null:owner.getAnnotation().getUserOwner().getName());
dbOwnership.put(FieldNames.Ownership.TENANT_OWNER_ID.name(), owner.getAnnotation().getTenantOwner()==null?null:owner.getAnnotation().getTenantOwner().getId());
dbOwnership.put(FieldNames.Ownership.OBJECT_DISPLAY_NAME.name(), owner.getDisplayNameOfAnnotatedObject());
ownershipCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbOwnership, new UpdateOptions().upsert(true));
ownershipCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbOwnership, new ReplaceOptions().upsert(true));
}
@Override
@@ -144,7 +144,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
stringPermissions.add(permission.toString());
}
dbRole.put(FieldNames.Role.PERMISSIONS.name(), stringPermissions);
roleCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbRole, new UpdateOptions().upsert(true));
roleCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbRole, new ReplaceOptions().upsert(true));
}
@Override
@@ -187,7 +187,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
dbRoleDefinitionMap.add(dbRoleDef);
}
dbUserGroup.put(FieldNames.UserGroup.ROLE_DEFINITION_MAP.name(), dbRoleDefinitionMap);
userGroupCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbUserGroup, new UpdateOptions().upsert(true));
userGroupCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbUserGroup, new ReplaceOptions().upsert(true));
}
@Override
@@ -232,7 +232,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
}
dbUser.put(FieldNames.User.DEFAULT_TENANT_IDS.name(), defaultTennants);
dbUser.put(FieldNames.User.SUBSCRIPTIONS.name(), createSubscriptions(user.getSubscriptions()));
usersCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbUser, new UpdateOptions().upsert(true));
usersCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbUser, new ReplaceOptions().upsert(true));
}
@Override
@@ -276,7 +276,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Document query = new Document(FieldNames.Settings.NAME.name(), FieldNames.Settings.VALUES.name());
dbSettings.put(FieldNames.Settings.NAME.name(), FieldNames.Settings.VALUES.name());
dbSettings.put(FieldNames.Settings.MAP.name(), createSettingsMapObject(settings));
settingCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbSettings, new UpdateOptions().upsert(true));
settingCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbSettings, new ReplaceOptions().upsert(true));
}
@Override
@@ -298,7 +298,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Document query = new Document(FieldNames.Preferences.USERNAME.name(), username);
Document update = new Document(FieldNames.Preferences.KEYS_AND_VALUES.name(), dbSettings);
update.put(FieldNames.Preferences.USERNAME.name(), username);
settingCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, update, new UpdateOptions().upsert(true));
settingCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, update, new ReplaceOptions().upsert(true));
}
@Override
@@ -316,7 +316,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
Document query = new Document(FieldNames.Settings.NAME.name(), FieldNames.Settings.TYPES.name());
dbSettingTypes.put(FieldNames.Settings.NAME.name(), FieldNames.Settings.TYPES.name());
dbSettingTypes.put(FieldNames.Settings.MAP.name(), createSettingTypesMapObject(settingTypes));
settingCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbSettingTypes, new UpdateOptions().upsert(true));
settingCollection.withWriteConcern(WriteConcern.ACKNOWLEDGED).replaceOne(query, dbSettingTypes, new ReplaceOptions().upsert(true));
}
private Document createSettingsMapObject(Map<String, Object> settings) {