Search in sources :

Example 6 with Task

use of com.xensource.xenapi.Task in project cloudstack by apache.

the class Xenserver625StorageProcessor method backupSnapshot.

protected String backupSnapshot(final Connection conn, final String primaryStorageSRUuid, final String localMountPoint, final String path, final String secondaryStorageMountPath, final String snapshotUuid, String prevBackupUuid, final String prevSnapshotUuid, final Boolean isISCSI, int wait) {
    boolean filesrcreated = false;
    if (prevBackupUuid == null) {
        prevBackupUuid = "";
    }
    SR ssSR = null;
    final String remoteDir = secondaryStorageMountPath;
    try {
        ssSR = createFileSr(conn, remoteDir, path);
        filesrcreated = true;
        final VDI snapshotvdi = VDI.getByUuid(conn, snapshotUuid);
        if (wait == 0) {
            wait = 2 * 60 * 60;
        }
        VDI dvdi = null;
        Task task = null;
        try {
            VDI previousSnapshotVdi = null;
            if (prevSnapshotUuid != null) {
                previousSnapshotVdi = VDI.getByUuid(conn, prevSnapshotUuid);
            }
            task = snapshotvdi.copyAsync(conn, ssSR, previousSnapshotVdi, null);
            // poll every 1 seconds ,
            hypervisorResource.waitForTask(conn, task, 1000, wait * 1000);
            hypervisorResource.checkForSuccess(conn, task);
            dvdi = Types.toVDI(task, conn);
        // copied = true;
        } finally {
            if (task != null) {
                try {
                    task.destroy(conn);
                } catch (final Exception e) {
                    s_logger.warn("unable to destroy task(" + task.toWireString() + ") due to " + e.toString());
                }
            }
        }
        final String result = dvdi.getUuid(conn).concat("#").concat(dvdi.getPhysicalUtilisation(conn).toString());
        return result;
    } catch (final Exception e) {
        final String msg = "Exception in backupsnapshot stage due to " + e.toString();
        s_logger.debug(msg);
        throw new CloudRuntimeException(msg, e);
    } finally {
        try {
            if (filesrcreated && ssSR != null) {
                hypervisorResource.removeSR(conn, ssSR);
            }
        } catch (final Exception e) {
            s_logger.debug("Exception in backupsnapshot cleanup stage due to " + e.toString());
        }
    }
}
Also used : Task(com.xensource.xenapi.Task) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VDI(com.xensource.xenapi.VDI) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SR(com.xensource.xenapi.SR)

Example 7 with Task

use of com.xensource.xenapi.Task in project cloudstack by apache.

the class CitrixResourceBase method rebootVM.

public void rebootVM(final Connection conn, final VM vm, final String vmName) throws Exception {
    Task task = null;
    try {
        task = vm.cleanRebootAsync(conn);
        try {
            // poll every 1 seconds , timeout after 10 minutes
            waitForTask(conn, task, 1000, 10 * 60 * 1000);
            checkForSuccess(conn, task);
        } catch (final Types.HandleInvalid e) {
            if (vm.getPowerState(conn) == VmPowerState.RUNNING) {
                task = null;
                return;
            }
            throw new CloudRuntimeException("Reboot VM catch HandleInvalid and VM is not in RUNNING state");
        }
    } catch (final XenAPIException e) {
        s_logger.debug("Unable to Clean Reboot VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString() + ", try hard reboot");
        try {
            vm.hardReboot(conn);
        } catch (final Exception e1) {
            final String msg = "Unable to hard Reboot VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString();
            s_logger.warn(msg, e1);
            throw new CloudRuntimeException(msg);
        }
    } finally {
        if (task != null) {
            try {
                task.destroy(conn);
            } catch (final Exception e1) {
                s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString());
            }
        }
    }
}
Also used : Types(com.xensource.xenapi.Types) Task(com.xensource.xenapi.Task) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 8 with Task

use of com.xensource.xenapi.Task in project cloudstack by apache.

the class CitrixResourceBase method startVM.

public void startVM(final Connection conn, final Host host, final VM vm, final String vmName) throws Exception {
    Task task = null;
    try {
        task = vm.startOnAsync(conn, host, false, true);
        try {
            // poll every 1 seconds , timeout after 10 minutes
            waitForTask(conn, task, 1000, 10 * 60 * 1000);
            checkForSuccess(conn, task);
        } catch (final Types.HandleInvalid e) {
            if (vm.getPowerState(conn) == VmPowerState.RUNNING) {
                s_logger.debug("VM " + vmName + " is in Running status");
                task = null;
                return;
            }
            throw new CloudRuntimeException("Start VM " + vmName + " catch HandleInvalid and VM is not in RUNNING state");
        } catch (final TimeoutException e) {
            if (vm.getPowerState(conn) == VmPowerState.RUNNING) {
                s_logger.debug("VM " + vmName + " is in Running status");
                task = null;
                return;
            }
            throw new CloudRuntimeException("Start VM " + vmName + " catch BadAsyncResult and VM is not in RUNNING state");
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to start VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString();
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg);
    } finally {
        if (task != null) {
            try {
                task.destroy(conn);
            } catch (final Exception e1) {
                s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString());
            }
        }
    }
}
Also used : Types(com.xensource.xenapi.Types) Task(com.xensource.xenapi.Task) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TimeoutException(java.util.concurrent.TimeoutException)

