Exemplo n.º 1
0
        public async Task <ClusterLoadInformation> GetClusterLoadAsync()
        {
            ClusterLoadInformation loadInfo = await this.fabricClient.QueryManager.GetClusterLoadInformationAsync();

            long replicaCount = await this.GetClusterReplicaCountAsync();

            foreach (string systemService in systemMetrics)
            {
                LoadMetricInformation item = loadInfo.LoadMetricInformationList.FirstOrDefault(x => String.Equals(x.Name, systemService, StringComparison.OrdinalIgnoreCase));
                if (item != null)
                {
                    loadInfo.LoadMetricInformationList.Remove(item);
                }
            }

            Type t = typeof(LoadMetricInformation);
            LoadMetricInformation countMetric = new LoadMetricInformation();

            t.GetProperty("Name").SetValue(countMetric, CountMetricName);
            t.GetProperty("ClusterBufferedCapacity").SetValue(countMetric, 0);
            t.GetProperty("ClusterCapacity").SetValue(countMetric, 0);
            t.GetProperty("ClusterLoad").SetValue(countMetric, replicaCount);
            t.GetProperty("ClusterRemainingBufferedCapacity").SetValue(countMetric, -1);
            t.GetProperty("ClusterRemainingCapacity").SetValue(countMetric, -1);
            t.GetProperty("IsClusterCapacityViolation").SetValue(countMetric, false);
            t.GetProperty("NodeBufferPercentage").SetValue(countMetric, 0);
            t.GetProperty("IsBalancedBefore").SetValue(countMetric, true);
            t.GetProperty("IsBalancedAfter").SetValue(countMetric, true);
            t.GetProperty("DeviationBefore").SetValue(countMetric, 0);
            t.GetProperty("DeviationAfter").SetValue(countMetric, 0);
            t.GetProperty("BalancingThreshold").SetValue(countMetric, 0);
            t.GetProperty("MaxNodeLoadNodeId").SetValue(countMetric, new NodeId(new System.Numerics.BigInteger(0), new System.Numerics.BigInteger(0)));
            t.GetProperty("MinNodeLoadNodeId").SetValue(countMetric, new NodeId(new System.Numerics.BigInteger(0), new System.Numerics.BigInteger(0)));

            loadInfo.LoadMetricInformationList.Add(countMetric);

            return(loadInfo);
        }
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, LoadMetricInformation obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            if (obj.Name != null)
            {
                writer.WriteProperty(obj.Name, "Name", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.IsBalancedBefore != null)
            {
                writer.WriteProperty(obj.IsBalancedBefore, "IsBalancedBefore", JsonWriterExtensions.WriteBoolValue);
            }

            if (obj.IsBalancedAfter != null)
            {
                writer.WriteProperty(obj.IsBalancedAfter, "IsBalancedAfter", JsonWriterExtensions.WriteBoolValue);
            }

            if (obj.DeviationBefore != null)
            {
                writer.WriteProperty(obj.DeviationBefore, "DeviationBefore", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.DeviationAfter != null)
            {
                writer.WriteProperty(obj.DeviationAfter, "DeviationAfter", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.BalancingThreshold != null)
            {
                writer.WriteProperty(obj.BalancingThreshold, "BalancingThreshold", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.Action != null)
            {
                writer.WriteProperty(obj.Action, "Action", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ActivityThreshold != null)
            {
                writer.WriteProperty(obj.ActivityThreshold, "ActivityThreshold", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ClusterCapacity != null)
            {
                writer.WriteProperty(obj.ClusterCapacity, "ClusterCapacity", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ClusterLoad != null)
            {
                writer.WriteProperty(obj.ClusterLoad, "ClusterLoad", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.CurrentClusterLoad != null)
            {
                writer.WriteProperty(obj.CurrentClusterLoad, "CurrentClusterLoad", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ClusterRemainingCapacity != null)
            {
                writer.WriteProperty(obj.ClusterRemainingCapacity, "ClusterRemainingCapacity", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ClusterCapacityRemaining != null)
            {
                writer.WriteProperty(obj.ClusterCapacityRemaining, "ClusterCapacityRemaining", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.IsClusterCapacityViolation != null)
            {
                writer.WriteProperty(obj.IsClusterCapacityViolation, "IsClusterCapacityViolation", JsonWriterExtensions.WriteBoolValue);
            }

            if (obj.NodeBufferPercentage != null)
            {
                writer.WriteProperty(obj.NodeBufferPercentage, "NodeBufferPercentage", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ClusterBufferedCapacity != null)
            {
                writer.WriteProperty(obj.ClusterBufferedCapacity, "ClusterBufferedCapacity", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.BufferedClusterCapacityRemaining != null)
            {
                writer.WriteProperty(obj.BufferedClusterCapacityRemaining, "BufferedClusterCapacityRemaining", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.ClusterRemainingBufferedCapacity != null)
            {
                writer.WriteProperty(obj.ClusterRemainingBufferedCapacity, "ClusterRemainingBufferedCapacity", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.MinNodeLoadValue != null)
            {
                writer.WriteProperty(obj.MinNodeLoadValue, "MinNodeLoadValue", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.MinimumNodeLoad != null)
            {
                writer.WriteProperty(obj.MinimumNodeLoad, "MinimumNodeLoad", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.MinNodeLoadNodeId != null)
            {
                writer.WriteProperty(obj.MinNodeLoadNodeId, "MinNodeLoadNodeId", NodeIdConverter.Serialize);
            }

            if (obj.MaxNodeLoadValue != null)
            {
                writer.WriteProperty(obj.MaxNodeLoadValue, "MaxNodeLoadValue", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.MaximumNodeLoad != null)
            {
                writer.WriteProperty(obj.MaximumNodeLoad, "MaximumNodeLoad", JsonWriterExtensions.WriteStringValue);
            }

            if (obj.MaxNodeLoadNodeId != null)
            {
                writer.WriteProperty(obj.MaxNodeLoadNodeId, "MaxNodeLoadNodeId", NodeIdConverter.Serialize);
            }

            if (obj.PlannedLoadRemoval != null)
            {
                writer.WriteProperty(obj.PlannedLoadRemoval, "PlannedLoadRemoval", JsonWriterExtensions.WriteStringValue);
            }

            writer.WriteEndObject();
        }