Beispiel #1
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            DatabaseAvailabilityGroupNetwork dataObject                = this.DataObject;
            IConfigurationSession            configSession             = this.SetupAdSession();
            DatabaseAvailabilityGroup        databaseAvailabilityGroup = DagTaskHelper.DagIdParameterToDag(this.DatabaseAvailabilityGroup, configSession);

            DagTaskHelper.VerifyDagAndServersAreWithinScopes <DatabaseAvailabilityGroupNetwork>(this, databaseAvailabilityGroup, true);
            if (databaseAvailabilityGroup.IsDagEmpty())
            {
                base.WriteError(new DagNetworkEmptyDagException(databaseAvailabilityGroup.Name), ErrorCategory.InvalidArgument, null);
            }
            DagTaskHelper.PreventTaskWhenAutoNetConfigIsEnabled(databaseAvailabilityGroup, this);
            DagNetworkObjectId identity = new DagNetworkObjectId(databaseAvailabilityGroup.Name, dataObject.Name);

            dataObject.SetIdentity(identity);
            DagNetworkConfigDataProvider     dagNetworkConfigDataProvider     = (DagNetworkConfigDataProvider)base.DataSession;
            DagNetworkConfiguration          dagNetworkConfiguration          = dagNetworkConfigDataProvider.ReadNetConfig(databaseAvailabilityGroup);
            DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork = dagNetworkConfiguration.FindNetwork(dataObject.Name);

            if (databaseAvailabilityGroupNetwork != null)
            {
                throw new DagNetworkManagementException(ServerStrings.DagNetworkCreateDupName(dataObject.Name));
            }
            DagNetworkValidation.ValidateSwitches(dataObject, new Task.TaskErrorLoggingDelegate(base.WriteError));
            if (base.Fields["Subnets"] != null)
            {
                DagNetworkValidation.ValidateSubnets(this.Subnets, dagNetworkConfiguration, this.Name, null, new Task.TaskErrorLoggingDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                dataObject.ReplaceSubnets(this.Subnets);
            }
            TaskLogger.LogExit();
        }
        private List <DatabaseAvailabilityGroupNetwork> Find(QueryFilter queryFilter, ObjectId rootId, bool deepSearch, SortBy sortBy)
        {
            List <DatabaseAvailabilityGroupNetwork> list = new List <DatabaseAvailabilityGroupNetwork>();
            DagNetworkQueryFilter dagNetworkQueryFilter  = null;

            if (queryFilter != null)
            {
                dagNetworkQueryFilter = (queryFilter as DagNetworkQueryFilter);
            }
            IEnumerable <DatabaseAvailabilityGroup> enumerable;

            if (this.TargetDag != null)
            {
                enumerable = new DatabaseAvailabilityGroup[]
                {
                    this.TargetDag
                };
            }
            else
            {
                string identity = "*";
                if (dagNetworkQueryFilter != null && dagNetworkQueryFilter.NamesToMatch != null && dagNetworkQueryFilter.NamesToMatch.DagName != null)
                {
                    identity = dagNetworkQueryFilter.NamesToMatch.DagName;
                }
                DatabaseAvailabilityGroupIdParameter databaseAvailabilityGroupIdParameter = DatabaseAvailabilityGroupIdParameter.Parse(identity);
                enumerable = databaseAvailabilityGroupIdParameter.GetObjects <DatabaseAvailabilityGroup>(null, this.m_adSession);
            }
            if (enumerable != null)
            {
                Regex regex = null;
                if (dagNetworkQueryFilter != null && dagNetworkQueryFilter.NamesToMatch != null && dagNetworkQueryFilter.NamesToMatch.NetName != null)
                {
                    string pattern = Wildcard.ConvertToRegexPattern(dagNetworkQueryFilter.NamesToMatch.NetName);
                    regex = new Regex(pattern, RegexOptions.IgnoreCase);
                }
                foreach (DatabaseAvailabilityGroup databaseAvailabilityGroup in enumerable)
                {
                    DagNetworkConfiguration dagNetworkConfiguration = (this.m_targetServer == null) ? DagNetworkRpc.GetDagNetworkConfig(databaseAvailabilityGroup) : DagNetworkRpc.GetDagNetworkConfig(this.m_targetServer);
                    if (dagNetworkConfiguration != null && dagNetworkConfiguration.Networks != null)
                    {
                        this.m_netConfig = dagNetworkConfiguration;
                        foreach (DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork in dagNetworkConfiguration.Networks)
                        {
                            if (regex == null || regex.IsMatch(databaseAvailabilityGroupNetwork.Name))
                            {
                                DagNetworkObjectId identity2 = new DagNetworkObjectId(databaseAvailabilityGroup.Name, databaseAvailabilityGroupNetwork.Name);
                                databaseAvailabilityGroupNetwork.SetIdentity(identity2);
                                databaseAvailabilityGroupNetwork.ResetChangeTracking();
                                list.Add(databaseAvailabilityGroupNetwork);
                            }
                        }
                    }
                }
            }
            return(list);
        }
        public void Delete(IConfigurable instance)
        {
            DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork = (DatabaseAvailabilityGroupNetwork)instance;
            DagNetworkObjectId dagNetworkObjectId = (DagNetworkObjectId)databaseAvailabilityGroupNetwork.Identity;

            this.GetDagByName(dagNetworkObjectId.DagName);
            RemoveDagNetworkRequest removeDagNetworkRequest = new RemoveDagNetworkRequest();

            removeDagNetworkRequest.Name = dagNetworkObjectId.NetName;
            DagNetworkRpc.RemoveDagNetwork(this.m_dag, removeDagNetworkRequest);
        }
        public void Save(IConfigurable instance)
        {
            DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork = (DatabaseAvailabilityGroupNetwork)instance;
            DagNetworkObjectId   dagNetworkObjectId   = (DagNetworkObjectId)databaseAvailabilityGroupNetwork.Identity;
            SetDagNetworkRequest setDagNetworkRequest = new SetDagNetworkRequest();

            if (dagNetworkObjectId == null)
            {
                setDagNetworkRequest.Name = databaseAvailabilityGroupNetwork.Name;
            }
            else
            {
                setDagNetworkRequest.Name = dagNetworkObjectId.NetName;
            }
            if (databaseAvailabilityGroupNetwork.IsChanged(DatabaseAvailabilityGroupNetworkSchema.Name))
            {
                setDagNetworkRequest.NewName = databaseAvailabilityGroupNetwork.Name;
            }
            if (databaseAvailabilityGroupNetwork.IsChanged(DatabaseAvailabilityGroupNetworkSchema.Description))
            {
                setDagNetworkRequest.Description = databaseAvailabilityGroupNetwork.Description;
            }
            if (databaseAvailabilityGroupNetwork.IsChanged(DatabaseAvailabilityGroupNetworkSchema.ReplicationEnabled))
            {
                setDagNetworkRequest.ReplicationEnabled = databaseAvailabilityGroupNetwork.ReplicationEnabled;
            }
            if (databaseAvailabilityGroupNetwork.IsChanged(DatabaseAvailabilityGroupNetworkSchema.IgnoreNetwork))
            {
                setDagNetworkRequest.IgnoreNetwork = databaseAvailabilityGroupNetwork.IgnoreNetwork;
            }
            if (databaseAvailabilityGroupNetwork.IsChanged(DatabaseAvailabilityGroupNetworkSchema.Subnets))
            {
                setDagNetworkRequest.SubnetListIsSet = true;
                foreach (DatabaseAvailabilityGroupNetworkSubnet databaseAvailabilityGroupNetworkSubnet in databaseAvailabilityGroupNetwork.Subnets)
                {
                    setDagNetworkRequest.Subnets.Add(databaseAvailabilityGroupNetworkSubnet.SubnetId, null);
                }
            }
            this.GetDagByName(dagNetworkObjectId.DagName);
            DagNetworkRpc.SetDagNetwork(this.m_dag, setDagNetworkRequest);
            DagNetworkObjectId identity = new DagNetworkObjectId(this.m_dag.Name, databaseAvailabilityGroupNetwork.Name);

            databaseAvailabilityGroupNetwork.SetIdentity(identity);
            databaseAvailabilityGroupNetwork.ResetChangeTracking();
            this.m_dagNet = databaseAvailabilityGroupNetwork;
        }
