Skip to content

Commit

Permalink
Support action filter by ams backend
Browse files Browse the repository at this point in the history
  • Loading branch information
majin.nathan committed Oct 8, 2024
1 parent 292111f commit 0822b13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private EndpointGroup apiGroup() {
path(
"/optimize",
() -> {
get("/actions", optimizerController::getActions);
get(
"/optimizerGroups/{optimizerGroup}/tables",
optimizerController::getOptimizerTables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.amoro.server.dashboard.response.OkResponse;
import org.apache.amoro.server.dashboard.response.PageResult;
import org.apache.amoro.server.dashboard.utils.OptimizingUtil;
import org.apache.amoro.server.optimizing.OptimizingStatus;
import org.apache.amoro.server.resource.ContainerMetadata;
import org.apache.amoro.server.resource.OptimizerInstance;
import org.apache.amoro.server.resource.ResourceContainers;
Expand All @@ -41,10 +42,13 @@
import javax.ws.rs.BadRequestException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/** The controller that handles optimizer requests. */
Expand All @@ -58,14 +62,26 @@ public OptimizerController(TableService tableService, DefaultOptimizingService o
this.optimizerManager = optimizerManager;
}

// TODO: use the real action interface to return.
public void getActions(Context ctx) {
ctx.json(
OkResponse.of(
Arrays.stream(OptimizingStatus.values())
.map(OptimizingStatus::displayValue)
.collect(Collectors.toList())));
}

/** Get optimize tables. * @return List of {@link TableOptimizingInfo} */
public void getOptimizerTables(Context ctx) {
String optimizerGroup = ctx.pathParam("optimizerGroup");
String dbFilterStr = ctx.queryParam("dbSearchInput");
String tableFilterStr = ctx.queryParam("tableSearchInput");
String[] requestedActions = ctx.queryParamAsClass("actions", String[].class).getOrDefault(null);
Integer page = ctx.queryParamAsClass("page", Integer.class).getOrDefault(1);
Integer pageSize = ctx.queryParamAsClass("pageSize", Integer.class).getOrDefault(20);
int offset = (page - 1) * pageSize;
Set<String> actionFilter =
requestedActions == null ? null : new HashSet<>(Arrays.asList(requestedActions));

List<TableRuntime> tableRuntimes = new ArrayList<>();
List<ServerTableIdentifier> tables = tableService.listManagedTables();
Expand All @@ -79,7 +95,10 @@ public void getOptimizerTables(Context ctx) {
&& (StringUtils.isEmpty(dbFilterStr)
|| StringUtils.containsIgnoreCase(identifier.getDatabase(), dbFilterStr))
&& (StringUtils.isEmpty(tableFilterStr)
|| StringUtils.containsIgnoreCase(identifier.getTableName(), tableFilterStr))) {
|| StringUtils.containsIgnoreCase(identifier.getTableName(), tableFilterStr))
&& (actionFilter == null
|| actionFilter.isEmpty()
|| actionFilter.contains(tableRuntime.getOptimizingStatus().displayValue()))) {
tableRuntimes.add(tableRuntime);
}
}
Expand Down

0 comments on commit 0822b13

Please sign in to comment.