Add plugin definition (#2351)
This commit is contained in:
75
be/src/plugin/plugin.h
Normal file
75
be/src/plugin/plugin.h
Normal file
@ -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 } \
|
||||
}
|
||||
|
||||
}
|
||||
39
be/src/plugin/plugin_manager.h
Normal file
39
be/src/plugin/plugin_manager.h
Normal file
@ -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 <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#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<std::string, Plugin*> _plugins;
|
||||
};
|
||||
|
||||
}
|
||||
65
fe/src/main/java/org/apache/doris/plugin/Plugin.java
Normal file
65
fe/src/main/java/org/apache/doris/plugin/Plugin.java
Normal file
@ -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<String, String> variable() {
|
||||
return Collections.EMPTY_MAP;
|
||||
}
|
||||
|
||||
public Map<String, String> status() {
|
||||
return Collections.EMPTY_MAP;
|
||||
}
|
||||
}
|
||||
50
fe/src/main/java/org/apache/doris/plugin/PluginManager.java
Normal file
50
fe/src/main/java/org/apache/doris/plugin/PluginManager.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
28
fe/src/main/java/org/apache/doris/plugin/PluginType.java
Normal file
28
fe/src/main/java/org/apache/doris/plugin/PluginType.java
Normal file
@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user