]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
java: support get pool id/replication interface
authorNoah Watkins <noahwatkins@gmail.com>
Wed, 16 Jan 2013 20:27:16 +0000 (12:27 -0800)
committerNoah Watkins <noahwatkins@gmail.com>
Fri, 18 Jan 2013 18:35:44 +0000 (10:35 -0800)
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/java/Makefile.am
src/java/java/com/ceph/fs/CephMount.java
src/java/java/com/ceph/fs/CephPoolException.java [new file with mode: 0644]
src/java/native/libcephfs_jni.cc
src/java/test/com/ceph/fs/CephMountTest.java
src/java/test/com/ceph/fs/CephUnmountedTest.java

index 788bea2c29b546d3212f229b9808ff469e834e7a..b8ab5f4b3f5386c5fa43b809cae90a0a2461d9d9 100644 (file)
@@ -8,7 +8,8 @@ JAVA_SRC = \
        java/com/ceph/fs/CephNotMountedException.java \
        java/com/ceph/fs/CephFileAlreadyExistsException.java \
        java/com/ceph/fs/CephAlreadyMountedException.java \
-       java/com/ceph/fs/CephNotDirectoryException.java
+       java/com/ceph/fs/CephNotDirectoryException.java \
+       java/com/ceph/fs/CephPoolException.java
 
 JAVA_TEST_SRC = \
   test/com/ceph/fs/CephDoubleMountTest.java \
index 11338585be81a7b5a2f0ecc562ca0cbb1bd02a73..10036f6c7688236a4f5760311fc60e08ce238666 100644 (file)
@@ -899,4 +899,42 @@ public class CephMount {
   }
 
   private static native int native_ceph_get_stripe_unit_granularity(long mountp);
+
+  /**
+   * Get the pool id for the named pool.
+   *
+   * @param name The pool name.
+   * @return The pool id.
+   */
+  public int get_pool_id(String name) throws CephPoolException {
+    rlock.lock();
+    try {
+      return native_ceph_get_pool_id(instance_ptr, name);
+    } catch (FileNotFoundException e) {
+      throw new CephPoolException("pool name " + name + " not found");
+    } finally {
+      rlock.unlock();
+    }
+  }
+
+  private static native int native_ceph_get_pool_id(long mountp, String name) throws FileNotFoundException;
+
+  /**
+   * Get the pool replication factor.
+   *
+   * @param pool_id The pool id.
+   * @return Number of replicas stored in the pool.
+   */
+  public int get_pool_replication(int pool_id) throws CephPoolException {
+    rlock.lock();
+    try {
+      return native_ceph_get_pool_replication(instance_ptr, pool_id);
+    } catch (FileNotFoundException e) {
+      throw new CephPoolException("pool id " + pool_id + " not found");
+    } finally {
+      rlock.unlock();
+    }
+  }
+
+  private static native int native_ceph_get_pool_replication(long mountp, int pool_id) throws FileNotFoundException;
 }
diff --git a/src/java/java/com/ceph/fs/CephPoolException.java b/src/java/java/com/ceph/fs/CephPoolException.java
new file mode 100644 (file)
index 0000000..1bedd44
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package com.ceph.fs;
+
+import java.io.IOException;
+
+/**
+ * Exception related to Ceph pool.
+ */
+public class CephPoolException extends IOException {
+
+  /**
+   * Construct CephPoolException.
+   */
+  public CephPoolException() {
+    super();
+  }
+
+  /**
+   * Construct CephPoolException with message.
+   */
+  public CephPoolException(String s) {
+    super(s);
+  }
+}
index 142cb2a529047205c6a7212f9f3c9a1065baff85..2fef171a976a22173d037b73bcb09a12dbfa9951 100644 (file)
@@ -2434,3 +2434,63 @@ JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1stripe_1uni
 
        return ret;
 }
