Skip to content

Commit

Permalink
refactor: use enhanced switch
Browse files Browse the repository at this point in the history
  • Loading branch information
yeikel committed Dec 10, 2024
1 parent 45324dd commit 9d518e9
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions api/src/main/java/io/kafbat/ui/service/KafkaConnectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,13 @@ public Mono<Void> deleteConnector(
public Mono<Void> updateConnectorState(KafkaCluster cluster, String connectName,
String connectorName, ConnectorActionDTO action) {
return api(cluster, connectName)
.mono(client -> {
switch (action) {
case RESTART:
return client.restartConnector(connectorName, false, false);
case RESTART_ALL_TASKS:
return restartTasks(cluster, connectName, connectorName, task -> true);
case RESTART_FAILED_TASKS:
return restartTasks(cluster, connectName, connectorName,
t -> t.getStatus().getState() == ConnectorTaskStatusDTO.FAILED);
case PAUSE:
return client.pauseConnector(connectorName);
case RESUME:
return client.resumeConnector(connectorName);
default:
throw new IllegalStateException("Unexpected value: " + action);
}
.mono(client -> switch (action) {
case RESTART -> client.restartConnector(connectorName, false, false);
case RESTART_ALL_TASKS -> restartTasks(cluster, connectName, connectorName, task -> true);
case RESTART_FAILED_TASKS -> restartTasks(cluster, connectName, connectorName,
t -> t.getStatus().getState() == ConnectorTaskStatusDTO.FAILED);
case PAUSE -> client.pauseConnector(connectorName);
case RESUME -> client.resumeConnector(connectorName);
});
}

Expand Down

0 comments on commit 9d518e9

Please sign in to comment.