Java Code Examples for org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException

The following examples show how to use org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException. 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: SwiftNativeFileSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Low-level operation to also set the block size for this operation
 * @param path       the file name to open
 * @param bufferSize the size of the buffer to be used.
 * @param readBlockSize how big should the read blockk/buffer size be?
 * @return the input stream
 * @throws FileNotFoundException if the file is not found
 * @throws IOException any IO problem
 */
public FSDataInputStream open(Path path,
                              int bufferSize,
                              long readBlockSize) throws IOException {
  if (readBlockSize <= 0) {
    throw new SwiftConfigurationException("Bad remote buffer size");
  }
  Path absolutePath = makeAbsolute(path);
  return new FSDataInputStream(
          new StrictBufferedFSInputStream(
                  new SwiftNativeInputStream(store,
                                     statistics,
                                     absolutePath,
                                     readBlockSize),
                  bufferSize));
}
 
Example 2
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 3
Source Project: big-c   Source File: SwiftNativeFileSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Low-level operation to also set the block size for this operation
 * @param path       the file name to open
 * @param bufferSize the size of the buffer to be used.
 * @param readBlockSize how big should the read blockk/buffer size be?
 * @return the input stream
 * @throws FileNotFoundException if the file is not found
 * @throws IOException any IO problem
 */
public FSDataInputStream open(Path path,
                              int bufferSize,
                              long readBlockSize) throws IOException {
  if (readBlockSize <= 0) {
    throw new SwiftConfigurationException("Bad remote buffer size");
  }
  Path absolutePath = makeAbsolute(path);
  return new FSDataInputStream(
          new StrictBufferedFSInputStream(
                  new SwiftNativeInputStream(store,
                                     statistics,
                                     absolutePath,
                                     readBlockSize),
                  bufferSize));
}
 
Example 4
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 5
Source Project: sahara-extra   Source File: SwiftNativeFileSystem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Low-level operation to also set the block size for this operation
 * @param path       the file name to open
 * @param bufferSize the size of the buffer to be used.
 * @param readBlockSize how big should the read blockk/buffer size be?
 * @return the input stream
 * @throws FileNotFoundException if the file is not found
 * @throws IOException any IO problem
 */
public FSDataInputStream open(Path path,
                              int bufferSize,
                              long readBlockSize) throws IOException {
  if (readBlockSize <= 0) {
    throw new SwiftConfigurationException("Bad remote buffer size");
  }
  Path absolutePath = makeAbsolute(path);
  return new FSDataInputStream(
          new StrictBufferedFSInputStream(
                  new SwiftNativeInputStream(store,
                                     statistics,
                                     absolutePath,
                                     readBlockSize),
                  bufferSize));
}
 
Example 6
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 7
Source Project: hadoop   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the container name from the hostname -the single element before the
 * first "." in the hostname
 *
 * @param hostname hostname to split
 * @return the container
 * @throws SwiftConfigurationException
 */
public static String extractContainerName(String hostname) throws
        SwiftConfigurationException {
  int i = hostname.indexOf(".");
  if (i <= 0) {
    throw invalidName(hostname);
  }
  return hostname.substring(0, i);
}
 
Example 8
Source Project: hadoop   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the service name from a longer hostname string
 *
 * @param hostname hostname
 * @return the separated out service name
 * @throws SwiftConfigurationException if the hostname was invalid
 */
public static String extractServiceName(String hostname) throws
        SwiftConfigurationException {
  int i = hostname.indexOf(".");
  if (i <= 0) {
    throw invalidName(hostname);
  }
  String service = hostname.substring(i + 1);
  if (service.isEmpty() || service.contains(".")) {
    //empty service contains dots in -not currently supported
    throw invalidName(hostname);
  }
  return service;
}
 
Example 9
Source Project: hadoop   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Build a properties instance bound to the configuration file -using
 * the filesystem URI as the source of the information.
 *
 * @param fsURI filesystem URI
 * @param conf  configuration
 * @return a properties file with the instance-specific properties extracted
 *         and bound to the swift client properties.
 * @throws SwiftConfigurationException if the configuration is invalid
 */
