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 2021/09/24 14:42:31 UTC

[GitHub] [cloudstack] SadiJr opened a new pull request #5511: Create UpdateBackupOffering API

SadiJr opened a new pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511


   ### Description
   
   This PR intends to create a new API to allow users to edit name and description of Backup Offerings.
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [x] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [x] Minor
   
   ### Screenshots (if appropriate):
   
   
   ### How Has This Been Tested?
   - I imported a new *Backup Offering*;
   - Using *cloud-monkey*, I changed the name of this *Backup Offering*, and checked, in DB, UI and listBackupOfferings API if the change was performed correctly;
   - Using *cloud-monkey*, I changed the description of this *Backup Offering*, and checked, in DB, UI and listBackupOfferings API if the change was performed correctly;
   Using *cloud-monkey*, I changed the name and description of this *Backup Offering*, and checked, in DB, UI and listBackupOfferings API if the change was performed correctly.
   
   Also, I added some unit tests.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] DaanHoogland commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
DaanHoogland commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-928994516


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] DaanHoogland commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
DaanHoogland commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-929075604


   it is only an API level change and unit tested, I think we can merge without further ado!? cc @nvazquez 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] SadiJr commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
SadiJr commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r716947016



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java
##########
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.backup;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.BackupOfferingResponse;
+import org.apache.cloudstack.backup.BackupManager;
+import org.apache.cloudstack.backup.BackupOffering;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)

Review comment:
       Done, thanks for the suggestion.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-929821433


   @SadiJr can add button in UI to edit backup offering name and description? 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] DaanHoogland commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
DaanHoogland commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-928994516






-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930679500


   @nvazquez a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930702956


   @nvazquez a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] SadiJr commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
SadiJr commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r716947016



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java
##########
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.backup;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.BackupOfferingResponse;
+import org.apache.cloudstack.backup.BackupManager;
+import org.apache.cloudstack.backup.BackupOffering;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)

Review comment:
       Done, thanks for the suggestion.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-928994998






-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez merged pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
nvazquez merged pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511


   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r718143140



##########
File path: server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java
##########
@@ -1050,4 +1054,45 @@ public Long getDelay() {
             return BackupSyncPollingInterval.value() * 1000L;
         }
     }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_VM_BACKUP_EDIT, eventDescription = "updating backup offering")
