コード例 #1
0
        /// <summary>
        /// Checks the current resource less than or equal with the other resource by comparing all the fields in the resource.
        /// </summary>
        /// <param name="other">The resource to compare</param>
        /// <returns>True if current resource is less than or equal with the other resource, otherwise return false.</returns>
        public bool LessThanOrEqual(ResourceSpec other)
        {
            Preconditions.CheckNotNull(other, "Cannot compare with null resources");

            if (Equals(Unknown) && other.Equals(Unknown))
            {
                return(true);
            }

            if (Equals(Unknown) || other.Equals(Unknown))
            {
                throw new IllegalArgumentException("Cannot compare specified resources with UNKNOWN resources.");
            }

            var cmp1 = CpuCores.Value < other.CpuCores.Value;
            var cmp2 = TaskHeapMemory.CompareTo(other.TaskHeapMemory);
            var cmp3 = TaskOffHeapMemory.CompareTo(other.TaskOffHeapMemory);
            var cmp4 = OnHeapManagedMemory.CompareTo(other.OnHeapManagedMemory);
            var cmp5 = OffHeapManagedMemory.CompareTo(other.OffHeapManagedMemory);

            if (cmp1 && cmp2 <= 0 && cmp3 <= 0 && cmp4 <= 0 && cmp5 <= 0)
            {
                foreach (var resource in ExtendedResources.Values)
                {
                    if (!other.ExtendedResources.ContainsKey(resource.Name) ||
                        (other.ExtendedResources.TryGetValue(resource.Name, out var it) && it.Value < resource.Value))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }