Class ODClient
- All Implemented Interfaces:
OdilonClient
This class implements the Interface OdilonClient
, Odilon Object Storage client.
For examples on using this library, please visit http://odilon.io
- Author:
- atolomei@novamens.com (Alejandro Tolomei), aferraria@novamens.com (Alejo Ferraria)
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
default network I/O timeout is 15 minutesstatic final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addServiceRequest
(String requestClass) void
close()
Shutdown Isn't Necessary because the threads and connections that are held will be released automatically if they remain idlevoid
createBucket
(String bucketName) Creates a newBucket
.created()
void
deleteAllBucketVersions
(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).void
deleteBucket
(String bucketName) Deletes aBucket
.void
deleteObject
(String bucketName, String objectName) Removes an object from a bucket.void
deleteObjectAllVersions
(String bucketName, String objectName) Deletes all the Object's previous versions, it does not delete the object current version (head version).boolean
existsBucket
(String bucketName) Returnstrue
if a bucket with namebucketName
existsboolean
existsObject
(String bucketName, String objectName) Checks for the existence of an Object.io.odilon.model.Bucket
Returns theBucket
int
Gets entire object's data asInputStream
in given bucket.void
Gets object's data and stores it to given file name.protected com.fasterxml.jackson.databind.ObjectMapper
io.odilon.model.ObjectMetadata
getObjectMetadata
(String bucketName, String objectName) ReturnsObjectMetadata
of given object in given bucket.io.odilon.model.ObjectMetadata
getObjectMetadataPreviousVersion
(String bucketName, String objectName) ReturnsObjectMetadata
of previous versionList<io.odilon.model.ObjectMetadata>
getObjectMetadataPreviousVersionAll
(String bucketName, String objectName) Returns all previous versions of an Object, sorted by version numbergetObjectPreviousVersion
(String bucketName, String objectName) Returns the binary data of the object's previous version ornull
if there is no previous version.getObjectVersion
(String bucketName, String objectName, int version) get InputStream of the version passed as parameter, null if head is version 0 parameter is non existent or previous versions were wipedgetPresignedObjectUrl
(String bucketName, String objectName) Returns an presigned URL to download the binary object with default expiry time.getPresignedObjectUrl
(String bucketName, String objectName, Optional<Integer> expires) A presigned URL is a way to grant temporary access to an Object, for example in an HTML webpage.getPresignedObjectUrl
(String bucketName, String objectName, Optional<Integer> expires, Map<String, String> reqParams) A presigned URL is a way to grant temporary access to an Object, for example in an HTML webpage.getUrl()
Returns the url of the Odilon serverboolean
hasVersions
(String bucketName, String objectName) Returnstrue
if the Object has previous versions, ie.void
Ignores check on server certificate for HTTPS connection.boolean
boolean
Returnstrue
if the bucket has no Objects, otherwisefalse
boolean
isHTTPS()
boolean
isSSL()
boolean
isValidBucketName
(String name) Returnstrue
if theString
bucketName is a valid name for an Odilon Bucketboolean
isValidObjectName
(String objectName) Returnstrue
if theString
objectName is a valid name for an Odilon objectboolean
Checks 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) Item
is a wrapper for Lists and otherIterable
structures of T where some elements may not be a T but an error.
T
must be Serializableio.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.MetricsValues
metrics()
Returns an instance ofMetricsValues
with info related to the activity of the serverping()
Returns the String "ok" or a String with the error reported by the Server.io.odilon.model.ObjectMetadata
Uploads theFile
file to the serverio.odilon.model.ObjectMetadata
Uploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadata
putObjectStream
(String bucketName, String objectName, InputStream stream, String fileName) Uploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadata
putObjectStream
(String bucketName, String objectName, InputStream stream, String fileName, String contentType) Uploads a File or any other binary stream to the server.io.odilon.model.ObjectMetadata
putObjectStream
(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.ObjectMetadata
putObjectStream
(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size, Optional<String> contentType) Uploads a InputStream to the server.io.odilon.model.ObjectMetadata
putObjectStream
(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.void
renameBucket
(String bucketName, String newBucketName) Renames aBucket
.void
restoreObjectPreviousVersions
(String bucketName, String objectName) Restores the previous version of the Object and deletes current version.void
setCharset
(String c) void
setChunkSize
(int chunkSize) void
setTimeout
(long connectTimeoutMilliseconds, long writeTimeoutMilliseconds, long readTimeoutMilliseconds) Sets HTTP connect, write and read timeouts.io.odilon.model.SystemInfo
ReturnsSystemInfo
toJSON()
toString()
void
traceOff()
Disables HTTP call tracing previously enabled.void
traceOn
(OutputStream traceStream) enabled printing the request-response raw info to a stream
-
Field Details
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUTdefault network I/O timeout is 15 minutes- See Also:
-
DEFAULT_USER_AGENT
-
-
Constructor Details
-
ODClient
By default the server has the following settings in file
odilon.properties
Note that these parameters can not be defined or modified by the client. They are configured on the server's odilon.properties file
- port. 9234
- accessKey. "odilon"
- secretKey. "odilon"
- Parameters:
endpoint
- can not be nullport
- can not be null (normally default port is 9234)accessKey
- can not be null (default is "odilon")secretKey
- can not be null (default is "odilon")
-
ODClient
-
ODClient
public ODClient(String endpoint, int port, String accessKey, String secretKey, boolean isSecure, boolean acceptAllCertificates) - Parameters:
endpoint
- can not be nullport
- can not be null (normally default port is 9234)accessKey
- can not be nullsecretKey
- can not be nullisSecure
- whether to use SSLacceptAllCertificates
- for self signed certificates
-
-
Method Details
-
putObjectStream
public io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, String fileName) throws ODClientException Description copied from interface:OdilonClient
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
OdilonClient.putObject(java.lang.String, java.lang.String, java.io.File)
- Specified by:
putObjectStream
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be nullstream
- InputStream with the binary data to uploadfileName
- name of the File uploaded- Returns:
- the
ObjectMetadata
of the Object ThrowsODClientException
See Minio to Odilon migration sample program on GitHub - Throws:
ODClientException
-
putObjectStream
public io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size) throws ODClientException Description copied from interface:OdilonClient
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
OdilonClient.putObject(java.lang.String, java.lang.String, java.io.File)
- Specified by:
putObjectStream
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket nameobjectName
- Object name- Returns:
- Throws:
ODClientException
-
isValidObjectName
Description copied from interface:OdilonClient
Returns
true
if theString
objectName 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
- Specified by:
isValidObjectName
in interfaceOdilonClient
- Parameters:
objectName
- can not be null- Returns:
- true if the objectName is a valid Odilon Object name
- objectName length less or equal to
-
putObjectStream
public io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size, Optional<String> contentType) throws ODClientException Description copied from interface:OdilonClient
Uploads a InputStream to the server. It will create a new object or update it if already exists.
This method calls
OdilonClient.putObject(java.lang.String, java.lang.String, java.io.File)
- Specified by:
putObjectStream
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Returns:
- Throws:
ODClientException
-
putObjectStream
public 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 Description copied from interface:OdilonClient
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
OdilonClient.putObject(java.lang.String, java.lang.String, java.io.File)
- Specified by:
putObjectStream
in interfaceOdilonClient
- Returns:
- Throws:
ODClientException
-
isAcceptAllCertificates
public boolean isAcceptAllCertificates()- Specified by:
isAcceptAllCertificates
in interfaceOdilonClient
-
isSSL
public boolean isSSL()- Specified by:
isSSL
in interfaceOdilonClient
-
putObject
public io.odilon.model.ObjectMetadata putObject(String bucketName, String objectName, File file) throws ODClientException Uploads the
Example:File
file to the serverString endpoint = "http://localhost"; // default port int port = 9234; // default credentials String accessKey = "odilon"; String secretKey = "odilon"; String bucketName = "demo_bucket"; String objectName1 = "demo_object1"; String objectName2 = "demo_object2"; File file1 = new File("test1.pdf"); File file2 = new File("test2.pdf"); // put two objects in the bucket // the bucket must exist before sending the object, // and object names must be unique for that bucket OdilonClient client = new ODClient(endpoint, port, accessKey, secretKey); client.putObject(bucketName, objectName1, file1); client.putObject(bucketName, objectName2, file2);
- Specified by:
putObject
in interfaceOdilonClient
- 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:
ObjectMetadata
of the Object created or updated- Throws:
ODClientException
- See Also:
-
putObject
public io.odilon.model.ObjectMetadata putObject(String bucketName, String objectName, Optional<List<String>> customTags, File file) throws ODClientException Description copied from interface:OdilonClient
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
OdilonClient.putObject(java.lang.String, java.lang.String, java.io.File)
but with a localFile
instead of anInputStream
- Specified by:
putObject
in interfaceOdilonClient
customTags
- Optional List of user defined tags- Returns:
- Throws:
ODClientException
-
putObjectStream
public io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, String fileName, String contentType) throws ODClientException Description copied from interface:OdilonClient
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
InputStream
after sending the data to the server. However, if anException
other thanODClientException
is thrown by this method, theInputStream
may not have been closed.Therefore callers must always attempt to close the
Example:InputStream
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( "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()); }
- Specified by:
putObjectStream
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be nullstream
- can not be null- Returns:
ObjectMetadata
of the Object created or updated- Throws:
ODClientException
-
listObjects
public io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(io.odilon.model.Bucket bucket) throws ODClientException Description copied from interface:OdilonClient
Lists the objects in the
Bucket
.- Specified by:
listObjects
in interfaceOdilonClient
- Parameters:
bucket
- can not be null- Returns:
- ResulSet of Items
- Throws:
ODClientException
-
listObjects
public io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName) throws ODClientException Item
is a wrapper for Lists and otherIterable
structures of T where some elements may not be a T but an error.
T
must be Serializabletry { 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()) ); }
- Specified by:
listObjects
in interfaceOdilonClient
- Parameters:
bucketName
- can not be null- Returns:
- Throws:
ODClientException
-
listObjects
public io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName, String prefix) throws ODClientException Description copied from interface:OdilonClient
Lists the objects in the
Bucket
.- Specified by:
listObjects
in interfaceOdilonClient
- Parameters:
bucketName
- can not be null- Returns:
- Throws:
ODClientException
-
listObjects
public 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 Description copied from interface:OdilonClient
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.
pageSize
is the number of items retrieved by each call to the server, if the value isOptional.empty()
the client will use the default pageSize value.
- Specified by:
listObjects
in interfaceOdilonClient
- Parameters:
bucketName
- can not be null- Returns:
ResultSet<Item<ObjectMetadata>>
. ResultSet isIterable
Item 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
-
listBuckets
Returns all buckets, sorted alphabetically
Example:
List<Bucket> bucketList = odilonClient.listBuckets(); for (Bucket bucket : bucketList) { System.out.println(bucket.creationDate() + ", " + bucket.name()); }
- Specified by:
listBuckets
in interfaceOdilonClient
- Returns:
- List of buckets
- Throws:
ODClientException
-
getObjectMetadataPreviousVersionAll
public List<io.odilon.model.ObjectMetadata> getObjectMetadataPreviousVersionAll(String bucketName, String objectName) throws ODClientException Returns all previous versions of an Object, sorted by version number
- Specified by:
getObjectMetadataPreviousVersionAll
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Returns:
- List of ObjectMetadata sorted by version number
- Throws:
ODClientException
-
isEmpty
Description copied from interface:OdilonClient
Returns
true
if the bucket has no Objects, otherwisefalse
- Specified by:
isEmpty
in interfaceOdilonClient
- Parameters:
bucketName
- can not be null- Returns:
- true if the bucket has no Objects
Throws
ODClientException
if bucketName is not an existing Bucket
the http error codeODHttpStatus.NOT_FOUND
and Odilon's error codeErrorCode.BUCKET_NOT_EXISTS
) - Throws:
ODClientException
-
existsBucket
Description copied from interface:OdilonClient
Returns
true
if a bucket with namebucketName
exists- Specified by:
existsBucket
in interfaceOdilonClient
- Parameters:
bucketName
- can not be null- Returns:
- true if the bucket exists in the Server
- Throws:
ODClientException
-
getBucket
Description copied from interface:OdilonClient
Returns the
Bucket
It will throw a
ODClientException
if 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() ); }
- Specified by:
getBucket
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket name- Returns:
- Bucket
Throws
ODClientException
BucketName is not an existing Bucket ->ODHttpStatus.NOT_FOUND
with error codeErrorCode.BUCKET_NOT_EXISTS
- Throws:
ODClientException
-
createBucket
Description copied from interface:OdilonClient
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_CHARS
and
match the regular expressionSharedConstant.bucket_valid_regex
(seeOdilonClient.isValidBucketName(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()) ); }
- Specified by:
createBucket
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket name Throws ODClientException if the bucket already exists (error codeErrorCode.OBJECT_ALREADY_EXIST
)- Throws:
ODClientException
-
renameBucket
Description copied from interface:OdilonClient
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()) ); }
- Specified by:
renameBucket
in interfaceOdilonClient
- 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
-
addServiceRequest
- Parameters:
requestClass
-- Throws:
ODClientException
-
deleteBucket
Description copied from interface:OdilonClient
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()) ); }
- Specified by:
deleteBucket
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket name ThrowsODHttpStatus.NOT_FOUND
if Bucket does not exist, with error codeErrorCode.BUCKET_NOT_EXISTS
ODHttpStatus.CONFLICT
if Bucket does not exist, with error codeErrorCode.BUCKET_NOT_EMPTY
- Throws:
ODClientException
-
deleteObject
Removes an object from a bucket.
Example:
odilonClient.deleteObject("my-bucketname", "my-objectname");
- Specified by:
deleteObject
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket nameobjectName
- Object name in the bucket- Throws:
ODClientException
-
deleteObjectAllVersions
Description copied from interface:OdilonClient
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.
- Specified by:
deleteObjectAllVersions
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Throws:
ODClientException
-
restoreObjectPreviousVersions
public void restoreObjectPreviousVersions(String bucketName, String objectName) throws ODClientException Description copied from interface:OdilonClient
Restores the previous version of the Object and deletes current version.
If the object does not have any previous versions, it throws an
ODClientException
- Specified by:
restoreObjectPreviousVersions
in interfaceOdilonClient
- 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
OdilonClient.deleteAllBucketVersions(java.lang.String)
orOdilonClient.deleteObjectAllVersions(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
-
deleteAllBucketVersions
Description copied from interface:OdilonClient
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()) ); }
- Specified by:
deleteAllBucketVersions
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket name ThrowsODClientException
Bucket does not exist ->ODHttpStatus.NOT_FOUND
with error codeErrorCode.BUCKET_NOT_EXISTS
Server does not have Version Control enabled ->ODHttpStatus.METHOD_NOT_ALLOWED
with error codeErrorCode.API_NOT_ENABLED
Version Control not enabled- Throws:
ODClientException
-
systemInfo
Returns
SystemInfo
- Specified by:
systemInfo
in interfaceOdilonClient
- Returns:
SystemInfo
- Throws:
ODClientException
-
isVersionControl
Description copied from interface:OdilonClient
Checks if the server has version control enabled
- Specified by:
isVersionControl
in interfaceOdilonClient
- Returns:
- true if the server has version control enabled
- Throws:
ODClientException
-
isHTTPS
public boolean isHTTPS()- Specified by:
isHTTPS
in interfaceOdilonClient
-
metrics
Description copied from interface:OdilonClient
Returns an instance of
MetricsValues
with 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
- Specified by:
metrics
in interfaceOdilonClient
- Returns:
MetricsValues
- Throws:
ODClientException
- Counter
A counter is just a gauge for an AtomicLong instance. You can increment or decrement its value.
-
ping
Returns the String "ok" or a String with the error reported by the Server. If the client can not connect to the Server, the method returns a message "can not connect"
Example:
String pingResult = odilonClient.ping(); if (!pingResult.equals("ok")) { System.out.println( "Server error -> " + pingResult)); }
- Specified by:
ping
in interfaceOdilonClient
- Returns:
- String "ok" or the error reported by the Server.
-
getPresignedObjectUrl
public String getPresignedObjectUrl(String bucketName, String objectName, Optional<Integer> expires, Map<String, String> reqParams) throws ODClientExceptionA 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.
- Throws:
ODClientException
-
getPresignedObjectUrl
public String getPresignedObjectUrl(String bucketName, String objectName, Optional<Integer> expires) throws ODClientException 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.
- Specified by:
getPresignedObjectUrl
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be nullexpires
- duration in seconds for the url to be valid- Returns:
- temporary url to download the file without authentication
- Throws:
ODClientException
-
getPresignedObjectUrl
Returns an presigned URL to download the binary object with default expiry time.
Default expiry time is 7 days in seconds.- Specified by:
getPresignedObjectUrl
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Returns:
- temporary url to download the file without authentication
- Throws:
ODClientException
-
existsObject
public boolean existsObject(String bucketName, String objectName) throws ODClientException, IOException Description copied from interface:OdilonClient
Checks for the existence of an Object.
Note that if the
Bucket
does not exist, the method does not throw anException
, it returnsfalse
- Specified by:
existsObject
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Returns:
- true if the Object exist
Throws
ODClientException
, IOException - Throws:
ODClientException
IOException
-
hasVersions
public boolean hasVersions(String bucketName, String objectName) throws ODClientException, IOException Description copied from interface:OdilonClient
Returns
true
if 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)- Specified by:
hasVersions
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Returns:
true
if the Object has more versions than the head version (ie. the head version must be greater than 0) ThrowsODClientException
Throws IOException- Throws:
ODClientException
IOException
-
getObjectMetadata
public io.odilon.model.ObjectMetadata getObjectMetadata(String bucketName, String objectName) throws ODClientException Returns
ObjectMetadata
of given object in given bucket.Example:
ObjectMetadata meta = odilonClient.getObjectMetadata("my-bucketname", "my-objectname"); System.out.println(meta.toString()));
- Specified by:
getObjectMetadata
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket nameobjectName
- Object name in the bucket- Returns:
ObjectMetadata
from server ThrowsODClientException
if object does not exist- Throws:
ODClientException
-
getObjectMetadataPreviousVersion
public io.odilon.model.ObjectMetadata getObjectMetadataPreviousVersion(String bucketName, String objectName) throws ODClientException Returns
ObjectMetadata
of previous versionExample:
ObjectMetadata meta = odilonClient.getObjectMetadata("my-bucketname", "my-objectname"); System.out.println(meta.toString()));
- Specified by:
getObjectMetadataPreviousVersion
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket name.objectName
- Object name in the bucket.- Returns:
- Throws:
ODClientException
-
getObject
Gets entire object's data as
Example:InputStream
in given bucket. The InputStream must be closed after use else the connection will remain open.InputStream stream = OdilonClient.getObject("my-bucketname", "my-objectname"); byte[] buf = new byte[16384]; int bytesRead; while ((bytesRead = stream.read(buf, 0, buf.length)) >= 0) { System.out.println(new String(buf, 0, bytesRead)); } stream.close();
- Specified by:
getObject
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket nameobjectName
- Object name in the bucket- Returns:
InputStream
containing the object data.- Throws:
ODClientException
-
getObjectPreviousVersion
public InputStream getObjectPreviousVersion(String bucketName, String objectName) throws ODClientException Description copied from interface:OdilonClient
Returns the binary data of the object's previous version or
null
if there is no previous version.- Specified by:
getObjectPreviousVersion
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Returns:
- ObjectMetadata of the object's previous version
- Throws:
ODClientException
-
getObjectVersion
public InputStream getObjectVersion(String bucketName, String objectName, int version) throws ODClientException get InputStream of the version passed as parameter, null if head is version 0 parameter is non existent or previous versions were wiped
- Specified by:
getObjectVersion
in interfaceOdilonClient
- Parameters:
bucketName
- can not be nullobjectName
- can not be null- Returns:
- Throws:
ODClientException
-
getObject
public void getObject(String bucketName, String objectName, String fileName) throws ODClientException, IOException Gets object's data and stores it to given file name.
Example:
odilonClient.getObject("my-bucketname", "my-objectname", "photo.jpg");
- Specified by:
getObject
in interfaceOdilonClient
- Parameters:
bucketName
- Bucket name.objectName
- Object name in the bucket.fileName
- file name.- Throws:
ODClientException
IOException
-
setTimeout
public 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));
- Specified by:
setTimeout
in interfaceOdilonClient
- Parameters:
connectTimeoutMilliseconds
- HTTP connect timeout in milliseconds.writeTimeoutMilliseconds
- HTTP write timeout in milliseconds.readTimeoutMilliseconds
- HTTP read timeout in milliseconds.
-
ignoreCertCheck
Ignores check on server certificate for HTTPS connection.
Example:
odilonClient.ignoreCertCheck();
-
close
Description copied from interface:OdilonClient
Shutdown Isn't Necessary because the threads and connections that are held will be released automatically if they remain idle
- Specified by:
close
in interfaceOdilonClient
- Throws:
ODClientException
-
isValidBucketName
Description copied from interface:OdilonClient
Returns
true
if theString
bucketName 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_regex
Informally speaking: letters A to Z and/or a to z, numbers, and/or - or _
- Specified by:
isValidBucketName
in interfaceOdilonClient
- Parameters:
name
- can not be null- Returns:
- true if the bucketName is a valid Odilon
Bucket
name
- bucketName length less or equal to
-
traceOn
Description copied from interface:OdilonClient
enabled printing the request-response raw info to a stream
- Specified by:
traceOn
in interfaceOdilonClient
-
traceOff
Disables HTTP call tracing previously enabled.
- Specified by:
traceOff
in interfaceOdilonClient
- Throws:
IOException
- upon connection error- See Also:
-
toJSON
-
toString
-
created
-
setChunkSize
public void setChunkSize(int chunkSize) - Specified by:
setChunkSize
in interfaceOdilonClient
-
getChunkSize
public int getChunkSize()- Specified by:
getChunkSize
in interfaceOdilonClient
-
setCharset
- Specified by:
setCharset
in interfaceOdilonClient
-
getCharset
- Specified by:
getCharset
in interfaceOdilonClient
- Returns:
- Charsert "UTF-8" is the default value.
-
getUrl
Description copied from interface:OdilonClient
Returns the url of the Odilon server
- Specified by:
getUrl
in interfaceOdilonClient
- Returns:
- server url (without the port)
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-