Skip to content

Commit

Permalink
HDDS-439. 'ozone oz volume create' should default to current logged i…
Browse files Browse the repository at this point in the history
…n user. Contributed by Dinesh Chitlangia.
  • Loading branch information
arp7 committed Oct 16, 2018
1 parent 2614078 commit 0bf8a11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Expand Up @@ -32,6 +32,7 @@
import java.util.Random;
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.hdds.cli.MissingSubcommandException;
Expand Down Expand Up @@ -60,6 +61,7 @@
import org.apache.hadoop.ozone.web.response.KeyInfo;
import org.apache.hadoop.ozone.web.response.VolumeInfo;
import org.apache.hadoop.ozone.web.utils.JsonUtils;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After;
import org.junit.AfterClass;
Expand Down Expand Up @@ -258,6 +260,26 @@ public List<Object> handleExecutionException(ExecutionException ex,
exceptionHandler, args);
}

/**
* Test to create volume without specifying --user or -u.
* @throws Exception
*/
@Test
public void testCreateVolumeWithoutUser() throws Exception {
String volumeName = "volume" + RandomStringUtils.randomNumeric(1);
String[] args = new String[] {"volume", "create", url + "/" + volumeName,
"--root"};

execute(shell, args);

String truncatedVolumeName =
volumeName.substring(volumeName.lastIndexOf('/') + 1);
OzoneVolume volumeInfo = client.getVolumeDetails(truncatedVolumeName);
assertEquals(truncatedVolumeName, volumeInfo.getName());
assertEquals(UserGroupInformation.getCurrentUser().getUserName(),
volumeInfo.getOwner());
}

@Test
public void testDeleteVolume() throws Exception {
LOG.info("Running testDeleteVolume");
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.apache.hadoop.ozone.web.ozShell.Shell;
import org.apache.hadoop.ozone.web.utils.JsonUtils;

import org.apache.hadoop.security.UserGroupInformation;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
Expand All @@ -45,8 +46,7 @@ public class CreateVolumeHandler extends Handler {
private String uri;

@Option(names = {"--user", "-u"},
description = "Owner of of the volume", required =
true)
description = "Owner of of the volume")
private String userName;

@Option(names = {"--quota", "-q"},
Expand All @@ -64,6 +64,9 @@ public class CreateVolumeHandler extends Handler {
*/
@Override
public Void call() throws Exception {
if(userName == null) {
userName = UserGroupInformation.getCurrentUser().getUserName();
}

URI ozoneURI = verifyURI(uri);
Path path = Paths.get(ozoneURI.getPath());
Expand Down

0 comments on commit 0bf8a11

Please sign in to comment.