diff --git a/amoro-ams/pom.xml b/amoro-ams/pom.xml
index 1a78ca0f26..1db3a8f81a 100644
--- a/amoro-ams/pom.xml
+++ b/amoro-ams/pom.xml
@@ -280,10 +280,10 @@
url-connection-client
-
- software.amazon.awssdk
- s3-transfer-manager
-
+
+ software.amazon.awssdk
+ s3-transfer-manager
+
org.apache.hadoop
diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java
index 1dd763f324..467f45aac6 100644
--- a/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/AmoroServiceContainer.java
@@ -27,6 +27,7 @@
import org.apache.amoro.config.ConfigHelpers;
import org.apache.amoro.config.Configurations;
import org.apache.amoro.server.dashboard.DashboardServer;
+import org.apache.amoro.server.dashboard.JavalinJsonMapper;
import org.apache.amoro.server.dashboard.response.ErrorResponse;
import org.apache.amoro.server.dashboard.utils.AmsUtil;
import org.apache.amoro.server.dashboard.utils.CommonUtil;
@@ -66,7 +67,6 @@
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
-import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -215,7 +215,7 @@ public void dispose() {
MetricManager.dispose();
}
- private void initConfig() throws IOException {
+ private void initConfig() throws Exception {
LOG.info("initializing configurations...");
new ConfigurationHelper().init();
}
@@ -243,6 +243,7 @@ private void initHttpService() {
config.addStaticFiles(dashboardServer.configStaticFiles());
config.sessionHandler(SessionHandler::new);
config.enableCorsForAllOrigins();
+ config.jsonMapper(JavalinJsonMapper.createDefaultJsonMapper());
config.showJavalinBanner = false;
});
httpServer.routes(
@@ -407,14 +408,14 @@ private class ConfigurationHelper {
private JsonNode yamlConfig;
- public void init() throws IOException {
+ public void init() throws Exception {
Map envConfig = initEnvConfig();
initServiceConfig(envConfig);
setIcebergSystemProperties();
initContainerConfig();
}
- private void initServiceConfig(Map envConfig) throws IOException {
+ private void initServiceConfig(Map envConfig) throws Exception {
LOG.info("initializing service configuration...");
String configPath = Environments.getConfigPath() + "/" + SERVER_CONFIG_FILENAME;
LOG.info("load config from path: {}", configPath);
@@ -438,6 +439,8 @@ private void initServiceConfig(Map envConfig) throws IOException
private Map initEnvConfig() {
LOG.info("initializing system env configuration...");
+ Map envs = System.getenv();
+ envs.forEach((k, v) -> LOG.info("export {}={}", k, v));
String prefix = AmoroManagementConf.SYSTEM_CONFIG.toUpperCase();
return ConfigHelpers.convertConfigurationKeys(prefix, System.getenv());
}
diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/DefaultOptimizingService.java b/amoro-ams/src/main/java/org/apache/amoro/server/DefaultOptimizingService.java
index d77b7f9170..6e8924b185 100644
--- a/amoro-ams/src/main/java/org/apache/amoro/server/DefaultOptimizingService.java
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/DefaultOptimizingService.java
@@ -33,6 +33,7 @@
import org.apache.amoro.resource.Resource;
import org.apache.amoro.resource.ResourceGroup;
import org.apache.amoro.server.exception.ForbiddenException;
+import org.apache.amoro.server.exception.IllegalTaskStateException;
import org.apache.amoro.server.exception.ObjectNotExistsException;
import org.apache.amoro.server.exception.PluginRetryAuthException;
import org.apache.amoro.server.exception.TaskNotFoundException;
@@ -49,7 +50,6 @@
import org.apache.amoro.server.table.DefaultTableService;
import org.apache.amoro.server.table.RuntimeHandlerChain;
import org.apache.amoro.server.table.TableRuntime;
-import org.apache.amoro.server.table.TableRuntimeMeta;
import org.apache.amoro.server.table.TableService;
import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
import org.apache.amoro.shade.guava32.com.google.common.collect.ImmutableList;
@@ -121,24 +121,24 @@ public RuntimeHandlerChain getTableRuntimeHandler() {
return tableHandlerChain;
}
- private void loadOptimizingQueues(List tableRuntimeMetaList) {
+ private void loadOptimizingQueues(List tableRuntimeMetaList) {
List optimizerGroups =
getAs(ResourceMapper.class, ResourceMapper::selectResourceGroups);
List optimizers = getAs(OptimizerMapper.class, OptimizerMapper::selectAll);
- Map> groupToTableRuntimes =
+ Map> groupToTableRuntimes =
tableRuntimeMetaList.stream()
- .collect(Collectors.groupingBy(TableRuntimeMeta::getOptimizerGroup));
+ .collect(Collectors.groupingBy(TableRuntime::getOptimizerGroup));
optimizerGroups.forEach(
group -> {
String groupName = group.getName();
- List tableRuntimeMetas = groupToTableRuntimes.remove(groupName);
+ List tableRuntimes = groupToTableRuntimes.remove(groupName);
OptimizingQueue optimizingQueue =
new OptimizingQueue(
tableService,
group,
this,
planExecutor,
- Optional.ofNullable(tableRuntimeMetas).orElseGet(ArrayList::new),
+ Optional.ofNullable(tableRuntimes).orElseGet(ArrayList::new),
maxPlanningParallelism);
optimizingQueueByGroup.put(groupName, optimizingQueue);
});
@@ -148,8 +148,8 @@ private void loadOptimizingQueues(List tableRuntimeMetaList) {
.forEach(groupName -> LOG.warn("Unloaded task runtime in group {}", groupName));
}
- private void registerOptimizer(OptimizerInstance optimizer, boolean needPersistency) {
- if (needPersistency) {
+ private void registerOptimizer(OptimizerInstance optimizer, boolean needPersistent) {
+ if (needPersistent) {
doAs(OptimizerMapper.class, mapper -> mapper.insertOptimizer(optimizer));
}
@@ -456,9 +456,9 @@ public void handleTableRemoved(TableRuntime tableRuntime) {
}
@Override
- protected void initHandler(List tableRuntimeMetaList) {
+ protected void initHandler(List tableRuntimeList) {
LOG.info("OptimizerManagementService begin initializing");
- loadOptimizingQueues(tableRuntimeMetaList);
+ loadOptimizingQueues(tableRuntimeList);
optimizerKeeper.start();
LOG.info("SuspendingDetector for Optimizer has been started.");
LOG.info("OptimizerManagementService initializing has completed");
@@ -566,7 +566,14 @@ private void retryTask(TaskRuntime task, OptimizingQueue queue) {
task.getTaskId(),
task.getResourceDesc());
// optimizing task of suspending optimizer would not be counted for retrying
- queue.retryTask(task);
+ try {
+ queue.retryTask(task);
+ } catch (IllegalTaskStateException e) {
+ LOG.error(
+ "Retry task {} failed due to {}, will check it in next round",
+ task.getTaskId(),
+ e.getMessage());
+ }
}
private Predicate buildSuspendingPredication(Set activeTokens) {
diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java
index 2e865974fb..bb773fca6d 100644
--- a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java
@@ -39,6 +39,7 @@
import org.apache.amoro.server.dashboard.controller.HealthCheckController;
import org.apache.amoro.server.dashboard.controller.LoginController;
import org.apache.amoro.server.dashboard.controller.OptimizerController;
+import org.apache.amoro.server.dashboard.controller.OptimizerGroupController;
import org.apache.amoro.server.dashboard.controller.OverviewController;
import org.apache.amoro.server.dashboard.controller.PlatformFileInfoController;
import org.apache.amoro.server.dashboard.controller.SettingController;
@@ -77,6 +78,7 @@ public class DashboardServer {
private final CatalogController catalogController;
private final HealthCheckController healthCheckController;
private final LoginController loginController;
+ private final OptimizerGroupController optimizerGroupController;
private final OptimizerController optimizerController;
private final PlatformFileInfoController platformFileInfoController;
private final SettingController settingController;
@@ -98,7 +100,8 @@ public DashboardServer(
this.catalogController = new CatalogController(tableService, platformFileManager);
this.healthCheckController = new HealthCheckController();
this.loginController = new LoginController(serviceConfig);
- this.optimizerController = new OptimizerController(tableService, optimizerManager);
+ this.optimizerGroupController = new OptimizerGroupController(tableService, optimizerManager);
+ this.optimizerController = new OptimizerController(optimizerManager);
this.platformFileInfoController = new PlatformFileInfoController(platformFileManager);
this.settingController = new SettingController(serviceConfig, optimizerManager);
ServerTableDescriptor tableDescriptor = new ServerTableDescriptor(tableService, serviceConfig);
@@ -221,6 +224,9 @@ private EndpointGroup apiGroup() {
get(
"/catalogs/{catalog}/dbs/{db}/tables/{table}/optimizing-processes",
tableController::getOptimizingProcesses);
+ get(
+ "/catalogs/{catalog}/dbs/{db}/tables/{table}/optimizing-types",
+ tableController::getOptimizingTypes);
get(
"/catalogs/{catalog}/dbs/{db}/tables/{table}/optimizing-processes/{processId}/tasks",
tableController::getOptimizingProcessTasks);
@@ -274,26 +280,29 @@ private EndpointGroup apiGroup() {
() -> {
get(
"/optimizerGroups/{optimizerGroup}/tables",
- optimizerController::getOptimizerTables);
- get("/optimizerGroups/{optimizerGroup}/optimizers", optimizerController::getOptimizers);
- get("/optimizerGroups", optimizerController::getOptimizerGroups);
+ optimizerGroupController::getOptimizerTables);
+ get(
+ "/optimizerGroups/{optimizerGroup}/optimizers",
+ optimizerGroupController::getOptimizers);
+ get("/optimizerGroups", optimizerGroupController::getOptimizerGroups);
get(
"/optimizerGroups/{optimizerGroup}/info",
- optimizerController::getOptimizerGroupInfo);
- delete(
- "/optimizerGroups/{optimizerGroup}/optimizers/{jobId}",
- optimizerController::releaseOptimizer);
+ optimizerGroupController::getOptimizerGroupInfo);
post(
"/optimizerGroups/{optimizerGroup}/optimizers",
- optimizerController::scaleOutOptimizer);
- get("/resourceGroups", optimizerController::getResourceGroup);
- post("/resourceGroups", optimizerController::createResourceGroup);
- put("/resourceGroups", optimizerController::updateResourceGroup);
- delete("/resourceGroups/{resourceGroupName}", optimizerController::deleteResourceGroup);
+ optimizerGroupController::scaleOutOptimizer);
+ post("/optimizers", optimizerController::createOptimizer);
+ delete("/optimizers/{jobId}", optimizerController::releaseOptimizer);
+ get("/resourceGroups", optimizerGroupController::getResourceGroup);
+ post("/resourceGroups", optimizerGroupController::createResourceGroup);
+ put("/resourceGroups", optimizerGroupController::updateResourceGroup);
+ delete(
+ "/resourceGroups/{resourceGroupName}",
+ optimizerGroupController::deleteResourceGroup);
get(
"/resourceGroups/{resourceGroupName}/delete/check",
- optimizerController::deleteCheckResourceGroup);
- get("/containers/get", optimizerController::getContainers);
+ optimizerGroupController::deleteCheckResourceGroup);
+ get("/containers/get", optimizerGroupController::getContainers);
});
// console apis
diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/JavalinJsonMapper.java b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/JavalinJsonMapper.java
new file mode 100644
index 0000000000..43bda20b7f
--- /dev/null
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/JavalinJsonMapper.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.amoro.server.dashboard;
+
+import io.javalin.plugin.json.JsonMapper;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.module.SimpleModule;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/** Json mapper to adapt shaded jackson. */
+public class JavalinJsonMapper implements JsonMapper {
+
+ private final ObjectMapper objectMapper;
+
+ public static JavalinJsonMapper createDefaultJsonMapper() {
+ ObjectMapper om = new ObjectMapper();
+ SimpleModule module = new SimpleModule();
+ module.addSerializer(TableFormat.class, new TableFormat.JsonSerializer());
+ module.addDeserializer(TableFormat.class, new TableFormat.JsonDeserializer());
+ om.registerModule(module);
+ return new JavalinJsonMapper(om);
+ }
+
+ public JavalinJsonMapper(ObjectMapper shadedMapper) {
+ this.objectMapper = shadedMapper;
+ }
+
+ @NotNull
+ @Override
+ public String toJsonString(@NotNull Object obj) {
+ if (obj instanceof String) {
+ return (String) obj;
+ }
+ try {
+ return objectMapper.writeValueAsString(obj);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @NotNull
+ @Override
+ public InputStream toJsonStream(@NotNull Object obj) {
+ if (obj instanceof String) {
+ String result = (String) obj;
+ return new ByteArrayInputStream(result.getBytes());
+ } else {
+ byte[] string = new byte[0];
+ try {
+ string = objectMapper.writeValueAsBytes(obj);
+ return new ByteArrayInputStream(string);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ @NotNull
+ @Override
+ public T fromJsonString(@NotNull String json, @NotNull Class targetClass) {
+ try {
+ return objectMapper.readValue(json, targetClass);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @NotNull
+ @Override
+ public T fromJsonStream(@NotNull InputStream json, @NotNull Class targetClass) {
+ try {
+ return objectMapper.readValue(json, targetClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/MixedAndIcebergTableDescriptor.java b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/MixedAndIcebergTableDescriptor.java
index 3db518a241..1bacd81a13 100644
--- a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/MixedAndIcebergTableDescriptor.java
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/MixedAndIcebergTableDescriptor.java
@@ -33,6 +33,7 @@
import org.apache.amoro.server.optimizing.MetricsSummary;
import org.apache.amoro.server.optimizing.OptimizingProcessMeta;
import org.apache.amoro.server.optimizing.OptimizingTaskMeta;
+import org.apache.amoro.server.optimizing.OptimizingType;
import org.apache.amoro.server.optimizing.TaskRuntime;
import org.apache.amoro.server.persistence.PersistentBase;
import org.apache.amoro.server.persistence.mapper.OptimizingMapper;
@@ -64,6 +65,7 @@
import org.apache.amoro.utils.MixedDataFiles;
import org.apache.amoro.utils.MixedTableUtil;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.iceberg.ContentFile;
import org.apache.iceberg.HasTableOperations;
@@ -501,7 +503,7 @@ public List getTableConsumerInfos(AmoroTable> amoroTable) {
@Override
public Pair, Integer> getOptimizingProcessesInfo(
- AmoroTable> amoroTable, int limit, int offset) {
+ AmoroTable> amoroTable, String type, ProcessStatus status, int limit, int offset) {
TableIdentifier tableIdentifier = amoroTable.id();
List processMetaList =
getAs(
@@ -511,6 +513,16 @@ public Pair, Integer> getOptimizingProcessesInfo(
tableIdentifier.getCatalog(),
tableIdentifier.getDatabase(),
tableIdentifier.getTableName()));
+
+ processMetaList =
+ processMetaList.stream()
+ .filter(
+ p ->
+ StringUtils.isBlank(type)
+ || type.equalsIgnoreCase(p.getOptimizingType().getStatus().displayValue()))
+ .filter(p -> status == null || status.name().equalsIgnoreCase(p.getStatus().name()))
+ .collect(Collectors.toList());
+
int total = processMetaList.size();
processMetaList =
processMetaList.stream().skip(offset).limit(limit).collect(Collectors.toList());
@@ -532,6 +544,15 @@ public Pair, Integer> getOptimizingProcessesInfo(
total);
}
+ @Override
+ public Map getTableOptimizingTypes(AmoroTable> amoroTable) {
+ Map types = Maps.newHashMap();
+ for (OptimizingType type : OptimizingType.values()) {
+ types.put(type.name(), type.getStatus().displayValue());
+ }
+ return types;
+ }
+
@Override
public List getOptimizingTaskInfos(
AmoroTable> amoroTable, String processId) {
diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/ServerTableDescriptor.java b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/ServerTableDescriptor.java
index 8caa17e685..521d80f62f 100644
--- a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/ServerTableDescriptor.java
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/ServerTableDescriptor.java
@@ -22,6 +22,7 @@
import org.apache.amoro.TableFormat;
import org.apache.amoro.api.TableIdentifier;
import org.apache.amoro.config.Configurations;
+import org.apache.amoro.process.ProcessStatus;
import org.apache.amoro.server.catalog.ServerCatalog;
import org.apache.amoro.server.persistence.PersistentBase;
import org.apache.amoro.server.table.TableService;
@@ -124,10 +125,11 @@ public List getTableConsumersInfos(TableIdentifier tableIdentifier
}
public Pair, Integer> getOptimizingProcessesInfo(
- TableIdentifier tableIdentifier, int limit, int offset) {
+ TableIdentifier tableIdentifier, String type, ProcessStatus status, int limit, int offset) {
AmoroTable> amoroTable = loadTable(tableIdentifier);
FormatTableDescriptor formatTableDescriptor = formatDescriptorMap.get(amoroTable.format());
- return formatTableDescriptor.getOptimizingProcessesInfo(amoroTable, limit, offset);
+ return formatTableDescriptor.getOptimizingProcessesInfo(
+ amoroTable, type, status, limit, offset);
}
public List getOptimizingProcessTaskInfos(
@@ -137,6 +139,12 @@ public List getOptimizingProcessTaskInfos(
return formatTableDescriptor.getOptimizingTaskInfos(amoroTable, processId);
}
+ public Map getTableOptimizingTypes(TableIdentifier tableIdentifier) {
+ AmoroTable> amoroTable = loadTable(tableIdentifier);
+ FormatTableDescriptor formatTableDescriptor = formatDescriptorMap.get(amoroTable.format());
+ return formatTableDescriptor.getTableOptimizingTypes(amoroTable);
+ }
+
private AmoroTable> loadTable(TableIdentifier identifier) {
ServerCatalog catalog = tableService.getServerCatalog(identifier.getCatalog());
return catalog.loadTable(identifier.getDatabase(), identifier.getTableName());
diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerController.java b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerController.java
index aa5abf386d..9e34df3ab3 100644
--- a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerController.java
+++ b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerController.java
@@ -19,159 +19,29 @@
package org.apache.amoro.server.dashboard.controller;
import io.javalin.http.Context;
-import org.apache.amoro.ServerTableIdentifier;
import org.apache.amoro.resource.Resource;
import org.apache.amoro.resource.ResourceGroup;
import org.apache.amoro.resource.ResourceType;
import org.apache.amoro.server.DefaultOptimizingService;
-import org.apache.amoro.server.dashboard.model.OptimizerInstanceInfo;
-import org.apache.amoro.server.dashboard.model.OptimizerResourceInfo;
-import org.apache.amoro.server.dashboard.model.TableOptimizingInfo;
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.resource.ContainerMetadata;
import org.apache.amoro.server.resource.OptimizerInstance;
import org.apache.amoro.server.resource.ResourceContainers;
-import org.apache.amoro.server.table.TableRuntime;
-import org.apache.amoro.server.table.TableService;
import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
-import org.apache.commons.lang3.StringUtils;
-import javax.ws.rs.BadRequestException;
-
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** The controller that handles optimizer requests. */
public class OptimizerController {
- private static final String ALL_GROUP = "all";
- private final TableService tableService;
+
private final DefaultOptimizingService optimizerManager;
- public OptimizerController(TableService tableService, DefaultOptimizingService optimizerManager) {
- this.tableService = tableService;
+ public OptimizerController(DefaultOptimizingService optimizerManager) {
this.optimizerManager = optimizerManager;
}
- /** 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);
- int offset = (page - 1) * pageSize;
-
- List tableRuntimes = new ArrayList<>();
- List tables = tableService.listManagedTables();
- for (ServerTableIdentifier identifier : tables) {
- TableRuntime tableRuntime = tableService.getRuntime(identifier);
- if (tableRuntime == null) {
- continue;
- }
- if ((ALL_GROUP.equals(optimizerGroup)
- || tableRuntime.getOptimizerGroup().equals(optimizerGroup))
- && (StringUtils.isEmpty(dbFilterStr)
- || StringUtils.containsIgnoreCase(identifier.getDatabase(), dbFilterStr))
- && (StringUtils.isEmpty(tableFilterStr)
- || StringUtils.containsIgnoreCase(identifier.getTableName(), tableFilterStr))) {
- tableRuntimes.add(tableRuntime);
- }
- }
- tableRuntimes.sort(
- (o1, o2) -> {
- // first we compare the status , and then we compare the start time when status are equal;
- int statDiff = o1.getOptimizingStatus().compareTo(o2.getOptimizingStatus());
- // status order is asc, startTime order is desc
- if (statDiff == 0) {
- long timeDiff = o1.getCurrentStatusStartTime() - o2.getCurrentStatusStartTime();
- return timeDiff >= 0 ? (timeDiff == 0 ? 0 : -1) : 1;
- } else {
- return statDiff;
- }
- });
- PageResult amsPageResult =
- PageResult.of(tableRuntimes, offset, pageSize, OptimizingUtil::buildTableOptimizeInfo);
- ctx.json(OkResponse.of(amsPageResult));
- }
-
- /** get optimizers. */
- public void getOptimizers(Context ctx) {
- String optimizerGroup = ctx.pathParam("optimizerGroup");
- Integer page = ctx.queryParamAsClass("page", Integer.class).getOrDefault(1);
- Integer pageSize = ctx.queryParamAsClass("pageSize", Integer.class).getOrDefault(20);
-
- int offset = (page - 1) * pageSize;
- List optimizers;
- if (optimizerGroup.equals("all")) {
- optimizers = optimizerManager.listOptimizers();
- } else {
- optimizers = optimizerManager.listOptimizers(optimizerGroup);
- }
- List optimizerList = new ArrayList<>(optimizers);
- optimizerList.sort(Comparator.comparingLong(OptimizerInstance::getStartTime).reversed());
- List result =
- optimizerList.stream()
- .map(
- e ->
- OptimizerInstanceInfo.builder()
- .token(e.getToken())
- .startTime(e.getStartTime())
- .touchTime(e.getTouchTime())
- .jobId(e.getResourceId())
- .groupName(e.getGroupName())
- .coreNumber(e.getThreadCount())
- .memory(e.getMemoryMb())
- .jobStatus("RUNNING")
- .container(e.getContainerName())
- .build())
- .collect(Collectors.toList());
-
- PageResult amsPageResult = PageResult.of(result, offset, pageSize);
- ctx.json(OkResponse.of(amsPageResult));
- }
-
- /** get optimizerGroup: optimizerGroupId, optimizerGroupName url = /optimizerGroups. */
- public void getOptimizerGroups(Context ctx) {
- List