HDFS-10684. WebHDFS DataNode calls fail without parameter createparent. Contributed by John Zhuge.
(cherry picked from commitfbdbbd57cd
) (cherry picked from commit6b795c34d0
)
This commit is contained in:
parent
120f3a0ff9
commit
158292fd7e
|
@ -39,7 +39,7 @@ public class CreateParentParam extends BooleanParam {
|
|||
* @param str a string representation of the parameter value.
|
||||
*/
|
||||
public CreateParentParam(final String str) {
|
||||
this(DOMAIN.parse(str));
|
||||
this(DOMAIN.parse(str == null ? DEFAULT : str));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,7 @@ public class OverwriteParam extends BooleanParam {
|
|||
* @param str a string representation of the parameter value.
|
||||
*/
|
||||
public OverwriteParam(final String str) {
|
||||
this(DOMAIN.parse(str));
|
||||
super(DOMAIN, DOMAIN.parse(str == null ? DEFAULT : str));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
@ -49,6 +50,7 @@ import org.apache.hadoop.hdfs.web.resources.NamenodeAddressParam;
|
|||
import org.apache.hadoop.io.IOUtils;
|
||||
import org.apache.hadoop.security.AccessControlException;
|
||||
import org.apache.hadoop.security.UserGroupInformation;
|
||||
import org.apache.hadoop.test.GenericTestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -533,6 +535,44 @@ public class TestWebHdfsFileSystemContract extends FileSystemContractBaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
public void testDatanodeCreateMissingParameter() throws IOException {
|
||||
final WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) fs;
|
||||
final Path testDir = new Path(MessageFormat.format("/test/{0}/{1}",
|
||||
TestWebHdfsFileSystemContract.class,
|
||||
GenericTestUtils.getMethodName()));
|
||||
assertTrue(webhdfs.mkdirs(testDir));
|
||||
|
||||
for (String dnCreateParam : new String[]{
|
||||
CreateFlagParam.NAME,
|
||||
CreateParentParam.NAME,
|
||||
OverwriteParam.NAME
|
||||
}) {
|
||||
final HttpOpParam.Op op = PutOpParam.Op.CREATE;
|
||||
final Path newfile = new Path(testDir, "newfile_" + dnCreateParam);
|
||||
final URL url = webhdfs.toUrl(op, newfile);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod(op.getType().toString());
|
||||
conn.setDoOutput(false);
|
||||
conn.setInstanceFollowRedirects(false);
|
||||
conn.connect();
|
||||
final String redirect = conn.getHeaderField("Location");
|
||||
conn.disconnect();
|
||||
|
||||
//remove createparent
|
||||
WebHdfsFileSystem.LOG.info("redirect = " + redirect);
|
||||
String re = "&" + dnCreateParam + "=[^&]*";
|
||||
String modified = redirect.replaceAll(re, "");
|
||||
WebHdfsFileSystem.LOG.info("modified = " + modified);
|
||||
|
||||
//connect to datanode
|
||||
conn = (HttpURLConnection)new URL(modified).openConnection();
|
||||
conn.setRequestMethod(op.getType().toString());
|
||||
conn.setDoOutput(op.getDoOutput());
|
||||
conn.connect();
|
||||
assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccess() throws IOException, InterruptedException {
|
||||
Path p1 = new Path("/pathX");
|
||||
|
|
Loading…
Reference in New Issue