+    public BackupOffering updateBackupOffering(UpdateBackupOfferingCmd updateBackupOfferingCmd) {
+        Long id = updateBackupOfferingCmd.getId();
+        String name = updateBackupOfferingCmd.getName();
+        String description = updateBackupOfferingCmd.getDescription();
+
+        BackupOfferingVO backupOfferingVO = backupOfferingDao.findById(id);
+        if (backupOfferingVO == null) {
+            throw new InvalidParameterValueException(String.format("Unable to find Backup Offering with id: [%s].", id));
+        }
+
+        LOG.debug(String.format("Trying to update Backup Offering [id: %s, name: %s, description: %s] to [name: %s, description: %s].",
+                backupOfferingVO.getUuid(), backupOfferingVO.getName(), backupOfferingVO.getDescription(), name, description));
+        if (StringUtils.isAllEmpty(name, description)) {
+            throw new InvalidParameterValueException(String.format("Can't update Backup Offering [id: %s] because there is no change in name or description.", backupOfferingVO.getId()));

Review comment:
       @SadiJr can you move this params null/empty check to cmd class (_UpdateBackupOfferingCmd_) before calling this method.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-931331313


   Hi @GutoVeronezi, @borisstoyanov will perform manual tests on this PR 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
rhtyd commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r716582666



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java
##########
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.backup;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.BackupOfferingResponse;
+import org.apache.cloudstack.backup.BackupManager;
+import org.apache.cloudstack.backup.BackupOffering;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class UpdateBackupOfferingCmd extends BaseCmd {
+    private static final Logger LOGGER = Logger.getLogger(UpdateBackupOfferingCmd.class.getName());
+    private static final String RESPONSE_NAME = "updatebackupofferingresponse";
+
+    @Inject
+    private BackupManager backupManager;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BackupOfferingResponse.class, required = true, description = "The ID of the Backup Offering to be updated")
+    private Long id;
+
+    @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the Backup Offering to be updated")
+    private String description;
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the Backup Offering to be updated")
+    private String name;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    public Long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public void execute() {
+        try {
+            BackupOffering result = backupManager.updateBackupOffering(this);
+
+            if (result == null) {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to update backup offering [id: %s, name: %s, description: %s].", id, name, description));
+            }
+            BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(result);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } catch (CloudRuntimeException e) {
+            ApiErrorCode paramError = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
+            LOGGER.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e);
+            throw new ServerApiException(paramError, e.getMessage());
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return RESPONSE_NAME;

Review comment:
       Normally we use:
   ```
       @Override
       public String getCommandName() {
           return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
       }
   ```
   Ref: https://github.com/shapeblue/hackerbook/blob/main/hack/api.md




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
sureshanaparti commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r718143140



##########
File path: server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java
##########
@@ -1050,4 +1054,45 @@ public Long getDelay() {
             return BackupSyncPollingInterval.value() * 1000L;
         }
     }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_VM_BACKUP_EDIT, eventDescription = "updating backup offering")
+    public BackupOffering updateBackupOffering(UpdateBackupOfferingCmd updateBackupOfferingCmd) {
+        Long id = updateBackupOfferingCmd.getId();
+        String name = updateBackupOfferingCmd.getName();
+        String description = updateBackupOfferingCmd.getDescription();
+
+        BackupOfferingVO backupOfferingVO = backupOfferingDao.findById(id);
+        if (backupOfferingVO == null) {
+            throw new InvalidParameterValueException(String.format("Unable to find Backup Offering with id: [%s].", id));
+        }
+
+        LOG.debug(String.format("Trying to update Backup Offering [id: %s, name: %s, description: %s] to [name: %s, description: %s].",
+                backupOfferingVO.getUuid(), backupOfferingVO.getName(), backupOfferingVO.getDescription(), name, description));
+        if (StringUtils.isAllEmpty(name, description)) {
+            throw new InvalidParameterValueException(String.format("Can't update Backup Offering [id: %s] because there is no change in name or description.", backupOfferingVO.getId()));

Review comment:
       @SadiJr can you move this params null/empty check to cmd class (_UpdateBackupOfferingCmd_) before calling this method.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930700372


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] GutoVeronezi commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
GutoVeronezi commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-931296702


   @nvazquez why assign @borisstoyanov to this PR?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] SadiJr commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
SadiJr commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930106115


   @rhtyd I will do this, but in another PR, as they are different contexts. Right now, the API is addressing our needs here :)


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] SadiJr commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
SadiJr commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930106115


   @rhtyd I will do this, but in another PR, as they are different contexts. Right now, the API is addressing our needs here :)


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] rhtyd commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
rhtyd commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-929821433


   @SadiJr can add button in UI to edit backup offering name and description? 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930702873


   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] SadiJr commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
SadiJr commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r718430835



##########
File path: server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java
##########
@@ -1050,4 +1054,45 @@ public Long getDelay() {
             return BackupSyncPollingInterval.value() * 1000L;
         }
     }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_VM_BACKUP_EDIT, eventDescription = "updating backup offering")
+    public BackupOffering updateBackupOffering(UpdateBackupOfferingCmd updateBackupOfferingCmd) {
+        Long id = updateBackupOfferingCmd.getId();
+        String name = updateBackupOfferingCmd.getName();
+        String description = updateBackupOfferingCmd.getDescription();
+
+        BackupOfferingVO backupOfferingVO = backupOfferingDao.findById(id);
+        if (backupOfferingVO == null) {
+            throw new InvalidParameterValueException(String.format("Unable to find Backup Offering with id: [%s].", id));
+        }
+
+        LOG.debug(String.format("Trying to update Backup Offering [id: %s, name: %s, description: %s] to [name: %s, description: %s].",
+                backupOfferingVO.getUuid(), backupOfferingVO.getName(), backupOfferingVO.getDescription(), name, description));
+        if (StringUtils.isAllEmpty(name, description)) {
+            throw new InvalidParameterValueException(String.format("Can't update Backup Offering [id: %s] because there is no change in name or description.", backupOfferingVO.getId()));

Review comment:
       Done. Thanks.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-929029796


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian :heavy_check_mark: suse15. SL-JID 1418


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] SadiJr commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
SadiJr commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r718430835



##########
File path: server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java
##########
@@ -1050,4 +1054,45 @@ public Long getDelay() {
             return BackupSyncPollingInterval.value() * 1000L;
         }
     }
