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.");
}
}
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);
}
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());
}
}
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");
}
}
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;
}
Aggregations