diff --git a/be/src/plugin/plugin.h b/be/src/plugin/plugin.h new file mode 100644 index 0000000000..4770650cf7 --- /dev/null +++ b/be/src/plugin/plugin.h @@ -0,0 +1,75 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +namespace doris { + +#define PLUGIN_NOT_DYNAMIC_INSTALL 1UL +#define PLUGIN_NOT_DYNAMIC_UNINSTALL 2UL +#define PLUGIN_INSTALL_EARLY 4UL + +#define DORIS_PLUGIN_VERSION 001100UL + +/** + * define a plugin: + * + * declare_plugin(PLUGIN_NAME) { + * xx_handler, + * init_method, + * close_method, + * PLUGIN_NOT_DYNAMIC_INSTALL | PLUGIN_NOT_DYNAMIC_UNINSTALL, + * NULL, + * NULL + * } declare_plugin_end + * + */ +struct Plugin { + // support by type-specific plugin + void* handler; + + // invoke when plugin install + int (*init)(void *); + + // invoke when plugin uninstall + int (*close)(void *); + + // flag for plugin + uint64_t flags; + + // use to set/get variables + void* variable; + + // return the plugin's status + void* status; +}; + + +#define declare_plugin(NAME) \ + __DECLARE_PLUGIN(NAME, ##NAME##_plugin_interface_version, \ + ##NAME##_sizeof_struct_st_plugin, \ + ##NAME##_plugin) + +#define __DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \ + int VERSION = DORIS_PLUGIN_VERSION; \ + int PSIZE = sizeof(struct st_plugin); \ + struct st_plugin DECLS[] = { + + +#define declare_plugin_end \ + , { 0, 0, 0, 0, 0, 0 } \ + } + +} diff --git a/be/src/plugin/plugin_manager.h b/be/src/plugin/plugin_manager.h new file mode 100644 index 0000000000..85b45dbce8 --- /dev/null +++ b/be/src/plugin/plugin_manager.h @@ -0,0 +1,39 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#include +#include + +#include "common/status.h" +#include "plugin/plugin.h" + +namespace doris { + +class PluginManager { + +public: + Status load_plugin(Plugin* plugin); + + Status unload_plugin(Plugin* plugin); + + Status get_plugin(std::string name); + +private: + std::unordered_map _plugins; +}; + +} \ No newline at end of file diff --git a/fe/src/main/java/org/apache/doris/plugin/Plugin.java b/fe/src/main/java/org/apache/doris/plugin/Plugin.java new file mode 100644 index 0000000000..4c5d9ec89e --- /dev/null +++ b/fe/src/main/java/org/apache/doris/plugin/Plugin.java @@ -0,0 +1,65 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 org.apache.doris.plugin; + +import java.io.Closeable; +import java.io.IOException; +import java.util.Collections; +import java.util.Map; + +public abstract class Plugin implements Closeable { + public static final int PLUGIN_DEFAULT_FLAGS = 0; + public static final int PLUGIN_NOT_DYNAMIC_INSTALL = 1; + public static final int PLUGIN_NOT_DYNAMIC_UNINSTALL = 2; + public static final int PLUGIN_INSTALL_EARLY = 4; + + /* + * just one constructor + * + * public Plugin() {} + * + * public Plugin(Path installPath) {} + */ + + /** + * invoke when the plugin install + */ + public void init() { } + + /** + * invoke when the plugin uninstall + */ + @Override + public void close() throws IOException { } + + public int flags() { + return PLUGIN_DEFAULT_FLAGS; + } + + public void setVariable(String key, String value) { + + } + + public Map variable() { + return Collections.EMPTY_MAP; + } + + public Map status() { + return Collections.EMPTY_MAP; + } +} diff --git a/fe/src/main/java/org/apache/doris/plugin/PluginManager.java b/fe/src/main/java/org/apache/doris/plugin/PluginManager.java new file mode 100644 index 0000000000..58cc17a433 --- /dev/null +++ b/fe/src/main/java/org/apache/doris/plugin/PluginManager.java @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 org.apache.doris.plugin; + +import java.util.Map; + +import com.google.common.collect.Maps; + +public class PluginManager { + + private final Map[] plugins = new Map[PluginType.MAX_PLUGIN_SIZE]; + + public PluginManager() { + + for (int i = 0; i < plugins.length; i++) { + plugins[i] = Maps.newConcurrentMap(); + } + } + + public void loadPlugin(Plugin plugin) { + + } + + public void unloadPlugin(Plugin plugin) { + + } + + public Plugin getPlugin(String name) { + return null; + } + + public Plugin getPlugin(String name, PluginType type) { + return null; + } +} diff --git a/fe/src/main/java/org/apache/doris/plugin/PluginType.java b/fe/src/main/java/org/apache/doris/plugin/PluginType.java new file mode 100644 index 0000000000..0357d5ec7a --- /dev/null +++ b/fe/src/main/java/org/apache/doris/plugin/PluginType.java @@ -0,0 +1,28 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 org.apache.doris.plugin; + +/** + * Describe the type of plugin + */ +public enum PluginType { + IMPORT, + STORAGE; + + public static int MAX_PLUGIN_SIZE = PluginType.values().length; +}