Interface OdilonClient
- All Known Implementing Classes:
ODClient
OdilonClient contains the API to interact with an Odilon server.
The implementation of this Interface is ODClient
This example connects to a Odilon server and sends a ping request to check the status of 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" if the server is normal
String ping = client.ping();
if (!ping.equals("ok")) {
System.out.println("ping error -> " + ping);
System.exit(1);
}
}- Author:
- atolomei@novamens.com (Alejandro Tolomei), aferraria@novamens.com (Alejo Ferraria)
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shutdown Isn't Necessary because the threads and connections that are held will be released automatically if they remain idlevoidcreateBucket(String bucketName) Creates a newBucket.voiddeleteAllBucketVersions(String bucketName) Deletes all the previous versions of all the Objects in theBucket.
Note that it does not delete the current version of the objects (called head version).voiddeleteBucket(String bucketName) Deletes aBucket.voiddeleteObject(String bucketName, String objectName) Removes an Object from aBucket.voiddeleteObjectAllVersions(String bucketName, String objectName) Deletes all the Object's previous versions, it does not delete the object current version (head version).booleanexistsBucket(String bucketName) Returnstrueif a bucket with namebucketNameexistsbooleanexistsObject(String bucketName, String objectName) Checks for the existence of an Object.io.odilon.model.BucketReturns theBucketintReturns the binary data (File) of this ObjectvoidRetrieves the binary data of this Object and saves it to aFilewith pathfilePathio.odilon.model.ObjectMetadatagetObjectMetadata(String bucketName, String objectName) Returns theObjectMetadataof the Object.io.odilon.model.ObjectMetadatagetObjectMetadataPreviousVersion(String bucketName, String objectName) ReturnsObjectMetadataof the version immediately previous to the head version, ornullif there is no previous versionList<io.odilon.model.ObjectMetadata> getObjectMetadataPreviousVersionAll(String bucketName, String objectName) Returns all the previous versions of an Object, the current version (head version) is not included in the List returnedgetObjectPreviousVersion(String bucketName, String objectName) Returns the binary data of the object's previous version ornullif there is no previous version.getObjectVersion(String bucketName, String objectName, int version) Returns the binary data of the version #versionof the object's ornullif the object does not have a version #version.getPresignedObjectUrl(String bucketName, String objectName) Returns a temporary URL to access or download the binary data of an Object without authenticationgetPresignedObjectUrl(String bucketName, String objectName, Optional<Integer> expiresInSeconds) Returns a temporary URL to access or download the binary data of an Object without authenticationgetUrl()Returns the url of the Odilon serverbooleanhasVersions(String bucketName, String objectName) Returnstrueif the Object has previous versions, ie.booleanbooleanReturnstrueif the bucket has no Objects, otherwisefalsebooleanisHTTPS()booleanisSSL()booleanisValidBucketName(String bucketName) Returnstrueif theStringbucketName is a valid name for an Odilon BucketbooleanisValidObjectName(String objectName) Returnstrueif theStringobjectName is a valid name for an Odilon objectbooleanChecks if the server has version control enabledList<io.odilon.model.Bucket> Returns all buckets, sorted alphabeticallyio.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(io.odilon.model.Bucket bucket) Lists the objects in theBucket.io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName) Lists the objects in theBucket.io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName, String prefix) Lists the objects in theBucket.io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> Lists the objects in theBucket.io.odilon.model.MetricsValuesmetrics()Returns an instance ofMetricsValueswith info related to the activity of the serverping()Returns the String "ok" if the server is normal or aStringwith the error reported by the Server.io.odilon.model.ObjectMetadataUploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadataUploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadataputObjectStream(String bucketName, String objectName, InputStream stream, String fileName) Uploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadataputObjectStream(String bucketName, String objectName, InputStream stream, String fileName, String contentType) Uploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadataputObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size) Uploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadataputObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size, Optional<String> contentType) Uploads a InputStream to the server.io.odilon.model.ObjectMetadataputObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size, Optional<String> contentType, Optional<List<String>> customTags) Uploads a File or any other binary stream to the server.voidrenameBucket(String bucketName, String newBucketName) Renames aBucket.voidrestoreObjectPreviousVersions(String bucketName, String objectName) Restores the previous version of the Object and deletes current version.voidsetCharset(String c) voidsetChunkSize(int chunkSize) voidsetPresignedUrl(String presignedEndPoint) Sets a specific url for presigned urls.voidsetPresignedUrl(String presignedEndPoint, boolean presignedSSL) voidsetPresignedUrl(String presignedEndPoint, int port, boolean presignedSSL) voidsetTimeout(long connectTimeoutMilliseconds, long writeTimeoutMilliseconds, long readTimeoutMilliseconds) Sets HTTP connect, write and read timeouts.io.odilon.model.SystemInfoReturns an instance ofSystemInfowith the info of the settings of the servervoidtraceOff()disable printing the request-response raw info to a streamvoidtraceOn(OutputStream traceStream) enabled printing the request-response raw info to a stream
-
Method Details
-
close
Shutdown Isn't Necessary because the threads and connections that are held will be released automatically if they remain idle
- Throws:
ODClientException
-
isHTTPS
boolean isHTTPS() -
createBucket
Creates a new
Bucket.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.
The bucket must not exist, if it exists the method will throw a
Example:ODClientException.
bucketName length must be lower or equal toSharedConstant.MAX_BUCKET_CHARSand
match the regular expressionSharedConstant.bucket_valid_regex(seeisValidBucketName(java.lang.String))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( "HTTP status -> " + String.valueOf(e.getHttpStatus())+ " | ErrorMsg -> " + e.getMessage() + " Odilon Error Code -> " + String.valueOf(e.getErrorCode()) ); }- Parameters:
bucketName- Bucket name Throws ODClientException if the bucket already exists (error codeErrorCode.OBJECT_ALREADY_EXIST)- Throws:
ODClientException
-
renameBucket
Renames a
Bucket.The new bucket name must not be used by another bucket
Example: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); // rename bucket to "bucket-demo-renamed" client.renameBucket(bucketName, "bucket-demo-renamed"); } catch (ODClientException e) { System.out.println( "HTTP status -> " + String.valueOf(e.getHttpStatus())+ " | ErrorMsg -> " + e.getMessage() + " Odilon Error Code -> " + String.valueOf(e.getErrorCode()) ); }- Parameters:
bucketName- existing Bucket namenewBucketName- new Bucket name Throws ODClientException if the bucket does not exist (ErrorCode.BUCKET_NOT_EXISTS) if newBucketName is already used by another bucket (ErrorCode.OBJECT_ALREADY_EXIST)- Throws:
ODClientException
-
listBuckets
Returns all buckets, sorted alphabetically
Example:
OdilonClient odilonClient = new ODClient(url, port, accessKey, secretKey); List<Bucket> bucketList = odilonClient.listBuckets(); bucketList.forEach( bucket -> { System.out.println(bucket.creationDate() + ", " + bucket.name()); if ( odilonClient.isEmpty(bucket.getName()) ) System.out.println(bucket.name() + " -> is empty"); else System.out.println(bucket.name() + " -> has objects"); ); }- Returns:
- List of Buckets, sorted alphabetically see also Sample ListObjects program on GitHub
- Throws:
ODClientException
-
isValidObjectName
Returns
trueif theStringobjectName is a valid name for an Odilon object- objectName length less or equal to
SharedConstant.MAX_OBJECT_CHARS - objectName must match Java Regular expression
SharedConstant.object_valid_regex
Informally speaking: object names can not have slash (/) or backslash (\)
Examples of invalid object names:- 2023/11/349460828-7.2.a.3.implementacion.pdf
- 2021/9/346049478-roses-2191636
Examples of valid object names:
- 1-documento rio-90876
- 2023-6-346227578-Quinquela-773x458.jpeg
- 2023-11-349460978-compliance-basic.png.enc
- Parameters:
objectName- can not be null- Returns:
- true if the objectName is a valid Odilon Object name
- objectName length less or equal to
-
isValidBucketName
Returns
trueif theStringbucketName is a valid name for an Odilon Bucket- bucketName length less or equal to
SharedConstant.MAX_BUCKET_CHARS - bucketName must match Java Regular expression
SharedConstant.bucket_valid_regexInformally speaking: letters A to Z and/or a to z, numbers, and/or - or _
- Parameters:
bucketName- can not be null- Returns:
- true if the bucketName is a valid Odilon
Bucketname
- bucketName length less or equal to
-
existsBucket
Returns
trueif a bucket with namebucketNameexists- Parameters:
bucketName- can not be null- Returns:
- true if the bucket exists in the Server
- Throws:
ODClientException
-
isEmpty
Returns
trueif the bucket has no Objects, otherwisefalse- Parameters:
bucketName- can not be null- Returns:
- true if the bucket has no Objects
Throws
ODClientExceptionif bucketName is not an existing Bucket
the http error codeODHttpStatus.NOT_FOUNDand Odilon's error codeErrorCode.BUCKET_NOT_EXISTS) - Throws:
ODClientException
-
getBucket
Returns the
BucketIt will throw a
ODClientExceptionif the bucket does not exist.Example:
if (odilonClient.existsBucket("test-bucket")( { Bucket bucket = odilonClient.getBucket("test-bucket"); System.out.println("bucket name ->" + bucket.getName() ); System.out.println("bucket created ->" + bucket.getCreationDate().toString() ); }- Parameters:
bucketName- Bucket name- Returns:
- Bucket
Throws
ODClientException
BucketName is not an existing Bucket ->ODHttpStatus.NOT_FOUNDwith error codeErrorCode.BUCKET_NOT_EXISTS - Throws:
ODClientException
-
deleteBucket
Deletes a
Bucket. The bucket must be empty to be deletedExample:
try { // deletes all buckets that have no objects for (Bucket bucket:odilonClient.listBuckets()) { if (odilonClient.isEmpty(bucket.getName())) { odilonClient.deleteBucket(bucket.getName()); } } } catch (ODClientException e) { System.out.println( "HTTP status -> " + String.valueOf(e.getHttpStatus())+ " | ErrorMsg -> " + e.getMessage() + " Odilon Error Code -> " + String.valueOf(e.getErrorCode()) ); }- Parameters:
bucketName- Bucket name ThrowsODHttpStatus.NOT_FOUNDif Bucket does not exist, with error codeErrorCode.BUCKET_NOT_EXISTS
ODHttpStatus.CONFLICTif Bucket does not exist, with error codeErrorCode.BUCKET_NOT_EMPTY- Throws:
ODClientException
-
deleteAllBucketVersions
Deletes all the previous versions of all the Objects in the
Bucket.
Note that it does not delete the current version of the objects (called head version).
This method is sometimes used to free disk in the server
Async executionThis method returns immediately after sending the command to the server, which processes the task asynchronously. The async command is atomic on each object but not globally, which means that until it finishes some objects can still have versions.
Example:
try { Bucket bucket = odilonClient.getBucket("test-version-control"); odilonClient.deleteAllBucketVersions(bucket.getName()); } catch (ODClientException e) { System.out.println( "HTTP status -> " + String.valueOf(e.getHttpStatus())+ " | ErrorMsg -> " + e.getMessage() + " Odilon Error Code -> " + String.valueOf(e.getErrorCode()) ); }- Parameters:
bucketName- Bucket name ThrowsODClientException
Bucket does not exist ->ODHttpStatus.NOT_FOUNDwith error codeErrorCode.BUCKET_NOT_EXISTS
Server does not have Version Control enabled ->ODHttpStatus.METHOD_NOT_ALLOWEDwith error codeErrorCode.API_NOT_ENABLEDVersion Control not enabled- Throws:
ODClientException
-
existsObject
Checks for the existence of an Object.
Note that if the
Bucketdoes not exist, the method does not throw anException, it returnsfalse- Parameters:
bucketName- can not be nullobjectName- can not be null- Returns:
- true if the Object exist
Throws
ODClientException, IOException - Throws:
ODClientExceptionIOException
-
getObjectMetadata
io.odilon.model.ObjectMetadata getObjectMetadata(String bucketName, String objectName) throws ODClientException Returns the
ObjectMetadataof the Object.
In addition to the binary file, an Object has metadata (calledObjectMetadata) 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.Every object contained by a bucket has a unique objectName in that bucket; therefore, the pair bucketName + objectName is a Global Unique Identifier for each object in Odilon.
Example:
try { Bucket bucket = odilonClient.getBucket("test-version-control"); ObjectMetadata meta = odilonClient.getObjectMetadata(bucket.getName(), "test1"); System.out.println(meta.toString()); } catch (ODClientException e) { System.out.println( "HTTP status -> " + String.valueOf(e.getHttpStatus())+ " | ErrorMsg -> " + e.getMessage() + " Odilon Error Code -> " + String.valueOf(e.getErrorCode()) ); System.exit(1); }- Parameters:
bucketName- can not be nullobjectName- can not be null- Returns:
ObjectMetadatafrom server ThrowsODClientExceptionif object does not exist- Throws:
ODClientException
-
getObject
Returns the binary data (File) of this Object
OdilonClient odilonClient = new ODClient(url, port, accessKey, secretKey); List<Bucket> bucketList = odilonClient.listBuckets(); bucketList.forEach( bucket -> { System.out.println(bucket.creationDate() + ", " + bucket.name()); if ( odilonClient.isEmpty(bucket.getName()) ) System.out.println(bucket.name() + " -> is empty"); else System.out.println(bucket.name() + " -> has objects"); ); }- Parameters:
bucketName- can not be nullobjectName- can not be null- Throws:
ODClientException
-
getObject
void getObject(String bucketName, String objectName, String filePath) throws ODClientException, IOException Retrieves the binary data of this Object and saves it to a
Filewith pathfilePath- Parameters:
bucketName- can not be nullobjectName- can not be nullfilePath- path and file name where to save the data downloaded (example: "c:\temp\myfile.pdf") Throws if object does not exist ->ODHttpStatus.NOT_FOUND,ErrorCode.OBJECT_NOT_FOUNDThrows IOException- Throws:
ODClientExceptionIOException
-
setPresignedUrl
Sets a specific url for presigned urls.
A presigned URL is a way to grant temporary access to an Object, for example in an HTML webpage. It remains valid for a limited period of time which is specified when the URL is generated.
Sometimes it may be useful for the presigned url to have a different prefix than the endpoint used to interact with the server.
For example: The server may be accessible by an application server at
http://localhost:9234
and the presigned url generated to be distributed in a html web page be reachable at:
http://files.odilon.io
ODilonClient client = new ODClient(("http://localhost", 9234, "odilon", "odilon"); // The firewall blocks port 9234 and the webserver is configured to allow access to // the odilon server at http://files.myportal.com client.setPresignedUrl("files.myportal.com", 80, false); -
setPresignedUrl
-
setPresignedUrl
-
getPresignedObjectUrl
String getPresignedObjectUrl(String bucketName, String objectName, Optional<Integer> expiresInSeconds) throws ODClientException Returns a temporary URL to access or download the binary data of an Object without authentication
A presigned URL is a way to grant temporary access to an Object, for example in an HTML webpage. It remains valid for a limited period of time which is specified when the URL is generated.
For the following example see also
Example:listObjects(java.lang.String, java.util.Optional<java.lang.String>, java.util.Optional<java.lang.Integer>)this.bucket = getClient().listBuckets().get(0); ResultSet<Item<ObjectMetadata>> rs = getClient().listObjects(this.bucket.getName()); int counter = 0; while (rs.hasNext() && counter++ < MAX) { Item<ObjectMetadata> item = rs.next(); if (item.isOk()) { ObjectMetadata meta = item.getObject(); // by default the link lasts 7 days logger.debug(meta.bucketName + " / " + meta.objectName + " (7 days) -> " + getClient().getPresignedObjectUrl(meta.bucketName, meta.objectName)); // url valid for 5 minutes logger.debug(meta.bucketName + " / " + meta.objectName + " (5 min) -> " + getClient().getPresignedObjectUrl(meta.bucketName, meta.objectName, Optional<Integer>(Integer.valueOf(60*5))); } }- Parameters:
bucketName- can not be nullobjectName- can not be nullexpiresInSeconds- duration in seconds for the url to be valid- Returns:
- temporary url to download the file without authentication
- Throws:
ODClientException
-
getPresignedObjectUrl
Returns a temporary URL to access or download the binary data of an Object without authentication
This is method calls
getPresignedObjectUrl(java.lang.String, java.lang.String, java.util.Optional<java.lang.Integer>)with the default value forexpiresInSeconds(ie. 7 days in seconds)- Parameters:
bucketName- can not be nullobjectName- can not be null- Returns:
- temporary url to download the file without authentication
- Throws:
ODClientException
-
putObjectStream
io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, String fileName, String contentType) throws ODClientException Uploads a File or any other binary stream to the server. It will create a new object or update an existing one.
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.Uploading a File requires the Bucket to exist and the ObjectName to be unique for that bucket.
If the objectName does not exist in the bucket, the server will create a new object, if the objectName exists in the bucket the server will update the object with the new binary data. in this case, if the server has Version Control enabled it will make a new version and the previous version of the object will not be deleted. If the server does not have Version Control enabled, the former version will be discarded.
Objects can optionally be uploaded with one or more user defined tags (String), for example to store a local id with the file uploaded
Odilon client closes the
InputStreamafter sending the data to the server. However, if anExceptionother thanODClientExceptionis thrown by this method, theInputStreammay not have been closed.Therefore callers must always attempt to close the
Example:InputStreamFile 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( "HTTP status -> " + String.valueOf(e.getHttpStatus())+ " | ErrorMsg -> " + e.getMessage() + " Odilon Error Code -> " + String.valueOf(e.getErrorCode()) ); } catch (FileNotFoundException | IOException e1) { System.out.println(e1.getMessage()); }- Parameters:
bucketName- can not be nullobjectName- can not be nullstream- can not be nullfileName-contentType-- Returns:
ObjectMetadataof the Object created or updated- Throws:
ODClientException
-
putObject
io.odilon.model.ObjectMetadata putObject(String bucketName, String objectName, File file) throws ODClientException Uploads a File or any other binary stream to the server. It will create a new object or update an existing one.
This method does the same as
putObject(java.lang.String, java.lang.String, java.io.File)
but with a localFileinstead of anInputStream- Parameters:
bucketName- can not be nullobjectName- can not be nullfile- can not be null, file.exists() must be true, file.isDirectory() must be false, Files.isRegularFile(file.toPath()) must be true Example: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); File dir = new File("directoryToUpload"); String bucketName = "bucket-demo"; // upload all Files from directory for (File file:dir.listFiles()) { if (!file.isDirectory()) { String objectName = fi.getName()+"-"+String.valueOf(Double.valueOf((Math.abs(Math.random()*100000))).intValue()); getClient().putObject(bucketName, objectName, fi); } }- Returns:
ObjectMetadataof the Object created or updated- Throws:
ODClientException- See Also:
-
putObject
io.odilon.model.ObjectMetadata putObject(String bucketName, String objectName, Optional<List<String>> customTags, File file) throws ODClientException Uploads a File or any other binary stream to the server. It will create a new object or update an existing one.
This method does the same as
putObject(java.lang.String, java.lang.String, java.io.File)
but with a localFileinstead of anInputStream- Parameters:
bucketName-objectName-customTags- Optional List of user defined tagsfile-- Returns:
- Throws:
ODClientException
-
putObjectStream
io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, String fileName) throws ODClientException Uploads a File or any other binary stream to the server. It will create a new object or update an existing one.
This method calls
putObject(java.lang.String, java.lang.String, java.io.File)- Parameters:
bucketName- can not be nullobjectName- can not be nullstream- InputStream with the binary data to uploadfileName- name of the File uploaded- Returns:
- the
ObjectMetadataof the Object ThrowsODClientExceptionSee Minio to Odilon migration sample program on GitHub - Throws:
ODClientException
-
putObjectStream
io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size, Optional<String> contentType) throws ODClientException Uploads a InputStream to the server. It will create a new object or update it if already exists.
This method calls
putObject(java.lang.String, java.lang.String, java.io.File)- Parameters:
bucketName- can not be nullobjectName- can not be nullstream-fileName-size-contentType-- Returns:
- Throws:
ODClientException
-
putObjectStream
io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size) throws ODClientException Uploads a File or any other binary stream to the server. It will create a new object or update an existing one.
This method calls
putObject(java.lang.String, java.lang.String, java.io.File)- Parameters:
bucketName- Bucket nameobjectName- Object namestream-fileName-size-- Returns:
- Throws:
ODClientException
-
putObjectStream
io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size, Optional<String> contentType, Optional<List<String>> customTags) throws ODClientException Uploads a File or any other binary stream to the server. It will create a new object or update an existing one.
This method calls
putObject(java.lang.String, java.lang.String, java.io.File)- Parameters:
bucketName-objectName-stream-fileName-size-contentType-customTags-- Returns:
- Throws:
ODClientException
-
deleteObject
Removes an Object from a
Bucket.Example:
odilonClient.deleteObject("my-bucketname", "my-objectname");- Parameters:
bucketName- can not be nullobjectName- can not be null- Throws:
ODClientException
-
hasVersions
Returns
trueif the Object has previous versions, ie. at least there is one version older than the head version (in which case the head version must be greater than 0)- Parameters:
bucketName- can not be nullobjectName- can not be null- Returns:
trueif the Object has more versions than the head version (ie. the head version must be greater than 0) ThrowsODClientExceptionThrows IOException- Throws:
ODClientExceptionIOException
-
getObjectMetadataPreviousVersion
io.odilon.model.ObjectMetadata getObjectMetadataPreviousVersion(String bucketName, String objectName) throws ODClientException Returns
ObjectMetadataof the version immediately previous to the head version, ornullif there is no previous version- Parameters:
bucketName- can not be nullobjectName- can not be null- Returns:
- Throws:
ODClientException
-
restoreObjectPreviousVersions
Restores the previous version of the Object and deletes current version.
If the object does not have any previous versions, it throws an
ODClientException- Parameters:
bucketName- can not be nullobjectName- can not be null ThrowsODClientException
- The server does not have Version Control enabled -> ODHttpStatus#METHOD_NOT_ALLOWED, ErrorCode#API_NOT_ENABLED
- The Object does not have a previous version (i.e. current version is version 0) -> ODHttpStatus#NOT_FOUND, ErrorCode#OBJECT_NOT_FOUND
- All the object's previous version has been deleted via
deleteAllBucketVersions(java.lang.String)ordeleteObjectAllVersions(java.lang.String,java.lang.String)-> ODHttpStatus#NOT_FOUND, ErrorCode#OBJECT_NOT_FOUND - Other, unexpected causes -> ODHttpStatus#INTERNAL_SERVER_ERROR, ErrorCode#INTERNAL_ERROR
- The server does not have Version Control enabled -> ODHttpStatus#METHOD_NOT_ALLOWED, ErrorCode#API_NOT_ENABLED
- Throws:
ODClientException
-
getObjectMetadataPreviousVersionAll
List<io.odilon.model.ObjectMetadata> getObjectMetadataPreviousVersionAll(String bucketName, String objectName) throws ODClientException Returns all the previous versions of an Object, the current version (head version) is not included in the List returned
- Parameters:
bucketName- can not be nullobjectName- can not be null- Returns:
- list of
ObjectMetadatasorted by version number, from 0 to (head version - 1) ThrowsODClientException - Throws:
ODClientException
-
getObjectPreviousVersion
Returns the binary data of the object's previous version or
nullif there is no previous version.- Parameters:
bucketName- can not be nullobjectName- can not be null- Returns:
- ObjectMetadata of the object's previous version
- Throws:
ODClientException
-
getObjectVersion
InputStream getObjectVersion(String bucketName, String objectName, int version) throws ODClientException Returns the binary data of the version #
versionof the object's ornullif the object does not have a version #version.- Parameters:
bucketName- can not be nullobjectName- can not be nullversion-- Returns:
- Throws:
ODClientException
-
deleteObjectAllVersions
Deletes all the Object's previous versions, it does not delete the object current version (head version).
After calling this method the Object will have only the head version.
- Parameters:
bucketName- can not be nullobjectName- can not be null- Throws:
ODClientException
-
listObjects
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName, Optional<String> prefix, Optional<Integer> pageSize) throws ODClientException Lists the objects in the
Bucket.ResultSet
Item <ObjectMetadata>can contain:
it item.isOk() -> aObjectMetadata.
otherwise -> or an String with an errorIf prefix is not
Optional.empty()the list will include only objects where the objectName starts with the prefix.
pageSizeis the number of items retrieved by each call to the server, if the value isOptional.empty()the client will use the default pageSize value.
- Parameters:
bucketName- can not be nullprefix-pageSize-- Returns:
ResultSet<Item<ObjectMetadata>>. ResultSet isIterableItem if ok() contain a instance of ObjectMetadata, otherwise a error() returns a String with the errorExample list all bucket's objects:
try { 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( "HTTP status -> " + String.valueOf(e.getHttpStatus())+ " | ErrorMsg -> " + e.getMessage() + " Odilon Error Code -> " + String.valueOf(e.getErrorCode()) ); } </p>- Throws:
ODClientException
-
listObjects
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName, String prefix) throws ODClientException Lists the objects in the
Bucket.- Parameters:
bucketName- can not be nullprefix-- Returns:
- Throws:
ODClientException
-
listObjects
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName) throws ODClientException Lists the objects in the
Bucket.- Parameters:
bucketName- can not be null- Returns:
- Throws:
ODClientException
-
listObjects
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(io.odilon.model.Bucket bucket) throws ODClientException Lists the objects in the
Bucket.- Parameters:
bucket- can not be null- Returns:
- ResulSet of Items
- Throws:
ODClientException
-
ping
String ping()Returns the String "ok" if the server is normal or a
Example:Stringwith the error reported by the Server.
If the client can not connect to the Server, the method returns a message "can not connect"String endpoint = "http://localhost"; int port = 9234; String accessKey = "odilon"; String secretKey = "odilon"; OdilonClient client = new ODClient(endpoint, port, accessKey, secretKey); String pingResult = odilonClient.ping(); if (!pingResult.equals("ok")) { System.out.println( "Server error -> " + pingResult)); }- Returns:
- String "ok" or the error reported by the Server.
-
metrics
Returns an instance of
MetricsValueswith info related to the activity of the serverThey are counters of events and meters that measure events per second in a 1m 5m and 15m windows
- Counter
A counter is just a gauge for an AtomicLong instance. You can increment or decrement its value.
- Meter
A meter measures the rate of events over time (e.g., “requests per second”). In addition to the mean rate, meters also track 1-, 5-, and 15-minute moving averages.
See https://metrics.dropwizard.io/4.2.0
Example:
cacheObjectHitCounter -> 1,224
cacheObjectMissCounter -> 637
cacheObjectSize -> 475
decryptFileMeter -> 0.27 0.42 0.24
encrpytFileMeter -> 0.49 0.67 0.46
objectCreateCounter -> 475
objectDeleteCounter -> 0
objectDeleteVersionCounter -> 0
objectGetMeter -> 0.55 0.85 0.48
objectPutMeter -> 0.49 0.67 0.46
objectUpdateCounter -> 162
replicaObjectCreate -> 0
replicaObjectDelete -> 0
replicaObjectUpdate -> 0
vaultDecryptMeter -> 0.00 0.00 0.00
vaultEncryptMeter -> 0.00 0.00 0.00
- Returns:
MetricsValues- Throws:
ODClientException
- Counter
A counter is just a gauge for an AtomicLong instance. You can increment or decrement its value.
-
systemInfo
Returns an instance of
SystemInfowith the info of the settings of the server- Returns:
SystemInfo- Throws:
ODClientException
-
isVersionControl
Checks if the server has version control enabled
- Returns:
- true if the server has version control enabled
- Throws:
ODClientException
-
getUrl
String getUrl()Returns the url of the Odilon server
- Returns:
- server url (without the port)
-
setTimeout
void setTimeout(long connectTimeoutMilliseconds, long writeTimeoutMilliseconds, long readTimeoutMilliseconds) Sets HTTP connect, write and read timeouts. A value of 0 means no timeout, otherwise values must be between 1 and Integer.MAX_VALUE when converted to milliseconds.
Example:
odilonClient.setTimeout(TimeUnit.SECONDS.toMillis(10), TimeUnit.SECONDS.toMillis(10), TimeUnit.SECONDS.toMillis(30));- Parameters:
connectTimeoutMilliseconds- HTTP connect timeout in milliseconds.writeTimeoutMilliseconds- HTTP write timeout in milliseconds.readTimeoutMilliseconds- HTTP read timeout in milliseconds.
-
setChunkSize
void setChunkSize(int chunkSize) -
getChunkSize
int getChunkSize() -
traceOn
enabled printing the request-response raw info to a stream
-
traceOff
disable printing the request-response raw info to a stream
- Throws:
IOException
-
setCharset
- Parameters:
c-
-
getCharset
String getCharset()- Returns:
- Charsert "UTF-8" is the default value.
-
isAcceptAllCertificates
boolean isAcceptAllCertificates() -
isSSL
boolean isSSL()
-