Search in sources :

Example 81 with EngineException

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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpURLConnectionBuilder(org.ovirt.engine.core.uutils.net.HttpURLConnectionBuilder) EngineException(org.ovirt.engine.core.common.errors.EngineException) File(java.io.File) URL(java.net.URL) EngineException(org.ovirt.engine.core.common.errors.EngineException) GeneralSecurityException(java.security.GeneralSecurityException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

Example 82 with EngineException

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) EngineException(org.ovirt.engine.core.common.errors.EngineException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EngineException(org.ovirt.engine.core.common.errors.EngineException) GeneralSecurityException(java.security.GeneralSecurityException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

Example 83 with EngineException

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) UploadStreamParameters(org.ovirt.engine.core.bll.UploadStreamParameters)

Example 84 with EngineException

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());
    }
}
Also used : StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) EngineException(org.ovirt.engine.core.common.errors.EngineException) VmReplicateDiskParameters(org.ovirt.engine.core.common.vdscommands.VmReplicateDiskParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 85 with EngineException

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());
    }
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) VmReplicateDiskParameters(org.ovirt.engine.core.common.vdscommands.VmReplicateDiskParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

EngineException (org.ovirt.engine.core.common.errors.EngineException)107 Guid (org.ovirt.engine.core.compat.Guid)30 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)25 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)18 ArrayList (java.util.ArrayList)17 VDS (org.ovirt.engine.core.common.businessentities.VDS)11 HashMap (java.util.HashMap)7 Pair (org.ovirt.engine.core.common.utils.Pair)7 HashSet (java.util.HashSet)6 List (java.util.List)6 Callable (java.util.concurrent.Callable)6 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)6 IOException (java.io.IOException)5 EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)5 Map (java.util.Map)4 PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)4 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 Set (java.util.Set)3 VdsActionParameters (org.ovirt.engine.core.common.action.VdsActionParameters)3