protected void InitializeLagTimes(DatabaseCopy preExistingCopy)
 {
     if (base.Fields["ReplayLagTime"] == null)
     {
         if (preExistingCopy == null)
         {
             this.m_replayLagTime = EnhancedTimeSpan.Parse("00:00:00");
         }
         else
         {
             this.m_replayLagTime = preExistingCopy.ReplayLagTime;
         }
     }
     else
     {
         this.m_replayLagTime = this.ReplayLagTime;
     }
     if (base.Fields["TruncationLagTime"] != null)
     {
         this.m_truncationLagTime = this.TruncationLagTime;
         return;
     }
     if (preExistingCopy == null)
     {
         this.m_truncationLagTime = EnhancedTimeSpan.Parse("00:00:00");
         return;
     }
     this.m_truncationLagTime = preExistingCopy.TruncationLagTime;
 }
Ejemplo n.º 2
0
 public static ADDatabaseCopyWrapper CreateWrapper(DatabaseCopy databaseCopy)
 {
     if (databaseCopy == null)
     {
         return(null);
     }
     return(new ADDatabaseCopyWrapper(databaseCopy));
 }
Ejemplo n.º 3
0
        protected DatabaseCopy SaveDBCopy()
        {
            TaskLogger.LogEnter();
            DatabaseCopy databaseCopy = null;

            if (this.preExistingDatabase != null)
            {
                foreach (DatabaseCopy databaseCopy2 in this.preExistingDatabase.InvalidDatabaseCopies)
                {
                    if (databaseCopy2.Name.Equals(this.OwnerServer.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        databaseCopy = databaseCopy2;
                        break;
                    }
                }
            }
            DatabaseCopy databaseCopy3 = databaseCopy ?? new DatabaseCopy();

            databaseCopy3.HostServer = (ADObjectId)this.OwnerServer.Identity;
            if (databaseCopy == null)
            {
                databaseCopy3.ActivationPreference = 1;
            }
            else
            {
                databaseCopy3.ActivationPreference = databaseCopy3.ActivationPreference;
            }
            ADRawEntry  adrawEntry = databaseCopy3;
            TDataObject dataObject = this.DataObject;

            adrawEntry.SetId(dataObject.Id.GetChildId(this.OwnerServer.Name));
            databaseCopy3.ParentObjectClass = ((this.DatabaseType == NewDatabaseTask <TDataObject> .ExchangeDatabaseType.Public) ? PublicFolderDatabase.MostDerivedClass : MailboxDatabase.MostDerivedClass);
            TDataObject dataObject2 = this.DataObject;
            ActivationPreferenceSetter <DatabaseCopy> activationPreferenceSetter = new ActivationPreferenceSetter <DatabaseCopy>(dataObject2.AllDatabaseCopies, databaseCopy3, (databaseCopy == null) ? EntryAction.Insert : EntryAction.Modify);
            UpdateResult updateResult = activationPreferenceSetter.UpdateCachedValues();

            if (updateResult == UpdateResult.AllChanged)
            {
                activationPreferenceSetter.SaveAllUpdatedValues(base.DataSession);
            }
            base.DataSession.Save(databaseCopy3);
            this.forcedReplicationSites = DagTaskHelper.DetermineRemoteSites(base.GlobalConfigSession, databaseCopy3.OriginatingServer, this.OwnerServer);
            if (this.forcedReplicationSites != null)
            {
                ITopologyConfigurationSession session = (ITopologyConfigurationSession)base.DataSession;
                TDataObject dataObject3    = this.DataObject;
                string      objectIdentity = dataObject3.Identity.ToString();
                if (DagTaskHelper.ForceReplication(session, this.DataObject, this.forcedReplicationSites, objectIdentity, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose)))
                {
                    DagTaskHelper.ForceReplication(session, databaseCopy3, this.forcedReplicationSites, objectIdentity, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                }
            }
            TaskLogger.LogExit();
            return(databaseCopy3);
        }
Ejemplo n.º 4
0
 private ADDatabaseCopyWrapper(DatabaseCopy copy) : base(copy)
 {
     this.DatabaseName                 = copy.DatabaseName;
     this.HostServerName               = copy.HostServerName;
     this.HostServer                   = copy.HostServer;
     this.ReplayLagTime                = copy.ReplayLagTime;
     this.TruncationLagTime            = copy.TruncationLagTime;
     this.ActivationPreferenceInternal = copy.ActivationPreferenceInternal;
     this.IsValidForRead               = copy.IsValidForRead;
     this.IsHostServerPresent          = copy.IsHostServerPresent;
 }
        private void VerifyCopyResponse(DatabaseCopy copy, string sourceServer, string sourceDb,
                                        string destServer, string destDb, bool isLocalDatabaseReplicationTarget,
                                        bool isContinuous, bool?isOfflineSecondary)
        {
            Assert.AreEqual(sourceServer, copy.SourceServerName);
            Assert.AreEqual(sourceDb, copy.SourceDatabaseName);
            Assert.AreEqual(destServer, copy.DestinationServerName);
            Assert.AreEqual(destDb, copy.DestinationDatabaseName);
            Assert.AreEqual(isContinuous, copy.IsContinuous);
            Assert.AreEqual(isLocalDatabaseReplicationTarget, copy.IsLocalDatabaseReplicationTarget);
            Assert.IsTrue(copy.IsInterlinkConnected);
            if (isOfflineSecondary.HasValue)
            {
                Assert.AreEqual(isOfflineSecondary, copy.IsOfflineSecondary);
            }

            if (IsRunningAgainstOneBox)
            {
                Assert.IsTrue(copy.StartDate > TestStartTime);
                Assert.IsTrue(copy.StartDate < DateTime.Now);
                Assert.IsTrue(copy.ModifyDate > TestStartTime);
                Assert.IsTrue(copy.ModifyDate < DateTime.Now);
                Assert.IsTrue(copy.StartDate <= copy.ModifyDate);
            }

            switch (copy.ReplicationStateDescription)
            {
            case "PENDING":
                Assert.IsTrue((int)copy.PercentComplete == 0);
                break;

            case "SEEDING":
                Assert.IsTrue(copy.PercentComplete > 0 && copy.PercentComplete < 100);
                break;

            case "CATCH_UP":
                Assert.AreEqual(100, copy.PercentComplete);
                Assert.IsTrue(copy.IsContinuous);
                break;

            case "":
                // After forced terminate, on the other side.
                Assert.IsFalse(copy.IsInterlinkConnected);
                break;

            default:
                Assert.Fail("Unexpected ReplicationStateDescription: " +
                            copy.ReplicationStateDescription);
                break;
            }
        }
Ejemplo n.º 6
0
        public static void GetMailboxCopyPostAction(DataRow inputRow, DataTable dataTable, DataObjectStore store)
        {
            DataRow                 dataRow                 = dataTable.Rows[0];
            MailboxDatabase         mailboxDatabase         = (MailboxDatabase)store.GetDataObject("MailboxDatabaseFoGet");
            DatabaseCopyStatusEntry databaseCopyStatusEntry = (DatabaseCopyStatusEntry)store.GetDataObject("DatabaseCopyStatusEntry");
            DatabaseCopy            databaseCopy            = null;

            foreach (DatabaseCopy databaseCopy2 in mailboxDatabase.DatabaseCopies)
            {
                if (string.Equals(databaseCopyStatusEntry.MailboxServer, databaseCopy2.HostServerName, StringComparison.InvariantCultureIgnoreCase))
                {
                    databaseCopy = databaseCopy2;
                    break;
                }
            }
            if (databaseCopy != null)
            {
                dataRow["ActivationPreference"] = databaseCopy.ActivationPreference;
                dataRow["DatabaseCopiesLength"] = mailboxDatabase.DatabaseCopies.Length;
                dataRow["ReplayLagTime"]        = databaseCopy.ReplayLagTime.ToString(TimeUnit.Day, 9);
            }
        }
Ejemplo n.º 7
0
        public static void ValidateDatabaseCopyActionTask(DatabaseCopy databaseCopy, bool allowInvalidDbCopy, bool fCheckDbReplicated, IConfigDataProvider session, ObjectId rootId, Task.TaskErrorLoggingDelegate writeError, LocalizedString mdbNotUniqueError, LocalizedString?singleDbCopyError, out Server server)
        {
            string databaseName = databaseCopy.DatabaseName;

            server = null;
            Database database = databaseCopy.GetDatabase <Database>();

            DatabaseTasksHelper.CheckDatabaseForCopyTaskImpl(database, fCheckDbReplicated, writeError, singleDbCopyError);
            if (database.Recovery)
            {
                writeError(new InvalidOperationException(Strings.ErrorInvalidOperationOnRecoveryMailboxDatabase(database.Name)), ErrorCategory.InvalidOperation, database.Identity);
            }
            if (databaseCopy.HostServer != null)
            {
                MailboxServerIdParameter serverIdParam = new MailboxServerIdParameter(databaseCopy.HostServer);
                server = databaseCopy.Session.Read <Server>(databaseCopy.HostServer);
                DatabaseTasksHelper.CheckServerObjectForCopyTask(serverIdParam, writeError, server);
                return;
            }
            if (!allowInvalidDbCopy && !databaseCopy.IsHostServerValid)
            {
                writeError(new InvalidOperationException(Strings.ErrorDbCopyHostServerInvalid(databaseCopy.Name)), ErrorCategory.InvalidData, databaseCopy);
            }
        }
Ejemplo n.º 8
0
 public void AddToDatabaseCopies(DatabaseCopy databaseCopy)
 {
     base.AddObject("DatabaseCopies", databaseCopy);
 }
Ejemplo n.º 9
0
 public static DatabaseCopy CreateDatabaseCopy(int localDatabaseId, bool isContinuous, bool isLocalDatabaseReplicationTarget, byte replicationState, bool isInterlinkConnected, global::System.Guid entityId)
 {
     DatabaseCopy databaseCopy = new DatabaseCopy();
     databaseCopy.LocalDatabaseId = localDatabaseId;
     databaseCopy.IsContinuous = isContinuous;
     databaseCopy.IsLocalDatabaseReplicationTarget = isLocalDatabaseReplicationTarget;
     databaseCopy.ReplicationState = replicationState;
     databaseCopy.IsInterlinkConnected = isInterlinkConnected;
     databaseCopy.EntityId = entityId;
     return databaseCopy;
 }
Ejemplo n.º 10
0
 private void RollbackOperation(MailboxDatabase mdb, DatabaseCopy dbCopy, ADSystemMailbox systemMailbox)
 {
     if (mdb == null || dbCopy == null)
     {
         if (systemMailbox != null)
         {
             try
             {
                 base.WriteVerbose(Strings.VerboseDeleteSystemMailbox(systemMailbox.Id.ToString()));
                 this.RecipientSessionForSystemMailbox.Delete(systemMailbox);
             }
             catch (DataSourceTransientException ex)
             {
                 this.WriteWarning(Strings.FailedToDeleteSystemMailbox(systemMailbox.Identity.ToString(), ex.Message));
                 TaskLogger.Trace("Failed to delete System Mailbox {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     systemMailbox.Identity,
                     mdb.Identity,
                     ex.ToString()
                 });
             }
             catch (DataSourceOperationException ex2)
             {
                 this.WriteWarning(Strings.FailedToDeleteSystemMailbox(systemMailbox.Identity.ToString(), ex2.Message));
                 TaskLogger.Trace("Failed to delete System Mailbox {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     systemMailbox.Identity,
                     mdb.Identity,
                     ex2.ToString()
                 });
             }
         }
         if (dbCopy != null)
         {
             try
             {
                 base.WriteVerbose(Strings.VerboseDeleteDBCopy(dbCopy.Id.ToString()));
                 base.DataSession.Delete(dbCopy);
             }
             catch (DataSourceTransientException ex3)
             {
                 this.WriteWarning(Strings.FailedToDeleteDatabaseCopy(dbCopy.Identity.ToString(), ex3.Message));
                 TaskLogger.Trace("Failed to delete Database Copy {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     dbCopy.Identity,
                     mdb.Identity,
                     ex3.ToString()
                 });
             }
             catch (DataSourceOperationException ex4)
             {
                 this.WriteWarning(Strings.FailedToDeleteDatabaseCopy(dbCopy.Identity.ToString(), ex4.Message));
                 TaskLogger.Trace("Failed to delete Database Copy {0} when rolling back created database object '{1}'. {2}", new object[]
                 {
                     dbCopy.Identity,
                     mdb.Identity,
                     ex4.ToString()
                 });
             }
         }
         if (mdb != null)
         {
             try
             {
                 base.WriteVerbose(Strings.VerboseDeleteMDB(mdb.Id.ToString()));
                 base.DataSession.Delete(mdb);
                 DatabaseTasksHelper.RemoveDatabaseFromClusterDB((ITopologyConfigurationSession)base.DataSession, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError), mdb);
             }
             catch (DataSourceTransientException ex5)
             {
                 this.WriteWarning(Strings.FailedToDeleteMailboxDatabase(mdb.Identity.ToString(), ex5.Message));
                 TaskLogger.Trace("Failed to delete Mailbox Database {0} when rolling back. {1}", new object[]
                 {
                     mdb.Identity,
                     ex5.ToString()
                 });
             }
             catch (DataSourceOperationException ex6)
             {
                 this.WriteWarning(Strings.FailedToDeleteMailboxDatabase(mdb.Identity.ToString(), ex6.Message));
                 TaskLogger.Trace("Failed to delete Mailbox Database {0} when rolling back. {1}", new object[]
                 {
                     mdb.Identity,
                     ex6.ToString()
                 });
             }
             catch (ClusterException ex7)
             {
                 this.WriteWarning(Strings.FailedToDeleteMailboxDatabase(mdb.Identity.ToString(), ex7.Message));
                 TaskLogger.Trace("Failed to delete Mailbox Database {0} when rolling back. {1}", new object[]
                 {
                     mdb.Identity,
                     ex7.ToString()
                 });
             }
         }
     }
 }
