Bug 13127: API error text refer to database ids instead of uuids

Description:

	Adding overloaded addProxyObject() function to CloudException
	and RuntimeCloudException classes and using this function
	to stuff exceptions with IDs, to reduce code footprint.
This commit is contained in:
Vijayendra Bhamidipati 2012-03-15 12:39:43 -07:00
parent 8e2fc79174
commit 005ba5e2b5
16 changed files with 156 additions and 787 deletions

View File

@ -500,24 +500,12 @@ public abstract class BaseCmd {
return project.getProjectAccountId();
} else {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
} else {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
}

View File

@ -104,14 +104,7 @@ public class AddAccountToProjectCmd extends BaseAsyncCmd {
//verify input parameters
if (project == null) {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}

View File

@ -112,7 +112,9 @@ public class CreateSnapshotPolicyCmd extends BaseCmd {
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(volume.getAccountId());
if (project.getState() != Project.State.Active) {
throw new PermissionDeniedException("Can't add resources to the project id=" + project.getId() + " in state=" + project.getState() + " as it's no longer active");
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, project.getId(), "projectId");
throw ex;
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of template is disabled: " + account);

View File

@ -210,7 +210,8 @@ import com.cloud.user.UserContext;
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(accountId);
if (project.getState() != Project.State.Active) {
throw new PermissionDeniedException("Can't add resources to the project id=" + project.getId() + " in state=" + project.getState() + " as it's no longer active");
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, project.getId(), "projectId");
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of template is disabled: " + account);

View File

@ -20,6 +20,7 @@ package com.cloud.exception;
import com.cloud.utils.IdentityProxy;
import java.util.ArrayList;
import com.cloud.utils.exception.CSExceptionErrorCode;
import com.cloud.utils.AnnotationHelper;
/**
* CloudException is a generic exception class that has an IdentityProxy
@ -49,6 +50,15 @@ public class CloudException extends Exception {
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
}
public void addProxyObject(Object voObj, Long id, String idFieldName) {
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(voObj);
if (tablename != null) {
addProxyObject(tablename, id, idFieldName);
}
return;
}
public CloudException() {
super();
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));

View File

@ -484,7 +484,9 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
}
}
if (agent == null) {
throw new AgentUnavailableException("Host is not in the right state: " + host.getStatus() , hostId);
AgentUnavailableException ex = new AgentUnavailableException("Host with specified id is not in the right state: " + host.getStatus(), hostId);
ex.addProxyObject(host, hostId, "hostId");
throw ex;
}
return agent;

View File

@ -67,7 +67,9 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements
List<HostVO> pxeServers = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.PxeServer, null, podId, zoneId);
if (pxeServers.size() != 0) {
throw new InvalidParameterValueException("Already had a PXE server in Pod: " + podId + " zone: " + zoneId);
InvalidParameterValueException ex = new InvalidParameterValueException("Already had a PXE server in Pod with specified podId and zone with specified zoneId");
ex.addProxyObject("pod", podId, "podId");
ex.addProxyObject(zone, zoneId, "zoneId");
}

View File

@ -169,7 +169,9 @@ public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMet
}
if (pxes.size() > 1) {
throw new CloudRuntimeException("Multiple PXE servers found in Pod " + host.getPodId() + " Zone " + host.getDataCenterId());
CloudRuntimeException ex = new CloudRuntimeException("Multiple PXE servers found in Pod " + host.getPodId() + " in Zone with specified id");
ex.addProxyObject("data_center", host.getDataCenterId(), "zoneId");
throw ex;
}
HostVO pxe = pxes.get(0);

View File

@ -966,13 +966,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Network network = _networksDao.findById(networkId);
if (network == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network id is invalid");
// 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");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
@ -1006,13 +1000,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
// zone is of type DataCenter. See DataCenterVO.java.
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, zone.getId(), "zoneId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(zone, zone.getId(), "zoneId");
throw ex;
}
@ -1439,19 +1427,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (errorIfAlreadySetup) {
InvalidParameterValueException ex = new InvalidParameterValueException("Found existing network configuration (with specified id) for offering (with specified id)");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(offering);
if (tablename != null) {
ex.addProxyObject(tablename, offering.getId(), "offeringId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
tablename = AnnotationHelper.getTableName(configs.get(0));
if (tablename != null) {
ex.addProxyObject(tablename, configs.get(0).getId(), "networkConfigId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(offering, offering.getId(), "offeringId");
ex.addProxyObject(configs.get(0), configs.get(0).getId(), "networkConfigId");
throw ex;
} else {
return configs;
@ -1467,19 +1444,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (errorIfAlreadySetup) {
InvalidParameterValueException ex = new InvalidParameterValueException("Found existing network configuration (with specified id) for offering (with specified id)");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(offering);
if (tablename != null) {
ex.addProxyObject(tablename, offering.getId(), "offeringId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
tablename = AnnotationHelper.getTableName(configs.get(0));
if (tablename != null) {
ex.addProxyObject(tablename, configs.get(0).getId(), "networkConfigId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(offering, offering.getId(), "offeringId");
ex.addProxyObject(configs.get(0), configs.get(0).getId(), "networkConfigId");
throw ex;
} else {
return configs;
@ -1528,12 +1494,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (networks.size() < 1) {
// see networkOfferingVO.java
CloudRuntimeException ex = new CloudRuntimeException("Unable to convert network offering with specified id to network profile");
String tablename = AnnotationHelper.getTableName(offering);
if (tablename != null) {
ex.addProxyObject(tablename, offering.getId(), "networkOfferingId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(offering, offering.getId(), "offeringId");
throw ex;
}
@ -1824,12 +1785,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
if (!element.implement(network, offering, dest, context)) {
CloudRuntimeException ex = new CloudRuntimeException("Failed to implement provider " + element.getProvider().getName() + " for network with specified id");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
ex.addProxyObject(tablename, network.getId(), "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, network.getId(), "networkId");
throw ex;
}
}
@ -2061,27 +2017,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
// Check for account wide pool. It will have an entry for account_vlan_map.
if (_accountVlanMapDao.findAccountVlanMap(ipVO.getAllocatedToAccountId(), ipVO.getVlanId()) != null) {
if (_accountVlanMapDao.findAccountVlanMap(ipVO.getAllocatedToAccountId(), ipVO.getVlanId()) != null) {
//see IPaddressVO.java
InvalidParameterValueException ex = new InvalidParameterValueException("Sepcified IP address uuid belongs to Account wide IP pool and cannot be disassociated");
String tablename = AnnotationHelper.getTableName(ipVO);
if (tablename != null) {
ex.addProxyObject(tablename, ipVO.getId(), "systemIpAddrId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(ipVO, ipVO.getId(), "systemIpAddrId");
throw ex;
}
// don't allow releasing system ip address
if (ipVO.getSystem()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Can't release system IP address with specified id");
String tablename = AnnotationHelper.getTableName(ipVO);
if (tablename != null) {
ex.addProxyObject(tablename, ipVO.getId(), "systemIpAddrId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(ipVO, ipVO.getId(), "systemIpAddrId");
throw ex;
}
@ -2251,13 +2197,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (ntwkOff == null || ntwkOff.isSystemOnly()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering by specified id");
if (ntwkOff != null) {
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(ntwkOff);
if (tablename != null) {
ex.addProxyObject(tablename, networkOfferingId, "networkOfferingId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(ntwkOff, networkOfferingId, "networkOfferingId");
throw ex;
}
throw ex;
@ -2284,13 +2224,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
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");
// 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");
}
ex.addProxyObject(zone, zoneId, "zoneId");
throw ex;
}
@ -2436,12 +2370,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// Can add vlan range only to the network which allows it
if (createVlan && !ntwkOff.getSpecifyIpRanges()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network offering with specified id doesn't support adding multiple ip ranges");
String tablename = AnnotationHelper.getTableName(ntwkOff);
if (tablename != null) {
ex.addProxyObject(tablename, ntwkOff.getId(), "networkOfferingId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(ntwkOff, ntwkOff.getId(), "networkOfferingId");
throw ex;
}
@ -2497,13 +2426,7 @@ 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);
// 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");
}
ex.addProxyObject(ntwkOff, ntwkOff.getId(), "networkOfferingId");
throw ex;
}
@ -2770,13 +2693,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) {
// getProject() returns type ProjectVO.
InvalidParameterValueException ex = new InvalidParameterValueException("Account " + caller + " cannot access specified project 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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
permittedAccounts.add(project.getProjectAccountId());
@ -2984,24 +2901,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// see NetworkVO.java
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find network with specified id");
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");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
// don't allow to delete system network
if (isNetworkSystem(network)) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id is system and can't be removed");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
ex.addProxyObject(tablename, network.getId(), "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, network.getId(), "networkId");
throw ex;
}
@ -3431,12 +3338,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NetworkVO network = _networksDao.findById(networkId);
if (network == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist");
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");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
@ -4138,26 +4040,14 @@ 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 with specified id");
// 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");
}
ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId");
throw ex;
}
// network offering should be in Enabled state
if (networkOffering.getState() != NetworkOffering.State.Enabled) {
InvalidParameterValueException ex = new InvalidParameterValueException("Network offering with specified id is not in " + NetworkOffering.State.Enabled + " state, can't upgrade to it");
// 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");
}
ex.addProxyObject(networkOffering, networkOfferingId, "networkOfferingId");
throw ex;
}
@ -4169,13 +4059,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (changeCidr) {
if (!checkForNonStoppedVmInNetwork(network.getId())) {
InvalidParameterValueException ex = new InvalidParameterValueException("All user vm of network of specified id should be stopped before changing CIDR!");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
// We could use network.getId() instead of networkId too.
ex.addProxyObject(tablename, networkId, "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
}
@ -4230,13 +4114,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (!shutdownNetworkElementsAndResources(context, true, network)) {
s_logger.warn("Failed to shutdown the network elements and resources as a part of network restart: " + network);
CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of update to network of specified id");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
// We could use network.getId() instead of networkId too.
ex.addProxyObject(tablename, networkId, "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
} else {
@ -4246,25 +4124,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (!shutdownNetwork(network.getId(), context, true)) {
s_logger.warn("Failed to shutdown the network as a part of update to network with specified id");
CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network as a part of update of specified network id");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
// We could use network.getId() instead of networkId too.
ex.addProxyObject(tablename, networkId, "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
}
} else {
CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of update to network with specified id; network is in wrong state: " + network.getState());
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
// We could use network.getId() instead of networkId too.
ex.addProxyObject(tablename, networkId, "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
}
@ -4275,13 +4141,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
boolean validStateToImplement = (networkState == Network.State.Implemented || networkState == Network.State.Setup || networkState == Network.State.Allocated);
if (restartNetwork && !validStateToImplement) {
CloudRuntimeException ex = new CloudRuntimeException("Failed to implement the network elements and resources as a part of update to network with specified id; network is in wrong state: " + networkState);
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
// We could use network.getId() instead of networkId too.
ex.addProxyObject(tablename, networkId, "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
@ -4331,13 +4191,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} catch (Exception ex) {
s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network update due to ", ex);
CloudRuntimeException e = new CloudRuntimeException("Failed to implement network (with specified id) elements and resources as a part of network update");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
// We could use network.getId() instead of networkId too.
e.addProxyObject(tablename, networkId, "networkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
e.addProxyObject(network, networkId, "networkId");
throw e;
}
}
@ -4856,12 +4710,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
PhysicalNetworkVO network = _physicalNetworkDao.findById(id);
if (network == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
ex.addProxyObject(tablename, id, "physicalNetworkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, id, "physicalNetworkId");
throw ex;
}
@ -4869,12 +4718,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
DataCenter zone = _dcDao.findById(network.getDataCenterId());
if (zone == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Zone with id=" + network.getDataCenterId() + " doesn't exist in the system");
String tablename = AnnotationHelper.getTableName(zone);
if (tablename != null) {
ex.addProxyObject(tablename, network.getDataCenterId(), "dataCenterId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(zone, network.getDataCenterId(), "dataCenterId");
throw ex;
}
if (newVnetRangeString != null) {
@ -5000,12 +4844,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (pNetwork == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
String tablename = AnnotationHelper.getTableName(pNetwork);
if (tablename != null) {
ex.addProxyObject(tablename, physicalNetworkId, "physicalNetworkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(pNetwork, physicalNetworkId, "physicalNetworkId");
throw ex;
}
@ -5180,12 +5019,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
if (network == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
String tablename = AnnotationHelper.getTableName(network);
if (tablename != null) {
ex.addProxyObject(tablename, physicalNetworkId, "physicalNetworkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(network, physicalNetworkId, "physicalNetworkId");
throw ex;
}
@ -5194,12 +5028,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId);
if (destNetwork == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system");
String tablename = AnnotationHelper.getTableName(destNetwork);
if (tablename != null) {
ex.addProxyObject(tablename, destinationPhysicalNetworkId, "destinationPhysicalNetworkId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(destNetwork, destinationPhysicalNetworkId, "destinationPhysicalNetworkId");
throw ex;
}
}

View File

@ -416,13 +416,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
UserVm vm = _vmDao.findById(instanceId);
if (vm == null || vm.getState() == State.Destroyed || vm.getState() == State.Expunging) {
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");
}
ex.addProxyObject(vm, instanceId, "instanceId");
throw ex;
}
@ -444,13 +438,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if (nicInSameNetwork == null) {
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");
}
ex.addProxyObject(vm, instanceId, "instanceId");
throw ex;
}
@ -496,13 +484,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if(!success){
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");
}
ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
// TBD: Also pack in the instanceIds in the exception using the right VO object or table name.
throw ex;
}
@ -542,13 +524,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
if (!applyLoadBalancerConfig(loadBalancerId)) {
s_logger.warn("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");
}
ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
throw ex;
}
success = true;
@ -570,13 +546,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
}
if(!success){
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");
}
ex.addProxyObject(loadBalancer, loadBalancerId, "loadBalancerId");
throw ex;
}
return success;
@ -801,23 +771,11 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
// make sure ip address exists
if (ipAddr == null || !ipAddr.readyToUse()) {
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");
}
ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
throw ex;
} else if (ipAddr.isOneToOneNat()) {
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");
}
ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
throw ex;
}
@ -826,13 +784,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
networkId = ipAddr.getAssociatedWithNetworkId();
if (networkId == null) {
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");
}
ex.addProxyObject(ipAddr, sourceIpId, "sourceIpId");
throw ex;
}
@ -843,15 +795,8 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
// verify that lb service is supported by the network
if (!_networkMgr.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
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");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
Transaction txn = Transaction.currentTxn();

View File

@ -1031,26 +1031,14 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
if (ipAddress.getSystem()) {
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");
}
ex.addProxyObject(ipAddress, ipId, "ipId");
throw ex;
}
Long vmId = ipAddress.getAssociatedWithVmId();
if (vmId == null) {
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");
}
ex.addProxyObject(ipAddress, ipId, "ipId");
throw ex;
}
@ -1077,13 +1065,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
if (!ipAddress.isOneToOneNat()) {
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");
}
ex.addProxyObject(ipAddress, ipId, "ipId");
throw ex;
}
@ -1143,13 +1125,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
if (ip == null || !ip.isOneToOneNat() || ip.getAssociatedWithVmId() == null) {
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");
}
ex.addProxyObject(ruleVO, rule.getId(), "ruleId");
throw ex;
}
@ -1182,14 +1158,8 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
UserVmVO vm = _vmDao.findById(sourceIp.getAssociatedWithVmId());
Network network = _networkMgr.getNetwork(networkId);
if (network == null) {
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");
}
CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address to map to specified vm id");
ex.addProxyObject(vm, vm.getId(), "vmId");
throw ex;
}

View File

@ -591,27 +591,15 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
Project project = getProject(projectId);
if (project == null) {
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");
}
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id");
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
//User can be added to Active project only
if (project.getState() != Project.State.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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
@ -686,13 +674,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
if (project == null) {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
@ -711,26 +693,15 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
ProjectAccount projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, account.getId());
if (projectAccount == null) {
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");
}
// Use the projectVO object and not the projectAccount object to inject the projectId.
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
//can't remove the owner of the project
if (projectAccount.getAccountRole() == Role.Admin) {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
@ -987,13 +958,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
if (project == null) {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
@ -1035,13 +1000,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
//verify input parameters
if (project == null) {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
@ -1052,13 +1011,7 @@ public class ProjectManagerImpl implements ProjectManager, Manager{
return _projectDao.findById(projectId);
} else {
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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}

View File

@ -331,26 +331,14 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
DataCenterVO zone = _dcDao.findById(dcId);
if (zone == null) {
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");
}
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
Account account = UserContext.current().getCaller();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
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");
}
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
@ -367,20 +355,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
// check if pod belongs to the zone
if (!Long.valueOf(pod.getDataCenterId()).equals(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");
}
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
}
@ -440,19 +416,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
// no longer tolerate exception during the cluster creation phase
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");
}
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
clusterId = cluster.getId();
@ -552,26 +517,14 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null) {
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");
}
ex.addProxyObject(cluster, clusterId, "clusterId");
throw ex;
} else {
if (cluster.getGuid() == null) {
List<HostVO> hosts = listAllHostsInCluster(clusterId);
if (!hosts.isEmpty()) {
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");
}
ex.addProxyObject(cluster, clusterId, "clusterId");
throw ex;
}
}
@ -611,13 +564,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
Account account = UserContext.current().getCaller();
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
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");
}
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
@ -634,19 +581,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
// check if pod belongs to the zone
if (!Long.valueOf(pod.getDataCenterId()).equals(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");
}
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
}
@ -698,19 +634,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
cluster = _clusterDao.findBy(clusterName, podId);
if (cluster == null) {
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");
}
ex.addProxyObject(pod, podId, "podId");
ex.addProxyObject(zone, dcId, "dcId");
throw ex;
}
}

View File

@ -671,13 +671,7 @@ public class ManagementServerImpl implements ManagementServer {
UserVmVO vmInstance = _userVmDao.findById(vmId);
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(vmInstance);
if (tablename != null) {
ex.addProxyObject(tablename, vmId, "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(vmInstance, vmId, "vmId");
throw ex;
}
@ -749,13 +743,7 @@ public class ManagementServerImpl implements ManagementServer {
UserVmVO vmInstance = _userVmDao.findById(vmId);
if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(vmInstance);
if (tablename != null) {
ex.addProxyObject(tablename, vmId, "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(vmInstance, vmId, "vmId");
throw ex;
}
@ -886,13 +874,7 @@ public class ManagementServerImpl implements ManagementServer {
VMInstanceVO vm = _vmInstanceDao.findById(vmId);
if (vm == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find 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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
// business logic
@ -901,13 +883,7 @@ public class ManagementServerImpl implements ManagementServer {
s_logger.debug("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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
@ -933,19 +909,8 @@ public class ManagementServerImpl implements ManagementServer {
s_logger.debug("Unable to find the host with id: " + srcHostId + " of this VM:" + vm);
}
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find the host (with specified id) of VM with specified id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(srcHost);
if (tablename != null) {
ex.addProxyObject(tablename, srcHostId, "hostId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
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");
}
ex.addProxyObject(srcHost, srcHostId, "hostId");
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
Long cluster = srcHost.getClusterId();
@ -1095,7 +1060,7 @@ public class ManagementServerImpl implements ManagementServer {
}
Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");
// Since we don't have a DomainVO object here, we directly set tablename to "domain".
String tablename = "domain";
ex.addProxyObject(tablename, domainId, "domainId");
@ -1118,13 +1083,7 @@ public class ManagementServerImpl implements ManagementServer {
Project project = _projectMgr.getProject(projectId);
if (project == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project by id " + 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");
}
ex.addProxyObject(project, projectId, "projectId");
throw ex;
}
accountId = project.getProjectAccountId();
@ -1293,25 +1252,13 @@ public class ManagementServerImpl implements ManagementServer {
if (isIso && template.getFormat() != ImageFormat.ISO) {
s_logger.error("Template Id " + templateId + " is not an ISO");
InvalidParameterValueException ex = new InvalidParameterValueException("Specified Template Id is not an ISO");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(template);
if (tablename != null) {
ex.addProxyObject(tablename, templateId, "templateId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(template, templateId, "templateId");
throw ex;
}// If ISO not requested then it shouldn't be an ISO.
if (!isIso && template.getFormat() == ImageFormat.ISO) {
s_logger.error("Incorrect format of the template id " + templateId);
InvalidParameterValueException ex = new InvalidParameterValueException("Incorrect format " + template.getFormat() + " of the specified template id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(template);
if (tablename != null) {
ex.addProxyObject(tablename, templateId, "templateId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(template, templateId, "templateId");
throw ex;
}
}
@ -1391,26 +1338,14 @@ public class ManagementServerImpl implements ManagementServer {
VMTemplateVO template = _templateDao.findById(id);
if (template == null || template.getRemoved() != null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find template/iso with specified id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(template);
if (tablename != null) {
ex.addProxyObject(tablename, id, "templateId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(template, id, "templateId");
throw ex;
}
// Don't allow to modify system template
if (id == Long.valueOf(1)) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(template);
if (tablename != null) {
ex.addProxyObject(tablename, id, "templateId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(template, id, "templateId");
throw ex;
}
@ -1911,13 +1846,7 @@ public class ManagementServerImpl implements ManagementServer {
DomainVO domain = _domainDao.findById(domainId);
if (domain == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain with specified domain id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(domain);
if (tablename != null) {
ex.addProxyObject(tablename, domainId, "domainId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(domain, domainId, "domainId");
throw ex;
} else if (domain.getParent() == null && domainName != null) {
// check if domain is ROOT domain - and deny to edit it with the new name
@ -1938,13 +1867,7 @@ public class ManagementServerImpl implements ManagementServer {
if (!domains.isEmpty() && !sameDomain) {
InvalidParameterValueException ex = new InvalidParameterValueException("Failed to update specified domain id with name '" + domainName + "' since it already exists in the system");
// Get the domainVO object's table name.
String tablename = AnnotationHelper.getTableName(domain);
if (tablename != null) {
ex.addProxyObject(tablename, domainId, "domainId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from domainVO proxy cglib object\n");
}
ex.addProxyObject(domain, domainId, "domainId");
throw ex;
}
}
@ -2645,13 +2568,7 @@ public class ManagementServerImpl implements ManagementServer {
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
if (systemVm == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a system vm of specified instanceId");
// Get the VMInstanceVO object's table name.
String tablename = AnnotationHelper.getTableName(systemVm);
if (tablename != null) {
ex.addProxyObject(tablename, instanceId, "instanceId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VMInstanceVO proxy cglib object\n");
}
ex.addProxyObject(systemVm, instanceId, "instanceId");
throw ex;
}
return systemVm.getType();
@ -2663,13 +2580,7 @@ public class ManagementServerImpl implements ManagementServer {
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(vmId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
if (systemVm == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a system vm with specified vmId");
// Get the VMInstanceVO object's table name.
String tablename = AnnotationHelper.getTableName(systemVm);
if (tablename != null) {
ex.addProxyObject(tablename, vmId, "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VMInstanceVO proxy cglib object\n");
}
ex.addProxyObject(systemVm, vmId, "vmId");
throw ex;
}
@ -2679,13 +2590,7 @@ public class ManagementServerImpl implements ManagementServer {
return startSecondaryStorageVm(vmId);
} else {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a system vm with specified vmId");
// Get the VMInstanceVO object's table name.
String tablename = AnnotationHelper.getTableName(systemVm);
if (tablename != null) {
ex.addProxyObject(tablename, vmId, "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VMInstanceVO proxy cglib object\n");
}
ex.addProxyObject(systemVm, vmId, "vmId");
throw ex;
}
}
@ -2698,13 +2603,7 @@ public class ManagementServerImpl implements ManagementServer {
VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(id, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
if (systemVm == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a system vm with specified vmId");
// Get the VMInstanceVO object's table name.
String tablename = AnnotationHelper.getTableName(systemVm);
if (tablename != null) {
ex.addProxyObject(tablename, id, "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VMInstanceVO proxy object\n");
}
ex.addProxyObject(systemVm, id, "vmId");
throw ex;
}
@ -2726,13 +2625,7 @@ public class ManagementServerImpl implements ManagementServer {
if (systemVm == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a system vm with specified vmId");
// Get the VMInstanceVO object's table name.
String tablename = AnnotationHelper.getTableName(systemVm);
if (tablename != null) {
ex.addProxyObject(tablename, cmd.getId(), "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VMInstanceVO proxy object\n");
}
ex.addProxyObject(systemVm, cmd.getId(), "vmId");
throw ex;
}
@ -2749,13 +2642,7 @@ public class ManagementServerImpl implements ManagementServer {
if (systemVm == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a system vm with specified vmId");
// Get the VMInstanceVO object's table name.
String tablename = AnnotationHelper.getTableName(systemVm);
if (tablename != null) {
ex.addProxyObject(tablename, cmd.getId(), "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VMInstanceVO proxy object\n");
}
ex.addProxyObject(systemVm, cmd.getId(), "vmId");
throw ex;
}
@ -2793,13 +2680,7 @@ public class ManagementServerImpl implements ManagementServer {
User user = _accountMgr.getUserIncludingRemoved(userId);
if ((user == null) || (user.getRemoved() != null)) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find active user of specified id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(user);
if (tablename != null) {
ex.addProxyObject(tablename, userId, "userId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(user, userId, "userId");
throw ex;
}
@ -2881,13 +2762,7 @@ public class ManagementServerImpl implements ManagementServer {
VolumeVO volume = _volumeDao.findById(volumeId);
if (volume == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find volume with specified volumeId");
// Get the VolumeVO object's table name.
String tablename = AnnotationHelper.getTableName(volume);
if (tablename != null) {
ex.addProxyObject(tablename, volumeId, "volumeId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VolumeVO proxy object\n");
}
ex.addProxyObject(volume, volumeId, "volumeId");
throw ex;
}
@ -2904,32 +2779,19 @@ public class ManagementServerImpl implements ManagementServer {
if (volume.getInstanceId() != null && ApiDBUtils.findVMInstanceById(volume.getInstanceId()).getState() != State.Stopped) {
s_logger.debug("Invalid state of the volume with ID: " + volumeId + ". It should be either detached or the VM should be in stopped state.");
PermissionDeniedException ex = new PermissionDeniedException("Invalid state of the volume with specified ID. It should be either detached or the VM should be in stopped state.");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(volume);
if (tablename != null) {
ex.addProxyObject(tablename, volumeId, "volumeId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VolumeVO proxy object\n");
}
ex.addProxyObject(volume, volumeId, "volumeId");
throw ex;
}
if (volume.getVolumeType() != Volume.Type.DATADISK) { // Datadisk dont have any template dependence.
VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
if (template != null) { // For ISO based volumes template = null and we allow extraction of all ISO based
// volumes
if (template != null) { // For ISO based volumes template = null and we allow extraction of all ISO based volumes
boolean isExtractable = template.isExtractable() && template.getTemplateType() != Storage.TemplateType.SYSTEM;
if (!isExtractable && account != null && account.getType() != Account.ACCOUNT_TYPE_ADMIN) { // Global
// admins are always allowed to extract
PermissionDeniedException ex = new PermissionDeniedException("The volume with specified volumeId is not allowed to be extracted");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(volume);
if (tablename != null) {
ex.addProxyObject(tablename, volumeId, "volumeId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from VolumeVO proxy object\n");
}
ex.addProxyObject(volume, volumeId, "volumeId");
throw ex;
}
}
@ -3066,13 +2928,7 @@ public class ManagementServerImpl implements ManagementServer {
InstanceGroupVO group = _vmGroupDao.findById(groupId.longValue());
if (group == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a vm group with specified groupId");
// Get the VolumeVO object's table name.
String tablename = AnnotationHelper.getTableName(group);
if (tablename != null) {
ex.addProxyObject(tablename, groupId, "groupId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from InstanceGroupVO proxy object\n");
}
ex.addProxyObject(group, groupId, "groupId");
throw ex;
}
@ -3296,13 +3152,7 @@ public class ManagementServerImpl implements ManagementServer {
SSHKeyPairVO s = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName());
if (s == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' does not exist for account " + owner.getAccountName() + " in specified domain id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(owner);
if (tablename != null) {
ex.addProxyObject(tablename, owner.getDomainId(), "domainId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(owner, owner.getDomainId(), "domainId");
throw ex;
}
@ -3385,13 +3235,7 @@ public class ManagementServerImpl implements ManagementServer {
UserVmVO vm = _userVmDao.findById(cmd.getId());
if (vm == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("No VM with specified id found.");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(vm);
if (tablename != null) {
ex.addProxyObject(tablename, cmd.getId(), "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(vm, cmd.getId(), "vmId");
throw ex;
}
@ -3402,13 +3246,7 @@ public class ManagementServerImpl implements ManagementServer {
String password = vm.getDetail("Encrypted.Password");
if (password == null || password.equals("")) {
InvalidParameterValueException ex = new InvalidParameterValueException("No password for VM with specified id found.");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(vm);
if (tablename != null) {
ex.addProxyObject(tablename, cmd.getId(), "vmId");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(vm, cmd.getId(), "vmId");
throw ex;
}
@ -3514,13 +3352,7 @@ public class ManagementServerImpl implements ManagementServer {
if (hpvCapabilities == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find the hypervisor capabilities for specified id");
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(hpvCapabilities);
if (tablename != null) {
ex.addProxyObject(tablename, id, "Id");
} else {
s_logger.info("\nCould not retrieve table name (annotation) from " + tablename + " VO proxy object\n");
}
ex.addProxyObject(hpvCapabilities, id, "Id");
throw ex;
}

View File

@ -2882,13 +2882,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
UserVmVO vm = _vmDao.findById(vmId);
if (vm == null || vm.getRemoved() != null) {
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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
@ -2907,13 +2901,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
status = _itMgr.destroy(vm, userCaller, caller);
} catch (OperationTimedoutException 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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
@ -2934,13 +2922,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
return _vmDao.findById(vmId);
} else {
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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
}
@ -3146,17 +3128,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
}
@Override
public HypervisorType getHypervisorTypeOfUserVM(long vmid) {
UserVmVO userVm = _vmDao.findById(vmid);
public HypervisorType getHypervisorTypeOfUserVM(long vmId) {
UserVmVO userVm = _vmDao.findById(vmId);
if (userVm == null) {
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");
}
InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id");
ex.addProxyObject(userVm, vmId, "vmId");
throw ex;
}
@ -3193,13 +3169,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
if (vm.getState() != State.Stopped) {
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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
@ -3243,13 +3213,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
s_logger.debug("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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM) && !vm.getHypervisorType().equals(HypervisorType.Ovm)) {
@ -3321,13 +3285,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
s_logger.debug("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");
}
ex.addProxyObject(vm, cmd.getVmId(), "vmId");
throw ex;
}
@ -3338,13 +3296,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
//don't allow to move the vm from the project
if (oldAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
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");
}
ex.addProxyObject(vm, cmd.getVmId(), "vmId");
throw ex;
}
Account newAccount = _accountService.getActiveAccountByName(cmd.getAccountName(), cmd.getDomainId());
@ -3533,13 +3485,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
NetworkVO network = _networkDao.findById(networkId);
if (network == null) {
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");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
@ -3549,13 +3495,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
NetworkOffering networkOffering = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
if (networkOffering.isSystemOnly()) {
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");
}
ex.addProxyObject(network, networkId, "networkId");
throw ex;
}
applicableNetworks.add(network);
@ -3624,13 +3564,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
UserVmVO vm = _vmDao.findById(vmId);
if (vm == null) {
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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
@ -3654,13 +3588,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
List<VolumeVO> rootVols = _volsDao.findByInstance(vmId);
if (rootVols.isEmpty()) {
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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
@ -3669,19 +3597,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
VMTemplateVO template = _templateDao.findById(templateId);
if (template == null) {
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");
}
ex.addProxyObject(vm, vmId, "vmId");
ex.addProxyObject(root, root.getId(), "volumeId");
throw ex;
}
@ -3691,13 +3608,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
} catch (ResourceUnavailableException e) {
s_logger.debug("Stop vm " + vmId + " failed", e);
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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
}
@ -3720,13 +3631,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
} catch (Exception e) {
s_logger.debug("Unable to start VM " + vmId, e);
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");
}
ex.addProxyObject(vm, vmId, "vmId");
throw ex;
}
}

View File

@ -17,6 +17,7 @@
*/
package com.cloud.utils.exception;
import com.cloud.utils.AnnotationHelper;
import com.cloud.utils.IdentityProxy;
import java.util.ArrayList;
@ -52,6 +53,15 @@ public class RuntimeCloudException extends RuntimeException {
super(message, cause);
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
}
public void addProxyObject(Object voObj, Long id, String idFieldName) {
// Get the VO object's table name.
String tablename = AnnotationHelper.getTableName(voObj);
if (tablename != null) {
addProxyObject(tablename, id, idFieldName);
}
return;
}
public RuntimeCloudException() {
super();