Difference between revisions of "Storage Manager"

From Gcube Wiki
Jump to: navigation, search
(Sample Usage)
(Sample Usage)
Line 77: Line 77:
 
  IClient client=new StorageClient("PortletsUser", "HomeLibrary", "HomeLibrary-ContentManager", AccessType.SHARED, scope).getClient();
 
  IClient client=new StorageClient("PortletsUser", "HomeLibrary", "HomeLibrary-ContentManager", AccessType.SHARED, scope).getClient();
 
</code>
 
</code>
 +
  
 
The following code explains how to upload a new file in the storage repository:
 
The following code explains how to upload a new file in the storage repository:
Line 82: Line 83:
 
  String id=client.put(true).LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFile("/img/pippo.jpg");
 
  String id=client.put(true).LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFile("/img/pippo.jpg");
 
</code>
 
</code>
 +
  
 
The following code explains how to download a file from the storage repository:
 
The following code explains how to download a file from the storage repository:
Line 87: Line 89:
 
  client.get().LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFile("/img/pippo.jpg");
 
  client.get().LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFile("/img/pippo.jpg");
 
</code>
 
</code>
 +
or alternatively, retrieve the file by Id
 +
<code>
 +
client.get().LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFileById(id);
 +
</code>
 +
  
The following code explains how to show the contents of a remote directoory on the storage repository:
+
The following code explains how to show the contents of a remote directory on the storage repository:
 
<code>
 
<code>
 
  List<StorageObject> list=client.showDir().RDir("img");
 
  List<StorageObject> list=client.showDir().RDir("img");
Line 107: Line 114:
 
  client.remove().RFile("/img/pluto.jpg");
 
  client.remove().RFile("/img/pluto.jpg");
 
</code>
 
</code>
 +
or alternatively, remove the file by Id
 +
<code>
 +
client.remove()..RFileById(id);
 +
</code>
 +
  
 
The following code explains how to remove a dir on the storage repository:
 
The following code explains how to remove a dir on the storage repository:

Revision as of 16:44, 3 April 2012

== Role ==



Role

Library for access and storage of unstructured bytestreams, or files, can be provided through a standards-based, POSIX-like API which supports the organisation and operations normally associated with local file systems whilst offering scalable and fault-tolerant remote storage.

The library acts a facade to the service and allows clients to download, upload, remove, add, and list files. Files have owners and owners may define access rights to files, allowing private, public, or group-based access.

Access Mode

There are 3 ways to access remote files

Private
Accessible only to the owner of the file
Public
accessible to all users of the community
Shared
Accessible to all users of the same group that owner


The credentials to use the library are:

GroupID
identification of the group or community membership
ClientID
the user ID, must be secret to protect their data

Operations

The StorageManger library implements many operation on remote file, the methods LFile and RFile refer to, respectively, Local File (if needed) and Remote File. In the call's signature, there are preceded from a method that identify a operation:

put(boolean replace)
put a local file in a remote directory. If replace is true then the remote file, if exist, will be replaced, false otherwise.
Example: put(true).LFile(“localPath”).RFile(“remotePath”)
get()
downloads a file from a remote path to a local directory
Example: get().LFile(“localPath”).RFile(“remotePath”);
remove()
removes a remote file
Example: remove().RFile(“remotePath”);
removeDir()
removes a remote directory
Example removeDir().LFile(“remoteDirPath”);
showDir()
shows the content of a directory
Example showDir.RFile(“remoteDirPAth”);
lock()
locks a remote file to prevent multiple access
Example lock().RFile(“remotePath”);
unlock(String lockKey)
unlocks a remote file
Example unlock(“key”).RFile(“remotePath”);
getTTL()
return the TimeToLive associated to a remote file if the file is currently locked
Example getTTL().RFile("remote/path/to/dir");
setTTL(int milliseconds)
set the TimeToLive to a remote file that is currently locked. This operation is consented max 5 times for any file.
Example setTTL(180000).RFile("remote/path/to/dir");

Sample Usage

The following code explains how to instatiate a client for do remote operation on the storage repository:

GCUBEScope scope = GCUBEScope.getScope("/gcube");
IClient client=new StorageClient("PortletsUser", "HomeLibrary", "HomeLibrary-ContentManager", AccessType.SHARED, scope).getClient();


The following code explains how to upload a new file in the storage repository:

String id=client.put(true).LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFile("/img/pippo.jpg");


The following code explains how to download a file from the storage repository:

client.get().LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFile("/img/pippo.jpg");

or alternatively, retrieve the file by Id

client.get().LFile("/home/rcirillo/FilePerTest/pippo.jpg").RFileById(id);


The following code explains how to show the contents of a remote directory on the storage repository:

List<StorageObject> list=client.showDir().RDir("img");

The following code explains how to lock a file on the storage repository:

String id=client.lock().RFile("/img/pluto.jpg");

The following code explains how to unlock a file on the storage repository:

client.unlock(id).RFile("/img/pluto.jpg");

The following code explains how to remove a file on the storage repository:

client.remove().RFile("/img/pluto.jpg");

or alternatively, remove the file by Id

client.remove()..RFileById(id);


The following code explains how to remove a dir on the storage repository:

client.removeDir().RDir("/img");