Skip to content

Commit

Permalink
[AMORO-3235] Support action filter by ams backend (#3236)
Browse files Browse the repository at this point in the history
* Support action filter by ams backend

* Support action filter by ams backend(merged)

* Apply spotless

* Fix bug

* spotless apply

---------

Co-authored-by: majin.nathan <majin.nathan@bytedance.com>
Co-authored-by: ZhouJinsong <zhoujinsong0505@163.com>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent 9933215 commit ba47df7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ private EndpointGroup apiGroup() {
path(
"/optimize",
() -> {
get("/actions", optimizerGroupController::getActions);
get(
"/optimizerGroups/{optimizerGroup}/tables",
optimizerGroupController::getOptimizerTables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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.persistence.TableRuntimeMeta;
import org.apache.amoro.server.resource.ContainerMetadata;
import org.apache.amoro.server.resource.OptimizerInstance;
Expand All @@ -40,10 +41,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,13 +62,22 @@ public OptimizerGroupController(
this.optimizerManager = optimizerManager;
}

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");
Integer page = ctx.queryParamAsClass("page", Integer.class).getOrDefault(1);
Integer pageSize = ctx.queryParamAsClass("pageSize", Integer.class).getOrDefault(20);
Set<String> actionFilter = new HashSet<>(ctx.queryParams("actions[]"));
int offset = (page - 1) * pageSize;

String optimizerGroupUsedInDbFilter = ALL_GROUP.equals(optimizerGroup) ? null : optimizerGroup;
Expand All @@ -76,6 +89,10 @@ public void getOptimizerTables(Context ctx) {
List<TableRuntime> tableRuntimes =
tableRuntimeBeans.stream()
.map(meta -> tableService.getRuntime(meta.getTableId()))
.filter(
tableRuntime ->
actionFilter.isEmpty()
|| actionFilter.contains(tableRuntime.getOptimizingStatus().displayValue()))
.collect(Collectors.toList());

PageResult<TableOptimizingInfo> amsPageResult =
Expand Down

0 comments on commit ba47df7

Please sign in to comment.