Search in sources :

Example 1 with BufferInputStream

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

the class Nimbus method downloadBlobChunk.

@SuppressWarnings("deprecation")
@Override
public ByteBuffer downloadBlobChunk(String session) throws AuthorizationException, TException {
    try {
        BufferInputStream is = blobDownloaders.get(session);
        if (is == null) {
            throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)");
        }
        byte[] ret = is.read();
        if (ret.length == 0) {
            is.close();
            blobDownloaders.remove(session);
        } else {
            blobDownloaders.put(session, is);
        }
        LOG.debug("Sending {} bytes", ret.length);
        return ByteBuffer.wrap(ret);
    } catch (Exception e) {
        LOG.warn("download blob chunk exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : BufferInputStream(org.apache.storm.utils.BufferInputStream) TException(org.apache.storm.thrift.TException) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 2 with BufferInputStream

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

the class Nimbus method beginBlobDownload.

@SuppressWarnings("deprecation")
@Override
public BeginDownloadResult beginBlobDownload(String key) throws AuthorizationException, KeyNotFoundException, TException {
    try {
        InputStreamWithMeta is = blobStore.getBlob(key, getSubject());
        String sessionId = Utils.uuid();
        BeginDownloadResult ret = new BeginDownloadResult(is.getVersion(), sessionId);
        ret.set_data_size(is.getFileLength());
        blobDownloaders.put(sessionId, new BufferInputStream(is, (int) conf.getOrDefault(Config.STORM_BLOBSTORE_INPUTSTREAM_BUFFER_SIZE_BYTES, 65536)));
        LOG.info("Created download session {} for {}", sessionId, key);
        return ret;
    } catch (Exception e) {
        LOG.warn("begin blob download exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : BufferInputStream(org.apache.storm.utils.BufferInputStream) TException(org.apache.storm.thrift.TException) InputStreamWithMeta(org.apache.storm.blobstore.InputStreamWithMeta) BeginDownloadResult(org.apache.storm.generated.BeginDownloadResult) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 3 with BufferInputStream

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

the class Nimbus method beginFileDownload.

@SuppressWarnings("deprecation")
@Override
public String beginFileDownload(String file) throws AuthorizationException, TException {
    try {
        beginFileDownloadCalls.mark();
        checkAuthorization(null, null, "fileDownload");
        BufferInputStream is = new BufferInputStream(blobStore.getBlob(file, null), Utils.getInt(conf.get(Config.STORM_BLOBSTORE_INPUTSTREAM_BUFFER_SIZE_BYTES), 65536));
        String id = Utils.uuid();
        downloaders.put(id, is);
        return id;
    } catch (Exception e) {
        LOG.warn("begin file download exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : BufferInputStream(org.apache.storm.utils.BufferInputStream) TException(org.apache.thrift.TException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 4 with BufferInputStream

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

the class Nimbus method downloadChunk.

@SuppressWarnings("deprecation")
@Override
public ByteBuffer downloadChunk(String id) throws AuthorizationException, TException {
    try {
        downloadChunkCalls.mark();
        checkAuthorization(null, null, "fileDownload");
        BufferInputStream is = downloaders.get(id);
        if (is == null) {
            throw new RuntimeException("Could not find input stream for id " + id);
        }
        byte[] ret = is.read();
        if (ret.length == 0) {
            is.close();
            downloaders.remove(id);
        }
        return ByteBuffer.wrap(ret);
    } catch (Exception e) {
        LOG.warn("download chunk exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : BufferInputStream(org.apache.storm.utils.BufferInputStream) TException(org.apache.storm.thrift.TException) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Aggregations

IOException (java.io.IOException)4 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)4 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)4 AuthorizationException (org.apache.storm.generated.AuthorizationException)4 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)4 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)4 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)4 NotAliveException (org.apache.storm.generated.NotAliveException)4 BufferInputStream (org.apache.storm.utils.BufferInputStream)4 IllegalStateException (org.apache.storm.generated.IllegalStateException)3 TException (org.apache.storm.thrift.TException)3 WrappedAlreadyAliveException (org.apache.storm.utils.WrappedAlreadyAliveException)3 WrappedAuthorizationException (org.apache.storm.utils.WrappedAuthorizationException)3 WrappedIllegalStateException (org.apache.storm.utils.WrappedIllegalStateException)3 WrappedInvalidTopologyException (org.apache.storm.utils.WrappedInvalidTopologyException)3 WrappedNotAliveException (org.apache.storm.utils.WrappedNotAliveException)3 InputStreamWithMeta (org.apache.storm.blobstore.InputStreamWithMeta)1 BeginDownloadResult (org.apache.storm.generated.BeginDownloadResult)1 TException (org.apache.thrift.TException)1