Beispiel #5
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            DatabaseAvailabilityGroupNetwork dataObject = this.DataObject;
            DagNetworkObjectId dagNetworkObjectId       = (DagNetworkObjectId)dataObject.Identity;

            ExTraceGlobals.CmdletsTracer.TraceError <string>((long)this.GetHashCode(), "Validating SetDAGNetwork({0})", dagNetworkObjectId.FullName);
            IConfigurationSession     configSession = this.SetupAdSession();
            DatabaseAvailabilityGroup dag           = DagTaskHelper.ReadDagByName(dagNetworkObjectId.DagName, configSession);

            DagTaskHelper.VerifyDagAndServersAreWithinScopes <DatabaseAvailabilityGroupNetwork>(this, dag, true);
            DagTaskHelper.PreventTaskWhenAutoNetConfigIsEnabled(dag, this);
            DagNetworkConfigDataProvider     dagNetworkConfigDataProvider = (DagNetworkConfigDataProvider)base.DataSession;
            DagNetworkConfiguration          networkConfig = dagNetworkConfigDataProvider.NetworkConfig;
            DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork = (DatabaseAvailabilityGroupNetwork)dataObject.GetOriginalObject();
            string name = databaseAvailabilityGroupNetwork.Name;
            DatabaseAvailabilityGroupNetwork networkBeingChanged = null;

            foreach (DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork2 in networkConfig.Networks)
            {
                if (databaseAvailabilityGroupNetwork2 == dataObject)
                {
                    networkBeingChanged = databaseAvailabilityGroupNetwork2;
                }
                else if (DatabaseAvailabilityGroupNetwork.NameComparer.Equals(databaseAvailabilityGroupNetwork2.Name, dataObject.Name))
                {
                    throw new DagNetworkManagementException(ServerStrings.DagNetworkRenameDupName(name, dataObject.Name));
                }
            }
            DagNetworkValidation.ValidateSwitches(dataObject, new Task.TaskErrorLoggingDelegate(base.WriteError));
            if (base.Fields["Subnets"] != null)
            {
                DagNetworkValidation.ValidateSubnets(this.Subnets, networkConfig, dataObject.Name, networkBeingChanged, new Task.TaskErrorLoggingDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                dataObject.ReplaceSubnets(this.Subnets);
            }
            DagNetworkValidation.WarnIfAllNetsAreDisabled(networkConfig, new Task.TaskWarningLoggingDelegate(this.WriteWarning));
            TaskLogger.LogExit();
        }
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            this.m_output = new HaTaskOutputHelper("remove-databaseavailabilitygroupnetwork", new Task.TaskErrorLoggingDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskProgressLoggingDelegate(base.WriteProgress), this.GetHashCode());
            DatabaseAvailabilityGroupNetwork dataObject = base.DataObject;
            DagNetworkObjectId dagNetworkObjectId       = (DagNetworkObjectId)dataObject.Identity;

            ExTraceGlobals.CmdletsTracer.TraceError <string>((long)this.GetHashCode(), "Validating RemoveDAGNetwork({0})", dagNetworkObjectId.FullName);
            IConfigurationSession     configSession = this.SetupAdSession();
            DatabaseAvailabilityGroup dag           = DagTaskHelper.ReadDagByName(dagNetworkObjectId.DagName, configSession);

            DagTaskHelper.VerifyDagAndServersAreWithinScopes <DatabaseAvailabilityGroupNetwork>(this, dag, true);
            DagTaskHelper.PreventTaskWhenAutoNetConfigIsEnabled(dag, this);
            foreach (DatabaseAvailabilityGroupNetworkSubnet databaseAvailabilityGroupNetworkSubnet in dataObject.Subnets)
            {
                if (databaseAvailabilityGroupNetworkSubnet.State != DatabaseAvailabilityGroupNetworkSubnet.SubnetState.Unknown)
                {
                    this.m_output.WriteErrorSimple(new DagNetworkManagementException(ServerStrings.DagNetworkCannotRemoveActiveSubnet(dataObject.Name)));
                }
            }
            TaskLogger.LogExit();
        }
Beispiel #7
0
 public Identity(DagNetworkObjectId id) : this(id.FullName, id.NetName)
 {
 }
 public DagNetworkQueryFilter(DagNetworkObjectId networkNames)
 {
     this.m_networkNames = networkNames;
 }