Skip to content

Commit

Permalink
Improve JNI building process and include only required dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mrow4a committed Feb 19, 2019
1 parent 79d0b6d commit 3f4d7cf
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 61 deletions.
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ stages:
variables:
MAVEN_OPTS: "-Xmx2g -XX:ReservedCodeCacheSize=512m"
JAVA_VERSION_MAJOR: "7"
XROOT_CLIENT_VERSION: "4.8.4-c201f"
LCG_VIEW: "LCG_94"
LCG_VERSION: "x86_64-centos7-gcc7-opt"

Expand All @@ -26,7 +27,7 @@ build-docker-image:
DOCKER_FILE: Dockerfile
TO: ${CI_REGISTRY_IMAGE}/base:latest

make-compile-test-step:
make-compile-test-step-centos:
<<: *krbtgt
stage: build
script:
Expand All @@ -48,11 +49,10 @@ make-compile-test-step-cvmfs:
# Prepare build environment
- yum install -y which HEP_OSlibs
- source /cvmfs/sft.cern.ch/lcg/views/$LCG_VIEW/$LCG_VERSION/setup.sh
- SYSLIB_OPTION="-L/cvmfs/sft.cern.ch/lcg/views/$LCG_VIEW/$LCG_VERSION/lib64"
- INCLUDE_PATH="/cvmfs/sft.cern.ch/lcg/views/$LCG_VIEW/$LCG_VERSION/include"
- XROOTD_LIB64_PATH="/cvmfs/sft.cern.ch/lcg/releases/xrootd/$XROOT_CLIENT_VERSION/$LCG_VERSION/lib64"
- XROOTD_INCLUDE_PATH="/cvmfs/sft.cern.ch/lcg/views/$LCG_VIEW/$LCG_VERSION/include/xrootd"
# Make compile and test
- MAVEN_FLAGS="-Dinclude.path=${INCLUDE_PATH} -Dxrootd.include.path=${XROOTD_INCLUDE_PATH} -Dsyslib.option=${SYSLIB_OPTION}" make all
- MAVEN_FLAGS="-Dxrootd.lib64.path=${XROOTD_LIB64_PATH} -Dxrootd.include.path=${XROOTD_INCLUDE_PATH}" make all
# Final rename
- for f in *.jar; do mv "${f}" "${f%-jar-with-dependencies.jar}-${LCG_VERSION}.jar"; done
artifacts:
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Must be specified in HADOOP_CONF_DIR in core-site.xml - ref https://github.com/d
Prerequisites:

```
- xrootd-client, xrootd-client-libs, xrootd-client-devel
- xrootd-client, xrootd-client-libs, xrootd-client-devel (tested with 4.8.4>)
- maven
```

Expand All @@ -38,8 +38,8 @@ make package

NOTES:

Since hadoop-xrootd-connector relies on NAR packaging (`.so` dependency for C++ `xrootd-client`), currently
it requires to build connector with correct platform `linux` and `gcc` version to avoid error below:
Since hadoop-xrootd-connector relies on `.so` dependency for C++ `xrootd-client`, currently
it requires to build connector with correct platform `linux` and `gcc` version to avoid error below:

```
java: symbol lookup error: /tmp/libhadoop-xrootd-1.0.0-SNAPSHOT9131106165051975528.so: undefined symbol: _ZN5XrdCl3URLC1ERKSs
Expand All @@ -49,7 +49,7 @@ Build with correct versions e.g. on `lxplus-cloud`:

```
source /cvmfs/sft.cern.ch/lcg/views/LCG_93/x86_64-slc6-gcc62-opt/setup.sh
make package
mvn clean package -X -Dxrootd.lib64.path=${XROOTD_LIB64_SO_FILES_PATH} -Dxrootd.include.path=${XROOTD_INCLUDE_HH_FILES_PATH}
```

CI generates jars for using the connector with CVMFS sourced software. The jars including the dependencies are published at `s3://binaries/hadoop-xrootd`.
Expand Down Expand Up @@ -77,8 +77,11 @@ $ make package
Manual quick test with debug mode

