protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            this.m_output            = new HaTaskOutputHelper("set-databaseavailabilitygroup", new Task.TaskErrorLoggingDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskProgressLoggingDelegate(base.WriteProgress), this.GetHashCode());
            this.m_dag               = this.DataObject;
            this.m_skipDagValidation = this.SkipDagValidation;
            DagTaskHelper.VerifyDagAndServersAreWithinScopes <DatabaseAvailabilityGroup>(this, this.m_dag, true);
            if (this.DatabaseAvailabilityGroupIpAddresses != null)
            {
                if (!this.m_dag.IsDagEmpty())
                {
                    this.PrepareServersInDagIfRequired();
                    foreach (AmServerName amServerName in this.m_serverNamesInDag)
                    {
                        DagTaskHelper.ValidateIPAddressList(this.m_output, amServerName.NetbiosName, this.DatabaseAvailabilityGroupIpAddresses, this.m_dag.Name);
                        DagTaskHelper.ValidateIPAddressList(this.m_output, amServerName.Fqdn, this.DatabaseAvailabilityGroupIpAddresses, this.m_dag.Name);
                    }
                }
                foreach (IPAddress ipaddress in this.DatabaseAvailabilityGroupIpAddresses)
                {
                    if (ipaddress.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        this.m_output.WriteErrorSimple(new DagTaskDagIpAddressesMustBeIpv4Exception());
                    }
                }
            }
            this.m_useAlternateWitnessServer = (this.m_dag.AlternateWitnessServer != null && DagTaskHelper.IsDagFailedOverToOtherSite(this.m_output, this.m_dag));
            if (!this.m_useAlternateWitnessServer)
            {
                this.m_fsw = new FileShareWitness((ITopologyConfigurationSession)base.DataSession, this.m_dag.Name, this.WitnessServer ?? this.m_dag.WitnessServer, this.WitnessDirectory ?? this.m_dag.WitnessDirectory);
                try
                {
                    this.m_fsw.Initialize();
                }
                catch (LocalizedException error)
                {
                    this.m_output.WriteErrorSimple(error);
                }
                this.CheckFsw(this.m_fsw.WitnessServerFqdn);
            }
            if (this.AlternateWitnessServer != null || this.AlternateWitnessDirectory != null || (this.m_dag.AlternateWitnessServer != null && this.m_dag.AlternateWitnessDirectory != null && !this.m_alternateWitnessServerParameterSpecified) || this.m_useAlternateWitnessServer)
            {
                this.m_afsw = new FileShareWitness((ITopologyConfigurationSession)base.DataSession, this.m_dag.Name, this.AlternateWitnessServer ?? this.m_dag.AlternateWitnessServer, this.AlternateWitnessDirectory ?? this.m_dag.AlternateWitnessDirectory);
                try
                {
                    this.m_afsw.Initialize();
                }
                catch (LocalizedException error2)
                {
                    this.m_output.WriteErrorSimple(error2);
                }
                if (this.m_fsw != null && SharedHelper.StringIEquals(this.m_afsw.WitnessServerFqdn, this.m_fsw.WitnessServerFqdn) && this.m_fsw.WitnessDirectory != this.m_afsw.WitnessDirectory)
                {
                    this.m_output.WriteErrorSimple(new DagFswAndAlternateFswOnSameWitnessServerButPointToDifferentDirectoriesException(this.m_fsw.WitnessServer.ToString(), this.m_fsw.WitnessDirectory.ToString(), this.m_afsw.WitnessDirectory.ToString()));
                }
                this.CheckFsw(this.m_afsw.WitnessServerFqdn);
            }
            Dictionary <AmServerName, Server> startedServers = new Dictionary <AmServerName, Server>();

            DatabaseAvailabilityGroupAction.ResolveServers(this.m_output, this.m_dag, this.m_allServers, startedServers, this.m_stoppedServers);
            if (!this.m_dag.IsDagEmpty())
            {
                this.PrepareServersInDagIfRequired();
                List <AmServerName>        list             = new List <AmServerName>(this.m_stoppedServers.Count);
                IEnumerable <AmServerName> serversInCluster = null;
                foreach (Server server in this.m_stoppedServers.Values)
                {
                    list.Add(new AmServerName(server.Id));
                }
                using (AmCluster amCluster = AmCluster.OpenDagClus(this.m_dag))
                {
                    serversInCluster = amCluster.EnumerateNodeNames();
                }
                if (!this.m_skipDagValidation)
                {
                    DagTaskHelper.CompareDagClusterMembership(this.m_output, this.m_dag.Name, this.m_serverNamesInDag, serversInCluster, list);
                }
            }
            if (base.Fields["DatacenterActivationMode"] != null && this.DatacenterActivationMode != DatacenterActivationModeOption.Off)
            {
                DagTaskHelper.CheckDagCanBeActivatedInDatacenter(this.m_output, this.m_dag, null, (ITopologyConfigurationSession)base.DataSession);
            }
            if (base.Fields["DatacenterActivationMode"] != null && this.DatacenterActivationMode == DatacenterActivationModeOption.Off)
            {
                this.DataObject.StartedMailboxServers = null;
                this.DataObject.StoppedMailboxServers = null;
            }
            TaskLogger.LogExit();
        }
