Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Copyright 1999-2024 Alibaba Group Holding Ltd.
*
* 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.alibaba.nacos.api.plugin;

import java.io.Serializable;
import java.util.List;

/**
* Plugin configuration item definition.
*
* @author WangzJi
* @since 3.2.0
*/
public class ConfigItemDefinition implements Serializable {

private static final long serialVersionUID = 1L;

/**
* Configuration key.
*/
private String key;

/**
* Display name.
*/
private String name;

/**
* Description.
*/
private String description;

/**
* Default value.
*/
private String defaultValue;

/**
* Configuration item type.
*/
private ConfigItemType type;

/**
* Whether this item is required.
*/
private boolean required;

/**
* Enum values (when type is ENUM).
*/
private List<String> enumValues;

public ConfigItemDefinition() {
}

public ConfigItemDefinition(String key, String name, ConfigItemType type) {
this.key = key;
this.name = name;
this.type = type;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getDefaultValue() {
return defaultValue;
}

public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}

public ConfigItemType getType() {
return type;
}

public void setType(ConfigItemType type) {
this.type = type;
}

public boolean isRequired() {
return required;
}

public void setRequired(boolean required) {
this.required = required;
}

public List<String> getEnumValues() {
return enumValues;
}

public void setEnumValues(List<String> enumValues) {
this.enumValues = enumValues;
}

/**
* Builder for ConfigItemDefinition.
*/
public static class Builder {

private final ConfigItemDefinition definition;

public Builder(String key, String name, ConfigItemType type) {
this.definition = new ConfigItemDefinition(key, name, type);
}

public Builder description(String description) {
definition.setDescription(description);
return this;
}

public Builder defaultValue(String defaultValue) {
definition.setDefaultValue(defaultValue);
return this;
}

public Builder required(boolean required) {
definition.setRequired(required);
return this;
}

public Builder enumValues(List<String> enumValues) {
definition.setEnumValues(enumValues);
return this;
}

public ConfigItemDefinition build() {
return definition;
}
}
}
46 changes: 46 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/plugin/ConfigItemType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 1999-2024 Alibaba Group Holding Ltd.
*
* 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.alibaba.nacos.api.plugin;

/**
* Configuration item type enumeration.
*
* @author WangzJi
* @since 3.2.0
*/
public enum ConfigItemType {

/**
* String type configuration.
*/
STRING,

/**
* Number type configuration.
*/
NUMBER,

/**
* Boolean type configuration.
*/
BOOLEAN,

/**
* Enumeration type configuration.
*/
ENUM
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 1999-2024 Alibaba Group Holding Ltd.
*
* 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.alibaba.nacos.api.plugin;

import java.util.List;
import java.util.Map;

/**
* Plugin configuration specification interface.
* Allows plugins to declare configurable properties.
*
* @author WangzJi
* @since 3.2.0
*/
public interface PluginConfigSpec {

/**
* Get configuration item definitions.
*
* @return list of configuration item definitions
*/
List<ConfigItemDefinition> getConfigDefinitions();

/**
* Apply configuration to the plugin.
*
* @param config configuration key-value pairs
*/
void applyConfig(Map<String, String> config);

/**
* Get current configuration.
*
* @return current configuration as key-value pairs
*/
Map<String, String> getCurrentConfig();
}
73 changes: 73 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/plugin/PluginProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 1999-2024 Alibaba Group Holding Ltd.
*
* 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.alibaba.nacos.api.plugin;

import java.util.Map;

/**
* Plugin provider SPI interface.
*
* <p>Each plugin type should have one implementation to provide plugin instances.
* This interface enables automatic plugin discovery through SPI mechanism,
* eliminating the need to manually register each plugin type in UnifiedPluginManager.
*
* <p>Example implementation:
* <pre>{@code
* public class AuthPluginProvider implements PluginProvider<AuthPluginService> {
* @Override
* public PluginType getPluginType() {
* return PluginType.AUTH;
* }
*
* @Override
* public Map<String, AuthPluginService> getAllPlugins() {
* return AuthPluginManager.getInstance().getAllPlugins();
* }
* }
* }</pre>
*
* @param <T> the plugin service type
* @author WangzJi
* @since 3.2.0
*/
public interface PluginProvider<T> {

/**
* Get the plugin type this provider manages.
*
* @return plugin type
*/
PluginType getPluginType();

/**
* Get all plugin instances managed by this provider.
* Key is the plugin name, value is the plugin instance.
*
* @return map of plugin name to plugin instance
*/
Map<String, T> getAllPlugins();

/**
* Get the order of this provider. Lower values have higher priority.
* Used when multiple providers exist for same type.
*
* @return order value, default is 0
*/
default int getOrder() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 1999-2024 Alibaba Group Holding Ltd.
*
* 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.alibaba.nacos.api.plugin;

/**
* Plugin state checker interface.
* Used to decouple plugin managers from core module.
*
* @author WangzJi
* @since 3.0.0
*/
public interface PluginStateChecker {

/**
* Check if plugin is enabled.
*
* @param pluginType plugin type string
* @param pluginName plugin name
* @return true if plugin is enabled, false otherwise
*/
boolean isPluginEnabled(String pluginType, String pluginName);
}
Loading
Loading