Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
36 changes: 36 additions & 0 deletions exaudfclient/exa_lib_loader.cc
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;
}

5 changes: 5 additions & 0 deletions exaudfclient/exa_lib_loader.h
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);
17 changes: 17 additions & 0 deletions exaudfclient/exa_set_env.cc
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;
}
}
3 changes: 3 additions & 0 deletions exaudfclient/exa_set_env.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void setup_environment();
84 changes: 84 additions & 0 deletions exaudfclient/exa_udf_base.cpp
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) {
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated
// 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) {
Comment thread
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);
Comment thread
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);
}
26 changes: 26 additions & 0 deletions exaudfclient/exa_udf_base.h
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;
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated

bool validate_arguments(int argc, char** argv);
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated
void parse_arguments(int argc, char** argv);
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated
int startClientBase(int argc, char** argv);

protected:
std::string m_socket;
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated
std::string m_languageArg;
bool mb_useCtpgParser = false;
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated
};
16 changes: 16 additions & 0 deletions exaudfclient/exa_udf_clients.cpp
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);
}
Comment thread
sgn4sangar marked this conversation as resolved.
Outdated
15 changes: 15 additions & 0 deletions exaudfclient/exa_udf_clients.h
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;
};
6 changes: 6 additions & 0 deletions exaudfclient/exa_udfclient.cc
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) {
Comment thread
tkilias marked this conversation as resolved.
ExaUdfClient client;
return client.startClientBase(argc, argv);
}
64 changes: 64 additions & 0 deletions exaudfclient/exa_vm_factory.cc
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
Comment thread
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
Comment thread
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
}
4 changes: 4 additions & 0 deletions exaudfclient/exa_vm_factory.h
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);
31 changes: 0 additions & 31 deletions exaudfclient/exaudfclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,46 +78,15 @@ int main(int argc, char **argv) {
std::string libexaudflibPath = string(CUSTOM_LIBEXAUDFLIB_PATH);
#else
std::string libexaudflibPath = ::getenv("LIBEXAUDFLIB_PATH");
//std::string libexaudflibPath="libexaudflib_complete.so";
//std::string libexaudflibPath = std::string(argv[3]);
//std::string libexaudflibPath = std::string("/exaudf/libexaudflib_complete.so");
#endif
#if 1

Lmid_t my_namespace_id;
// DBGMSG(std::cerr, "Load libprotobuf into new namespace");
// DBGVAR(std::cerr, libProtobufPath);
// handle = dlmopen(LM_ID_NEWLM, libProtobufPath.c_str(),RTLD_NOW);
// if (!handle) {
// std::cerr << "Error when dynamically loading libprotobuf: " << dlerror() << endl;
// exit(EXIT_FAILURE);
// }
// if(dlinfo(handle, RTLD_DI_LMID, &my_namespace_id) != 0) {
// cerr << "Error when getting namespace id " << dlerror() << endl;
// exit(EXIT_FAILURE);
// }
DBGMSG(cerr, "Load libexaudflib");
DBGVAR(cerr, libexaudflibPath);
handle = dlmopen(LM_ID_NEWLM, libexaudflibPath.c_str(), RTLD_NOW);
// handle = dlopen(libexaudflibPath.c_str(), RTLD_NOW);

if (!handle) {
fprintf(stderr, "dmlopen: %s\n", dlerror());
exit(EXIT_FAILURE);
}
#else
handle = dlopen(libProtobufPath.c_str(),RTLD_NOW|RTLD_GLOBAL);
if (!handle) {
cerr << "Error when dynamically loading libprotobuf: " << dlerror() << endl;
exit(EXIT_FAILURE);
}
handle = dlopen("/exaudf/libexaudflib.so",RTLD_NOW);
if (!handle) {
fprintf(stderr, "dlopen: %s\n", dlerror());
exit(EXIT_FAILURE);
}
#endif


MAIN_FUN exaudfclient_main = (MAIN_FUN)load_dynamic("exaudfclient_main");
VOID_FUN_WITH_SWIGVM_PARAMS_P set_SWIGVM_params = (VOID_FUN_WITH_SWIGVM_PARAMS_P)load_dynamic("set_SWIGVM_params");
Expand Down
Loading