This commit is contained in:
Alexander Trofimov 2015-04-17 22:41:35 +03:00
commit b5d2bf04a2
6 changed files with 57 additions and 32 deletions

View file

@ -103,7 +103,7 @@ namespace WebsitePanel.Providers.Virtualization
List<CertificateInfo> GetCertificates(string remoteServer); List<CertificateInfo> GetCertificates(string remoteServer);
void SetReplicaServer(string remoteServer, string thumbprint, string storagePath); void SetReplicaServer(string remoteServer, string thumbprint, string storagePath);
void UnsetReplicaServer(string remoteServer); void UnsetReplicaServer(string remoteServer);
bool IsReplicaServer(string remoteServer); ReplicationServerInfo GetReplicaServer(string remoteServer);
void EnableVmReplication(string vmId, string replicaServer, VmReplication replication); void EnableVmReplication(string vmId, string replicaServer, VmReplication replication);
void SetVmReplication(string vmId, string replicaServer, VmReplication replication); void SetVmReplication(string vmId, string replicaServer, VmReplication replication);
void TestReplicationServer(string vmId, string replicaServer, string localThumbprint); void TestReplicationServer(string vmId, string replicaServer, string localThumbprint);

View file

@ -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; }
}
}

View file

@ -330,6 +330,7 @@
<Compile Include="Virtualization\Replication\CertificateInfo.cs" /> <Compile Include="Virtualization\Replication\CertificateInfo.cs" />
<Compile Include="Virtualization\Replication\ReplicaFrequency.cs" /> <Compile Include="Virtualization\Replication\ReplicaFrequency.cs" />
<Compile Include="Virtualization\Replication\ReplicationHealth.cs" /> <Compile Include="Virtualization\Replication\ReplicationHealth.cs" />
<Compile Include="Virtualization\Replication\ReplicationServerInfo.cs" />
<Compile Include="Virtualization\Replication\VmReplicationMode.cs" /> <Compile Include="Virtualization\Replication\VmReplicationMode.cs" />
<Compile Include="Virtualization\Replication\ReplicaMode.cs" /> <Compile Include="Virtualization\Replication\ReplicaMode.cs" />
<Compile Include="Virtualization\Replication\ReplicationState.cs" /> <Compile Include="Virtualization\Replication\ReplicationState.cs" />

View file

@ -1984,9 +1984,12 @@ namespace WebsitePanel.Providers.Virtualization
public void SetReplicaServer(string remoteServer, string thumbprint, string storagePath) public void SetReplicaServer(string remoteServer, string thumbprint, string storagePath)
{ {
// we cant enable firewall rules on remote server // we cant enable firewall rules on remote server
if (!string.IsNullOrEmpty(remoteServer)) if (string.IsNullOrEmpty(remoteServer))
ReplicaHelper.SetFirewallRule(PowerShell, true); ReplicaHelper.SetFirewallRule(PowerShell, true);
if (GetReplicaServer(remoteServer) != null)
UnsetReplicaServer(remoteServer);
ReplicaHelper.SetReplicaServer(PowerShell, true, remoteServer, thumbprint, storagePath); ReplicaHelper.SetReplicaServer(PowerShell, true, remoteServer, thumbprint, storagePath);
} }
@ -1995,8 +1998,9 @@ namespace WebsitePanel.Providers.Virtualization
ReplicaHelper.SetReplicaServer(PowerShell, false, remoteServer, null, null); 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"); Command cmd = new Command("Get-VMReplicationServer");
if (!string.IsNullOrEmpty(remoteServer)) if (!string.IsNullOrEmpty(remoteServer))
@ -2004,9 +2008,16 @@ namespace WebsitePanel.Providers.Virtualization
cmd.Parameters.Add("ComputerName", remoteServer); cmd.Parameters.Add("ComputerName", remoteServer);
} }
Collection<PSObject> result = PowerShell.Execute(cmd, true); Collection<PSObject> 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) public void EnableVmReplication(string vmId, string replicaServer, VmReplication replication)

View file

