Search in sources :

Example 1 with AtomicOutputStream

use of com.alibaba.jstorm.blobstore.AtomicOutputStream in project jstorm by alibaba.

the class ServiceHandler method cancelBlobUpload.

@Override
public void cancelBlobUpload(String session) throws TException {
    AtomicOutputStream os = (AtomicOutputStream) data.getBlobUploaders().get(session);
    if (os == null) {
        throw new TException("Blob for session " + session + " does not exist (or timed out)");
    }
    try {
        os.cancel();
    } catch (IOException e) {
        LOG.error("AtomicOutputStream cancel failed when finishBlobUpload for session {}", session);
    }
    LOG.info("Canceling uploading blob for session {}. Closing session.", session);
    data.getBlobUploaders().remove(session);
}
Also used : TException(org.apache.thrift.TException) AtomicOutputStream(com.alibaba.jstorm.blobstore.AtomicOutputStream) IOException(java.io.IOException)

Example 2 with AtomicOutputStream

use of com.alibaba.jstorm.blobstore.AtomicOutputStream in project jstorm by alibaba.

the class ServiceHandler method beginCreateBlob.

@Override
public String beginCreateBlob(String blobKey, SettableBlobMeta meta) throws KeyAlreadyExistsException {
    String sessionId = UUID.randomUUID().toString();
    AtomicOutputStream out = data.getBlobStore().createBlob(blobKey, meta);
    data.getBlobUploaders().put(sessionId, out);
    LOG.info("Created blob for {} with session id {}", blobKey, sessionId);
    return sessionId;
}
Also used : AtomicOutputStream(com.alibaba.jstorm.blobstore.AtomicOutputStream)

Example 3 with AtomicOutputStream

use of com.alibaba.jstorm.blobstore.AtomicOutputStream in project jstorm by alibaba.

the class ServiceHandler method finishBlobUpload.

@Override
public void finishBlobUpload(String session) throws TException {
    AtomicOutputStream os = (AtomicOutputStream) data.getBlobUploaders().get(session);
    if (os == null) {
        throw new TException("Blob for session " + session + " does not exist (or timed out)");
    }
    try {
        os.close();
    } catch (IOException e) {
        LOG.error("AtomicOutputStream close failed when finishBlobUpload for session {}", session);
    }
    LOG.info("Finished uploading blob for session {}. Closing session.", session);
    data.getBlobUploaders().remove(session);
}
Also used : TException(org.apache.thrift.TException) AtomicOutputStream(com.alibaba.jstorm.blobstore.AtomicOutputStream) IOException(java.io.IOException)

Example 4 with AtomicOutputStream

use of com.alibaba.jstorm.blobstore.AtomicOutputStream in project jstorm by alibaba.

the class ServiceHandler method uploadBlobChunk.

@Override
public void uploadBlobChunk(String session, ByteBuffer chunk) throws TException {
    AtomicOutputStream os = (AtomicOutputStream) data.getBlobUploaders().get(session);
    if (os == null) {
        throw new TException("Blob for session " + session + " does not exist (or timed out)");
    }
    byte[] chunkArray = chunk.array();
    int remaining = chunk.remaining();
    int arrayOffset = chunk.arrayOffset();
    int position = chunk.position();
    try {
        os.write(chunkArray, (arrayOffset + position), remaining);
        data.getBlobUploaders().put(session, os);
    } catch (IOException e) {
        LOG.error("Blob upload failed", e);
        throw new TException(e);
    }
}
Also used : TException(org.apache.thrift.TException) AtomicOutputStream(com.alibaba.jstorm.blobstore.AtomicOutputStream) IOException(java.io.IOException)

Example 5 with AtomicOutputStream

use of com.alibaba.jstorm.blobstore.AtomicOutputStream in project jstorm by alibaba.

the class StormConfig method write_nimbus_topology_code.

public static void write_nimbus_topology_code(String topologyId, byte[] data, NimbusData nimbusData) throws Exception {
    String codeKey = master_stormcode_key(topologyId);
    AtomicOutputStream out = nimbusData.getBlobStore().updateBlob(codeKey);
    out.write(data);
    out.close();
    if (nimbusData.getBlobStore() instanceof LocalFsBlobStore) {
        NimbusInfo nimbusInfo = nimbusData.getNimbusHostPortInfo();
        int versionForKey = BlobStoreUtils.getVersionForKey(codeKey, nimbusInfo, nimbusData.getConf());
        nimbusData.getStormClusterState().setup_blobstore(codeKey, nimbusInfo, versionForKey);
    }
}
Also used : LocalFsBlobStore(com.alibaba.jstorm.blobstore.LocalFsBlobStore) AtomicOutputStream(com.alibaba.jstorm.blobstore.AtomicOutputStream) NimbusInfo(backtype.storm.nimbus.NimbusInfo)

Aggregations

AtomicOutputStream (com.alibaba.jstorm.blobstore.AtomicOutputStream)8 IOException (java.io.IOException)4 TException (org.apache.thrift.TException)3 NimbusInfo (backtype.storm.nimbus.NimbusInfo)2 LocalFsBlobStore (com.alibaba.jstorm.blobstore.LocalFsBlobStore)2 BufferInputStream (backtype.storm.utils.BufferInputStream)1 ExpiredCallback (com.alibaba.jstorm.utils.ExpiredCallback)1