Example 9 with Task

use of com.xensource.xenapi.Task in project cloudstack by apache.

the class XenServer610MigrateVolumeCommandWrapper method execute.

@Override
public Answer execute(final MigrateVolumeCommand command, final XenServer610Resource xenServer610Resource) {
    final Connection connection = xenServer610Resource.getConnection();
    final String volumeUUID = command.getVolumePath();
    final StorageFilerTO poolTO = command.getPool();
    try {
        final String uuid = poolTO.getUuid();
        final SR destinationPool = xenServer610Resource.getStorageRepository(connection, uuid);
        final VDI srcVolume = xenServer610Resource.getVDIbyUuid(connection, volumeUUID);
        final Map<String, String> other = new HashMap<String, String>();
        other.put("live", "true");
        // Live migrate the vdi across pool.
        final Task task = srcVolume.poolMigrateAsync(connection, destinationPool, other);
        final long timeout = xenServer610Resource.getMigrateWait() * 1000L;
        xenServer610Resource.waitForTask(connection, task, 1000, timeout);
        xenServer610Resource.checkForSuccess(connection, task);
        final VDI dvdi = Types.toVDI(task, connection);
        return new MigrateVolumeAnswer(command, true, null, dvdi.getUuid(connection));
    } catch (final Exception e) {
        final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
        s_logger.error(msg, e);
        return new MigrateVolumeAnswer(command, false, msg, null);
    }
}
Also used : Task(com.xensource.xenapi.Task) HashMap(java.util.HashMap) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) SR(com.xensource.xenapi.SR)

Example 10 with Task

use of com.xensource.xenapi.Task in project cloudstack by apache.

the class CitrixResourceBase method shutdownVM.

public void shutdownVM(final Connection conn, final VM vm, final String vmName) throws XmlRpcException {
    Task task = null;
    try {
        task = vm.cleanShutdownAsync(conn);
        try {
            // poll every 1 seconds , timeout after 10 minutes
            waitForTask(conn, task, 1000, 10 * 60 * 1000);
            checkForSuccess(conn, task);
        } catch (final TimeoutException e) {
            if (vm.getPowerState(conn) == VmPowerState.HALTED) {
                task = null;
                return;
            }
            throw new CloudRuntimeException("Shutdown VM catch HandleInvalid and VM is not in HALTED state");
        }
    } catch (final XenAPIException e) {
        s_logger.debug("Unable to cleanShutdown VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString());
        try {
            VmPowerState state = vm.getPowerState(conn);
            if (state == VmPowerState.RUNNING) {
                try {
                    vm.hardShutdown(conn);
                } catch (final Exception e1) {
                    s_logger.debug("Unable to hardShutdown VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString());
                    state = vm.getPowerState(conn);
                    if (state == VmPowerState.RUNNING) {
                        forceShutdownVM(conn, vm);
                    }
                    return;
                }
            } else if (state == VmPowerState.HALTED) {
                return;
            } else {
                final String msg = "After cleanShutdown the VM status is " + state.toString() + ", that is not expected";
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
        } catch (final Exception e1) {
            final String msg = "Unable to hardShutdown VM(" + vmName + ") on host(" + _host.getUuid() + ") due to " + e.toString();
            s_logger.warn(msg, e1);
            throw new CloudRuntimeException(msg);
        }
    } finally {
        if (task != null) {
            try {
                task.destroy(conn);
            } catch (final Exception e1) {
                s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString());
            }
        }
    }
}
Also used : Task(com.xensource.xenapi.Task) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VmPowerState(com.xensource.xenapi.Types.VmPowerState) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Task (com.xensource.xenapi.Task)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 XenAPIException (com.xensource.xenapi.Types.XenAPIException)16 XmlRpcException (org.apache.xmlrpc.XmlRpcException)16 InternalErrorException (com.cloud.exception.InternalErrorException)15 VDI (com.xensource.xenapi.VDI)14 SR (com.xensource.xenapi.SR)13 Connection (com.xensource.xenapi.Connection)12 Types (com.xensource.xenapi.Types)10 TimeoutException (java.util.concurrent.TimeoutException)8 NfsTO (com.cloud.agent.api.to.NfsTO)7 IOException (java.io.IOException)7 MalformedURLException (java.net.MalformedURLException)7 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 HashMap (java.util.HashMap)7 ConfigurationException (javax.naming.ConfigurationException)7 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)7 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)7 SAXException (org.xml.sax.SAXException)7