use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method getScriptLocation.
private String getScriptLocation(final UploadEntity.ResourceType resourceType) {
String scriptsDir = (String) this._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.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method checkSecondaryStorageResourceLimit.
private synchronized void checkSecondaryStorageResourceLimit(final TemplateOrVolumePostUploadCommand cmd, final int contentLengthInGB) {
final String rootDir = getRootDir(cmd.getDataTo()) + File.separator;
final long accountId = cmd.getAccountId();
final long accountTemplateDirSize = 0;
final File accountTemplateDir = new File(rootDir + getTemplatePathForAccount(accountId));
if (accountTemplateDir.exists()) {
FileUtils.sizeOfDirectory(accountTemplateDir);
}
long accountVolumeDirSize = 0;
final File accountVolumeDir = new File(rootDir + getVolumePathForAccount(accountId));
if (accountVolumeDir.exists()) {
accountVolumeDirSize = FileUtils.sizeOfDirectory(accountVolumeDir);
}
long accountSnapshotDirSize = 0;
final File accountSnapshotDir = new File(rootDir + getSnapshotPathForAccount(accountId));
if (accountSnapshotDir.exists()) {
accountSnapshotDirSize = FileUtils.sizeOfDirectory(accountSnapshotDir);
}
s_logger.debug("accountTemplateDirSize: " + accountTemplateDirSize + " accountSnapshotDirSize: " + accountSnapshotDirSize + " accountVolumeDirSize: " + accountVolumeDirSize);
final int accountDirSizeInGB = getSizeInGB(accountTemplateDirSize + accountSnapshotDirSize + accountVolumeDirSize);
final int defaultMaxAccountSecondaryStorageInGB = Integer.parseInt(cmd.getDefaultMaxAccountSecondaryStorage());
if (accountDirSizeInGB + contentLengthInGB > defaultMaxAccountSecondaryStorageInGB) {
s_logger.error("accountDirSizeInGb: " + accountDirSizeInGB + " defaultMaxAccountSecondaryStorageInGB: " + defaultMaxAccountSecondaryStorageInGB + " contentLengthInGB:" + contentLengthInGB);
final String errorMessage = "Maximum number of resources of type secondary_storage for account has exceeded";
updateStateMapWithError(cmd.getEntityUUID(), errorMessage);
throw new InvalidParameterValueException(errorMessage);
}
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method createUploadEntity.
public UploadEntity createUploadEntity(String uuid, final String metadata, final long contentLength) {
final TemplateOrVolumePostUploadCommand cmd = getTemplateOrVolumePostUploadCmd(metadata);
UploadEntity uploadEntity = null;
if (cmd == null) {
final String errorMessage = "unable decode and deserialize metadata.";
updateStateMapWithError(uuid, errorMessage);
throw new InvalidParameterValueException(errorMessage);
} else {
uuid = cmd.getEntityUUID();
if (isOneTimePostUrlUsed(cmd)) {
uploadEntity = this.uploadEntityStateMap.get(uuid);
final StringBuilder errorMessage = new StringBuilder("The one time post url is already used");
if (uploadEntity != null) {
errorMessage.append(" and the upload is in ").append(uploadEntity.getUploadState()).append(" state.");
}
throw new InvalidParameterValueException(errorMessage.toString());
}
final int maxSizeInGB = Integer.parseInt(cmd.getMaxUploadSize());
final int contentLengthInGB = getSizeInGB(contentLength);
if (contentLengthInGB > maxSizeInGB) {
final String errorMessage = "Maximum file upload size exceeded. Content Length received: " + contentLengthInGB + "GB. Maximum allowed size: " + maxSizeInGB + "GB.";
updateStateMapWithError(uuid, errorMessage);
throw new InvalidParameterValueException(errorMessage);
}
checkSecondaryStorageResourceLimit(cmd, contentLengthInGB);
try {
final String absolutePath = cmd.getAbsolutePath();
uploadEntity = new UploadEntity(uuid, cmd.getEntityId(), UploadEntity.Status.IN_PROGRESS, cmd.getName(), absolutePath);
uploadEntity.setMetaDataPopulated(true);
uploadEntity.setResourceType(UploadEntity.ResourceType.valueOf(cmd.getType()));
uploadEntity.setFormat(ImageFormat.valueOf(cmd.getImageFormat()));
// relative path with out ssvm mount info.
uploadEntity.setTemplatePath(absolutePath);
final String dataStoreUrl = cmd.getDataTo();
final String installPathPrefix = getRootDir(dataStoreUrl) + File.separator + absolutePath;
uploadEntity.setInstallPathPrefix(installPathPrefix);
uploadEntity.setChksum(cmd.getChecksum());
uploadEntity.setMaxSizeInGB(maxSizeInGB);
uploadEntity.setDescription(cmd.getDescription());
uploadEntity.setContentLength(contentLength);
// create a install dir
if (!this._storage.exists(installPathPrefix)) {
this._storage.mkdir(installPathPrefix);
}
this.uploadEntityStateMap.put(uuid, uploadEntity);
} catch (final Exception e) {
// upload entity will be null incase an exception occurs and the handler will not proceed.
s_logger.error("exception occurred while creating upload entity ", e);
updateStateMapWithError(uuid, e.getMessage());
}
}
return uploadEntity;
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class MigrateSystemVMCmd method execute.
@Override
public void execute() {
final Host destinationHost = _resourceService.getHost(getHostId());
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
}
try {
CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
// FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
final VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
if (migratedVm != null) {
// return the generic system VM instance response
final SystemVmResponse response = _responseGenerator.createSystemVmResponse(migratedVm);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate the system vm");
}
} catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (final ConcurrentOperationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (final ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (final VirtualMachineMigrationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.
the class ScaleSystemVMCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("SystemVm Id: " + getId());
final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
VirtualMachine result = null;
try {
result = _mgr.upgradeSystemVM(this);
} catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (final ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (final ManagementServerException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (final VirtualMachineMigrationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
if (result != null) {
final SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade system vm");
}
}
Aggregations