-
Notifications
You must be signed in to change notification settings - Fork 14
#1456: Cleaned up and refactored exaudfclient cc #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sgn4sangar
wants to merge
13
commits into
master
Choose a base branch
from
refactoring/1456_cleanup_exaudfclient_cc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b563112
removed the commented out and dead codes
sgn4sangar 2d5a777
refactoring phase-1
sgn4sangar ef49152
adding the parse options for java vm
sgn4sangar 5fe2ffd
ah.. one more missing piece
sgn4sangar 2e800a6
reorganizing as per comments
sgn4sangar 6142c75
Merge branch 'master' into refactoring/1456_cleanup_exaudfclient_cc
sgn4sangar 35b72a7
no more individual lang based subclass
sgn4sangar 0748c70
updating all the recent comments
sgn4sangar e5ad9af
reorganized files and updated bazel script
sgn4sangar bbb9931
including the load_dynamic
sgn4sangar d6a441d
updating the BUILD script
sgn4sangar 64e5554
ci: retrigger tests
sgn4sangar a98a198
making the exaudflib_handle static
sgn4sangar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #include <iostream> | ||
| #include <string> | ||
| #include <sstream> | ||
| #include <dlfcn.h> | ||
| #include <dlfcn.h> | ||
|
|
||
| #include "exa_lib_loader.h" | ||
| #include "utils/debug_message.h" | ||
|
|
||
| void* exa_load_libary(const std::string& stdLibPath) { | ||
| if (stdLibPath.empty()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| void* handle = dlmopen(LM_ID_NEWLM, stdLibPath.c_str(), RTLD_NOW); | ||
| if (!handle) { | ||
| std::cerr << "dlmopen error: " << dlerror() << "; while loading " << stdLibPath << std::endl; | ||
| return nullptr; | ||
| } | ||
| return handle; | ||
| } | ||
|
|
||
| void* exa_load_symbol(void *handle, const std::string& symbol_name) { | ||
| void *p_res = nullptr; | ||
| char *error = nullptr; | ||
| if(handle) { | ||
| p_res = dlsym(handle, symbol_name.c_str()); | ||
|
|
||
| if((error = dlerror()) != nullptr) { | ||
| std::cerr << "Error when trying to load symbol '" << symbol_name << "': " << error << std::endl; | ||
| return nullptr; | ||
| } | ||
| } | ||
| return p_res; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
| #include <string> | ||
|
|
||
| void* exa_load_libary(const std::string& stdLibPath); | ||
| void* exa_load_symbol(void *handle, const std::string& symbol_name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include <iostream> | ||
| #include <cstdlib> | ||
| #include <cstdio> | ||
| #include <clocale> | ||
| #include <cstring> | ||
| #include <cerrno> | ||
|
|
||
| #include "exa_set_env.h" | ||
|
|
||
| void setup_environment() { | ||
| if (::setenv("HOME", "/tmp", 1) == -1) { | ||
| std::cerr << "Failed setting HOME env var: " << std::strerror(errno) << std::endl; | ||
| } | ||
| if (::setlocale(LC_ALL, "en_US.utf8") == nullptr) { | ||
| std::cerr << "Failed setting locale: " << std::strerror(errno) << std::endl; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| void setup_environment(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #include <iostream> | ||
| #include <cstring> | ||
| #include <cstdlib> | ||
| #include <string> | ||
|
|
||
| #include "exaudf_lib_output_path.h" | ||
| #include "vm/swig_vm.h" | ||
| #include "exa_udf_base.h" | ||
| #include "exa_lib_loader.h" | ||
| #include "exa_set_env.h" | ||
| #include "utils/debug_message.h" | ||
|
|
||
|
|
||
| void ExaUdfClientBase::parse_arguments(int argc, char** argv) { | ||
| // Now assumption is that all cmd line aguments are already validated. | ||
| m_socket = argv[1]; | ||
| m_languageArg = argv[2]; | ||
|
|
||
| mb_useCtpgParser = false; | ||
| const char* env_val = ::getenv("SCRIPT_OPTIONS_PARSER_VERSION"); | ||
| if(env_val && strcmp(env_val, "2") == 0) { | ||
| mb_useCtpgParser = true; | ||
| } else if(argc == 4) { | ||
| std::string parse_option(argv[3]); | ||
| mb_useCtpgParser = (parse_option.compare("scriptOptionsParserVersion=2") == 0); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| bool ExaUdfClientBase::validate_arguments(int argc, char** argv) { | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
| if (argc < 3 || argc > 4) { | ||
| usage(argv[0]); | ||
| return false; | ||
| } | ||
|
|
||
| if (argc == 4 && | ||
| strcmp(argv[3], "scriptOptionsParserVersion=1") != 0 && | ||
| strcmp(argv[3], "scriptOptionsParserVersion=2") != 0) { | ||
| usage(argv[0]); | ||
| return false; | ||
| } | ||
|
|
||
| if (!((strcmp(argv[2], "lang=python") == 0) | ||
| || (strcmp(argv[2], "lang=java") == 0) | ||
| || (strcmp(argv[2], "lang=streaming") == 0) | ||
| || (strcmp(argv[2], "lang=benchmark") == 0))) { | ||
| usage(argv[0]); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| int ExaUdfClientBase::startClientBase(int argc, char** argv) { | ||
| if (!validate_arguments(argc, argv)) { | ||
| usage(argv[0]); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
| parse_arguments(argc, argv); | ||
|
|
||
| std::string libexaudflibPath; | ||
| #ifdef CUSTOM_LIBEXAUDFLIB_PATH | ||
| libexaudflibPath = std::string(CUSTOM_LIBEXAUDFLIB_PATH); | ||
| #else | ||
| libexaudflibPath = std::string(::getenv("LIBEXAUDFLIB_PATH")); | ||
| #endif | ||
| DBGMSG(std::cerr, "Load libexaudflib"); | ||
| DBGVAR(std::cerr, libexaudflibPath); | ||
| void* handle = exa_load_libary(libexaudflibPath); | ||
| if (!handle) { | ||
| std::cerr << "Failed to load library: " << libexaudflibPath << std::endl; | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
||
| MAIN_FUN exaudfclient_main = (MAIN_FUN)exa_load_symbol(handle, "exaudfclient_main"); | ||
| SET_SWIGVM_PARAMS set_SWIGVM_params = (SET_SWIGVM_PARAMS)exa_load_symbol(handle, "set_SWIGVM_params"); | ||
|
|
||
| setup_environment(); | ||
| std::function<SWIGVMContainers::SWIGVM*()> vmMaker = create_vm(m_languageArg, mb_useCtpgParser); | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
|
|
||
| SWIGVMContainers::SWIGVM_params = new SWIGVM_params_t(true); | ||
| set_SWIGVM_params(SWIGVMContainers::SWIGVM_params); | ||
| return exaudfclient_main(vmMaker, argc, argv); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
| #include <functional> | ||
| #include <string> | ||
|
|
||
| #include "vm/swig_vm.h" | ||
|
|
||
| typedef bool (*SET_SWIGVM_PARAMS)(SWIGVM_params_t*); | ||
| typedef int (*MAIN_FUN)(std::function<SWIGVMContainers::SWIGVM*()> vmMaker, int, char**); | ||
|
|
||
| class ExaUdfClientBase { | ||
| public: | ||
| virtual ~ExaUdfClientBase() = default; | ||
| virtual void usage(const std::string& programName) = 0; | ||
| virtual std::function<SWIGVMContainers::SWIGVM*()> create_vm( | ||
| const std::string& languageArg, | ||
| bool useCtpgParser) = 0; | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
|
|
||
| bool validate_arguments(int argc, char** argv); | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
| void parse_arguments(int argc, char** argv); | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
| int startClientBase(int argc, char** argv); | ||
|
|
||
| protected: | ||
| std::string m_socket; | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
| std::string m_languageArg; | ||
| bool mb_useCtpgParser = false; | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
sgn4sangar marked this conversation as resolved.
Outdated
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include <iostream> | ||
|
|
||
| #include "exa_udf_clients.h" | ||
| #include "exa_vm_factory.h" | ||
|
|
||
| void ExaUdfClient::usage(const std::string& programName) { | ||
| std::cerr << "Usage: " << programName | ||
| << " <socket> lang=python|lang=java|lang=streaming|lang=benchmark <scriptOptionsParserVersion=1|2>" | ||
| << std::endl; | ||
| } | ||
|
|
||
| std::function<SWIGVMContainers::SWIGVM*()> ExaUdfClient::create_vm( | ||
| const std::string& languageArg, | ||
| bool useCtpgParser) { | ||
| return ::create_vm(languageArg, useCtpgParser); | ||
| } | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #pragma once | ||
| #include <string> | ||
|
|
||
| #include "exa_udf_base.h" | ||
| #include "vm/swig_vm.h" | ||
|
|
||
| class ExaUdfClient : public ExaUdfClientBase { | ||
| public: | ||
| ~ExaUdfClient() override = default; | ||
|
|
||
| void usage(const std::string& programName) override; | ||
| std::function<SWIGVMContainers::SWIGVM*()> create_vm( | ||
| const std::string& languageArg, | ||
| bool useCtpgParser) override; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #include "exa_udf_clients.h" | ||
|
|
||
| int main(int argc, char **argv) { | ||
|
tkilias marked this conversation as resolved.
|
||
| ExaUdfClient client; | ||
| return client.startClientBase(argc, argv); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #include <functional> | ||
| #include "exa_vm_factory.h" | ||
|
|
||
| #ifdef ENABLE_JAVA_VM | ||
| #include "javacontainer/javacontainer_builder.h" | ||
| #endif //ENABLE_JAVA_VM | ||
|
|
||
| #ifdef ENABLE_PYTHON_VM | ||
| #include "python/pythoncontainer.h" | ||
| #endif //ENABLE_PYTHON_VM | ||
|
|
||
| #ifdef UDF_PLUGIN_CLIENT | ||
| #include "protegrityclient.h" | ||
| #endif //UDF_PLUGIN_CLIENT | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
|
|
||
| #ifdef ENABLE_STREAMING_VM | ||
| #include "streaming_container/streamingcontainer.h" | ||
| #endif | ||
|
|
||
| #ifdef ENABLE_BENCHMARK_VM | ||
| #include "benchmark_container/benchmark_container.h" | ||
| #endif | ||
|
|
||
| std::function<SWIGVMContainers::SWIGVM*()> create_vm(const std::string& argv_lang, bool use_ctpg_options_parser) { | ||
| #ifdef UDF_PLUGIN_CLIENT | ||
| return [](){return new SWIGVMContainers::Protegrity(false);}; | ||
| #else | ||
|
sgn4sangar marked this conversation as resolved.
Outdated
|
||
| if(argv_lang.compare("lang=python") == 0) { | ||
| #ifdef ENABLE_PYTHON_VM | ||
| return []() { return new SWIGVMContainers::PythonVM(false); }; | ||
| #else | ||
| throw SWIGVMContainers::SWIGVM::exception("this exaudfclient has been compilied without Python support"); | ||
| #endif | ||
| } | ||
| else if(argv_lang.compare("lang=java") == 0) { | ||
| #ifdef ENABLE_JAVA_VM | ||
| if (use_ctpg_options_parser) { | ||
| return [&](){return SWIGVMContainers::JavaContainerBuilder().useCtpgParser().build();}; | ||
| } else { | ||
| return [&](){return SWIGVMContainers::JavaContainerBuilder().build();}; | ||
| } | ||
| #else | ||
| throw SWIGVMContainers::SWIGVM::exception("this exaudfclient has been compilied without Java support"); | ||
| #endif | ||
| } | ||
| else if(argv_lang.compare("lang=streaming") == 0) { | ||
| #ifdef ENABLE_STREAMING_VM | ||
| return []() { return new SWIGVMContainers::StreamingVM(false); }; | ||
| #else | ||
| throw SWIGVMContainers::SWIGVM::exception("this exaudfclient has been compilied without Streaming support"); | ||
| #endif | ||
| } | ||
| else if(argv_lang.compare("lang=benchmark") == 0) { | ||
| #ifdef ENABLE_BENCHMARK_VM | ||
| return []() { return new SWIGVMContainers::BenchmarkVM(false); }; | ||
| #else | ||
| throw SWIGVMContainers::SWIGVM::exception("this exaudfclient has been compilied without Benchmark support"); | ||
| #endif | ||
| } | ||
| else { | ||
| throw SWIGVMContainers::SWIGVM::exception("unsupported language specified in argv"); | ||
| } | ||
| #endif | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #pragma once | ||
| #include "vm/swig_vm.h" | ||
|
|
||
| std::function<SWIGVMContainers::SWIGVM*()> create_vm(const std::string& argv_lang, bool use_ctpg_options_parser); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.