Search in sources :

Example 31 with InternalErrorException

use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.

the class LibvirtPrepareForMigrationCommandWrapper method execute.

@Override
public Answer execute(final PrepareForMigrationCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final VirtualMachineTO vm = command.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    final NicTO[] nics = vm.getNics();
    boolean skipDisconnect = false;
    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    try {
        final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
        final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vm.getName());
        for (final NicTO nic : nics) {
            libvirtComputingResource.getVifDriver(nic.getType()).plug(nic, null, "");
        }
        /* setup disks, e.g for iso */
        final DiskTO[] volumes = vm.getDisks();
        for (final DiskTO volume : volumes) {
            if (volume.getType() == VolumeType.ISO) {
                libvirtComputingResource.getVolumePath(conn, volume);
            }
        }
        skipDisconnect = true;
        if (!storagePoolMgr.connectPhysicalDisksViaVmSpec(vm)) {
            return new PrepareForMigrationAnswer(command, "failed to connect physical disks to host");
        }
        return new PrepareForMigrationAnswer(command);
    } catch (final LibvirtException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } catch (final InternalErrorException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } catch (final URISyntaxException e) {
        return new PrepareForMigrationAnswer(command, e.toString());
    } finally {
        if (!skipDisconnect) {
            storagePoolMgr.disconnectPhysicalDisksViaVmSpec(vm);
        }
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) PrepareForMigrationAnswer(com.cloud.legacymodel.communication.answer.PrepareForMigrationAnswer) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) NicTO(com.cloud.legacymodel.to.NicTO) DiskTO(com.cloud.legacymodel.to.DiskTO)

Example 32 with InternalErrorException

use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.

the class ExtractTemplateCmd method execute.

