HADOOP-6560. Handle invalid har:// uri in HarFileSystem.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@910726 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
44185c3874
commit
18c6d65749
|
@ -202,6 +202,8 @@ Trunk (unreleased changes)
|
||||||
|
|
||||||
HADOOP-6548. Replace mortbay imports with commons logging. (cdouglas)
|
HADOOP-6548. Replace mortbay imports with commons logging. (cdouglas)
|
||||||
|
|
||||||
|
HADOOP-6560. Handle invalid har:// uri in HarFileSystem. (szetszwo)
|
||||||
|
|
||||||
Release 0.21.0 - Unreleased
|
Release 0.21.0 - Unreleased
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -182,12 +182,20 @@ public class HarFileSystem extends FilterFileSystem {
|
||||||
return FileSystem.getDefaultUri(conf);
|
return FileSystem.getDefaultUri(conf);
|
||||||
}
|
}
|
||||||
String host = rawURI.getHost();
|
String host = rawURI.getHost();
|
||||||
String[] str = host.split("-", 2);
|
if (host == null) {
|
||||||
if (str[0] == null) {
|
throw new IOException("URI: " + rawURI
|
||||||
throw new IOException("URI: " + rawURI + " is an invalid Har URI.");
|
+ " is an invalid Har URI since host==null."
|
||||||
|
+ " Expecting har://<scheme>-<host>/<path>.");
|
||||||
}
|
}
|
||||||
String underLyingScheme = str[0];
|
int i = host.indexOf('-');
|
||||||
String underLyingHost = (str.length > 1)? str[1]:null;
|
if (i < 0) {
|
||||||
|
throw new IOException("URI: " + rawURI
|
||||||
|
+ " is an invalid Har URI since '-' not found."
|
||||||
|
+ " Expecting har://<scheme>-<host>/<path>.");
|
||||||
|
}
|
||||||
|
final String underLyingScheme = host.substring(0, i);
|
||||||
|
i++;
|
||||||
|
final String underLyingHost = i == host.length()? null: host.substring(i);
|
||||||
int underLyingPort = rawURI.getPort();
|
int underLyingPort = rawURI.getPort();
|
||||||
String auth = (underLyingHost == null && underLyingPort == -1)?
|
String auth = (underLyingHost == null && underLyingPort == -1)?
|
||||||
null:(underLyingHost+":"+underLyingPort);
|
null:(underLyingHost+":"+underLyingPort);
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.hadoop.fs;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestHarFileSystem {
|
||||||
|
@Test
|
||||||
|
public void testHarUri() {
|
||||||
|
final Configuration conf = new Configuration();
|
||||||
|
checkInvalidPath("har://hdfs-/foo.har", conf);
|
||||||
|
checkInvalidPath("har://hdfs/foo.har", conf);
|
||||||
|
checkInvalidPath("har://-hdfs/foo.har", conf);
|
||||||
|
checkInvalidPath("har://-/foo.har", conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkInvalidPath(String s, Configuration conf) {
|
||||||
|
System.out.println("\ncheckInvalidPath: " + s);
|
||||||
|
final Path p = new Path(s);
|
||||||
|
try {
|
||||||
|
p.getFileSystem(conf);
|
||||||
|
Assert.fail(p + " is an invalid path.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("GOOD: Got an exception.");
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue