From 7c85eb643f66ff9fba8d1979151fd45a4d8219c7 Mon Sep 17 00:00:00 2001 From: VoosW Date: Mon, 29 Oct 2012 19:35:27 +0100 Subject: [PATCH] change "Getdatabase" code for Exchange 2010SP2 so that it accepts a database group name of DAG\MailboxDatabase to turn off the load-balancing and instead use a fixed database. The default behaviour of load-balancing mailboxes between all Provsioning-Enabled mailbox databases of the DAG-Group is still present and functioning. --- .../Exchange2010SP2.cs | 94 ++++++++++++++----- 1 file changed, 71 insertions(+), 23 deletions(-) diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2010SP2.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2010SP2.cs index 65d4dabf..230ac187 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2010SP2.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/Exchange2010SP2.cs @@ -607,15 +607,42 @@ namespace WebsitePanel.Providers.HostedSolution ExchangeLog.LogStart("GetDatabase"); ExchangeLog.LogInfo("DAG: " + dagName); - //Get Dag Servers + // this part of code handles mailboxnames like in the old 2007 provider + // check if DAG is in reality DAG\mailboxdatabase + string dagNameDAG = string.Empty; + string dagNameMBX = string.Empty; + bool isFixedDatabase = false; + if (dagName.Contains("\\")) + { + // split the two parts and extract DAG-Name and mailboxdatabase-name + string[] parts = dagName.Split(new char[] { '\\' }, 2, StringSplitOptions.None); + dagNameDAG = parts[0]; + dagNameMBX = parts[1]; + // check that we realy have a database name + if (!String.IsNullOrEmpty(dagNameMBX)) + { + isFixedDatabase = true; + } + } + else + { + // there is no mailboxdatabase-name use the loadbalancing-code + dagNameDAG = dagName; + isFixedDatabase = false; + } + + //Get Dag Servers - with the name of the database availability group Collection dags = null; Command cmd = new Command("Get-DatabaseAvailabilityGroup"); - cmd.Parameters.Add("Identity", dagName); + cmd.Parameters.Add("Identity", dagNameDAG); dags = ExecuteShellCommand(runSpace, cmd); if (htBbalancer == null) htBbalancer = new Hashtable(); + // use fully qualified dagName for loadbalancer. Thus if there are two services and one of them + // contains only the DAG, the "fixed" database could also be used in loadbalancing. If you do not want this, + // set either IsExcludedFromProvisioning or IsSuspendedFromProvisioning - it is not evaluated for fixed databases if (htBbalancer[dagName] == null) htBbalancer.Add(dagName, 0); @@ -628,35 +655,56 @@ namespace WebsitePanel.Providers.HostedSolution { System.Collections.Generic.List lstDatabase = new System.Collections.Generic.List(); - foreach (object objServer in servers) + if (!isFixedDatabase) // "old" loadbalancing code + { + foreach (object objServer in servers) + { + Collection databases = null; + cmd = new Command("Get-MailboxDatabase"); + cmd.Parameters.Add("Server", ObjToString(objServer)); + databases = ExecuteShellCommand(runSpace, cmd); + + foreach (PSObject objDatabase in databases) + { + if (((bool)GetPSObjectProperty(objDatabase, "IsExcludedFromProvisioning") == false) && + ((bool)GetPSObjectProperty(objDatabase, "IsSuspendedFromProvisioning") == false)) + { + string db = ObjToString(GetPSObjectProperty(objDatabase, "Identity")); + + bool bAdd = true; + foreach (string s in lstDatabase) + { + if (s.ToLower() == db.ToLower()) + { + bAdd = false; + break; + } + } + + if (bAdd) + { + lstDatabase.Add(db); + ExchangeLog.LogInfo("AddDatabase: " + db); + } + } + } + } + } + else // new fixed database code { Collection databases = null; cmd = new Command("Get-MailboxDatabase"); - cmd.Parameters.Add("Server", ObjToString(objServer)); + cmd.Parameters.Add("Identity", dagNameMBX); databases = ExecuteShellCommand(runSpace, cmd); + // do not check "IsExcludedFromProvisioning" or "IsSuspended", just check if it is a member of the DAG foreach (PSObject objDatabase in databases) { - if (((bool)GetPSObjectProperty(objDatabase, "IsExcludedFromProvisioning") == false) && - ((bool)GetPSObjectProperty(objDatabase, "IsSuspendedFromProvisioning") == false)) + string dagSetting = ObjToString(GetPSObjectProperty(objDatabase, "MasterServerOrAvailabilityGroup")); + if (dagNameDAG.Equals(dagSetting, StringComparison.OrdinalIgnoreCase)) { - string db = ObjToString(GetPSObjectProperty(objDatabase, "Identity")); - - bool bAdd = true; - foreach (string s in lstDatabase) - { - if (s.ToLower() == db.ToLower()) - { - bAdd = false; - break; - } - } - - if (bAdd) - { - lstDatabase.Add(db); - ExchangeLog.LogInfo("AddDatabase: " + db); - } + lstDatabase.Add(dagNameMBX); + ExchangeLog.LogInfo("AddFixedDatabase: " + dagNameMBX); } } }