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

[GUI] Revise UpdatePartition #889

Merged
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
24 changes: 20 additions & 4 deletions common/src/main/java/org/astraea/common/admin/AsyncAdminImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ public CompletionStage<Set<String>> topicNames(boolean listInternal) {
}

@Override
public CompletionStage<List<Topic>> topics(Set<String> names) {
public CompletionStage<List<Topic>> topics(Set<String> topics) {
if (topics.isEmpty()) return CompletableFuture.completedFuture(List.of());
return to(kafkaAdmin
.describeConfigs(
names.stream()
topics.stream()
.map(topic -> new ConfigResource(ConfigResource.Type.TOPIC, topic))
.collect(Collectors.toList()))
.all())
.thenCombine(
to(kafkaAdmin.describeTopics(names).all()),
to(kafkaAdmin.describeTopics(topics).all()),
(configs, desc) ->
configs.entrySet().stream()
.map(
Expand All @@ -114,12 +115,14 @@ public CompletionStage<List<Topic>> topics(Set<String> names) {

@Override
public CompletionStage<Void> deleteTopics(Set<String> topics) {
if (topics.isEmpty()) return CompletableFuture.completedFuture(null);
return to(kafkaAdmin.deleteTopics(topics).all());
}

@Override
public CompletionStage<Map<TopicPartition, Long>> deleteRecords(
Map<TopicPartition, Long> offsets) {
if (offsets.isEmpty()) return CompletableFuture.completedFuture(Map.of());
return Utils.sequence(
kafkaAdmin
.deleteRecords(
Expand All @@ -146,6 +149,7 @@ public CompletionStage<Map<TopicPartition, Long>> deleteRecords(

@Override
public CompletionStage<Set<TopicPartition>> topicPartitions(Set<String> topics) {
if (topics.isEmpty()) return CompletableFuture.completedFuture(Set.of());
return to(kafkaAdmin.describeTopics(topics).all())
.thenApply(
r ->
Expand All @@ -159,6 +163,7 @@ public CompletionStage<Set<TopicPartition>> topicPartitions(Set<String> topics)

@Override
public CompletionStage<Set<TopicPartitionReplica>> topicPartitionReplicas(Set<Integer> brokers) {
if (brokers.isEmpty()) return CompletableFuture.completedFuture(Set.of());
return topicNames(true)
.thenCompose(topics -> to(kafkaAdmin.describeTopics(topics).all()))
.thenApply(
Expand All @@ -182,6 +187,7 @@ public CompletionStage<Set<TopicPartitionReplica>> topicPartitionReplicas(Set<In

@Override
public CompletionStage<List<Partition>> partitions(Set<String> topics) {
if (topics.isEmpty()) return CompletableFuture.completedFuture(List.of());
var allPartitions =
to(kafkaAdmin.describeTopics(topics).all())
.thenApply(
Expand Down Expand Up @@ -351,6 +357,7 @@ public CompletionStage<Set<String>> consumerGroupIds() {

@Override
public CompletionStage<List<ConsumerGroup>> consumerGroups(Set<String> consumerGroupIds) {
if (consumerGroupIds.isEmpty()) return CompletableFuture.completedFuture(List.of());
return to(kafkaAdmin.describeConsumerGroups(consumerGroupIds).all())
.thenCombine(
Utils.sequence(
Expand Down Expand Up @@ -398,6 +405,7 @@ public CompletionStage<List<ConsumerGroup>> consumerGroups(Set<String> consumerG

@Override
public CompletionStage<List<ProducerState>> producerStates(Set<TopicPartition> partitions) {
if (partitions.isEmpty()) return CompletableFuture.completedFuture(List.of());
return to(kafkaAdmin
.describeProducers(
partitions.stream()
Expand All @@ -416,7 +424,7 @@ public CompletionStage<List<ProducerState>> producerStates(Set<TopicPartition> p

@Override
public CompletionStage<List<AddingReplica>> addingReplicas(Set<String> topics) {

if (topics.isEmpty()) return CompletableFuture.completedFuture(List.of());
return topicPartitions(topics)
.thenApply(ps -> ps.stream().map(TopicPartition::to).collect(Collectors.toSet()))
.thenCompose(ps -> to(kafkaAdmin.listPartitionReassignments(ps).reassignments()))
Expand Down Expand Up @@ -483,6 +491,7 @@ public CompletionStage<Set<String>> transactionIds() {

@Override
public CompletionStage<List<Transaction>> transactions(Set<String> transactionIds) {
if (transactionIds.isEmpty()) return CompletableFuture.completedFuture(List.of());
return to(kafkaAdmin.describeTransactions(transactionIds).all())
.thenApply(
ts ->
Expand All @@ -493,6 +502,7 @@ public CompletionStage<List<Transaction>> transactions(Set<String> transactionId

@Override
public CompletionStage<List<Replica>> replicas(Set<String> topics) {
if (topics.isEmpty()) return CompletableFuture.completedFuture(List.of());
// pre-group folders by (broker -> topic partition) to speedup seek
return logDirs()
.thenCombine(
Expand Down Expand Up @@ -673,6 +683,7 @@ public CompletionStage<Boolean> run() {

@Override
public CompletionStage<Void> moveToBrokers(Map<TopicPartition, List<Integer>> assignments) {
if (assignments.isEmpty()) return CompletableFuture.completedFuture(null);
return to(
kafkaAdmin
.alterPartitionReassignments(
Expand All @@ -686,6 +697,7 @@ public CompletionStage<Void> moveToBrokers(Map<TopicPartition, List<Integer>> as

@Override
public CompletionStage<Void> moveToFolders(Map<TopicPartitionReplica, String> assignments) {
if (assignments.isEmpty()) return CompletableFuture.completedFuture(null);
return to(
kafkaAdmin
.alterReplicaLogDirs(
Expand Down Expand Up @@ -726,6 +738,7 @@ public CompletionStage<Void> addPartitions(String topic, int total) {

@Override
public CompletionStage<Void> setConfigs(String topic, Map<String, String> override) {
if (override.isEmpty()) return CompletableFuture.completedFuture(null);
return to(
kafkaAdmin
.incrementalAlterConfigs(
Expand All @@ -743,6 +756,7 @@ public CompletionStage<Void> setConfigs(String topic, Map<String, String> overri

@Override
public CompletionStage<Void> unsetConfigs(String topic, Set<String> keys) {
if (keys.isEmpty()) return CompletableFuture.completedFuture(null);
return to(
kafkaAdmin
.incrementalAlterConfigs(
Expand All @@ -759,6 +773,7 @@ public CompletionStage<Void> unsetConfigs(String topic, Set<String> keys) {

@Override
public CompletionStage<Void> setConfigs(int brokerId, Map<String, String> override) {
if (override.isEmpty()) return CompletableFuture.completedFuture(null);
return to(
kafkaAdmin
.incrementalAlterConfigs(
Expand All @@ -776,6 +791,7 @@ public CompletionStage<Void> setConfigs(int brokerId, Map<String, String> overri

@Override
public CompletionStage<Void> unsetConfigs(int brokerId, Set<String> keys) {
if (keys.isEmpty()) return CompletableFuture.completedFuture(null);
return to(
kafkaAdmin
.incrementalAlterConfigs(
Expand Down
8 changes: 3 additions & 5 deletions gui/src/main/java/org/astraea/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
import org.astraea.gui.tab.ConsumerTab;
import org.astraea.gui.tab.CreateTopicTab;
import org.astraea.gui.tab.MetricsTab;
import org.astraea.gui.tab.MoveTopicTab;
import org.astraea.gui.tab.MovingReplicaTab;
import org.astraea.gui.tab.PartitionTab;
import org.astraea.gui.tab.ProducerTab;
import org.astraea.gui.tab.SettingTab;
import org.astraea.gui.tab.TopicTab;
import org.astraea.gui.tab.TransactionTab;
import org.astraea.gui.tab.TruncateRecordTab;
import org.astraea.gui.tab.UpdateBrokerTab;
import org.astraea.gui.tab.UpdatePartitionTab;
import org.astraea.gui.tab.UpdateTopicTab;

/**
Expand Down Expand Up @@ -74,11 +73,10 @@ public void start(Stage stage) {
TransactionTab.of(context),
MovingReplicaTab.of(context),
CreateTopicTab.of(context),
UpdateTopicTab.of(context),
UpdateBrokerTab.of(context),
MoveTopicTab.of(context),
UpdateTopicTab.of(context),
UpdatePartitionTab.of(context),
BalancerTab.of(context),
TruncateRecordTab.of(context),
AboutTab.of(context))),
300,
300));
Expand Down
66 changes: 43 additions & 23 deletions gui/src/main/java/org/astraea/gui/pane/PaneBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;
import java.util.function.Supplier;
Expand Down Expand Up @@ -55,9 +55,10 @@ public static PaneBuilder of() {

private List<RadioButton> radioButtons = new ArrayList<>();

private Supplier<CompletionStage<Map<String, String>>> inputInitializer =
() -> CompletableFuture.completedFuture(Map.of());
private final Set<String> inputKeys = new LinkedHashSet<>();

private final Map<String, String> inputKeyDefaultValue = new HashMap<>();

private final Map<String, Boolean> inputKeyPriority = new LinkedHashMap<>();
private final Map<String, Boolean> inputKeyNumberOnly = new LinkedHashMap<>();
private Label searchLabel = null;
Expand Down Expand Up @@ -93,15 +94,23 @@ public <T extends RadioButtonAble> PaneBuilder radioButtons(List<T> objs) {
* @return this builder
*/
public PaneBuilder input(String key, boolean required, boolean numberOnly) {
return input(key, required, numberOnly, null);
}

/**
* add key to this builder
*
* @param key to add
* @param required true if key is required. The font will get highlight
* @param numberOnly true if the value associated to key must be number
* @param defaultValue to show by default
* @return this builder
*/
public PaneBuilder input(String key, boolean required, boolean numberOnly, String defaultValue) {
inputKeys.add(key);
inputKeyPriority.put(key, required);
inputKeyNumberOnly.put(key, numberOnly);
return this;
}

public PaneBuilder inputInitializer(
Supplier<CompletionStage<Map<String, String>>> inputInitializer) {
this.inputInitializer = inputInitializer;
if (defaultValue != null) inputKeyDefaultValue.put(key, defaultValue);
return this;
}

Expand All @@ -116,6 +125,17 @@ public PaneBuilder input(Set<String> keys) {
return this;
}

/**
* set the keys and their default values
*
* @param keysAndValues keys and default values
* @return this
*/
public PaneBuilder input(Map<String, String> keysAndValues) {
keysAndValues.forEach((k, v) -> input(k, false, false, v));
return this;
}

public PaneBuilder searchField(String hint) {
searchLabel = Label.of(hint);
return this;
Expand All @@ -129,7 +149,7 @@ public PaneBuilder buttonName(String name) {
public PaneBuilder buttonAction(
BiFunction<Input, Logger, CompletionStage<List<Map<String, Object>>>> buttonAction) {
this.buttonAction = buttonAction;
tableView = TableView.copyable();
if (tableView == null) tableView = TableView.copyable();
return this;
}

Expand All @@ -139,6 +159,12 @@ public PaneBuilder buttonListener(
return this;
}

public PaneBuilder tableView(List<Map<String, Object>> data) {
if (tableView == null) tableView = TableView.copyable();
tableView.update(data);
return this;
}

public Pane build() {
var nodes = new ArrayList<Node>();
if (!radioButtons.isEmpty()) nodes.add(HBox.of(Pos.CENTER, radioButtons.toArray(Node[]::new)));
Expand All @@ -156,19 +182,13 @@ public Pane build() {
inputKeyNumberOnly.getOrDefault(key, false)
? TextField.onlyNumber()
: TextField.of()));
inputInitializer
.get()
.whenComplete(
(r, e) -> {
if (r != null)
r.forEach(
(key, value) ->
pairs.entrySet().stream()
.filter(pair -> pair.getKey().key().equals(key))
.map(Map.Entry::getValue)
.findFirst()
.ifPresent(field -> field.text(value)));
});
inputKeyDefaultValue.forEach(
(key, value) ->
pairs.entrySet().stream()
.filter(pair -> pair.getKey().key().equals(key))
.map(Map.Entry::getValue)
.findFirst()
.ifPresent(field -> field.text(value)));
var gridPane = pairs.size() <= 3 ? GridPane.singleColumn(pairs, 3) : GridPane.of(pairs, 3);
nodes.add(gridPane);
textFields =
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/java/org/astraea/gui/pane/Tab.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Tab extends javafx.scene.control.Tab {
* @param nodeSupplier offers the newest content
* @return tab
*/
public static Tab dynamical(String name, Supplier<CompletionStage<Node>> nodeSupplier) {
public static Tab dynamic(String name, Supplier<CompletionStage<Node>> nodeSupplier) {
var t = new Tab(name);
t.setOnSelectionChanged(
ignored -> {
Expand Down
Loading