Пример #1
0
        private IList <Endpoint> ReadEndpoints(CoreTopology coreTopology, ReadReplicaTopology rrTopology, Policy policy)
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ISet <ServerInfo> possibleReaders = rrTopology.Members().SetOfKeyValuePairs().Select(entry => new ServerInfo(entry.Value.connectors().boltAddress(), entry.Key, entry.Value.groups())).collect(Collectors.toSet());

            if (_allowReadsOnFollowers || possibleReaders.Count == 0)
            {
                ISet <MemberId> validCores = coreTopology.Members().Keys;
                try
                {
                    MemberId leader = _leaderLocator.Leader;
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                    validCores = validCores.Where(memberId => !memberId.Equals(leader)).collect(Collectors.toSet());
                }
                catch (NoLeaderFoundException)
                {
                    // we might end up using the leader for reading during this ttl, should be fine in general
                }

                foreach (MemberId validCore in validCores)
                {
                    Optional <CoreServerInfo> coreServerInfo = coreTopology.find(validCore);
                    coreServerInfo.ifPresent(coreServerInfo1 => possibleReaders.Add(new ServerInfo(coreServerInfo1.connectors().boltAddress(), validCore, coreServerInfo1.groups())));
                }
            }

            ISet <ServerInfo> readers = policy.Apply(possibleReaders);

            return(readers.Select(r => Endpoint.read(r.boltAddress())).ToList());
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupplyDefaultUnfilteredPolicyForEmptyContext() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSupplyDefaultUnfilteredPolicyForEmptyContext()
        {
            // given
            Policies policies = new Policies(_log);

            // when
            Policy            policy = policies.SelectFor(emptyMap());
            ISet <ServerInfo> input  = asSet(new ServerInfo(new AdvertisedSocketAddress("bolt", 1), new MemberId(System.Guid.randomUUID()), asSet("groupA")), new ServerInfo(new AdvertisedSocketAddress("bolt", 2), new MemberId(System.Guid.randomUUID()), asSet("groupB"))
                                             );

            ISet <ServerInfo> output = policy.Apply(input);

            // then
            assertEquals(input, output);
            assertEquals(Policies.DefaultPolicyConflict, policy);
        }
Пример #3
0
        /// <summary>
        /// Returns whether there is sufficient disk space quota for the requested space.
        /// </summary>
        /// <param name="space">Amount of space requested.</param>
        /// <returns>True if the requested space is under the quota limit. Otherwise false is returned.</returns>
        public bool Allowed(long space)
        {
            bool hasSpace = true;

            // Check the overall domain/member policy first to make sure that there
            // is space available.
            if (memberPolicy != null)
            {
                // Apply the rule to see if there is space available.
                Rule.Result result = memberPolicy.Apply(usedDiskSpace + space, DiskSpaceQuotaPolicyID);
                if (result == Rule.Result.Allow)
                {
                    // If there is a collection policy, let it update the
                    // used disk space.
                    if (collectionPolicy == null)
                    {
                        // Update the snapshot.
                        usedDiskSpace += space;
                    }
                }
                else
                {
                    hasSpace = false;
                }
            }

            // See if there is a collection policy that limits the amount of data
            // in the collection.
            if ((collectionPolicy != null) && (hasSpace == true))
            {
                // Apply the rule to see if there is space available in the collection.
                Rule.Result result = collectionPolicy.Apply(collectionSpace + space, null);
                if (result == Rule.Result.Allow)
                {
                    usedDiskSpace   += space;
                    collectionSpace += space;
                }
                else
                {
                    hasSpace = false;
                }
            }

            return(hasSpace);
        }
Пример #4
0
        /// <summary>
        /// Returns whether the specified file is allowed to pass through the filter.
        /// </summary>
        /// <param name="fileName">Name of the file including its extension.</param>
        /// <returns>True if the file is allowed to pass through the filter. Otherwise false is returned.</returns>
        public bool Allowed(string fileName)
        {
            bool   isAllowed = true;
            string fullPath  = Path.GetFileName(fileName);

            // Check the overall domain/member policy first to make sure that the file type is not excluded.
            if (memberPolicy != null)
            {
                // Apply the rule to see if there is space available.
                isAllowed = (memberPolicy.Apply(fullPath, FileTypeFilterPolicyID) == Rule.Result.Allow);
            }

            if ((collectionPolicy != null) && isAllowed)
            {
                // Apply the rule to see if the file type is allowed in the collection.
                isAllowed = (collectionPolicy.Apply(fullPath, FileTypeFilterPolicyID) == Rule.Result.Allow);
            }
            return(isAllowed);
        }
Пример #5
0
        /// <summary>
        /// Returns whether the specified file size is allowed to pass through the filter.
        /// </summary>
        /// <param name="fileSize">Size in bytes of a file.</param>
        /// <returns>True if the file size is allowed to pass through the filter. Otherwise false is returned.</returns>
        public bool Allowed(long fileSize)
        {
            bool isAllowed = true;

            // Check the overall domain/member policy first to make sure that the
            // file size doesn't exceed the limit.
            if (memberPolicy != null)
            {
                // Apply the rule to see if there is space available.
                isAllowed = (memberPolicy.Apply(fileSize, FileSizeFilterPolicyID) == Rule.Result.Allow);
            }

            // See if there is a collection policy that limits the size of a file in the collection.
            if ((collectionPolicy != null) && isAllowed)
            {
                // Apply the rule to see if the file size exceeds the policy on the collection.
                isAllowed = (collectionPolicy.Apply(fileSize, null) == Rule.Result.Allow);
            }

            return(isAllowed);
        }