public static Properties bind(URI fsURI, Configuration conf) throws
        SwiftConfigurationException {
  String host = fsURI.getHost();
  if (host == null || host.isEmpty()) {
    //expect shortnames -> conf names
    throw invalidName(host);
  }

  String container = extractContainerName(host);
  String service = extractServiceName(host);

  //build filename schema
  String prefix = buildSwiftInstancePrefix(service);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Filesystem " + fsURI
            + " is using configuration keys " + prefix);
  }
  Properties props = new Properties();
  props.setProperty(SWIFT_SERVICE_PROPERTY, service);
  props.setProperty(SWIFT_CONTAINER_PROPERTY, container);
  copy(conf, prefix + DOT_AUTH_URL, props, SWIFT_AUTH_PROPERTY, true);
  copy(conf, prefix + DOT_USERNAME, props, SWIFT_USERNAME_PROPERTY, true);
  copy(conf, prefix + DOT_APIKEY, props, SWIFT_APIKEY_PROPERTY, false);
  copy(conf, prefix + DOT_PASSWORD, props, SWIFT_PASSWORD_PROPERTY,
          props.contains(SWIFT_APIKEY_PROPERTY) ? true : false);
  copy(conf, prefix + DOT_TENANT, props, SWIFT_TENANT_PROPERTY, false);
  copy(conf, prefix + DOT_REGION, props, SWIFT_REGION_PROPERTY, false);
  copy(conf, prefix + DOT_HTTP_PORT, props, SWIFT_HTTP_PORT_PROPERTY, false);
  copy(conf, prefix +
          DOT_HTTPS_PORT, props, SWIFT_HTTPS_PORT_PROPERTY, false);

  copyBool(conf, prefix + DOT_PUBLIC, props, SWIFT_PUBLIC_PROPERTY, false);
  copyBool(conf, prefix + DOT_LOCATION_AWARE, props,
           SWIFT_LOCATION_AWARE_PROPERTY, false);

  return props;
}
 
Example 10
Source Project: hadoop   Source File: SwiftRestClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get a mandatory configuration option
 *
 * @param props property set
 * @param key   key
 * @return value of the configuration
 * @throws SwiftConfigurationException if there was no match for the key
 */
private static String getOption(Properties props, String key) throws
        SwiftConfigurationException {
  String val = props.getProperty(key);
  if (val == null) {
    throw new SwiftConfigurationException("Undefined property: " + key);
  }
  return val;
}
 
Example 11
Source Project: hadoop   Source File: SwiftTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the test URI
 * @param conf configuration
 * @throws SwiftConfigurationException missing parameter or bad URI
 */
public static URI getServiceURI(Configuration conf) throws
                                                    SwiftConfigurationException {
  String instance = conf.get(TEST_FS_SWIFT);
  if (instance == null) {
    throw new SwiftConfigurationException(
      "Missing configuration entry " + TEST_FS_SWIFT);
  }
  try {
    return new URI(instance);
  } catch (URISyntaxException e) {
    throw new SwiftConfigurationException("Bad URI: " + instance);
  }
}
 
Example 12
Source Project: hadoop   Source File: TestRestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
public void expectBindingFailure(URI fsURI, Configuration config) {
  try {
    Properties binding = RestClientBindings.bind(fsURI, config);
    //if we get here, binding didn't fail- there is something else.
    //list the properties but not the values.
    StringBuilder details = new StringBuilder() ;
    for (Object key: binding.keySet()) {
      details.append(key.toString()).append(" ");
    }
    fail("Expected a failure, got the binding [ "+ details+"]");
  } catch (SwiftConfigurationException expected) {

  }
}
 
Example 13
Source Project: hadoop   Source File: TestRestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * inner test method that expects container extraction to fail
 * -if not prints a meaningful error message.
 *
 * @param hostname hostname to parse
 */
private static void expectExtractContainerFail(String hostname) {
  try {
    String container = RestClientBindings.extractContainerName(hostname);
    fail("Expected an error -got a container of '" + container
            + "' from " + hostname);
  } catch (SwiftConfigurationException expected) {
    //expected
  }
}
 
Example 14
Source Project: hadoop   Source File: TestRestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * inner test method that expects service extraction to fail
 * -if not prints a meaningful error message.
 *
 * @param hostname hostname to parse
 */
public static void expectExtractServiceFail(String hostname) {
  try {
    String service = RestClientBindings.extractServiceName(hostname);
    fail("Expected an error -got a service of '" + service
            + "' from " + hostname);
  } catch (SwiftConfigurationException expected) {
    //expected
  }
}
 
Example 15
Source Project: big-c   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the container name from the hostname -the single element before the
 * first "." in the hostname
 *
 * @param hostname hostname to split
 * @return the container
 * @throws SwiftConfigurationException
 */
public static String extractContainerName(String hostname) throws
        SwiftConfigurationException {
  int i = hostname.indexOf(".");
  if (i <= 0) {
    throw invalidName(hostname);
  }
  return hostname.substring(0, i);
}
 
Example 16
Source Project: big-c   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the service name from a longer hostname string
 *
 * @param hostname hostname
 * @return the separated out service name
 * @throws SwiftConfigurationException if the hostname was invalid
 */
