org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException Java Examples
The following examples show how to use
org.apache.hadoop.fs.swift.exceptions.SwiftConfigurationException.
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 big-c with Apache License 2.0 | 6 votes |
/** * 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 hadoop with Apache License 2.0 | 6 votes |
/** * 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: SwiftNativeFileSystem.java From big-c with Apache License 2.0 | 6 votes |
/** * 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 File: SwiftNativeFileSystem.java From sahara-extra with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: SwiftNativeFileSystem.java From hadoop with Apache License 2.0 | 6 votes |
/** * 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 File: SwiftObjectPath.java From sahara-extra with Apache License 2.0 | 6 votes |
/** * 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 File: TestRestClientBindings.java From big-c with Apache License 2.0 | 5 votes |
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 #8
Source File: RestClientBindings.java From sahara-extra with Apache License 2.0 | 5 votes |
/** * 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 #9
Source File: SwiftTestUtils.java From big-c with Apache License 2.0 | 5 votes |
/** * 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 #10
Source File: SwiftRestClient.java From big-c with Apache License 2.0 | 5 votes |
/** * 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 File: RestClientBindings.java From big-c with Apache License 2.0 | 5 votes |
/** * 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 #12
Source File: SwiftRestClient.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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 #13
Source File: TestRestClientBindings.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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 #14
Source File: TestRestClientBindings.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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 #15
Source File: RestClientBindings.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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 #16
Source File: RestClientBindings.java From hadoop with Apache License 2.0 | 5 votes |
/** * 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 File: TestRestClientBindings.java From hadoop with Apache License 2.0 | 5 votes |
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 #18
Source File: TestRestClientBindings.java From big-c with Apache License 2.0 | 5 votes |
/** * 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 #19
Source File: TestRestClientBindings.java From big-c with Apache License 2.0 | 5 votes |
/** * 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 #20
Source File: TestRestClientBindings.java From sahara-extra with Apache License 2.0 | 5 votes |
/** * 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 #21
Source File: RestClientBindings.java From sahara-extra with Apache License 2.0 | 5 votes |
/** * 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 #22
Source File: SwiftRestClient.java From sahara-extra with Apache License 2.0 | 5 votes |
/** * 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 #23
Source File: SwiftTestUtils.java From sahara-extra with Apache License 2.0 | 5 votes |
/** * 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 #24
Source File: TestSwiftConfig.java From sahara-extra with Apache License 2.0 | 5 votes |
@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 #25
Source File: TestSwiftConfig.java From sahara-extra with Apache License 2.0 | 5 votes |
@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 #26
Source File: TestSwiftConfig.java From sahara-extra with Apache License 2.0 | 5 votes |
@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 #27
Source File: TestSwiftConfig.java From sahara-extra with Apache License 2.0 | 5 votes |
@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(); }
Example #28
Source File: TestSwiftConfig.java From sahara-extra with Apache License 2.0 | 5 votes |
@Test public void testBadConnectTimeout() throws Exception { final Configuration configuration = createCoreConfig(); configuration.set(SWIFT_CONNECTION_TIMEOUT, "three"); try { mkInstance(configuration); } catch (SwiftConfigurationException e) { if (TestUtils.isHadoop1()) Assert.fail(); return; } if (!TestUtils.isHadoop1()) Assert.fail(); }
Example #29
Source File: TestRestClientBindings.java From sahara-extra with Apache License 2.0 | 5 votes |
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 #30
Source File: TestRestClientBindings.java From sahara-extra with Apache License 2.0 | 5 votes |
/** * 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 } }