Java Code Examples for org.apache.hadoop.fs.swift.http.RestClientBindings

The following examples show how to use org.apache.hadoop.fs.swift.http.RestClientBindings. These examples are extracted from open source projects. 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 Project: hadoop   Source File: SwiftObjectPath.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a path tuple of (container, path), where the container is
 * chosen from the host of the URI.
 * A trailing slash can be added to the path. This is the point where
 * these /-es need to be appended, because when you construct a {@link Path}
 * instance, {@link Path#normalizePath(String, String)} is called
 * -which strips off any trailing slash.
 *
 * @param uri              uri to start from
 * @param path             path underneath
 * @param addTrailingSlash should a trailing slash be added if there isn't one.
 * @return a new instance.
 * @throws SwiftConfigurationException if the URI host doesn't parse into
 *                                     container.service
 */
public static SwiftObjectPath fromPath(URI uri,
                                       Path path,
                                       boolean addTrailingSlash)
        throws SwiftConfigurationException {

  String url =
          path.toUri().getPath().replaceAll(PATH_PART_PATTERN.pattern(), "");
  //add a trailing slash if needed
  if (addTrailingSlash && !url.endsWith("/")) {
    url += "/";
  }

  String container = uri.getHost();
  if (container == null) {
    //no container, not good: replace with ""
    container = "";
  } else if (container.contains(".")) {
    //its a container.service URI. Strip the container
    container = RestClientBindings.extractContainerName(container);
  }
  return new SwiftObjectPath(container, url);
}
 
Example 2
Source Project: big-c   Source File: SwiftObjectPath.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a path tuple of (container, path), where the container is
 * chosen from the host of the URI.
 * A trailing slash can be added to the path. This is the point where
 * these /-es need to be appended, because when you construct a {@link Path}
 * instance, {@link Path#normalizePath(String, String)} is called
 * -which strips off any trailing slash.
 *
 * @param uri              uri to start from
 * @param path             path underneath
 * @param addTrailingSlash should a trailing slash be added if there isn't one.
 * @return a new instance.
 * @throws SwiftConfigurationException if the URI host doesn't parse into
 *                                     container.service
 */
public static SwiftObjectPath fromPath(URI uri,
                                       Path path,
                                       boolean addTrailingSlash)
        throws SwiftConfigurationException {

  String url =
          path.toUri().getPath().replaceAll(PATH_PART_PATTERN.pattern(), "");
  //add a trailing slash if needed
  if (addTrailingSlash && !url.endsWith("/")) {
    url += "/";
  }

  String container = uri.getHost();
  if (container == null) {
    //no container, not good: replace with ""
    container = "";
  } else if (container.contains(".")) {
    //its a container.service URI. Strip the container
    container = RestClientBindings.extractContainerName(container);
  }
  return new SwiftObjectPath(container, url);
}
 
Example 3
Source Project: sahara-extra   Source File: SwiftObjectPath.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a path tuple of (container, path), where the container is
 * chosen from the host of the URI.
 * A trailing slash can be added to the path. This is the point where
 * these /-es need to be appended, because when you construct a {@link Path}
 * instance, {@link Path#normalizePath(String, String)} is called
 * -which strips off any trailing slash.
 *
 * @param uri              uri to start from
 * @param path             path underneath
 * @param addTrailingSlash should a trailing slash be added if there isn't one.
 * @return a new instance.
 * @throws SwiftConfigurationException if the URI host doesn't parse into
 *                                     container.service
 */
public static SwiftObjectPath fromPath(URI uri,
                                       Path path,
                                       boolean addTrailingSlash)
        throws SwiftConfigurationException {

  String url =
          path.toUri().getPath().replaceAll(PATH_PART_PATTERN.pattern(), "");
  //add a trailing slash if needed
  if (addTrailingSlash && !url.endsWith("/")) {
    url += "/";
  }

  String container = uri.getHost();
  if (container == null) {
    //no container, not good: replace with ""
    container = "";
  } else if (container.contains(".")) {
    //its a container.service URI. Strip the container
    container = RestClientBindings.extractContainerName(container);
  }
  return new SwiftObjectPath(container, url);
}
 
Example 4
Source Project: hadoop   Source File: TestSwiftObjectPath.java    License: 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 5
Source Project: hadoop   Source File: TestSwiftObjectPath.java    License: 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 6
Source Project: hadoop   Source File: TestSwiftObjectPath.java    License: 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 7
Source Project: big-c   Source File: TestSwiftObjectPath.java    License: 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 8
Source Project: big-c   Source File: TestSwiftObjectPath.java    License: 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 Project: big-c   Source File: TestSwiftObjectPath.java    License: 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 10
Source Project: sahara-extra   Source File: TestSwiftObjectPath.java    License: 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 11
Source Project: sahara-extra   Source File: TestSwiftObjectPath.java    License: 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 12
Source Project: sahara-extra   Source File: TestSwiftObjectPath.java    License: 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 13
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testConfIsValid() throws Throwable {
  Configuration conf = new Configuration();
  URI fsURI = SwiftTestUtils.getServiceURI(conf);
  RestClientBindings.bind(fsURI, conf);
}
 
Example 14
Source Project: big-c   Source File: TestSwiftFileSystemExtendedContract.java    License: Apache License 2.0 4 votes vote down vote up
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testConfIsValid() throws Throwable {
  Configuration conf = new Configuration();
  URI fsURI = SwiftTestUtils.getServiceURI(conf);
  RestClientBindings.bind(fsURI, conf);
}
 
Example 15
@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testConfIsValid() throws Throwable {
  Configuration conf = new Configuration();
  URI fsURI = SwiftTestUtils.getServiceURI(conf);
  RestClientBindings.bind(fsURI, conf);
}