Ejemplo n.º 11
0
 public DatabaseCopyIdParameter(DatabaseCopy databaseCopy) : base(databaseCopy.Id)
 {
 }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            base.InternalProcessRecord();
            if (this.m_invalidDbCopy == null && !this.m_fConfigOnly)
            {
                ReplayState.DeleteState(this.m_server.Fqdn, this.DataObject, true);
            }
            DatabaseCopy databaseCopy = this.m_invalidDbCopy ?? new DatabaseCopy();

            databaseCopy.HostServer = (ADObjectId)this.m_server.Identity;
            if (base.Fields["ActivationPreference"] == null)
            {
                if (this.m_invalidDbCopy == null)
                {
                    this.ActivationPreference = (uint)(this.DataObject.AllDatabaseCopies.Length + 1);
                }
                else
                {
                    this.ActivationPreference = (uint)this.m_invalidDbCopy.ActivationPreference;
                }
            }
            databaseCopy.ActivationPreference = (int)this.ActivationPreference;
            DatabaseCopy databaseCopy2 = null;

            if (databaseCopy.ActivationPreference == 1)
            {
                databaseCopy2 = databaseCopy;
            }
            else if (this.ActivationPreference != 0U)
            {
                databaseCopy2 = SetMailboxDatabaseCopy.GetDatabaseCopyOfPreference1(new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), this.DataObject, databaseCopy);
            }
            ActivationPreferenceSetter <DatabaseCopy> activationPreferenceSetter = new ActivationPreferenceSetter <DatabaseCopy>(this.DataObject.AllDatabaseCopies, databaseCopy, (this.m_invalidDbCopy == null) ? EntryAction.Insert : EntryAction.Modify);
            UpdateResult updateResult = activationPreferenceSetter.UpdateCachedValues();

            if (updateResult == UpdateResult.AllChanged)
            {
                activationPreferenceSetter.SaveAllUpdatedValues(base.DataSession);
            }
            databaseCopy.ReplayLagTime     = this.m_replayLagTime;
            databaseCopy.TruncationLagTime = this.m_truncationLagTime;
            databaseCopy.SetId(this.DataObject.Id.GetChildId(this.m_server.Name.ToUpperInvariant()));
            databaseCopy.ParentObjectClass = (this.DataObject.IsPublicFolderDatabase ? PublicFolderDatabase.MostDerivedClass : MailboxDatabase.MostDerivedClass);
            if (databaseCopy2 != null)
            {
                base.WriteVerbose(Strings.UpdatingLegDnForDatabaseCopy(databaseCopy.Name));
                ITopologyConfigurationSession adSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, base.SessionSettings, 338, "InternalProcessRecord", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\database\\AddMailboxDatabaseCopy.cs");
                SetMailboxDatabaseCopy.UpdateServerLegdnForDatabaseSite(new Task.TaskErrorLoggingDelegate(base.WriteError), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), adSession, databaseCopy2);
            }
            base.WriteVerbose(Strings.UpdatingDatabaseCopyObject(databaseCopy.HostServer.Name, databaseCopy.ReplayLagTime.ToString(), databaseCopy.TruncationLagTime.ToString()));
            base.DataSession.Save(databaseCopy);
            MailboxDatabase database = databaseCopy.GetDatabase <MailboxDatabase>();

            if (this.m_firstCopy && database.DataMoveReplicationConstraint == DataMoveReplicationConstraintParameter.None)
            {
                database.DataMoveReplicationConstraint = DataMoveReplicationConstraintParameter.SecondCopy;
                base.DataSession.Save(database);
                base.WriteVerbose(Strings.ConstraintUpgrade(database.Identity.ToString(), DataMoveReplicationConstraintParameter.None, DataMoveReplicationConstraintParameter.SecondCopy));
            }
            ITopologyConfigurationSession topologyConfigurationSession = (ITopologyConfigurationSession)base.DataSession;

            ADObjectId[] array = DagTaskHelper.DetermineRemoteSites(topologyConfigurationSession, databaseCopy.OriginatingServer, this.m_server);
            if (array != null)
            {
                DagTaskHelper.ForceReplication(topologyConfigurationSession, databaseCopy, array, this.DataObject.Identity.ToString(), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
            }
            if (!this.m_fConfigOnly)
            {
                this.RunSourceConfigurationUpdaterRpc();
            }
            if (!this.IsThirdPartyReplicationEnabled && !this.m_SeedingPostponedSpecified && !base.SeedingPostponed && !this.m_fConfigOnly)
            {
                base.CreateTargetEdbDirectory();
                base.PerformSeedIfNecessary();
            }
            if (!this.m_fConfigOnly)
            {
                this.RunTargetConfigurationUpdaterRpc();
            }
            this.WriteWarning(Strings.WarnAdministratorToRestartService(this.m_server.Name));
            TaskLogger.LogExit();
        }
 public static ADDatabaseCopyWrapper CreateWrapper(DatabaseCopy databaseCopy)
 {
     return(ADDatabaseCopyWrapper.CreateWrapper(databaseCopy));
 }
