Search in sources :

Example 1 with WrappedKeyAlreadyExistsException

use of org.apache.storm.utils.WrappedKeyAlreadyExistsException in project storm by apache.

the class HdfsBlobStore method createBlob.

@Override
public AtomicOutputStream createBlob(String key, SettableBlobMeta meta, Subject who) throws AuthorizationException, KeyAlreadyExistsException {
    if (meta.get_replication_factor() <= 0) {
        meta.set_replication_factor((int) conf.get(Config.STORM_BLOBSTORE_REPLICATION_FACTOR));
    }
    who = checkAndGetSubject(who);
    validateKey(key);
    aclHandler.normalizeSettableBlobMeta(key, meta, who, READ | WRITE | ADMIN);
    BlobStoreAclHandler.validateSettableACLs(key, meta.get_acl());
    aclHandler.hasPermissions(meta.get_acl(), READ | WRITE | ADMIN, who, key);
    if (hbs.exists(DATA_PREFIX + key)) {
        throw new WrappedKeyAlreadyExistsException(key);
    }
    BlobStoreFileOutputStream outputStream = null;
    try {
        BlobStoreFile metaFile = hbs.write(META_PREFIX + key, true);
        metaFile.setMetadata(meta);
        outputStream = new BlobStoreFileOutputStream(metaFile);
        outputStream.write(Utils.thriftSerialize(meta));
        outputStream.close();
        outputStream = null;
        BlobStoreFile dataFile = hbs.write(DATA_PREFIX + key, true);
        dataFile.setMetadata(meta);
        cacheMetas.put(key, meta);
        return new BlobStoreFileOutputStream(dataFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.cancel();
            } catch (IOException e) {
            // Ignored
            }
        }
    }
}
Also used : WrappedKeyAlreadyExistsException(org.apache.storm.utils.WrappedKeyAlreadyExistsException) BlobStoreFile(org.apache.storm.blobstore.BlobStoreFile) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 BlobStoreFile (org.apache.storm.blobstore.BlobStoreFile)1 WrappedKeyAlreadyExistsException (org.apache.storm.utils.WrappedKeyAlreadyExistsException)1