use of java.net.URISyntaxException in project flink by apache.
the class BlobCacheSuccessTest method uploadFileGetTest.
private void uploadFileGetTest(final Configuration config, boolean cacheWorksWithoutServer, boolean cacheHasAccessToFs) {
// First create two BLOBs and upload them to BLOB server
final byte[] buf = new byte[128];
final List<BlobKey> blobKeys = new ArrayList<BlobKey>(2);
BlobServer blobServer = null;
BlobCache blobCache = null;
try {
// Start the BLOB server
blobServer = new BlobServer(config);
final InetSocketAddress serverAddress = new InetSocketAddress(blobServer.getPort());
// Upload BLOBs
BlobClient blobClient = null;
try {
blobClient = new BlobClient(serverAddress, config);
blobKeys.add(blobClient.put(buf));
// Make sure the BLOB key changes
buf[0] = 1;
blobKeys.add(blobClient.put(buf));
} finally {
if (blobClient != null) {
blobClient.close();
}
}
if (cacheWorksWithoutServer) {
// Now, shut down the BLOB server, the BLOBs must still be accessible through the cache.
blobServer.shutdown();
blobServer = null;
}
final Configuration cacheConfig;
if (cacheHasAccessToFs) {
cacheConfig = config;
} else {
// just in case parameters are still read from the server,
// create a separate configuration object for the cache
cacheConfig = new Configuration(config);
cacheConfig.setString(HighAvailabilityOptions.HA_STORAGE_PATH, temporaryFolder.getRoot().getPath() + "/does-not-exist");
}
blobCache = new BlobCache(serverAddress, cacheConfig);
for (BlobKey blobKey : blobKeys) {
blobCache.getURL(blobKey);
}
if (blobServer != null) {
// Now, shut down the BLOB server, the BLOBs must still be accessible through the cache.
blobServer.shutdown();
blobServer = null;
}
final URL[] urls = new URL[blobKeys.size()];
for (int i = 0; i < blobKeys.size(); i++) {
urls[i] = blobCache.getURL(blobKeys.get(i));
}
// Verify the result
assertEquals(blobKeys.size(), urls.length);
for (final URL url : urls) {
assertNotNull(url);
try {
final File cachedFile = new File(url.toURI());
assertTrue(cachedFile.exists());
assertEquals(buf.length, cachedFile.length());
} catch (URISyntaxException e) {
fail(e.getMessage());
}
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
} finally {
if (blobServer != null) {
blobServer.shutdown();
}
if (blobCache != null) {
blobCache.shutdown();
}
}
}
use of java.net.URISyntaxException in project hadoop by apache.
the class HarFileSystem method decodeHarURI.
/**
* decode the raw URI to get the underlying URI
* @param rawURI raw Har URI
* @return filtered URI of the underlying fileSystem
*/
private URI decodeHarURI(URI rawURI, Configuration conf) throws IOException {
String tmpAuth = rawURI.getAuthority();
//return it
if (tmpAuth == null) {
//create a path
return FileSystem.getDefaultUri(conf);
}
String authority = rawURI.getAuthority();
int i = authority.indexOf('-');
if (i < 0) {
throw new IOException("URI: " + rawURI + " is an invalid Har URI since '-' not found." + " Expecting har://<scheme>-<host>/<path>.");
}
if (rawURI.getQuery() != null) {
// query component not allowed
throw new IOException("query component in Path not supported " + rawURI);
}
URI tmp;
try {
// convert <scheme>-<host> to <scheme>://<host>
URI baseUri = new URI(authority.replaceFirst("-", "://"));
tmp = new URI(baseUri.getScheme(), baseUri.getAuthority(), rawURI.getPath(), rawURI.getQuery(), rawURI.getFragment());
} catch (URISyntaxException e) {
throw new IOException("URI: " + rawURI + " is an invalid Har URI. Expecting har://<scheme>-<host>/<path>.");
}
return tmp;
}
use of java.net.URISyntaxException in project hadoop by apache.
the class Path method makeQualified.
/**
* Returns a qualified path object.
*
* @param defaultUri if this path is missing the scheme or authority
* components, borrow them from this URI
* @param workingDir if this path isn't absolute, treat it as relative to this
* working directory
* @return this path if it contains a scheme and authority and is absolute, or
* a new path that includes a path and authority and is fully qualified
*/
@InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" })
public Path makeQualified(URI defaultUri, Path workingDir) {
Path path = this;
if (!isAbsolute()) {
path = new Path(workingDir, this);
}
URI pathUri = path.toUri();
String scheme = pathUri.getScheme();
String authority = pathUri.getAuthority();
String fragment = pathUri.getFragment();
if (scheme != null && (authority != null || defaultUri.getAuthority() == null))
return path;
if (scheme == null) {
scheme = defaultUri.getScheme();
}
if (authority == null) {
authority = defaultUri.getAuthority();
if (authority == null) {
authority = "";
}
}
URI newUri = null;
try {
newUri = new URI(scheme, authority, normalizePath(scheme, pathUri.getPath()), null, fragment);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
return new Path(newUri);
}
use of java.net.URISyntaxException in project hadoop by apache.
the class FsUrlConnection method connect.
@Override
public void connect() throws IOException {
try {
FileSystem fs = FileSystem.get(url.toURI(), conf);
is = fs.open(new Path(url.getPath()));
} catch (URISyntaxException e) {
throw new IOException(e.toString());
}
}
use of java.net.URISyntaxException in project camel by apache.
the class HttpsAsyncRouteTest method configureSslContextFactory.
protected void configureSslContextFactory(SslContextFactory sslContextFactory) {
sslContextFactory.setKeyManagerPassword(pwd);
sslContextFactory.setKeyStorePassword(pwd);
URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
try {
sslContextFactory.setKeyStorePath(keyStoreUrl.toURI().getPath());
} catch (URISyntaxException e) {
throw new RuntimeException(e.getMessage(), e);
}
sslContextFactory.setTrustStoreType("JKS");
}
Aggregations