-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64d7eeb
commit 7fcf5af
Showing
11 changed files
with
388 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ore/src/main/java/com/huaweicloud/sermant/core/command/AgentUnInstallCommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.command; | ||
|
||
import com.huaweicloud.sermant.core.AgentCoreEntrance; | ||
import com.huaweicloud.sermant.core.common.LoggerFactory; | ||
|
||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Agent卸载命令执行器 | ||
* | ||
* @author zhp | ||
* @since 2023-09-09 | ||
*/ | ||
public class AgentUnInstallCommandExecutor implements CommandExecutor { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(); | ||
|
||
@Override | ||
public void execute(String commandContent) { | ||
AgentCoreEntrance.unInstall(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...re/sermant-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.command; | ||
|
||
/** | ||
* 动态安装卸载的指令枚举 | ||
* | ||
* @author zhp | ||
* @since 2023-09-09 | ||
*/ | ||
public enum Command { | ||
/** | ||
* 卸载agent指令 | ||
*/ | ||
UNINSTALL_AGENT("UNINSTALL-AGENT", "卸载agent"), | ||
/** | ||
* 安装插件指令 | ||
*/ | ||
INSTALL_PLUGINS("INSTALL-PLUGINS", "安装插件"), | ||
/** | ||
* 卸载插件指令 | ||
*/ | ||
UNINSTALL_PLUGINS("UNINSTALL-PLUGINS", "卸载插件"); | ||
private final String code; | ||
|
||
private final String desc; | ||
|
||
Command(String code, String desc) { | ||
this.code = code; | ||
this.desc = desc; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public String getDesc() { | ||
return desc; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...nt-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.command; | ||
|
||
/** | ||
* 指令执行器 | ||
* | ||
* @author zhp | ||
* @since 2023-09-09 | ||
*/ | ||
public interface CommandExecutor { | ||
|
||
/** | ||
* 执行指令 | ||
* | ||
* @param commandContent 指令的具体内容 | ||
*/ | ||
void execute(String commandContent); | ||
} |
76 changes: 76 additions & 0 deletions
76
...t-agentcore-core/src/main/java/com/huaweicloud/sermant/core/command/CommandProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.command; | ||
|
||
import com.huaweicloud.sermant.core.common.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* 命令处理器 | ||
* | ||
* @author zhp | ||
* @since 2023-09-09 | ||
*/ | ||
public class CommandProcessor { | ||
/** | ||
* 命令执行器Map | ||
*/ | ||
private static final Map<String, CommandExecutor> COMMAND_EXECUTOR_MAP = new HashMap<>(); | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(); | ||
|
||
static { | ||
COMMAND_EXECUTOR_MAP.put(Command.INSTALL_PLUGINS.getCode(), new PluginsInstallCommandExecutor()); | ||
COMMAND_EXECUTOR_MAP.put(Command.UNINSTALL_AGENT.getCode(), new AgentUnInstallCommandExecutor()); | ||
COMMAND_EXECUTOR_MAP.put(Command.UNINSTALL_PLUGINS.getCode(), new PluginsUnInstallCommandExecutor()); | ||
} | ||
|
||
/** | ||
* 构造函数 | ||
*/ | ||
private CommandProcessor() { | ||
} | ||
|
||
/** | ||
* 处理指令 | ||
* | ||
* @param command 指令 | ||
* @param commandContent 指令内容 | ||
*/ | ||
public static void process(String command, String commandContent) { | ||
CommandExecutor commandExecutor = chooseExecutor(command); | ||
if (commandExecutor == null) { | ||
LOGGER.log(Level.SEVERE, "No corresponding command executor found"); | ||
return; | ||
} | ||
commandExecutor.execute(commandContent); | ||
} | ||
|
||
/** | ||
* 选择命令执行器 | ||
* | ||
* @param command 命令 | ||
* @return 命令执行器 | ||
*/ | ||
public static CommandExecutor chooseExecutor(String command) { | ||
return COMMAND_EXECUTOR_MAP.get(command); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ore/src/main/java/com/huaweicloud/sermant/core/command/PluginsInstallCommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.command; | ||
|
||
import com.huaweicloud.sermant.core.common.LoggerFactory; | ||
import com.huaweicloud.sermant.core.plugin.PluginManager; | ||
import com.huaweicloud.sermant.core.utils.StringUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 插件安装命令执行器 | ||
* | ||
* @author zhp | ||
* @since 2023-09-09 | ||
*/ | ||
public class PluginsInstallCommandExecutor implements CommandExecutor { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(); | ||
|
||
@Override | ||
public void execute(String commandContent) { | ||
if (StringUtils.isEmpty(commandContent)) { | ||
LOGGER.log(Level.FINER, "The installed plugin information is empty"); | ||
return; | ||
} | ||
String[] pluginNames = commandContent.split(","); | ||
PluginManager.install(Arrays.stream(pluginNames).collect(Collectors.toSet())); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...e/src/main/java/com/huaweicloud/sermant/core/command/PluginsUnInstallCommandExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved. | ||
* | ||
* Licensed 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 com.huaweicloud.sermant.core.command; | ||
|
||
import com.huaweicloud.sermant.core.common.LoggerFactory; | ||
import com.huaweicloud.sermant.core.plugin.PluginManager; | ||
import com.huaweicloud.sermant.core.utils.StringUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 插件卸载命令执行器 | ||
* | ||
* @author zhp | ||
* @since 2023-09-09 | ||
*/ | ||
public class PluginsUnInstallCommandExecutor implements CommandExecutor { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(); | ||
|
||
@Override | ||
public void execute(String commandContent) { | ||
if (StringUtils.isEmpty(commandContent)) { | ||
LOGGER.log(Level.FINER, "The unInstalled plugin information is empty"); | ||
return; | ||
} | ||
String[] pluginNames = commandContent.split(","); | ||
PluginManager.unInstall(Arrays.stream(pluginNames).collect(Collectors.toSet())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.