From bbd165fdbd793578c8c26544ce39947dd3d8877a Mon Sep 17 00:00:00 2001 From: Alexander Trofimov Date: Fri, 17 Apr 2015 15:35:12 -0400 Subject: [PATCH] wsp-10329 Adding hyper-v replica to HyperV Provider. Server Part 5. --- .../IVirtualizationServer2012.cs | 2 +- .../Replication/ReplicationServerInfo.cs | 13 +++++ .../WebsitePanel.Providers.Base.csproj | 1 + .../HyperV2012R2.cs | 19 +++++-- .../VirtualizationServerProxy2012.cs | 50 +++++++++---------- .../VirtualizationServer2012.asmx.cs | 4 +- 6 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/Replication/ReplicationServerInfo.cs diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/IVirtualizationServer2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/IVirtualizationServer2012.cs index e792d49d..ce81e1ac 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/IVirtualizationServer2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/IVirtualizationServer2012.cs @@ -103,7 +103,7 @@ namespace WebsitePanel.Providers.Virtualization List GetCertificates(string remoteServer); void SetReplicaServer(string remoteServer, string thumbprint, string storagePath); void UnsetReplicaServer(string remoteServer); - bool IsReplicaServer(string remoteServer); + ReplicationServerInfo GetReplicaServer(string remoteServer); void EnableVmReplication(string vmId, string replicaServer, VmReplication replication); void SetVmReplication(string vmId, string replicaServer, VmReplication replication); void TestReplicationServer(string vmId, string replicaServer, string localThumbprint); diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/Replication/ReplicationServerInfo.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/Replication/ReplicationServerInfo.cs new file mode 100644 index 00000000..e218cb60 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/Virtualization/Replication/ReplicationServerInfo.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WebsitePanel.Providers.Virtualization +{ + public class ReplicationServerInfo + { + public bool Enabled { get; set; } + public string ComputerName { get; set; } + } +} diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj index 6ac5b9f7..79730c35 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/WebsitePanel.Providers.Base.csproj @@ -330,6 +330,7 @@ + diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs index e1becaaf..f177136b 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.Virtualization.HyperV-2012R2/HyperV2012R2.cs @@ -1984,9 +1984,12 @@ namespace WebsitePanel.Providers.Virtualization public void SetReplicaServer(string remoteServer, string thumbprint, string storagePath) { // we cant enable firewall rules on remote server - if (!string.IsNullOrEmpty(remoteServer)) + if (string.IsNullOrEmpty(remoteServer)) ReplicaHelper.SetFirewallRule(PowerShell, true); + if (GetReplicaServer(remoteServer) != null) + UnsetReplicaServer(remoteServer); + ReplicaHelper.SetReplicaServer(PowerShell, true, remoteServer, thumbprint, storagePath); } @@ -1995,8 +1998,9 @@ namespace WebsitePanel.Providers.Virtualization ReplicaHelper.SetReplicaServer(PowerShell, false, remoteServer, null, null); } - public bool IsReplicaServer(string remoteServer) + public ReplicationServerInfo GetReplicaServer(string remoteServer) { + ReplicationServerInfo replicaServer = null; Command cmd = new Command("Get-VMReplicationServer"); if (!string.IsNullOrEmpty(remoteServer)) @@ -2004,9 +2008,16 @@ namespace WebsitePanel.Providers.Virtualization cmd.Parameters.Add("ComputerName", remoteServer); } - Collection result = PowerShell.Execute(cmd, true); + Collection result = PowerShell.Execute(cmd, false); - return result != null && result.Count > 0; + if (result != null && result.Count > 0) + { + replicaServer = new ReplicationServerInfo(); + replicaServer.Enabled = result[0].GetBool("RepEnabled"); + replicaServer.ComputerName = result[0].GetString("ComputerName"); + } + + return replicaServer; } public void EnableVmReplication(string vmId, string replicaServer, VmReplication replication) diff --git a/WebsitePanel/Sources/WebsitePanel.Server.Client/VirtualizationServerProxy2012.cs b/WebsitePanel/Sources/WebsitePanel.Server.Client/VirtualizationServerProxy2012.cs index 05f71105..d9f917c9 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server.Client/VirtualizationServerProxy2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server.Client/VirtualizationServerProxy2012.cs @@ -133,7 +133,7 @@ namespace WebsitePanel.Providers.Virtualization2012 { private System.Threading.SendOrPostCallback UnsetReplicaServerOperationCompleted; - private System.Threading.SendOrPostCallback IsReplicaServerOperationCompleted; + private System.Threading.SendOrPostCallback GetReplicaServerOperationCompleted; private System.Threading.SendOrPostCallback EnableVmReplicationOperationCompleted; @@ -309,7 +309,7 @@ namespace WebsitePanel.Providers.Virtualization2012 { public event UnsetReplicaServerCompletedEventHandler UnsetReplicaServerCompleted; /// - public event IsReplicaServerCompletedEventHandler IsReplicaServerCompleted; + public event GetReplicaServerCompletedEventHandler GetReplicaServerCompleted; /// public event EnableVmReplicationCompletedEventHandler EnableVmReplicationCompleted; @@ -2486,43 +2486,43 @@ namespace WebsitePanel.Providers.Virtualization2012 { /// [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] - [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/IsReplicaServer", 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 IsReplicaServer(string remoteServer) { - object[] results = this.Invoke("IsReplicaServer", new object[] { + [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://smbsaas/websitepanel/server/GetReplicaServer", 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 ReplicationServerInfo GetReplicaServer(string remoteServer) { + object[] results = this.Invoke("GetReplicaServer", new object[] { remoteServer}); - return ((bool)(results[0])); + return ((ReplicationServerInfo)(results[0])); } /// - public System.IAsyncResult BeginIsReplicaServer(string remoteServer, System.AsyncCallback callback, object asyncState) { - return this.BeginInvoke("IsReplicaServer", new object[] { + public System.IAsyncResult BeginGetReplicaServer(string remoteServer, System.AsyncCallback callback, object asyncState) { + return this.BeginInvoke("GetReplicaServer", new object[] { remoteServer}, callback, asyncState); } /// - public bool EndIsReplicaServer(System.IAsyncResult asyncResult) { + public ReplicationServerInfo EndGetReplicaServer(System.IAsyncResult asyncResult) { object[] results = this.EndInvoke(asyncResult); - return ((bool)(results[0])); + return ((ReplicationServerInfo)(results[0])); } /// - public void IsReplicaServerAsync(string remoteServer) { - this.IsReplicaServerAsync(remoteServer, null); + public void GetReplicaServerAsync(string remoteServer) { + this.GetReplicaServerAsync(remoteServer, null); } /// - public void IsReplicaServerAsync(string remoteServer, object userState) { - if ((this.IsReplicaServerOperationCompleted == null)) { - this.IsReplicaServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnIsReplicaServerOperationCompleted); + public void GetReplicaServerAsync(string remoteServer, object userState) { + if ((this.GetReplicaServerOperationCompleted == null)) { + this.GetReplicaServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetReplicaServerOperationCompleted); } - this.InvokeAsync("IsReplicaServer", new object[] { - remoteServer}, this.IsReplicaServerOperationCompleted, userState); + this.InvokeAsync("GetReplicaServer", new object[] { + remoteServer}, this.GetReplicaServerOperationCompleted, userState); } - private void OnIsReplicaServerOperationCompleted(object arg) { - if ((this.IsReplicaServerCompleted != null)) { + private void OnGetReplicaServerOperationCompleted(object arg) { + if ((this.GetReplicaServerCompleted != null)) { System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg)); - this.IsReplicaServerCompleted(this, new IsReplicaServerCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); + this.GetReplicaServerCompleted(this, new GetReplicaServerCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState)); } } @@ -4111,26 +4111,26 @@ namespace WebsitePanel.Providers.Virtualization2012 { /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] - public delegate void IsReplicaServerCompletedEventHandler(object sender, IsReplicaServerCompletedEventArgs e); + public delegate void GetReplicaServerCompletedEventHandler(object sender, GetReplicaServerCompletedEventArgs e); /// [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] - public partial class IsReplicaServerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { + public partial class GetReplicaServerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { private object[] results; - internal IsReplicaServerCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : + internal GetReplicaServerCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : base(exception, cancelled, userState) { this.results = results; } /// - public bool Result { + public ReplicationServerInfo Result { get { this.RaiseExceptionIfNecessary(); - return ((bool)(this.results[0])); + return ((ReplicationServerInfo)(this.results[0])); } } } diff --git a/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServer2012.asmx.cs b/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServer2012.asmx.cs index 1d49cfa3..c2276774 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServer2012.asmx.cs +++ b/WebsitePanel/Sources/WebsitePanel.Server/VirtualizationServer2012.asmx.cs @@ -925,12 +925,12 @@ namespace WebsitePanel.Server } [WebMethod, SoapHeader("settings")] - public bool IsReplicaServer(string remoteServer) + public ReplicationServerInfo GetReplicaServer(string remoteServer) { try { Log.WriteStart("'{0}' IsReplicaServer", ProviderSettings.ProviderName); - var result = VirtualizationProvider.IsReplicaServer(remoteServer); + var result = VirtualizationProvider.GetReplicaServer(remoteServer); Log.WriteEnd("'{0}' IsReplicaServer", ProviderSettings.ProviderName); return result; }