diff --git a/api/src/com/cloud/api/BaseCmd.java b/api/src/com/cloud/api/BaseCmd.java index a2481f50ce2..762a1ef42f1 100755 --- a/api/src/com/cloud/api/BaseCmd.java +++ b/api/src/com/cloud/api/BaseCmd.java @@ -60,6 +60,7 @@ import com.cloud.user.DomainService; import com.cloud.user.ResourceLimitService; import com.cloud.utils.Pair; import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.AnnotationHelper; import com.cloud.vm.BareMetalVmService; import com.cloud.vm.UserVmService; @@ -485,7 +486,7 @@ public abstract class BaseCmd { if (!enabledOnly || account.getState() == Account.State.enabled) { return account.getId(); } else { - throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active"); + throw new PermissionDeniedException("Can't add resources to the account id=" + account.getId() + " in state=" + account.getState() + " as it's no longer active"); } } else { throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain id=" + domainId); @@ -498,10 +499,26 @@ public abstract class BaseCmd { if (!enabledOnly || project.getState() == Project.State.Active) { return project.getProjectAccountId(); } else { - throw new PermissionDeniedException("Can't add resources to the project id=" + projectId + " in state=" + project.getState() + " as it's no longer active"); + PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } else { - throw new InvalidParameterValueException("Unable to find project by id " + projectId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified projectId"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } return null; diff --git a/api/src/com/cloud/api/commands/AddAccountToProjectCmd.java b/api/src/com/cloud/api/commands/AddAccountToProjectCmd.java index ee89b7d1038..04ecba0de7b 100644 --- a/api/src/com/cloud/api/commands/AddAccountToProjectCmd.java +++ b/api/src/com/cloud/api/commands/AddAccountToProjectCmd.java @@ -32,6 +32,8 @@ import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; import com.cloud.projects.Project; import com.cloud.user.UserContext; +import com.cloud.utils.AnnotationHelper; + @Implementation(description="Adds acoount to a project", responseObject=SuccessResponse.class, since="3.0.0") public class AddAccountToProjectCmd extends BaseAsyncCmd { @@ -101,7 +103,16 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd { Project project= _projectService.getProject(projectId); //verify input parameters if (project == null) { - throw new InvalidParameterValueException("Unable to find project by id " + projectId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id"); + // getProject() returns an object of type ProjectVO. + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } return _projectService.getProjectOwner(projectId).getId(); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 37233f19710..ff10186d478 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2037,9 +2037,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag // Verify input parameters IPAddressVO ipVO = _ipAddressDao.findById(ipAddressId); if (ipVO == null) { - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find ip address by id"); - ex.addProxyObject("user_ip_address", ipAddressId, "ipAddressId"); - throw ex; + throw new InvalidParameterValueException("Unable to find ip address by id"); } if (ipVO.getAllocatedTime() == null) { @@ -2124,9 +2122,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public String getNextAvailableMacAddressInNetwork(long networkId) throws InsufficientAddressCapacityException { String mac = _networksDao.getNextAvailableMacAddress(networkId); if (mac == null) { - InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId); - ex.addProxyObject("networks", networkId, "networkId"); - throw ex; + throw new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId); } return mac; } @@ -2255,7 +2251,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId); if (networkOffering == null || networkOffering.isSystemOnly()) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering by specified id"); - ex.addProxyObject("network_offerings", networkOfferingId, "networkOfferingId"); + if (networkOffering != null) { + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(networkOffering); + if (tablename != null) { + ex.addProxyObject(tablename, networkOfferingId, "networkOfferingId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; + } throw ex; } // validate physical network and zone @@ -2264,9 +2269,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (physicalNetworkId != null) { pNtwk = _physicalNetworkDao.findById(physicalNetworkId); if (pNtwk == null) { - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a physical network having the given id"); - ex.addProxyObject("physical_network", physicalNetworkId, "physicalNetworkId"); - throw ex; + throw new InvalidParameterValueException("Unable to find a physical network having the specified physical network id"); } } @@ -2275,11 +2278,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } DataCenter zone = _dcDao.findById(zoneId); + if (zone == null) { + throw new InvalidParameterValueException("Specified zone id was not found"); + } + if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) { // See DataCenterVO.java PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled"); - ex.addProxyObject("data_center", zone.getId(), "zoneId"); - throw ex; + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, zoneId, "zoneId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } // Only domain and account ACL types are supported in Acton. @@ -2333,11 +2346,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } DomainVO domain = _domainDao.findById(domainId); - if (domain == null) { - // see DomainVO.java - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain by specified if"); - ex.addProxyObject("domain", domainId, "domainId"); - throw ex; + if (domain == null) { + throw new InvalidParameterValueException("Unable to find domain by specified id"); } _accountMgr.checkAccess(caller, domain); } @@ -2488,8 +2498,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (ntwkOff.getState() != NetworkOffering.State.Enabled) { // see NetworkOfferingVO InvalidParameterValueException ex = new InvalidParameterValueException("Can't use specified network offering id as its stat is not " + NetworkOffering.State.Enabled); - ex.addProxyObject("network_offerings", networkOfferingId, "networkOfferingId"); - throw ex; + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(networkOfferingId); + if (tablename != null) { + ex.addProxyObject(tablename, networkOfferingId, "networkOfferingId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } // Validate physical network @@ -2716,9 +2732,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag DomainVO domain = _domainDao.findById(domainId); if (domain == null) { // see DomainVO.java - InvalidParameterValueException ex = new InvalidParameterValueException("Specified domain id doesn't exist in the system"); - ex.addProxyObject("domain", domainId, "domainId"); - throw ex; + throw new InvalidParameterValueException("Specified domain id doesn't exist in the system"); } _accountMgr.checkAccess(caller, domain); @@ -2726,9 +2740,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Account owner = _accountMgr.getActiveAccountByName(accountName, domainId); if (owner == null) { // see DomainVO.java - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain"); - ex.addProxyObject("domain", domainId, "domainId"); - throw ex; + throw new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain"); } _accountMgr.checkAccess(caller, null, true, owner); @@ -2753,17 +2765,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } else { permittedAccounts.clear(); Project project = _projectMgr.getProject(projectId); - if (project == null) { - // see ProjectVO.java - InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project by specified id"); - ex.addProxyObject("projects", projectId, "projectId"); - throw ex; + if (project == null) { + throw new InvalidParameterValueException("Unable to find project by specified id"); } if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) { - // see ProjectVO.java + // getProject() returns type ProjectVO. InvalidParameterValueException ex = new InvalidParameterValueException("Account " + caller + " cannot access specified project id"); - ex.addProxyObject("projects", projectId, "projectId"); - throw ex; + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } permittedAccounts.add(project.getProjectAccountId()); } @@ -3571,7 +3586,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!areServicesSupportedInNetwork(networkId, service)) { // TBD: networkId to uuid. No VO object being passed. So we will need to call - // addProxyObject with hardcoded tablename. + // addProxyObject with hardcoded tablename. Or we should probably look up the correct dao proxy object. throw new UnsupportedServiceException("Service " + service.getName() + " is not supported in the network id=" + networkId); } diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index ffbb35d329c..693bb228a71 100755 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -104,6 +104,7 @@ import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; +import com.cloud.utils.AnnotationHelper; import com.cloud.vm.Nic; import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachine.State; @@ -414,7 +415,15 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa UserVm vm = _vmDao.findById(instanceId); if (vm == null || vm.getState() == State.Destroyed || vm.getState() == State.Expunging) { - throw new InvalidParameterValueException("Invalid instance id: " + instanceId); + InvalidParameterValueException ex = new InvalidParameterValueException("Invalid instance id specified"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, instanceId, "instanceId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } _rulesMgr.checkRuleAndUserVm(loadBalancer, vm, caller); @@ -434,7 +443,15 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa } if (nicInSameNetwork == null) { - throw new InvalidParameterValueException("VM " + instanceId + " cannot be added because it doesn't belong in the same network."); + InvalidParameterValueException ex = new InvalidParameterValueException("VM " + instanceId + " cannot be added because it doesn't belong in the same network."); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, instanceId, "instanceId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } if (s_logger.isDebugEnabled()) { @@ -478,7 +495,16 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa } if(!success){ - throw new CloudRuntimeException("Failed to add load balancer rule id " + loadBalancerId + " for vms " + instanceIds); + CloudRuntimeException ex = new CloudRuntimeException("Failed to add specified loadbalancerruleid for vms " + instanceIds); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(loadBalancer); + if (tablename != null) { + ex.addProxyObject(tablename, loadBalancerId, "loadBalancerId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + // TBD: Also pack in the instanceIds in the exception using the right VO object or table name. + throw ex; } return success; @@ -515,7 +541,15 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa if (!applyLoadBalancerConfig(loadBalancerId)) { s_logger.warn("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds); - throw new CloudRuntimeException("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds); + CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + instanceIds); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(loadBalancer); + if (tablename != null) { + ex.addProxyObject(tablename, loadBalancerId, "loadBalancerId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } success = true; } catch (ResourceUnavailableException e) { @@ -535,7 +569,15 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e); } if(!success){ - throw new CloudRuntimeException("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds); + CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + instanceIds); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(loadBalancer); + if (tablename != null) { + ex.addProxyObject(tablename, loadBalancerId, "loadBalancerId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } return success; } @@ -758,16 +800,40 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa Long networkId = ipAddr.getSourceNetworkId(); // make sure ip address exists if (ipAddr == null || !ipAddr.readyToUse()) { - throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id" + sourceIpId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id specified"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(ipAddr); + if (tablename != null) { + ex.addProxyObject(tablename, sourceIpId, "sourceIpId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } else if (ipAddr.isOneToOneNat()) { - throw new InvalidParameterValueException("Unable to create load balancer rule; ip id=" + sourceIpId + " has static nat enabled"); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule; specified sourceip id has static nat enabled"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(ipAddr); + if (tablename != null) { + ex.addProxyObject(tablename, sourceIpId, "sourceIpId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } _firewallMgr.validateFirewallRule(caller.getCaller(), ipAddr, srcPortStart, srcPortEnd, lb.getProtocol(), Purpose.LoadBalancing, FirewallRuleType.User); networkId = ipAddr.getAssociatedWithNetworkId(); if (networkId == null) { - throw new InvalidParameterValueException("Unable to create load balancer rule ; ip id=" + sourceIpId + " is not associated with any network"); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to create load balancer rule ; specified sourceip id is not associated with any network"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(ipAddr); + if (tablename != null) { + ex.addProxyObject(tablename, sourceIpId, "sourceIpId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } NetworkVO network = _networkDao.findById(networkId); @@ -776,7 +842,15 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesMa // verify that lb service is supported by the network if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.Lb)) { - throw new InvalidParameterValueException("LB service is not supported in network id= " + networkId); + InvalidParameterValueException ex = new InvalidParameterValueException("LB service is not supported in specified network id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(network); + if (tablename != null) { + ex.addProxyObject(tablename, networkId, "networkId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java index 7a696d1b897..4a6821e9f6e 100755 --- a/server/src/com/cloud/network/rules/RulesManagerImpl.java +++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java @@ -70,6 +70,7 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.Ip; +import com.cloud.utils.AnnotationHelper; import com.cloud.vm.Nic; import com.cloud.vm.UserVmVO; import com.cloud.vm.VirtualMachine; @@ -1029,12 +1030,28 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { checkIpAndUserVm(ipAddress, null, caller); if (ipAddress.getSystem()) { - throw new InvalidParameterValueException("Can't disable static nat for system IP address " + ipAddress); + InvalidParameterValueException ex = new InvalidParameterValueException("Can't disable static nat for system IP address with specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(ipAddress); + if (tablename != null) { + ex.addProxyObject(tablename, ipId, "ipId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } Long vmId = ipAddress.getAssociatedWithVmId(); if (vmId == null) { - throw new InvalidParameterValueException("IP address " + ipAddress + " is not associated with any vm Id"); + InvalidParameterValueException ex = new InvalidParameterValueException("Specified IP address id is not associated with any vm Id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(ipAddress); + if (tablename != null) { + ex.addProxyObject(tablename, ipId, "ipId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } // if network has elastic IP functionality supported, we first have to disable static nat on old ip in order to @@ -1059,7 +1076,15 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { checkIpAndUserVm(ipAddress, null, caller); if (!ipAddress.isOneToOneNat()) { - throw new InvalidParameterValueException("One to one nat is not enabled for the ip id=" + ipId); + InvalidParameterValueException ex = new InvalidParameterValueException("One to one nat is not enabled for the specified ip id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(ipAddress); + if (tablename != null) { + ex.addProxyObject(tablename, ipId, "ipId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } // Revoke all firewall rules for the ip @@ -1117,7 +1142,15 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { FirewallRuleVO ruleVO = _firewallDao.findById(rule.getId()); if (ip == null || !ip.isOneToOneNat() || ip.getAssociatedWithVmId() == null) { - throw new InvalidParameterValueException("Source ip address of the rule id=" + rule.getId() + " is not static nat enabled"); + InvalidParameterValueException ex = new InvalidParameterValueException("Source ip address of the specified firewall rule id is not static nat enabled"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(ruleVO); + if (tablename != null) { + ex.addProxyObject(tablename, rule.getId(), "ruleId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } String dstIp; @@ -1149,7 +1182,15 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { UserVmVO vm = _vmDao.findById(sourceIp.getAssociatedWithVmId()); Network network = _networkMgr.getNetwork(networkId); if (network == null) { - throw new CloudRuntimeException("Unable to find ip address to map to in vm id=" + vm.getId()); + CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address to map to specified vm id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vm.getId(), "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } if (caller != null) { @@ -1201,7 +1242,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager { s_logger.debug("Allocating system ip and enabling static nat for it for the vm " + vm + " in guest network " + guestNetwork); IpAddress ip = _networkMgr.assignSystemIp(guestNetwork.getId(), _accountMgr.getAccount(vm.getAccountId()), false, true); if (ip == null) { - throw new CloudRuntimeException("Failed to allocate system ip for vm " + vm + " in guest network " + guestNetwork); + throw new CloudRuntimeException("Failed to allocate system ip for vm " + vm + " in guest network " + guestNetwork); } s_logger.debug("Allocated system ip " + ip + ", now enabling static nat on it for vm " + vm); diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java index 88a795be629..6954e344de3 100755 --- a/server/src/com/cloud/projects/ProjectManagerImpl.java +++ b/server/src/com/cloud/projects/ProjectManagerImpl.java @@ -74,6 +74,7 @@ import com.cloud.utils.Ternary; import com.cloud.utils.component.Inject; import com.cloud.utils.component.Manager; import com.cloud.utils.concurrency.NamedThreadFactory; +import com.cloud.utils.AnnotationHelper; import com.cloud.utils.db.DB; import com.cloud.utils.db.Filter; import com.cloud.utils.db.JoinBuilder; @@ -590,12 +591,28 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ Project project = getProject(projectId); if (project == null) { - throw new InvalidParameterValueException("Unable to find the project id=" + projectId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } //User can be added to Active project only if (project.getState() != Project.State.Active) { - throw new InvalidParameterValueException("Can't add account to the project id=" + projectId + " in state=" + project.getState() + " as it's no longer active"); + InvalidParameterValueException ex = new InvalidParameterValueException("Can't add account to the specified project id in state=" + project.getState() + " as it's no longer active"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } //check that account-to-add exists @@ -603,7 +620,10 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ if (accountName != null) { account = _accountMgr.getActiveAccountByName(accountName, project.getDomainId()); if (account == null) { - throw new InvalidParameterValueException("Unable to find account name=" + accountName + " in domain id=" + project.getDomainId()); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account name=" + accountName + " in specified domain id"); + // We don't have a DomainVO object with us, so just pass the tablename "domain" manually. + ex.addProxyObject("domain", project.getDomainId(), "domainId"); + throw ex; } //verify permissions - only project owner can assign @@ -665,13 +685,23 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ Project project = getProject(projectId); if (project == null) { - throw new InvalidParameterValueException("Unable to find the project id=" + projectId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } //check that account-to-remove exists Account account = _accountMgr.getActiveAccountByName(accountName, project.getDomainId()); if (account == null) { - throw new InvalidParameterValueException("Unable to find account name=" + accountName + " in domain id=" + project.getDomainId()); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account name=" + accountName + " in domain id=" + project.getDomainId()); + // Since we don't have a domainVO object, pass the table name manually. + ex.addProxyObject("domain", project.getDomainId(), "domainId"); } //verify permissions @@ -680,12 +710,28 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ //Check if the account exists in the project ProjectAccount projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, account.getId()); if (projectAccount == null) { - throw new InvalidParameterValueException("Account " + accountName + " is not assigned to the project id=" + projectId); + InvalidParameterValueException ex = new InvalidParameterValueException("Account " + accountName + " is not assigned to the project with specified id"); + // Use the projectVO object and nt the projectAccount object to inject the projectId. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } //can't remove the owner of the project if (projectAccount.getAccountRole() == Role.Admin) { - throw new InvalidParameterValueException("Unable to delete account " + accountName + " from the project id=" + projectId + " as the account is the owner of the project"); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to delete account " + accountName + " from the project with specified id as the account is the owner of the project"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } return deleteAccountFromProject(projectId, account.getId()); @@ -940,7 +986,15 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ ProjectVO project = getProject(projectId); if (project == null) { - throw new InvalidParameterValueException("Unable to find the project id=" + projectId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } //verify permissions @@ -980,7 +1034,15 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ ProjectVO project= getProject(projectId); //verify input parameters if (project == null) { - throw new InvalidParameterValueException("Unable to find project by id " + projectId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } _accountMgr.checkAccess(caller,AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId())); @@ -989,7 +1051,15 @@ public class ProjectManagerImpl implements ProjectManager, Manager{ s_logger.debug("Successfully suspended project id=" + projectId); return _projectDao.findById(projectId); } else { - throw new CloudRuntimeException("Failed to suspend project id=" + projectId); + CloudRuntimeException ex = new CloudRuntimeException("Failed to suspend project with specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(project); + if (tablename != null) { + ex.addProxyObject(tablename, projectId, "projectId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index b0fe2b679da..09926655dd6 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -140,6 +140,7 @@ import com.cloud.utils.net.Ip; import com.cloud.utils.net.NetUtils; import com.cloud.utils.ssh.SSHCmdHelper; import com.cloud.utils.ssh.sshException; +import com.cloud.utils.AnnotationHelper; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineManager; @@ -329,23 +330,58 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma // Check if the zone exists in the system DataCenterVO zone = _dcDao.findById(dcId); if (zone == null) { - throw new InvalidParameterValueException("Can't find zone by id " + dcId); + InvalidParameterValueException ex = new InvalidParameterValueException("Can't find zone by the id specified"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, dcId, "dcId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } Account account = UserContext.current().getCaller(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { - throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + dcId); + PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, dcId, "dcId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } + HostPodVO pod = _podDao.findById(podId); + if (pod == null) { + throw new InvalidParameterValueException("Can't find pod with specified podId " + podId); + } + // Check if the pod exists in the system if (podId != null) { if (_podDao.findById(podId) == null) { throw new InvalidParameterValueException("Can't find pod by id " + podId); } // check if pod belongs to the zone - HostPodVO pod = _podDao.findById(podId); if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) { - throw new InvalidParameterValueException("Pod " + podId + " doesn't belong to the zone " + dcId); + InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified id doesn't belong to the zone " + dcId); + // Get the pod VO object's table name. + String tablename = AnnotationHelper.getTableName(pod); + if (tablename != null) { + ex.addProxyObject(tablename, podId, "podId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + // Get the zone VO object's table name. + tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, dcId, "dcId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } @@ -402,7 +438,22 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma cluster = _clusterDao.persist(cluster); } catch (Exception e) { // no longer tolerate exception during the cluster creation phase - throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + podId + " and data center " + dcId, e); + CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod and data center with specified ids", e); + // Get the pod VO object's table name. + String tablename = AnnotationHelper.getTableName(pod); + if (tablename != null) { + ex.addProxyObject(tablename, podId, "podId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + // Get the zone VO object's table name. + tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, dcId, "dcId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } clusterId = cluster.getId(); result.add(cluster); @@ -500,12 +551,28 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma if (clusterId != null) { ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null) { - throw new InvalidParameterValueException("can not fine cluster for clusterId " + clusterId); + InvalidParameterValueException ex = new InvalidParameterValueException("can not find cluster for specified clusterId"); + // Get the cluster VO object's table name. + String tablename = AnnotationHelper.getTableName(cluster); + if (tablename != null) { + ex.addProxyObject(tablename, clusterId, "clusterId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } else { if (cluster.getGuid() == null) { List hosts = listAllHostsInCluster(clusterId); if (!hosts.isEmpty()) { - throw new CloudRuntimeException("Guid is not updated for cluster " + clusterId + " need to wait hosts in this cluster up"); + CloudRuntimeException ex = new CloudRuntimeException("Guid is not updated for cluster with specified cluster id; need to wait for hosts in this cluster to come up"); + // Get the cluster VO object's table name. + String tablename = AnnotationHelper.getTableName(cluster); + if (tablename != null) { + ex.addProxyObject(tablename, clusterId, "clusterId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } } @@ -543,18 +610,44 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma Account account = UserContext.current().getCaller(); if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) { - throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + dcId); + PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled"); + // Get the zone VO object's table name. + String tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, dcId, "dcId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } + HostPodVO pod = _podDao.findById(podId); + if (pod == null) { + throw new InvalidParameterValueException("Can't find pod with specified podId " + podId); + } + // Check if the pod exists in the system if (podId != null) { if (_podDao.findById(podId) == null) { throw new InvalidParameterValueException("Can't find pod by id " + podId); } - // check if pod belongs to the zone - HostPodVO pod = _podDao.findById(podId); + // check if pod belongs to the zone if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) { - throw new InvalidParameterValueException("Pod " + podId + " doesn't belong to the zone " + dcId); + InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified podId" + podId + " doesn't belong to the zone with specified zoneId" + dcId); + // Get the pod VO object's table name. + String tablename = AnnotationHelper.getTableName(pod); + if (tablename != null) { + ex.addProxyObject(tablename, podId, "podId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, dcId, "dcId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } @@ -604,7 +697,21 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma } catch (Exception e) { cluster = _clusterDao.findBy(clusterName, podId); if (cluster == null) { - throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + podId + " and data center " + dcId, e); + CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod with specified podId and data center with specified dcID", e); + // Get the pod VO object's table name. + String tablename = AnnotationHelper.getTableName(pod); + if (tablename != null) { + ex.addProxyObject(tablename, podId, "podId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + tablename = AnnotationHelper.getTableName(zone); + if (tablename != null) { + ex.addProxyObject(tablename, dcId, "dcId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } clusterId = cluster.getId(); @@ -705,7 +812,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma // Verify that host exists HostVO host = _hostDao.findById(hostId); if (host == null) { - throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist"); + throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist"); } _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), host.getDataCenterId()); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 439792e1772..95ecd28226b 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -224,6 +224,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.ExecutionException; import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.net.NetUtils; +import com.cloud.utils.AnnotationHelper; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.InstanceGroupDao; @@ -2880,7 +2881,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager // Verify input parameters UserVmVO vm = _vmDao.findById(vmId); if (vm == null || vm.getRemoved() != null) { - throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a virtual machine with specified vmId"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } if (vm.getState() == State.Destroyed || vm.getState() == State.Expunging) { @@ -2897,7 +2906,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager try { status = _itMgr.destroy(vm, userCaller, caller); } catch (OperationTimedoutException e) { - throw new CloudRuntimeException("Unable to destroy " + vm, e); + CloudRuntimeException ex = new CloudRuntimeException("Unable to destroy with specified vmId", e); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } if (status) { @@ -2916,7 +2933,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager return _vmDao.findById(vmId); } else { - throw new CloudRuntimeException("Failed to destroy vm with id " + vmId); + CloudRuntimeException ex = new CloudRuntimeException("Failed to destroy vm with specified vmId"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } @@ -3124,7 +3149,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager public HypervisorType getHypervisorTypeOfUserVM(long vmid) { UserVmVO userVm = _vmDao.findById(vmid); if (userVm == null) { - throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmid); + InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with id " + vmid); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(userVm); + if (tablename != null) { + ex.addProxyObject(tablename, vmid, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } return userVm.getHypervisorType(); @@ -3159,7 +3192,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } if (vm.getState() != State.Stopped) { - throw new InvalidParameterValueException("VM is not Stopped, unable to migrate the vm " + vm); + InvalidParameterValueException ex = new InvalidParameterValueException("VM is not Stopped, unable to migrate the vm having the specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } if (vm.getType() != VirtualMachine.Type.User) { @@ -3201,7 +3242,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (s_logger.isDebugEnabled()) { s_logger.debug("VM is not Running, unable to migrate the vm " + vm); } - throw new InvalidParameterValueException("VM is not Running, unable to migrate the vm " + vm); + InvalidParameterValueException ex = new InvalidParameterValueException("VM is not Running, unable to migrate the vm with specified id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM) && !vm.getHypervisorType().equals(HypervisorType.Ovm)) { if (s_logger.isDebugEnabled()) { @@ -3271,7 +3320,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (s_logger.isDebugEnabled()) { s_logger.debug("VM is Running, unable to move the vm " + vm); } - throw new InvalidParameterValueException("VM is Running, unable to move the vm " + vm); + InvalidParameterValueException ex = new InvalidParameterValueException("VM is Running, unable to move the vm with specified vmId"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, cmd.getVmId(), "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } Account oldAccount = _accountService.getActiveAccountById(vm.getAccountId()); @@ -3280,7 +3337,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } //don't allow to move the vm from the project if (oldAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) { - throw new InvalidParameterValueException("Vm id=" + cmd.getVmId() + " belongs to the project and can't be moved"); + InvalidParameterValueException ex = new InvalidParameterValueException("Specified Vm id belongs to the project and can't be moved"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, cmd.getVmId(), "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } Account newAccount = _accountService.getActiveAccountByName(cmd.getAccountName(), cmd.getDomainId()); if (newAccount == null || newAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) { @@ -3467,7 +3532,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager for (Long networkId : networkIdList) { NetworkVO network = _networkDao.findById(networkId); if (network == null) { - throw new InvalidParameterValueException("Unable to find network by id " + networkId); + InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find specified network id"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(network); + if (tablename != null) { + ex.addProxyObject(tablename, networkId, "networkId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } _networkMgr.checkNetworkPermissions(newAccount, network); @@ -3475,7 +3548,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager //don't allow to use system networks NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); if (networkOffering.isSystemOnly()) { - throw new InvalidParameterValueException("Network id=" + networkId + " is system only and can't be used for vm deployment"); + InvalidParameterValueException ex = new InvalidParameterValueException("Specified Network id is system only and can't be used for vm deployment"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(network); + if (tablename != null) { + ex.addProxyObject(tablename, networkId, "networkId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } applicableNetworks.add(network); } @@ -3542,7 +3623,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager long vmId = cmd.getVmId(); UserVmVO vm = _vmDao.findById(vmId); if (vm == null) { - throw new InvalidParameterValueException("Cann not find VM with ID " + vmId); + InvalidParameterValueException ex = new InvalidParameterValueException("Cann not find VM with ID " + vmId); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } Account owner = _accountDao.findById(vm.getAccountId()); @@ -3564,14 +3653,36 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager List rootVols = _volsDao.findByInstance(vmId); if (rootVols.isEmpty()) { - throw new InvalidParameterValueException("Can not find root volume for VM " + vmId); + InvalidParameterValueException ex = new InvalidParameterValueException("Can not find root volume for VM " + vmId); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } VolumeVO root = rootVols.get(0); long templateId = root.getTemplateId(); VMTemplateVO template = _templateDao.findById(templateId); if (template == null) { - throw new InvalidParameterValueException("Cannot find template for volume " + root.getId() + " vm " + vmId); + InvalidParameterValueException ex = new InvalidParameterValueException("Cannot find template for specified volumeid and vmId"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + tablename = AnnotationHelper.getTableName(root); + if (tablename != null) { + ex.addProxyObject(tablename, root.getId(), "volumeId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } if (needRestart) { @@ -3579,7 +3690,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager _itMgr.stop(vm, user, caller); } catch (ResourceUnavailableException e) { s_logger.debug("Stop vm " + vmId + " failed", e); - throw new CloudRuntimeException("Stop vm " + vmId + " failed"); + CloudRuntimeException ex = new CloudRuntimeException("Stop vm failed for specified vmId"); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } } @@ -3600,7 +3719,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager _itMgr.start(vm, null, user, caller); } catch (Exception e) { s_logger.debug("Unable to start VM " + vmId, e); - throw new CloudRuntimeException("Unable to start VM " + vmId + " " + e.getMessage()); + CloudRuntimeException ex = new CloudRuntimeException("Unable to start VM with specified id" + e.getMessage()); + // Get the VO object's table name. + String tablename = AnnotationHelper.getTableName(vm); + if (tablename != null) { + ex.addProxyObject(tablename, vmId, "vmId"); + } else { + s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n"); + } + throw ex; } }