Add plugin definition (#2351)

This commit is contained in:
Seaven
2019-12-13 21:38:17 +08:00
committed by ZHAO Chun
parent 02c4edb98e
commit e4cc17599f
5 changed files with 257 additions and 0 deletions

75
be/src/plugin/plugin.h Normal file
View 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 } \
}
}

View 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;
};
}

View 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;
}
}

View 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;
}
}

View 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;
}