wsp-10329 Adding hyper-v replica to HyperV Provider. Server Part 6.

This commit is contained in:
Alexander Trofimov 2015-04-22 03:38:44 -04:00
parent e8495ac0c6
commit 3a8e9e8355
7 changed files with 37 additions and 86 deletions

View file

@ -109,7 +109,7 @@ namespace WebsitePanel.Providers.Virtualization
void TestReplicationServer(string vmId, string replicaServer, string localThumbprint); void TestReplicationServer(string vmId, string replicaServer, string localThumbprint);
void StartInitialReplication(string vmId); void StartInitialReplication(string vmId);
VmReplication GetReplication(string vmId); VmReplication GetReplication(string vmId);
bool DisableVmReplication(string vmId, string replicaServer); void DisableVmReplication(string vmId);
ReplicationDetailInfo GetReplicationInfo(string vmId); ReplicationDetailInfo GetReplicationInfo(string vmId);
void PauseReplication(string vmId); void PauseReplication(string vmId);
void ResumeReplication(string vmId); void ResumeReplication(string vmId);

View file

@ -14,6 +14,7 @@ namespace WebsitePanel.Providers.Virtualization
FailedOver, FailedOver,
NotApplicable, NotApplicable,
ReadyForInitialReplication, ReadyForInitialReplication,
InitialReplicationInProgress,
Replicating, Replicating,
Resynchronizing, Resynchronizing,
ResynchronizeSuspended, ResynchronizeSuspended,

View file

@ -7,7 +7,7 @@
public string Thumbprint { get; set; } public string Thumbprint { get; set; }
[Persistent] [Persistent]
public string VhdToReplicate { get; set; } public string[] VhdToReplicate { get; set; }
[Persistent] [Persistent]
public ReplicaFrequency ReplicaFrequency { get; set; } public ReplicaFrequency ReplicaFrequency { get; set; }

View file

