Пример #1
0
        /// <summary>
        /// Creates availability group using Smo
        /// </summary>
        /// <param name="agName">Availability group name.</param>
        /// <param name="dbNames">Datbases to be part of the AG.</param>
        /// <param name="replicas">replicas to be part of the AG.</param>
        /// <param name="server">smo server.</param>
        public static AvailabilityGroup CreateAG(string agName, IEnumerable <string> dbNames, IEnumerable <Smo.Server> replicas, Smo.Server server)
        {
            if (!AGHelper.IsAGExist(agName, server))
            {
                AvailabilityGroup ag = new AvailabilityGroup(server, agName);
                foreach (string dbName in dbNames)
                {
                    ag.AvailabilityDatabases.Add(new AvailabilityDatabase(ag, dbName));
                }

                foreach (Smo.Server replica in replicas)
                {
                    AvailabilityReplica ar = new AvailabilityReplica(ag, replica.Name);
                    ar.EndpointUrl      = ARHelper.GetHadrEndpointUrl(replica);
                    ar.AvailabilityMode = AvailabilityReplicaAvailabilityMode.AsynchronousCommit;
                    ar.FailoverMode     = AvailabilityReplicaFailoverMode.Manual;
                    ag.AvailabilityReplicas.Add(ar);
                }
                ag.Create();
                return(ag);
            }
            else
            {
                throw new Exception(string.Format("The requested availability Group {0} already exist in the given server {1}", agName, server.Name));
            }
        }
Пример #2
0
 /// <summary>
 /// Drop the given ag using Smo.
 /// </summary>
 /// <param name="agName">Availability group name.</param>
 /// <param name="server">smo server.</param>
 public static void DropAG(string agName, Smo.Server server)
 {
     if (AGHelper.IsAGExist(agName, server))
     {
         AvailabilityGroup ag = server.AvailabilityGroups[agName];
         ag.Drop();
     }
 }
Пример #3
0
 /// <summary>
 /// Drop availability replica from an availability group.
 /// NoOp, if availability group isn't exist or replica isn't part of the given AG.
 /// </summary>
 /// <param name="arName">Availability replica name</param>
 /// <param name="agName">Availability groups name</param>
 /// <param name="server">SMO server</param>
 public static void DropAR(string arName, string agName, SMO.Server server)
 {
     if (AGHelper.IsAGExist(agName, server) && AGHelper.AGContainsReplicas(agName, new string[] { arName }, server))
     {
         AvailabilityGroup ag = server.AvailabilityGroups[agName];
         ag.AvailabilityReplicas.Remove(arName);
     }
 }
Пример #4
0
 public void CleanUp()
 {
     if (AGHelper.IsAGExist(agName, primary))
     {
         AGHelper.DropAG(agName, primary);
     }
     CleanupDatabases();
     StopBackup();
 }
Пример #5
0
 /// <summary>
 /// Checks whether the give availability groups is enabled or not.
 /// </summary>
 /// <param name="agName">Availability group name.</param>
 /// <param name="server">smo server.</param>
 /// <returns>true if the given ag is enabled, otherwise false.</returns>
 public static bool IsAGEnabled(string agName, Smo.Server server)
 {
     if (!AGHelper.IsAGExist(agName, server))
     {
         AvailabilityGroup ag = server.AvailabilityGroups[agName];
         //TODO: AvailabilityGroup doesn't have method to enable it
         throw new NotImplementedException();
     }
     else
     {
         throw new Exception(string.Format("The requested availability Group {0} is not exist in the given server {1}", agName, server.Name));
     }
 }
Пример #6
0
        public void Setup()
        {
            agName = "HadrBenchTest";


            baseDBpath = @"\\zechen-d1\dbshare\";
            dbshare    = @"\\zechen-d1\dbshare\bench\";
            //primaryServerName = @"ze-2016-v1\sql16rtm01";
            //secondaryServerName = @"ze-2016-v2\sql16rtm01";
            // start point of dbCount, lets say 500
            primaryDbsNames = new List <string>();
            primaryDbs      = new List <Database>();

            dbCacheLock = new ReaderWriterLockSlim();

            dbCount = 0;
            // create three replicas

            replicas            = new List <Server>();
            secondaries         = new List <Server>();
            replicaEndpointUrls = new List <string>();
            primaryServerName   = string.Empty;

            Smo.Server srv;
            srv = new Smo.Server(@"ze-bench-01\hadrBenchMark01");
            replicas.Add(srv);
            // primary is important
            primaryServerName = @"ze-bench-01\hadrBenchMark01";
            primary           = srv;
            //report server always point to 01
            reportSrv        = srv;
            reportServerName = primaryServerName;
            reportDBName     = @"FailoverResult";
            string username = "******";
            string password = "******";

            reportConnecionString = string.Format("server={0}; Initial Catalog={1};uid={2}; pwd={3} ", primaryServerName, reportDBName, username, password);


            srv = new Smo.Server(@"ze-bench-02\hadrBenchMark01");
            replicas.Add(srv);
            secondaries.Add(srv);
            srv = new Smo.Server(@"ze-bench-03\hadrBenchMark01");
            replicas.Add(srv);
            secondaries.Add(srv);

            string replicaEndpointUrl = string.Empty;

            foreach (Smo.Server server in replicas)
            {
                replicaEndpointUrl = ARHelper.GetHadrEndpointUrl(server);
                replicaEndpointUrls.Add(replicaEndpointUrl);
            }



            if (!AGHelper.IsAGExist(agName, primary))
            {
                TestCreateAGWithTwoReplicasWithoutDatabase();
            }

            this.notConnectedDBs = new List <string>();


            stopBackup = false;
        }