mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	bug 8493: Check for resource limit for copy templates/ISO between zones.
This commit is contained in:
		
							parent
							
								
									3bd3dacf9e
								
							
						
					
					
						commit
						67a92e3f1d
					
				
							
								
								
									
										6
									
								
								api/src/com/cloud/api/commands/CopyIsoCmd.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										6
									
								
								api/src/com/cloud/api/commands/CopyIsoCmd.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -29,6 +29,7 @@ import com.cloud.api.ServerApiException;
 | 
			
		||||
import com.cloud.api.response.TemplateResponse;
 | 
			
		||||
import com.cloud.async.AsyncJob;
 | 
			
		||||
import com.cloud.event.EventTypes;
 | 
			
		||||
import com.cloud.exception.ResourceAllocationException;
 | 
			
		||||
import com.cloud.exception.StorageUnavailableException;
 | 
			
		||||
import com.cloud.template.VirtualMachineTemplate;
 | 
			
		||||
import com.cloud.user.Account;
 | 
			
		||||
@ -119,6 +120,9 @@ public class CopyIsoCmd extends BaseAsyncCmd {
 | 
			
		||||
        } catch (StorageUnavailableException ex) {
 | 
			
		||||
            s_logger.warn("Exception: ", ex);
 | 
			
		||||
            throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
        } catch (ResourceAllocationException ex) {
 | 
			
		||||
        	s_logger.warn("Exception: ", ex);
 | 
			
		||||
        	throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
 | 
			
		||||
		}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								api/src/com/cloud/api/commands/CopyTemplateCmd.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										6
									
								
								api/src/com/cloud/api/commands/CopyTemplateCmd.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -29,6 +29,7 @@ import com.cloud.api.ServerApiException;
 | 
			
		||||
import com.cloud.api.response.TemplateResponse;
 | 
			
		||||
import com.cloud.async.AsyncJob;
 | 
			
		||||
import com.cloud.event.EventTypes;
 | 
			
		||||
import com.cloud.exception.ResourceAllocationException;
 | 
			
		||||
import com.cloud.exception.StorageUnavailableException;
 | 
			
		||||
import com.cloud.template.VirtualMachineTemplate;
 | 
			
		||||
import com.cloud.user.Account;
 | 
			
		||||
@ -121,7 +122,10 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
 | 
			
		||||
        } catch (StorageUnavailableException ex) {
 | 
			
		||||
            s_logger.warn("Exception: ", ex);
 | 
			
		||||
            throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
        } catch (ResourceAllocationException ex) {
 | 
			
		||||
        	s_logger.warn("Exception: ", ex);
 | 
			
		||||
        	throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
 | 
			
		||||
		}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								api/src/com/cloud/template/TemplateService.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										4
									
								
								api/src/com/cloud/template/TemplateService.java
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -39,8 +39,8 @@ public interface TemplateService {
 | 
			
		||||
    
 | 
			
		||||
    VirtualMachineTemplate registerTemplate(RegisterTemplateCmd cmd) throws URISyntaxException, ResourceAllocationException;
 | 
			
		||||
    VirtualMachineTemplate registerIso(RegisterIsoCmd cmd) throws IllegalArgumentException, ResourceAllocationException;   
 | 
			
		||||
    VirtualMachineTemplate copyIso(CopyIsoCmd cmd) throws StorageUnavailableException;
 | 
			
		||||
    VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException;
 | 
			
		||||
    VirtualMachineTemplate copyIso(CopyIsoCmd cmd) throws StorageUnavailableException, ResourceAllocationException;
 | 
			
		||||
    VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException;
 | 
			
		||||
    boolean detachIso(DetachIsoCmd cmd);
 | 
			
		||||
    boolean attachIso(AttachIsoCmd cmd);
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,7 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
import com.cloud.exception.InternalErrorException;
 | 
			
		||||
import com.cloud.exception.InvalidParameterValueException;
 | 
			
		||||
import com.cloud.exception.ResourceAllocationException;
 | 
			
		||||
import com.cloud.exception.StorageUnavailableException;
 | 
			
		||||
import com.cloud.storage.Storage.ImageFormat;
 | 
			
		||||
import com.cloud.storage.Storage.TemplateType;
 | 
			
		||||
@ -104,9 +105,10 @@ public interface TemplateManager {
 | 
			
		||||
        	throw new IllegalArgumentException("The template hasnt been downloaded ");
 | 
			
		||||
        }
 | 
			
		||||
     * @throws StorageUnavailableException 
 | 
			
		||||
     * @throws ResourceAllocationException 
 | 
			
		||||
     * @throws InvalidParameterValueException 
 | 
			
		||||
     */
 | 
			
		||||
    boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId) throws StorageUnavailableException;
 | 
			
		||||
    boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId) throws StorageUnavailableException, ResourceAllocationException;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * Deletes a template from secondary storage servers
 | 
			
		||||
 | 
			
		||||
