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:
Tsz-wo Sze 2010-02-16 22:17:54 +00:00
parent 44185c3874
commit 18c6d65749
3 changed files with 63 additions and 5 deletions

View File

@ -202,6 +202,8 @@ Trunk (unreleased changes)
HADOOP-6548. Replace mortbay imports with commons logging. (cdouglas)
HADOOP-6560. Handle invalid har:// uri in HarFileSystem. (szetszwo)
Release 0.21.0 - Unreleased
INCOMPATIBLE CHANGES

View File

@ -182,12 +182,20 @@ public class HarFileSystem extends FilterFileSystem {
return FileSystem.getDefaultUri(conf);
}
String host = rawURI.getHost();
String[] str = host.split("-", 2);
if (str[0] == null) {
throw new IOException("URI: " + rawURI + " is an invalid Har URI.");
if (host == null) {
throw new IOException("URI: " + rawURI
+ " is an invalid Har URI since host==null."
+ " Expecting har://<scheme>-<host>/<path>.");
}
String underLyingScheme = str[0];
String underLyingHost = (str.length > 1)? str[1]:null;
int i = host.indexOf('-');
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();
String auth = (underLyingHost == null && underLyingPort == -1)?
null:(underLyingHost+":"+underLyingPort);

View File

@ -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);
}
}
}