+
+    @Override
+    @ActionEvent(eventType = EventTypes.EVENT_VM_BACKUP_EDIT, eventDescription = "updating backup offering")
+    public BackupOffering updateBackupOffering(UpdateBackupOfferingCmd updateBackupOfferingCmd) {
+        Long id = updateBackupOfferingCmd.getId();
+        String name = updateBackupOfferingCmd.getName();
+        String description = updateBackupOfferingCmd.getDescription();
+
+        BackupOfferingVO backupOfferingVO = backupOfferingDao.findById(id);
+        if (backupOfferingVO == null) {
+            throw new InvalidParameterValueException(String.format("Unable to find Backup Offering with id: [%s].", id));
+        }
+
+        LOG.debug(String.format("Trying to update Backup Offering [id: %s, name: %s, description: %s] to [name: %s, description: %s].",
+                backupOfferingVO.getUuid(), backupOfferingVO.getName(), backupOfferingVO.getDescription(), name, description));
+        if (StringUtils.isAllEmpty(name, description)) {
+            throw new InvalidParameterValueException(String.format("Can't update Backup Offering [id: %s] because there is no change in name or description.", backupOfferingVO.getId()));

Review comment:
       Done. Thanks.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-929288727


   @DaanHoogland lets start a round of tests
   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930679248


   @blueorangutan package


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-930690441


   Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: debian :heavy_check_mark: suse15. SL-JID 1450


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] SadiJr commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
SadiJr commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r716671556



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java
##########
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.backup;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.BackupOfferingResponse;
+import org.apache.cloudstack.backup.BackupManager;
+import org.apache.cloudstack.backup.BackupOffering;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class UpdateBackupOfferingCmd extends BaseCmd {
+    private static final Logger LOGGER = Logger.getLogger(UpdateBackupOfferingCmd.class.getName());
+    private static final String RESPONSE_NAME = "updatebackupofferingresponse";
+
+    @Inject
+    private BackupManager backupManager;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = BackupOfferingResponse.class, required = true, description = "The ID of the Backup Offering to be updated")
+    private Long id;
+
+    @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the Backup Offering to be updated")
+    private String description;
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "The name of the Backup Offering to be updated")
+    private String name;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    public Long getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+    @Override
+    public void execute() {
+        try {
+            BackupOffering result = backupManager.updateBackupOffering(this);
+
+            if (result == null) {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to update backup offering [id: %s, name: %s, description: %s].", id, name, description));
+            }
+            BackupOfferingResponse response = _responseGenerator.createBackupOfferingResponse(result);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } catch (CloudRuntimeException e) {
+            ApiErrorCode paramError = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
+            LOGGER.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e);
+            throw new ServerApiException(paramError, e.getMessage());
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return RESPONSE_NAME;

Review comment:
       Done, thanks.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] nvazquez commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
nvazquez commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-929288727


   @DaanHoogland lets start a round of tests
   @blueorangutan test


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-931324438


   <b>Trillian test result (tid-2244)</b>
   Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
   Total time taken: 37672 seconds
   Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr5511-t2244-kvm-centos7.zip
   Smoke tests completed. 90 look OK, 0 have errors
   Only failed tests results shown below:
   
   
   Test | Result | Time (s) | Test File
   --- | --- | --- | ---
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] RodrigoDLopez commented on a change in pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
RodrigoDLopez commented on a change in pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#discussion_r716676396



##########
File path: api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java
##########
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.backup;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.BackupOfferingResponse;
+import org.apache.cloudstack.backup.BackupManager;
+import org.apache.cloudstack.backup.BackupOffering;
+import org.apache.log4j.Logger;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)

Review comment:
       hey @SadiJr thanks for the PR
   what do you think in insert the since tag here?
   ```
   @APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false since = "4.16.0")
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [cloudstack] blueorangutan commented on pull request #5511: Create UpdateBackupOffering API

Posted by GitBox <gi...@apache.org>.
blueorangutan commented on pull request #5511:
URL: https://github.com/apache/cloudstack/pull/5511#issuecomment-928994998


   @DaanHoogland a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org