Example #1
0
 public bool Exists()
 {
     if (!this.m_initialized)
     {
         string ex = Strings.DagFswInternalErrorFswObjectNotInitialized.ToString();
         if (this.m_initializationException != null)
         {
             ex = this.m_initializationException.Message;
         }
         throw new DagFswNotInitializedException(ex);
     }
     if (this.m_exists == null)
     {
         try
         {
             string text;
             byte[] securityDescriptorBinaryForm;
             NetShare.GetShareInfoWithSecurity(this.WitnessServerFqdn, this.ShareName, out text, out this.m_existingShareRemark, out this.m_shareType, out this.m_sharePermissions, out this.m_shareMaxUses, out securityDescriptorBinaryForm);
             this.m_existingWitnessDirectory = NonRootLocalLongFullPath.Parse(text);
             TaskLogger.Trace("Found existing witness share \\\\{0}\\{1} pointing to {2} (expecting {3})", new object[]
             {
                 this.WitnessServer,
                 this.ShareName,
                 text,
                 this.m_witnessDirectory.ToString()
             });
             if (this.m_existingWitnessDirectory != this.WitnessDirectory)
             {
                 throw new DagFswSharePointsToWrongDirectoryException(this.ShareName, this.WitnessServerFqdn, this.m_existingWitnessDirectory.ToString(), this.WitnessDirectory.ToString());
             }
             this.m_existingSecurity = new DirectorySecurity();
             this.m_existingSecurity.SetSecurityDescriptorBinaryForm(securityDescriptorBinaryForm);
             this.m_exists = new bool?(true);
         }
         catch (Win32Exception ex2)
         {
             if ((long)ex2.NativeErrorCode == 2310L)
             {
                 this.m_exists = new bool?(false);
             }
             else
             {
                 if (ex2.NativeErrorCode == 5)
                 {
                     throw new DagFswInsufficientPermissionsToAccessFswException(this.WitnessServerFqdn, ex2);
                 }
                 throw new DagFswServerNotAccessibleException(this.WitnessServerFqdn, ex2);
             }
         }
     }
     return(this.m_exists.Value);
 }
Example #2
0
 public FileShareWitness(ITopologyConfigurationSession adSession, string dagName, FileShareWitnessServerName witnessServer, NonRootLocalLongFullPath witnessDirectory, IAmCluster cluster) : this(adSession, dagName, witnessServer, witnessDirectory)
 {
     this.m_clusterReference.SetTarget(cluster);
 }
Example #3
0
 public FileShareWitness(ITopologyConfigurationSession adSession, string dagName, FileShareWitnessServerName witnessServer, NonRootLocalLongFullPath witnessDirectory) : this(adSession, dagName)
 {
     this.m_witnessServer    = witnessServer;
     this.m_witnessDirectory = witnessDirectory;
 }
