Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAT-16600] Implement method to send ping signal to DB server for connect command #517

Merged
merged 3 commits into from
May 23, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
* #L%
*/

import com.mongodb.MongoException;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import liquibase.CatalogAndSchema;
import liquibase.Scope;
import liquibase.changelog.ChangeLogHistoryServiceFactory;
import liquibase.database.DatabaseConnection;
import liquibase.exception.DatabaseException;
import liquibase.exception.LiquibaseException;
import liquibase.executor.Executor;
import liquibase.executor.ExecutorService;
Expand All @@ -32,6 +36,9 @@
import liquibase.nosql.database.AbstractNoSqlDatabase;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.bson.BsonDocument;
import org.bson.BsonInt64;
import org.bson.conversions.Bson;

import static liquibase.nosql.executor.NoSqlExecutor.EXECUTOR_NAME;

Expand Down Expand Up @@ -118,5 +125,19 @@ public Boolean getSupportsValidator() {
return MongoConfiguration.SUPPORTS_VALIDATOR.getCurrentValue();
}

@Override
vitaliimak marked this conversation as resolved.
Show resolved Hide resolved
public void checkDatabaseConnection() throws DatabaseException {
DatabaseConnection connection = getConnection();
try {
if (connection instanceof MongoConnection) {
MongoClient mongoClient = ((MongoConnection) connection).getMongoClient();
Bson command = new BsonDocument("ping", new BsonInt64(1));
MongoDatabase adminDb = mongoClient.getDatabase(ADMIN_DATABASE_NAME);
adminDb.runCommand(command);
}
} catch (MongoException e) {
throw new DatabaseException(e);
}
}

}
Loading