Java Code Examples for org.apache.hadoop.fs.swift.util.SwiftObjectPath#fromPath()

The following examples show how to use org.apache.hadoop.fs.swift.util.SwiftObjectPath#fromPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSwiftFileSystemDirectories.java    From sahara-extra with Apache License 2.0 6 votes vote down vote up
private String[] getRawObjectNames() throws Exception {
  SwiftRestClient client;
  client = SwiftRestClient.getInstance(fs.getUri(), fs.getConf());
  SwiftObjectPath path = SwiftObjectPath.fromPath(fs.getUri(), new Path("/"));
  byte[] bytes = client.listDeepObjectsInDirectory(path, true, true);
  final CollectionType collectionType = JSONUtil.getJsonMapper().
    getTypeFactory().constructCollectionType(List.class,
                                             SwiftObjectFileStatus.class);
  final List<SwiftObjectFileStatus> fileStatusList =
    JSONUtil.toObject(new String(bytes), collectionType);
  final ArrayList<String> objects = new ArrayList();
  for (SwiftObjectFileStatus status : fileStatusList) {
    if (status.getName() != null) {
      objects.add(status.getName());
    } else if (status.getSubdir() != null) {
      objects.add(status.getSubdir());
    }
  }
  return objects.toArray(new String[objects.size()]);
}
 
Example 2
Source File: TestSwiftObjectPath.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParsePath() throws Exception {
  final String pathString = "/home/user/files/file1";
  final Path path = new Path(pathString);
  final URI uri = new URI("http://container.localhost");
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          pathString);

  assertEquals(expected, actual);
}
 
Example 3
Source File: TestSwiftObjectPath.java    From sahara-extra with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParsePath() throws Exception {
  final String pathString = "/home/user/files/file1";
  final Path path = new Path(pathString);
  final URI uri = new URI("http://container.localhost");
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          pathString);

  assertEquals(expected, actual);
}
 
Example 4
Source File: TestSwiftObjectPath.java    From sahara-extra with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParseUrlPath() throws Exception {
  final String pathString = "swift://container.service1/home/user/files/file1";
  final URI uri = new URI(pathString);
  final Path path = new Path(pathString);
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          "/home/user/files/file1");

  assertEquals(expected, actual);
}
 
Example 5
Source File: TestSwiftFileSystemRename.java    From sahara-extra with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testRenamePseudoDir() throws Throwable {
  assumeRenameSupported();

  // create file directory (don't create directory file)
  SwiftRestClient client;
  client = SwiftRestClient.getInstance(fs.getUri(), fs.getConf());
  SwiftObjectPath path = SwiftObjectPath.fromPath(fs.getUri(), new Path("/test/olddir/file"));
  client.upload(path, new ByteArrayInputStream(new byte[0]), 0);

  rename(path("/test/olddir"), path("/test/newdir"), true, false, true);
  SwiftTestUtils.assertIsDirectory(fs, path("/test/newdir"));
  assertIsFile(path("/test/newdir/file"));
}
 
Example 6
Source File: TestSwiftObjectPath.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testConvertToPath() throws Throwable {
  String initialpath = "/dir/file1";
  Path ipath = new Path(initialpath);
  SwiftObjectPath objectPath = SwiftObjectPath.fromPath(new URI(initialpath),
          ipath);
  URI endpoint = new URI(ENDPOINT);
  URI uri = SwiftRestClient.pathToURI(objectPath, endpoint);
  LOG.info("Inital Hadoop Path =" + initialpath);
  LOG.info("Merged URI=" + uri);
}
 
Example 7
Source File: TestSwiftObjectPath.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParseAuthenticatedUrl() throws Exception {
  final String pathString = "swift://container.service1/v2/AUTH_00345h34l93459y4/home/tom/documents/finance.docx";
  final URI uri = new URI(pathString);
  final Path path = new Path(pathString);
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          "/home/tom/documents/finance.docx");

  assertEquals(expected, actual);
}
 
Example 8
Source File: TestSwiftObjectPath.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParseUrlPath() throws Exception {
  final String pathString = "swift://container.service1/home/user/files/file1";
  final URI uri = new URI(pathString);
  final Path path = new Path(pathString);
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          "/home/user/files/file1");

  assertEquals(expected, actual);
}
 
Example 9
Source File: TestSwiftRestClient.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPutAndDelete() throws Throwable {
  assumeEnabled();
  SwiftRestClient client = createClient();
  client.authenticate();
  Path path = new Path("restTestPutAndDelete");
  SwiftObjectPath sobject = SwiftObjectPath.fromPath(serviceURI, path);
  byte[] stuff = new byte[1];
  stuff[0] = 'a';
  client.upload(sobject, new ByteArrayInputStream(stuff), stuff.length);
  //check file exists
  Duration head = new Duration();
  Header[] responseHeaders = client.headRequest("expect success",
                                                sobject,
                                                SwiftRestClient.NEWEST);
  head.finished();
  LOG.info("head request duration " + head);
  for (Header header: responseHeaders) {
    LOG.info(header.toString());
  }
  //delete the file
  client.delete(sobject);
  //check file is gone
  try {
    Header[] headers = client.headRequest("expect fail",
                                          sobject,
                                          SwiftRestClient.NEWEST);
    Assert.fail("Expected deleted file, but object is still present: "
                + sobject);
  } catch (FileNotFoundException e) {
    //expected
  }
  for (DurationStats stats: client.getOperationStatistics()) {
    LOG.info(stats);
  }
}
 
