2
Copyright (C) 2011- The University of Notre Dame
3
This software is distributed under the GNU General Public License.
4
See the file COPYING for details.
7
#include "hdfs_library.h"
18
#define HDFS_LOAD_FUNC( lval, name ) \
19
hs->lval = dlsym(hs->libhdfs_handle,name); \
21
debug(D_NOTICE|D_HDFS,"couldn't find %s in libhdfs.so",name); \
25
void hdfs_library_close(struct hdfs_library *hs)
27
dlclose(hs->libjvm_handle);
28
dlclose(hs->libhdfs_handle);
32
struct hdfs_library *hdfs_library_open()
34
static int did_warning = 0;
36
if(!getenv("JAVA_HOME") || !getenv("HADOOP_HOME") || !getenv("CLASSPATH") || !getenv("LIBHDFS_PATH") || !getenv("LIBJVM_PATH")) {
38
debug(D_NOTICE | D_HDFS, "Sorry, to use HDFS, you need to set up Java and Hadoop first.\n");
39
debug(D_NOTICE | D_HDFS, "Please set JAVA_HOME and HADOOP_HOME appropriately,\n");
40
debug(D_NOTICE | D_HDFS, "then use chirp_server_hdfs or parrot_run_hdfs as needed.\n");
47
struct hdfs_library *hs = malloc(sizeof(*hs));
49
const char *libjvm_path = getenv("LIBJVM_PATH");
50
hs->libjvm_handle = dlopen(libjvm_path, RTLD_LAZY);
51
if(!hs->libjvm_handle) {
52
debug(D_NOTICE | D_HDFS, "couldn't dlopen LIBJVM_PATH=%s: %s", libjvm_path, dlerror());
58
const char *libhdfs_path = getenv("LIBHDFS_PATH");
59
hs->libhdfs_handle = dlopen(libhdfs_path, RTLD_LAZY);
60
if(!hs->libhdfs_handle) {
61
dlclose(hs->libjvm_handle);
63
debug(D_NOTICE | D_HDFS, "couldn't dlopen LIBHDFS_PATH=%s: %s", dlerror());
68
HDFS_LOAD_FUNC(connect, "hdfsConnect");
69
HDFS_LOAD_FUNC(connect_as_user, "hdfsConnectAsUser");
70
HDFS_LOAD_FUNC(disconnect, "hdfsDisconnect");
71
HDFS_LOAD_FUNC(listdir, "hdfsListDirectory");
72
HDFS_LOAD_FUNC(open, "hdfsOpenFile");
73
HDFS_LOAD_FUNC(close, "hdfsCloseFile");
74
HDFS_LOAD_FUNC(flush, "hdfsFlush");
75
HDFS_LOAD_FUNC(read, "hdfsRead");
76
HDFS_LOAD_FUNC(pread, "hdfsPread");
77
HDFS_LOAD_FUNC(write, "hdfsWrite");
78
HDFS_LOAD_FUNC(exists, "hdfsExists");
79
HDFS_LOAD_FUNC(mkdir, "hdfsCreateDirectory");
80
HDFS_LOAD_FUNC(unlink, "hdfsDelete");
81
HDFS_LOAD_FUNC(rename, "hdfsRename");
82
HDFS_LOAD_FUNC(stat, "hdfsGetPathInfo");
83
HDFS_LOAD_FUNC(free_stat, "hdfsFreeFileInfo");
84
HDFS_LOAD_FUNC(get_hosts, "hdfsGetHosts");
85
HDFS_LOAD_FUNC(free_hosts, "hdfsFreeHosts");
86
HDFS_LOAD_FUNC(get_default_block_size, "hdfsGetDefaultBlockSize");
87
HDFS_LOAD_FUNC(get_capacity, "hdfsGetCapacity");
88
HDFS_LOAD_FUNC(get_used, "hdfsGetUsed");
89
HDFS_LOAD_FUNC(chmod, "hdfsChmod");
90
HDFS_LOAD_FUNC(utime, "hdfsUtime");
91
HDFS_LOAD_FUNC(chdir, "hdfsSetWorkingDirectory");
96
hdfs_library_close(hs);