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..c7ce598bd2 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); @@ -274,26 +277,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/controller/OptimizerController.java b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerController.java index c5770be20b..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 @@ -23,137 +23,25 @@ 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.persistence.TableRuntimeMeta; 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 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; - - String optimizerGroupUsedInDbFilter = ALL_GROUP.equals(optimizerGroup) ? null : optimizerGroup; - // get all info from underlying table table_runtime - List tableRuntimeBeans = - tableService.getTableRuntimes( - optimizerGroupUsedInDbFilter, dbFilterStr, tableFilterStr, pageSize, offset); - - List tableRuntimes = - tableRuntimeBeans.stream() - .map(meta -> tableService.getRuntime(meta.getTableId())) - .collect(Collectors.toList()); - - 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> result = - optimizerManager.listResourceGroups().stream() - .filter( - resourceGroup -> - !ResourceContainers.EXTERNAL_CONTAINER_NAME.equals( - resourceGroup.getContainer())) - .map( - e -> { - Map mapObj = new HashMap<>(); - mapObj.put("optimizerGroupName", e.getName()); - return mapObj; - }) - .collect(Collectors.toList()); - ctx.json(OkResponse.of(result)); - } - - /** get optimizer info: occupationCore, occupationMemory */ - public void getOptimizerGroupInfo(Context ctx) { - String optimizerGroup = ctx.pathParam("optimizerGroup"); - List optimizers; - if (optimizerGroup.equals("all")) { - optimizers = optimizerManager.listOptimizers(); - } else { - optimizers = optimizerManager.listOptimizers(optimizerGroup); - } - OptimizerResourceInfo optimizerResourceInfo = new OptimizerResourceInfo(); - optimizers.forEach( - e -> { - optimizerResourceInfo.addOccupationCore(e.getThreadCount()); - optimizerResourceInfo.addOccupationMemory(e.getMemoryMb()); - }); - ctx.json(OkResponse.of(optimizerResourceInfo)); - } - /** * release optimizer. * @@ -180,12 +68,11 @@ public void releaseOptimizer(Context ctx) { ctx.json(OkResponse.of("Success to release optimizer")); } - /** scale out optimizers, url:/optimizerGroups/{optimizerGroup}/optimizers. */ - public void scaleOutOptimizer(Context ctx) { - String optimizerGroup = ctx.pathParam("optimizerGroup"); - Map map = ctx.bodyAsClass(Map.class); - int parallelism = map.get("parallelism"); - + /** scale out optimizers, url:/optimizers. */ + public void createOptimizer(Context ctx) { + Map map = ctx.bodyAsClass(Map.class); + int parallelism = Integer.parseInt(map.get("parallelism").toString()); + String optimizerGroup = map.get("optimizerGroup").toString(); ResourceGroup resourceGroup = optimizerManager.getResourceGroup(optimizerGroup); Resource resource = new Resource.Builder( @@ -195,75 +82,7 @@ public void scaleOutOptimizer(Context ctx) { .build(); ResourceContainers.get(resource.getContainerName()).requestResource(resource); optimizerManager.createResource(resource); - ctx.json(OkResponse.of("success to scaleOut optimizer")); - } - - /** get {@link List} url = /optimize/resourceGroups */ - public void getResourceGroup(Context ctx) { - List result = - optimizerManager.listResourceGroups().stream() - .map( - group -> { - List optimizers = - optimizerManager.listOptimizers(group.getName()); - OptimizerResourceInfo optimizerResourceInfo = new OptimizerResourceInfo(); - optimizerResourceInfo.setResourceGroup( - optimizerManager.getResourceGroup(group.getName())); - optimizers.forEach( - optimizer -> { - optimizerResourceInfo.addOccupationCore(optimizer.getThreadCount()); - optimizerResourceInfo.addOccupationMemory(optimizer.getMemoryMb()); - }); - return optimizerResourceInfo; - }) - .collect(Collectors.toList()); - ctx.json(OkResponse.of(result)); - } - - /** - * create optimizeGroup: name, container, schedulePolicy, properties url = - * /optimize/resourceGroups/create - */ - public void createResourceGroup(Context ctx) { - Map map = ctx.bodyAsClass(Map.class); - String name = (String) map.get("name"); - String container = (String) map.get("container"); - Map properties = (Map) map.get("properties"); - if (optimizerManager.getResourceGroup(name) != null) { - throw new BadRequestException(String.format("Optimizer group:%s already existed.", name)); - } - ResourceGroup.Builder builder = new ResourceGroup.Builder(name, container); - builder.addProperties(properties); - optimizerManager.createResourceGroup(builder.build()); - ctx.json(OkResponse.of("The optimizer group has been successfully created.")); - } - - /** - * update optimizeGroup: name, container, schedulePolicy, properties url = - * /optimize/resourceGroups/update - */ - public void updateResourceGroup(Context ctx) { - Map map = ctx.bodyAsClass(Map.class); - String name = (String) map.get("name"); - String container = (String) map.get("container"); - Map properties = (Map) map.get("properties"); - ResourceGroup.Builder builder = new ResourceGroup.Builder(name, container); - builder.addProperties(properties); - optimizerManager.updateResourceGroup(builder.build()); - ctx.json(OkResponse.of("The optimizer group has been successfully updated.")); - } - - /** delete optimizeGroup url = /optimize/resourceGroups/{resourceGroupName} */ - public void deleteResourceGroup(Context ctx) { - String name = ctx.pathParam("resourceGroupName"); - optimizerManager.deleteResourceGroup(name); - ctx.json(OkResponse.of("The optimizer group has been successfully deleted.")); - } - - /** check if optimizerGroup can be deleted url = /optimize/resourceGroups/delete/check */ - public void deleteCheckResourceGroup(Context ctx) { - String name = ctx.pathParam("resourceGroupName"); - ctx.json(OkResponse.of(optimizerManager.canDeleteResourceGroup(name))); + ctx.json(OkResponse.of("success to create optimizer")); } /** check if optimizerGroup can be deleted url = /optimize/containers/get */ diff --git a/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerGroupController.java b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerGroupController.java new file mode 100644 index 0000000000..8d8ac3fc79 --- /dev/null +++ b/amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/OptimizerGroupController.java @@ -0,0 +1,278 @@ +/* + * 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.controller; + +import io.javalin.http.Context; +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.persistence.TableRuntimeMeta; +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 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 OptimizerGroupController { + private static final String ALL_GROUP = "all"; + private final TableService tableService; + private final DefaultOptimizingService optimizerManager; + + public OptimizerGroupController( + TableService tableService, DefaultOptimizingService optimizerManager) { + this.tableService = tableService; + 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; + + String optimizerGroupUsedInDbFilter = ALL_GROUP.equals(optimizerGroup) ? null : optimizerGroup; + // get all info from underlying table table_runtime + List tableRuntimeBeans = + tableService.getTableRuntimes( + optimizerGroupUsedInDbFilter, dbFilterStr, tableFilterStr, pageSize, offset); + + List tableRuntimes = + tableRuntimeBeans.stream() + .map(meta -> tableService.getRuntime(meta.getTableId())) + .collect(Collectors.toList()); + + 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> result = + optimizerManager.listResourceGroups().stream() + .filter( + resourceGroup -> + !ResourceContainers.EXTERNAL_CONTAINER_NAME.equals( + resourceGroup.getContainer())) + .map( + e -> { + Map mapObj = new HashMap<>(); + mapObj.put("optimizerGroupName", e.getName()); + return mapObj; + }) + .collect(Collectors.toList()); + ctx.json(OkResponse.of(result)); + } + + /** get optimizer info: occupationCore, occupationMemory */ + public void getOptimizerGroupInfo(Context ctx) { + String optimizerGroup = ctx.pathParam("optimizerGroup"); + List optimizers; + if (optimizerGroup.equals("all")) { + optimizers = optimizerManager.listOptimizers(); + } else { + optimizers = optimizerManager.listOptimizers(optimizerGroup); + } + OptimizerResourceInfo optimizerResourceInfo = new OptimizerResourceInfo(); + optimizers.forEach( + e -> { + optimizerResourceInfo.addOccupationCore(e.getThreadCount()); + optimizerResourceInfo.addOccupationMemory(e.getMemoryMb()); + }); + ctx.json(OkResponse.of(optimizerResourceInfo)); + } + + /** + * release optimizer. + * + * @pathParam jobId + */ + public void releaseOptimizer(Context ctx) { + String resourceId = ctx.pathParam("jobId"); + Preconditions.checkArgument( + !resourceId.isEmpty(), "resource id can not be empty, maybe it's a external optimizer"); + + List optimizerInstances = + optimizerManager.listOptimizers().stream() + .filter(e -> resourceId.equals(e.getResourceId())) + .collect(Collectors.toList()); + Preconditions.checkState( + !optimizerInstances.isEmpty(), + String.format( + "The resource ID %s has not been indexed" + " to any optimizer.", resourceId)); + Resource resource = optimizerManager.getResource(resourceId); + resource.getProperties().putAll(optimizerInstances.get(0).getProperties()); + ResourceContainers.get(resource.getContainerName()).releaseOptimizer(resource); + optimizerManager.deleteResource(resourceId); + optimizerManager.deleteOptimizer(resource.getGroupName(), resourceId); + ctx.json(OkResponse.of("Success to release optimizer")); + } + + /** scale out optimizers, url:/optimizerGroups/{optimizerGroup}/optimizers. */ + public void scaleOutOptimizer(Context ctx) { + String optimizerGroup = ctx.pathParam("optimizerGroup"); + Map map = ctx.bodyAsClass(Map.class); + int parallelism = map.get("parallelism"); + + ResourceGroup resourceGroup = optimizerManager.getResourceGroup(optimizerGroup); + Resource resource = + new Resource.Builder( + resourceGroup.getContainer(), resourceGroup.getName(), ResourceType.OPTIMIZER) + .setProperties(resourceGroup.getProperties()) + .setThreadCount(parallelism) + .build(); + ResourceContainers.get(resource.getContainerName()).requestResource(resource); + optimizerManager.createResource(resource); + ctx.json(OkResponse.of("success to scaleOut optimizer")); + } + + /** get {@link List} url = /optimize/resourceGroups */ + public void getResourceGroup(Context ctx) { + List result = + optimizerManager.listResourceGroups().stream() + .map( + group -> { + List optimizers = + optimizerManager.listOptimizers(group.getName()); + OptimizerResourceInfo optimizerResourceInfo = new OptimizerResourceInfo(); + optimizerResourceInfo.setResourceGroup( + optimizerManager.getResourceGroup(group.getName())); + optimizers.forEach( + optimizer -> { + optimizerResourceInfo.addOccupationCore(optimizer.getThreadCount()); + optimizerResourceInfo.addOccupationMemory(optimizer.getMemoryMb()); + }); + return optimizerResourceInfo; + }) + .collect(Collectors.toList()); + ctx.json(OkResponse.of(result)); + } + + /** + * create optimizeGroup: name, container, schedulePolicy, properties url = + * /optimize/resourceGroups/create + */ + public void createResourceGroup(Context ctx) { + Map map = ctx.bodyAsClass(Map.class); + String name = (String) map.get("name"); + String container = (String) map.get("container"); + Map properties = (Map) map.get("properties"); + if (optimizerManager.getResourceGroup(name) != null) { + throw new BadRequestException(String.format("Optimizer group:%s already existed.", name)); + } + ResourceGroup.Builder builder = new ResourceGroup.Builder(name, container); + builder.addProperties(properties); + optimizerManager.createResourceGroup(builder.build()); + ctx.json(OkResponse.of("The optimizer group has been successfully created.")); + } + + /** + * update optimizeGroup: name, container, schedulePolicy, properties url = + * /optimize/resourceGroups/update + */ + public void updateResourceGroup(Context ctx) { + Map map = ctx.bodyAsClass(Map.class); + String name = (String) map.get("name"); + String container = (String) map.get("container"); + Map properties = (Map) map.get("properties"); + ResourceGroup.Builder builder = new ResourceGroup.Builder(name, container); + builder.addProperties(properties); + optimizerManager.updateResourceGroup(builder.build()); + ctx.json(OkResponse.of("The optimizer group has been successfully updated.")); + } + + /** delete optimizeGroup url = /optimize/resourceGroups/{resourceGroupName} */ + public void deleteResourceGroup(Context ctx) { + String name = ctx.pathParam("resourceGroupName"); + optimizerManager.deleteResourceGroup(name); + ctx.json(OkResponse.of("The optimizer group has been successfully deleted.")); + } + + /** check if optimizerGroup can be deleted url = /optimize/resourceGroups/delete/check */ + public void deleteCheckResourceGroup(Context ctx) { + String name = ctx.pathParam("resourceGroupName"); + ctx.json(OkResponse.of(optimizerManager.canDeleteResourceGroup(name))); + } + + /** check if optimizerGroup can be deleted url = /optimize/containers/get */ + public void getContainers(Context ctx) { + ctx.json( + OkResponse.of( + ResourceContainers.getMetadataList().stream() + .map(ContainerMetadata::getName) + .collect(Collectors.toList()))); + } +} diff --git a/amoro-web/src/language/en.ts b/amoro-web/src/language/en.ts index d78bbc6e67..7a8deeabca 100644 --- a/amoro-web/src/language/en.ts +++ b/amoro-web/src/language/en.ts @@ -194,6 +194,7 @@ export default { search: 'Search', reset: 'Reset', invalidInput: 'Invalid input', + createOptimizer: 'Create Optimizer', addgroup: 'Add Group', editgroup: 'Edit Group', cannotDeleteGroupModalTitle: 'Can\'t remove this group.', diff --git a/amoro-web/src/language/zh.ts b/amoro-web/src/language/zh.ts index 036420b786..a794732c5f 100644 --- a/amoro-web/src/language/zh.ts +++ b/amoro-web/src/language/zh.ts @@ -194,6 +194,7 @@ export default { search: '搜索', reset: '重置', invalidInput: '非法输入', + createOptimizer: '创建优化器', addgroup: '添加组', editgroup: '编辑组', cannotDeleteGroupModalTitle: '不能移除这个组', diff --git a/amoro-web/src/services/optimize.service.ts b/amoro-web/src/services/optimize.service.ts index 75846dc01a..cd1c368078 100644 --- a/amoro-web/src/services/optimize.service.ts +++ b/amoro-web/src/services/optimize.service.ts @@ -62,14 +62,24 @@ export function scaleoutResource( return request.post(`ams/v1/optimize/optimizerGroups/${optimizerGroup}/optimizers`, { parallelism }) } +export function createOptimizerResource( + params: { + optimizerGroup: string + parallelism: number + }, +) { + const { optimizerGroup, parallelism } = params + return request.post(`ams/v1/optimize/optimizers`, { optimizerGroup, parallelism }) +} + export function releaseResource( params: { optimizerGroup: string jobId: string }, ) { - const { optimizerGroup, jobId } = params - return request.delete(`ams/v1/optimize/optimizerGroups/${optimizerGroup}/optimizers/${jobId}`) + const { jobId } = params + return request.delete(`ams/v1/optimize/optimizers/${jobId}`) } export async function getResourceGroupsListAPI() { diff --git a/amoro-web/src/views/resource/components/CreateOptimizerModal.vue b/amoro-web/src/views/resource/components/CreateOptimizerModal.vue new file mode 100644 index 0000000000..be668be9bd --- /dev/null +++ b/amoro-web/src/views/resource/components/CreateOptimizerModal.vue @@ -0,0 +1,126 @@ + + + + + + \ No newline at end of file diff --git a/amoro-web/src/views/resource/components/List.vue b/amoro-web/src/views/resource/components/List.vue index 6e9a206b30..3693d97118 100644 --- a/amoro-web/src/views/resource/components/List.vue +++ b/amoro-web/src/views/resource/components/List.vue @@ -25,8 +25,6 @@ import { getOptimizerResourceList, getResourceGroupsListAPI, groupDeleteAPI, gro import { usePagination } from '@/hooks/usePagination' import { dateFormat, mbToSize } from '@/utils' -import ScaleOut from '@/views/resource/components/ScaleOut.vue' - const props = defineProps<{ curGroupName?: string, type: string }>() const emit = defineEmits<{ @@ -249,12 +247,6 @@ onMounted(() => { - diff --git a/amoro-web/src/views/resource/index.vue b/amoro-web/src/views/resource/index.vue index 20b2858fca..24f6c80d52 100644 --- a/amoro-web/src/views/resource/index.vue +++ b/amoro-web/src/views/resource/index.vue @@ -24,6 +24,7 @@ import { shallowReactive, toRefs, watch, + ref, } from 'vue' import { useI18n } from 'vue-i18n' import { useRoute, useRouter } from 'vue-router' @@ -33,6 +34,7 @@ import { usePlaceholder } from '@/hooks/usePlaceholder' import { usePagination } from '@/hooks/usePagination' import type { IIOptimizeGroupItem, ILableAndValue } from '@/types/common.type' import GroupModal from '@/views/resource/components/GroupModal.vue' +import CreateOptimizerModal from '@/views/resource/components/CreateOptimizerModal.vue' export default defineComponent({ name: 'Resource', @@ -40,6 +42,7 @@ export default defineComponent({ List, GroupModal, TableList, + CreateOptimizerModal, }, setup() { const { t } = useI18n() @@ -69,6 +72,9 @@ export default defineComponent({ }, groupKeyCount: 1, showTab: false as boolean, + showCreateOptimizer: false as boolean, + optimizerEdit: false, + optimizerEditRecord: null, }) watch( @@ -92,6 +98,16 @@ export default defineComponent({ state.showGroupModal = true } + const createOptimizer = (editRecord: any | null) => { + if (editRecord) { + state.optimizerEdit = true + state.optimizerEditRecord = { ...editRecord } + } else { + state.optimizerEdit = false + } + state.showCreateOptimizer = true + } + const onChangeTab = (key: string) => { const query = { ...route.query } query.tab = key @@ -102,6 +118,7 @@ export default defineComponent({ state.showTab = true }) + let createOptimizer1 = createOptimizer; return { placeholder, pagination, @@ -109,6 +126,7 @@ export default defineComponent({ tabConfig, onChangeTab, editGroup, + createOptimizer, t, } }, @@ -136,6 +154,9 @@ export default defineComponent({ :tab="t('optimizers')" :class="[activeTab === 'optimizers' ? 'active' : '']" > + + {{ t("createOptimizer") }} + +