Esempio n. 1
0
 // Token: 0x060008AD RID: 2221 RVA: 0x000296B0 File Offset: 0x000278B0
 private static void SetFswSharePath(ITaskOutputHelper output, IAmCluster cluster, IAmClusterResource fsw, string fswShare)
 {
     try
     {
         fsw.OfflineResource();
         fsw.SetPrivateProperty <string>("SharePath", fswShare);
         fsw.OnlineResource();
     }
     catch (ClusterException ex)
     {
         Win32Exception ex2 = null;
         if (ex.TryGetTypedInnerException(out ex2))
         {
             output.AppendLogMessage("SetFswSharePath() caught an AmClusterApiException with errorcode={0} and NativeErrorCode={1}. ex = {2}", new object[]
             {
                 ex2.ErrorCode,
                 ex2.NativeErrorCode,
                 ex2
             });
             if (ex2.NativeErrorCode == 5)
             {
                 string text = cluster.CnoName;
                 if (text == string.Empty)
                 {
                     using (IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup())
                     {
                         if (amClusterGroup != null && amClusterGroup.OwnerNode != null)
                         {
                             text = amClusterGroup.OwnerNode.NetbiosName;
                         }
                     }
                 }
                 output.WriteErrorSimple(new DagTaskFswNeedsCnoPermissionException(fswShare, text));
             }
         }
         throw;
     }
 }
Esempio n. 2
0
        // Token: 0x060008AC RID: 2220 RVA: 0x00029304 File Offset: 0x00027504
        internal static void CreateFileShareWitnessQuorum(ITaskOutputHelper output, IAmCluster cluster, string fswShare)
        {
            output = (output ?? NullTaskOutputHelper.GetNullLogger());
            IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup();

            if (amClusterGroup == null)
            {
                Thread.Sleep(10000);
                amClusterGroup = cluster.FindCoreClusterGroup();
                if (amClusterGroup == null)
                {
                    throw new FailedToGetClusterCoreGroupException();
                }
            }
            using (amClusterGroup)
            {
                IEnumerable <AmClusterResource> source = amClusterGroup.EnumerateResourcesOfType("File Share Witness");
                IAmClusterResource amClusterResource   = source.ElementAtOrDefault(0);
                try
                {
                    bool flag = false;
                    if (amClusterResource == null)
                    {
                        output.AppendLogMessage("CreateFileShareWitnessQuorum: Could not find an existing FSW resource. A new one will be created.", new object[0]);
                        flag = true;
                    }
                    else if (amClusterResource.GetState() == AmResourceState.Failed)
                    {
                        output.AppendLogMessage("CreateFileShareWitnessQuorum: The existing FSW resource is in a Failed state. It should be deleted and recreated.", new object[0]);
                        flag = true;
                    }
                    else
                    {
                        string privateProperty = amClusterResource.GetPrivateProperty <string>("SharePath");
                        if (!SharedHelper.StringIEquals(privateProperty, fswShare))
                        {
                            output.AppendLogMessage("CreateFileShareWitnessQuorum: There is already a FSW, but the current share path ({0}) is not what's desired ({1}). Will try to fix it.", new object[]
                            {
                                privateProperty,
                                fswShare
                            });
                            List <string> list = new List <string>(4);
                            foreach (IAmClusterNode amClusterNode in cluster.EnumerateNodes())
                            {
                                using (amClusterNode)
                                {
                                    if (!AmClusterNode.IsNodeUp(amClusterNode.State))
                                    {
                                        list.Add(amClusterNode.Name.NetbiosName);
                                    }
                                }
                            }
                            if (list.Count > 0)
                            {
                                output.WriteErrorSimple(new DagTaskSetDagNeedsAllNodesUpToChangeQuorumException(string.Join(",", list.ToArray())));
                            }
                            DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare);
                        }
                    }
                    AmResourceState state;
                    if (!flag && amClusterResource != null)
                    {
                        try
                        {
                            state = amClusterResource.GetState();
                            if (state != AmResourceState.Online)
                            {
                                output.AppendLogMessage("The FSW is not online (it is {0}). Attempting to bring online.", new object[]
                                {
                                    state
                                });
                                amClusterResource.OnlineResource();
                            }
                            state = amClusterResource.GetState();
                            output.AppendLogMessage("The fsw resource is now in state {0}.", new object[]
                            {
                                state
                            });
                            if (state != AmResourceState.Online)
                            {
                                flag = true;
                            }
                        }
                        catch (ClusterException ex)
                        {
                            output.AppendLogMessage("Bringing the FSW resource online failed, so it will be deleted and recreated. For the record, the error was {0}", new object[]
                            {
                                ex
                            });
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        if (amClusterResource != null)
                        {
                            amClusterResource.Dispose();
                            amClusterResource = null;
                        }
                        output.AppendLogMessage("CreateFileShareWitnessQuorum: Calling RevertToMnsQuorum to clean everything up first.", new object[0]);
                        DagHelper.RevertToMnsQuorum(output, cluster);
                        string text = string.Format("File Share Witness ({0})", fswShare);
                        output.AppendLogMessage("Creating a new file share witness resource named '{0}'.", new object[]
                        {
                            text
                        });
                        amClusterResource = amClusterGroup.CreateResource(text, "File Share Witness");
                        DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare);
                    }
                    output.AppendLogMessage("The FSW resource is now in state {0}.", new object[]
                    {
                        amClusterResource.GetState()
                    });
                    string text2;
                    uint   maxLogSize;
                    string quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize);
                    output.AppendLogMessage("The current quorum resource is '{0}'. About to set it to the FSW.", new object[]
                    {
                        quorumResourceInformation
                    });
                    state = amClusterResource.GetState();
                    if (state != AmResourceState.Online)
                    {
                        output.WriteErrorSimple(new DagTaskFileShareWitnessResourceIsStillNotOnlineException(fswShare, state.ToString()));
                    }
                    cluster.SetQuorumResource(amClusterResource, null, maxLogSize);
                    quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize);
                    output.AppendLogMessage("The quorum resource is now '{0}'.", new object[]
                    {
                        quorumResourceInformation
                    });
                    output.AppendLogMessage("Bringing the quorum resource online...", new object[0]);
                    amClusterResource.OnlineResource();
                }
                finally
                {
                    if (amClusterResource != null)
                    {
                        amClusterResource.Dispose();
                        amClusterResource = null;
                    }
                }
            }
        }