Example #4
0
        public bool Initialize()
        {
            if (this.m_witnessServer == null)
            {
                List <string> frontendTransportServersInLocalSite = ReplayConfiguration.GetFrontendTransportServersInLocalSite();
                if (frontendTransportServersInLocalSite != null && frontendTransportServersInLocalSite.Count > 0)
                {
                    foreach (string text in frontendTransportServersInLocalSite)
                    {
                        if (!this.ServerHasMailboxRole(text))
                        {
                            if (!FileShareWitnessServerName.TryParse(text, out this.m_witnessServer))
                            {
                                TaskLogger.Trace("Attempt to parse FrontendTransport server name {0} to its file share witness name failed.", new object[]
                                {
                                    text
                                });
                                break;
                            }
                            break;
                        }
                    }
                }
                if (this.m_witnessServer == null)
                {
                    this.m_initializationException = new DagFswUnableToDetermineFrontendTransportServerException();
                    throw this.m_initializationException;
                }
            }
            try
            {
                this.AssignWitnessServerFqdn();
            }
            catch (ArgumentException ex)
            {
                this.m_initializationException = new DagFswUnableToParseWitnessServerNameException(ex);
                throw this.m_initializationException;
            }
            catch (ErrorUnableToFindFqdnForHostADErrorException ex2)
            {
                this.m_initializationException = new DagFswUnableToParseWitnessServerNameException(ex2);
                throw this.m_initializationException;
            }
            string text2 = this.WitnessServer.DomainName;

            if (string.IsNullOrEmpty(text2))
            {
                int num = this.WitnessServerFqdn.IndexOf('.');
                if (num > -1)
                {
                    text2 = this.WitnessServerFqdn.Substring(num + 1);
                }
            }
            string arg = string.Format(FileShareWitness.s_dagShareNameFormat, this.m_dagName, text2);

            UncFileSharePath.TryParse(string.Format(FileShareWitness.s_uncPathFormat, this.WitnessServerFqdn, arg), out this.m_fileShareWitnessShare);
            if (this.m_witnessDirectory == null)
            {
                string text3 = WmiWrapper.TryGetSystemDrive(this.WitnessServerFqdn);
                if (text3 == null)
                {
                    this.m_initializationException = new DagFswUnableToBindWitnessDirectoryException(this.WitnessServerFqdn);
                    throw this.m_initializationException;
                }
                this.m_witnessDirectory = NonRootLocalLongFullPath.Parse(string.Format(FileShareWitness.s_defaultDirectoryFormat, text3, arg));
            }
            this.m_initialized = true;
            return(this.m_initialized);
        }
        internal static NonRootLocalLongFullPath GetDefaultLogFolderPath(string databaseName, string serverDataPath, ADObjectId OwnerServerId, IEnumerable <Database> existingDatabases, Task.TaskErrorLoggingDelegate logError)
        {
            string        value         = LocalLongFullPath.ConvertInvalidCharactersInFileName(databaseName);
            StringBuilder stringBuilder = new StringBuilder(serverDataPath);

            stringBuilder.Append(Path.DirectorySeparatorChar.ToString()).Append(value);
            string text = null;
            NonRootLocalLongFullPath nonRootLocalLongFullPath = null;
            Exception ex = null;

            try
            {
                text = stringBuilder.ToString();
                nonRootLocalLongFullPath = NonRootLocalLongFullPath.Parse(text);
                nonRootLocalLongFullPath.ValidateDirectoryPathLength();
                for (int i = 0; i < 200; i++)
                {
                    bool flag = false;
                    foreach (Database database in existingDatabases)
                    {
                        if (nonRootLocalLongFullPath == database.LogFolderPath)
                        {
                            if (database.Servers != null && database.Servers.Length != 0)
                            {
                                foreach (ADObjectId adobjectId in database.Servers)
                                {
                                    if (OwnerServerId == adobjectId)
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                            }
                            else if (OwnerServerId == database.Server)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        break;
                    }
                    text = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[]
                    {
                        stringBuilder,
                        i + 1
                    });
                    nonRootLocalLongFullPath = NonRootLocalLongFullPath.Parse(text);
                    nonRootLocalLongFullPath.ValidateDirectoryPathLength();
                }
            }
            catch (ArgumentException ex2)
            {
                ex = ex2;
            }
            catch (FormatException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                nonRootLocalLongFullPath = null;
                if (logError != null)
                {
                    logError(new InvalidOperationException(Strings.ErrorFailToParseLocalLongFullPath(databaseName, DatabaseSchema.LogFolderPath.Name, text, ex.Message)), ErrorCategory.InvalidOperation, databaseName);
                }
            }
            return(nonRootLocalLongFullPath);
        }
Example #6
0
        private void ProcessFileShareWitness()
        {
            FileShareWitnessServerName fileShareWitnessServerName = this.AlternateWitnessServer ?? this.m_dag.AlternateWitnessServer;
            NonRootLocalLongFullPath   nonRootLocalLongFullPath   = this.AlternateWitnessDirectory ?? this.m_dag.AlternateWitnessDirectory;

            if (this.UsePrimaryWitnessServer)
            {
                fileShareWitnessServerName = this.m_dag.WitnessServer;
                nonRootLocalLongFullPath   = this.m_dag.WitnessDirectory;
            }
            string serverName = (fileShareWitnessServerName != null) ? fileShareWitnessServerName.ToString() : Strings.CreateAltFswWillAutomaticallyCalculateLater;
            string filePath   = (nonRootLocalLongFullPath != null) ? nonRootLocalLongFullPath.ToString() : Strings.CreateAltFswWillAutomaticallyCalculateLater;

            this.m_output.WriteProgressIncrementalSimple(Strings.ProgressCreateAltFsw(serverName, filePath), 10);
            this.m_afsw = new FileShareWitness((ITopologyConfigurationSession)base.DataSession, this.m_dag.Name, fileShareWitnessServerName, nonRootLocalLongFullPath);
            try
            {
                this.m_afsw.Initialize();
            }
            catch (LocalizedException error)
            {
                this.m_output.WriteErrorSimple(error);
            }
            this.CheckFsw(this.m_afsw.WitnessServerFqdn);
            if (SharedHelper.StringIEquals(this.m_afsw.WitnessServer.ToString(), this.m_dag.WitnessServer.ToString()) && this.m_dag.WitnessDirectory != this.m_afsw.WitnessDirectory)
            {
                this.m_output.WriteErrorSimple(new DagFswAndAlternateFswOnSameWitnessServerButPointToDifferentDirectoriesException(this.m_afsw.WitnessServer.ToString(), this.m_dag.WitnessDirectory.ToString(), this.m_afsw.WitnessDirectory.ToString()));
            }
            if (!this.UsePrimaryWitnessServer)
            {
                this.m_dag.SetAlternateWitnessServer(this.m_afsw.FileShareWitnessShare, this.m_afsw.WitnessDirectory);
            }
            else
            {
                this.m_dag.SetWitnessServer(this.m_afsw.FileShareWitnessShare, this.m_afsw.WitnessDirectory);
            }
            base.DataSession.Save(this.m_dag);
            try
            {
                this.m_output.AppendLogMessage("Creating the file share of the FSW...", new object[0]);
                this.m_afsw.Create();
                if (this.m_dag.Servers.Count == 0 && this.m_afsw.IsJustCreated)
                {
                    this.m_output.AppendLogMessage("Because there are no servers in the DAG, and the file share witness was just created, then the permissions may be incorrect (the CNO account might not yet exist). Deleting the FSW.", new object[0]);
                    this.m_afsw.Delete();
                }
            }
            catch (LocalizedException ex)
            {
                this.m_output.AppendLogMessage("There was an exception encountered during creation and/or deletion of the FSW ('{0}'). If it was an error during deletion, then we'll just ignore it.", new object[]
                {
                    ex.Message
                });
                if (this.m_afsw.GetExceptionType(ex) != FileShareWitnessExceptionType.FswDeleteError)
                {
                    this.m_output.WriteWarning(ex.LocalizedString);
                }
                else
                {
                    this.m_output.AppendLogMessage("Yes, it was a an error related to deleting the FSW. Continuing on.", new object[0]);
                }
            }
        }
Example #7
0
 internal void SetAlternateWitnessServer(UncFileSharePath alternateWitnessServer, NonRootLocalLongFullPath alternateWitnessDirectory)
 {
     this[DatabaseAvailabilityGroupSchema.AlternateWitnessServer]    = alternateWitnessServer;
     this[DatabaseAvailabilityGroupSchema.AlternateWitnessDirectory] = alternateWitnessDirectory;
 }