use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostHelper method createMonthlyEaAccountCostStats.
static List<ComputeStats> createMonthlyEaAccountCostStats(Map<LocalDate, EaAccountCost> monthlyEaAccountCosts, Map<LocalDate, Double> monthlyTotalCosts, ComputeStateWithDescription computeHostDesc) {
List<ComputeStats> accountStats = new ArrayList<>();
String usageCostStatName = AzureCostConstants.USAGE_COST;
String marketplaceCostStatName = AzureCostConstants.MARKETPLACE_COST;
String separatelyBilledCostStatName = AzureCostConstants.SEPARATELY_BILLED_COST;
String costUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
for (Entry<LocalDate, Double> monthlyTotalCost : monthlyTotalCosts.entrySet()) {
ComputeStats accountStat = new ComputeStats();
accountStat.computeLink = computeHostDesc.documentSelfLink;
accountStat.statValues = new ConcurrentSkipListMap<>();
LocalDate month = monthlyTotalCost.getKey();
long timeStamp = adaptMonthToCostTimeStamp(month);
EaAccountCost eaAccountCost = monthlyEaAccountCosts.get(month);
ServiceStat usageCostServiceStat = AzureCostHelper.createServiceStat(usageCostStatName, eaAccountCost.monthlyEaAccountUsageCost, costUnit, timeStamp);
ServiceStat marketplaceCostServiceStat = AzureCostHelper.createServiceStat(marketplaceCostStatName, eaAccountCost.monthlyEaAccountMarketplaceCost, costUnit, timeStamp);
ServiceStat separatelyBilledCostServiceStat = AzureCostHelper.createServiceStat(separatelyBilledCostStatName, eaAccountCost.monthlyEaAccountSeparatelyBilledCost, costUnit, timeStamp);
accountStat.statValues.put(usageCostStatName, Collections.singletonList(usageCostServiceStat));
accountStat.statValues.put(marketplaceCostStatName, Collections.singletonList(marketplaceCostServiceStat));
accountStat.statValues.put(separatelyBilledCostStatName, Collections.singletonList(separatelyBilledCostServiceStat));
accountStats.add(accountStat);
}
return accountStats;
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostHelper method createOldestBillDownloadedStat.
static ComputeStats createOldestBillDownloadedStat(ComputeStateWithDescription computeHostDesc, long billParsedMillis, long currentMonthBillParsedMillis) {
ComputeStats stats = new ComputeStats();
stats.computeLink = computeHostDesc.documentSelfLink;
stats.statValues = new ConcurrentSkipListMap<>();
stats.addCustomProperty(PhotonModelConstants.CONTAINS_BILL_PROCESSED_TIME_STAT, Boolean.TRUE.toString());
ServiceStat oldestBillDownloadedStat = AzureCostHelper.createServiceStat(AzureCostConstants.OLDEST_BILL_PROCESSED_MILLIS, billParsedMillis, PhotonModelConstants.UNIT_MILLISECONDS, currentMonthBillParsedMillis);
stats.statValues.put(oldestBillDownloadedStat.name, Collections.singletonList(oldestBillDownloadedStat));
return stats;
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostHelper method createApiKeyExpiresTimeStat.
static ComputeStats createApiKeyExpiresTimeStat(ComputeStateWithDescription computeHostDesc, long keyExpiryTime) {
ComputeStats accountStats = new ComputeStats();
accountStats.computeLink = computeHostDesc.documentSelfLink;
accountStats.statValues = new ConcurrentSkipListMap<>();
ServiceStat keyExpiryTimeMillis = AzureCostHelper.createServiceStat(AzureCostConstants.EA_ACCOUNT_USAGE_KEY_EXPIRY_TIME_MILLIS, keyExpiryTime, PhotonModelConstants.UNIT_MILLISECONDS, AzureCostHelper.getMillisNow());
accountStats.statValues.put(keyExpiryTimeMillis.name, Collections.singletonList(keyExpiryTimeMillis));
return accountStats;
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AWSCostStatsService method createServiceStatsForAccount.
protected void createServiceStatsForAccount(AWSCostStatsCreationContext statsData, LocalDate billMonth, AwsAccountDetailDto awsAccountDetailDto) {
Consumer<ComputeState> serviceStatsProcessor = (accountComputeState) -> {
ComputeStats awsServiceStats = new ComputeStats();
awsServiceStats.statValues = new ConcurrentHashMap<>();
awsServiceStats.computeLink = accountComputeState.documentSelfLink;
awsServiceStats.addCustomProperty(PhotonModelConstants.DOES_CONTAIN_SERVICE_STATS, Boolean.TRUE.toString());
for (AwsServiceDetailDto serviceDetailDto : awsAccountDetailDto.serviceDetailsMap.values()) {
Map<String, List<ServiceStat>> statsForAwsService = createStatsForAwsService(serviceDetailDto);
awsServiceStats.statValues.putAll(statsForAwsService);
}
if (!awsServiceStats.statValues.isEmpty()) {
statsData.statsResponse.statsList.add(awsServiceStats);
}
};
insertEC2ServiceDetail(awsAccountDetailDto);
processAccountStats(statsData, billMonth, awsAccountDetailDto, serviceStatsProcessor);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AWSCostStatsService method createResourceStatsForAccount.
protected void createResourceStatsForAccount(AWSCostStatsCreationContext statsData, AwsAccountDetailDto awsAccountDetailDto) {
Map<String, AwsServiceDetailDto> serviceDetails = awsAccountDetailDto.serviceDetailsMap;
List<AwsServices> supportedServices = Arrays.asList(AwsServices.EC2_Instance_Usage, AwsServices.EC2_EBS, AwsServices.S3);
for (String service : serviceDetails.keySet()) {
if (!supportedServices.contains(AwsServices.getByName(service))) {
continue;
}
Map<String, AwsResourceDetailDto> resourceDetailsMap = serviceDetails.get(service).resourceDetailsMap;
if (resourceDetailsMap == null) {
continue;
}
for (Entry<String, AwsResourceDetailDto> entry : resourceDetailsMap.entrySet()) {
String resourceId = entry.getKey();
AwsResourceDetailDto resourceDetails = entry.getValue();
if ((resourceDetails == null) || (resourceDetails.directCosts == null)) {
continue;
}
Set<String> resourceLinks = statsData.awsResourceLinksById.getOrDefault(resourceId, Collections.emptySet());
for (String resourceStateLink : resourceLinks) {
ComputeStats resourceStats = createStatsForResource(resourceStateLink, resourceDetails);
statsData.statsResponse.statsList.add(resourceStats);
}
}
}
}
Aggregations