From ef01f658063d9dc702109751a416371dd07a0fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cv=5Fkkhuang=E2=80=9D?= <“420895376@qq.com”> Date: Thu, 28 Nov 2024 10:23:44 +0800 Subject: [PATCH] push updaet udf kill engine --- .../manager/am/conf/AMConfiguration.java | 1 + .../manager/am/restful/EngineRestfulApi.java | 16 ++++++-- .../engine/DefaultEngineStopService.scala | 40 ++++++++++--------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/conf/AMConfiguration.java b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/conf/AMConfiguration.java index 051b53e3a5..197e450ea3 100644 --- a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/conf/AMConfiguration.java +++ b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/conf/AMConfiguration.java @@ -104,6 +104,7 @@ public class AMConfiguration { CommonVars.apply("wds.linkis.allow.batch.kill.engine.types", "trino,appconn,io_file,jdbc"); public static final CommonVars MULTI_USER_ENGINE_USER = CommonVars.apply("wds.linkis.multi.user.engine.user", getDefaultMultiEngineUser()); + public static final String UDF_KILL_ENGINE_TYPE = CommonVars.apply("linkis.udf.kill.engine.type", "spark,hive").getValue(); public static final CommonVars ENGINE_LOCKER_MAX_TIME = CommonVars.apply("wds.linkis.manager.am.engine.locker.max.time", 1000 * 60 * 5); diff --git a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/restful/EngineRestfulApi.java b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/restful/EngineRestfulApi.java index 4f68937e63..223c1b2c23 100644 --- a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/restful/EngineRestfulApi.java +++ b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/java/org/apache/linkis/manager/am/restful/EngineRestfulApi.java @@ -737,7 +737,7 @@ public Message executeEngineConnOperation(HttpServletRequest req, @RequestBody J @ApiOperation( value = "kill egineconns of a ecm", - notes = "Kill engine after updating configuration", + notes = "Kill engine by cteator or engineType", response = Message.class) @ApiImplicitParams({ @ApiImplicitParam(name = "creator", dataType = "String", required = true, example = "IDE"), @@ -748,7 +748,7 @@ public Message executeEngineConnOperation(HttpServletRequest req, @RequestBody J example = "hive-2.3.3"), }) @ApiOperationSupport(ignoreParameters = {"param"}) - @RequestMapping(path = "/rm/killEngineByUpdateConfig", method = RequestMethod.POST) + @RequestMapping(path = "/rm/killEngineByCreatorEngineType", method = RequestMethod.POST) public Message killEngineByUpdateConfig(HttpServletRequest req, @RequestBody JsonNode jsonNode) throws AMErrorException { String userName = ModuleUserUtils.getOperationUser(req); @@ -770,10 +770,18 @@ public Message killEngineByUpdateConfig(HttpServletRequest req, @RequestBody Jso && AMConfiguration.isUnAllowKilledEngineType(engineType)) { return Message.error("multi user engine does not support this feature(多用户引擎不支持此功能)"); } - engineStopService.stopUnlockECByUserCreatorAndECType(userName, creatorStr, engineType); + if (engineType.equals(Configuration.GLOBAL_CONF_SYMBOL())) { + Arrays.stream(AMConfiguration.UDF_KILL_ENGINE_TYPE.split(",")) + .forEach( + engine -> + engineStopService.stopUnlockECByUserCreatorAndECType( + userName, creatorStr, engine)); + } else { + engineStopService.stopUnlockECByUserCreatorAndECType( + userName, creatorStr, engineType); + } return Message.ok("Kill engineConn succeed"); } - static ServiceInstance getServiceInstance(JsonNode jsonNode) throws AMErrorException { String applicationName = jsonNode.get("applicationName").asText(); String instance = jsonNode.get("instance").asText(); diff --git a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/am/service/engine/DefaultEngineStopService.scala b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/am/service/engine/DefaultEngineStopService.scala index 3c6d7eaffd..f3cccaac9d 100644 --- a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/am/service/engine/DefaultEngineStopService.scala +++ b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/am/service/engine/DefaultEngineStopService.scala @@ -290,24 +290,28 @@ class DefaultEngineStopService extends AbstractEngineService with EngineStopServ dealEngineByEngineNode(engineNodes.toList, userName) } // kill EMnode by user creator - if (StringUtils.isNotBlank(engineType) && !creator.equals(Configuration.GLOBAL_CONF_SYMBOL)) { - val filterEngineNode = engineNodes - .filter(_.getOwner.equals(userName)) - .filter(node => { - var filterResult = false - if (!node.getLabels.isEmpty) { - val userCreator = LabelUtil.getUserCreatorLabel(node.getLabels) - val engineTypeLabel = LabelUtil.getEngineTypeLabel(node.getLabels).getStringValue - if ( - userCreator.getUser.equals(userName) && userCreator.getCreator - .equals(creator) && engineTypeLabel.equals(engineType) - ) { - filterResult = true - } - } - filterResult - }) - .toList + if (StringUtils.isNotBlank(engineType)) { + val filterEngineNode = creator match { + case Configuration.GLOBAL_CONF_SYMBOL => + engineNodes + .filter(_.getOwner.equals(userName)) + .filter(!_.getLabels.isEmpty) + .filter(node => + LabelUtil.getUserCreatorLabel(node.getLabels).getUser.equals(userName) + && LabelUtil.getEngineTypeLabel(node.getLabels).getEngineType.equals(engineType) + ) + .toList + case _ => + engineNodes + .filter(_.getOwner.equals(userName)) + .filter(!_.getLabels.isEmpty) + .filter(node => + LabelUtil.getUserCreatorLabel(node.getLabels).getUser.equals(userName) + && LabelUtil.getUserCreatorLabel(node.getLabels).getCreator.equals(creator) + && LabelUtil.getEngineTypeLabel(node.getLabels).getEngineType.equals(engineType) + ) + .toList + } dealEngineByEngineNode(filterEngineNode, userName) } }