Search in sources :

Example 91 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class DeleteNiciraNvpDeviceCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final boolean result = niciraNvpElementService.deleteNiciraNvpDevice(this);
        if (result) {
            final SuccessResponse response = new SuccessResponse(getCommandName());
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Nicira device.");
        }
    } catch (final InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (final CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 92 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ListNiciraNvpDevicesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
    try {
        final List<NiciraNvpDeviceVO> niciraDevices = niciraNvpElementService.listNiciraNvpDevices(this);
        final ListResponse<NiciraNvpDeviceResponse> response = new ListResponse<>();
        final List<NiciraNvpDeviceResponse> niciraDevicesResponse = new ArrayList<>();
        if (niciraDevices != null && !niciraDevices.isEmpty()) {
            for (final NiciraNvpDeviceVO niciraDeviceVO : niciraDevices) {
                final NiciraNvpDeviceResponse niciraDeviceResponse = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraDeviceVO);
                niciraDevicesResponse.add(niciraDeviceResponse);
            }
        }
        response.setResponses(niciraDevicesResponse);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (final InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (final CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) NiciraNvpDeviceResponse(com.cloud.api.response.NiciraNvpDeviceResponse)

Example 93 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class CloudStackImageStoreLifeCycleImpl method initialize.

@Override
public DataStore initialize(final Map<String, Object> dsInfos) {
    final Long dcId = (Long) dsInfos.get("zoneId");
    final String url = (String) dsInfos.get("url");
    String name = (String) dsInfos.get("name");
    if (name == null) {
        name = url;
    }
    final String providerName = (String) dsInfos.get("providerName");
    final DataStoreRole role = (DataStoreRole) dsInfos.get("role");
    final Map<String, String> details = (Map<String, String>) dsInfos.get("details");
    String logString = "";
    if (url.contains("cifs")) {
        logString = cleanPassword(url);
    } else {
        logString = StringUtils.cleanString(url);
    }
    s_logger.info("Trying to add a new data store at " + logString + " to data center " + dcId);
    URI uri = null;
    try {
        uri = new URI(UriUtils.encodeURIComponent(url));
        if (uri.getScheme() == null) {
            throw new InvalidParameterValueException("uri.scheme is null " + StringUtils.cleanString(url) + ", add nfs:// (or cifs://) as a prefix");
        } else if (uri.getScheme().equalsIgnoreCase("nfs")) {
            if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
                throw new InvalidParameterValueException("Your host and/or path is wrong.  Make sure it's of the format nfs://hostname/path");
            }
        } else if (uri.getScheme().equalsIgnoreCase("cifs")) {
            // Don't validate against a URI encoded URI.
            final URI cifsUri = new URI(url);
            final String warnMsg = UriUtils.getCifsUriParametersProblems(cifsUri);
            if (warnMsg != null) {
                throw new InvalidParameterValueException(warnMsg);
            }
        }
    } catch (final URISyntaxException e) {
        throw new InvalidParameterValueException(url + " is not a valid uri");
    }
    if (dcId == null) {
        throw new InvalidParameterValueException("DataCenter id is null, and cloudstack default image store has to be associated with a data center");
    }
    final Map<String, Object> imageStoreParameters = new HashMap<>();
    imageStoreParameters.put("name", name);
    imageStoreParameters.put("zoneId", dcId);
    imageStoreParameters.put("url", url);
    imageStoreParameters.put("protocol", uri.getScheme().toLowerCase());
    // default cloudstack provider only supports zone-wide image store
    imageStoreParameters.put("scope", ScopeType.ZONE);
    imageStoreParameters.put("providerName", providerName);
    imageStoreParameters.put("role", role);
    final ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters, details);
    return imageStoreMgr.getImageStore(ids.getId());
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI)

Example 94 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class AffinityGroupServiceImpl method createAffinityGroup.

@DB
@Override
public AffinityGroup createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType, final String description) {
    // validate the affinityGroupType
    final Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
    if (typeProcessorMap == null || typeProcessorMap.isEmpty()) {
        throw new InvalidParameterValueException("Unable to create affinity group, no Affinity Group Types configured");
    }
    final AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
    if (processor == null) {
        throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type" + affinityGroupType);
    }
    final Account caller = CallContext.current().getCallingAccount();
    if (processor.isAdminControlledGroup() && !_accountMgr.isRootAdmin(caller.getId())) {
        throw new PermissionDeniedException("Cannot create the affinity group");
    }
    final ControlledEntity.ACLType aclType;
    final Account owner;
    boolean domainLevel = false;
    if (projectId == null && domainId != null && accountName == null) {
        verifyAccessToDomainWideProcessor(caller, processor);
        final DomainVO domain = getDomain(domainId);
        _accountMgr.checkAccess(caller, domain);
        // domain level group, owner is SYSTEM.
        owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
        aclType = ControlledEntity.ACLType.Domain;
        domainLevel = true;
    } else {
        owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
        aclType = ControlledEntity.ACLType.Account;
    }
    verifyAffinityGroupNameInUse(owner.getAccountId(), owner.getDomainId(), affinityGroupName);
    verifyDomainLevelAffinityGroupName(domainLevel, owner.getDomainId(), affinityGroupName);
    final AffinityGroupVO group = createAffinityGroup(processor, owner, aclType, affinityGroupName, affinityGroupType, description, domainLevel, domainId);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Created affinity group =" + affinityGroupName);
    }
    return group;
}
Also used : Account(com.cloud.user.Account) DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ControlledEntity(com.cloud.acl.ControlledEntity) ACLType(com.cloud.acl.ControlledEntity.ACLType) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) DB(com.cloud.utils.db.DB)

Example 95 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method releasePublicIpRange.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_RELEASE, eventDescription = "releasing a public ip range", async = false)
public boolean releasePublicIpRange(final ReleasePublicIpRangeCmd cmd) {
    final Long vlanDbId = cmd.getId();
    final VlanVO vlan = _vlanDao.findById(vlanDbId);
    if (vlan == null) {
        throw new InvalidParameterValueException("Please specify a valid IP range id.");
    }
    return releasePublicIpRange(vlanDbId, CallContext.current().getCallingUserId(), CallContext.current().getCallingAccount());
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) VlanVO(com.cloud.dc.VlanVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)478 Account (com.cloud.user.Account)199 ActionEvent (com.cloud.event.ActionEvent)151 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)146 ArrayList (java.util.ArrayList)104 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)72 List (java.util.List)61 TransactionStatus (com.cloud.utils.db.TransactionStatus)57 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)53 ServerApiException (com.cloud.api.ServerApiException)46 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)44 Network (com.cloud.network.Network)40 Pair (com.cloud.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 HostVO (com.cloud.host.HostVO)30 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30