From 7c2fffe67aabfa7faa4544e3e25f9bdfd5da27b5 Mon Sep 17 00:00:00 2001 From: abhishek Date: Thu, 13 Jan 2011 17:06:28 -0800 Subject: [PATCH] bug 7989: fixing this regression status 7989: resolved fixed --- api/src/com/cloud/api/commands/DeployVMCmd.java | 3 +++ api/src/com/cloud/vm/UserVmService.java | 5 ++++- server/src/com/cloud/api/ApiDispatcher.java | 2 +- server/src/com/cloud/vm/UserVmManagerImpl.java | 9 ++++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/src/com/cloud/api/commands/DeployVMCmd.java b/api/src/com/cloud/api/commands/DeployVMCmd.java index 8e0bfab0088..c0a7fc2abd3 100644 --- a/api/src/com/cloud/api/commands/DeployVMCmd.java +++ b/api/src/com/cloud/api/commands/DeployVMCmd.java @@ -20,6 +20,8 @@ package com.cloud.api.commands; import java.util.List; +import javax.naming.InsufficientResourcesException; + import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; @@ -34,6 +36,7 @@ import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.exception.StorageUnavailableException; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.user.Account; import com.cloud.user.UserContext; diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java index 3b40a26da45..b102c7cbcb0 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -19,6 +19,8 @@ package com.cloud.vm; import java.util.List; +import javax.naming.InsufficientResourcesException; + import com.cloud.api.ServerApiException; import com.cloud.api.commands.AttachVolumeCmd; import com.cloud.api.commands.CreateTemplateCmd; @@ -121,10 +123,11 @@ public interface UserVmService { * @throws InsufficientCapacityException if there is insufficient capacity to deploy the VM. * @throws ConcurrentOperationException if there are multiple users working on the same VM or in the same environment. * @throws ResourceUnavailableException if the resources required to deploy the VM is not currently available. + * @throws InsufficientResourcesException * @throws PermissionDeniedException if the caller doesn't have any access rights to the VM. * @throws InvalidParameterValueException if the parameters are incorrect. */ - UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException; + UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException; /** * Starts the virtual machine created from createVirtualMachine. diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index b6e56be5efb..ed56a8a353a 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -94,7 +94,7 @@ public class ApiDispatcher { } else if (t instanceof ServerApiException) { s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription()); if (UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errorMsg); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errorMsg.length() > 0 ? errorMsg : ((ServerApiException) t).getDescription()); } else { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index e5b57b175a3..ac1dd8170aa 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit; import javax.ejb.Local; import javax.naming.ConfigurationException; +import javax.naming.InsufficientResourcesException; import org.apache.log4j.Logger; @@ -2114,7 +2115,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } @Override @DB - public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException { + public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException { Account caller = UserContext.current().getCaller(); String accountName = cmd.getAccountName(); @@ -2143,6 +2144,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager _accountMgr.checkAccess(caller, domain); _accountMgr.checkAccess(owner, domain); } + //check if we have available pools for vm deployment + List availablePools = _storagePoolDao.listPoolsByStatus(com.cloud.host.Status.Up); + + if( availablePools == null || availablePools.size() < 1) { + throw new StorageUnavailableException("There are no available pools in the UP state for vm deployment",-1); + } ServiceOfferingVO offering = _serviceOfferingDao.findById(cmd.getServiceOfferingId()); if (offering == null || offering.getRemoved() != null) {