Example 10
Source File: TestSwiftObjectPath.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testConvertToPath() throws Throwable {
  String initialpath = "/dir/file1";
  Path ipath = new Path(initialpath);
  SwiftObjectPath objectPath = SwiftObjectPath.fromPath(new URI(initialpath),
          ipath);
  URI endpoint = new URI(ENDPOINT);
  URI uri = SwiftRestClient.pathToURI(objectPath, endpoint);
  LOG.info("Inital Hadoop Path =" + initialpath);
  LOG.info("Merged URI=" + uri);
}
 
Example 11
Source File: TestSwiftObjectPath.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParseAuthenticatedUrl() throws Exception {
  final String pathString = "swift://container.service1/v2/AUTH_00345h34l93459y4/home/tom/documents/finance.docx";
  final URI uri = new URI(pathString);
  final Path path = new Path(pathString);
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          "/home/tom/documents/finance.docx");

  assertEquals(expected, actual);
}
 
Example 12
Source File: TestSwiftObjectPath.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParseUrlPath() throws Exception {
  final String pathString = "swift://container.service1/home/user/files/file1";
  final URI uri = new URI(pathString);
  final Path path = new Path(pathString);
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          "/home/user/files/file1");

  assertEquals(expected, actual);
}
 
Example 13
Source File: TestSwiftObjectPath.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParsePath() throws Exception {
  final String pathString = "/home/user/files/file1";
  final Path path = new Path(pathString);
  final URI uri = new URI("http://container.localhost");
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          pathString);

  assertEquals(expected, actual);
}
 
Example 14
Source File: TestSwiftRestClient.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testPutAndDelete() throws Throwable {
  assumeEnabled();
  SwiftRestClient client = createClient();
  client.authenticate();
  Path path = new Path("restTestPutAndDelete");
  SwiftObjectPath sobject = SwiftObjectPath.fromPath(serviceURI, path);
  byte[] stuff = new byte[1];
  stuff[0] = 'a';
  client.upload(sobject, new ByteArrayInputStream(stuff), stuff.length);
  //check file exists
  Duration head = new Duration();
  Header[] responseHeaders = client.headRequest("expect success",
                                                sobject,
                                                SwiftRestClient.NEWEST);
  head.finished();
  LOG.info("head request duration " + head);
  for (Header header: responseHeaders) {
    LOG.info(header.toString());
  }
  //delete the file
  client.delete(sobject);
  //check file is gone
  try {
    Header[] headers = client.headRequest("expect fail",
                                          sobject,
                                          SwiftRestClient.NEWEST);
    Assert.fail("Expected deleted file, but object is still present: "
                + sobject);
  } catch (FileNotFoundException e) {
    //expected
  }
  for (DurationStats stats: client.getOperationStatistics()) {
    LOG.info(stats);
  }
}
 
Example 15
Source File: TestSwiftObjectPath.java    From sahara-extra with Apache License 2.0 5 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testParseAuthenticatedUrl() throws Exception {
  final String pathString = "swift://container.service1/v2/AUTH_00345h34l93459y4/home/tom/documents/finance.docx";
  final URI uri = new URI(pathString);
  final Path path = new Path(pathString);
  final SwiftObjectPath expected = SwiftObjectPath.fromPath(uri, path);
  final SwiftObjectPath actual = new SwiftObjectPath(
          RestClientBindings.extractContainerName(uri),
          "/home/tom/documents/finance.docx");

  assertEquals(expected, actual);
}
 
Example 16
Source File: SwiftNativeFileSystemStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
private SwiftObjectPath toObjectPath(Path path) throws
        SwiftConfigurationException {
  return SwiftObjectPath.fromPath(uri, path);
}
 
Example 17
Source File: SwiftNativeFileSystemStore.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private SwiftObjectPath toDirPath(Path path) throws
        SwiftConfigurationException {
  return SwiftObjectPath.fromPath(uri, path, false);
}
 
Example 18
Source File: SwiftNativeFileSystemStore.java    From big-c with Apache License 2.0 4 votes vote down vote up
private SwiftObjectPath toDirPath(Path path) throws
        SwiftConfigurationException {
  return SwiftObjectPath.fromPath(uri, path, false);
}
 
Example 19
Source File: SwiftNativeFileSystemStore.java    From sahara-extra with Apache License 2.0 4 votes vote down vote up
private SwiftObjectPath toDirPath(Path path) throws
        SwiftConfigurationException {
  return SwiftObjectPath.fromPath(uri, path, true);
}
 
Example 20
Source File: SwiftNativeFileSystemStore.java    From sahara-extra with Apache License 2.0 4 votes vote down vote up
private SwiftObjectPath toObjectPath(Path path) throws
        SwiftConfigurationException {
  return SwiftObjectPath.fromPath(uri, path);
}