Ejemplo n.º 1
0
        public override string ToString()
        {
            StringBuilder compliantBlocksSB = new StringBuilder();

            compliantBlocksSB.Append("\nBlocks satisfying the specified storage policy:");
            compliantBlocksSB.Append("\nStorage Policy                  # of blocks       % of blocks\n"
                                     );
            StringBuilder nonCompliantBlocksSB  = new StringBuilder();
            Formatter     compliantFormatter    = new Formatter(compliantBlocksSB);
            Formatter     nonCompliantFormatter = new Formatter(nonCompliantBlocksSB);
            NumberFormat  percentFormat         = NumberFormat.GetPercentInstance();

            percentFormat.SetMinimumFractionDigits(4);
            percentFormat.SetMaximumFractionDigits(4);
            foreach (KeyValuePair <StoragePolicySummary.StorageTypeAllocation, long> storageComboCount
                     in SortByComparator(storageComboCounts))
            {
                double percent = (double)storageComboCount.Value / (double)totalBlocks;
                StoragePolicySummary.StorageTypeAllocation sta = storageComboCount.Key;
                if (sta.PolicyMatches())
                {
                    compliantFormatter.Format("%-25s %10d  %20s%n", sta.GetStoragePolicyDescriptor(),
                                              storageComboCount.Value, percentFormat.Format(percent));
                }
                else
                {
                    if (nonCompliantBlocksSB.Length == 0)
                    {
                        nonCompliantBlocksSB.Append("\nBlocks NOT satisfying the specified storage policy:"
                                                    );
                        nonCompliantBlocksSB.Append("\nStorage Policy                  ");
                        nonCompliantBlocksSB.Append("Specified Storage Policy      # of blocks       % of blocks\n"
                                                    );
                    }
                    nonCompliantFormatter.Format("%-35s %-20s %10d  %20s%n", sta.GetStoragePolicyDescriptor
                                                     (), sta.GetSpecifiedStoragePolicy().GetName(), storageComboCount.Value, percentFormat
                                                 .Format(percent));
                }
            }
            if (nonCompliantBlocksSB.Length == 0)
            {
                nonCompliantBlocksSB.Append("\nAll blocks satisfy specified storage policy.\n");
            }
            compliantFormatter.Close();
            nonCompliantFormatter.Close();
            return(compliantBlocksSB.ToString() + nonCompliantBlocksSB);
        }
Ejemplo n.º 2
0
        // Add a storage type combination
        internal virtual void Add(StorageType[] storageTypes, BlockStoragePolicy policy)
        {
            StoragePolicySummary.StorageTypeAllocation storageCombo = new StoragePolicySummary.StorageTypeAllocation
                                                                          (storageTypes, policy);
            long count = storageComboCounts[storageCombo];

            if (count == null)
            {
                storageComboCounts[storageCombo] = 1l;
                storageCombo.SetActualStoragePolicy(GetStoragePolicy(storageCombo.GetStorageTypes
                                                                         ()));
            }
            else
            {
                storageComboCounts[storageCombo] = count + 1;
            }
            totalBlocks++;
        }