Skip to content

Commit

Permalink
Merge pull request #1607 from hanbingleixue/develop
Browse files Browse the repository at this point in the history
Add front-end pages and services with dynamic mounting function
  • Loading branch information
Sherlockhan authored Aug 31, 2024
2 parents c5d5819 + 938289b commit a61202c
Show file tree
Hide file tree
Showing 17 changed files with 884 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. 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 io.sermant.backend.controller;

import io.sermant.backend.entity.config.Result;
import io.sermant.backend.entity.config.ResultCodeType;
import io.sermant.backend.entity.hotplugging.HotPluggingConfig;
import io.sermant.backend.service.HotPluggingService;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
* Hot Plugging controller
*
* @author zhp
* @since 2024-08-22
*/
@RestController
@RequestMapping("/sermant")
public class HotPluggingController {
@Resource
private HotPluggingService hotPluggingService;

/**
* publish configuration
*
* @param hotPluggingConfig hot plugging configuration information
* @return The result of publish hot plugging configuration
*/
@PostMapping("/publishHotPluggingConfig")
public Result<Boolean> publishHotPluggingConfig(@RequestBody HotPluggingConfig hotPluggingConfig) {
if (hotPluggingConfig == null || StringUtils.isEmpty(hotPluggingConfig.getCommandType())
|| StringUtils.isEmpty(hotPluggingConfig.getInstanceIds())) {
return new Result<>(ResultCodeType.MISS_PARAM);
}
return hotPluggingService.publishHotPluggingConfig(hotPluggingConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.sermant.backend.entity;

import io.sermant.backend.entity.event.EventLevel;
import io.sermant.backend.entity.event.EventType;
import lombok.Getter;
import lombok.Setter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public Result(String code, String message) {
this.message = message;
}

/**
* Constructor
*
* @param resultCodeType Result information
*/
public Result(ResultCodeType resultCodeType) {
this.code = resultCodeType.getCode();
this.message = resultCodeType.getMessage();
}

/**
* Constructor
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class EventsRequestEntity {
*/
private List<String> service = new ArrayList<>();

/**
* event name
*/
private List<String> name = new ArrayList<>();

/**
* address
*/
Expand Down Expand Up @@ -70,4 +75,9 @@ public class EventsRequestEntity {
* session id
*/
private String sessionId;

/**
* instance id
*/
private List<String> instanceIds = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public class HeartbeatMessage {

private Map<String, PluginInfo> pluginInfoMap = new HashMap<>();

private String appName;

private String artifact;

private String processId;

private boolean dynamicInstall;

public String getHostName() {
return hostName;
}
Expand Down Expand Up @@ -146,4 +154,36 @@ public boolean isHealth() {
public void setHealth(boolean health) {
this.health.compareAndSet(!health, health);
}

public String getAppName() {
return appName;
}

public void setAppName(String appName) {
this.appName = appName;
}

public String getArtifact() {
return artifact;
}

public void setArtifact(String artifact) {
this.artifact = artifact;
}

public String getProcessId() {
return processId;
}

public boolean isDynamicInstall() {
return dynamicInstall;
}

public void setDynamicInstall(boolean dynamicInstall) {
this.dynamicInstall = dynamicInstall;
}

public void setProcessId(String processId) {
this.processId = processId;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (C) 2024-2024 Sermant Authors. 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.
Expand All @@ -14,44 +14,35 @@
* limitations under the License.
*/

package io.sermant.backend.entity;
package io.sermant.backend.entity.hotplugging;

/**
* Event Type
* Enumeration of instructions for dynamic installation and uninstallation
*
* @author xuezechao
* @since 2023-03-02
* @author zhp
* @since 2024-08-22
*/
public enum EventType {
public enum CommandType {
/**
* OPERATION event
* Install plugin instruction
*/
OPERATION(0, "operation"),

INSTALL_PLUGINS("INSTALL-PLUGINS"),
/**
* GOVERNANCE event
* Update plugin instruction
*/
GOVERNANCE(1, "governance"),

UPDATE_PLUGINS("UPDATE-PLUGINS"),
/**
* LOG event
* Uninstall plugin instruction
*/
LOG(2, "log");

private final int type;
UNINSTALL_PLUGINS("UNINSTALL-PLUGINS");

private final String description;

EventType(int type, String description) {
this.type = type;
this.description = description;
}
private final String value;

public int getType() {
return type;
CommandType(String value) {
this.value = value;
}

public String getDescription() {
return description;
public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2023 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (C) 2024-2024 Sermant Authors. 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.
Expand All @@ -14,37 +14,42 @@
* limitations under the License.
*/

package io.sermant.backend.entity;
package io.sermant.backend.entity.hotplugging;

import lombok.Getter;
import lombok.Setter;

/**
* Event Level
* Hot Plugging configuration
*
* @author xuezechao
* @since 2023-03-02
* @author zhp
* @since 2024-08-22
*/
public enum EventLevel {
@Getter
@Setter
public class HotPluggingConfig {
/**
* EMERGENCY Level
* Plugin Names
*/
EMERGENCY(300),
private String pluginNames;

/**
* IMPORTANT Level
* JavaAgent Path
*/
IMPORTANT(200),
private String agentPath;

/**
* NORMAL Level
* parameter information
*/
NORMAL(100);

private final int levelThreshold;
private String params;

EventLevel(int levelThreshold) {
this.levelThreshold = levelThreshold;
}
/**
* Command type
*/
private String commandType;

public int getLevelThreshold() {
return levelThreshold;
}
/**
* Instance ID
*/
private String instanceIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,22 @@ public void process(WatchedEvent event) {
}
}

/**
* Get Configuration Center Client
*
* @return Configuration Center Client
*/
public ConfigClient getConfigClient() {
return getConfigClient(null);
}

/**
* Get Configuration Center Client
*
* @param namespace Configuration namespace
* @return Configuration Center Client
*/
private ConfigClient getConfigClient(String namespace) {
public ConfigClient getConfigClient(String namespace) {
if (!ConfigCenterType.NACOS.name().equals(dynamicConfig.getDynamicConfigType())
|| StringUtils.isEmpty(namespace)) {
return configClient;
Expand Down
Loading

0 comments on commit a61202c

Please sign in to comment.