org.apache.hadoop.fs.s3.S3Exception#org.jets3t.service.S3ServiceException源码实例Demo

下面列出了org.apache.hadoop.fs.s3.S3Exception#org.jets3t.service.S3ServiceException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void write(final Path container, final Distribution distribution, final LoginCallback prompt) throws BackgroundException {
    if(distribution.getMethod().equals(Distribution.WEBSITE)) {
        try {
            if(distribution.isEnabled()) {
                String suffix = "index.html";
                if(StringUtils.isNotBlank(distribution.getIndexDocument())) {
                    suffix = PathNormalizer.name(distribution.getIndexDocument());
                }
                // Enable website endpoint
                session.getClient().setWebsiteConfig(container.getName(), new S3WebsiteConfig(suffix));
            }
            else {
                // Disable website endpoint
                session.getClient().deleteWebsiteConfig(container.getName());
            }
        }
        catch(S3ServiceException e) {
            throw new S3ExceptionMappingService().map("Cannot write website configuration", e);
        }
    }
    else {
        super.write(container, distribution, prompt);
    }
}
 
源代码2 项目: hadoop   文件: Jets3tNativeFileSystemStore.java
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
  S3Credentials s3Credentials = new S3Credentials();
  s3Credentials.initialize(uri, conf);
  try {
    AWSCredentials awsCredentials =
      new AWSCredentials(s3Credentials.getAccessKey(),
          s3Credentials.getSecretAccessKey());
    this.s3Service = new RestS3Service(awsCredentials);
  } catch (S3ServiceException e) {
    handleException(e);
  }
  multipartEnabled =
      conf.getBoolean("fs.s3n.multipart.uploads.enabled", false);
  multipartBlockSize = Math.min(
      conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024),
      MAX_PART_SIZE);
  multipartCopyBlockSize = Math.min(
      conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE),
      MAX_PART_SIZE);
  serverSideEncryptionAlgorithm = conf.get("fs.s3n.server-side-encryption-algorithm");

  bucket = new S3Bucket(uri.getHost());
}
 
源代码3 项目: hadoop   文件: Jets3tFileSystemStore.java
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
  
  this.conf = conf;
  
  S3Credentials s3Credentials = new S3Credentials();
  s3Credentials.initialize(uri, conf);
  try {
    AWSCredentials awsCredentials =
      new AWSCredentials(s3Credentials.getAccessKey(),
          s3Credentials.getSecretAccessKey());
    this.s3Service = new RestS3Service(awsCredentials);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  bucket = new S3Bucket(uri.getHost());

  this.bufferSize = conf.getInt(
                     S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_KEY,
                     S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_DEFAULT
      );
}
 
源代码4 项目: hadoop-gpu   文件: Jets3tFileSystemStore.java
public Set<Path> listDeepSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket, prefix, null);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }    
}
 
源代码5 项目: hadoop   文件: Jets3tFileSystemStore.java
@Override
public Set<Path> listSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, PATH_DELIMITER);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码6 项目: hadoop   文件: Jets3tFileSystemStore.java
@Override
public Set<Path> listDeepSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }    
}
 
