Search in sources :

Example 6 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class ImportVmCommand method moveOrCopyAllImageGroups.

protected void moveOrCopyAllImageGroups(Guid containerID, Iterable<DiskImage> disks) {
    for (DiskImage disk : disks) {
        ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForDisk(disk, containerID));
        if (!vdcRetValue.getSucceeded()) {
            throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy disk!");
        }
        // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
        getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 7 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class ImportVmCommand method copyAllMemoryImages.

private void copyAllMemoryImages(Guid containerId) {
    Set<Guid> handledMemoryDisks = new HashSet<>();
    for (Snapshot snapshot : getVm().getSnapshots()) {
        if (!snapshot.containsMemory()) {
            continue;
        }
        Guid memoryDiskId = snapshot.getMemoryDiskId();
        if (!handledMemoryDisks.contains(memoryDiskId)) {
            handledMemoryDisks.add(memoryDiskId);
            // copy the memory dump image
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForMemoryDumpImage(containerId, memoryDiskDomainMap.get(memoryDiskId), memoryDiskId, getMemoryDiskImageId(memoryDiskId)));
            if (!vdcRetValue.getSucceeded()) {
                throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy memory image");
            }
            // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
            getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
        }
        Guid confDiskId = snapshot.getMetadataDiskId();
        if (!handledMemoryDisks.contains(confDiskId)) {
            handledMemoryDisks.add(confDiskId);
            // copy the memory configuration (of the VM) image
            ActionReturnValue vdcRetValue = runInternalActionWithTasksContext(ActionType.CopyImageGroup, buildMoveOrCopyImageGroupParametersForMemoryConfImage(containerId, memoryDiskDomainMap.get(confDiskId), confDiskId, getMemoryDiskImageId(confDiskId)));
            if (!vdcRetValue.getSucceeded()) {
                throw new EngineException(vdcRetValue.getFault().getError(), "Failed to copy metadata image");
            }
            // TODO: Currently REST-API doesn't support coco for async commands, remove when bug 1199011 fixed
            getTaskIdList().addAll(vdcRetValue.getVdsmTaskIdList());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet)

Example 8 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class CreateBrickCommand method runAnsibleCreateBrickPlaybook.

private void runAnsibleCreateBrickPlaybook() throws IOException, InterruptedException {
    List<String> disks = new ArrayList<>();
    Double totalSize = 0.0;
    for (StorageDevice device : getParameters().getDisks()) {
        disks.add(device.getDevPath());
        // size is returned in MiB
        totalSize += device.getSize();
    }
    if (totalSize < MIN_VG_SIZE) {
        totalSize = totalSize - MIN_METADATA_PERCENT * totalSize;
    } else {
        totalSize = totalSize - DEFAULT_METADATA_SIZE_MB;
    }
    Pair<SizeUnit, Double> convertedSize = SizeConverter.autoConvert(totalSize.longValue(), SizeUnit.MiB);
    String deviceSize = convertedSize.getSecond() + convertedSize.getFirst().toString();
    String ssdDevice = "";
    if (getParameters().getCacheDevice() != null) {
        ssdDevice = getParameters().getCacheDevice().getDevPath();
    }
    int diskCount = getParameters().getNoOfPhysicalDisksInRaidVolume() == null ? 1 : getParameters().getNoOfPhysicalDisksInRaidVolume();
    AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("ssd", ssdDevice), new Pair<>("disks", JsonHelper.objectToJson(disks, false)), new Pair<>("vgname", "RHGS_vg_" + getParameters().getLvName()), new Pair<>("size", deviceSize), new Pair<>("diskcount", diskCount), new Pair<>("stripesize", getParameters().getStripeSize()), new Pair<>("wipefs", "yes"), new Pair<>("disktype", getParameters().getRaidType().toString()), new Pair<>("lvname", getParameters().getLvName() + "_lv"), new Pair<>("cache_lvname", getParameters().getLvName() + "_cache_lv"), new Pair<>("cache_lvsize", getParameters().getCacheSize() + "GiB"), new Pair<>("cachemode", getParameters().getCacheMode()), new Pair<>("fstype", GlusterConstants.FS_TYPE_XFS), new Pair<>("mntpath", getParameters().getMountPoint())).logFileDirectory(CreateBrickCommand.CREATE_BRICK_LOG_DIRECTORY).logFilePrefix("ovirt-gluster-brick-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.CREATE_BRICK_PLAYBOOK);
    AnsibleReturnValue ansibleReturnValue = ansibleExecutor.runCommand(command);
    if (ansibleReturnValue.getAnsibleReturnCode() != AnsibleReturnCode.OK) {
        log.error("Failed to execute Ansible create brick role. Please check logs for more details: {}", command.logFile());
        throw new EngineException(EngineError.GeneralException, String.format("Failed to execute Ansible create brick role. Please check logs for more details: %1$s", command.logFile()));
    }
}
Also used : SizeUnit(org.ovirt.engine.core.common.utils.SizeConverter.SizeUnit) AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) StorageDevice(org.ovirt.engine.core.common.businessentities.gluster.StorageDevice) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 9 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class AbstractVmProviderProxy method testConnection.

@Override
public void testConnection() {
    chooseDcForCheckingIfGetNamesFromExternalProviderSupported();
    QueryReturnValue retVal = Backend.getInstance().runInternalQuery(QueryType.GetVmsFromExternalProvider, buildGetVmsFromExternalProviderQueryParameters());
    if (!retVal.getSucceeded()) {
        throw new EngineException(EngineError.PROVIDER_FAILURE, retVal.getExceptionString());
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 10 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class BaseProviderProxy method runHttpMethod.

protected byte[] runHttpMethod(HttpMethodType httpMethod, String contentType, String body, HttpURLConnection connection) {
    byte[] result = null;
    try {
        connection.setRequestProperty("Content-Type", contentType);
        connection.setDoInput(true);
        connection.setDoOutput(httpMethod != HttpMethodType.GET);
        connection.setRequestMethod(httpMethod.toString());
        if (body != null) {
            byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
            connection.setRequestProperty("Content-Length", String.valueOf(bytes.length));
            try (OutputStream outputStream = connection.getOutputStream()) {
                outputStream.write(bytes);
            }
        }
        result = getResponse(connection);
    } catch (SSLException e) {
        throw new EngineException(EngineError.PROVIDER_SSL_FAILURE, e.getMessage());
    } catch (IOException e) {
        handleException(e);
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
    return result;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) EngineException(org.ovirt.engine.core.common.errors.EngineException) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

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