public final class SwiftRestClient extends Object
Modifier and Type | Field and Description |
---|---|
static org.apache.commons.httpclient.Header |
NEWEST
Header that says "use newest version" -ensures that
the query doesn't pick up older versions served by
an eventually consistent filesystem (except in the special case
of a network partition, at which point no guarantees about
consistency can be made.
|
Modifier and Type | Method and Description |
---|---|
AccessToken |
authenticate()
Authenticate to Openstack Keystone
As well as returning the access token, the member fields
token ,
endpointURI and objectLocationURI are set up for re-use. |
boolean |
copyObject(SwiftObjectPath src,
SwiftObjectPath dst,
org.apache.commons.httpclient.Header... headers)
Copy an object.
|
void |
createContainer(String containerName)
Create a container -if it already exists, do nothing
|
boolean |
delete(SwiftObjectPath path,
org.apache.commons.httpclient.Header... requestHeaders)
Deletes object from swift.
|
byte[] |
findObjectsByPrefix(SwiftObjectPath path,
org.apache.commons.httpclient.Header... requestHeaders)
Find objects under a prefix
|
long |
getBlocksizeKB()
Get the blocksize of this filesystem
|
int |
getBufferSizeKB()
Get the buffer size in KB
|
int |
getConnectTimeout() |
String |
getContainer()
Get the container to which this client is bound
|
long |
getContentLength(SwiftObjectPath path)
Get the length of the remote object
|
long |
getContentLength(URI uri)
Returns object length
|
HttpBodyContent |
getData(SwiftObjectPath path,
org.apache.commons.httpclient.Header... requestHeaders)
Get the path contents as an input stream.
|
HttpBodyContent |
getData(SwiftObjectPath path,
long offset,
long length)
Make an HTTP GET request to Swift to get a range of data in the object.
|
static SwiftRestClient |
getInstance(URI filesystemURI,
org.apache.hadoop.conf.Configuration config)
Create an instance against a specific FS URI,
|
byte[] |
getObjectLocation(SwiftObjectPath path,
org.apache.commons.httpclient.Header... requestHeaders)
Returns object location as byte[]
|
List<DurationStats> |
getOperationStatistics()
Get the current operation statistics
|
int |
getPartSizeKB()
Get the partition size in KB
|
String |
getProxyHost() |
int |
getProxyPort() |
String |
getRegion()
Get the region which this client is bound to
|
int |
getRetryCount() |
String |
getTenant()
Get the tenant to which this client is bound
|
int |
getThrottleDelay() |
String |
getUsername()
Get the username this client identifies itself as
|
org.apache.commons.httpclient.Header[] |
headRequest(String reason,
SwiftObjectPath path,
org.apache.commons.httpclient.Header... requestHeaders)
Issue a head request
|
boolean |
isLocationAware()
Is this client bound to a location aware Swift blobstore
-that is, can you query for the location of partitions
|
boolean |
isUsePublicURL() |
byte[] |
listDeepObjectsInDirectory(SwiftObjectPath path,
boolean listDeep,
org.apache.commons.httpclient.Header... requestHeaders)
Find objects in a directory
|
static URI |
pathToURI(SwiftObjectPath path,
URI endpointURI)
Converts Swift path to URI to make request.
|
int |
putRequest(SwiftObjectPath path,
org.apache.commons.httpclient.Header... requestHeaders)
Issue a put request
|
String |
toString() |
void |
upload(SwiftObjectPath path,
InputStream data,
long length,
org.apache.commons.httpclient.Header... requestHeaders)
Uploads file as Input Stream to Swift.
|
public static final org.apache.commons.httpclient.Header NEWEST
public HttpBodyContent getData(SwiftObjectPath path, long offset, long length) throws IOException
path
- path to objectoffset
- offset from file beginninglength
- file lengthIOException
- ProblemsSwiftException
- swift specific errorFileNotFoundException
- path is not therepublic long getContentLength(URI uri) throws IOException
uri
- file URISwiftException
- on swift-related issuesIOException
- on network/IO problemspublic long getContentLength(SwiftObjectPath path) throws IOException
path
- object to probeIOException
- on any failurepublic HttpBodyContent getData(SwiftObjectPath path, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
path
- path to filerequestHeaders
- http headersIOException
- on IO FaultsFileNotFoundException
- if there is nothing at the pathpublic byte[] getObjectLocation(SwiftObjectPath path, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
path
- path to filerequestHeaders
- http headersIOException
- on IO Faultspublic byte[] findObjectsByPrefix(SwiftObjectPath path, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
path
- path prefixrequestHeaders
- optional request headersIOException
- on IO FaultsFileNotFoundException
- if nothing is at the end of the URI -that is,
the directory is emptypublic byte[] listDeepObjectsInDirectory(SwiftObjectPath path, boolean listDeep, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
path
- path prefixrequestHeaders
- optional request headersIOException
- on IO FaultsFileNotFoundException
- if nothing is at the end of the URI -that is,
the directory is emptypublic boolean copyObject(SwiftObjectPath src, SwiftObjectPath dst, org.apache.commons.httpclient.Header... headers) throws IOException
src
- source pathdst
- destination pathheaders
- any headersIOException
- on IO Faultspublic void upload(SwiftObjectPath path, InputStream data, long length, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
path
- path to Swiftdata
- object datalength
- length of datarequestHeaders
- http headersIOException
- on IO Faultspublic boolean delete(SwiftObjectPath path, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
path
- path to filerequestHeaders
- http headersIOException
- on IO Faultspublic org.apache.commons.httpclient.Header[] headRequest(String reason, SwiftObjectPath path, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
reason
- reason -used in logspath
- path to queryrequestHeaders
- request headerIOException
- IO problemsFileNotFoundException
- if there is nothing at the endpublic int putRequest(SwiftObjectPath path, org.apache.commons.httpclient.Header... requestHeaders) throws IOException
path
- pathrequestHeaders
- optional headersIOException
- any problempublic AccessToken authenticate() throws IOException
token
,
endpointURI
and objectLocationURI
are set up for re-use.
This method is re-entrant -if more than one thread attempts to authenticate
neither will block -but the field values with have those of the last caller.
IOException
public void createContainer(String containerName) throws IOException
containerName
- the container nameIOException
- IO problemsSwiftBadRequestException
- invalid container nameSwiftInvalidResponseException
- error from the serverpublic static SwiftRestClient getInstance(URI filesystemURI, org.apache.hadoop.conf.Configuration config) throws IOException
filesystemURI
- filesystem to bond toconfig
- source of configuration dataIOException
- on instantiation problemspublic static URI pathToURI(SwiftObjectPath path, URI endpointURI) throws SwiftException
path
- path to objectendpointURI
- damain url e.g. http://domain.comSwiftException
public String getRegion()
public String getTenant()
public String getUsername()
public String getContainer()
public boolean isLocationAware()
public long getBlocksizeKB()
public int getPartSizeKB()
public int getBufferSizeKB()
public int getProxyPort()
public String getProxyHost()
public int getRetryCount()
public int getConnectTimeout()
public boolean isUsePublicURL()
public int getThrottleDelay()
public List<DurationStats> getOperationStatistics()
Copyright © 2015 Apache Software Foundation. All Rights Reserved.