示例#2
0
        private MailboxDatabaseWithLocationInfo FindDatabaseForProvisioning()
        {
            ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(base.DomainController, true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 874, "FindDatabaseForProvisioning", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\GroupMailbox\\NewGroupMailbox.cs");

            this.stopWatch.Restart();
            Server server = topologyConfigurationSession.FindLocalServer();

            this.WriteDebugInfo("Found localServer. Time took:{0} sec", new object[]
            {
                this.stopWatch.Elapsed.TotalSeconds.ToString("n2")
            });
            if (server == null)
            {
                this.WriteError(new ObjectNotFoundException(new LocalizedString(Environment.MachineName), null), ExchangeErrorCategory.ServerTransient, null, true);
            }
            DatabaseAvailabilityGroup databaseAvailabilityGroup = null;

            this.stopWatch.Restart();
            if (ExEnvironment.IsSdfDomain)
            {
                databaseAvailabilityGroup = DagTaskHelper.ReadDagByName("NAMSR01DG050", topologyConfigurationSession);
                this.WriteDebugInfo("Found Dag {0} . Time took:{1} sec", new object[]
                {
                    "NAMSR01DG050",
                    this.stopWatch.Elapsed.TotalSeconds.ToString("n2")
                });
                if (databaseAvailabilityGroup == null)
                {
                    this.WriteError(new GroupMailboxFailedToFindDagException(Strings.ErrorIncorrectInputDag("NAMSR01DG050")), ExchangeErrorCategory.ServerTransient, null, true);
                }
            }
            else if (server.DatabaseAvailabilityGroup != null)
            {
                databaseAvailabilityGroup = DagTaskHelper.ReadDag(server.DatabaseAvailabilityGroup, topologyConfigurationSession);
                this.WriteDebugInfo("Dag found:{0} for id={1}. Time took:{2} sec", new object[]
                {
                    databaseAvailabilityGroup != null,
                    server.DatabaseAvailabilityGroup,
                    this.stopWatch.Elapsed.TotalSeconds.ToString("n2")
                });
            }
            else
            {
                this.WriteDebugInfo("The current server does not belong to a dag.", new object[0]);
            }
            List <MailboxDatabase> list;
            List <MailboxDatabase> list2;

            this.FetchDatabases(topologyConfigurationSession, databaseAvailabilityGroup, server, out list, out list2);
            Random random = new Random();

            while (list.Count > 0)
            {
                int             index           = random.Next(list.Count);
                MailboxDatabase mailboxDatabase = list[index];
                list.RemoveAt(index);
                DatabaseLocationInfo databaseLocationInfo = this.GetDatabaseLocationInfo(mailboxDatabase);
                if (databaseLocationInfo != null)
                {
                    if (string.Equals(databaseLocationInfo.ServerFqdn, server.Fqdn, StringComparison.OrdinalIgnoreCase))
                    {
                        return(new MailboxDatabaseWithLocationInfo(mailboxDatabase, databaseLocationInfo));
                    }
                    list2.Add(mailboxDatabase);
                }
            }
            this.WriteDebugInfo("Picking a remote database", new object[0]);
            while (list2.Count > 0)
            {
                int             index2           = random.Next(list2.Count);
                MailboxDatabase mailboxDatabase2 = list2[index2];
                list2.RemoveAt(index2);
                DatabaseLocationInfo databaseLocationInfo2 = this.GetDatabaseLocationInfo(mailboxDatabase2);
                if (databaseLocationInfo2 != null)
                {
                    return(new MailboxDatabaseWithLocationInfo(mailboxDatabase2, databaseLocationInfo2));
                }
            }
            return(null);
        }
 protected override bool IsKnownException(Exception e)
 {
     return(DagTaskHelper.IsKnownException(this, e) || base.IsKnownException(e));
 }
示例#4
0
        private List <string> JoinStartedNodes(IEnumerable <Server> serversToStart)
        {
            if (serversToStart == null)
            {
                throw new ArgumentNullException("serversToStart");
            }
            List <string> list = new List <string>(1);

            using (AmCluster amCluster = AmCluster.OpenDagClus(this.m_dag))
            {
                using (IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup())
                {
                    try
                    {
                        using (DumpClusterTopology dumpClusterTopology = new DumpClusterTopology(amCluster, this.m_output))
                        {
                            dumpClusterTopology.Dump();
                        }
                    }
                    catch (ClusterException ex)
                    {
                        this.m_output.AppendLogMessage("DumpClusterTopology( {0} ) failed with exception = {1}. This is OK.", new object[]
                        {
                            this.m_dag.Name,
                            ex.Message
                        });
                        this.m_output.AppendLogMessage("Ignoring previous error, as it is acceptable if the cluster does not exist yet.", new object[0]);
                    }
                    AmServerName ownerNode = amClusterGroup.OwnerNode;
                    DatabaseTasksHelper.CheckReplayServiceRunningOnNode(ownerNode, new Task.TaskErrorLoggingDelegate(base.WriteError));
                    if (amCluster.CnoName != string.Empty)
                    {
                        using (IAmClusterResource amClusterResource = amClusterGroup.FindResourceByTypeName("Network Name"))
                        {
                            DagTaskHelper.LogCnoState(this.m_output, this.m_dag.Name, amClusterResource);
                        }
                    }
                    foreach (Server server in serversToStart)
                    {
                        bool         flag         = false;
                        AmServerName amServerName = new AmServerName(server);
                        try
                        {
                            if (amCluster.IsEvictedBasedOnMemberShip(amServerName))
                            {
                                this.m_output.WriteProgressSimple(Strings.ProgressJoinNode(amServerName.NetbiosName));
                                this.m_output.AppendLogMessage("ForceCleanup the Node {0}", new object[]
                                {
                                    server.Name
                                });
                                DatabaseAvailabilityGroupAction.ForceCleanupOneNodeLocally(this.m_dag.Name, server, TimeSpan.FromSeconds(15.0), this.m_output);
                                this.m_output.AppendLogMessage("Join the node {0} to the cluster", new object[]
                                {
                                    server.Name
                                });
                                DatabaseAvailabilityGroupAction.JoinOneNode(ownerNode, amServerName, this.m_output);
                                flag = true;
                            }
                            else
                            {
                                this.m_output.AppendLogMessage("{0} is not evicted", new object[]
                                {
                                    amServerName
                                });
                            }
                            if (!AmCluster.IsRunning(amServerName))
                            {
                                try
                                {
                                    this.m_output.AppendLogMessage("{0} cluster service is not running, try to start the service", new object[]
                                    {
                                        server.Name
                                    });
                                    this.m_output.WriteProgressSimple(Strings.ProgressStartClussvc(amServerName.NetbiosName));
                                    DatabaseAvailabilityGroupAction.TryStartClussvcOnNode(amServerName, this.m_output);
                                }
                                catch (InvalidOperationException)
                                {
                                    this.m_output.AppendLogMessage("Got an invalidOperationException, most likely the node {0} is force cleanedup", new object[]
                                    {
                                        amServerName
                                    });
                                    if (flag)
                                    {
                                        this.m_output.AppendLogMessage("STRANGE! we joined {0} but cannot start the service!", new object[]
                                        {
                                            amServerName
                                        });
                                        throw;
                                    }
                                    this.m_output.WriteProgressSimple(Strings.ProgressJoinNode(amServerName.NetbiosName));
                                    DatabaseAvailabilityGroupAction.JoinForceCleanupNode(ownerNode, amServerName, this.m_output);
                                    flag = true;
                                }
                            }
                            if (flag)
                            {
                                ICollection <AmServerName> startedMailboxServers = from server1 in this.m_dag.StartedMailboxServers
                                                                                   select new AmServerName(server1);
                                DatabaseAvailabilityGroupAction.FixIPAddress(new AmServerName(server.Fqdn), this.m_dag, startedMailboxServers, this.m_output);
                            }
                        }
                        catch (LocalizedException ex2)
                        {
                            this.m_output.WriteWarning(Strings.FailedToJoinNode(server.Name, this.m_dag.Name, ex2.Message));
                            list.Add(server.Name);
                        }
                        catch (InvalidOperationException ex3)
                        {
                            this.m_output.WriteWarning(Strings.FailedToJoinNode(server.Name, this.m_dag.Name, ex3.Message));
                            list.Add(server.Name);
                        }
                    }
                }
            }
            return(list);
        }