@ -700,7 +700,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    @DB
 | 
			
		||||
    public boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId) throws StorageUnavailableException {
 | 
			
		||||
    public boolean copy(long userId, long templateId, long sourceZoneId, long destZoneId) throws StorageUnavailableException, ResourceAllocationException {
 | 
			
		||||
    	HostVO srcSecHost = _storageMgr.getSecondaryStorageHost(sourceZoneId);
 | 
			
		||||
    	HostVO dstSecHost = _storageMgr.getSecondaryStorageHost(destZoneId);
 | 
			
		||||
    	DataCenterVO destZone = _dcDao.findById(destZoneId);
 | 
			
		||||
@ -731,10 +731,16 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
 | 
			
		||||
        srcTmpltHost = _tmpltHostDao.findByHostTemplate(srcSecHost.getId(), templateId);
 | 
			
		||||
        if (srcTmpltHost == null || srcTmpltHost.getDestroyed() || srcTmpltHost.getDownloadState() != VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
 | 
			
		||||
	      	throw new InvalidParameterValueException("Please specify a template that is installed on secondary storage host: " + srcSecHost.getName());
 | 
			
		||||
	      }
 | 
			
		||||
	    }
 | 
			
		||||
        
 | 
			
		||||
        // Event details
 | 
			
		||||
        Account account = _accountDao.findById(vmTemplate.getAccountId());
 | 
			
		||||
        AccountVO account = _accountDao.findById(vmTemplate.getAccountId());
 | 
			
		||||
        if (_accountMgr.resourceLimitExceeded(account, ResourceType.template)) {
 | 
			
		||||
        	ResourceAllocationException rae = new ResourceAllocationException("Maximum number of templates and ISOs for account: " + account.getAccountName() + " has been exceeded.");
 | 
			
		||||
        	rae.setResourceType("template");
 | 
			
		||||
        	throw rae;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Event details        
 | 
			
		||||
        String copyEventType;
 | 
			
		||||
        String createEventType;
 | 
			
		||||
        if (vmTemplate.getFormat().equals(ImageFormat.ISO)){
 | 
			
		||||
@ -788,7 +794,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
 | 
			
		||||
    }
 | 
			
		||||
      
 | 
			
		||||
    @Override
 | 
			
		||||
    public VirtualMachineTemplate copyIso(CopyIsoCmd cmd) throws StorageUnavailableException {
 | 
			
		||||
    public VirtualMachineTemplate copyIso(CopyIsoCmd cmd) throws StorageUnavailableException, ResourceAllocationException {
 | 
			
		||||
    	Long isoId = cmd.getId();
 | 
			
		||||
    	Long userId = UserContext.current().getCallerUserId();
 | 
			
		||||
    	Long sourceZoneId = cmd.getSourceZoneId();
 | 
			
		||||
@ -822,7 +828,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException {
 | 
			
		||||
    public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException {
 | 
			
		||||
    	Long templateId = cmd.getId();
 | 
			
		||||
    	Long userId = UserContext.current().getCallerUserId();
 | 
			
		||||
    	Long sourceZoneId = cmd.getSourceZoneId();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user