java: add Java and C++ source files
PATCH 1/3 java: add Java and C++ source files
This adds all of the Java and C++ source files that make up the libcephfs Java wrappers package.
--- src/java/README | 43 + src/java/build.xml | 67 ++ .../java/net/newdream/ceph/fs/CephConstants.java | 38 + .../java/net/newdream/ceph/fs/CephDirectory.java | 84 ++ .../java/net/newdream/ceph/fs/CephException.java | 21 + .../ceph/fs/CephInvalidStateException.java | 11 + src/java/java/net/newdream/ceph/fs/CephMount.java | 360 +++++++ .../net/newdream/ceph/fs/CephNativeLoader.java | 16 + src/java/java/net/newdream/ceph/fs/CephProxy.java | 217 ++++ src/java/java/net/newdream/ceph/fs/CephStat.java | 15 + .../java/net/newdream/ceph/fs/CephStatVFS.java | 14 + src/java/java/net/newdream/ceph/fs/CephStruct.java | 33 + src/java/native/libcephfs_jni.cc | 1037 ++++++++++++++++++++ src/java/test/CephMountCreateTest.java | 76 ++ src/java/test/CephMountTest.java | 72 ++ 15 files changed, 2104 insertions(+), 0 deletions(-) create mode 100644 src/java/README create mode 100644 src/java/build.xml create mode 100644 src/java/java/net/newdream/ceph/fs/CephConstants.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephDirectory.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephException.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephInvalidStateException.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephMount.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephNativeLoader.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephProxy.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephStat.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephStatVFS.java create mode 100644 src/java/java/net/newdream/ceph/fs/CephStruct.java create mode 100644 src/java/native/libcephfs_jni.cc create mode 100644 src/java/test/CephMountCreateTest.java create mode 100644 src/java/test/CephMountTest.java
src/java/README new file +43 -0
@@ -0,0 +1,43 @@ +libcephfs Java wrappers +======================= + +- native/: C++ +- java/: Java +- test/: JUnit tests +- lib/: JUnit library +- build.xml: Test runner + +Building +-------- + +Autotools handles the build using the configure flag --enable-cephfs-java + +Testing +------- + +Testing depends on JUnit. To run the tests make sure that the JUnit JAR is +available in the lib/ directory. For example: + + $ mkdir lib + $ cd lib + $ curl -O https://github.com/downloads/KentBeck/junit/junit-4.8.2.jar + +Ant is used to run the unit tests: + + $ ant test + +1. The tests depend on the compiled wrappers. If the wrappers are installed as +part of a package (e.g. Debian package) then this should 'just work'. Ant will +also look in the current directory for 'libcephfs.jar' and in ../.libs for the +JNI library. If all else fails, set the environment variables CEPHFS_JAR, and +CEPHFS_JNI_LIB accordingly. + +2. Set CEPHFS_CONF environment variable to point to a ceph.conf. This can be +ommitted if the desired configuration file can be found in a default location. + +Documentation +------------- + +Ant is used to build the Javadocs: + + $ ant docs
src/java/build.xml new file +67 -0
67 lines not on this page · raw message
src/java/java/net/newdream/ceph/fs/CephConstants.java new file +38 -0
@@ -0,0 +1,38 @@ +package net.newdream.ceph.fs; + +public class CephConstants { + + /* + * The constants here are initialized from JNI. + */ + static { + CephNativeLoader.checkLoaded(); + } + + /* lseek */ + public static int SEEK_SET; + public static int SEEK_CUR; + public static int SEEK_END; + + /* open */ + public static int O_RDONLY; + public static int O_RDWR; + public static int O_APPEND; + public static int O_CREAT; + public static int O_TRUNC; + public static int O_EXCL; + + /* setattr */ + public static int SETATTR_MODE; + public static int SETATTR_UID; + public static int SETATTR_GID; + public static int SETATTR_MTIME; + public static int SETATTR_ATIME; + + /* errno */ + public static int EINVAL; + public static int ENOENT; + public static int EEXIST; + public static int ERANGE; + public static int ENAMETOOLONG; +}
src/java/java/net/newdream/ceph/fs/CephDirectory.java new file +84 -0
84 lines not on this page · raw message
src/java/java/net/newdream/ceph/fs/CephException.java new file +21 -0
@@ -0,0 +1,21 @@ +package net.newdream.ceph.fs; + +/** + * Class that represents generic Ceph exception. + */ +public class CephException extends Exception { + + /** + * Create basic CephException. + */ + public CephException() { + super(); + } + + /** + * Create CephException with message. + */ + public CephException(String s) { + super(s); + } +}
src/java/java/net/newdream/ceph/fs/CephInvalidStateException.java new file +11 -0
@@ -0,0 +1,11 @@ +package net.newdream.ceph.fs; + +/** + * Represents invalid use of low-level Ceph pointers. + */ +public class CephInvalidStateException extends CephException { + + public CephInvalidStateException(String m) { + super(m); + } +}
src/java/java/net/newdream/ceph/fs/CephMount.java new file +360 -0
360 lines not on this page · raw message
src/java/java/net/newdream/ceph/fs/CephNativeLoader.java new file +16 -0
@@ -0,0 +1,16 @@ +package net.newdream.ceph.fs; + +class CephNativeLoader { + + private static boolean loaded = false; + + static { + if (!loaded) { + System.loadLibrary("cephfs_jni"); + CephProxy.native_initialize(); + loaded = true; + } + } + + static void checkLoaded() { assert(loaded); } +}
src/java/java/net/newdream/ceph/fs/CephProxy.java new file +217 -0
217 lines not on this page · raw message
src/java/java/net/newdream/ceph/fs/CephStat.java new file +15 -0
@@ -0,0 +1,15 @@ +package net.newdream.ceph.fs; + +/** + * Holds struct stat fields. + */ +public class CephStat { + int mode; + int uid; + int gid; + long size; + long blksize; + long blocks; + long a_time; + long m_time; +}
src/java/java/net/newdream/ceph/fs/CephStatVFS.java new file +14 -0
@@ -0,0 +1,14 @@ +package net.newdream.ceph.fs; + +/** + * Holds struct statvfs fields. + */ +public class CephStatVFS { + long bsize; + long frsize; + long blocks; + long bavail; + long files; + long fsid; + long namemax; +}
src/java/java/net/newdream/ceph/fs/CephStruct.java new file +33 -0
@@ -0,0 +1,33 @@ +package net.newdream.ceph.fs; + +/** + * Basic handling of low-level Ceph structs. + * + * - Enforces state + * - Holds JNI C pointer (to be implemented) + */ +abstract class CephStruct<T extends Enum<T>> { + private T state; + + CephStruct(T initState) { + state = initState; + } + + void setState(T state) { + this.state = state; + } + + void requireState(T ... states) throws CephException { + for (int i = 0; i < states.length; i++) { + if (this.state == states[i]) + return; + } + String msg = "valid state(s):"; + for (int i = 0; i < states.length; i++) { + msg += " " + states[i].name(); + if (i < (states.length-1)) + msg += ","; + } + throw new CephInvalidStateException(msg); + } +}
src/java/native/libcephfs_jni.cc new file +1037 -0
1,037 lines not on this page · raw message
src/java/test/CephMountCreateTest.java new file +76 -0
76 lines not on this page · raw message
src/java/test/CephMountTest.java new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Quoted 2 lines · Noah Watkins
This adds all of the Java and C++ source files that make up the libcephfs Java wrappers package.
...
Quoted 2 lines
+2. Set
CEPHFS_CONFenvironment variable to point to a ceph.conf. This can be +ommitted if the desired configuration file can be found in a default location.
Simple typo, "omitted".
Quoted 1 line
+package net.newdream.ceph.fs;
I think com.ceph.fs would be a smaller punishment on the programmers using this, and we have that domain name.
Quoted 1 line
src/java/test/CephMountCreateTest.java +0
-0
...
Quoted 5 lines
+ * This tests the mount root dir functionality. It creates an empty
+ * directory in the real root, then it re-mounts the file system
+ * with the empty directory specified as the root. Assertions are
+ * that the "/" in the normal mount is non-empty, and that "/" is
+ * empty in the mount with the empty directory as the root.
So the JUnit tests require a functional ceph cluster to run. Can you state that explicitly in the source/docs, please?
I did not dig deep, and I'm no Java expert, but more client-side support is exciting stuff!
bad fsid
I recreated the file system and got this on the client until it was rebooted.
Is there a step I missed?
Quoted 1 line
libceph: bad fsid, had 02f7ef57-25e0-475f-8948-5c562a4d370c got 6089a28f-8ff4-42f5-8825-1a929f5770bd
Re: bad fsid
Quoted 7 lines · Matt Weil
I recreated the file system and got this on the client until it was rebooted.
Is there a step I missed?
Quoted 2 lines
libceph: bad fsid, had 02f7ef57-25e0-475f-8948-5c562a4d370c got 6089a28f-8ff4-42f5-8825-1a929f5770bd
Sounds like you had the client in continuous operation even when you deleted the previous cephfs and created a new one -- the client doesn't know that that happened, and was warning about an unexpected destination.
If you destroy & recreate your whole cluster, you need to restart clients too. Neatest way would be to have the client apps be down during the fs recreate, otherwise you will get these log messages.
Quoted 9 lines · Tommi Virtanen
Quoted 1 line · Noah Watkins
Simple typo, "omitted".
Quoted 1 line
+package net.newdream.ceph.fs;
I think com.ceph.fs would be a smaller punishment on the programmers using this, and we have that domain name.
I took care of these--good timing with the com.ceph.fs rename.
Quoted 6 lines
src/java/test/CephMountCreateTest.java
Quoted 2 lines
src/java/test/CephMountCreateTest.java +0
-0...
So the JUnit tests require a functional ceph cluster to run. Can you state that explicitly in the source/docs, please?
Yes, I'll make this clear in the source and docs. Is there currently a mechanism available for testing libcephfs w/o a functional cluster? If so it would probably be feasible to adapt the same techniques to the Java library.
Thanks,
Noah
Quoted 3 lines · Noah Watkins
Quoted 2 lines
So the JUnit tests require a functional ceph cluster to run. Can you state that explicitly in the source/docs, please?
Yes, I'll make this clear in the source and docs. Is there currently a mechanism available for testing libcephfs w/o a functional cluster? If so it would probably be feasible to adapt the same techniques to the Java library.
No, I don't think there is. Something in the spirit of to src/vstart.sh might be the best way forward, or just a thing that launches a vm and uses chef to install ceph using the cookbooks. vstart itself has a lot of historical baggage.