Search in sources :

Example 36 with InvalidParameterValueException

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

the class NfsSecondaryStorageResource method validatePostUploadRequest.

public void validatePostUploadRequest(final String signature, final String metadata, final String timeout, final String hostname, final long contentLength, final String uuid) throws InvalidParameterValueException {
    // check none of the params are empty
    if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(metadata) || StringUtils.isEmpty(timeout)) {
        updateStateMapWithError(uuid, "signature, metadata and expires are compulsory fields.");
        throw new InvalidParameterValueException("signature, metadata and expires are compulsory fields.");
    }
    // check that contentLength exists and is greater than zero
    if (contentLength <= 0) {
        throw new InvalidParameterValueException("content length is not set in the request or has invalid value.");
    }
    // validate signature
    final String fullUrl = "https://" + hostname + "/upload/" + uuid;
    final String computedSignature = EncryptionUtil.generateSignature(metadata + fullUrl + timeout, getPostUploadPSK());
    final boolean isSignatureValid = computedSignature.equals(signature);
    if (!isSignatureValid) {
        updateStateMapWithError(uuid, "signature validation failed.");
        throw new InvalidParameterValueException("signature validation failed.");
    }
    // validate timeout
    final DateTime timeoutDateTime = DateTime.parse(timeout, ISODateTimeFormat.dateTime());
    if (timeoutDateTime.isBeforeNow()) {
        updateStateMapWithError(uuid, "request not valid anymore.");
        throw new InvalidParameterValueException("request not valid anymore.");
    }
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DateTime(org.joda.time.DateTime)

Example 37 with InvalidParameterValueException

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

the class NfsSecondaryStorageResource method getScriptLocation.

private String getScriptLocation(final UploadEntity.ResourceType resourceType) {
    String scriptsDir = (String) _params.get("template.scripts.dir");
    if (scriptsDir == null) {
        scriptsDir = "scripts/storage/secondary";
    }
    String scriptname = null;
    if (resourceType == UploadEntity.ResourceType.VOLUME) {
        scriptname = "createvolume.sh";
    } else if (resourceType == UploadEntity.ResourceType.TEMPLATE) {
        scriptname = "createtmplt.sh";
    } else {
        throw new InvalidParameterValueException("cannot find script for resource type: " + resourceType);
    }
    return Script.findScript(scriptsDir, scriptname);
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 38 with InvalidParameterValueException

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

the class AddNetworkDeviceCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final Host device = nwDeviceMgr.addNetworkDevice(this);
        final NetworkDeviceResponse response = nwDeviceMgr.getApiResponse(device);
        response.setObjectName("networkdevice");
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (final InvalidParameterValueException ipve) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage());
    } catch (final CloudRuntimeException cre) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkDeviceResponse(com.cloud.api.response.NetworkDeviceResponse) Host(com.cloud.host.Host)

Example 39 with InvalidParameterValueException

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

the class UpdateClusterCmd method execute.

@Override
public void execute() {
    final Cluster cluster = _resourceService.getCluster(getId());
    if (cluster == null) {
        throw new InvalidParameterValueException("Unable to find the cluster by id=" + getId());
    }
    final Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
    if (result != null) {
        final ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
        clusterResponse.setResponseName(getCommandName());
        this.setResponseObject(clusterResponse);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update cluster");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Cluster(com.cloud.org.Cluster) ClusterResponse(com.cloud.api.response.ClusterResponse)

Example 40 with InvalidParameterValueException

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

the class ListHostsCmd method getDetails.

public EnumSet<HostDetails> getDetails() throws InvalidParameterValueException {
    final EnumSet<HostDetails> dv;
    if (viewDetails == null || viewDetails.size() <= 0) {
        dv = EnumSet.of(HostDetails.all);
    } else {
        try {
            final ArrayList<HostDetails> dc = new ArrayList<>();
            for (final String detail : viewDetails) {
                dc.add(HostDetails.valueOf(detail));
            }
            dv = EnumSet.copyOf(dc);
        } catch (final IllegalArgumentException e) {
            throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(HostDetails.class));
        }
    }
    return dv;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) HostDetails(com.cloud.api.ApiConstants.HostDetails) ArrayList(java.util.ArrayList)

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