HDDS-568. ozone sh volume info, update, delete operations fail when volume name is not prefixed by /.
Contributed by Dinesh Chitlangia.
This commit is contained in:
parent
605622c87b
commit
4de2dc2699
|
@ -283,6 +283,33 @@ public class TestOzoneShell {
|
||||||
GenericTestUtils.assertExceptionContains(
|
GenericTestUtils.assertExceptionContains(
|
||||||
"Info Volume failed, error:VOLUME_NOT_FOUND", e);
|
"Info Volume failed, error:VOLUME_NOT_FOUND", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
volumeName = "volume" + RandomStringUtils.randomNumeric(5);
|
||||||
|
volumeArgs = VolumeArgs.newBuilder()
|
||||||
|
.setOwner("bilbo")
|
||||||
|
.setQuota("100TB")
|
||||||
|
.build();
|
||||||
|
client.createVolume(volumeName, volumeArgs);
|
||||||
|
volume = client.getVolumeDetails(volumeName);
|
||||||
|
assertNotNull(volume);
|
||||||
|
|
||||||
|
//volumeName prefixed with /
|
||||||
|
String volumeNameWithSlashPrefix = "/" + volumeName;
|
||||||
|
args = new String[] {"volume", "delete",
|
||||||
|
url + "/" + volumeNameWithSlashPrefix};
|
||||||
|
execute(shell, args);
|
||||||
|
output = out.toString();
|
||||||
|
assertTrue(output.contains("Volume " + volumeName + " is deleted"));
|
||||||
|
|
||||||
|
// verify if volume has been deleted
|
||||||
|
try {
|
||||||
|
client.getVolumeDetails(volumeName);
|
||||||
|
fail("Get volume call should have thrown.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
GenericTestUtils.assertExceptionContains(
|
||||||
|
"Info Volume failed, error:VOLUME_NOT_FOUND", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -295,6 +322,7 @@ public class TestOzoneShell {
|
||||||
.build();
|
.build();
|
||||||
client.createVolume(volumeName, volumeArgs);
|
client.createVolume(volumeName, volumeArgs);
|
||||||
|
|
||||||
|
//volumeName supplied as-is
|
||||||
String[] args = new String[] {"volume", "info", url + "/" + volumeName};
|
String[] args = new String[] {"volume", "info", url + "/" + volumeName};
|
||||||
execute(shell, args);
|
execute(shell, args);
|
||||||
|
|
||||||
|
@ -303,6 +331,17 @@ public class TestOzoneShell {
|
||||||
assertTrue(output.contains("createdOn")
|
assertTrue(output.contains("createdOn")
|
||||||
&& output.contains(OzoneConsts.OZONE_TIME_ZONE));
|
&& output.contains(OzoneConsts.OZONE_TIME_ZONE));
|
||||||
|
|
||||||
|
//volumeName prefixed with /
|
||||||
|
String volumeNameWithSlashPrefix = "/" + volumeName;
|
||||||
|
args = new String[] {"volume", "info",
|
||||||
|
url + "/" + volumeNameWithSlashPrefix};
|
||||||
|
execute(shell, args);
|
||||||
|
|
||||||
|
output = out.toString();
|
||||||
|
assertTrue(output.contains(volumeName));
|
||||||
|
assertTrue(output.contains("createdOn")
|
||||||
|
&& output.contains(OzoneConsts.OZONE_TIME_ZONE));
|
||||||
|
|
||||||
// test infoVolume with invalid volume name
|
// test infoVolume with invalid volume name
|
||||||
args = new String[] {"volume", "info",
|
args = new String[] {"volume", "info",
|
||||||
url + "/" + volumeName + "/invalid-name"};
|
url + "/" + volumeName + "/invalid-name"};
|
||||||
|
@ -365,6 +404,15 @@ public class TestOzoneShell {
|
||||||
vol = client.getVolumeDetails(volumeName);
|
vol = client.getVolumeDetails(volumeName);
|
||||||
assertEquals(newUser, vol.getOwner());
|
assertEquals(newUser, vol.getOwner());
|
||||||
|
|
||||||
|
//volume with / prefix
|
||||||
|
String volumeWithPrefix = "/" + volumeName;
|
||||||
|
String newUser2 = "new-user2";
|
||||||
|
args = new String[] {"volume", "update", url + "/" + volumeWithPrefix,
|
||||||
|
"--user", newUser2};
|
||||||
|
execute(shell, args);
|
||||||
|
vol = client.getVolumeDetails(volumeName);
|
||||||
|
assertEquals(newUser2, vol.getOwner());
|
||||||
|
|
||||||
// test error conditions
|
// test error conditions
|
||||||
args = new String[] {"volume", "update", url + "/invalid-volume",
|
args = new String[] {"volume", "update", url + "/invalid-volume",
|
||||||
"--user", newUser};
|
"--user", newUser};
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.apache.hadoop.ozone.web.ozShell;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
@ -153,6 +155,32 @@ public abstract class Handler implements Callable<Void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param uri
|
||||||
|
* @return volumeName
|
||||||
|
* @throws Exception
|
||||||
|
* @throws OzoneClientException when uri is null or invalid volume name
|
||||||
|
*/
|
||||||
|
protected String parseVolumeName(String uri) throws Exception{
|
||||||
|
URI ozoneURI = verifyURI(uri);
|
||||||
|
Path path = Paths.get(ozoneURI.getPath());
|
||||||
|
int pathNameCount = path.getNameCount();
|
||||||
|
if (pathNameCount != 1) {
|
||||||
|
String errorMessage;
|
||||||
|
if (pathNameCount < 1) {
|
||||||
|
errorMessage = "Volume name is required to perform volume " +
|
||||||
|
"operations like info, update, create and delete. ";
|
||||||
|
} else {
|
||||||
|
errorMessage = "Invalid volume name. Delimiters (/) not allowed in " +
|
||||||
|
"volume name";
|
||||||
|
}
|
||||||
|
throw new OzoneClientException(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ozoneURI.getPath().replaceAll("^/+", "");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVerbose() {
|
public boolean isVerbose() {
|
||||||
return parent.isVerbose();
|
return parent.isVerbose();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,6 @@
|
||||||
|
|
||||||
package org.apache.hadoop.ozone.web.ozShell.volume;
|
package org.apache.hadoop.ozone.web.ozShell.volume;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.apache.hadoop.ozone.client.OzoneClientException;
|
|
||||||
import org.apache.hadoop.ozone.web.ozShell.Handler;
|
import org.apache.hadoop.ozone.web.ozShell.Handler;
|
||||||
import org.apache.hadoop.ozone.web.ozShell.Shell;
|
import org.apache.hadoop.ozone.web.ozShell.Shell;
|
||||||
|
|
||||||
|
@ -43,14 +40,7 @@ public class DeleteVolumeHandler extends Handler {
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
|
|
||||||
URI ozoneURI = verifyURI(uri);
|
String volumeName = parseVolumeName(uri);
|
||||||
if (ozoneURI.getPath().isEmpty()) {
|
|
||||||
throw new OzoneClientException(
|
|
||||||
"Volume name is required to delete a volume");
|
|
||||||
}
|
|
||||||
|
|
||||||
// we need to skip the slash in the URI path
|
|
||||||
String volumeName = ozoneURI.getPath().substring(1);
|
|
||||||
|
|
||||||
if (isVerbose()) {
|
if (isVerbose()) {
|
||||||
System.out.printf("Volume name : %s%n", volumeName);
|
System.out.printf("Volume name : %s%n", volumeName);
|
||||||
|
|
|
@ -18,11 +18,6 @@
|
||||||
|
|
||||||
package org.apache.hadoop.ozone.web.ozShell.volume;
|
package org.apache.hadoop.ozone.web.ozShell.volume;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import org.apache.hadoop.ozone.client.OzoneClientException;
|
|
||||||
import org.apache.hadoop.ozone.client.OzoneClientUtils;
|
import org.apache.hadoop.ozone.client.OzoneClientUtils;
|
||||||
import org.apache.hadoop.ozone.client.OzoneVolume;
|
import org.apache.hadoop.ozone.client.OzoneVolume;
|
||||||
import org.apache.hadoop.ozone.web.ozShell.Handler;
|
import org.apache.hadoop.ozone.web.ozShell.Handler;
|
||||||
|
@ -48,22 +43,7 @@ public class InfoVolumeHandler extends Handler{
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
|
|
||||||
URI ozoneURI = verifyURI(uri);
|
String volumeName = parseVolumeName(uri);
|
||||||
Path path = Paths.get(ozoneURI.getPath());
|
|
||||||
int pathNameCount = path.getNameCount();
|
|
||||||
if (pathNameCount != 1) {
|
|
||||||
String errorMessage;
|
|
||||||
if (pathNameCount < 1) {
|
|
||||||
errorMessage = "Volume name is required to get info of a volume";
|
|
||||||
} else {
|
|
||||||
errorMessage = "Invalid volume name. Delimiters (/) not allowed in " +
|
|
||||||
"volume name";
|
|
||||||
}
|
|
||||||
throw new OzoneClientException(errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// we need to skip the slash in the URI path
|
|
||||||
String volumeName = ozoneURI.getPath().substring(1);
|
|
||||||
|
|
||||||
OzoneVolume vol = client.getObjectStore().getVolume(volumeName);
|
OzoneVolume vol = client.getObjectStore().getVolume(volumeName);
|
||||||
System.out.printf("%s%n", JsonUtils.toJsonStringWithDefaultPrettyPrinter(
|
System.out.printf("%s%n", JsonUtils.toJsonStringWithDefaultPrettyPrinter(
|
||||||
|
|
|
@ -25,13 +25,10 @@ import picocli.CommandLine.Parameters;
|
||||||
import org.apache.hadoop.hdds.client.OzoneQuota;
|
import org.apache.hadoop.hdds.client.OzoneQuota;
|
||||||
import org.apache.hadoop.ozone.client.OzoneVolume;
|
import org.apache.hadoop.ozone.client.OzoneVolume;
|
||||||
import org.apache.hadoop.ozone.client.OzoneClientUtils;
|
import org.apache.hadoop.ozone.client.OzoneClientUtils;
|
||||||
import org.apache.hadoop.ozone.client.OzoneClientException;
|
|
||||||
import org.apache.hadoop.ozone.web.ozShell.Handler;
|
import org.apache.hadoop.ozone.web.ozShell.Handler;
|
||||||
import org.apache.hadoop.ozone.web.ozShell.Shell;
|
import org.apache.hadoop.ozone.web.ozShell.Shell;
|
||||||
import org.apache.hadoop.ozone.web.utils.JsonUtils;
|
import org.apache.hadoop.ozone.web.utils.JsonUtils;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes update volume calls.
|
* Executes update volume calls.
|
||||||
*/
|
*/
|
||||||
|
@ -57,14 +54,7 @@ public class UpdateVolumeHandler extends Handler {
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
|
|
||||||
URI ozoneURI = verifyURI(uri);
|
String volumeName = parseVolumeName(uri);
|
||||||
if (ozoneURI.getPath().isEmpty()) {
|
|
||||||
throw new OzoneClientException(
|
|
||||||
"Volume name is required to update a volume");
|
|
||||||
}
|
|
||||||
|
|
||||||
// we need to skip the slash in the URI path
|
|
||||||
String volumeName = ozoneURI.getPath().substring(1);
|
|
||||||
|
|
||||||
OzoneVolume volume = client.getObjectStore().getVolume(volumeName);
|
OzoneVolume volume = client.getObjectStore().getVolume(volumeName);
|
||||||
if (quota != null && !quota.isEmpty()) {
|
if (quota != null && !quota.isEmpty()) {
|
||||||
|
|
Loading…
Reference in New Issue