Search in sources :

Example 61 with InsufficientCapacityException

use of com.cloud.exception.InsufficientCapacityException in project cloudstack by apache.

the class ApiServer method handleRequest.

@Override
@SuppressWarnings("rawtypes")
public String handleRequest(final Map params, final String responseType, final StringBuilder auditTrailSb) throws ServerApiException {
    checkCharacterInkParams(params);
    String response = null;
    String[] command = null;
    try {
        command = (String[]) params.get("command");
        if (command == null) {
            s_logger.error("invalid request, no command sent");
            if (s_logger.isTraceEnabled()) {
                s_logger.trace("dumping request parameters");
                for (final Object key : params.keySet()) {
                    final String keyStr = (String) key;
                    final String[] value = (String[]) params.get(key);
                    s_logger.trace("   key: " + keyStr + ", value: " + ((value == null) ? "'null'" : value[0]));
                }
            }
            throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent");
        } else {
            // Don't allow Login/Logout APIs to go past this point
            if (authManager.getAPIAuthenticator(command[0]) != null) {
                return null;
            }
            final Map<String, String> paramMap = new HashMap<String, String>();
            final Set keys = params.keySet();
            final Iterator keysIter = keys.iterator();
            while (keysIter.hasNext()) {
                final String key = (String) keysIter.next();
                if ("command".equalsIgnoreCase(key)) {
                    continue;
                }
                final String[] value = (String[]) params.get(key);
                paramMap.put(key, value[0]);
            }
            Class<?> cmdClass = getCmdClass(command[0]);
            if (cmdClass != null) {
                APICommand annotation = cmdClass.getAnnotation(APICommand.class);
                if (annotation == null) {
                    s_logger.error("No APICommand annotation found for class " + cmdClass.getCanonicalName());
                    throw new CloudRuntimeException("No APICommand annotation found for class " + cmdClass.getCanonicalName());
                }
                BaseCmd cmdObj = (BaseCmd) cmdClass.newInstance();
                cmdObj = ComponentContext.inject(cmdObj);
                cmdObj.configure();
                cmdObj.setFullUrlParams(paramMap);
                cmdObj.setResponseType(responseType);
                cmdObj.setHttpMethod(paramMap.get(ApiConstants.HTTPMETHOD).toString());
                // This is where the command is either serialized, or directly dispatched
                StringBuilder log = new StringBuilder();
                response = queueCommand(cmdObj, paramMap, log);
                buildAuditTrail(auditTrailSb, command[0], log.toString());
            } else {
                final String errorString = "Unknown API command: " + command[0];
                s_logger.warn(errorString);
                auditTrailSb.append(" " + errorString);
                throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, errorString);
            }
        }
    } catch (final InvalidParameterValueException ex) {
        s_logger.info(ex.getMessage());
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex);
    } catch (final IllegalArgumentException ex) {
        s_logger.info(ex.getMessage());
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex);
    } catch (final PermissionDeniedException ex) {
        final ArrayList<ExceptionProxyObject> idList = ex.getIdProxyList();
        if (idList != null) {
            final StringBuffer buf = new StringBuffer();
            for (final ExceptionProxyObject obj : idList) {
                buf.append(obj.getDescription());
                buf.append(":");
                buf.append(obj.getUuid());
                buf.append(" ");
            }
            s_logger.info("PermissionDenied: " + ex.getMessage() + " on objs: [" + buf.toString() + "]");
        } else {
            s_logger.info("PermissionDenied: " + ex.getMessage());
        }
        throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, ex.getMessage(), ex);
    } catch (final AccountLimitException ex) {
        s_logger.info(ex.getMessage());
        throw new ServerApiException(ApiErrorCode.ACCOUNT_RESOURCE_LIMIT_ERROR, ex.getMessage(), ex);
    } catch (final InsufficientCapacityException ex) {
        s_logger.info(ex.getMessage());
        String errorMsg = ex.getMessage();
        if (!accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())) {
            // hide internal details to non-admin user for security reason
            errorMsg = BaseCmd.USER_ERROR_MESSAGE;
        }
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, errorMsg, ex);
    } catch (final ResourceAllocationException ex) {
        s_logger.info(ex.getMessage());
        throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage(), ex);
    } catch (final ResourceUnavailableException ex) {
        s_logger.info(ex.getMessage());
        String errorMsg = ex.getMessage();
        if (!accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())) {
            // hide internal details to non-admin user for security reason
            errorMsg = BaseCmd.USER_ERROR_MESSAGE;
        }
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, errorMsg, ex);
    } catch (final ServerApiException ex) {
        s_logger.info(ex.getDescription());
        throw ex;
    } catch (final Exception ex) {
        s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command), ex);
        String errorMsg = ex.getMessage();
        if (!accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())) {
            // hide internal details to non-admin user for security reason
            errorMsg = BaseCmd.USER_ERROR_MESSAGE;
        }
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg, ex);
    }
    return response;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) APICommand(org.apache.cloudstack.api.APICommand) BaseCmd(org.apache.cloudstack.api.BaseCmd) AccountLimitException(com.cloud.exception.AccountLimitException) HttpException(org.apache.http.HttpException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InterruptedIOException(java.io.InterruptedIOException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudAuthenticationException(com.cloud.exception.CloudAuthenticationException) IOException(java.io.IOException) RequestLimitException(com.cloud.exception.RequestLimitException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ParseException(java.text.ParseException) EventBusException(org.apache.cloudstack.framework.events.EventBusException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConnectionClosedException(org.apache.http.ConnectionClosedException) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Iterator(java.util.Iterator) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ExceptionProxyObject(com.cloud.utils.exception.ExceptionProxyObject) ResponseObject(org.apache.cloudstack.api.ResponseObject) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ExceptionProxyObject(com.cloud.utils.exception.ExceptionProxyObject) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) AccountLimitException(com.cloud.exception.AccountLimitException)

Example 62 with InsufficientCapacityException

use of com.cloud.exception.InsufficientCapacityException in project cloudstack by apache.

the class CreateServiceInstanceCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        _vrouterService.startServiceInstance(getEntityId());
        ServiceInstanceResponse response = _vrouterService.createServiceInstanceResponse(getEntityId());
        response.setObjectName("serviceinstance");
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception ex) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ServiceInstanceResponse(org.apache.cloudstack.network.contrail.api.response.ServiceInstanceResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 63 with InsufficientCapacityException

use of com.cloud.exception.InsufficientCapacityException in project cloudstack by apache.

the class ContrailElementImpl method implement.

/**
     * Network add/update.
     */
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.debug("NetworkElement implement: " + network.getName() + ", traffic type: " + network.getTrafficType());
    if (network.getTrafficType() == TrafficType.Guest) {
        s_logger.debug("ignore network " + network.getName());
        return true;
    }
    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
    if (vnModel == null) {
        vnModel = new VirtualNetworkModel(network, network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
        vnModel.setProperties(_manager.getModelController(), network);
    }
    try {
        if (!vnModel.verify(_manager.getModelController())) {
            vnModel.update(_manager.getModelController());
        }
        _manager.getDatabase().getVirtualNetworks().add(vnModel);
    } catch (Exception ex) {
        s_logger.warn("virtual-network update: ", ex);
    }
    return true;
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IOException(java.io.IOException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 64 with InsufficientCapacityException

use of com.cloud.exception.InsufficientCapacityException in project cloudstack by apache.

the class ContrailElementImpl method prepare.

@Override
public boolean prepare(Network network, NicProfile nicProfile, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.debug("NetworkElement prepare: " + network.getName() + ", traffic type: " + network.getTrafficType());
    if (network.getTrafficType() == TrafficType.Guest) {
        s_logger.debug("ignore network " + network.getName());
        return true;
    }
    s_logger.debug("network: " + network.getId());
    VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
    if (vnModel == null) {
        // this may be the first time we see this network.
        return false;
    }
    VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
    if (vmModel == null) {
        VMInstanceVO vmVo = (VMInstanceVO) vm.getVirtualMachine();
        vmModel = new VirtualMachineModel(vmVo, vm.getUuid());
        vmModel.setProperties(_manager.getModelController(), vmVo);
    }
    NicVO nic = _nicDao.findById(nicProfile.getId());
    assert nic != null;
    VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
    if (vmiModel == null) {
        vmiModel = new VMInterfaceModel(nic.getUuid());
        vmiModel.addToVirtualMachine(vmModel);
        vmiModel.addToVirtualNetwork(vnModel);
    }
    try {
        vmiModel.build(_manager.getModelController(), (VMInstanceVO) vm.getVirtualMachine(), nic);
    } catch (IOException ex) {
        s_logger.warn("vm interface set", ex);
        return false;
    }
    InstanceIpModel ipModel = vmiModel.getInstanceIp();
    if (ipModel == null) {
        ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
        ipModel.addToVMInterface(vmiModel);
    }
    ipModel.setAddress(nicProfile.getIPv4Address());
    try {
        vmModel.update(_manager.getModelController());
    } catch (Exception ex) {
        s_logger.warn("virtual-machine-update", ex);
        return false;
    }
    _manager.getDatabase().getVirtualMachines().add(vmModel);
    return true;
}
Also used : VMInterfaceModel(org.apache.cloudstack.network.contrail.model.VMInterfaceModel) VirtualMachineModel(org.apache.cloudstack.network.contrail.model.VirtualMachineModel) VMInstanceVO(com.cloud.vm.VMInstanceVO) IOException(java.io.IOException) NicVO(com.cloud.vm.NicVO) InstanceIpModel(org.apache.cloudstack.network.contrail.model.InstanceIpModel) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IOException(java.io.IOException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 65 with InsufficientCapacityException

use of com.cloud.exception.InsufficientCapacityException in project cloudstack by apache.

the class DeleteSslCertCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        _certService.deleteSslCert(this);
        SuccessResponse rsp = new SuccessResponse();
        rsp.setResponseName(getCommandName());
        rsp.setObjectName("success");
        this.setResponseObject(rsp);
    } catch (Exception e) {
        throw new CloudRuntimeException(e);
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ServerApiException(org.apache.cloudstack.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Aggregations

InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)85 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)77 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)70 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)36 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)23 ServerApiException (org.apache.cloudstack.api.ServerApiException)23 Account (com.cloud.user.Account)18 ConfigurationException (javax.naming.ConfigurationException)17 ArrayList (java.util.ArrayList)15 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)14 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)14 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)12 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)11 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)11 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)10 NetworkVO (com.cloud.network.dao.NetworkVO)10 DB (com.cloud.utils.db.DB)10 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)9 Network (com.cloud.network.Network)9