Ejemplo n.º 14
0
 public static void CheckDatabaseCopyForCopyTask(Database database, Task.TaskErrorLoggingDelegate writeError, Server server, out DatabaseCopy databaseCopy, out DatabaseCopy[] databaseCopies)
 {
     databaseCopy   = null;
     databaseCopies = database.GetDatabaseCopies();
     if (databaseCopies == null || databaseCopies.Length == 0)
     {
         writeError(new CopyConfigurationErrorException(Strings.ErrorCouldNotReadDatabaseCopy(database.Name)), ErrorCategory.ReadError, database.Identity);
     }
     else
     {
         foreach (DatabaseCopy databaseCopy2 in databaseCopies)
         {
             if (databaseCopy2.HostServer.ObjectGuid == server.Guid)
             {
                 databaseCopy = databaseCopy2;
                 break;
             }
         }
     }
     if (databaseCopy == null && database.ReplicationType == ReplicationType.Remote)
     {
         writeError(new InvalidOperationException(Strings.ErrorDbCopyNotHostedOnServer(database.Identity.ToString(), server.Identity.ToString())), ErrorCategory.InvalidData, database.Identity);
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            // Obtain the database name from the given parameters.
            string databaseName = null;

            if (this.MyInvocation.BoundParameters.ContainsKey("Database"))
            {
                databaseName = this.Database.Name;
            }
            else if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseName"))
            {
                databaseName = this.DatabaseName;
            }

            string partnerDatabaseName = this.PartnerDatabase == null ?
                                         databaseName : this.PartnerDatabase;

            // Do nothing if force is not specified and user cancelled the operation
            string actionDescription = string.Format(
                CultureInfo.InvariantCulture,
                Resources.StartAzureSqlDatabaseCopyDescription,
                this.ConnectionContext.ServerName,
                databaseName,
                this.PartnerServer,
                partnerDatabaseName);
            string actionWarning = string.Format(
                CultureInfo.InvariantCulture,
                Resources.StartAzureSqlDatabaseCopyWarning,
                this.ConnectionContext.ServerName,
                databaseName,
                this.PartnerServer,
                partnerDatabaseName);

            this.WriteVerbose(actionDescription);
            if (!this.Force.IsPresent &&
                !this.ShouldProcess(
                    actionDescription,
                    actionWarning,
                    Resources.ShouldProcessCaption))
            {
                return;
            }

            try
            {
                int?maxLagInMinutes =
                    this.MyInvocation.BoundParameters.ContainsKey("MaxLagInMinutes") ?
                    (int?)this.MaxLagInMinutes : null;

                // Update the database with the specified name
                DatabaseCopy databaseCopy = this.ConnectionContext.StartDatabaseCopy(
                    databaseName,
                    this.PartnerServer,
                    partnerDatabaseName,
                    maxLagInMinutes,
                    this.ContinuousCopy.IsPresent);

                this.WriteObject(databaseCopy, true);
            }
            catch (Exception ex)
            {
                SqlDatabaseExceptionHandler.WriteErrorDetails(
                    this,
                    this.ConnectionContext.ClientRequestId,
                    ex);
            }
        }