Java Code Examples for org.apache.hadoop.fs.swift.http.RestClientBindings#extractContainerName()

The following examples show how to use org.apache.hadoop.fs.swift.http.RestClientBindings#extractContainerName() . 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: SwiftObjectPath.java    From hadoop with 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 File: SwiftObjectPath.java    From big-c with 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 File: SwiftObjectPath.java    From sahara-extra with 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 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 5
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 6
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 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 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 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: 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 10
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 11
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 12
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);
}