public static String extractServiceName(String hostname) throws
        SwiftConfigurationException {
  int i = hostname.indexOf(".");
  if (i <= 0) {
    throw invalidName(hostname);
  }
  String service = hostname.substring(i + 1);
  if (service.isEmpty() || service.contains(".")) {
    //empty service contains dots in -not currently supported
    throw invalidName(hostname);
  }
  return service;
}
 
Example 17
Source Project: big-c   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Build a properties instance bound to the configuration file -using
 * the filesystem URI as the source of the information.
 *
 * @param fsURI filesystem URI
 * @param conf  configuration
 * @return a properties file with the instance-specific properties extracted
 *         and bound to the swift client properties.
 * @throws SwiftConfigurationException if the configuration is invalid
 */
public static Properties bind(URI fsURI, Configuration conf) throws
        SwiftConfigurationException {
  String host = fsURI.getHost();
  if (host == null || host.isEmpty()) {
    //expect shortnames -> conf names
    throw invalidName(host);
  }

  String container = extractContainerName(host);
  String service = extractServiceName(host);

  //build filename schema
  String prefix = buildSwiftInstancePrefix(service);
  if (LOG.isDebugEnabled()) {
    LOG.debug("Filesystem " + fsURI
            + " is using configuration keys " + prefix);
  }
  Properties props = new Properties();
  props.setProperty(SWIFT_SERVICE_PROPERTY, service);
  props.setProperty(SWIFT_CONTAINER_PROPERTY, container);
  copy(conf, prefix + DOT_AUTH_URL, props, SWIFT_AUTH_PROPERTY, true);
  copy(conf, prefix + DOT_USERNAME, props, SWIFT_USERNAME_PROPERTY, true);
  copy(conf, prefix + DOT_APIKEY, props, SWIFT_APIKEY_PROPERTY, false);
  copy(conf, prefix + DOT_PASSWORD, props, SWIFT_PASSWORD_PROPERTY,
          props.contains(SWIFT_APIKEY_PROPERTY) ? true : false);
  copy(conf, prefix + DOT_TENANT, props, SWIFT_TENANT_PROPERTY, false);
  copy(conf, prefix + DOT_REGION, props, SWIFT_REGION_PROPERTY, false);
  copy(conf, prefix + DOT_HTTP_PORT, props, SWIFT_HTTP_PORT_PROPERTY, false);
  copy(conf, prefix +
          DOT_HTTPS_PORT, props, SWIFT_HTTPS_PORT_PROPERTY, false);

  copyBool(conf, prefix + DOT_PUBLIC, props, SWIFT_PUBLIC_PROPERTY, false);
  copyBool(conf, prefix + DOT_LOCATION_AWARE, props,
           SWIFT_LOCATION_AWARE_PROPERTY, false);

  return props;
}
 
Example 18
Source Project: big-c   Source File: SwiftRestClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get a mandatory configuration option
 *
 * @param props property set
 * @param key   key
 * @return value of the configuration
 * @throws SwiftConfigurationException if there was no match for the key
 */
private static String getOption(Properties props, String key) throws
        SwiftConfigurationException {
  String val = props.getProperty(key);
  if (val == null) {
    throw new SwiftConfigurationException("Undefined property: " + key);
  }
  return val;
}
 
Example 19
Source Project: big-c   Source File: SwiftTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the test URI
 * @param conf configuration
 * @throws SwiftConfigurationException missing parameter or bad URI
 */
public static URI getServiceURI(Configuration conf) throws
                                                    SwiftConfigurationException {
  String instance = conf.get(TEST_FS_SWIFT);
  if (instance == null) {
    throw new SwiftConfigurationException(
      "Missing configuration entry " + TEST_FS_SWIFT);
  }
  try {
    return new URI(instance);
  } catch (URISyntaxException e) {
    throw new SwiftConfigurationException("Bad URI: " + instance);
  }
}
 
Example 20
Source Project: big-c   Source File: TestRestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
public void expectBindingFailure(URI fsURI, Configuration config) {
  try {
    Properties binding = RestClientBindings.bind(fsURI, config);
    //if we get here, binding didn't fail- there is something else.
    //list the properties but not the values.
    StringBuilder details = new StringBuilder() ;
    for (Object key: binding.keySet()) {
      details.append(key.toString()).append(" ");
    }
    fail("Expected a failure, got the binding [ "+ details+"]");
  } catch (SwiftConfigurationException expected) {

  }
}
 
Example 21
Source Project: big-c   Source File: TestRestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * inner test method that expects container extraction to fail
 * -if not prints a meaningful error message.
 *
 * @param hostname hostname to parse
 */
