use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class BaseProviderProxy method createConnection.
protected HttpURLConnection createConnection(String relativePath) {
URL hostUrl = getUrl();
HttpURLConnectionBuilder builder;
HttpURLConnection result;
try {
builder = new HttpURLConnectionBuilder().appendRelativePath(hostUrl, relativePath);
if (new File(EngineLocalConfig.getInstance().getExternalProvidersTrustStore().getAbsolutePath()).exists()) {
builder.setTrustStore(EngineLocalConfig.getInstance().getExternalProvidersTrustStore().getAbsolutePath()).setTrustStorePassword(EngineLocalConfig.getInstance().getExternalProvidersTrustStorePassword()).setTrustStoreType(EngineLocalConfig.getInstance().getExternalProvidersTrustStoreType()).setHttpsProtocol(Config.getValue(ConfigValues.ExternalCommunicationProtocol));
}
result = builder.create();
handleCredentials(result);
} catch (Exception ex) {
log.error("Cannot communicate with provider", ex);
throw new EngineException(EngineError.PROVIDER_FAILURE);
}
return result;
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class BaseProviderProxy method getResponse.
public byte[] getResponse(HttpURLConnection connection) throws IOException {
byte[] response;
ByteArrayOutputStream bytesOs = new ByteArrayOutputStream();
try (BufferedInputStream bis = new BufferedInputStream(connection.getInputStream())) {
beforeReadResponse(connection);
byte[] buff = new byte[8196];
while (true) {
int read = bis.read(buff, 0, 8196);
if (read > 0) {
bytesOs.write(buff, 0, read);
} else {
break;
}
}
response = bytesOs.toByteArray();
afterReadResponse(connection, response);
} catch (Exception ex) {
log.error("Exception is {} ", ex.getMessage());
log.debug("Exception: ", ex);
if (ex instanceof EngineException) {
throw (EngineException) ex;
} else {
throw new EngineException(EngineError.PROVIDER_FAILURE, ex.getMessage());
}
}
return response;
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStorageDomainCommand method performOvfUpdateForDomain.
private boolean performOvfUpdateForDomain(byte[] ovfData, StorageDomainOvfInfo storageDomainOvfInfo, DiskImage ovfDisk, List<Guid> vmAndTemplatesIds) {
Guid storagePoolId = ovfDisk.getStoragePoolId();
Guid storageDomainId = ovfDisk.getStorageIds().get(0);
Guid diskId = ovfDisk.getId();
Guid volumeId = ovfDisk.getImageId();
storageDomainOvfInfo.setStoredOvfIds(null);
try {
setOvfVolumeDescription(storagePoolId, storageDomainId, diskId, volumeId, generateOvfStoreDescription(storageDomainOvfInfo.getLastUpdated(), false, null));
storageDomainOvfInfoDao.update(storageDomainOvfInfo);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(ovfData);
Long size = Long.valueOf(ovfData.length);
UploadStreamParameters uploadStreamParameters = new UploadStreamParameters(storagePoolId, storageDomainId, diskId, volumeId, byteArrayInputStream, size);
uploadStreamParameters.setParentCommand(getActionType());
uploadStreamParameters.setParentParameters(getParameters());
uploadStreamParameters.setEndProcedure(EndProcedure.COMMAND_MANAGED);
ActionReturnValue actionReturnValue = runInternalActionWithTasksContext(ActionType.UploadStream, uploadStreamParameters);
if (actionReturnValue.getSucceeded()) {
storageDomainOvfInfo.setStatus(StorageDomainOvfInfoStatus.UPDATED);
storageDomainOvfInfo.setStoredOvfIds(vmAndTemplatesIds);
storageDomainOvfInfo.setLastUpdated(updateDate);
setOvfVolumeDescription(storagePoolId, storageDomainId, diskId, volumeId, getPostUpdateOvfStoreDescription(size));
storageDomainOvfInfoDao.update(storageDomainOvfInfo);
return true;
}
} catch (EngineException e) {
log.warn("failed to update domain '{}' ovf store disk '{}'", storageDomainId, diskId);
}
failedOvfDisks.add(diskId);
return false;
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class LiveMigrateDiskCommand method replicateDiskStart.
private void replicateDiskStart() {
if (Guid.Empty.equals(getParameters().getVdsId())) {
throw new EngineException(EngineError.down, "VM " + getParameters().getVmId() + " is not running on any VDS");
}
StorageType targetType = getDstStorageDomain().getStorageStaticData().getStorageType();
Optional<String> diskType = vmInfoBuildUtils.getNetworkDiskType(getVm(), targetType);
// Start disk migration
VmReplicateDiskParameters migrationStartParams = new VmReplicateDiskParameters(getParameters().getVdsId(), getParameters().getVmId(), getParameters().getStoragePoolId(), getParameters().getSourceStorageDomainId(), getParameters().getTargetStorageDomainId(), getParameters().getImageGroupID(), getParameters().getDestinationImageId(), diskType.orElse(null));
VDSReturnValue ret = resourceManager.runVdsCommand(VDSCommandType.VmReplicateDiskStart, migrationStartParams);
if (!ret.getSucceeded()) {
log.error("Failed VmReplicateDiskStart (Disk '{}' , VM '{}')", getParameters().getImageGroupID(), getParameters().getVmId());
throw new EngineException(ret.getVdsError().getCode(), ret.getVdsError().getMessage());
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class LiveMigrateDiskCommand method replicateDiskFinish.
private void replicateDiskFinish(Guid srcDomain, Guid dstDomain) {
VmReplicateDiskParameters migrationStartParams = new VmReplicateDiskParameters(getParameters().getVdsId(), getParameters().getVmId(), getParameters().getStoragePoolId(), srcDomain, dstDomain, getParameters().getImageGroupID(), getParameters().getDestinationImageId(), null);
VDSReturnValue ret = resourceManager.runVdsCommand(VDSCommandType.VmReplicateDiskFinish, migrationStartParams);
if (!ret.getSucceeded()) {
throw new EngineException(ret.getVdsError().getCode(), ret.getVdsError().getMessage());
}
}
Aggregations