You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2020/02/06 16:35:58 UTC

[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #3739: Add new command to update security group name

DaanHoogland commented on a change in pull request #3739: Add new command to update security group name
URL: https://github.com/apache/cloudstack/pull/3739#discussion_r375943057
 
 

 ##########
 File path: server/src/main/java/com/cloud/network/security/SecurityGroupManagerImpl.java
 ##########
 @@ -1117,6 +1122,60 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
         s_logger.debug("Security group mappings are removed successfully for vm id=" + userVmId);
     }
 
+    @DB
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_SECURITY_GROUP_UPDATE, eventDescription = "updating security group")
+    public SecurityGroup updateSecurityGroup(UpdateSecurityGroupCmd cmd) {
+        final Long groupId = cmd.getId();
+        final String newName = cmd.getName();
+        Account caller = CallContext.current().getCallingAccount();
+
+        SecurityGroupVO group = _securityGroupDao.findById(groupId);
+        if (group == null) {
+            throw new InvalidParameterValueException("Unable to find security group: " + groupId + "; failed to update security group.");
+        }
+
+        if (newName == null) {
+            s_logger.debug("security group name is not changed. id=" + groupId);
+            return group;
+        }
+
+        if (StringUtils.isBlank(newName)) {
+            throw new InvalidParameterValueException("Security group name cannot be empty");
+        }
+
+        // check permissions
+        _accountMgr.checkAccess(caller, null, true, group);
+
+        return Transaction.execute(new TransactionCallback<SecurityGroupVO>() {
+            @Override
+            public SecurityGroupVO doInTransaction(TransactionStatus status) {
+                SecurityGroupVO group = _securityGroupDao.lockRow(groupId, true);
+                if (group == null) {
+                    throw new InvalidParameterValueException("Unable to find security group by id " + groupId);
 
 Review comment:
   the message here could better be "unable to acquire lock for security group with id " + groupId

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services