private static ensureResourceGovernanceMetrics()

in src/Sfx/App/Scripts/ViewModels/MetricsViewModel.ts [46:108]


        private static ensureResourceGovernanceMetrics(metrics: LoadMetricInformation[]): LoadMetricInformation[] {
            let cpuCapacityAvailable: boolean = false;
            let memoryCapacityAvailable: boolean = false;
            let metricsWithResourceGov: LoadMetricInformation[] = _.map(metrics, m => {
                if (m.name === "servicefabric:/_CpuCores") {
                    cpuCapacityAvailable = true;
                } else if (m.name === "servicefabric:/_MemoryInMB") {
                    memoryCapacityAvailable = true;
                }
                return m;
            });
            if (!cpuCapacityAvailable) {
                let zeroCpuCapacity: LoadMetricInformation = new LoadMetricInformation(null, {
                    Name: "servicefabric:/_CpuCores",
                    IsBalancedBefore: true,
                    IsBalancedAfter: true,
                    DeviationBefore: "",
                    DeviationAfter: "",
                    BalancingThreshold: "",
                    Action: "",
                    ActivityThreshold: "",
                    ClusterCapacity: 0,
                    ClusterLoad: 0,
                    CurrentClusterLoad: 0,
                    RemainingUnbufferedCapacity: 0,
                    NodeBufferPercentage: 0,
                    BufferedCapacity: 0,
                    RemainingBufferedCapacity: 0,
                    IsClusterCapacityViolation: false,
                    MinNodeLoadValue: 0,
                    MinNodeLoadId: null,
                    MaxNodeLoadValue: 0,
                    MaxNodeLoadId: null
                });
                metricsWithResourceGov.unshift(zeroCpuCapacity);
            }
            if (!memoryCapacityAvailable) {
                let zeroMemoryCapacity: LoadMetricInformation = new LoadMetricInformation(null, {
                    Name: "servicefabric:/_MemoryInMB",
                    IsBalancedBefore: true,
                    IsBalancedAfter: true,
                    DeviationBefore: "",
                    DeviationAfter: "",
                    BalancingThreshold: "",
                    Action: "",
                    ActivityThreshold: "",
                    ClusterCapacity: 0,
                    ClusterLoad: 0,
                    CurrentClusterLoad: 0,
                    RemainingUnbufferedCapacity: 0,
                    NodeBufferPercentage: 0,
                    BufferedCapacity: 0,
                    RemainingBufferedCapacity: 0,
                    IsClusterCapacityViolation: false,
                    MinNodeLoadValue: 0,
                    MinNodeLoadId: null,
                    MaxNodeLoadValue: 0,
                    MaxNodeLoadId: null
                });
                metricsWithResourceGov.unshift(zeroMemoryCapacity);
            }
            return metricsWithResourceGov;
        }