```
# Optionaly enable debug mode
# Optionaly enable debug mode for JAVA
$ export HADOOP_XROOTD_DEBUG=1
# Optionaly enable debug mode for XROOTD Client C++ library
$ export Xrd_debug=1
# Add to Hadoop Classpath (Spark Driver or Executor extra classpath - spark.driver.extraClassPath)
$ VERSION=$(mvn help:evaluate -Dexpression=project.version $@ 2>/dev/null\
Expand Down
8 changes: 4 additions & 4 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
MAVEN_PROFILE=standalone

all: package test

package:
mvn package -DskipTests $(MAVEN_FLAGS)
all: clean package test

clean:
mvn clean
rm -f *.jar

package:
mvn package -DskipTests $(MAVEN_FLAGS)

test:
set -e ;\
export HADOOP_CLASSPATH="${PWD}/*:$(hadoop classpath)";\
Expand Down
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.cern.eos</groupId>
<version>1.0.0</version>
<version>1.0.1</version>
<artifactId>hadoop-xrootd</artifactId>
<packaging>nar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<syslib.option></syslib.option>
<xrootd.lib64.path>/usr/lib64</xrootd.lib64.path>
<xrootd.include.path>/usr/include/xrootd</xrootd.include.path>
<include.path>/usr/include</include.path>
</properties>

<dependencies>
Expand Down Expand Up @@ -48,7 +47,7 @@
<linker>
<options>
<!-- This is needed for final assembly of .so -->
<option>${syslib.option}</option>
<option>-L${xrootd.lib64.path}</option>
</options>
<sysLibs>
<sysLib>
Expand All @@ -71,7 +70,6 @@
<cpp>
<!-- This are header files required by xrootd-connector cpp classes -->
<systemIncludePaths>
<systemIncludePath>${include.path}</systemIncludePath>
<systemIncludePath>${xrootd.include.path}</systemIncludePath>
</systemIncludePaths>
</cpp>
Expand Down
9 changes: 5 additions & 4 deletions src/main/cpp/ch_cern_eos_XRootDClFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include "stdlib.h"

#include "ch_cern_eos_XRootDClFile.h"
#include "xrootd/XrdCl/XrdClFile.hh"
#include "xrootd/XrdCl/XrdClDefaultEnv.hh"
#include "XrdCl/XrdClFile.hh"
#include "XrdCl/XrdClDefaultEnv.hh"

int Xrd_debug = 0;

Expand Down Expand Up @@ -127,7 +127,7 @@ extern "C" {

long code = *(long *) &status;
if (Xrd_debug || status.status != 0)
printf("XrdClFile.Read %ld return 0x%x status %s\n", handle, code, status.ToStr().c_str());
printf("XrdClFile.Read %ld return 0x%li status %s\n", handle, code, status.ToStr().c_str());

return -code;
};
Expand Down Expand Up @@ -171,7 +171,8 @@ extern "C" {
XrdCl::XRootDStatus status = file->Close(timeout);
if (Xrd_debug || status.status != 0)
std::cout << "closeFile " << handle << ": status " << status.ToString() << "\n";
/* delete file; /* No: this will be handled through "dispose" of the java object */

/* delete file will be handled through "dispose" of the java object */

return *(jlong *) &status;
};
Expand Down
57 changes: 29 additions & 28 deletions src/main/cpp/ch_cern_eos_XRootDFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <stdio.h>

#include "ch_cern_eos_XRootDClFile.h"
#include "xrootd/XrdCl/XrdClFile.hh"
#include "xrootd/XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClFile.hh"
#include "XrdCl/XrdClFileSystem.hh"
#include "ch_cern_eos_XRootDFileSystem.h"

#ifdef __cplusplus
Expand All @@ -31,7 +31,7 @@ extern "C" {
#define ch_cern_eos_XRootDKrb5FileSystem_SHUTDOWN_HOOK_PRIORITY 10L


int EOS_debug = 0;
int Hadoop_Xrd_debug = 0;

/*
* Class: ch_cern_eos_XRootDFileSystem
Expand All @@ -45,10 +45,10 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_initFileSystem (JNIEnv
std::string urlS(urlstr);
XrdCl::URL url(urlS);

char *dd = getenv("EOS_debug");
if (dd) EOS_debug = 1;
char *dd = getenv("Xrd_debug");
if (dd) Hadoop_Xrd_debug = 1;

if (EOS_debug) {
if (Hadoop_Xrd_debug) {
std::cout << "initFileSystem urlS " << urlS << "\n";
std::cout << "initFileSystem url " << url.GetURL() << "\n";
}
Expand All @@ -69,7 +69,7 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_initFileSystem (JNIEnv
JNIEXPORT jobject JNICALL Java_ch_cern_eos_XRootDFileSystem_getFileStatusS (JNIEnv *env, jobject This, jlong handle, jstring url_p, jobject path) {
XrdCl::FileSystem *fs = (XrdCl::FileSystem *) handle;
const char *fn = env->GetStringUTFChars(url_p, 0);
if (EOS_debug) {
if (Hadoop_Xrd_debug) {
std::cout << "getFileStatusS fs handle " << handle << "\n";
printf("getFileStatusS: '%s'\n", fn);
}
Expand All @@ -81,23 +81,23 @@ JNIEXPORT jobject JNICALL Java_ch_cern_eos_XRootDFileSystem_getFileStatusS (JNIE

env->ReleaseStringUTFChars(url_p, fn);

if (EOS_debug) std::cout << "getFileStatusS: status" << status.ToString() << "\n";
if (Hadoop_Xrd_debug) std::cout << "getFileStatusS: status" << status.ToString() << "\n";

if (status.status != 0) return NULL;

if (EOS_debug) std::cout << resp->TestFlags(resp->IsDir) << " " << resp->GetSize() << " " << resp->GetModTime() << "\n";
if (Hadoop_Xrd_debug) std::cout << resp->TestFlags(resp->IsDir) << " " << resp->GetSize() << " " << resp->GetModTime() << "\n";

jclass cls = env->FindClass("org/apache/hadoop/fs/FileStatus");
jmethodID methodID = env->GetMethodID(cls, "<init>", "(JZIJJLorg/apache/hadoop/fs/Path;)V");

if (EOS_debug) {
if (Hadoop_Xrd_debug) {
std::cout << "cls " << cls << "\n";
std::cout << "methodID " << methodID << "\n";
}

jobject st = env->NewObject(cls, methodID, resp->GetSize(), resp->TestFlags(resp->IsDir), 1, 256*1024L, resp->GetModTime()*1000, path );

if (EOS_debug) std::cout << "st " << *(long *) &st << "\n";
if (Hadoop_Xrd_debug) std::cout << "st " << *(long *) &st << "\n";

return st;

Expand All @@ -111,7 +111,7 @@ JNIEXPORT jobject JNICALL Java_ch_cern_eos_XRootDFileSystem_getFileStatusS (JNIE
JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_Rm (JNIEnv *env, jobject This, jlong handle, jstring fn_p) {
XrdCl::FileSystem *fs = (XrdCl::FileSystem *) handle;
const char *fn = env->GetStringUTFChars(fn_p, 0);
if (EOS_debug) {
if (Hadoop_Xrd_debug) {
std::cout << "Rm fs handle " << handle << "\n";
printf("delete: '%s'\n", fn);
}
Expand All @@ -122,13 +122,13 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_Rm (JNIEnv *env, jobje

#if 0
if (status.status == 1 && status.code == 400 && status.errNo == 3016) {
if (EOS_debug)
std::cout << "retry RmDir " << status.status <<" "<<status.code<<" "<<status.errNo<< "\n";
if (Hadoop_Xrd_debug)
std::cout << "retry RmDir " << status.status <<" "<<status.code<<" "<<status.errNo<< "\n";
status = fs->RmDir(fn, timeout);
}
#endif

if (EOS_debug)
if (Hadoop_Xrd_debug)
std::cout << "Rm " << fn << " " << handle << ": status " <<status.status<<" "<<status.code<<" "<<status.errNo<<" "<< status.ToString() << "\n";
env->ReleaseStringUTFChars(fn_p, fn);

Expand All @@ -145,7 +145,7 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_RmDir (JNIEnv *env, jo

XrdCl::FileSystem *fs = (XrdCl::FileSystem *) handle;
const char *fn = env->GetStringUTFChars(fn_p, 0);
if (EOS_debug) {
if (Hadoop_Xrd_debug) {
std::cout << "RmDir fs handle " << handle << "\n";
printf("delete: '%s'\n", fn);
}
Expand All @@ -154,7 +154,7 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_RmDir (JNIEnv *env, jo

XrdCl::XRootDStatus status = fs->RmDir(fn, timeout);

if (EOS_debug) std::cout << "RmDir " << fn << " " << handle << ": status " << status.ToString() << "\n";
if (Hadoop_Xrd_debug) std::cout << "RmDir " << fn << " " << handle << ": status " << status.ToString() << "\n";
env->ReleaseStringUTFChars(fn_p, fn);

return *(jlong *) &status;
Expand All @@ -175,9 +175,9 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_Mv (JNIEnv *env, jobje
XrdCl::XRootDStatus status = fs->Mv(src, dst, timeout);
env->ReleaseStringUTFChars(src_p, src);
env->ReleaseStringUTFChars(dst_p, dst);
if (EOS_debug) {
if (Hadoop_Xrd_debug) {
std::cout << "Mv fs handle " << handle << "\n";
printf("rename '%s' '%s' status = 0x%x\n", src, dst, status.ToString().c_str());
printf("rename '%s' '%s' status = 0x%s\n", src, dst, status.ToString().c_str());
}


Expand All @@ -195,13 +195,13 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_MkDir (JNIEnv *env, jo
uint16_t timeout = 0;

XrdCl::Access::Mode mode = static_cast<XrdCl::Access::Mode>(mode_p);
if (EOS_debug)
if (Hadoop_Xrd_debug)
std::cout << "MkDir mode " << mode << "\n";


XrdCl::XRootDStatus status = fs->MkDir(dirname, XrdCl::MkDirFlags::MakePath, mode, timeout);
if (EOS_debug) {
printf("mkdir handle %d '%s' mode 0%o status = 0x%x %s\n", handle, dirname, mode, status.ToString().c_str());
if (Hadoop_Xrd_debug) {
printf("mkdir handle %li '%s' mode 0%o status = 0x%s\n", handle, dirname, mode, status.ToString().c_str());
}
env->ReleaseStringUTFChars(dirname_p, dirname);

Expand All @@ -219,7 +219,7 @@ JNIEXPORT jobjectArray JNICALL Java_ch_cern_eos_XRootDFileSystem_listFileStatusS

XrdCl::FileSystem *fs = (XrdCl::FileSystem *) handle;
const char *fn = env->GetStringUTFChars(url_p, 0);
if (EOS_debug) {
if (Hadoop_Xrd_debug) {
std::cout << "listFileStatusS fs handle " << handle << "\n";
printf("listFileStatusS: '%s'\n", fn);
}
Expand All @@ -237,7 +237,7 @@ JNIEXPORT jobjectArray JNICALL Java_ch_cern_eos_XRootDFileSystem_listFileStatusS
else
numEntries = 0;

if (EOS_debug) printf("listFileStatusS: found %d entries\n", numEntries);
if (Hadoop_Xrd_debug) printf("listFileStatusS: found %d entries\n", numEntries);


jclass cls_FileStatus = env->FindClass("org/apache/hadoop/fs/FileStatus");
Expand All @@ -250,7 +250,7 @@ JNIEXPORT jobjectArray JNICALL Java_ch_cern_eos_XRootDFileSystem_listFileStatusS
for (int i=0; i < numEntries; i++) {
XrdCl::StatInfo *si = list->At(i)->GetStatInfo();
std::string name = list->At(i)->GetName();
if (EOS_debug) printf("listFileStatusS entry %d: %s\n", i, name.c_str());
if (Hadoop_Xrd_debug) printf("listFileStatusS entry %d: %s\n", i, name.c_str());

jstring j_name = env->NewStringUTF(name.c_str());
jobject path = env->NewObject(cls_Path, mid_Pathinit, pp, j_name);
Expand Down Expand Up @@ -279,6 +279,7 @@ JNIEXPORT void JNICALL Java_ch_cern_eos_XRootDFileSystem_setenv (JNIEnv *env, jc
const char *ccv = env->GetStringUTFChars(ccv_p, 0);

int code = setenv((char *) ccn, ccv, 1);
if (Hadoop_Xrd_debug) printf("setenv status: %d\n", code);

env->ReleaseStringUTFChars(ccn_p, ccn);
env->ReleaseStringUTFChars(ccv_p, ccv);
Expand Down Expand Up @@ -333,9 +334,9 @@ JNIEXPORT jlong JNICALL Java_ch_cern_eos_XRootDFileSystem_Prepare (JNIEnv *env,
uint16_t timeout = 0;
XrdCl::Buffer *buf = NULL;
XrdCl::XRootDStatus status = fs->Prepare(fileList, pFlags, 0, buf, timeout);
if (EOS_debug || !status.IsOK()) {
std::cout << "Prepare fs handle " << handle << " flags " << pFlags << " resp " << buf << "\n";
printf("Prepare '%s'... (%d) status = %s\n", fileList.at(0).c_str(), fileList.size(), status.ToStr().c_str());
if (Hadoop_Xrd_debug || !status.IsOK()) {
std::cout << "Prepare fs handle " << handle << " flags " << pFlags << " resp " << buf << "\n";
printf("Prepare '%s'... (%li) status = %s\n", fileList.at(0).c_str(), fileList.size(), status.ToStr().c_str());
}
// The following should not be needed because "std::vector" takes care of it
// for (i = 0; i < numUris; i++) delete fileList[i];
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/ch/cern/eos/Krb5TokenRenewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@

public class Krb5TokenRenewer extends TokenRenewer {
public String krb5ccname;
private DebugLogger eosDebugLogger = new DebugLogger(false);
private static DebugLogger eosDebugLogger;

public Krb5TokenRenewer() {
// FIXME: This should be enabled with logger property, not by env
eosDebugLogger = new DebugLogger(System.getenv("HADOOP_XROOTD_DEBUG") != null);
}

public boolean handleKind(Text kind) {
return Krb5TokenIdentifier.KIND_NAME.equals(kind);
Expand All @@ -46,9 +51,6 @@ public boolean isManaged(Token<?> token) throws IOException {
}

public long renew(Token<?> token, Configuration conf) throws IOException {
// FIXME: This should be enabled with logger property, not by env
String prop_EOS_debug = System.getProperty("HADOOP_XROOTD_DEBUG");
eosDebugLogger.setDebug(((prop_EOS_debug != null) && (prop_EOS_debug.equals("true"))));
byte krb5cc[] = token.getPassword();
int cc_version;

Expand Down Expand Up @@ -174,5 +176,7 @@ public long renew(Token<?> token, Configuration conf) throws IOException {
}

public void cancel(Token<?> token, Configuration conf) throws IOException {
byte krb5cc[] = token.getPassword();
eosDebugLogger.printDebug("cancel: token l=" + krb5cc.length);
}
};
3 changes: 1 addition & 2 deletions src/main/java/ch/cern/eos/XRootDFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public void initialize(URI uri, Configuration conf) throws IOException {
setConf(conf);

// FIXME: This should be enabled with logger property, not by env
String prop_EOS_debug = System.getenv("HADOOP_XROOTD_DEBUG");
eosDebugLogger = new DebugLogger(prop_EOS_debug != null);
eosDebugLogger = new DebugLogger(System.getenv("HADOOP_XROOTD_DEBUG") != null);
XRootDKrb5.setDebug(eosDebugLogger.isDebugEnabled());
this.uri = uri;

Expand Down
Loading

0 comments on commit 3f4d7cf

Please sign in to comment.