You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by de...@apache.org on 2013/12/25 11:07:00 UTC
git commit: updated refs/heads/master to 38d6c2e
Updated Branches:
refs/heads/master 03226ba53 -> 38d6c2ea6
CLOUDSTACK-5639: Cold storage migration doesn't work for hyper-v. Made
changes to make sure CopyCommand honours requests for volume copy from
primary to secondary storage and vice versa.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/38d6c2ea
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/38d6c2ea
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/38d6c2ea
Branch: refs/heads/master
Commit: 38d6c2ea6054e6525b5a762196c6da58c69dc779
Parents: 03226ba
Author: Devdeep Singh <de...@gmail.com>
Authored: Wed Dec 25 21:58:59 2013 +0530
Committer: Devdeep Singh <de...@gmail.com>
Committed: Wed Dec 25 15:23:48 2013 +0530
----------------------------------------------------------------------
.../HypervResource/CloudStackTypes.cs | 81 ++++++++++++++++----
.../HypervResource/HypervResourceController.cs | 55 ++++++++++++-
2 files changed, 117 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/38d6c2ea/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
index eb20d7f..896a324 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs
@@ -153,14 +153,33 @@ namespace HypervResource
get
{
string fileName = null;
- if (this.primaryDataStore.isLocal)
+ if (this.primaryDataStore != null)
{
- fileName = Path.Combine(this.primaryDataStore.Path, this.name);
+ PrimaryDataStoreTO store = this.primaryDataStore;
+ if (store.isLocal)
+ {
+ fileName = Path.Combine(store.Path, this.name);
+ }
+ else
+ {
+ fileName = @"\\" + store.uri.Host + store.uri.LocalPath + @"\" + this.name;
+ fileName = Utils.NormalizePath(fileName);
+ }
+ }
+ else if (this.nfsDataStore != null)
+ {
+ fileName = this.nfsDataStore.UncPath;
+ if (this.path != null)
+ {
+ fileName += @"\" + this.path;
+ }
+ fileName = Utils.NormalizePath(fileName + @"\" + this.name);
}
else
{
- fileName = @"\\" + this.primaryDataStore.uri.Host + this.primaryDataStore.uri.LocalPath + @"\" + this.name;
- fileName = Utils.NormalizePath(fileName);
+ String errMsg = "Invalid dataStore in VolumeObjectTO spec";
+ logger.Error(errMsg);
+ throw new InvalidDataException(errMsg);
}
if (this.format != null)
@@ -175,9 +194,11 @@ namespace HypervResource
public dynamic dataStore;
public string format;
public string name;
+ public string path;
public string uuid;
public ulong size;
public PrimaryDataStoreTO primaryDataStore;
+ public NFSTO nfsDataStore;
public static VolumeObjectTO ParseJson(dynamic json)
{
@@ -196,15 +217,17 @@ namespace HypervResource
dataStore = volumeObjectTOJson.dataStore,
format = ((string)volumeObjectTOJson.format),
name = (string)volumeObjectTOJson.name,
+ path = volumeObjectTOJson.path,
uuid = (string)volumeObjectTOJson.uuid,
size = (ulong)volumeObjectTOJson.size
};
result.primaryDataStore = PrimaryDataStoreTO.ParseJson(volumeObjectTOJson.dataStore);
+ result.nfsDataStore = NFSTO.ParseJson(volumeObjectTOJson.dataStore);
// Assert
- if (result.dataStore == null || result.primaryDataStore == null)
+ if (result.dataStore == null || (result.primaryDataStore == null && result.nfsDataStore == null))
{
- String errMsg = "VolumeObjectTO missing primary dataStore in spec " + volumeObjectTOJson.ToString();
+ String errMsg = "VolumeObjectTO missing dataStore in spec " + volumeObjectTOJson.ToString();
logger.Error(errMsg);
throw new ArgumentNullException(errMsg);
}
@@ -220,22 +243,48 @@ namespace HypervResource
{
logger.Info("No image format in VolumeObjectTO, going to use format from first file that matches " + volInfo.FullFileName);
- string path = volInfo.primaryDataStore.Path;
- if (!volInfo.primaryDataStore.isLocal)
+ string path = null;
+ if (volInfo.primaryDataStore != null)
{
- path = volInfo.primaryDataStore.UncPath;
+ if (volInfo.primaryDataStore.isLocal)
+ {
+ path = volInfo.primaryDataStore.Path;
+ }
+ else
+ {
+ path = volInfo.primaryDataStore.UncPath;
+ }
}
-
- string[] choices = choices = Directory.GetFiles(path, volInfo.name + ".vhd*");
- if (choices.Length != 1)
+ else if (volInfo.nfsDataStore != null)
{
- String errMsg = "Tried to guess file extension, but cannot find file corresponding to " + Path.Combine(volInfo.primaryDataStore.Path, volInfo.name); // format being guessed.
- logger.Debug(errMsg);
+ path = volInfo.nfsDataStore.UncPath;
+ if (volInfo.path != null)
+ {
+ path += @"\" + volInfo.path;
+ }
}
else
{
- string[] splitFileName = choices[0].Split(new char[] { '.' });
- volInfo.format = splitFileName[splitFileName.Length - 1];
+ String errMsg = "VolumeObjectTO missing dataStore in spec " + volInfo.ToString();
+ logger.Error(errMsg);
+ throw new ArgumentNullException(errMsg);
+ }
+
+ path = Utils.NormalizePath(path);
+ if (Directory.Exists(path))
+ {
+ string[] choices = choices = Directory.GetFiles(path, volInfo.name + ".vhd*");
+ if (choices.Length != 1)
+ {
+ String errMsg = "Tried to guess file extension, but cannot find file corresponding to " +
+ Path.Combine(volInfo.primaryDataStore.Path, volInfo.name);
+ logger.Debug(errMsg);
+ }
+ else
+ {
+ string[] splitFileName = choices[0].Split(new char[] { '.' });
+ volInfo.format = splitFileName[splitFileName.Length - 1];
+ }
}
logger.Debug("Going to use file " + volInfo.FullFileName);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/38d6c2ea/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
index f48a6f0..35bce5d 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs
@@ -688,7 +688,6 @@ namespace HypervResource
}
// POST api/HypervResource/CheckHealthCommand
- // TODO: create test
[HttpPost]
[ActionName(CloudStackTypes.CheckHealthCommand)]
public JContainer CheckHealthCommand([FromBody]dynamic cmd)
@@ -706,6 +705,24 @@ namespace HypervResource
}
}
+ // POST api/HypervResource/CheckOnHostCommand
+ [HttpPost]
+ [ActionName(CloudStackTypes.CheckOnHostCommand)]
+ public JContainer CheckOnHostCommand([FromBody]dynamic cmd)
+ {
+ using (log4net.NDC.Push(Guid.NewGuid().ToString()))
+ {
+ logger.Info(CloudStackTypes.CheckOnHostCommand + cmd.ToString());
+ object ansContent = new
+ {
+ result = true,
+ details = "resource is alive",
+ contextMap = contextMap
+ };
+ return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.CheckOnHostAnswer);
+ }
+ }
+
// POST api/HypervResource/CheckSshCommand
// TODO: create test
[HttpPost]
@@ -1229,6 +1246,7 @@ namespace HypervResource
using (log4net.NDC.Push(Guid.NewGuid().ToString()))
{
// Log command *after* we've removed security details from the command.
+ logger.Info(CloudStackTypes.CopyCommand + cmd.ToString());
bool result = false;
string details = null;
@@ -1240,10 +1258,9 @@ namespace HypervResource
TemplateObjectTO srcTemplateObjectTO = TemplateObjectTO.ParseJson(cmd.srcTO);
TemplateObjectTO destTemplateObjectTO = TemplateObjectTO.ParseJson(cmd.destTO);
+ VolumeObjectTO srcVolumeObjectTO = VolumeObjectTO.ParseJson(cmd.srcTO);
VolumeObjectTO destVolumeObjectTO = VolumeObjectTO.ParseJson(cmd.destTO);
- logger.Info(CloudStackTypes.CopyCommand + cmd.ToString());
-
string destFile = null;
if (destTemplateObjectTO != null && destTemplateObjectTO.primaryDataStore != null)
{
@@ -1379,6 +1396,38 @@ namespace HypervResource
result = true;
}
}
+ else if (srcVolumeObjectTO != null && destVolumeObjectTO != null)
+ {
+ var guessedDestFile = destVolumeObjectTO.FullFileName;
+ if (File.Exists(guessedDestFile))
+ {
+ logger.Info("Deleting existing file " + guessedDestFile);
+ File.Delete(guessedDestFile);
+ }
+
+ destVolumeObjectTO.format = srcVolumeObjectTO.format;
+ destFile = destVolumeObjectTO.FullFileName;
+ if (File.Exists(destFile))
+ {
+ logger.Info("Deleting existing file " + destFile);
+ File.Delete(destFile);
+ }
+
+ string srcFile = srcVolumeObjectTO.FullFileName;
+ if (!File.Exists(srcFile))
+ {
+ details = "Local template file missing from " + srcFile;
+ }
+ else
+ {
+ // Create the directory before copying the files. CreateDirectory
+ // doesn't do anything if the directory is already present.
+ Directory.CreateDirectory(Path.GetDirectoryName(destFile));
+ File.Copy(srcFile, destFile);
+ newData = cmd.destTO;
+ result = true;
+ }
+ }
else
{
details = "Data store combination not supported";