mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-02 20:02:29 +01:00 
			
		
		
		
	Bug 13127: API error text refer to database ids instead of uuids
Description: 1) Added a setProxyObject() method to CloudException and RuntimeCloudException 2) Modified a bunch of throw exceptions in NetworkManagerImpl.java to call setProxyObject() before throwing an exception. 3) Changed scope of ProxyIdentity attribute to protected. 4) Added routines to ServerApiException to get/set IdentityProxy object, and routine in RuntimeCloudException to get the Idproxy object. 5) Modified the exception handling around the dispatcher and handlerequest() to copy over the IdentityProxy information before rethrowing an exception eventually back to handle(). 6) Removed duplicate IdentityProxy object in ServerApiException. It was extending RuntimeCloudException which already had an IdentityProxy object.
This commit is contained in:
		
							parent
							
								
									768d7a2a26
								
							
						
					
					
						commit
						c3fbe29cf8
					
				@ -17,6 +17,7 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.cloud.api;
 | 
			
		||||
import com.cloud.utils.IdentityProxy;
 | 
			
		||||
import com.cloud.utils.exception.RuntimeCloudException;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings("serial")
 | 
			
		||||
@ -49,4 +50,5 @@ public class ServerApiException extends RuntimeCloudException {
 | 
			
		||||
    public void setDescription(String description) {
 | 
			
		||||
        _description = description;
 | 
			
		||||
    }
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -209,6 +209,7 @@ public class CreateNetworkCmd extends BaseCmd {
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
 | 
			
		||||
    	// an exception thrown by createNetwork() will be caught by the dispatcher. 
 | 
			
		||||
        Network result = _networkService.createNetwork(this);
 | 
			
		||||
        if (result != null) {
 | 
			
		||||
            NetworkResponse response = _responseGenerator.createNetworkResponse(result);
 | 
			
		||||
 | 
			
		||||
@ -30,13 +30,13 @@ import com.cloud.utils.IdentityProxy;
 | 
			
		||||
 | 
			
		||||
public class CloudException extends Exception {
 | 
			
		||||
    
 | 
			
		||||
	IdentityProxy id;
 | 
			
		||||
	protected IdentityProxy id;
 | 
			
		||||
	
 | 
			
		||||
	public CloudException(String table_name, Long id) {
 | 
			
		||||
		this.id = new IdentityProxy();
 | 
			
		||||
        this.id.setTableName(table_name);
 | 
			
		||||
        this.id.setValue(id);
 | 
			
		||||
    }
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public CloudException(String message) {
 | 
			
		||||
		super(message);		
 | 
			
		||||
@ -52,4 +52,14 @@ public class CloudException extends Exception {
 | 
			
		||||
		super();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
	public void setProxyObject(String table_name, Long id) {
 | 
			
		||||
		this.id = new IdentityProxy();
 | 
			
		||||
		this.id.setTableName(table_name);
 | 
			
		||||
		this.id.setValue(id);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public IdentityProxy getIdProxy() {
 | 
			
		||||
		return id;
 | 
			
		||||
	}	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -40,6 +40,7 @@ import com.cloud.exception.InvalidParameterValueException;
 | 
			
		||||
import com.cloud.exception.PermissionDeniedException;
 | 
			
		||||
import com.cloud.exception.ResourceAllocationException;
 | 
			
		||||
import com.cloud.exception.ResourceUnavailableException;
 | 
			
		||||
import com.cloud.utils.IdentityProxy;
 | 
			
		||||
import com.cloud.server.ManagementServer;
 | 
			
		||||
import com.cloud.user.Account;
 | 
			
		||||
import com.cloud.user.UserContext;
 | 
			
		||||
@ -137,24 +138,83 @@ public class ApiDispatcher {
 | 
			
		||||
            cmd.execute();
 | 
			
		||||
 | 
			
		||||
        } catch (Throwable t) {
 | 
			
		||||
            if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) {
 | 
			
		||||
                s_logger.info(t.getMessage());
 | 
			
		||||
                throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
 | 
			
		||||
            if (t instanceof InvalidParameterValueException) {
 | 
			
		||||
            	// earlier, we'd log the db id as part of the log message, but now since we've pushed
 | 
			
		||||
            	// the id into a IdentityProxy object, we would need to dump that object alongwith the
 | 
			
		||||
            	// message.
 | 
			
		||||
            	InvalidParameterValueException ref = (InvalidParameterValueException)t;
 | 
			
		||||
            	ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getProxyObject();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	ex.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                	s_logger.info(t.getMessage() + " uuid: " + id.getValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                	s_logger.info(t.getMessage());
 | 
			
		||||
                }
 | 
			
		||||
                throw ex;
 | 
			
		||||
            } else if(t instanceof IllegalArgumentException) {
 | 
			
		||||
            	throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
 | 
			
		||||
            } else if (t instanceof PermissionDeniedException) {
 | 
			
		||||
                s_logger.info("PermissionDenied: " + t.getMessage());
 | 
			
		||||
                throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
 | 
			
		||||
            	PermissionDeniedException ref = (PermissionDeniedException)t;
 | 
			
		||||
            	ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getProxyObject();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	ex.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                	s_logger.info("PermissionDenied: " + t.getMessage() + "uuid: " + id.getValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                	s_logger.info("PermissionDenied: " + t.getMessage());
 | 
			
		||||
                }
 | 
			
		||||
                throw ex;
 | 
			
		||||
            } else if (t instanceof AccountLimitException) {
 | 
			
		||||
                s_logger.info(t.getMessage());
 | 
			
		||||
                throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
 | 
			
		||||
            	AccountLimitException ref = (AccountLimitException)t;
 | 
			
		||||
            	ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getProxyObject();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	ex.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                	s_logger.info(t.getMessage() + "uuid: " + id.getValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                	s_logger.info(t.getMessage());
 | 
			
		||||
                }
 | 
			
		||||
                throw ex;
 | 
			
		||||
            } else if (t instanceof InsufficientCapacityException) {
 | 
			
		||||
                s_logger.info(t.getMessage());
 | 
			
		||||
                throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
 | 
			
		||||
            	InsufficientCapacityException ref = (InsufficientCapacityException)t;
 | 
			
		||||
            	ServerApiException ex = new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getIdProxy();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	ex.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                	s_logger.info(t.getMessage() + "uuid: " + id.getValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                	s_logger.info(t.getMessage());
 | 
			
		||||
                }
 | 
			
		||||
                throw ex;
 | 
			
		||||
            } else if (t instanceof ResourceAllocationException) {
 | 
			
		||||
                s_logger.warn("Exception: ", t);
 | 
			
		||||
                throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
 | 
			
		||||
            	ResourceAllocationException ref = (ResourceAllocationException)t;
 | 
			
		||||
                ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getIdProxy();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	ex.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                	s_logger.warn("Exception: " + t.getMessage() + "uuid: " + ref.getIdProxy().getValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                	s_logger.warn("Exception: ", t);
 | 
			
		||||
                }
 | 
			
		||||
                throw ex;
 | 
			
		||||
            } else if (t instanceof ResourceUnavailableException) {
 | 
			
		||||
                s_logger.warn("Exception: ", t);
 | 
			
		||||
                throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
 | 
			
		||||
            	ResourceUnavailableException ref = (ResourceUnavailableException)t;
 | 
			
		||||
                ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getIdProxy();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	ex.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                	s_logger.warn("Exception: " + t.getMessage() + "uuid: " + ref.getIdProxy().getValue());
 | 
			
		||||
                } else {
 | 
			
		||||
                	s_logger.warn("Exception: ", t);
 | 
			
		||||
                }
 | 
			
		||||
                throw ex;
 | 
			
		||||
            } else if (t instanceof AsyncCommandQueued) {
 | 
			
		||||
                throw (AsyncCommandQueued) t;
 | 
			
		||||
            } else if (t instanceof ServerApiException) {
 | 
			
		||||
 | 
			
		||||
@ -106,6 +106,7 @@ import com.cloud.user.DomainManager;
 | 
			
		||||
import com.cloud.user.User;
 | 
			
		||||
import com.cloud.user.UserAccount;
 | 
			
		||||
import com.cloud.user.UserContext;
 | 
			
		||||
import com.cloud.utils.IdentityProxy;
 | 
			
		||||
import com.cloud.utils.Pair;
 | 
			
		||||
import com.cloud.utils.PropertiesUtil;
 | 
			
		||||
import com.cloud.utils.component.ComponentLocator;
 | 
			
		||||
@ -427,9 +428,23 @@ public class ApiServer implements HttpRequestHandler {
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            if (ex instanceof InvalidParameterValueException) {
 | 
			
		||||
                throw new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
 | 
			
		||||
            	InvalidParameterValueException ref = (InvalidParameterValueException)ex;
 | 
			
		||||
            	ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getProxyObject();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	e.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                }
 | 
			
		||||
                throw e;
 | 
			
		||||
            } else if (ex instanceof PermissionDeniedException) {
 | 
			
		||||
                throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, ex.getMessage());
 | 
			
		||||
            	PermissionDeniedException ref = (PermissionDeniedException)ex;
 | 
			
		||||
            	ServerApiException e = new ServerApiException(BaseCmd.ACCOUNT_ERROR, ex.getMessage());
 | 
			
		||||
                // copy over the IdentityProxy information as well and throw the serverapiexception.
 | 
			
		||||
                IdentityProxy id = ref.getProxyObject();
 | 
			
		||||
                if (id != null) {
 | 
			
		||||
                	e.setProxyObject(id.getTableName(), id.getValue());
 | 
			
		||||
                }
 | 
			
		||||
                throw e;
 | 
			
		||||
            } else if (ex instanceof ServerApiException) {
 | 
			
		||||
                throw (ServerApiException) ex;
 | 
			
		||||
            } else {
 | 
			
		||||
 | 
			
		||||
@ -401,10 +401,15 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
        if (addrs.size() == 0) {
 | 
			
		||||
            if (podId != null) {
 | 
			
		||||
                throw new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
 | 
			
		||||
                InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", Pod.class, podId);
 | 
			
		||||
            	// for now, we hardcode the table names, but we should ideally do a lookup for the tablename from the VO object.
 | 
			
		||||
            	ex.setProxyObject("Pod", podId);
 | 
			
		||||
            	throw ex;
 | 
			
		||||
            }
 | 
			
		||||
            s_logger.warn(errorMessage.toString());
 | 
			
		||||
            throw new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
 | 
			
		||||
            InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Insufficient address capacity", DataCenter.class, dcId);
 | 
			
		||||
            ex.setProxyObject("data_center", dcId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        assert (addrs.size() == 1) : "Return size is incorrect: " + addrs.size();
 | 
			
		||||
@ -487,7 +492,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
            owner = _accountDao.acquireInLockTable(ownerId);
 | 
			
		||||
 | 
			
		||||
            if (owner == null) {
 | 
			
		||||
                throw new ConcurrentOperationException("Unable to lock account " + ownerId);
 | 
			
		||||
            	// this ownerId comes from owner or type Account. See the class "AccountVO" and the annotations in that class
 | 
			
		||||
            	// to get the table name and field name that is queried to fill this ownerid.
 | 
			
		||||
            	ConcurrentOperationException ex = new ConcurrentOperationException("Unable to lock account");
 | 
			
		||||
            	ex.setProxyObject("account", ownerId);
 | 
			
		||||
            	throw ex;
 | 
			
		||||
            }
 | 
			
		||||
            if (s_logger.isDebugEnabled()) {
 | 
			
		||||
                s_logger.debug("lock account " + ownerId + " is acquired");
 | 
			
		||||
@ -567,14 +576,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
            // The admin is making the call, determine if it is for someone else or for himself
 | 
			
		||||
            if (domainId != null) {
 | 
			
		||||
                if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
 | 
			
		||||
                    throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, , permission denied");
 | 
			
		||||
                    PermissionDeniedException ex = new PermissionDeniedException("Invalid domain id given, permission denied");
 | 
			
		||||
                    ex.setProxyObject("domain", domainId);
 | 
			
		||||
                    throw ex;
 | 
			
		||||
                }
 | 
			
		||||
                if (accountName != null) {
 | 
			
		||||
                    Account userAccount = _accountMgr.getActiveAccountByName(accountName, domainId);
 | 
			
		||||
                    if (userAccount != null) {
 | 
			
		||||
                        account = userAccount;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        throw new PermissionDeniedException("Unable to find account " + accountName + " in domain " + domainId + ", permission denied");
 | 
			
		||||
                    	PermissionDeniedException ex = new PermissionDeniedException("Unable to find account " + accountName + " in specified domain, permission denied");
 | 
			
		||||
                    	ex.setProxyObject("domain", domainId);
 | 
			
		||||
                    	throw ex;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
@ -667,7 +680,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
                        services.add(Service.SourceNat);
 | 
			
		||||
                        networkSNAT.add(ip.getAssociatedWithNetworkId());
 | 
			
		||||
                    } else {
 | 
			
		||||
                        throw new CloudRuntimeException("Multiply generic source NAT IPs provided for network " + ip.getAssociatedWithNetworkId());
 | 
			
		||||
                    	CloudRuntimeException ex = new CloudRuntimeException("Multiple generic soure NAT IPs provided for network");
 | 
			
		||||
                    	// see the IPAddressVO.java class.
 | 
			
		||||
                    	ex.setProxyObject("user_ip_address", ip.getAssociatedWithNetworkId());
 | 
			
		||||
                    	throw ex;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                ipToServices.put(ip, services);
 | 
			
		||||
@ -953,7 +969,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        long ownerId = ipOwner.getId();
 | 
			
		||||
        Network network = _networksDao.findById(networkId);
 | 
			
		||||
        if (network == null) {
 | 
			
		||||
            throw new InvalidParameterValueException("Network id is invalid: " + networkId);
 | 
			
		||||
            InvalidParameterValueException ex = new InvalidParameterValueException("Network id is invalid");
 | 
			
		||||
            ex.setProxyObject("networks", networkId);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // check permissions
 | 
			
		||||
@ -984,7 +1001,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        boolean assign = false;
 | 
			
		||||
 | 
			
		||||
        if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
 | 
			
		||||
            throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getId());
 | 
			
		||||
            // zone is of type DataCenter. See DataCenterVO.java.
 | 
			
		||||
            PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled");
 | 
			
		||||
            ex.setProxyObject("data_center", zone.getId());
 | 
			
		||||
            throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        PublicIp ip = null;
 | 
			
		||||
@ -1028,7 +1048,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
            ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, network.getId(), isSourceNat, assign, null, isSystem);
 | 
			
		||||
 | 
			
		||||
            if (ip == null) {
 | 
			
		||||
                throw new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId());
 | 
			
		||||
            	InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zone.getId());
 | 
			
		||||
            	ex.setProxyObject("data_center", zone.getId());
 | 
			
		||||
            	throw ex;
 | 
			
		||||
            }
 | 
			
		||||
            UserContext.current().setEventDetails("Ip Id: " + ip.getId());
 | 
			
		||||
            Ip ipAddress = ip.getAddress();
 | 
			
		||||
@ -1439,7 +1461,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (networks.size() < 1) {
 | 
			
		||||
                throw new CloudRuntimeException("Unable to convert network offering to network profile: " + offering.getId());
 | 
			
		||||
            	// see networkOfferingVO.java
 | 
			
		||||
            	CloudRuntimeException ex = new CloudRuntimeException("Unable to convert network offering to network profile");
 | 
			
		||||
            	ex.setProxyObject("network_offerings", offering.getId());
 | 
			
		||||
            	throw ex;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return networks;
 | 
			
		||||
@ -1641,7 +1666,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
        NetworkVO network = _networksDao.acquireInLockTable(networkId, _networkLockTimeout);
 | 
			
		||||
        if (network == null) {
 | 
			
		||||
            throw new ConcurrentOperationException("Unable to acquire network configuration: " + networkId);
 | 
			
		||||
        	// see NetworkVO.java
 | 
			
		||||
        	ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
 | 
			
		||||
        	ex.setProxyObject("networks", networkId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
@ -1715,7 +1743,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        for (NetworkElement element : _networkElements) {
 | 
			
		||||
            if (providersToImplement.contains(element.getProvider())) {
 | 
			
		||||
                if (!isProviderEnabledInPhysicalNetwork(getPhysicalNetworkId(network), "VirtualRouter")) {
 | 
			
		||||
                    throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or not enabled in physical network id=" + network.getPhysicalNetworkId());
 | 
			
		||||
                	// see NetworkVO.java. 
 | 
			
		||||
                	CloudRuntimeException ex = new CloudRuntimeException("Service provider " + element.getProvider().getName() + "either doesn't exist or is not enabled in specified physical network id");
 | 
			
		||||
                	ex.setProxyObject("networks", network.getPhysicalNetworkId());
 | 
			
		||||
                }
 | 
			
		||||
                if (s_logger.isDebugEnabled()) {
 | 
			
		||||
                    s_logger.debug("Asking " + element.getName() + " to implemenet " + network);
 | 
			
		||||
@ -1730,7 +1760,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        s_logger.debug("Reprogramming network " + network + " as a part of network implement");
 | 
			
		||||
        if (!reprogramNetworkRules(network.getId(), UserContext.current().getCaller(), network)) {
 | 
			
		||||
            s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
 | 
			
		||||
            throw new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
 | 
			
		||||
            // see DataCenterVO.java
 | 
			
		||||
            ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
 | 
			
		||||
            ex.setProxyObject("data_center", network.getDataCenterId());
 | 
			
		||||
            throw ex;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -1924,7 +1957,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        // Verify input parameters
 | 
			
		||||
        IPAddressVO ipVO = _ipAddressDao.findById(ipAddressId);
 | 
			
		||||
        if (ipVO == null) {
 | 
			
		||||
            throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId);
 | 
			
		||||
        	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find ip address by id");
 | 
			
		||||
        	ex.setProxyObject("user_ip_address", ipAddressId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (ipVO.getAllocatedTime() == null) {
 | 
			
		||||
@ -1950,7 +1985,10 @@ 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) {
 | 
			
		||||
            throw new InvalidParameterValueException("Ip address id=" + ipAddressId + " belongs to Account wide IP pool and cannot be disassociated");
 | 
			
		||||
        	//see IPaddressVO.java
 | 
			
		||||
        	InvalidParameterValueException ex = new InvalidParameterValueException("Sepcified IP address uuid belongs to Account wide IP pool and cannot be disassociated");
 | 
			
		||||
        	ex.setProxyObject("user_ip_address", ipAddressId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // don't allow releasing system ip address
 | 
			
		||||
@ -1994,9 +2032,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
    public String getNextAvailableMacAddressInNetwork(long networkId) throws InsufficientAddressCapacityException {
 | 
			
		||||
        String mac = _networksDao.getNextAvailableMacAddress(networkId);
 | 
			
		||||
        if (mac == null) {
 | 
			
		||||
            throw new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId);
 | 
			
		||||
        	InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException("Unable to create another mac address", Network.class, networkId);
 | 
			
		||||
        	ex.setProxyObject("networks", networkId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return mac;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -2091,7 +2130,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
            String cidrSubnet = NetUtils.getCidrSubNet(currCidrAddress, cidrSizeToUse);
 | 
			
		||||
 | 
			
		||||
            if (cidrSubnet.equals(ntwkCidrSubnet)) {
 | 
			
		||||
                throw new InvalidParameterValueException("Warning: The existing network " + networkId + " have conflict CIDR subnets with new network!");
 | 
			
		||||
            	InvalidParameterValueException ex = new InvalidParameterValueException("Warning: The specified existing network has conflict CIDR subnets with new network!");
 | 
			
		||||
            	ex.setProxyObject("networks", networkId);
 | 
			
		||||
            	throw ex;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -2121,7 +2162,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        // Validate network offering
 | 
			
		||||
        NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
 | 
			
		||||
        if (networkOffering == null || networkOffering.isSystemOnly()) {
 | 
			
		||||
            throw new InvalidParameterValueException("Unable to find network offeirng by id " + networkOfferingId);
 | 
			
		||||
        	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find network offering by specified id");
 | 
			
		||||
        	ex.setProxyObject("network_offerings", networkOfferingId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
        // validate physical network and zone
 | 
			
		||||
        // Check if physical network exists
 | 
			
		||||
@ -2129,7 +2172,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        if (physicalNetworkId != null) {
 | 
			
		||||
            pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
 | 
			
		||||
            if (pNtwk == null) {
 | 
			
		||||
                throw new InvalidParameterValueException("Unable to find physical network by id " + physicalNetworkId);
 | 
			
		||||
            	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a physical network having the given id");
 | 
			
		||||
            	ex.setProxyObject("physical_network", physicalNetworkId);
 | 
			
		||||
            	throw ex;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -2139,7 +2184,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
        DataCenter zone = _dcDao.findById(zoneId);
 | 
			
		||||
        if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
 | 
			
		||||
            throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getId());
 | 
			
		||||
        	// See DataCenterVO.java
 | 
			
		||||
        	PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation since specified Zone is currently disabled");
 | 
			
		||||
        	ex.setProxyObject("data_center", zone.getId());
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Only domain and account ACL types are supported in Acton.
 | 
			
		||||
@ -2194,7 +2242,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
                DomainVO domain = _domainDao.findById(domainId);
 | 
			
		||||
                if (domain == null) {
 | 
			
		||||
                    throw new InvalidParameterValueException("Unable to find domain by id " + domainId);
 | 
			
		||||
                	// see DomainVO.java
 | 
			
		||||
                	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain by specified if");
 | 
			
		||||
                	ex.setProxyObject("domain", domainId);
 | 
			
		||||
                	throw ex;
 | 
			
		||||
                }
 | 
			
		||||
                _accountMgr.checkAccess(caller, domain);
 | 
			
		||||
            }
 | 
			
		||||
@ -2330,12 +2381,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
        // Validate network offering
 | 
			
		||||
        if (networkOffering.getState() != NetworkOffering.State.Enabled) {
 | 
			
		||||
            throw new InvalidParameterValueException("Can't use network offering id=" + networkOfferingId + " as its state is not " + 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.setProxyObject("network_offerings", networkOfferingId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Validate physical network
 | 
			
		||||
        if (pNtwk.getState() != PhysicalNetwork.State.Enabled) {
 | 
			
		||||
            throw new InvalidParameterValueException("Physical network id " + pNtwk.getId() + " is in incorrect state: " + pNtwk.getState());
 | 
			
		||||
        	// see PhysicalNetworkVO.java
 | 
			
		||||
        	InvalidParameterValueException ex = new InvalidParameterValueException("Specified physical network id is in incorrect state:" + pNtwk.getState());
 | 
			
		||||
        	ex.setProxyObject("physical_network", pNtwk.getId());
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Validate zone
 | 
			
		||||
@ -2546,14 +2603,20 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        if (domainId != null) {
 | 
			
		||||
            DomainVO domain = _domainDao.findById(domainId);
 | 
			
		||||
            if (domain == null) {
 | 
			
		||||
                throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist in the system");
 | 
			
		||||
            	// see DomainVO.java
 | 
			
		||||
            	InvalidParameterValueException ex = new InvalidParameterValueException("Specified domain id doesn't exist in the system");
 | 
			
		||||
            	ex.setProxyObject("domain", domainId);
 | 
			
		||||
            	throw ex;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            _accountMgr.checkAccess(caller, domain);
 | 
			
		||||
            if (accountName != null) {
 | 
			
		||||
                Account owner = _accountMgr.getActiveAccountByName(accountName, domainId);
 | 
			
		||||
                if (owner == null) {
 | 
			
		||||
                    throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
 | 
			
		||||
                	// see DomainVO.java
 | 
			
		||||
                	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account " + accountName + " in specified domain");
 | 
			
		||||
                	ex.setProxyObject("domain", domainId);
 | 
			
		||||
                	throw ex;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                _accountMgr.checkAccess(caller, null, true, owner);
 | 
			
		||||
@ -2579,10 +2642,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
                permittedAccounts.clear();
 | 
			
		||||
                Project project = _projectMgr.getProject(projectId);
 | 
			
		||||
                if (project == null) {
 | 
			
		||||
                    throw new InvalidParameterValueException("Unable to find project by id " + projectId);
 | 
			
		||||
                	// see ProjectVO.java
 | 
			
		||||
                	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project by specified id");
 | 
			
		||||
                	ex.setProxyObject("projects", projectId);
 | 
			
		||||
                	throw ex;
 | 
			
		||||
                }
 | 
			
		||||
                if (!_projectMgr.canAccessProjectAccount(caller, project.getProjectAccountId())) {
 | 
			
		||||
                    throw new InvalidParameterValueException("Account " + caller + " can't access project id=" + projectId);
 | 
			
		||||
                	// see ProjectVO.java
 | 
			
		||||
                	InvalidParameterValueException ex = new InvalidParameterValueException("Account " + caller + " cannot access specified project id");
 | 
			
		||||
                	ex.setProxyObject("projects", projectId);
 | 
			
		||||
                	throw ex;
 | 
			
		||||
                }
 | 
			
		||||
                permittedAccounts.add(project.getProjectAccountId());
 | 
			
		||||
            }
 | 
			
		||||
@ -2786,6 +2855,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        // Verify network id
 | 
			
		||||
        NetworkVO network = _networksDao.findById(networkId);
 | 
			
		||||
        if (network == null) {
 | 
			
		||||
        	// see NetworkVO.java
 | 
			
		||||
        	
 | 
			
		||||
            throw new InvalidParameterValueException("unable to find network " + networkId);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -3183,8 +3254,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
 | 
			
		||||
        // Check if network exists
 | 
			
		||||
        NetworkVO network = _networksDao.findById(networkId);
 | 
			
		||||
        if (network == null) {
 | 
			
		||||
            throw new InvalidParameterValueException("Network with id=" + networkId + " doesn't exist");
 | 
			
		||||
        if (network == null) {        	
 | 
			
		||||
            InvalidParameterValueException ex = new InvalidParameterValueException("Network with specified id doesn't exist");
 | 
			
		||||
            ex.setProxyObject("networks", networkId);
 | 
			
		||||
            throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Don't allow to restart network if it's not in Implemented/Setup state
 | 
			
		||||
@ -3867,7 +3940,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
 | 
			
		||||
        // verify input parameters
 | 
			
		||||
        NetworkVO network = _networksDao.findById(networkId);
 | 
			
		||||
        if (network == null) {
 | 
			
		||||
            throw new InvalidParameterValueException("Network id=" + networkId + "doesn't exist in the system");
 | 
			
		||||
        	// see NetworkVO.java
 | 
			
		||||
            //throw new InvalidParameterValueException("Network id=" + networkId + "doesn't exist in the system");
 | 
			
		||||
        	InvalidParameterValueException ex = new InvalidParameterValueException("Specified network id doesn't exist in the system");
 | 
			
		||||
        	ex.setProxyObject("networks", networkId);
 | 
			
		||||
        	throw ex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // don't allow to update network in Destroy state
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,7 @@ import com.cloud.utils.SerialVersionUID;
 | 
			
		||||
 * wrap exceptions that you know there's no point in dealing with.
 | 
			
		||||
 * This will be filled in more later as needed.
 | 
			
		||||
 */
 | 
			
		||||
public class CloudRuntimeException extends RuntimeException {
 | 
			
		||||
public class CloudRuntimeException extends RuntimeCloudException {
 | 
			
		||||
 | 
			
		||||
    private static final long serialVersionUID = SerialVersionUID.CloudRuntimeException;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
@ -30,7 +30,7 @@ import com.cloud.utils.IdentityProxy;
 | 
			
		||||
 | 
			
		||||
public class RuntimeCloudException extends RuntimeException {
 | 
			
		||||
    
 | 
			
		||||
	IdentityProxy id;
 | 
			
		||||
	protected IdentityProxy id;
 | 
			
		||||
	
 | 
			
		||||
	public RuntimeCloudException(String table_name, Long id) {
 | 
			
		||||
		this.id = new IdentityProxy();
 | 
			
		||||
@ -51,5 +51,15 @@ public class RuntimeCloudException extends RuntimeException {
 | 
			
		||||
		//this.id = NULL; ??
 | 
			
		||||
		super();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setProxyObject(String table_name, Long id) {
 | 
			
		||||
		this.id = new IdentityProxy();
 | 
			
		||||
		this.id.setTableName(table_name);
 | 
			
		||||
		this.id.setValue(id);
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public IdentityProxy getProxyObject() {
 | 
			
		||||
		return id;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user