Interface OdilonClient
-
- All Known Implementing Classes:
ODClient
public interface OdilonClient
Inteface of a Odilon Object Storage client.
See https://Odilon.ioSee Implementation of this Interface:
ODClient
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addServiceRequest(String requestClass)
void
createBucket(String bucketName)
bucketName length must be lower or equal toSharedConstant.MAX_BUCKET_CHARS
and match the regular expressionSharedConstant.bucket_valid_regex
(seeisValidBucketName(java.lang.String)
)void
deleteAllBucketVersions(String bucketName)
Deletes all Objects' previous versions.void
deleteBucket(String bucketName)
Deletes a bucket.void
deleteObject(String bucketName, String objectName)
Removes an object from a bucket.void
deleteObjectAllVersions(String bucketName, String objectName)
boolean
existsBucket(String bucketName)
boolean
existsObject(String bucketName, String objectName)
Checks the existence of Object: bucketName, objectName
Note that if the bucket does not exist, the method does not throw an Exception, it returns falseio.odilon.model.Bucket
getBucket(String bucketName)
Returns theBucket
InputStream
getObject(String bucketName, String objectName)
void
getObject(String bucketName, String objectName, String fileName)
io.odilon.model.ObjectMetadata
getObjectMetadata(String bucketName, String objectName)
In addition to the binary file, an Object has metadata (calledObjectMetadata
) that is returned by some of the API calls.io.odilon.model.ObjectMetadata
getObjectMetadataPreviousVersion(String bucketName, String objectName)
List<io.odilon.model.ObjectMetadata>
getObjectMetadataPreviousVersionAll(String bucketName, String objectName)
InputStream
getObjectPreviousVersion(String bucketName, String objectName)
InputStream
getObjectVersion(String bucketName, String objectName, int version)
String
getPresignedObjectUrl(String bucketName, String objectName)
This is method callsgetPresignedObjectUrl(java.lang.String, java.lang.String, java.util.Optional<java.lang.Integer>)
with the default value for expiresInSeconds (7 days in seconds)String
getPresignedObjectUrl(String bucketName, String objectName, Optional<Integer> expiresInSeconds)
A presigned URL is a way to grant temporary access to an Object, for example in an HTML webpage.String
getUrl()
boolean
hasVersions(String bucketName, String objectName)
boolean
isEmpty(String bucketName)
boolean
isValidBucketName(String bucketName)
Max length:SharedConstant.MAX_BUCKET_CHARS
Regular expression that must match:SharedConstant.bucket_valid_regex
boolean
isVersionControl()
List<io.odilon.model.Bucket>
listBuckets()
Returns all buckets, sorted alphabeticallyio.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>>
listObjects(io.odilon.model.Bucket bucket)
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>>
listObjects(String bucketName)
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>>
listObjects(String bucketName, String prefix)
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>>
listObjects(String bucketName, Optional<String> prefix, Optional<Integer> pageSize)
Item <T>
is a wrapper for Lists and other iterable structures ofT
where some elements may not be aT
but an error.
T
must be Serializableio.odilon.model.MetricsValues
metrics()
MetricsValues
String
ping()
Returns the String "ok" or a String with the error reported by the Server.io.odilon.model.ObjectMetadata
putObject(String bucketName, String objectName, File file)
This method does the same asputObject(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String, java.lang.String)
but with a localFile
instead of anInputStream
io.odilon.model.ObjectMetadata
putObject(String bucketName, String objectName, InputStream stream, String fileName, String contentType)
Odilon stores objects using a flat structure of containers called Buckets.io.odilon.model.ObjectMetadata
putObjectStream(String bucketName, String objectName, InputStream stream, String fileName)
io.odilon.model.ObjectMetadata
putObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size)
io.odilon.model.ObjectMetadata
putObjectStream(String bucketName, String objectName, InputStream stream, Optional<String> fileName, Optional<Long> size, Optional<String> contentType)
void
restoreObjectPreviousVersions(String bucketName, String objectName)
void
setTimeout(long connectTimeout, long writeTimeout, long readTimeout)
======================================= CLIENT SETTINGS ==========================================io.odilon.model.SystemInfo
systemInfo()
SystemInfo
void
traceOff()
void
traceOn(OutputStream traceStream)
======================================= DEBUG ==========================================
-
-
-
Method Detail
-
createBucket
void createBucket(String bucketName) throws ODClientException
bucketName length must be lower or equal to
Example:SharedConstant.MAX_BUCKET_CHARS
and 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( String.valueOf(e.getHttpStatus())+ " " + e.getMessage() + " " + String.valueOf(e.getErrorCode()) ); }
- Parameters:
bucketName
- Bucket name- Throws:
ODClientException
- if the bucket already exists (error codeErrorCode.OBJECT_ALREADY_EXIST
)
-
listBuckets
List<io.odilon.model.Bucket> listBuckets() throws ODClientException
Returns all buckets, sorted alphabetically
Example:
OdilonClient odilonClient = new ODClient(url, port, accessKey, secretKey); List<Bucket> bucketList = odilonClient.listBuckets(); for (Bucket bucket : bucketList) { System.out.println(bucket.creationDate() + ", " + bucket.name()); }
- Returns:
- List of Buckets
- Throws:
ODClientException
-
isValidBucketName
boolean isValidBucketName(String bucketName) throws ODClientException
- Max length:
SharedConstant.MAX_BUCKET_CHARS
- Regular expression that must match:
SharedConstant.bucket_valid_regex
- Parameters:
bucketName
- Bucket name- Returns:
- whether the bucketName is a valid Odilon bucket name
- Throws:
ODClientException
- Max length:
-
existsBucket
boolean existsBucket(String bucketName) throws ODClientException
- Parameters:
bucketName
-- Returns:
- whether the bucket exists in the Server
- Throws:
ODClientException
-
isEmpty
boolean isEmpty(String bucketName) throws ODClientException
- Parameters:
bucketName
- Bucket name- Returns:
- true if the bucket has no Objects
- Throws:
ODClientException
-
getBucket
io.odilon.model.Bucket getBucket(String bucketName) throws ODClientException
Returns the
Bucket
- Parameters:
bucketName
- Bucket name- Returns:
- Bucket
- Throws:
ODClientException
- if the Bucket does not exist the error codegetErrorCode()
returnsErrorCode.BUCKET_NOT_EXISTS
-
deleteBucket
void deleteBucket(String bucketName) throws ODClientException
Deletes a bucket. The bucket must be empty to be deleted
- Parameters:
bucketName
- Bucket name- Throws:
ODClientException
-
Bucket does not exist ->ODHttpStatus.NOT_FOUND
with error codeErrorCode.BUCKET_NOT_EXISTS
Bucket is not empty ->with error code {@link ErrorCode.BUCKET_NOT_EMPTY}
-
deleteAllBucketVersions
void deleteAllBucketVersions(String bucketName) throws ODClientException
Deletes all Objects' previous versions. It does not delete the current version (called head version).
This method is sometimes used to free disk in the serverThe method returns immediately after sending the command to the server. The command is processed asynchronously in the server.
- Parameters:
bucketName
- Bucket name- Throws:
ODClientException
-
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
-
existsObject
boolean existsObject(String bucketName, String objectName) throws ODClientException, IOException
Checks the existence of Object: bucketName, objectName
Note that if the bucket does not exist, the method does not throw an Exception, it returns false- Parameters:
bucketName
- Bucket nameobjectName
- Object name- Returns:
- true if the Object exist
- Throws:
ODClientException
IOException
-
getObjectMetadata
io.odilon.model.ObjectMetadata getObjectMetadata(String bucketName, String objectName) throws ODClientException
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.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.
- Parameters:
bucketName
- Bucket nameobjectName
- Object name- Returns:
- Throws:
ODClientException
-
getObject
InputStream getObject(String bucketName, String objectName) throws ODClientException
- Parameters:
bucketName
- Bucket nameobjectName
- Object name- Throws:
ODClientException
-
getObject
void getObject(String bucketName, String objectName, String fileName) throws ODClientException, IOException
- Parameters:
bucketName
- Bucket nameobjectName
- Object namefileName
- path and file name where to save to data downloaded- Throws:
ODClientException
IOException
-
getPresignedObjectUrl
String getPresignedObjectUrl(String bucketName, String objectName, Optional<Integer> expiresInSeconds) 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.
Example: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
- Bucket nameobjectName
- Object nameexpiresInSeconds
- duration in seconds for the url to be valid- Returns:
- temporary url to download the file without authentication
- Throws:
ODClientException
-
getPresignedObjectUrl
String getPresignedObjectUrl(String bucketName, String objectName) throws ODClientException
This is method calls
getPresignedObjectUrl(java.lang.String, java.lang.String, java.util.Optional<java.lang.Integer>)
with the default value for expiresInSeconds (7 days in seconds)- Parameters:
bucketName
- Bucket nameobjectName
- Object name- Returns:
- Throws:
ODClientException
-
putObject
io.odilon.model.ObjectMetadata putObject(String bucketName, String objectName, InputStream stream, String fileName, String contentType) throws ODClientException
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.
The 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(String.valueOf(e.getHttpStatus())+" " + e.getMessage() +" " + String.valueOf(e.getErrorCode())); } catch (FileNotFoundException | IOException e1) { System.out.println(e1.getMessage()); }
- Parameters:
bucketName
- Bucket nameobjectName
- Object namestream
-fileName
-contentType
-- Returns:
ObjectMetadata
of the Object created or updated- Throws:
ODClientException
-
putObject
io.odilon.model.ObjectMetadata putObject(String bucketName, String objectName, File file) throws ODClientException
This method does the same as
putObject(java.lang.String, java.lang.String, java.io.InputStream, java.lang.String, java.lang.String)
but with a localFile
instead of anInputStream
- Parameters:
bucketName
- Bucket nameobjectName
- Object namefile
-- Returns:
ObjectMetadata
of the Object created or updated- Throws:
ODClientException
-
putObjectStream
io.odilon.model.ObjectMetadata putObjectStream(String bucketName, String objectName, InputStream stream, String fileName) throws ODClientException
- Parameters:
bucketName
- Bucket nameobjectName
- Object namestream
-fileName
-- Returns:
- 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
- Parameters:
bucketName
- Bucket nameobjectName
- Object namestream
-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
- Parameters:
bucketName
- Bucket nameobjectName
- Object namestream
-fileName
-size
-- Returns:
- Throws:
ODClientException
-
deleteObject
void deleteObject(String bucketName, String objectName) throws ODClientException
Removes an object from a bucket.
Example:
odilonClient.deleteObject("my-bucketname", "my-objectname");
- Parameters:
bucketName
- Bucket nameobjectName
- Object name in the bucket- Throws:
ODClientException
-
hasVersions
boolean hasVersions(String bucketName, String objectName) throws ODClientException, IOException
- Parameters:
bucketName
- Bucket nameobjectName
- Object name- Returns:
true
if the Object has more versions than the head version (ie. the head version must be greater than 0)- Throws:
ODClientException
IOException
-
getObjectMetadataPreviousVersion
io.odilon.model.ObjectMetadata getObjectMetadataPreviousVersion(String bucketName, String objectName) throws ODClientException
- Throws:
ODClientException
-
getObjectMetadataPreviousVersionAll
List<io.odilon.model.ObjectMetadata> getObjectMetadataPreviousVersionAll(String bucketName, String objectName) throws ODClientException
- Throws:
ODClientException
-
getObjectPreviousVersion
InputStream getObjectPreviousVersion(String bucketName, String objectName) throws ODClientException
- Throws:
ODClientException
-
getObjectVersion
InputStream getObjectVersion(String bucketName, String objectName, int version) throws ODClientException
- Throws:
ODClientException
-
deleteObjectAllVersions
void deleteObjectAllVersions(String bucketName, String objectName) throws ODClientException
- Throws:
ODClientException
-
restoreObjectPreviousVersions
void restoreObjectPreviousVersions(String bucketName, String objectName) throws ODClientException
- 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
Item <T>
is a wrapper for Lists and other iterable structures ofT
where some elements may not be aT
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()) ); }
- Throws:
ODClientException
-
listObjects
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName, String prefix) throws ODClientException
- Parameters:
bucketName
- Bucket nameprefix
-- Returns:
- Throws:
ODClientException
-
listObjects
io.odilon.model.list.ResultSet<io.odilon.model.list.Item<io.odilon.model.ObjectMetadata>> listObjects(String bucketName) throws ODClientException
- Parameters:
bucketName
- Bucket name- 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
- Parameters:
bucketName
- Bucket name- Returns:
- Throws:
ODClientException
-
ping
String ping()
Returns the String "ok" or a String with the error reported by the Server.
Example:
If the client can not connect to the Server, the method returns a message "can not connect"{@code 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
io.odilon.model.MetricsValues metrics() throws ODClientException
MetricsValues
- Returns:
- Throws:
ODClientException
-
systemInfo
io.odilon.model.SystemInfo systemInfo() throws ODClientException
SystemInfo
- Returns:
- Throws:
ODClientException
-
isVersionControl
boolean isVersionControl() throws ODClientException
- Returns:
- true if the server has version control enabled
- Throws:
ODClientException
-
getUrl
String getUrl()
- Returns:
- server url (without the port)
-
setTimeout
void setTimeout(long connectTimeout, long writeTimeout, long readTimeout)
======================================= CLIENT SETTINGS ==========================================
-
traceOn
void traceOn(OutputStream traceStream)
======================================= DEBUG ==========================================
-
traceOff
void traceOff() throws IOException
- Throws:
IOException
-
addServiceRequest
void addServiceRequest(String requestClass) throws ODClientException
- Throws:
ODClientException
-
-