Code Monkey home page Code Monkey logo

odilon-client's Introduction

sunflower-g72ba79a53_1280

Odilon Java SDK

About Odilon

Odilon is a scalable and lightweight Open Source Object Storage that runs on standard hardware.

It is an infrastructure software designed to be used by applications that need to store to store terabytes of medium to large size objects (like photos, pdfs, audio, video) securely and safely through encryption, replication and redundancy.

It has a simple single-level folder structure similar to the Bucket / Object model of Amazon S3. It is small and easy to integrate, offers encryption, data protection and fault tolerance (software RAID and Erasure Codes) and detection of silent data degradation. Odilon also supports version control and master - standby replication over the Internet for disaster recovery and ransomware recovery.

For more info visit Odilon's website Java Development with Odilon SDK and also GitHub page

Odilon Java SDK Concepts

A Java client program that interacts with the Odilon server must include the Odilon SDK jar in the classpath. A typical architecture for a Web Application is



web-app-odilon-en



In order to access the Odilon server from a Java Application you have to include Odilon client JAR in the classpath. The interaction is managed by an instance of OdilonClient that connects to the server using the credentials: AccessKey (ie. username) and SecretKey (ie. password)



/* these are the default values for the Server */
String endpoint = "http://localhost";
int port = 9234;
String accessKey = "odilon";
String secretKey = "odilon";
						
/** OdilonClient is the interface, ODClient is the implementation */
OdilonClient client = new ODClient(endpoint, port, accessKey, secretKey);

/** ping checks the status of server, it returns the String "ok" when the server is normal */
String ping = client.ping();
if (!ping.equals("ok")) {
	System.out.println("ping error -> " + ping);
	System.exit(1);
}


Odilon stores objects using a flat structure of containers called Buckets. A bucket is like a folder, it just contains binary objects, potentially a very large number. Every object contained by a bucket has a unique ObjectName in that bucket; therefore, the pair BucketName + ObjectName is a Unique ID for each object in Odilon.



try {
    String bucketName = "bucket-demo";
    /** check if the bucket exists, if not create it */
    if (client.existsBucket(bucketName))
        System.out.println("bucket already exists ->" + bucketName );
    else 
        client.createBucket(bucketName);
} catch (ODClientException e) {
        System.out.println(String.valueOf(e.getHttpStatus())+ " " + e.getMessage()+" " + String.valueOf(e.getErrorCode()));
}


Uploading a File requires the Bucket to exist and the ObjectName to be unique for that bucket.



File file = new File("test.pdf");
String bucketName = "bucket-demo";
String objectName = file.getName();

try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file))) {	
	client.putObjectStream(bucketName, objectName, inputStream, Optional.of(file.getName()), Optional.empty());
} catch (ODClientException e) {
	System.out.println(String.valueOf(e.getHttpStatus())+" " + e.getMessage()+" " + String.valueOf(e.getErrorCode()));
} catch (FileNotFoundException | IOException e1) {
	System.out.println(e1.getClass().getName() + " " + e1.getMessage());
}


In addition to the binary file, an Object has Metadata (called ObjectMetadata) that is returned by some of the API calls. Odilon allows to retrieve Objects individually by BucketName + ObjectName and also supports to list the contents of a bucket and other simple queries.



try {
	/** list all bucket's objects */
	ResultSet<Item <ObjectMetadata>> resultSet = client.listObjects(bucket.getName());
	while (resultSet.hasNext()) {
		Item item = resultSet.next();
		if (item.isOk())
			System.out.println("ObjectName:"+item.getObject().objectName+" | file: " + item.getObject().fileName);
		else
			System.out.println(item.getErrorString());
	}
} catch (ODClientException e) {
   	System.out.println(String.valueOf( e.getHttpStatus())+ " "+e.getMessage() + " "+String.valueOf(e.getErrorCode()));
}


Sample Programs

Resources

Odilon Server

See odilon Server

odilon-client's People

Contributors

atolomei avatar

Stargazers

Juan Bovio avatar Ioan Rîpan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.