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

Add Frontend to ZDB #407

Merged
merged 5 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<zeebe-test-container.version>3.6.3</zeebe-test-container.version>
<version.slf4j>2.0.13</version.slf4j>
<version.awaitility>4.2.1</version.awaitility>
<version.jackson>2.13.0</version.jackson>
<jackson-databind.version>2.13.0</jackson-databind.version>
Expand Down
136 changes: 136 additions & 0 deletions frontend/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>


<parent>
<groupId>io.zell</groupId>
<artifactId>zdb</artifactId>
<version>2.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>frontend</artifactId>
<name>frontend</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.0</junit.version>
</properties>

<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>21</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zell</groupId>
<artifactId>backend</artifactId>
<version>2.4.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${version.slf4j}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>

<!-- Google code format plugin -->
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>${plugin.version.fmt}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>io.zell.zdb.frontend.ZdbFrontendMain</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>io.zell.zdb.frontend.ZdbFrontendMain</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
163 changes: 163 additions & 0 deletions frontend/src/main/java/io/zell/zdb/frontend/LogViewController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright © 2021 Christopher Kujawa ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.zell.zdb.frontend;

import io.zell.zdb.log.LogContentReader;
import io.zell.zdb.log.records.ApplicationRecord;
import io.zell.zdb.log.records.PersistedRecord;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.function.Consumer;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.*;
import javafx.stage.DirectoryChooser;

public class LogViewController implements Initializable {

@FXML private TableView<ZeebeRecord> zeebeData;

@FXML private Button findDataPath;

@FXML private TextField dataPath;

@FXML private TextField instanceKey;
@FXML private TextField fromPosition;
@FXML private TextField toPosition;
private final DirectoryChooser directoryChooser = new DirectoryChooser();
private ObservableList<ZeebeRecord> dataObservableList;

@Override
public void initialize(final URL url, final ResourceBundle resourceBundle) {
// time to initialize fields
final var userHome = System.getProperty("user.home");
this.dataPath.setText(userHome);

this.dataObservableList = FXCollections.observableList(new ArrayList<>());
// put into the data table view
this.zeebeData.setItems(this.dataObservableList);

// define columns
this.zeebeData
.getColumns()
.setAll(
LogViewController.<Long>createTableColumn("Position", "position"),
LogViewController.<Long>createTableColumn(
"Source\nRecord\nPosition", "sourceRecordPosition"),
LogViewController.<Long>createTableColumn("Timestamp", "timestamp"),
LogViewController.<Long>createTableColumn("Key", "key"),
LogViewController.<String>createTableColumn("Record\ntype", "recordType"),
LogViewController.<String>createTableColumn("Value\ntype", "valueType"),
LogViewController.<String>createTableColumn("Intent", "intent"),
LogViewController.<String>createTableColumn("Rejection\ntype", "rejectionType"),
LogViewController.<String>createTableColumn("Rejection\nreason", "rejectionReason"),
LogViewController.<Long>createTableColumn("Request\nID", "requestId"),
LogViewController.<Integer>createTableColumn("Request\nstream\nID", "requestStreamId"),
LogViewController.<Integer>createTableColumn("Protocol\nversion", "protocolVersion"),
LogViewController.<String>createTableColumn("Broker\nversion", "brokerVersion"),
LogViewController.<Integer>createTableColumn("Record\nversion", "recordVersion"),
LogViewController.<String>createTableColumn("Auth\ndata", "authData"),
LogViewController.<String>createTableColumn("Record\nvalue", "recordValue"));

// enable multi-selection
this.zeebeData.getSelectionModel().setCellSelectionEnabled(true);
this.zeebeData.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
this.zeebeData.setOnKeyPressed(new TableViewKeyEventClipboardCopier<>(this.zeebeData));
}

private static <T> TableColumn<ZeebeRecord, T> createTableColumn(
final String displayName, final String propertyName) {
final TableColumn<ZeebeRecord, T> column = new TableColumn<ZeebeRecord, T>(displayName);
column.setCellValueFactory(new PropertyValueFactory<ZeebeRecord, T>(propertyName));
return column;
}

@FXML
protected void onFindFile() {
this.directoryChooser.setTitle("Zeebe data path");
this.directoryChooser.setInitialDirectory(new File(System.getProperty("user.home")));

final File file = this.directoryChooser.showDialog(this.findDataPath.getScene().getWindow());
if (file != null) {
this.dataPath.setText(file.getAbsolutePath());
findLog();
}
}

@FXML
private void findLog() {
if (this.dataPath.getText() == null || this.dataPath.getText().isBlank()) {
return;
}
final var logContentReader = new LogContentReader(new File(this.dataPath.getText()).toPath());

consumeValueFromTextField(this.instanceKey, logContentReader::filterForProcessInstance);
consumeValueFromTextField(this.fromPosition, logContentReader::seekToPosition);
consumeValueFromTextField(this.toPosition, logContentReader::limitToPosition);

fillTableWithData(logContentReader);
}

private void consumeValueFromTextField(final TextField textField, final Consumer<Long> consumer) {
if (textField.getText() != null && !textField.getText().isBlank()) {
try {
final long instanceKeyLong = Long.parseLong(textField.getText());
consumer.accept(instanceKeyLong);
} catch (final NumberFormatException nfe) {
System.out.printf(
"Expected to retrieve a number as instance key, but '%s' wasn't%n",
textField.getText());
}
}
}

private void fillTableWithData(final LogContentReader logContentReader) {
this.dataObservableList.clear();
while (logContentReader.hasNext()) {
final PersistedRecord next = logContentReader.next();

if (next instanceof final ApplicationRecord applicationRecord) {
for (final var r : applicationRecord.getEntries()) {
final var zeebeRecord =
new ZeebeRecord(
r.getPosition(),
r.getSourceRecordPosition(),
r.getTimestamp(),
r.getKey(),
r.getRecordType().name(),
r.getValueType().name(),
r.getIntent().name(),
r.getRejectionType().name(),
r.getRejectionReason(),
r.getRequestId(),
r.getRequestStreamId(),
r.getProtocolVersion(),
r.getBrokerVersion(),
r.getRecordVersion(),
r.getAuthData(),
r.getRecordValue().toString());
this.dataObservableList.add(zeebeRecord);
}
}
}
}
}
Loading
Loading