Skip to content

Commit

Permalink
Add dynamically configured entity classes
Browse files Browse the repository at this point in the history
Signed-off-by: hanbingleixue <[email protected]>
  • Loading branch information
hanbingleixue committed May 31, 2024
1 parent ba3b2c4 commit 96b8056
Show file tree
Hide file tree
Showing 6 changed files with 399 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2024-2024 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 io.sermant.backend.entity.config;

import lombok.Getter;
import lombok.Setter;

/**
* configuration information
*
* @author zhp
* @since 2024-05-16
*/
@Getter
@Setter
public class ConfigInfo {
private String pluginType;

private String nameSpace;

private String serviceName;

private String environment;

private String appName;

private String zone;

private String group;

private String key;

private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024-2024 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 io.sermant.backend.entity.config;

import lombok.Getter;
import lombok.Setter;

/**
* Configuration Center Information
*
* @author zhp
* @since 2024-05-16
*/
@Getter
@Setter
public class ConfigServerInfo {
private String serverAddress;

private String userName;

private String password;

private String secretKey;

private String dynamicConfigType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (C) 2024-2024 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 io.sermant.backend.entity.config;

import io.sermant.backend.handler.config.DatabaseWriteProhibitionPluginHandler;
import io.sermant.backend.handler.config.FlowcontrolPluginHandler;
import io.sermant.backend.handler.config.LoadbalancerPluginHandler;
import io.sermant.backend.handler.config.MqConsumeProhibitionPluginHandler;
import io.sermant.backend.handler.config.OtherPluginHandler;
import io.sermant.backend.handler.config.PluginHandler;
import io.sermant.backend.handler.config.RemovalPluginHandler;
import io.sermant.backend.handler.config.RouterPluginHandler;
import io.sermant.backend.handler.config.ServiceRegistryPluginHandler;
import io.sermant.backend.handler.config.SpringBootRegistryPluginHandler;
import io.sermant.backend.handler.config.TagTransmissionPluginHandler;
import lombok.Getter;

import java.util.Optional;

/**
* Plugin type
*
* @author zhp
* @since 2024-05-16
*/
@Getter
public enum PluginType {
/**
* Label routing plugin
*/
ROUTER("router", new RouterPluginHandler()),

/**
* Springboot registration plugin
*/
SPRINGBOOT_REGISTRY("springboot-registry", new SpringBootRegistryPluginHandler()),

/**
* Register migration plugin
*/
SERVICE_REGISTRY("service-registry", new ServiceRegistryPluginHandler()),

/**
* flowcontrol plugin
*/
FLOW_CONTROL("flowcontrol", new FlowcontrolPluginHandler()),
/**
* Outlier instance removal plugin
*/
REMOVAL("removal", new RemovalPluginHandler()),

/**
* Load balancing plugin
*/
LOADBALANCER("loadbalancer", new LoadbalancerPluginHandler()),

/**
* Traffic tag transparency plugin
*/
TAG_TRANSMISSION("tag-transmission", new TagTransmissionPluginHandler()),

/**
* Message queue prohibited consumption plugin
*/
MQ_CONSUME_PROHIBITION("mq-consume-prohibition", new MqConsumeProhibitionPluginHandler()),

/**
* Database write prohibited plugin
*/
DATABASE_WRITE_PROHIBITION("database-write-prohibition", new DatabaseWriteProhibitionPluginHandler()),

/**
* other plugin
*/
OTHER("other", new OtherPluginHandler());

private final String pluginName;

private final PluginHandler handler;

PluginType(String pluginName, PluginHandler handler) {
this.pluginName = pluginName;
this.handler = handler;
}

/**
* Obtain plugin type based on plugin name
*
* @param pluginName plugin name
* @return plugin type
*/
public static Optional<PluginType> getPluginType(String pluginName) {
for (PluginType pluginType : PluginType.values()) {
if (pluginType.pluginName.equals(pluginName)) {
return Optional.of(pluginType);
}
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024-2024 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 io.sermant.backend.entity.config;

import lombok.Getter;
import lombok.Setter;

/**
* configuration information
*
* @param <R> Result data type
* @author zhp
* @since 2024-05-16
*/
@Getter
@Setter
public class Result<R> {
private String code;

private String message;

private R data;

/**
* Constructor
*
* @param code result code
* @param message result message
*/
public Result(String code, String message) {
this.code = code;
this.message = message;
}

/**
* Constructor
*
* @param code result code
* @param message result message
* @param data result data
*/
public Result(String code, String message, R data) {
this.code = code;
this.message = message;
this.data = data;
}

public boolean isSuccess() {
return ResultCodeType.SUCCESS.getCode().equals(this.code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2024-2024 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 io.sermant.backend.entity.config;

import lombok.Getter;

/**
* Result encoding type
*
* @author zhp
* @since 2024-05-16
*/
@Getter
public enum ResultCodeType {
/**
* Interface call successful
*/
SUCCESS("00", "Success."),

/**
* Unable to establish connection with Configuration Center failed
*/
CONNECT_FAIL("01", "Unable to establish connection with Configuration Center failed."),

/**
* Configuration query failed
*/
QUERY_FAIL("02", "Configuration query failed."),

/**
* configuration item already exists
*/
EXISTS("03", "configuration item already exists."),

/**
* Failed to add configuration
*/
ADD_FAIL("04", "Failed to add configuration."),

/**
* Failed to modify configuration
*/
MODIFY_FAIL("05", "Failed to modify configuration."),

/**
* Failed to delete configuration
*/
DELETE_FAIL("06", "Failed to delete configuration."),

/**
* Configuration does not exist
*/
NOT_EXISTS("07", "Configuration does not exist."),

/**

Check failure on line 69 in sermant-backend/src/main/java/io/sermant/backend/entity/config/ResultCodeType.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 Block comment has incorrect indentation level 4, expected is 5, indentation should be the same level as line 72. Raw Output: /home/runner/work/Sermant/Sermant/./sermant-backend/src/main/java/io/sermant/backend/entity/config/ResultCodeType.java:69:5: error: Block comment has incorrect indentation level 4, expected is 5, indentation should be the same level as line 72. (com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck)
* Missing parameter information
*/
MISS_PARAM("08", "Missing parameter information."),

/**
* Interface call failed
*/
FAIL("09", "Failure.");

private final String code;

private final String message;

ResultCodeType(String code, String message) {
this.code = code;
this.message = message;
}
}
Loading

0 comments on commit 96b8056

Please sign in to comment.