@Override
public void execute() {
    try {
        CallContext.current().setEventDetails(getEventDescription());
        final String uploadUrl = _templateService.extract(this);
        if (uploadUrl != null) {
            final ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract template");
        }
    } catch (final InternalErrorException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ExtractResponse(com.cloud.api.response.ExtractResponse) ServerApiException(com.cloud.api.ServerApiException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException)

Example 33 with InternalErrorException

use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor method createVolumeFromSnapshot.

@Override
public Answer createVolumeFromSnapshot(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final DataTO srcData = cmd.getSrcTO();
    final SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
    final DataTO destData = cmd.getDestTO();
    final DataStoreTO imageStore = srcData.getDataStore();
    if (srcData.getDataStore() instanceof PrimaryDataStoreTO && destData.getDataStore() instanceof PrimaryDataStoreTO) {
        return createVolumeFromSnapshot2(cmd);
    }
    if (!(imageStore instanceof NfsTO)) {
        return new CopyCmdAnswer("unsupported protocol");
    }
    final NfsTO nfsImageStore = (NfsTO) imageStore;
    final String primaryStorageNameLabel = destData.getDataStore().getUuid();
    final String secondaryStorageUrl = nfsImageStore.getUrl();
    final int wait = cmd.getWait();
    boolean result = false;
    // Generic error message.
    String details = null;
    String volumeUUID = null;
    if (secondaryStorageUrl == null) {
        details += " because the URL passed: " + secondaryStorageUrl + " is invalid.";
        return new CopyCmdAnswer(details);
    }
    try {
        final SR primaryStorageSR = hypervisorResource.getSRByNameLabelandHost(conn, primaryStorageNameLabel);
        if (primaryStorageSR == null) {
            throw new InternalErrorException("Could not create volume from snapshot because the primary Storage SR could not be created from the name label: " + primaryStorageNameLabel);
        }
        // Get the absolute path of the snapshot on the secondary storage.
        String snapshotInstallPath = snapshot.getPath();
        final int index = snapshotInstallPath.lastIndexOf(nfsImageStore.getPathSeparator());
        final String snapshotName = snapshotInstallPath.substring(index + 1);
        if (!snapshotName.startsWith("VHD-") && !snapshotName.endsWith(".vhd")) {
            snapshotInstallPath = snapshotInstallPath + ".vhd";
        }
        final URI snapshotURI = new URI(secondaryStorageUrl + nfsImageStore.getPathSeparator() + snapshotInstallPath);
        final String snapshotPath = snapshotURI.getHost() + ":" + snapshotURI.getPath();
        final String srUuid = primaryStorageSR.getUuid(conn);
        volumeUUID = copy_vhd_from_secondarystorage(conn, snapshotPath, srUuid, wait);
        result = true;
        final VDI volume = VDI.getByUuid(conn, volumeUUID);
        final VDI.Record vdir = volume.getRecord(conn);
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(volumeUUID);
        newVol.setSize(vdir.virtualSize);
        return new CopyCmdAnswer(newVol);
    } catch (final XenAPIException e) {
        details += " due to " + e.toString();
        s_logger.warn(details, e);
    } catch (final Exception e) {
        details += " due to " + e.getMessage();
        s_logger.warn(details, e);
    }
    if (!result) {
        // Is this logged at a higher level?
        s_logger.error(details);
    }
    // In all cases return something.
    return new CopyCmdAnswer(details);
}
Also used : SnapshotObjectTO(com.cloud.legacymodel.to.SnapshotObjectTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DataTO(com.cloud.legacymodel.to.DataTO) PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) SR(com.xensource.xenapi.SR)

Example 34 with InternalErrorException

use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor method destroySnapshotOnPrimaryStorageExceptThis.

protected boolean destroySnapshotOnPrimaryStorageExceptThis(final Connection conn, final String volumeUuid, final String avoidSnapshotUuid) {
    try {
        final VDI volume = getVDIbyUuid(conn, volumeUuid);
        if (volume == null) {
            throw new InternalErrorException("Could not destroy snapshot on volume " + volumeUuid + " due to can not find it");
        }
        // To avoid deleting snapshots which are still waiting in queue to get backed up.
        final VDI avoidSnapshot = getVDIbyUuid(conn, avoidSnapshotUuid);
        if (avoidSnapshot == null) {
            throw new InternalErrorException("Could not find current snapshot " + avoidSnapshotUuid);
        }
        final Set<VDI> snapshots = volume.getSnapshots(conn);
        for (final VDI snapshot : snapshots) {
            try {
                if (!snapshot.getUuid(conn).equals(avoidSnapshotUuid) && snapshot.getSnapshotTime(conn).before(avoidSnapshot.getSnapshotTime(conn))) {
                    snapshot.destroy(conn);
                }
            } catch (final Exception e) {
                final String msg = "Destroying snapshot: " + snapshot + " on primary storage failed due to " + e.toString();
                s_logger.warn(msg, e);
            }
        }
        s_logger.debug("Successfully destroyed snapshot on volume: " + volumeUuid + " execept this current snapshot " + avoidSnapshotUuid);
        return true;
    } catch (final XenAPIException e) {
        final String msg = "Destroying snapshot on volume: " + volumeUuid + " execept this current snapshot " + avoidSnapshotUuid + " failed due to " + e.toString();
        s_logger.error(msg, e);
    } catch (final Exception e) {
        final String msg = "Destroying snapshot on volume: " + volumeUuid + " execept this current snapshot " + avoidSnapshotUuid + " failed due to " + e.toString();
        s_logger.warn(msg, e);
    }
    return false;
}
Also used : XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 35 with InternalErrorException

use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.

the class XenServerStorageProcessor method copyVolumeFromPrimaryToSecondary.

@Override
public Answer copyVolumeFromPrimaryToSecondary(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final VolumeObjectTO srcVolume = (VolumeObjectTO) cmd.getSrcTO();
    final VolumeObjectTO destVolume = (VolumeObjectTO) cmd.getDestTO();
    final int wait = cmd.getWait();
    final DataStoreTO destStore = destVolume.getDataStore();
    if (destStore instanceof NfsTO) {
        SR secondaryStorage = null;
        try {
            final NfsTO nfsStore = (NfsTO) destStore;
            final URI uri = new URI(nfsStore.getUrl());
            // Create the volume folder
            if (!hypervisorResource.createSecondaryStorageFolder(conn, uri.getHost() + ":" + uri.getPath(), destVolume.getPath())) {
                throw new InternalErrorException("Failed to create the volume folder.");
            }
            // Create a SR for the volume UUID folder
            secondaryStorage = hypervisorResource.createNfsSRbyURI(conn, new URI(nfsStore.getUrl() + nfsStore.getPathSeparator() + destVolume.getPath()), false);
            // Look up the volume on the source primary storage pool
            final VDI srcVdi = getVDIbyUuid(conn, srcVolume.getPath());
            // Copy the volume to secondary storage
            final VDI destVdi = hypervisorResource.cloudVDIcopy(conn, srcVdi, secondaryStorage, wait);
            final String destVolumeUUID = destVdi.getUuid(conn);
            final VolumeObjectTO newVol = new VolumeObjectTO();
            newVol.setPath(destVolume.getPath() + nfsStore.getPathSeparator() + destVolumeUUID + ".vhd");
            newVol.setSize(srcVolume.getSize());
            return new CopyCmdAnswer(newVol);
        } catch (final Exception e) {
            s_logger.debug("Failed to copy volume to secondary: " + e.toString());
            return new CopyCmdAnswer("Failed to copy volume to secondary: " + e.toString());
        } finally {
            hypervisorResource.removeSR(conn, secondaryStorage);
        }
    }
    return new CopyCmdAnswer("unsupported protocol");
}
Also used : PrimaryDataStoreTO(com.cloud.legacymodel.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) Connection(com.xensource.xenapi.Connection) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) NfsTO(com.cloud.legacymodel.to.NfsTO) URI(java.net.URI) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) SR(com.xensource.xenapi.SR)

Aggregations

InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)37 Connect (org.libvirt.Connect)15 LibvirtException (org.libvirt.LibvirtException)15 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)14 Answer (com.cloud.legacymodel.communication.answer.Answer)14 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)14 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)12 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)12 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)12 Test (org.junit.Test)12 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)11 TemplateFormatInfo (com.cloud.legacymodel.storage.TemplateFormatInfo)11 NicTO (com.cloud.legacymodel.to.NicTO)11 Processor (com.cloud.common.storageprocessor.Processor)10 TemplateLocation (com.cloud.common.storageprocessor.TemplateLocation)10 LibvirtVmDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef)9 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)9 URISyntaxException (java.net.URISyntaxException)9 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)8 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)8