@ -133,7 +133,7 @@ namespace WebsitePanel.Providers.Virtualization2012 {
private System.Threading.SendOrPostCallback UnsetReplicaServerOperationCompleted; private System.Threading.SendOrPostCallback UnsetReplicaServerOperationCompleted;
private System.Threading.SendOrPostCallback IsReplicaServerOperationCompleted; private System.Threading.SendOrPostCallback GetReplicaServerOperationCompleted;
private System.Threading.SendOrPostCallback EnableVmReplicationOperationCompleted; private System.Threading.SendOrPostCallback EnableVmReplicationOperationCompleted;
@ -309,7 +309,7 @@ namespace WebsitePanel.Providers.Virtualization2012 {
public event UnsetReplicaServerCompletedEventHandler UnsetReplicaServerCompleted; public event UnsetReplicaServerCompletedEventHandler UnsetReplicaServerCompleted;
/// <remarks/> /// <remarks/>
public event IsReplicaServerCompletedEventHandler IsReplicaServerCompleted; public event GetReplicaServerCompletedEventHandler GetReplicaServerCompleted;
/// <remarks/> /// <remarks/>
public event EnableVmReplicationCompletedEventHandler EnableVmReplicationCompleted; public event EnableVmReplicationCompletedEventHandler EnableVmReplicationCompleted;
@ -2486,43 +2486,43 @@ 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/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)] [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 bool IsReplicaServer(string remoteServer) { public ReplicationServerInfo GetReplicaServer(string remoteServer) {
object[] results = this.Invoke("IsReplicaServer", new object[] { object[] results = this.Invoke("GetReplicaServer", new object[] {
remoteServer}); remoteServer});
return ((bool)(results[0])); return ((ReplicationServerInfo)(results[0]));
} }
/// <remarks/> /// <remarks/>
public System.IAsyncResult BeginIsReplicaServer(string remoteServer, System.AsyncCallback callback, object asyncState) { public System.IAsyncResult BeginGetReplicaServer(string remoteServer, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("IsReplicaServer", new object[] { return this.BeginInvoke("GetReplicaServer", new object[] {
remoteServer}, callback, asyncState); remoteServer}, callback, asyncState);
} }
/// <remarks/> /// <remarks/>
public bool EndIsReplicaServer(System.IAsyncResult asyncResult) { public ReplicationServerInfo EndGetReplicaServer(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult); object[] results = this.EndInvoke(asyncResult);
return ((bool)(results[0])); return ((ReplicationServerInfo)(results[0]));
} }
/// <remarks/> /// <remarks/>
public void IsReplicaServerAsync(string remoteServer) { public void GetReplicaServerAsync(string remoteServer) {
this.IsReplicaServerAsync(remoteServer, null); this.GetReplicaServerAsync(remoteServer, null);
} }
/// <remarks/> /// <remarks/>
public void IsReplicaServerAsync(string remoteServer, object userState) { public void GetReplicaServerAsync(string remoteServer, object userState) {
if ((this.IsReplicaServerOperationCompleted == null)) { if ((this.GetReplicaServerOperationCompleted == null)) {
this.IsReplicaServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnIsReplicaServerOperationCompleted); this.GetReplicaServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetReplicaServerOperationCompleted);
} }
this.InvokeAsync("IsReplicaServer", new object[] { this.InvokeAsync("GetReplicaServer", new object[] {
remoteServer}, this.IsReplicaServerOperationCompleted, userState); remoteServer}, this.GetReplicaServerOperationCompleted, userState);
} }
private void OnIsReplicaServerOperationCompleted(object arg) { private void OnGetReplicaServerOperationCompleted(object arg) {
if ((this.IsReplicaServerCompleted != null)) { if ((this.GetReplicaServerCompleted != 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.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 {
/// <remarks/> /// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] [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);
/// <remarks/> /// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")] [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")] [System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class IsReplicaServerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs { public partial class GetReplicaServerCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results; 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) { base(exception, cancelled, userState) {
this.results = results; this.results = results;
} }
/// <remarks/> /// <remarks/>
public bool Result { public ReplicationServerInfo Result {
get { get {
this.RaiseExceptionIfNecessary(); this.RaiseExceptionIfNecessary();
return ((bool)(this.results[0])); return ((ReplicationServerInfo)(this.results[0]));
} }
} }
} }

View file

@ -925,12 +925,12 @@ namespace WebsitePanel.Server
} }
[WebMethod, SoapHeader("settings")] [WebMethod, SoapHeader("settings")]
public bool IsReplicaServer(string remoteServer) public ReplicationServerInfo GetReplicaServer(string remoteServer)
{ {
try try
{ {
Log.WriteStart("'{0}' IsReplicaServer", ProviderSettings.ProviderName); Log.WriteStart("'{0}' IsReplicaServer", ProviderSettings.ProviderName);
var result = VirtualizationProvider.IsReplicaServer(remoteServer); var result = VirtualizationProvider.GetReplicaServer(remoteServer);
Log.WriteEnd("'{0}' IsReplicaServer", ProviderSettings.ProviderName); Log.WriteEnd("'{0}' IsReplicaServer", ProviderSettings.ProviderName);
return result; return result;
} }