From 019ad51eae2ec31f5943e482776c5ba38ab4f7cd Mon Sep 17 00:00:00 2001 From: Alexander Trofimov Date: Fri, 17 Apr 2015 19:18:49 +0300 Subject: [PATCH] wsp-10329 Adding hyper-v replica to HyperV Provider. Enterprise Part 3. --- .../VirtualizationServerController2012.cs | 1 + .../HyperV2012R2_Settings.ascx.resx | 13 ++-- .../HyperV2012R2_Settings.ascx | 48 +++++++++---- .../HyperV2012R2_Settings.ascx.cs | 67 +++++++++++++++++++ .../HyperV2012R2_Settings.ascx.designer.cs | 63 +++++++++++++++++ 5 files changed, 175 insertions(+), 17 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization2012/VirtualizationServerController2012.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization2012/VirtualizationServerController2012.cs index 4b722429..79a19aeb 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization2012/VirtualizationServerController2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Code/Virtualization2012/VirtualizationServerController2012.cs @@ -3736,6 +3736,7 @@ namespace WebsitePanel.EnterpriseServer VirtualizationServer2012 vs = GetVirtualizationProxy(serviceId); vs.SetReplicaServer(remoteServer, thumbprint, storagePath); + result.IsSuccess = true; } catch (Exception ex) { diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/HyperV2012R2_Settings.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/HyperV2012R2_Settings.ascx.resx index 494ca0db..6f5392eb 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/HyperV2012R2_Settings.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/HyperV2012R2_Settings.ascx.resx @@ -408,7 +408,7 @@ The following substitution variables can be used in the pattern:<br/> Enter the thumbnail of a SSL certificate - SSL Certificate Thumbnail: + SSL Certificate Thumbprint: Can not to set server as a replication server with the entered server name, replication path and SSL certificate @@ -416,9 +416,6 @@ The following substitution variables can be used in the pattern:<br/> Path for Replications: - - Replica Server: - Replication @@ -426,7 +423,7 @@ The following substitution variables can be used in the pattern:<br/> Enter path to replication virtual machines - Enter a replication server name + Enter a replication server No Hyper-v Replication @@ -437,7 +434,13 @@ The following substitution variables can be used in the pattern:<br/> This is a Replica Server + + Please add a server with the enabled replication and select it from list + Please enter replication path + + Replication Server: + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx index 1c5c12e1..a1c3b68a 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx @@ -152,18 +152,40 @@ -
- - - - +
- - No Hyper-v Replication - Enable Hyper-V Replication - This is a Replica Server - -
+ + + + + + +
+ + No Hyper-v Replication + Enable Hyper-V Replication + This is a Replica Server + +
+ + + + + + + + +
+ + + + + +
+ +
+
@@ -180,6 +202,8 @@ + diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.cs index 2814fe0c..974ce822 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.cs @@ -27,9 +27,12 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; +using System.Collections.Generic; using System.Collections.Specialized; +using System.Data; using System.Linq; using System.Web.UI.WebControls; +using WebsitePanel.EnterpriseServer; using WebsitePanel.Providers.Common; using WebsitePanel.Providers.Virtualization; @@ -45,6 +48,8 @@ namespace WebsitePanel.Portal.ProviderControls public string RemoteServerName { get { return IsRemoteServer ? txtServerName.Text.Trim() : ""; } } public string CertificateThumbprint { get { return IsRemoteServer ? txtCertThumbnail.Text.Trim() : ddlCertThumbnail.SelectedValue; } } public bool IsReplicaServer { get { return ReplicationModeList.SelectedValue == "IsReplicaServer"; } } + public bool EnabledReplica { get { return ReplicationModeList.SelectedValue == "Enable"; } } + public string ReplicaServerId { get; set; } void IHostingServiceProviderSettings.BindSettings(StringDictionary settings) { @@ -103,6 +108,7 @@ namespace WebsitePanel.Portal.ProviderControls // replica ReplicationModeList.SelectedValue = settings["ReplicaMode"] ?? "Disabled"; txtReplicaPath.Text = settings["ReplicaServerPath"]; + ReplicaServerId = settings["ReplicaServerId"]; ToggleControls(); @@ -171,6 +177,7 @@ namespace WebsitePanel.Portal.ProviderControls // replication settings["ReplicaMode"] = ReplicationModeList.SelectedValue; + settings["ReplicaServerId"] = ddlReplicaServer.SelectedValue; settings["ReplicaServerPath"] = txtReplicaPath.Text; settings["ReplicaServerThumbprint"] = CertificateThumbprint; @@ -211,6 +218,64 @@ namespace WebsitePanel.Portal.ProviderControls } } + + private void BindReplicaServices() + { + ddlReplicaServer.Items.Clear(); + + ServiceInfo serviceInfo = ES.Services.Servers.GetServiceInfo(PanelRequest.ServiceId); + DataView dvServices = ES.Services.Servers.GetRawServicesByGroupName(ResourceGroups.VPS2012).Tables[0].DefaultView; + + List services = GetServices(ReplicaServerId); + + foreach (DataRowView dr in dvServices) + { + int serviceId = (int)dr["ServiceID"]; + + ServiceInfo currentServiceInfo = ES.Services.Servers.GetServiceInfo(serviceId); + if (currentServiceInfo == null || currentServiceInfo.ProviderId != serviceInfo.ProviderId) + continue; + + var currentServiceSettings = ConvertArrayToDictionary(ES.Services.Servers.GetServiceSettings(serviceId)); + if (currentServiceSettings["ReplicaMode"] == ReplicaMode.IsReplicaServer.ToString()) + continue; + + var exists = false; + if (services != null) + exists = services.Any(current => current != null && current.ServiceId == serviceId); + + var listItem = new ListItem(dr["FullServiceName"].ToString(), serviceId.ToString()) {Selected = exists}; + ddlReplicaServer.Items.Add(listItem); + } + } + + private List GetServices(string data) + { + if (string.IsNullOrEmpty(data)) + return null; + List list = new List(); + string[] servicesIds = data.Split(','); + foreach (string current in servicesIds) + { + ServiceInfo serviceInfo = ES.Services.Servers.GetServiceInfo(Utils.ParseInt(current)); + list.Add(serviceInfo); + } + + + return list; + } + + private StringDictionary ConvertArrayToDictionary(string[] settings) + { + StringDictionary r = new StringDictionary(); + foreach (string setting in settings) + { + int idx = setting.IndexOf('='); + r.Add(setting.Substring(0, idx), setting.Substring(idx + 1)); + } + return r; + } + private void ToggleControls() { ServerNameRow.Visible = (radioServer.SelectedIndex == 1); @@ -230,11 +295,13 @@ namespace WebsitePanel.Portal.ProviderControls // Replica IsReplicaServerRow.Visible = IsReplicaServer; + EnableReplicaRow.Visible = EnabledReplica; ddlCertThumbnail.Visible = !IsRemoteServer; txtCertThumbnail.Visible = CertificateThumbnailValidator.Visible = IsRemoteServer; IsReplicaServerRow.Visible = IsReplicaServer; ReplicaPathErrorTr.Visible = ReplicaErrorTr.Visible = false; if (IsReplicaServer) BindCertificates(); + if (EnabledReplica) BindReplicaServices(); } protected void radioServer_SelectedIndexChanged(object sender, EventArgs e) diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.designer.cs index 2ae51e9a..d8100907 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/HyperV2012R2_Settings.ascx.designer.cs @@ -363,6 +363,60 @@ namespace WebsitePanel.Portal.ProviderControls { /// protected global::System.Web.UI.WebControls.RadioButtonList ReplicationModeList; + /// + /// EnableReplicaRow control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlTableRow EnableReplicaRow; + + /// + /// locReplicaServer control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Localize locReplicaServer; + + /// + /// ddlReplicaServer control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.DropDownList ddlReplicaServer; + + /// + /// ReplicaServerValidator control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator ReplicaServerValidator; + + /// + /// EnableReplicaErrorTr control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlTableRow EnableReplicaErrorTr; + + /// + /// locEnableReplicaError control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label locEnableReplicaError; + /// /// IsReplicaServerRow control. /// @@ -417,6 +471,15 @@ namespace WebsitePanel.Portal.ProviderControls { /// protected global::System.Web.UI.WebControls.RequiredFieldValidator CertificateThumbnailValidator; + /// + /// CertificateDdlThumbnailValidator control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.RequiredFieldValidator CertificateDdlThumbnailValidator; + /// /// ReplicaPathErrorTr control. ///