+
+/*
+ * Class:     com_ceph_fs_CephMount
+ * Method:    native_ceph_get_pool_id
+ * Signature: (JLjava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1pool_1id
+  (JNIEnv *env, jclass clz, jlong j_mntp, jstring jname)
+{
+  struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
+  CephContext *cct = ceph_get_mount_context(cmount);
+  const char *c_name;
+  int ret;
+
+  CHECK_MOUNTED(cmount, -1);
+  CHECK_ARG_NULL(jname, "@name is null", -1);
+
+  c_name = env->GetStringUTFChars(jname, NULL);
+  if (!c_name) {
+    cephThrowInternal(env, "failed to pin memory");
+    return -1;
+  }
+
+  ldout(cct, 10) << "jni: get_pool_id: name " << c_name << dendl;
+
+  ret = ceph_get_pool_id(cmount, c_name);
+  if (ret < 0)
+    handle_error(env, ret);
+
+  ldout(cct, 10) << "jni: get_pool_id: ret " << ret << dendl;
+
+  env->ReleaseStringUTFChars(jname, c_name);
+
+  return ret;
+}
+
+/*
+ * Class:     com_ceph_fs_CephMount
+ * Method:    native_ceph_get_pool_replication
+ * Signature: (JI)I
+ */
+JNIEXPORT jint JNICALL Java_com_ceph_fs_CephMount_native_1ceph_1get_1pool_1replication
+  (JNIEnv *env, jclass clz, jlong j_mntp, jint jpoolid)
+{
+  struct ceph_mount_info *cmount = get_ceph_mount(j_mntp);
+  CephContext *cct = ceph_get_mount_context(cmount);
+  int ret;
+
+  CHECK_MOUNTED(cmount, -1);
+
+  ldout(cct, 10) << "jni: get_pool_replication: poolid " << jpoolid << dendl;
+
+  ret = ceph_get_pool_replication(cmount, jpoolid);
+  if (ret < 0)
+    handle_error(env, ret);
+
+  ldout(cct, 10) << "jni: get_pool_replication: ret " << ret << dendl;
+
+  return ret;
+}
index 0ed74ec4b98b7ce92b0301f2396bb864cefb4947..984c2cb737755e4535a18c43029f132d5176f1ac 100644 (file)
@@ -834,4 +834,37 @@ public class CephMountTest {
   public void test_get_stripe_unit_gran() throws Exception {
     assertTrue(mount.get_stripe_unit_granularity() > 0);
   }
+
+  /*
+   * pool info. below we use "data" and "metadata" pool names which we assume
+   * to exist (they are the default pools created for file data / metadata in
+   * CephFS).
+   */
+
+  @Test
+  public void test_get_pool_id() throws Exception {
+    /* returns valid pool ids */
+    assertTrue(mount.get_pool_id("data") >= 0);
+    assertTrue(mount.get_pool_id("metadata") >= 0);
+
+    /* test non-existent pool name */
+    try {
+      mount.get_pool_id("asdlfkjlsejflkjef");
+      assertTrue(false);
+    } catch (CephPoolException e) {}
+  }
+
+  @Test
+  public void test_get_pool_replication() throws Exception {
+    /* test invalid pool id */
+    try {
+      mount.get_pool_replication(-1);
+      assertTrue(false);
+    } catch (CephPoolException e) {}
+
+    /* test valid pool id */
+    int poolid = mount.get_pool_id("data");
+    assertTrue(poolid >= 0);
+    assertTrue(mount.get_pool_replication(poolid) > 0);
+  }
 }
index 7169bbf6f6e67ae1e788fab6bb76022cc45f609f..ae4d41e1e984b6d3cdae7661c861344d89278e20 100644 (file)
@@ -135,4 +135,14 @@ public class CephUnmountedTest {
   public void test_get_stripe_unit_gran() throws Exception {
     mount.get_stripe_unit_granularity();
   }
+
+  @Test(expected=CephNotMountedException.class)
+  public void test_get_pool_id() throws Exception {
+    mount.get_pool_id("data");
+  }
+
+  @Test(expected=CephNotMountedException.class)
+  public void test_get_pool_replication() throws Exception {
+    mount.get_pool_replication(1);
+  }
 }