예제 #1
0
  /**
   * prepare to uploading topology jar, return the file location
   *
   * @throws
   */
  @Override
  public String beginFileUpload() throws TException {
    String fileLoc = null;
    try {
      fileLoc = StormConfig.masterInbox(conf) + "/stormjar-" + UUID.randomUUID() + ".jar";

      data.getUploaders().put(fileLoc, Channels.newChannel(new FileOutputStream(fileLoc)));
      LOG.info("Uploading file from client to " + fileLoc);
    } catch (FileNotFoundException e) {
      LOG.error(" file not found " + fileLoc);
      throw new TException(e);
    } catch (IOException e) {
      LOG.error(" IOException  " + fileLoc, e);
      throw new TException(e);
    }
    return fileLoc;
  }
예제 #2
0
  @Override
  public void finishFileUpload(String location) throws TException {

    TimeCacheMap<Object, Object> uploaders = data.getUploaders();
    Object obj = uploaders.get(location);
    if (obj == null) {
      throw new TException("File for that location does not exist (or timed out)");
    }
    try {
      if (obj instanceof WritableByteChannel) {
        WritableByteChannel channel = (WritableByteChannel) obj;
        channel.close();
        uploaders.remove(location);
        LOG.info("Finished uploading file from client: " + location);
      } else {
        throw new TException("Object isn't WritableByteChannel for " + location);
      }
    } catch (IOException e) {
      LOG.error(" WritableByteChannel close failed when finishFileUpload " + location);
    }
  }
예제 #3
0
 /** uploading topology jar data */
 @Override
 public void uploadChunk(String location, ByteBuffer chunk) throws TException {
   TimeCacheMap<Object, Object> uploaders = data.getUploaders();
   Object obj = uploaders.get(location);
   if (obj == null) {
     throw new TException("File for that location does not exist (or timed out) " + location);
   }
   try {
     if (obj instanceof WritableByteChannel) {
       WritableByteChannel channel = (WritableByteChannel) obj;
       channel.write(chunk);
       uploaders.put(location, channel);
     } else {
       throw new TException("Object isn't WritableByteChannel for " + location);
     }
   } catch (IOException e) {
     String errMsg = " WritableByteChannel write filed when uploadChunk " + location;
     LOG.error(errMsg);
     throw new TException(e);
   }
 }