Skip to content

Commit

Permalink
Release/0.1.7 (#7)
Browse files Browse the repository at this point in the history
* Upgrade bigtable library

* Use bigtable emulator

* Refactor to use javafx services

* Improve error description
  • Loading branch information
erikmafo authored Jun 28, 2020
1 parent 44b4f31 commit 618a7ca
Show file tree
Hide file tree
Showing 40 changed files with 839 additions and 527 deletions.
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.erikmafo</groupId>
<artifactId>bigtableviewer</artifactId>
<version>0.1.6</version>
<version>0.1.7</version>
<packaging>jar</packaging>
<name>bigtableviewer</name>

Expand Down Expand Up @@ -173,6 +173,16 @@
</build>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable</artifactId>
<version>1.13.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable-emulator</artifactId>
<version>0.122.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
Expand All @@ -185,11 +195,6 @@
<version>11.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-hbase-1.x-shaded</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand Down
45 changes: 2 additions & 43 deletions src/main/java/com/erikmafo/btviewer/MainApp.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package com.erikmafo.btviewer;
import com.erikmafo.btviewer.config.AppConfig;
import com.erikmafo.btviewer.config.ApplicationEnvironment;
import com.erikmafo.btviewer.services.*;
import com.erikmafo.btviewer.services.inmemory.InMemoryBigtableClient;
import com.erikmafo.btviewer.services.inmemory.InMemoryInstanceManager;
import com.erikmafo.btviewer.services.inmemory.InMemoryTableConfigManager;
import com.erikmafo.btviewer.services.inmemory.TestDataUtil;
import com.google.inject.Binder;
import com.google.inject.Guice;
import com.google.inject.Module;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
Expand All @@ -18,7 +10,7 @@
/**
* Created by erikmafo on 12.12.17.
*/
public class MainApp extends Application implements Module {
public class MainApp extends Application {

public static void main(String[] args) {
launch(args);
Expand All @@ -27,7 +19,7 @@ public static void main(String[] args) {
@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
loader.setControllerFactory(Guice.createInjector(this)::getInstance);
loader.setControllerFactory(Guice.createInjector(new ServicesModule())::getInstance);
Parent root = loader.load();
primaryStage.setTitle("Bigtable viewer");
primaryStage.setScene(new Scene(root, 800, 700));
Expand All @@ -38,37 +30,4 @@ public void start(Stage primaryStage) throws Exception{
public void stop() throws Exception {
super.stop();
}

@Override
public void configure(Binder binder) {

var config = AppConfig.load(ApplicationEnvironment.get());

if (config.useInMemoryBigtableClient()) {
var inMemoryBigtableClient = new InMemoryBigtableClient();
TestDataUtil.injectWithTestData(inMemoryBigtableClient);
binder.bind(BigtableClient.class).toInstance(inMemoryBigtableClient);
}
else {
binder.bind(BigtableClient.class).toInstance(new BigtableClientImpl());
}

if (config.useInMemoryTableConfigManager()) {
var inMemoryTableConfigManager = new InMemoryTableConfigManager();
binder.bind(TableConfigManager.class).toInstance(inMemoryTableConfigManager);
}
else {
binder.bind(TableConfigManager.class).toInstance(new TableConfigManagerImpl());
}

if (config.useInMemoryInstanceManager()) {
var inMemoryInstanceManager = new InMemoryInstanceManager();
TestDataUtil.injectWithTestData(inMemoryInstanceManager);
binder.bind(BigtableInstanceManager.class).toInstance(inMemoryInstanceManager);
} else {
binder.bind(BigtableInstanceManager.class).toInstance(new BigtableInstanceManagerImpl());
}

binder.bind(CredentialsManager.class).toInstance(new CredentialsManager());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ private void addColumn(String family, String qualifier) {
private TableColumn<BigtableRow, Object> getQualifierTableColumn(String family, String qualifier) {
TableColumn<BigtableRow, Object> qualifierColumn = new TableColumn<>(qualifier);
qualifierColumn.setCellValueFactory(param -> {
BigtableRow bigtableRow = param.getValue();
return new ReadOnlyObjectWrapper<>(bigtableRow.getCellValue(family, qualifier, valueConverter));
var row = param.getValue();
return new ReadOnlyObjectWrapper<>(row.getCellValue(family, qualifier, valueConverter));
});
return qualifierColumn;
}
Expand All @@ -150,6 +150,10 @@ private void setBigTableRows(ObservableList<BigtableRow> bigtableRows) {
}

public void setValueConverter(BigtableValueConverter valueConverter) {
if (valueConverter.equals(this.valueConverter)) {
return;
}

this.valueConverter = valueConverter;
var rows = this.tableView.getItems();
clear();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/erikmafo/btviewer/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ private static String getConfigName(ApplicationEnvironment environment) {
String.format("config.%s.properties", environment.getName());
}

private final boolean useInMemoryBigtableClient;
private final boolean useBigtableEmulator;
private final boolean useInMemoryTableConfigManager;
private final boolean useInMemoryInstanceManager;

@Inject
public AppConfig(@Named("USE_IN_MEMORY_BIGTABLE_CLIENT") boolean useInMemoryBigtableClient,
public AppConfig(@Named("USE_BIGTABLE_EMULATOR") boolean useBigtableEmulator,
@Named("USE_IN_MEMORY_TABLE_CONFIG_MANAGER") boolean useInMemoryTableConfigManager,
@Named("USE_IN_MEMORY_INSTANCE_MANAGER") boolean useInMemoryInstanceManager) {
this.useInMemoryBigtableClient = useInMemoryBigtableClient;
this.useBigtableEmulator = useBigtableEmulator;
this.useInMemoryTableConfigManager = useInMemoryTableConfigManager;
this.useInMemoryInstanceManager = useInMemoryInstanceManager;
}

public boolean useInMemoryBigtableClient() {
return useInMemoryBigtableClient;
public boolean useBigtableEmulator() {
return useBigtableEmulator;
}

public boolean useInMemoryTableConfigManager() {
Expand Down
138 changes: 68 additions & 70 deletions src/main/java/com/erikmafo/btviewer/controllers/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import com.erikmafo.btviewer.model.*;
import com.erikmafo.btviewer.services.*;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;

import javax.inject.Inject;
import java.io.IOException;
import java.util.List;

/**
* Created by erikmafo on 23.12.17.
Expand All @@ -31,20 +31,30 @@ public class MainController {
@FXML
private BigtableTableView bigtableTableView;

private final CredentialsManager credentialsManager;
private final BigtableInstanceManager bigtableInstanceManager;
private final TableConfigManager tableConfigManager;
private final BigtableClient bigtableClient;
private final SaveCredentialsPathService saveCredentialsPathService;
private final SaveInstancesService saveInstancesService;
private final LoadInstancesService loadInstancesService;
private final SaveTableConfigurationService saveTableConfigurationService;
private final LoadTableConfigurationService loadTableConfigurationService;
private final ReadRowsService readRowsService;
private final ListTablesService listTablesService;

@Inject
public MainController(CredentialsManager credentialsManager,
BigtableInstanceManager bigtableInstanceManager,
TableConfigManager tableConfigManager,
BigtableClient bigtableClient) {
this.credentialsManager = credentialsManager;
this.bigtableInstanceManager = bigtableInstanceManager;
this.tableConfigManager = tableConfigManager;
this.bigtableClient = bigtableClient;
public MainController(
SaveCredentialsPathService saveCredentialsPathService,
SaveInstancesService saveInstancesService,
LoadInstancesService loadInstancesService,
SaveTableConfigurationService saveTableConfigurationService,
LoadTableConfigurationService loadTableConfigurationService,
ReadRowsService readRowsService,
ListTablesService listTablesService) {
this.saveCredentialsPathService = saveCredentialsPathService;
this.saveInstancesService = saveInstancesService;
this.loadInstancesService = loadInstancesService;
this.saveTableConfigurationService = saveTableConfigurationService;
this.loadTableConfigurationService = loadTableConfigurationService;
this.readRowsService = readRowsService;
this.listTablesService = listTablesService;
}

public void initialize() {
Expand All @@ -61,12 +71,10 @@ public void initialize() {
}

private void loadBigtableInstances() {
try {
tablesListView.addBigtableInstances(bigtableInstanceManager.getInstances());
} catch (IOException e) {
e.printStackTrace();
displayErrorInfo("Unable to load bigtable instances");
}
loadInstancesService.setOnSucceeded(stateEvent ->
tablesListView.addBigtableInstances(loadInstancesService.getValue()));
loadInstancesService.setOnFailed(stateEvent -> displayErrorInfo("Failed to load instances", stateEvent));
loadInstancesService.restart();
}

private void onAddNewBigtableInstance(ActionEvent event) {
Expand All @@ -79,76 +87,66 @@ private void onAddNewBigtableInstance(ActionEvent event) {
}

private void saveInstance(BigtableInstance instance) {
try {
List<BigtableInstance> allInstances = bigtableInstanceManager.getInstances();
allInstances.add(instance);
bigtableInstanceManager.setInstances(allInstances);
} catch (IOException e) {
e.printStackTrace();
displayErrorInfo(String.format("Unable to save bigtable instance %s", instance.getInstanceId()));
}
saveInstancesService.addInstance(instance);
saveInstancesService.setOnFailed(stateEvent -> displayErrorInfo("Unable to save instance", stateEvent));
saveInstancesService.restart();
}

private void listBigtableTables(BigtableInstance instance) {
ListBigtableTables listBigtableTables =
new ListBigtableTables(bigtableClient, instance, credentialsManager.getCredentialsPath());
listBigtableTables.setOnSucceeded(workerStateEvent ->
tablesListView.addBigtableTables(listBigtableTables.getValue()));
listBigtableTables.start();
listTablesService.setInstance(instance);
listTablesService.setOnSucceeded(workerStateEvent ->
tablesListView.addBigtableTables(listTablesService.getValue()));
listTablesService.setOnFailed(stateEvent -> displayErrorInfo("Unable to list tables", stateEvent));
listTablesService.restart();
}

private void onScanTableAction(ScanTableAction actionEvent) {
bigtableTableView.clear();
BigtableTable currentTable = tablesListView.selectedTableProperty().get();
var currentTable = tablesListView.selectedTableProperty().get();
loadTableConfiguration(currentTable);
BigtableReadRequest request = new BigtableReadRequestBuilder()
.setCredentialsPath(credentialsManager.getCredentialsPath())
var request = new BigtableReadRequestBuilder()
.setTable(currentTable)
.setRowRange(new BigtableRowRange(actionEvent.getFrom(), actionEvent.getTo()))
.build();

readBigtableRows(request);
}

private void loadTableConfiguration(BigtableTable currentTable) {
var tableConfiguration = getTableConfiguration(currentTable);
if (tableConfiguration != null) {
bigtableTableView.setValueConverter(new BigtableValueConverter(tableConfiguration.getCellDefinitions()));
}
loadTableConfigurationService.setTable(currentTable);
loadTableConfigurationService.setOnSucceeded(event -> bigtableTableView.setValueConverter(
new BigtableValueConverter(loadTableConfigurationService.getValue().getCellDefinitions())));
loadTableConfigurationService.setOnFailed(event -> displayErrorInfo("Unable to load table configuration", event));
loadTableConfigurationService.restart();
}

private void onConfigureRowValueTypes(ActionEvent event) {
var table = tablesListView.selectedTableProperty().get();
var currentTableConfig = getTableConfiguration(table);
BigtableValueTypesDialog.displayAndAwaitResult(bigtableTableView.getColumns(), currentTableConfig)
.whenComplete((configuration, throwable) -> {
bigtableTableView.setValueConverter(new BigtableValueConverter(configuration.getCellDefinitions()));
saveTableConfiguration(table, configuration);
});
loadTableConfigurationService.setTable(table);
loadTableConfigurationService.setOnSucceeded(e -> BigtableValueTypesDialog
.displayAndAwaitResult(bigtableTableView.getColumns(), loadTableConfigurationService.getValue())
.whenComplete((configuration, throwable) -> updateTableConfiguration(table, configuration))
);
loadTableConfigurationService.setOnFailed(e -> BigtableValueTypesDialog
.displayAndAwaitResult(bigtableTableView.getColumns(), null)
.whenComplete((configuration, throwable) -> updateTableConfiguration(table, configuration))
);
loadTableConfigurationService.restart();
}

private BigtableTableConfiguration getTableConfiguration(BigtableTable table) {
BigtableTableConfiguration currentTableConfig = null;
try {
currentTableConfig = tableConfigManager.getTableConfiguration(table);
} catch (IOException e) {
e.printStackTrace();
displayErrorInfo(String.format("Unable load table configuration for table %s", table.getName()));
}
return currentTableConfig;
private void updateTableConfiguration(BigtableTable table, BigtableTableConfiguration configuration) {
bigtableTableView.setValueConverter(new BigtableValueConverter(configuration.getCellDefinitions()));
saveTableConfiguration(table, configuration);
}

private void saveTableConfiguration(BigtableTable table, BigtableTableConfiguration configuration) {
try {
tableConfigManager.saveTableConfiguration(table, configuration);
} catch (IOException e) {
e.printStackTrace();
displayErrorInfo("Unable to save table configuration");
}
saveTableConfigurationService.setTableConfiguration(table, configuration);
saveTableConfigurationService.setOnFailed(event -> displayErrorInfo("Failed to save table configuration", event));
saveTableConfigurationService.restart();
}

private void displayErrorInfo(String errorText) {
var alert = new Alert(Alert.AlertType.ERROR, errorText, ButtonType.CLOSE);
private void displayErrorInfo(String errorText, WorkerStateEvent event) {
var exception = event.getSource().getException();
var alert = new Alert(Alert.AlertType.ERROR, errorText + " " + exception.getLocalizedMessage(), ButtonType.CLOSE);
alert.showAndWait();
}

Expand All @@ -162,22 +160,22 @@ private void onBigtableTableSelected(ObservableValue<? extends BigtableTable> ob

private BigtableReadRequest createReadRequest(BigtableTable newValue) {
return new BigtableReadRequestBuilder()
.setCredentialsPath(credentialsManager.getCredentialsPath())
.setTable(newValue)
.setRowRange(BigtableRowRange.DEFAULT)
.build();
}

private void readBigtableRows(BigtableReadRequest request) {
var readBigtableRows = new ReadBigtableRows(bigtableClient, request);
readBigtableRows.setOnSucceeded(workerStateEvent -> {
readRowsService.setReadRequest(request);
readRowsService.setOnSucceeded(workerStateEvent -> {
bigtableTableView.setVisible(true);
rowSelectionView.getProgressBar().setVisible(false);
loadTableConfiguration(request.getBigtableTable());
readBigtableRows.getValue().forEach(row -> bigtableTableView.add(row));
readRowsService.getValue().forEach(row -> bigtableTableView.add(row));
});
readRowsService.setOnFailed(stateEvent -> displayErrorInfo("Unable to read bigtable rows", stateEvent));
rowSelectionView.getProgressBar().setVisible(true);
rowSelectionView.getProgressBar().progressProperty().bind(readBigtableRows.progressProperty());
readBigtableRows.start();
rowSelectionView.getProgressBar().progressProperty().bind(readRowsService.progressProperty());
readRowsService.restart();
}
}
Loading

0 comments on commit 618a7ca

Please sign in to comment.