Search in sources :

Example 1 with Container

use of org.javaswift.joss.model.Container in project alluxio by Alluxio.

the class SwiftUnderFileSystem method getObjectListingChunk.

@Override
protected ObjectListingChunk getObjectListingChunk(String key, boolean recursive) throws IOException {
    Container container = mAccount.getContainer(mContainerName);
    String prefix = PathUtils.normalizePath(key, PATH_SEPARATOR);
    // In case key is root (empty string) do not normalize prefix
    prefix = prefix.equals(PATH_SEPARATOR) ? "" : prefix;
    PaginationMap paginationMap = container.getPaginationMap(prefix, getListingChunkLength());
    if (paginationMap != null && paginationMap.getNumberOfPages() > 0) {
        return new SwiftObjectListingChunk(paginationMap, 0, recursive);
    }
    return null;
}
Also used : Container(org.javaswift.joss.model.Container) PaginationMap(org.javaswift.joss.model.PaginationMap)

Example 2 with Container

use of org.javaswift.joss.model.Container in project alluxio by Alluxio.

the class SwiftUnderFileSystem method getObjectStatus.

@Override
protected ObjectStatus getObjectStatus(String key) {
    Container container = mAccount.getContainer(mContainerName);
    StoredObject meta = container.getObject(key);
    if (meta != null && meta.exists()) {
        return new ObjectStatus(meta.getContentLength(), meta.getLastModifiedAsDate().getTime());
    }
    return null;
}
Also used : Container(org.javaswift.joss.model.Container) StoredObject(org.javaswift.joss.model.StoredObject)

Example 3 with Container

use of org.javaswift.joss.model.Container in project alluxio by Alluxio.

the class SwiftUnderFileSystem method copyObject.

@Override
protected boolean copyObject(String source, String destination) {
    LOG.debug("copy from {} to {}", source, destination);
    // Retry copy for a few times, in case some Swift internal errors happened during copy.
    for (int i = 0; i < NUM_RETRIES; i++) {
        try {
            Container container = mAccount.getContainer(mContainerName);
            container.getObject(source).copyObject(container, container.getObject(destination));
            return true;
        } catch (CommandException e) {
            LOG.error("Source path {} does not exist", source);
            return false;
        } catch (Exception e) {
            LOG.error("Failed to copy file {} to {}", source, destination, e.getMessage());
            if (i != NUM_RETRIES - 1) {
                LOG.error("Retrying copying file {} to {}", source, destination);
            }
        }
    }
    LOG.error("Failed to copy file {} to {}, after {} retries", source, destination, NUM_RETRIES);
    return false;
}
Also used : Container(org.javaswift.joss.model.Container) CommandException(org.javaswift.joss.exception.CommandException) IOException(java.io.IOException) CommandException(org.javaswift.joss.exception.CommandException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException)

Example 4 with Container

use of org.javaswift.joss.model.Container in project alluxio by Alluxio.

the class SwiftUnderFileSystem method createEmptyObject.

@Override
protected boolean createEmptyObject(String key) {
    try {
        Container container = mAccount.getContainer(mContainerName);
        StoredObject object = container.getObject(key);
        object.uploadObject(new byte[0]);
        return true;
    } catch (CommandException e) {
        LOG.error("Failed to create object: {}", key, e);
        return false;
    }
}
Also used : Container(org.javaswift.joss.model.Container) StoredObject(org.javaswift.joss.model.StoredObject) CommandException(org.javaswift.joss.exception.CommandException)

Example 5 with Container

use of org.javaswift.joss.model.Container in project alluxio by Alluxio.

the class SwiftUnderFileSystem method deleteObject.

@Override
protected boolean deleteObject(String path) throws IOException {
    try {
        Container container = mAccount.getContainer(mContainerName);
        StoredObject object = container.getObject(path);
        if (object != null) {
            object.delete();
            return true;
        }
    } catch (CommandException e) {
        LOG.debug("Object {} not found", path);
    }
    return false;
}
Also used : Container(org.javaswift.joss.model.Container) StoredObject(org.javaswift.joss.model.StoredObject) CommandException(org.javaswift.joss.exception.CommandException)

Aggregations

Container (org.javaswift.joss.model.Container)10 StoredObject (org.javaswift.joss.model.StoredObject)6 IOException (java.io.IOException)3 CommandException (org.javaswift.joss.exception.CommandException)3 FileNotFoundException (java.io.FileNotFoundException)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1 StocatorPath (com.ibm.stocator.fs.common.StocatorPath)1 ConfigurationParseException (com.ibm.stocator.fs.common.exception.ConfigurationParseException)1 DummyAccessProvider (com.ibm.stocator.fs.swift.auth.DummyAccessProvider)1 JossAccount (com.ibm.stocator.fs.swift.auth.JossAccount)1 PasswordScopeAccessProvider (com.ibm.stocator.fs.swift.auth.PasswordScopeAccessProvider)1 SwiftConnectionManager (com.ibm.stocator.fs.swift.http.SwiftConnectionManager)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Path (org.apache.hadoop.fs.Path)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 AccountConfig (org.javaswift.joss.client.factory.AccountConfig)1 AlreadyExistsException (org.javaswift.joss.exception.AlreadyExistsException)1