源代码7 项目: hadoop   文件: Jets3tFileSystemStore.java
private void put(String key, InputStream in, long length, boolean storeMetadata)
    throws IOException {
  
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(length);
    if (storeMetadata) {
      object.addAllMetadata(METADATA);
    }
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码8 项目: hadoop   文件: Jets3tFileSystemStore.java
@Override
public void dump() throws IOException {
  StringBuilder sb = new StringBuilder("S3 Filesystem, ");
  sb.append(bucket.getName()).append("\n");
  try {
    S3Object[] objects = s3Service.listObjects(bucket.getName(), PATH_DELIMITER, null);
    for (int i = 0; i < objects.length; i++) {
      Path path = keyToPath(objects[i].getKey());
      sb.append(path).append("\n");
      INode m = retrieveINode(path);
      sb.append("\t").append(m.getFileType()).append("\n");
      if (m.getFileType() == FileType.DIRECTORY) {
        continue;
      }
      for (int j = 0; j < m.getBlocks().length; j++) {
        sb.append("\t").append(m.getBlocks()[j]).append("\n");
      }
    }
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  System.out.println(sb);
}
 
源代码9 项目: hadoop   文件: MigrationTool.java
@Override
public Set<Path> listAllPaths() throws IOException {
  try {
    String prefix = urlEncode(Path.SEPARATOR);
    S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }   
}
 
源代码10 项目: big-c   文件: Jets3tNativeFileSystemStore.java
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
  S3Credentials s3Credentials = new S3Credentials();
  s3Credentials.initialize(uri, conf);
  try {
    AWSCredentials awsCredentials =
      new AWSCredentials(s3Credentials.getAccessKey(),
          s3Credentials.getSecretAccessKey());
    this.s3Service = new RestS3Service(awsCredentials);
  } catch (S3ServiceException e) {
    handleException(e);
  }
  multipartEnabled =
      conf.getBoolean("fs.s3n.multipart.uploads.enabled", false);
  multipartBlockSize = Math.min(
      conf.getLong("fs.s3n.multipart.uploads.block.size", 64 * 1024 * 1024),
      MAX_PART_SIZE);
  multipartCopyBlockSize = Math.min(
      conf.getLong("fs.s3n.multipart.copy.block.size", MAX_PART_SIZE),
      MAX_PART_SIZE);
  serverSideEncryptionAlgorithm = conf.get("fs.s3n.server-side-encryption-algorithm");

  bucket = new S3Bucket(uri.getHost());
}
 
源代码11 项目: big-c   文件: Jets3tFileSystemStore.java
@Override
public void initialize(URI uri, Configuration conf) throws IOException {
  
  this.conf = conf;
  
  S3Credentials s3Credentials = new S3Credentials();
  s3Credentials.initialize(uri, conf);
  try {
    AWSCredentials awsCredentials =
      new AWSCredentials(s3Credentials.getAccessKey(),
          s3Credentials.getSecretAccessKey());
    this.s3Service = new RestS3Service(awsCredentials);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  bucket = new S3Bucket(uri.getHost());

  this.bufferSize = conf.getInt(
                     S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_KEY,
                     S3FileSystemConfigKeys.S3_STREAM_BUFFER_SIZE_DEFAULT
      );
}
 
源代码12 项目: big-c   文件: Jets3tFileSystemStore.java
private void checkMetadata(S3Object object) throws S3FileSystemException,
    S3ServiceException {
  
  String name = (String) object.getMetadata(FILE_SYSTEM_NAME);
  if (!FILE_SYSTEM_VALUE.equals(name)) {
    throw new S3FileSystemException("Not a Hadoop S3 file.");
  }
  String type = (String) object.getMetadata(FILE_SYSTEM_TYPE_NAME);
  if (!FILE_SYSTEM_TYPE_VALUE.equals(type)) {
    throw new S3FileSystemException("Not a block file.");
  }
  String dataVersion = (String) object.getMetadata(FILE_SYSTEM_VERSION_NAME);
  if (!FILE_SYSTEM_VERSION_VALUE.equals(dataVersion)) {
    throw new VersionMismatchException(FILE_SYSTEM_VERSION_VALUE,
        dataVersion);
  }
}
 
源代码13 项目: big-c   文件: Jets3tFileSystemStore.java
@Override
public Set<Path> listSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, PATH_DELIMITER);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码14 项目: big-c   文件: Jets3tFileSystemStore.java
@Override
public Set<Path> listDeepSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }    
}
 
