Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches: [master]
pull_request:

jobs:
build:
name: Build and unit tests (JDK ${{ matrix.java }})
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
java: [17, 21]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: maven
- name: Build, run the cluster-free unit tests and generate Javadoc
run: >-
./mvnw -B -ntp
-Dtest='RadosBaseTest,ErrorCodeTest'
-Dsurefire.failIfNoSpecifiedTests=false
verify javadoc:javadoc

integration:
name: Integration tests against a MicroCeph cluster
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
- name: Install librados, librbd and libradosstriper
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends librados2 librbd1 libradosstriper1
- name: Bootstrap a single-node Ceph cluster
run: sudo src/test/scripts/microceph-setup.sh
- name: Run all tests
run: ./mvnw -B -ntp test
- name: Cluster status on failure
if: failure()
run: sudo microceph.ceph -s || true
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

92 changes: 63 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,87 @@
# RADOS Java
These are Java bindings for [librados](https://docs.ceph.com/en/latest/rados/api/librados/) (C) which use JNA.

Both RADOS and RBD are implemented in these bindings.
[![CI](https://github.com/ceph/rados-java/actions/workflows/ci.yml/badge.svg)](https://github.com/ceph/rados-java/actions/workflows/ci.yml)

By using JNA there is no need for building the bindings against any header
you can use them on any system where JNA and librados are present.
Java bindings for [librados](https://docs.ceph.com/en/latest/rados/api/librados/),
[librbd](https://docs.ceph.com/en/latest/rbd/api/librbdpy/) and libradosstriper
from the [Ceph](https://ceph.io/) project, implemented with
[JNA](https://github.com/java-native-access/jna).

The bindings follow the current librados C API and require Ceph Nautilus (14.2)
or newer: the `rados_pool_stat_t` struct layout and the deprecated auid calls
changed in Nautilus.
Because JNA binds at runtime there is no native build against the Ceph
headers: the bindings work on any system where JNA and the Ceph client
libraries are present.

# Maven
## Building
## Requirements

Building requires JDK 17 or newer and Maven 3.6+ (or use the bundled `./mvnw`).
* Java 17 or newer
* librados2, librbd1 and libradosstriper1 from Ceph **Nautilus (14.2) or
newer**. The `rados_pool_stat_t` struct layout and the deprecated auid calls
changed in Nautilus, older versions are not supported.

```bash
$ mvn clean install (-Dcom.ceph.rados.skipTests)
## Using the library

```xml
<dependency>
<groupId>com.ceph</groupId>
<artifactId>rados</artifactId>
<version>0.7.0</version>
</dependency>
```

## Tests
```java
import com.ceph.rados.IoCTX;
import com.ceph.rados.Rados;

```bash
$ mvn test
try (Rados rados = new Rados("admin")) {
rados.confReadFile(new File("/etc/ceph/ceph.conf"));
rados.connect();

try (IoCTX io = rados.ioCtxCreate("data")) {
io.write("hello", "world".getBytes(StandardCharsets.UTF_8));
System.out.println(io.stat("hello").getSize());
}
}
```

You can also run specific tests:
`Rados`, `IoCTX`, `IoCTXStriper`, `RbdImage`, `Completion`, `ReadOp` and
`ListCtx` are `AutoCloseable` and release their native handles on `close()`.

## Building

Building requires JDK 17 or newer. The Maven wrapper downloads a suitable
Maven version.

```bash
mvn -Dtest=com.ceph.rados.TestRados
./mvnw clean install -Dcom.ceph.rados.skipTests=true
```

## Tests

The unit tests that do not need a cluster can always be run:

```bash
mvn -Dtest=com.ceph.rbd.TestRbd
./mvnw test -Dtest='RadosBaseTest,ErrorCodeTest' -Dsurefire.failIfNoSpecifiedTests=false
```

# Unit Tests
The tests require a running Ceph cluster. By default it will read /etc/ceph/ceph.conf
and use "admin" as a cephx id.
The remaining tests are integration tests that require a running Ceph cluster.
By default they read `/etc/ceph/ceph.conf`, authenticate as `admin` and use
the pools `data` (RADOS and striper) and `rbd` (RBD). These pools have to
EXIST prior to running the tests and should be EMPTY.

All tests will be performed on the pools "data" (RADOS) and "rbd" (RBD).
**DO NOT RUN THESE TESTS AGAINST A PRODUCTION CLUSTER.**

These pools have to EXIST prior to running the tests and should be EMPTY!
The defaults can be overridden with environment variables:

DO NOT RUN THESE TESTS ON A PRODUCTION PLATFORM.
* `RADOS_JAVA_ID`
* `RADOS_JAVA_CONFIG_FILE`
* `RADOS_JAVA_POOL`

You can overrride this by setting these environment variables:
* RADOS_JAVA_ID
* RADOS_JAVA_CONFIG_FILE
* RADOS_JAVA_POOL
```bash
./mvnw test
./mvnw test -Dtest=com.ceph.rados.TestRados
./mvnw test -Dtest=com.ceph.rbd.TestRbd
```

N.B.: You need to make sure jna.jar and junit.jar are present in /usr/share/java
`src/test/scripts/microceph-setup.sh` bootstraps a throw-away single-node
cluster with [MicroCeph](https://canonical-microceph.readthedocs-hosted.com/)
and creates the pools, which is what the GitHub Actions workflow uses.
10 changes: 10 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
librados-java (1:0.7.0-1) unstable; urgency=medium

* New upstream release 0.7.0 (the pom.xml version); an epoch is needed
because the previous Debian version was 1.0.
* Bindings fixed against the current librados C API (Nautilus+).
* Java 17 baseline, JNA 5.17, JUnit 5.
* Modern debhelper (compat 13) packaging.

-- Wido den Hollander <wido@denhollander.io> Tue, 27 Oct 2026 08:50:07 +0000

librados-java (1.0) unstable; urgency=low

* Release of version 1.0
Expand Down
1 change: 0 additions & 1 deletion debian/compat

This file was deleted.

20 changes: 12 additions & 8 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
Source: librados-java
Section: libs
Priority: extra
Maintainer: Wido den Hollander <wido@42on.com>
Build-Depends: debhelper (>= 7), openjdk-7-jdk | openjdk-8-jdk, maven (>= 3)
Standards-Version: 3.8.1
Homepage: http://www.github.com/ceph/rados-java
Section: java
Priority: optional
Maintainer: Wido den Hollander <wido@denhollander.io>
Build-Depends: debhelper-compat (= 13), default-jdk (>= 2:1.17) | openjdk-17-jdk, maven (>= 3.6)
Standards-Version: 4.7.0
Homepage: https://github.com/ceph/rados-java
Rules-Requires-Root: no

Package: librados-java
Architecture: all
Depends: librados2 (>= 0.80), librbd1 (>= 0.80)
Description: Java JNA bindings for librados and librbd
Depends: ${misc:Depends}, default-jre-headless (>= 2:1.17) | java17-runtime-headless, librados2 (>= 14.2), librbd1 (>= 14.2), libradosstriper1 (>= 14.2)
Description: Java JNA bindings for librados, librbd and libradosstriper
Java bindings for the Ceph RADOS object store client library (librados),
the RADOS block device library (librbd) and libradosstriper, implemented
with JNA so no native build against the Ceph headers is required.
1 change: 0 additions & 1 deletion debian/debhelper.log

This file was deleted.

4 changes: 2 additions & 2 deletions debian/librados-java.docs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
README
LICENSE
README.md
LICENSE
1 change: 0 additions & 1 deletion debian/librados-java.install

This file was deleted.

56 changes: 15 additions & 41 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,50 +1,24 @@
#!/usr/bin/make -f

export DH_VERBOSE=1
export DH_OPTIONS

VERSION := $(shell grep '^ <version>' pom.xml| cut -d'>' -f2 |cut -d'<' -f1)
VERSION := $(shell grep '^ <version>' pom.xml | cut -d'>' -f2 | cut -d'<' -f1)
JAVADIR := debian/librados-java/usr/share/java

configure: configure-stamp
configure-stamp:
dh_testdir
touch configure-stamp
%:
dh $@

build: build-indep
override_dh_auto_build:
mvn -B -ntp -Dcom.ceph.rados.skipTests=true clean package

build-indep: build-indep-stamp
override_dh_auto_test:
# The tests need a running Ceph cluster, see README.md

build-indep-stamp: configure
mvn clean
mvn -DskipTests install
touch $@
override_dh_auto_install:
install -D -m 0644 target/rados-$(VERSION).jar $(JAVADIR)/rados-$(VERSION).jar
dh_link usr/share/java/rados-$(VERSION).jar usr/share/java/rados.jar
install -m 0644 target/dependencies/jna*.jar $(JAVADIR)/

clean:
dh_testdir
dh_testroot
rm -f build-arch-stamp build-indep-stamp configure-stamp
dh_clean

install:
dh_testdir
dh_testroot
dh_prep -s

mkdir -p debian/tmp/usr/share/java
cp target/rados-${VERSION}.jar debian/tmp/usr/share/java
dh_link usr/share/java/rados-${VERSION}.jar usr/share/java/rados.jar
cp target/dependencies/jna*.jar debian/tmp/usr/share/java

dh_installdirs
dh_install

binary: install
dh_install
dh_installchangelogs
dh_link
dh_compress
dh_fixperms
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb
override_dh_auto_clean:
mvn -B -ntp -q clean || true
dh_auto_clean
25 changes: 0 additions & 25 deletions src/test/docker/Dockerfile

This file was deleted.

Loading
Loading