@ -74,6 +74,7 @@ namespace WebsitePanel.Providers.Virtualization
{ {
Command cmd = new Command("Stop-VM"); Command cmd = new Command("Stop-VM");
cmd.Parameters.Add("Name", vmName);
if (force) cmd.Parameters.Add("Force"); if (force) cmd.Parameters.Add("Force");
if (!string.IsNullOrEmpty(server)) cmd.Parameters.Add("ComputerName", server); if (!string.IsNullOrEmpty(server)) cmd.Parameters.Add("ComputerName", server);
//if (!string.IsNullOrEmpty(reason)) cmd.Parameters.Add("Reason", reason); //if (!string.IsNullOrEmpty(reason)) cmd.Parameters.Add("Reason", reason);

View file

@ -102,7 +102,7 @@ namespace WebsitePanel.Providers.Virtualization
public ReplicaMode ReplicaMode public ReplicaMode ReplicaMode
{ {
get { return (ReplicaMode) ProviderSettings.GetInt("ReplicaMode"); } get { return (ReplicaMode) Enum.Parse(typeof(ReplicaMode) , ProviderSettings["ReplicaMode"]); }
} }
protected string ReplicaServerPath protected string ReplicaServerPath
{ {
@ -780,10 +780,10 @@ namespace WebsitePanel.Providers.Virtualization
Command cmd = new Command("Get-VMSwitch"); Command cmd = new Command("Get-VMSwitch");
// Not needed as the PowerShellManager adds the computer name // Not needed as the PowerShellManager adds the computer name
//if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName); if (!string.IsNullOrEmpty(computerName)) cmd.Parameters.Add("ComputerName", computerName);
if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type); if (!string.IsNullOrEmpty(type)) cmd.Parameters.Add("SwitchType", type);
Collection<PSObject> result = PowerShell.Execute(cmd, true, true); Collection<PSObject> result = PowerShell.Execute(cmd, false, true);
foreach (PSObject current in result) foreach (PSObject current in result)
{ {
@ -2037,19 +2037,18 @@ namespace WebsitePanel.Providers.Virtualization
var excludes = vm.Disks var excludes = vm.Disks
.Select(d => d.Path) .Select(d => d.Path)
.Where(p => !p.Equals(replication.VhdToReplicate, StringComparison.OrdinalIgnoreCase)) .Where(p => replication.VhdToReplicate.All(vp => !p.Equals(vp, StringComparison.OrdinalIgnoreCase)))
.ToArray(); .ToArray();
if (excludes.Any()) if (excludes.Any())
cmd.Parameters.Add("ExcludedVhdPath", excludes); cmd.Parameters.Add("ExcludedVhdPath", excludes);
// recovery points // recovery points
cmd.Parameters.Add("RecoveryHistory", replication.AdditionalRecoveryPoints);
if (replication.AdditionalRecoveryPoints > 0) if (replication.AdditionalRecoveryPoints > 0)
{ {
if (replication.AdditionalRecoveryPoints > 24) if (replication.AdditionalRecoveryPoints > 24)
throw new Exception("AdditionalRecoveryPoints can not be greater than 24"); throw new Exception("AdditionalRecoveryPoints can not be greater than 24");
cmd.Parameters.Add("RecoveryHistory", replication.AdditionalRecoveryPoints);
if (replication.VSSSnapshotFrequencyHour > 0) if (replication.VSSSnapshotFrequencyHour > 0)
{ {
if (replication.VSSSnapshotFrequencyHour > 12) if (replication.VSSSnapshotFrequencyHour > 12)
@ -2059,10 +2058,7 @@ namespace WebsitePanel.Providers.Virtualization
} }
} }
PowerShell.Execute(cmd, true); PowerShell.Execute(cmd, true, true);
// Initial Replication
StartInitialReplication(vmId);
} }
public void SetVmReplication(string vmId, string replicaServer, VmReplication replication) public void SetVmReplication(string vmId, string replicaServer, VmReplication replication)
@ -2080,21 +2076,13 @@ namespace WebsitePanel.Providers.Virtualization
cmd.Parameters.Add("CertificateThumbprint", replication.Thumbprint); cmd.Parameters.Add("CertificateThumbprint", replication.Thumbprint);
cmd.Parameters.Add("ReplicationFrequencySec", (int)replication.ReplicaFrequency); cmd.Parameters.Add("ReplicationFrequencySec", (int)replication.ReplicaFrequency);
var excludes = vm.Disks
.Select(d => d.Path)
.Where(p => !p.Equals(replication.VhdToReplicate, StringComparison.OrdinalIgnoreCase))
.ToArray();
if (excludes.Any())
cmd.Parameters.Add("ExcludedVhdPath", excludes);
// recovery points // recovery points
cmd.Parameters.Add("RecoveryHistory", replication.AdditionalRecoveryPoints);
if (replication.AdditionalRecoveryPoints > 0) if (replication.AdditionalRecoveryPoints > 0)
{ {
if (replication.AdditionalRecoveryPoints > 24) if (replication.AdditionalRecoveryPoints > 24)
throw new Exception("AdditionalRecoveryPoints can not be greater than 24"); throw new Exception("AdditionalRecoveryPoints can not be greater than 24");
cmd.Parameters.Add("RecoveryHistory", replication.AdditionalRecoveryPoints);
if (replication.VSSSnapshotFrequencyHour > 0) if (replication.VSSSnapshotFrequencyHour > 0)
{ {
if (replication.VSSSnapshotFrequencyHour > 12) if (replication.VSSSnapshotFrequencyHour > 12)
@ -2102,6 +2090,10 @@ namespace WebsitePanel.Providers.Virtualization
cmd.Parameters.Add("VSSSnapshotFrequencyHour", replication.VSSSnapshotFrequencyHour); cmd.Parameters.Add("VSSSnapshotFrequencyHour", replication.VSSSnapshotFrequencyHour);
} }
else
{
cmd.Parameters.Add("DisableVSSSnapshotReplication");
}
} }
PowerShell.Execute(cmd, true); PowerShell.Execute(cmd, true);
@ -2163,36 +2155,21 @@ namespace WebsitePanel.Providers.Virtualization
excludes.Add(item.Path.ToString()); excludes.Add(item.Path.ToString());
replica.VhdToReplicate = vm.Disks replica.VhdToReplicate = vm.Disks
.Select(d => d.Path) .Select(d => d.Path)
.FirstOrDefault(p => excludes.All(ep => !p.Equals(ep, StringComparison.OrdinalIgnoreCase))); .Where(p => excludes.All(ep => !p.Equals(ep, StringComparison.OrdinalIgnoreCase)))
.ToArray();
} }
return replica; return replica;
} }
public bool DisableVmReplication(string vmId, string replicaServer) public void DisableVmReplication(string vmId)
{ {
if (ReplicaMode != ReplicaMode.ReplicationEnabled) if (ReplicaMode == ReplicaMode.None)
throw new Exception("Server does not allow replication by settings"); throw new Exception("Server does not allow replication by settings");
var vm = GetVirtualMachine(vmId); var vm = GetVirtualMachine(vmId);
ReplicaHelper.RemoveVmReplication(PowerShell, vm.Name, ServerNameSettings); ReplicaHelper.RemoveVmReplication(PowerShell, vm.Name, ServerNameSettings);
// move it to EnterpriseServer?
// If we have access - delete garbage from replica server
try
{
ReplicaHelper.RemoveVmReplication(PowerShell, vm.Name, replicaServer);
// Delete replica vm
VirtualMachineHelper.Stop(PowerShell, vm.Name, true, replicaServer);
VirtualMachineHelper.Delete(PowerShell, vm.Name, replicaServer);
}
catch
{
return false;
}
return true;
} }
@ -2212,13 +2189,13 @@ namespace WebsitePanel.Providers.Virtualization
if (result != null && result.Count > 0) if (result != null && result.Count > 0)
{ {
replica = new ReplicationDetailInfo(); replica = new ReplicationDetailInfo();
replica.AverageLatency = result[0].GetProperty<TimeSpan>("AverageReplicationLatency"); replica.AverageLatency = result[0].GetProperty<TimeSpan?>("AverageReplicationLatency") ?? new TimeSpan();
replica.AverageSize = result[0].GetMb("AverageReplicationSize"); replica.AverageSize = result[0].GetMb("AverageReplicationSize");
replica.Errors = result[0].GetInt("ReplicationErrors"); replica.Errors = result[0].GetInt("ReplicationErrors");
replica.FromTime = result[0].GetProperty<DateTime>("MonitoringStartTime"); replica.FromTime = result[0].GetProperty<DateTime>("MonitoringStartTime");
replica.Health = result[0].GetEnum<ReplicationHealth>("ReplicationHealth"); replica.Health = result[0].GetEnum<ReplicationHealth>("ReplicationHealth");
replica.HealthDetails = result[0].GetString("ReplicationHealthDetails"); replica.HealthDetails = string.Join(". ", result[0].GetProperty<string[]>("ReplicationHealthDetails"));
replica.LastSynhronizedAt = result[0].GetProperty<DateTime>("LastReplicationTime"); replica.LastSynhronizedAt = result[0].GetProperty<DateTime?>("LastReplicationTime") ?? new DateTime();
replica.MaximumSize = result[0].GetMb("MaximumReplicationSize"); replica.MaximumSize = result[0].GetMb("MaximumReplicationSize");
replica.Mode = result[0].GetEnum<VmReplicationMode>("ReplicationMode"); replica.Mode = result[0].GetEnum<VmReplicationMode>("ReplicationMode");
replica.PendingSize = result[0].GetMb("PendingReplicationSize"); replica.PendingSize = result[0].GetMb("PendingReplicationSize");

View file

@ -2749,45 +2749,40 @@ namespace WebsitePanel.Providers.Virtualization2012 {
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/DisableVmReplication", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/DisableVmReplication", RequestNamespace="http://smbsaas/websitepanel/server/", ResponseNamespace="http://smbsaas/websitepanel/server/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool DisableVmReplication(string vmId, string replicaServer) { public void DisableVmReplication(string vmId) {
object[] results = this.Invoke("DisableVmReplication", new object[] { this.Invoke("DisableVmReplication", new object[] {
vmId, vmId});
replicaServer});
return ((bool)(results[0]));
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginDisableVmReplication(string vmId, string replicaServer, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginDisableVmReplication(string vmId, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DisableVmReplication", new object[] { return this.BeginInvoke("DisableVmReplication", new object[] {
vmId, vmId}, callback, asyncState);
replicaServer}, callback, asyncState);
} }
/// <remarks/> /// <remarks/>
public bool EndDisableVmReplication(System.IAsyncResult asyncResult) { public void EndDisableVmReplication(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult); this.EndInvoke(asyncResult);
return ((bool)(results[0]));
} }
/// <remarks/> /// <remarks/>
public void DisableVmReplicationAsync(string vmId, string replicaServer) { public void DisableVmReplicationAsync(string vmId) {
this.DisableVmReplicationAsync(vmId, replicaServer, null); this.DisableVmReplicationAsync(vmId, null);
} }
/// <remarks/> /// <remarks/>
public void DisableVmReplicationAsync(string vmId, string replicaServer, object userState) { public void DisableVmReplicationAsync(string vmId, object userState) {
if ((this.DisableVmReplicationOperationCompleted == null)) { if ((this.DisableVmReplicationOperationCompleted == null)) {
this.DisableVmReplicationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDisableVmReplicationOperationCompleted); this.DisableVmReplicationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDisableVmReplicationOperationCompleted);
} }
this.InvokeAsync("DisableVmReplication", new object[] { this.InvokeAsync("DisableVmReplication", new object[] {
vmId, vmId}, this.DisableVmReplicationOperationCompleted, userState);
replicaServer}, this.DisableVmReplicationOperationCompleted, userState);
} }
private void OnDisableVmReplicationOperationCompleted(object arg) { private void OnDisableVmReplicationOperationCompleted(object arg) {
if ((this.DisableVmReplicationCompleted != null)) { if ((this.DisableVmReplicationCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.DisableVmReplicationCompleted(this, new DisableVmReplicationCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); this.DisableVmReplicationCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
} }
} }
@ -4179,29 +4174,7 @@ namespace WebsitePanel.Providers.Virtualization2012 {
/// <remarks/> /// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void DisableVmReplicationCompletedEventHandler(object sender, DisableVmReplicationCompletedEventArgs e); public delegate void DisableVmReplicationCompletedEventHandler(object sender, System.ComponentModel.AsyncCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class DisableVmReplicationCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal DisableVmReplicationCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public bool Result {
get {
this.RaiseExceptionIfNecessary();
return ((bool)(this.results[0]));
}
}
}
/// <remarks/> /// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]

View file

@ -1023,14 +1023,13 @@ namespace WebsitePanel.Server
} }
[WebMethod, SoapHeader("settings")] [WebMethod, SoapHeader("settings")]
public bool DisableVmReplication(string vmId, string replicaServer) public void DisableVmReplication(string vmId)
{ {
try try
{ {
Log.WriteStart("'{0}' DisableVmReplication", ProviderSettings.ProviderName); Log.WriteStart("'{0}' DisableVmReplication", ProviderSettings.ProviderName);
var result = VirtualizationProvider.DisableVmReplication(vmId, replicaServer); VirtualizationProvider.DisableVmReplication(vmId);
Log.WriteEnd("'{0}' DisableVmReplication", ProviderSettings.ProviderName); Log.WriteEnd("'{0}' DisableVmReplication", ProviderSettings.ProviderName);
return result;
} }
catch (Exception ex) catch (Exception ex)
{ {