源代码15 项目: big-c   文件: Jets3tFileSystemStore.java
private void put(String key, InputStream in, long length, boolean storeMetadata)
    throws IOException {
  
  try {
    S3Object object = new S3Object(key);
    object.setDataInputStream(in);
    object.setContentType("binary/octet-stream");
    object.setContentLength(length);
    if (storeMetadata) {
      object.addAllMetadata(METADATA);
    }
    s3Service.putObject(bucket, object);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码16 项目: big-c   文件: Jets3tFileSystemStore.java
@Override
public void dump() throws IOException {
  StringBuilder sb = new StringBuilder("S3 Filesystem, ");
  sb.append(bucket.getName()).append("\n");
  try {
    S3Object[] objects = s3Service.listObjects(bucket.getName(), PATH_DELIMITER, null);
    for (int i = 0; i < objects.length; i++) {
      Path path = keyToPath(objects[i].getKey());
      sb.append(path).append("\n");
      INode m = retrieveINode(path);
      sb.append("\t").append(m.getFileType()).append("\n");
      if (m.getFileType() == FileType.DIRECTORY) {
        continue;
      }
      for (int j = 0; j < m.getBlocks().length; j++) {
        sb.append("\t").append(m.getBlocks()[j]).append("\n");
      }
    }
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  System.out.println(sb);
}
 
源代码17 项目: big-c   文件: MigrationTool.java
@Override
public Set<Path> listAllPaths() throws IOException {
  try {
    String prefix = urlEncode(Path.SEPARATOR);
    S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }   
}
 
源代码18 项目: hadoop-gpu   文件: Jets3tNativeFileSystemStore.java
public void dump() throws IOException {
  StringBuilder sb = new StringBuilder("S3 Native Filesystem, ");
  sb.append(bucket.getName()).append("\n");
  try {
    S3Object[] objects = s3Service.listObjects(bucket);
    for (int i = 0; i < objects.length; i++) {
      sb.append(objects[i].getKey()).append("\n");
    }
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  System.out.println(sb);
}
 
源代码19 项目: red5-examples   文件: S3FilenameGenerator.java
public static List<String> getBucketList() {
	logger.debug("Get the bucket list");
	List<String> bucketList = new ArrayList<String>(3);
	try {
		S3Service s3Service = new RestS3Service(awsCredentials); 
		S3Bucket[] buckets = s3Service.listAllBuckets();
		for (S3Bucket bucket: buckets) {
			logger.debug("Bucket: {}", bucket.getName());
			bucketList.add(bucket.getName());
		}
		logger.debug("Bucket count: {}", buckets.length);
	} catch (S3ServiceException e) {
		logger.error("Error during bucket listing", e);
	}
	return bucketList;
}
 
源代码20 项目: RDFS   文件: Jets3tNativeFileSystemStore.java
public void initialize(URI uri, Configuration conf) throws IOException {
  S3Credentials s3Credentials = new S3Credentials();
  s3Credentials.initialize(uri, conf);
  try {
    AWSCredentials awsCredentials =
      new AWSCredentials(s3Credentials.getAccessKey(),
          s3Credentials.getSecretAccessKey());
    this.s3Service = new RestS3Service(awsCredentials);
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  bucket = new S3Bucket(uri.getHost());
}
 
源代码21 项目: RDFS   文件: Jets3tNativeFileSystemStore.java
public FileMetadata retrieveMetadata(String key) throws IOException {
  try {
    S3Object object = s3Service.getObjectDetails(bucket, key);
    return new FileMetadata(key, object.getContentLength(),
        object.getLastModifiedDate().getTime());
  } catch (S3ServiceException e) {
    // Following is brittle. Is there a better way?
    if (e.getMessage().contains("ResponseCode=404")) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码22 项目: RDFS   文件: Jets3tNativeFileSystemStore.java
public InputStream retrieve(String key, long byteRangeStart)
  throws IOException {
  try {
    S3Object object = s3Service.getObject(bucket, key, null, null, null,
                                          null, byteRangeStart, null);
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码23 项目: RDFS   文件: Jets3tNativeFileSystemStore.java
private PartialListing list(String prefix, String delimiter,
    int maxListingLength, String priorLastKey) throws IOException {
  try {
    if (prefix.length() > 0 && !prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3ObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(),
        prefix, delimiter, maxListingLength, priorLastKey);
    
    FileMetadata[] fileMetadata =
      new FileMetadata[chunk.getObjects().length];
    for (int i = 0; i < fileMetadata.length; i++) {
      S3Object object = chunk.getObjects()[i];
      fileMetadata[i] = new FileMetadata(object.getKey(),
          object.getContentLength(), object.getLastModifiedDate().getTime());
    }
    return new PartialListing(chunk.getPriorLastKey(), fileMetadata,
        chunk.getCommonPrefixes());
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码24 项目: hadoop-gpu   文件: Jets3tFileSystemStore.java
public void dump() throws IOException {
  StringBuilder sb = new StringBuilder("S3 Filesystem, ");
  sb.append(bucket.getName()).append("\n");
  try {
    S3Object[] objects = s3Service.listObjects(bucket, PATH_DELIMITER, null);
    for (int i = 0; i < objects.length; i++) {
      Path path = keyToPath(objects[i].getKey());
      sb.append(path).append("\n");
      INode m = retrieveINode(path);
      sb.append("\t").append(m.getFileType()).append("\n");
      if (m.getFileType() == FileType.DIRECTORY) {
        continue;
      }
      for (int j = 0; j < m.getBlocks().length; j++) {
        sb.append("\t").append(m.getBlocks()[j]).append("\n");
      }
    }
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  System.out.println(sb);
}
 
源代码25 项目: RDFS   文件: Jets3tFileSystemStore.java
private InputStream get(String key, boolean checkMetadata)
    throws IOException {
  
  try {
    S3Object object = s3Service.getObject(bucket, key);
    if (checkMetadata) {
      checkMetadata(object);
    }
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码26 项目: hadoop-gpu   文件: Jets3tFileSystemStore.java
private InputStream get(String key, boolean checkMetadata)
    throws IOException {
  
  try {
    S3Object object = s3Service.getObject(bucket, key);
    if (checkMetadata) {
      checkMetadata(object);
    }
    return object.getDataInputStream();
  } catch (S3ServiceException e) {
    if ("NoSuchKey".equals(e.getS3ErrorCode())) {
      return null;
    }
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码27 项目: RDFS   文件: Jets3tFileSystemStore.java
public Set<Path> listSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket, prefix, PATH_DELIMITER);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}
 
源代码28 项目: RDFS   文件: Jets3tFileSystemStore.java
public Set<Path> listDeepSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket, prefix, null);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }    
}
 
源代码29 项目: RDFS   文件: Jets3tFileSystemStore.java
public void dump() throws IOException {
  StringBuilder sb = new StringBuilder("S3 Filesystem, ");
  sb.append(bucket.getName()).append("\n");
  try {
    S3Object[] objects = s3Service.listObjects(bucket, PATH_DELIMITER, null);
    for (int i = 0; i < objects.length; i++) {
      Path path = keyToPath(objects[i].getKey());
      sb.append(path).append("\n");
      INode m = retrieveINode(path);
      sb.append("\t").append(m.getFileType()).append("\n");
      if (m.getFileType() == FileType.DIRECTORY) {
        continue;
      }
      for (int j = 0; j < m.getBlocks().length; j++) {
        sb.append("\t").append(m.getBlocks()[j]).append("\n");
      }
    }
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
  System.out.println(sb);
}
 
源代码30 项目: hadoop-gpu   文件: Jets3tFileSystemStore.java
public Set<Path> listSubPaths(Path path) throws IOException {
  try {
    String prefix = pathToKey(path);
    if (!prefix.endsWith(PATH_DELIMITER)) {
      prefix += PATH_DELIMITER;
    }
    S3Object[] objects = s3Service.listObjects(bucket, prefix, PATH_DELIMITER);
    Set<Path> prefixes = new TreeSet<Path>();
    for (int i = 0; i < objects.length; i++) {
      prefixes.add(keyToPath(objects[i].getKey()));
    }
    prefixes.remove(path);
    return prefixes;
  } catch (S3ServiceException e) {
    if (e.getCause() instanceof IOException) {
      throw (IOException) e.getCause();
    }
    throw new S3Exception(e);
  }
}