Updated Branches: refs/heads/4.2-workplace d17e17a22 -> ba7f810fe
Add vdi.copyV2Async to handle new way of copy vdi Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ba7f810f Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ba7f810f Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ba7f810f Branch: refs/heads/4.2-workplace Commit: ba7f810fe6bc667cfea8e12c927ce49b792e6a15 Parents: d17e17a Author: edison su <[email protected]> Authored: Wed Dec 4 17:07:26 2013 -0800 Committer: edison su <[email protected]> Committed: Wed Dec 4 17:07:26 2013 -0800 ---------------------------------------------------------------------- .../src/com/xensource/xenapi/VDI.java | 2 +- .../xen/resource/CitrixResourceBase.java | 2 +- .../xen/resource/XenServerStorageProcessor.java | 118 ++++++++++++------- 3 files changed, 76 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ba7f810f/deps/XenServerJava/src/com/xensource/xenapi/VDI.java ---------------------------------------------------------------------- diff --git a/deps/XenServerJava/src/com/xensource/xenapi/VDI.java b/deps/XenServerJava/src/com/xensource/xenapi/VDI.java index bc2beb1..5f7b050 100644 --- a/deps/XenServerJava/src/com/xensource/xenapi/VDI.java +++ b/deps/XenServerJava/src/com/xensource/xenapi/VDI.java @@ -1614,7 +1614,7 @@ public class VDI extends XenAPIObject { return Types.toTask(result); } - public Task copyDaveAsync(Connection c, SR sr, Map<String, String> params) throws BadServerResponse, XenAPIException, XmlRpcException { + public Task copyV2Async(Connection c, SR sr, Map<String, Object> params) throws BadServerResponse, XenAPIException, XmlRpcException { String method_call = "Async.VDI.copy"; String session = c.getSessionReference(); Object[] method_params = {Marshalling.toXMLRPC(session), Marshalling.toXMLRPC(ref), Marshalling.toXMLRPC(sr), Marshalling.toXMLRPC(params)}; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ba7f810f/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 03e59df..2050225 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -3983,7 +3983,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe Map<String,String> params = new HashMap<String, String>(); params.put("base-src", snashotPaPaUuid); params.put("base-dst", prevBackupUuid); - task = snapshotvdi.copyDaveAsync(conn, ssSR, params); + //task = snapshotvdi.copyDaveAsync(conn, ssSR, params); // poll every 1 seconds , waitForTask(conn, task, 1000, wait * 1000); checkForSuccess(conn, task); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ba7f810f/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java index f5d5256..69a13ed 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageProcessor.java @@ -29,22 +29,14 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.TimeoutException; +import com.xensource.xenapi.*; import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Host; -import com.xensource.xenapi.PBD; -import com.xensource.xenapi.Pool; -import com.xensource.xenapi.SR; -import com.xensource.xenapi.Types; import com.xensource.xenapi.Types.BadServerResponse; import com.xensource.xenapi.Types.XenAPIException; -import com.xensource.xenapi.VBD; -import com.xensource.xenapi.VDI; -import com.xensource.xenapi.VM; -import com.xensource.xenapi.VMGuestMetrics; import org.apache.cloudstack.storage.command.AttachAnswer; import org.apache.cloudstack.storage.command.AttachCommand; @@ -1109,46 +1101,84 @@ public class XenServerStorageProcessor implements StorageProcessor { } - protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, String localMountPoint, String path, String secondaryStorageMountPath, String snapshotUuid, String prevBackupUuid, Boolean isISCSI, int wait) { - String backupSnapshotUuid = null; - + protected String backupSnapshot(Connection conn, String primaryStorageSRUuid, String localMountPoint, String path, String secondaryStorageMountPath, String snapshotUuid, String prevBackupUuid, String prevSnapshotUuid, Boolean isISCSI, int wait) { + String errMsg = null; + boolean mounted = false; + boolean filesrcreated = false; + boolean copied = false; if (prevBackupUuid == null) { prevBackupUuid = ""; } + SR ssSR = null; + String localDir = "/var/cloud_mount/" + UUID.randomUUID().toString(); + String remoteDir = secondaryStorageMountPath + File.separator + path; - // Each argument is put in a separate line for readability. - // Using more lines does not harm the environment. - String backupUuid = UUID.randomUUID().toString(); - String results = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-snapshot", "backupSnapshot", wait, - "primaryStorageSRUuid", primaryStorageSRUuid, "path", path, "secondaryStorageMountPath", secondaryStorageMountPath, - "snapshotUuid", snapshotUuid, "prevBackupUuid", prevBackupUuid, "backupUuid", backupUuid, "isISCSI", isISCSI.toString(), "localMountPoint", localMountPoint); - String errMsg = null; - if (results == null || results.isEmpty()) { - errMsg = "Could not copy backupUuid: " + backupSnapshotUuid - + " from primary storage " + primaryStorageSRUuid + " to secondary storage " - + secondaryStorageMountPath + " due to null"; - } else { + try { + String results = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-snapshot", "mountNfsSecondaryStorage", wait, + "localDir", localDir, "remoteDir", remoteDir); + if (results == null || results.isEmpty()) { + errMsg = "Could not mount secondary storage " + remoteDir; + s_logger.warn(errMsg); + throw new CloudRuntimeException(errMsg); + } + mounted = true; - String[] tmp = results.split("#"); - String status = tmp[0]; - backupSnapshotUuid = tmp[1]; - // status == "1" if and only if backupSnapshotUuid != null - // So we don't rely on status value but return backupSnapshotUuid as an - // indicator of success. - if (status != null && status.equalsIgnoreCase("1") && backupSnapshotUuid != null) { - s_logger.debug("Successfully copied backupUuid: " + backupSnapshotUuid - + " to secondary storage"); - return backupSnapshotUuid; - } else { - errMsg = "Could not copy backupUuid: " + backupSnapshotUuid - + " from primary storage " + primaryStorageSRUuid + " to secondary storage " - + secondaryStorageMountPath + " due to " + tmp[1]; + ssSR = hypervisorResource.createFileSR(conn, localDir, remoteDir); + filesrcreated = true; + + VDI snapshotvdi = VDI.getByUuid(conn, snapshotUuid); + Task task = null; + if (wait == 0) { + wait = 2 * 60 * 60; + } + VDI dvdi = null; + try { + Map<String,Object> params = new HashMap<String, Object>(); + if (prevSnapshotUuid != null) { + VDI previousSnapshotVdi = VDI.getByUuid(conn,prevSnapshotUuid); + params.put("base-vdi", previousSnapshotVdi); + } + task = snapshotvdi.copyV2Async(conn, ssSR, params); + // poll every 1 seconds , + hypervisorResource.waitForTask(conn, task, 1000, wait * 1000); + hypervisorResource.checkForSuccess(conn, task); + dvdi = Types.toVDI(task, conn); + copied = true; + } catch (TimeoutException e) { + throw new CloudRuntimeException(e.toString()); + } finally { + if (task != null) { + try { + task.destroy(conn); + } catch (Exception e1) { + s_logger.warn("unable to destroy task(" + task.toString() + ") on host(" + + ") due to ", e1); + } + } + } + String backupUuid = dvdi.getUuid(conn); + return backupUuid; + } catch (Exception e) { + 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) { + ssSR.forget(conn); + } + if (mounted) { + String results = hypervisorResource.callHostPluginAsync(conn, "cloud-plugin-snapshot", "umountNfsSecondaryStorage", + wait, "localDir", localDir); + if (results == null || results.isEmpty()) { + errMsg = "Could not umount secondary storage " + remoteDir + " on host "; + s_logger.debug(errMsg); + } + } + } catch (Exception e) { + s_logger.debug("Exception in backupsnapshot cleanup stage due to " + e.toString()); } } - String source = backupUuid + ".vhd"; - hypervisorResource.killCopyProcess(conn, source); - s_logger.warn(errMsg); - throw new CloudRuntimeException(errMsg); } private boolean destroySnapshotOnPrimaryStorageExceptThis(Connection conn, String volumeUuid, String avoidSnapshotUuid){ @@ -1310,7 +1340,7 @@ public class XenServerStorageProcessor implements StorageProcessor { } } else { snapshotBackupUuid = backupSnapshot(conn, primaryStorageSRUuid, localMountPoint, folder, - secondaryStorageMountPath, snapshotUuid, prevBackupUuid, isISCSI, wait); + secondaryStorageMountPath, snapshotUuid, prevBackupUuid, prevSnapshotUuid, isISCSI, wait); finalPath = folder + File.separator + snapshotBackupUuid; }