private static void expectExtractContainerFail(String hostname) {
  try {
    String container = RestClientBindings.extractContainerName(hostname);
    fail("Expected an error -got a container of '" + container
            + "' from " + hostname);
  } catch (SwiftConfigurationException expected) {
    //expected
  }
}
 
Example 22
Source Project: big-c   Source File: TestRestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * inner test method that expects service extraction to fail
 * -if not prints a meaningful error message.
 *
 * @param hostname hostname to parse
 */
public static void expectExtractServiceFail(String hostname) {
  try {
    String service = RestClientBindings.extractServiceName(hostname);
    fail("Expected an error -got a service of '" + service
            + "' from " + hostname);
  } catch (SwiftConfigurationException expected) {
    //expected
  }
}
 
Example 23
Source Project: sahara-extra   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the container name from the hostname -the single element before the
 * first "." in the hostname
 *
 * @param hostname hostname to split
 * @return the container
 * @throws SwiftConfigurationException
 */
public static String extractContainerName(String hostname) throws
        SwiftConfigurationException {
  int i = hostname.indexOf(".");
  if (i <= 0) {
    throw invalidName(hostname);
  }
  return hostname.substring(0, i);
}
 
Example 24
Source Project: sahara-extra   Source File: RestClientBindings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the service name from a longer hostname string
 *
 * @param hostname hostname
 * @return the separated out service name
 * @throws SwiftConfigurationException if the hostname was invalid
 */
public static String extractServiceName(String hostname) throws
        SwiftConfigurationException {
  int i = hostname.indexOf(".");
  if (i <= 0) {
    throw invalidName(hostname);
  }
  String service = hostname.substring(i + 1);
  if (service.isEmpty() || service.contains(".")) {
    //empty service contains dots in -not currently supported
    throw invalidName(hostname);
  }
  return service;
}
 
Example 25
Source Project: sahara-extra   Source File: SwiftRestClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get a mandatory configuration option
 *
 * @param props property set
 * @param key   key
 * @return value of the configuration
 * @throws SwiftConfigurationException if there was no match for the key
 */
private static String getOption(Properties props, String key) throws
        SwiftConfigurationException {
  String val = props.getProperty(key);
  if (val == null) {
    throw new SwiftConfigurationException("Undefined property: " + key);
  }
  return val;
}
 
Example 26
Source Project: sahara-extra   Source File: SwiftTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the test URI
 * @param conf configuration
 * @throws SwiftConfigurationException missing parameter or bad URI
 */
public static URI getServiceURI(Configuration conf) throws
                                                    SwiftConfigurationException {
  String instance = conf.get(TEST_FS_SWIFT);
  if (instance == null) {
    throw new SwiftConfigurationException(
      "Missing configuration entry " + TEST_FS_SWIFT);
  }
  try {
    return new URI(instance);
  } catch (URISyntaxException e) {
    throw new SwiftConfigurationException("Bad URI: " + instance);
  }
}
 
Example 27
Source Project: sahara-extra   Source File: TestSwiftConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException.class)
public void testEmptyUrl() throws Exception {
  final Configuration configuration = new Configuration();

  set(configuration, DOT_TENANT, "tenant");
  set(configuration, DOT_USERNAME, "username");
  set(configuration, DOT_PASSWORD, "password");
  mkInstance(configuration);
}
 
Example 28
Source Project: sahara-extra   Source File: TestSwiftConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException.class)
public void testEmptyUsername() throws Exception {
  final Configuration configuration = new Configuration();
  set(configuration, DOT_AUTH_URL, "http://localhost:8080");
  set(configuration, DOT_TENANT, "tenant");
  set(configuration, DOT_PASSWORD, "password");
  mkInstance(configuration);
}
 
Example 29
Source Project: sahara-extra   Source File: TestSwiftConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException.class)
public void testEmptyPassword() throws Exception {
  final Configuration configuration = new Configuration();
  set(configuration, DOT_AUTH_URL, "http://localhost:8080");
  set(configuration, DOT_TENANT, "tenant");
  set(configuration, DOT_USERNAME, "username");
  mkInstance(configuration);
}
 
Example 30
Source Project: sahara-extra   Source File: TestSwiftConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBadRetryCount() throws Exception {
  final Configuration configuration = createCoreConfig();
  configuration.set(SWIFT_RETRY_COUNT, "three");
  try {
    mkInstance(configuration);
  } catch (SwiftConfigurationException e) {
    if (TestUtils.isHadoop1())
      Assert.fail();
    return;
  }
  if (!TestUtils.isHadoop1())
    Assert.fail();
}