Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D988B189C7 for ; Tue, 19 Jan 2016 16:48:48 +0000 (UTC) Received: (qmail 10613 invoked by uid 500); 19 Jan 2016 16:48:48 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 10573 invoked by uid 500); 19 Jan 2016 16:48:48 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 10559 invoked by uid 99); 19 Jan 2016 16:48:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Jan 2016 16:48:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9342BDFCB5; Tue, 19 Jan 2016 16:48:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: remi@apache.org To: commits@cloudstack.apache.org Date: Tue, 19 Jan 2016 16:48:48 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/5] git commit: updated refs/heads/master to f98f983 Repository: cloudstack Updated Branches: refs/heads/master fac259f0f -> f98f98358 CLOUDSTACK-9132: API createVolume takes empty string for name parameter Added conditions to check if the name is empty or blank. If it is empty or blank, then it generates a random name. Made the name field as optional in UI as well as in API. Added required unit tests. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/55f8b32a Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/55f8b32a Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/55f8b32a Branch: refs/heads/master Commit: 55f8b32aa00baf0609f54891230269ed97bedb5a Parents: 3ee53d3 Author: Nitin Kumar Maharana Authored: Tue Dec 29 16:45:41 2015 +0530 Committer: Nitin Kumar Maharana Committed: Fri Jan 8 13:41:41 2016 +0530 ---------------------------------------------------------------------- .../command/user/volume/CreateVolumeCmd.java | 2 +- .../com/cloud/storage/VolumeApiServiceImpl.java | 24 ++++++++++++++--- .../cloud/storage/VolumeApiServiceImplTest.java | 28 ++++++++++++++++++++ ui/scripts/docs.js | 2 +- ui/scripts/storage.js | 5 +--- 5 files changed, 51 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f8b32a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java index 1e3c01c..54c376e 100644 --- a/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java @@ -79,7 +79,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd { description = "the ID of the disk offering. Either diskOfferingId or snapshotId must be passed in.") private Long diskOfferingId; - @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the disk volume") + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the disk volume") private String volumeName; @Parameter(name = ApiConstants.SIZE, type = CommandType.LONG, description = "Arbitrary volume size") http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f8b32a/server/src/com/cloud/storage/VolumeApiServiceImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index afa5cc4..5a53f9c 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -476,6 +476,25 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic }); } + /** + * Retrieves the volume name from CreateVolumeCmd object. + * + * If the retrieved volume name is null, empty or blank, then A random name + * will be generated using getRandomVolumeName method. + * + * @param cmd + * @return Either the retrieved name or a random name. + */ + public String getVolumeNameFromCommand(CreateVolumeCmd cmd) { + String userSpecifiedName = cmd.getVolumeName(); + + if (org.apache.commons.lang.StringUtils.isBlank(userSpecifiedName)) { + userSpecifiedName = getRandomVolumeName(); + } + + return userSpecifiedName; + } + /* * Just allocate a volume in the database, don't send the createvolume cmd * to hypervisor. The volume will be finally created only when it's attached @@ -671,10 +690,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic throw new InvalidParameterValueException("Zone is not configured to use local storage but volume's disk offering " + diskOffering.getName() + " uses it"); } - String userSpecifiedName = cmd.getVolumeName(); - if (userSpecifiedName == null) { - userSpecifiedName = getRandomVolumeName(); - } + String userSpecifiedName = getVolumeNameFromCommand(cmd); VolumeVO volume = commitVolume(cmd, caller, owner, displayVolume, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentVolume, userSpecifiedName, _uuidMgr.generateUuid(Volume.class, cmd.getCustomId())); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f8b32a/server/test/com/cloud/storage/VolumeApiServiceImplTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/storage/VolumeApiServiceImplTest.java b/server/test/com/cloud/storage/VolumeApiServiceImplTest.java index 0e46142..4b502a4 100644 --- a/server/test/com/cloud/storage/VolumeApiServiceImplTest.java +++ b/server/test/com/cloud/storage/VolumeApiServiceImplTest.java @@ -29,6 +29,8 @@ import java.util.UUID; import javax.inject.Inject; import com.cloud.user.User; +import junit.framework.Assert; +import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -97,6 +99,8 @@ public class VolumeApiServiceImplTest { SnapshotInfo snapshotInfoMock; @Mock VolumeService volService; + @Mock + CreateVolumeCmd createVol; DetachVolumeCmd detachCmd = new DetachVolumeCmd(); Class _detachCmdClass = detachCmd.getClass(); @@ -355,6 +359,30 @@ public class VolumeApiServiceImplTest { _svc.takeSnapshot(5L, Snapshot.MANUAL_POLICY_ID, 3L, null, false); } + @Test + public void testNullGetVolumeNameFromCmd() { + when(createVol.getVolumeName()).thenReturn(null); + Assert.assertNotNull(_svc.getVolumeNameFromCommand(createVol)); + } + + @Test + public void testEmptyGetVolumeNameFromCmd() { + when(createVol.getVolumeName()).thenReturn(""); + Assert.assertNotNull(_svc.getVolumeNameFromCommand(createVol)); + } + + @Test + public void testBlankGetVolumeNameFromCmd() { + when(createVol.getVolumeName()).thenReturn(" "); + Assert.assertNotNull(_svc.getVolumeNameFromCommand(createVol)); + } + + @Test + public void testNonEmptyGetVolumeNameFromCmd() { + when(createVol.getVolumeName()).thenReturn("abc"); + Assert.assertSame(_svc.getVolumeNameFromCommand(createVol), "abc"); + } + @After public void tearDown() { CallContext.unregister(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f8b32a/ui/scripts/docs.js ---------------------------------------------------------------------- diff --git a/ui/scripts/docs.js b/ui/scripts/docs.js index ed6ab0c..30e123b 100755 --- a/ui/scripts/docs.js +++ b/ui/scripts/docs.js @@ -1008,7 +1008,7 @@ cloudStack.docs = { }, // Add volume helpVolumeName: { - desc: 'Give the volume a unique name so you can find it later.', + desc: 'Give a unique volume name. If it is not provided, a name will be generated randomly.', externalLink: '' }, helpVolumeAvailabilityZone: { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f8b32a/ui/scripts/storage.js ---------------------------------------------------------------------- diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js index 2f93917..39dfccf 100644 --- a/ui/scripts/storage.js +++ b/ui/scripts/storage.js @@ -80,10 +80,7 @@ fields: { name: { docID: 'helpVolumeName', - label: 'label.name', - validation: { - required: true - } + label: 'label.name' }, availabilityZone: { label: 'label.availability.zone',