Search in sources :

Example 21 with ResourceAllocationException

use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.

the class GetUploadParamsForVolumeCmd method execute.

@Override
public void execute() throws ServerApiException {
    try {
        final GetUploadParamsResponse response = _volumeService.uploadVolume(this);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (MalformedURLException | ResourceAllocationException e) {
        s_logger.error("exception while uploading volume", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "exception while uploading a volume: " + e.getMessage());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ServerApiException(com.cloud.api.ServerApiException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) GetUploadParamsResponse(com.cloud.api.response.GetUploadParamsResponse)

Example 22 with ResourceAllocationException

use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.

the class AddNetworkServiceProviderCmdTest method testCreateProviderToPhysicalNetworkSuccess.

@Test
public void testCreateProviderToPhysicalNetworkSuccess() {
    final NetworkService networkService = Mockito.mock(NetworkService.class);
    addNetworkServiceProviderCmd._networkService = networkService;
    final PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito.mock(PhysicalNetworkServiceProvider.class);
    Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(physicalNetworkServiceProvider);
    try {
        addNetworkServiceProviderCmd.create();
    } catch (final ResourceAllocationException e) {
        e.printStackTrace();
    }
}
Also used : NetworkService(com.cloud.network.NetworkService) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) Test(org.junit.Test)

Example 23 with ResourceAllocationException

use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.

the class ApiServer method handleRequest.

@Override
public String handleRequest(final Map params, final String responseType, final StringBuilder auditTrailSb) throws ServerApiException {
    checkCharacterInkParams(params);
    final String response;
    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<>();
            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]);
            }
            final Class<?> cmdClass = getCmdClass(command[0]);
            if (cmdClass != null) {
                final 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
                final 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" : printCommand(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) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) EventBusException(com.cloud.framework.events.EventBusException) HttpException(org.apache.http.HttpException) AccountLimitException(com.cloud.legacymodel.exceptions.AccountLimitException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RequestLimitException(com.cloud.legacymodel.exceptions.RequestLimitException) URISyntaxException(java.net.URISyntaxException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ParseException(java.text.ParseException) CloudAuthenticationException(com.cloud.legacymodel.exceptions.CloudAuthenticationException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConnectionClosedException(org.apache.http.ConnectionClosedException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Iterator(java.util.Iterator) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ExceptionProxyObject(com.cloud.legacymodel.exceptions.ExceptionProxyObject) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) ExceptionProxyObject(com.cloud.legacymodel.exceptions.ExceptionProxyObject) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) AccountLimitException(com.cloud.legacymodel.exceptions.AccountLimitException)

Example 24 with ResourceAllocationException

use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.

the class ListStorageNetworkIpRangeCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final List<StorageNetworkIpRange> results = _storageNetworkService.listIpRange(this);
        final ListResponse<StorageNetworkIpRangeResponse> response = new ListResponse<>();
        final List<StorageNetworkIpRangeResponse> resList = new ArrayList<>(results.size());
        for (final StorageNetworkIpRange r : results) {
            final StorageNetworkIpRangeResponse resp = _responseGenerator.createStorageNetworkIpRangeResponse(r);
            resList.add(resp);
        }
        response.setResponses(resList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (final Exception e) {
        s_logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId());
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) StorageNetworkIpRange(com.cloud.legacymodel.dc.StorageNetworkIpRange) StorageNetworkIpRangeResponse(com.cloud.api.response.StorageNetworkIpRangeResponse) ArrayList(java.util.ArrayList) ServerApiException(com.cloud.api.ServerApiException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException)

Example 25 with ResourceAllocationException

use of com.cloud.legacymodel.exceptions.ResourceAllocationException in project cosmic by MissionCriticalCloud.

the class DeleteStorageNetworkIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        _storageNetworkService.deleteIpRange(this);
        final SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } catch (final Exception e) {
        s_logger.warn("Failed to delete storage network ip range " + getId(), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException) ServerApiException(com.cloud.api.ServerApiException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException)

Aggregations

ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)37 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)20 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)19 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)18 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)18 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)17 ServerApiException (com.cloud.api.ServerApiException)14 DB (com.cloud.utils.db.DB)13 Account (com.cloud.legacymodel.user.Account)11 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)8 ArrayList (java.util.ArrayList)8 ConfigurationException (javax.naming.ConfigurationException)8 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)7 TransactionStatus (com.cloud.utils.db.TransactionStatus)7 ExecutionException (java.util.concurrent.ExecutionException)6 NetworkRuleConflictException (com.cloud.legacymodel.exceptions.NetworkRuleConflictException)5 Network (com.cloud.legacymodel.network.Network)5 HypervisorType (com.cloud.model.enumeration.HypervisorType)5 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)5 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)4