Search in sources :

Example 21 with StoredObject

use of org.javaswift.joss.model.StoredObject in project stocator by CODAIT.

the class SwiftAPIClient method rename.

@Override
public boolean rename(String hostName, String srcPath, String dstPath) throws IOException {
    LOG.debug("Rename from {} to {}. hostname is {}", srcPath, dstPath, hostName);
    String objNameSrc = srcPath.toString();
    if (srcPath.toString().startsWith(hostName)) {
        objNameSrc = getObjName(hostName, srcPath);
    }
    String objNameDst = dstPath.toString();
    if (objNameDst.toString().startsWith(hostName)) {
        objNameDst = getObjName(hostName, dstPath);
    }
    if (stocatorPath.isTemporaryPathContain(objNameSrc)) {
        LOG.debug("Rename on the temp object {}. Return true", objNameSrc);
        return true;
    }
    LOG.debug("Rename modified from {} to {}", objNameSrc, objNameDst);
    Container cont = mJossAccount.getAccount().getContainer(container);
    StoredObject so = cont.getObject(objNameSrc);
    StoredObject soDst = cont.getObject(objNameDst);
    so.copyObject(cont, soDst);
    return true;
}
Also used : Container(org.javaswift.joss.model.Container) StoredObject(org.javaswift.joss.model.StoredObject)

Example 22 with StoredObject

use of org.javaswift.joss.model.StoredObject in project stocator by CODAIT.

the class SwiftAPIClient method delete.

@Override
public boolean delete(String hostName, Path path, boolean recursive) throws IOException {
    String obj = path.toString();
    if (path.toString().startsWith(hostName)) {
        obj = getObjName(hostName, path);
    }
    LOG.debug("Object name to delete {}. Path {}", obj, path.toString());
    try {
        StoredObject so = mJossAccount.getAccount().getContainer(container).getObject(obj);
        if (so.exists()) {
            so.delete();
            objectCache.remove(obj);
        }
    } catch (Exception e) {
        LOG.warn(e.getMessage());
        LOG.warn("Delete on {} resulted in FileNotFound exception", path);
        return false;
    }
    return true;
}
Also used : StoredObject(org.javaswift.joss.model.StoredObject) ConfigurationParseException(com.ibm.stocator.fs.common.exception.ConfigurationParseException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AlreadyExistsException(org.javaswift.joss.exception.AlreadyExistsException) IOException(java.io.IOException)

Example 23 with StoredObject

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

the class SwiftMockOutputStream method close.

@Override
public void close() throws IOException {
    if (mClosed) {
        return;
    }
    mOutputStream.close();
    try {
        Container container = mAccount.getContainer(mContainerName);
        StoredObject object = container.getObject(mObjectName);
        object.uploadObject(mFile);
    } catch (Exception e) {
        throw new IOException(e);
    }
    // Close successful
    mClosed = true;
}
Also used : Container(org.javaswift.joss.model.Container) StoredObject(org.javaswift.joss.model.StoredObject) IOException(java.io.IOException) IOException(java.io.IOException)

Example 24 with StoredObject

use of org.javaswift.joss.model.StoredObject 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)

Example 25 with StoredObject

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

the class SwiftUnderFileSystem method createEmptyObject.

@Override
public 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)

Aggregations

StoredObject (org.javaswift.joss.model.StoredObject)26 IOException (java.io.IOException)9 Container (org.javaswift.joss.model.Container)8 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)3 StocatorPath (com.ibm.stocator.fs.common.StocatorPath)2 ConfigurationParseException (com.ibm.stocator.fs.common.exception.ConfigurationParseException)2 JossAccount (com.ibm.stocator.fs.swift.auth.JossAccount)2 DataFile (edu.harvard.iq.dataverse.DataFile)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 Path (org.apache.hadoop.fs.Path)2 AlreadyExistsException (org.javaswift.joss.exception.AlreadyExistsException)2 CommandException (org.javaswift.joss.exception.CommandException)2 Account (org.javaswift.joss.model.Account)2 DirectoryOrObject (org.javaswift.joss.model.DirectoryOrObject)2 Dataset (edu.harvard.iq.dataverse.Dataset)1 File (java.io.File)1 Date (java.util.Date)1 Properties (java.util.Properties)1