HDFS-12205. Ozone: List Key on an empty ozone bucket fails with command failed error. Contributed by Lokesh Jain.

This commit is contained in:
Yiqun Lin 2017-09-26 14:43:52 +08:00 committed by Owen O'Malley
parent 8052374e79
commit 712bd70ac7
3 changed files with 69 additions and 6 deletions

View File

@ -634,6 +634,10 @@ public void createBucket(BucketArgs args) throws OzoneException {
userDB.put(args.getParentName().getBytes(encoding),
bucketList.toDBString().getBytes(encoding));
// Update userDB with volume/bucket -> empty key list
userDB.put(args.getResourceName().getBytes(encoding),
new ListKeys().toDBString().getBytes(encoding));
// and update the metadataDB with volume/bucket->BucketInfo
metadataDB.put(args.getResourceName().getBytes(encoding),
bucketInfo.toDBString().getBytes(encoding));
@ -916,12 +920,7 @@ public void commitKey(KeyArgs args, OutputStream stream)
ListKeys keyList;
byte[] bucketListBytes = userDB.get(args.getParentName()
.getBytes(encoding));
if (bucketListBytes == null) {
keyList = new ListKeys();
} else {
keyList = ListKeys.parse(new String(bucketListBytes, encoding));
}
KeyInfo keyInfo;
byte[] objectBytes = metadataDB.get(args.getResourceName()

View File

@ -178,4 +178,8 @@ public void testGetVolumesOfAnotherUserShouldFail() throws IOException {
super.testGetVolumesOfAnotherUserShouldFail(port);
}
@Test
public void testListKeyOnEmptyBucket() throws IOException {
super.testListKeyOnEmptyBucket(port);
}
}

View File

@ -351,4 +351,64 @@ public void testGetVolumesOfAnotherUserShouldFail(int port)
}
}
public void testListKeyOnEmptyBucket(int port) throws IOException {
SimpleDateFormat format =
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZ", Locale.US);
CloseableHttpClient client = createHttpClient();
String volumeName = OzoneUtils.getRequestID().toLowerCase();
String bucketName = OzoneUtils.getRequestID().toLowerCase() + "bucket";
try {
HttpPost httppost = new HttpPost(
String.format("http://localhost:%d/%s", port, volumeName));
httppost.addHeader(Header.OZONE_VERSION_HEADER,
Header.OZONE_V1_VERSION_HEADER);
httppost.addHeader(HttpHeaders.DATE,
format.format(new Date(Time.monotonicNow())));
httppost.addHeader(HttpHeaders.AUTHORIZATION,
Header.OZONE_SIMPLE_AUTHENTICATION_SCHEME + " "
+ OzoneConsts.OZONE_SIMPLE_HDFS_USER);
httppost.addHeader(Header.OZONE_USER, OzoneConsts.OZONE_SIMPLE_HDFS_USER);
HttpResponse response = client.execute(httppost);
assertEquals(response.toString(), HTTP_CREATED,
response.getStatusLine().getStatusCode());
client.close();
client = createHttpClient();
httppost = new HttpPost(String
.format("http://localhost:%d/%s/%s", port, volumeName, bucketName));
httppost.addHeader(Header.OZONE_VERSION_HEADER,
Header.OZONE_V1_VERSION_HEADER);
httppost.addHeader(HttpHeaders.DATE,
format.format(new Date(Time.monotonicNow())));
httppost.addHeader(HttpHeaders.AUTHORIZATION,
Header.OZONE_SIMPLE_AUTHENTICATION_SCHEME + " "
+ OzoneConsts.OZONE_SIMPLE_HDFS_USER);
httppost.addHeader(Header.OZONE_USER, OzoneConsts.OZONE_SIMPLE_HDFS_USER);
response = client.execute(httppost);
assertEquals(response.toString(), HTTP_CREATED,
response.getStatusLine().getStatusCode());
client.close();
client = createHttpClient();
HttpGet httpget = new HttpGet(String
.format("http://localhost:%d/%s/%s", port, volumeName, bucketName));
httpget.addHeader(Header.OZONE_VERSION_HEADER,
Header.OZONE_V1_VERSION_HEADER);
httpget.addHeader(HttpHeaders.DATE,
format.format(new Date(Time.monotonicNow())));
httpget.addHeader(HttpHeaders.AUTHORIZATION,
Header.OZONE_SIMPLE_AUTHENTICATION_SCHEME + " "
+ OzoneConsts.OZONE_SIMPLE_HDFS_USER);
httpget.addHeader(Header.OZONE_USER, OzoneConsts.OZONE_SIMPLE_HDFS_USER);
response = client.execute(httpget);
assertEquals(response.toString() + " " + response.getStatusLine()
.getReasonPhrase(), HTTP_OK,
response.getStatusLine().getStatusCode());
} finally {
client.close();
}
}
}