You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cloudstack.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/12/01 16:25:58 UTC

[jira] [Commented] (CLOUDSTACK-9607) Preventing template deletion when template is in use.

    [ https://issues.apache.org/jira/browse/CLOUDSTACK-9607?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15712394#comment-15712394 ] 

ASF GitHub Bot commented on CLOUDSTACK-9607:
--------------------------------------------

Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1773#discussion_r90480678
  
    --- Diff: server/src/com/cloud/template/TemplateManagerImpl.java ---
    @@ -1176,6 +1176,23 @@ public boolean deleteTemplate(DeleteTemplateCmd cmd) {
                 throw new InvalidParameterValueException("unable to find template with id " + templateId);
             }
     
    +        List<VMInstanceVO> vmInstanceVOList;
    +        if(cmd.getZoneId() != null) {
    +            vmInstanceVOList = _vmInstanceDao.listNonExpungedByZoneAndTemplate(cmd.getZoneId(), templateId);
    +        }
    +        else {
    +            vmInstanceVOList = _vmInstanceDao.listNonExpungedByTemplate(templateId);
    +        }
    +        if(!cmd.isForced() && CollectionUtils.isNotEmpty(vmInstanceVOList)) {
    +            StringBuilder s  = new StringBuilder("Unable to delete template with id: " + templateId + " because some VM instances are using it. ");
    +            for (VMInstanceVO elm : vmInstanceVOList) {
    +                s.append(elm.getInstanceName() + ", ");
    +            }
    +
    +            s_logger.warn(s.substring(0,s.length()-2));
    +            throw new InvalidParameterValueException(s.substring(0,s.length()-2));
    --- End diff --
    
    Lines 1187-1193 should replaced with the following to be DRY and improve clarity:
    ```java
    final String message = String.format("Unable to delete template with id: %1$s because VM instances: [%2$s] are using it.",  templateId, Joiner.on(",").join(vmInstanceVOList));
    s_logger.warn(message);
    throw new InvalidParameterValueException(message);
    ```


> Preventing template deletion when template is in use.
> -----------------------------------------------------
>
>                 Key: CLOUDSTACK-9607
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-9607
>             Project: CloudStack
>          Issue Type: Bug
>      Security Level: Public(Anyone can view this level - this is the default.) 
>            Reporter: Priyank Parihar
>            Assignee: Priyank Parihar
>
> Consider this scenario:
> 1. User launches a VM from Template and keep it running
> 2. Admin logins and deleted that template [CloudPlatform does not check existing / running VM etc. while the deletion is done]
> 3. User resets the VM
> 4. CloudPlatform fails to star the VM as it cannot find the corresponding template.
> It throws error as 
> java.lang.RuntimeException: Job failed due to exception Resource [Host:11] is unreachable: Host 11: Unable to start instance due to can't find ready template: 209 for data center 1
>         at com.cloud.vm.VmWorkJobDispatcher.runJob(VmWorkJobDispatcher.java:113)
>         at org.apache.cloudstack.framework.jobs.impl.AsyncJobManagerImpl$5.runInContext(AsyncJobManagerImpl.java:495)
> Client is requesting better handing of this scenario. We need to check existing / running VM's when the template is deleted and warn admin about the possible issue that may occur.
> REPRO STEPS
> ==================
> 1. Launches a VM from Template and keep it running
> 2. Now delete that template 
> 3. Reset the VM
> 4. CloudPlatform fails to star the VM as it cannot find the corresponding template.
> EXPECTED BEHAVIOR
> ==================
> Cloud platform should throw some warning message while the template is deleted if that template is being used by existing / running VM's
> ACTUAL BEHAVIOR
> ==================
> Cloud platform does not throw as waring etc.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)