/** * Appends the given path to the given base URI. * * @param base the base URI * @param path the path to append * @return the URI resulting from appending the base and the path * @throws URISyntaxException if URI syntax error is encountered */ public static URI appendPath(URI base, String path) throws URISyntaxException { return new URI(base.getScheme(), base.getAuthority(), PathUtils.concatPath(base.getPath(), path), base.getQuery(), base.getFragment()); }
private static URI extractClusterUri(URI uri) { try { return new URI(uri.getScheme(), uri.getAuthority(), null, null, null); } catch (URISyntaxException e) { throw new AssertionError(e); } } }
URI a = new URI("http://www.foo.com"); URI b = new URI("bar.html"); URI c = a.resolve(b); c.toString() -> "http://www.foo.combar.html" c.getAuthority() -> "www.foo.com" c.getPath() -> "bar.html"
public OssStorageResource(OSS oss, String location) { Assert.notNull(oss, "Object Storage Service can not be null"); Assert.isTrue(location.startsWith(OssStorageProtocolResolver.PROTOCOL), "Location must start with " + OssStorageProtocolResolver.PROTOCOL); this.oss = oss; try { URI locationUri = new URI(location); this.bucketName = locationUri.getAuthority(); if (locationUri.getPath() != null && locationUri.getPath().length() > 1) { this.objectKey = locationUri.getPath().substring(1); } else { this.objectKey = null; } this.location = locationUri; } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid location: " + location, e); } }
/** * Mangle given local java keystore file URI to allow use as a * LocalJavaKeyStoreProvider. * @param localFile absolute URI with file scheme and no authority component. * i.e. return of File.toURI, * e.g. file:///home/larry/creds.jceks * @return URI of the form localjceks://file/home/larry/creds.jceks * @throws IllegalArgumentException if localFile isn't not a file uri or if it * has an authority component. * @throws URISyntaxException if the wrapping process violates RFC 2396 */ public static URI nestURIForLocalJavaKeyStoreProvider(final URI localFile) throws URISyntaxException { if (!("file".equals(localFile.getScheme()))) { throw new IllegalArgumentException("passed URI had a scheme other than " + "file."); } if (localFile.getAuthority() != null) { throw new IllegalArgumentException("passed URI must not have an " + "authority component. For non-local keystores, please use " + JavaKeyStoreProvider.class.getName()); } return new URI(LocalJavaKeyStoreProvider.SCHEME_NAME, "//file" + localFile.getSchemeSpecificPart(), localFile.getFragment()); }
@Override public String toString() { // we can't use uri.toString(), which escapes everything, because we want // illegal characters unescaped in the string, for glob processing, etc. final StringBuilder buffer = new StringBuilder(); if (uri.getScheme() != null) { buffer.append(uri.getScheme()); buffer.append(":"); } if (uri.getAuthority() != null) { buffer.append("//"); buffer.append(uri.getAuthority()); } if (uri.getPath() != null) { String path = uri.getPath(); if (path.indexOf('/') == 0 && hasWindowsDrive(path, true) && // has windows drive uri.getScheme() == null && // but no scheme uri.getAuthority() == null) { // or authority path = path.substring(1); // remove slash before drive } buffer.append(path); } return buffer.toString(); }
@Override protected URI getInitURI(URI fsUri, org.apache.hadoop.conf.Configuration hadoopConfig) { final String scheme = fsUri.getScheme(); final String authority = fsUri.getAuthority(); if (scheme == null && authority == null) { fsUri = org.apache.hadoop.fs.FileSystem.getDefaultUri(hadoopConfig); } else if (scheme != null && authority == null) { URI defaultUri = org.apache.hadoop.fs.FileSystem.getDefaultUri(hadoopConfig); if (scheme.equals(defaultUri.getScheme()) && defaultUri.getAuthority() != null) { fsUri = defaultUri; } } LOG.debug("Using scheme {} for s3a file system backing the S3 File System", fsUri); return fsUri; }
/** * Convert IGFS path into Hadoop path. * * @param path IGFS path. * @return Hadoop path. */ private Path convert(IgfsPath path) { URI uri = fileSystemForUser().getUri(); return new Path(uri.getScheme(), uri.getAuthority(), path.toString()); }
private static HttpResponse doCall(ArmeriaCallFactory callFactory, Request request) { final HttpUrl httpUrl = request.url(); final URI uri = httpUrl.uri(); final HttpClient httpClient = callFactory.getHttpClient(uri.getAuthority(), uri.getScheme()); final String uriString; if (uri.getQuery() == null) { uriString = httpUrl.encodedPath(); } else {
private static Path reservedRawPath(URI uri) { return new Path(uri.getScheme(), uri.getAuthority(), CopyUtils.RAW_RESERVED_VIRTUAL_PATH + uri.getPath()); }
/** * Converts the current endpoint set for this client into virtual addressing style, by placing * the name of the specified bucket before the S3 service endpoint. * * @param bucketName The name of the bucket to use in the virtual addressing style of the returned URI. * @return A new URI, creating from the current service endpoint URI and the specified bucket. */ private static URI convertToVirtualHostEndpoint(URI endpoint, String bucketName) { try { return new URI(String.format("%s://%s.%s", endpoint.getScheme(), bucketName, endpoint.getAuthority())); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid bucket name: " + bucketName, e); } }
/** * A naive implementation of generating a jobSpec's URI within a multi-hop flow that follows the convention: * <JOB_CATALOG_SCHEME>/{@link ConfigurationKeys#JOB_GROUP_KEY}/{@link ConfigurationKeys#JOB_NAME_KEY}. */ private static URI jobSpecURIGenerator(String jobGroup, String jobName, FlowSpec flowSpec) throws URISyntaxException { return new URI(JobSpec.Builder.DEFAULT_JOB_CATALOG_SCHEME, flowSpec.getUri().getAuthority(), StringUtils.appendIfMissing(StringUtils.prependIfMissing(flowSpec.getUri().getPath(), "/"), "/") + jobGroup + "/" + jobName, null); } }
/** * Returns the parent of a path, i.e., everything that precedes the last separator * or <code>null</code> if at root. * * @return the parent of a path or <code>null</code> if at root. */ public Path getParent() { final String path = uri.getPath(); final int lastSlash = path.lastIndexOf('/'); final int start = hasWindowsDrive(path, true) ? 3 : 0; if ((path.length() == start) || // empty path (lastSlash == start && path.length() == start + 1)) { // at root return null; } String parent; if (lastSlash == -1) { parent = CUR_DIR; } else { final int end = hasWindowsDrive(path, true) ? 3 : 0; parent = path.substring(0, lastSlash == end ? end + 1 : lastSlash); } return new Path(uri.getScheme(), uri.getAuthority(), parent); }
@Inject public HdfsStorage(final HdfsAuth hdfsAuth, final FileSystem hdfs, final AzkabanCommonModuleConfig config) { this.hdfsAuth = requireNonNull(hdfsAuth); this.hdfs = requireNonNull(hdfs); this.rootUri = config.getHdfsRootUri(); requireNonNull(this.rootUri.getAuthority(), "URI must have host:port mentioned."); checkArgument(HDFS_SCHEME.equals(this.rootUri.getScheme())); }
private Path makeRelative(String initial, Path p) { String scheme = this.uri.getScheme(); String authority = this.uri.getAuthority(); Path root = new Path(Path.SEPARATOR); if (root.compareTo(p) == 0) return new Path(scheme, authority, initial); Path retPath = new Path(p.getName()); Path parent = p.getParent(); for (int i=0; i < p.depth()-1; i++) { retPath = new Path(parent.getName(), retPath); parent = parent.getParent(); } return new Path(new Path(scheme, authority, initial), retPath.toString()); }
private Client<HttpRequest, HttpResponse> newHttpClient(URI uri, Scheme scheme, ClientOptions options) { try { @SuppressWarnings("unchecked") final Client<HttpRequest, HttpResponse> client = delegate().newClient( new URI(Scheme.of(SerializationFormat.NONE, scheme.sessionProtocol()).uriText(), uri.getAuthority(), null, null, null), Client.class, options); return client; } catch (URISyntaxException e) { throw new Error(e); // Should never happen. } } }
/** * Determine if a uri is in asterisk-form according to * <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>. */ public static boolean isAsteriskForm(URI uri) { return "*".equals(uri.getPath()) && uri.getScheme() == null && uri.getSchemeSpecificPart() == null && uri.getHost() == null && uri.getAuthority() == null && uri.getQuery() == null && uri.getFragment() == null; }
/** * Convert the input URI into a correctly formatted uri prefix. In the future, may also resolve d2 uris. */ public static String resolveUriPrefix(URI serverURI) throws URISyntaxException { if (RESTLI_SCHEMES.contains(serverURI.getScheme())) { return new URI(serverURI.getScheme(), serverURI.getAuthority(), null, null, null).toString() + "/"; } throw new RuntimeException("Unrecognized scheme for URI " + serverURI); } }
/** * A naive implementation of generating a jobSpec's URI within a multi-hop logical Flow. */ @Override public URI jobSpecURIGenerator(Object... objects) { FlowSpec flowSpec = (FlowSpec) objects[0]; ServiceNode sourceNode = (ServiceNode) objects[1]; ServiceNode targetNode = (ServiceNode) objects[2]; try { return new URI(JobSpec.Builder.DEFAULT_JOB_CATALOG_SCHEME, flowSpec.getUri().getAuthority(), StringUtils.appendIfMissing(StringUtils.prependIfMissing(flowSpec.getUri().getPath(), "/"),"/") + sourceNode.getNodeName() + "-" + targetNode.getNodeName(), null); } catch (URISyntaxException e) { log.error( "URI construction failed when jobSpec from " + sourceNode.getNodeName() + " to " + targetNode.getNodeName()); throw new RuntimeException(); } } }
@Test public void getStoreURI() { URI storeURI = this._simpleHadoopFilesystemConfigStore.getStoreURI(); Assert.assertEquals(storeURI.getScheme(), SimpleHDFSConfigStoreFactory.SIMPLE_HDFS_SCHEME_PREFIX + "file"); Assert.assertNull(storeURI.getAuthority()); Assert.assertEquals(storeURI.getPath(), System.getProperty("user.dir") + File.separator + CONFIG_DIR_NAME); }