Skip to content

Commit

Permalink
Refactor checks with interface + 1 implementation by check
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Leclerc <[email protected]>
  • Loading branch information
sylvlecl committed Jun 8, 2021
1 parent a2a241e commit a81433c
Show file tree
Hide file tree
Showing 12 changed files with 604 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Lists;
import com.powsybl.afs.cassandra.checks.CassandraAppStorageCheckSupport;
import com.powsybl.afs.cassandra.checks.CassandraAppStorageChecks;
import com.powsybl.afs.storage.*;
import com.powsybl.afs.storage.buffer.*;
import com.powsybl.afs.storage.check.FileSystemCheckIssue;
Expand Down Expand Up @@ -327,7 +329,7 @@ public CassandraAppStorage(String fileSystemName, Supplier<CassandraContext> con

// prepared statement
preparedStatementsSupplier = Suppliers.memoize(PreparedStatements::new);
checks = new CassandraAppStorageChecks(this, this::getSession);
checks = new CassandraAppStorageChecks();
}

@Override
Expand Down Expand Up @@ -1490,7 +1492,31 @@ public List<String> getSupportedFileSystemChecks() {

@Override
public List<FileSystemCheckIssue> checkFileSystem(FileSystemCheckOptions options) {
return checks.check(options);
return checks.check(checkSupport(), options);
}

/**
* Provides access to internal functionalities for maintenance checks
*/
private CassandraAppStorageCheckSupport checkSupport() {
return new CassandraAppStorageCheckSupport() {
@Override
public CassandraAppStorage getStorage() {
return CassandraAppStorage.this;
}

@Override
public Session getSession() {
return CassandraAppStorage.this.getSession();
}

@Override
public void removeData(UUID nodeId) {
List<Statement> statements = new ArrayList<>();
CassandraAppStorage.this.removeAllData(nodeId, statements);
executeStatements(statements);
}
};
}

private void executeStatements(List<Statement> statements) {
Expand Down
Loading

0 comments on commit a81433c

Please sign in to comment.