use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AWSCostStatsService method createAccountStats.
protected void createAccountStats(AWSCostStatsCreationContext statsData, LocalDate billMonth, AwsAccountDetailDto awsAccountDetailDto) {
Consumer<ComputeState> accountStatsProcessor = (accountComputeState) -> {
ComputeStats accountStats = new ComputeStats();
accountStats.statValues = new ConcurrentHashMap<>();
accountStats.computeLink = accountComputeState.documentSelfLink;
if (isBillUpdated(statsData, awsAccountDetailDto)) {
logWithContext(statsData, Level.INFO, () -> String.format("Persisting cost of Account: %s (%s) for month: %s", awsAccountDetailDto.id, accountComputeState.documentSelfLink, billMonth));
ServiceStat costStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.COST), awsAccountDetailDto.billProcessedTimeMillis, awsAccountDetailDto.cost);
accountStats.statValues.put(costStat.name, Collections.singletonList(costStat));
ServiceStat otherCostsStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), AWSConstants.OTHER_CHARGES, awsAccountDetailDto.billProcessedTimeMillis, awsAccountDetailDto.otherCharges);
accountStats.statValues.put(otherCostsStat.name, Collections.singletonList(otherCostsStat));
ServiceStat oneTimeChargesStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), PhotonModelConstants.ACCOUNT_ONE_TIME_CHARGES, awsAccountDetailDto.billProcessedTimeMillis, awsAccountDetailDto.accountOneTimeCharges);
accountStats.statValues.put(oneTimeChargesStat.name, Collections.singletonList(oneTimeChargesStat));
}
if (!accountStats.statValues.isEmpty()) {
statsData.statsResponse.statsList.add(accountStats);
}
};
processAccountStats(statsData, billMonth, awsAccountDetailDto, accountStatsProcessor);
ResourceMetrics prevMarkerMetrics = statsData.accountsMarkersMap.get(awsAccountDetailDto.id);
if (prevMarkerMetrics != null) {
prevMarkerMetrics.entries.putAll(transformMapDataTypes(awsAccountDetailDto.lineCountPerInterval));
}
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class VSphereAdapterStatsService method persistStats.
private void persistStats(List<ServiceStat> stats, ComputeStatsRequest statsRequest) {
ComputeStats cs = new ComputeStats();
cs.computeLink = statsRequest.resourceReference.toString();
cs.statValues = new HashMap<>();
if (stats != null) {
for (ServiceStat stat : stats) {
cs.statValues.put(stat.name, Collections.singletonList(stat));
}
}
SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
respBody.statsList = new ArrayList<>();
respBody.statsList.add(cs);
respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsRequest.nextStage);
respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
// Verify if this makes sense? These tasks should always be local to deployment?
this.sendRequest(Operation.createPatch(statsRequest.taskReference).setBody(respBody));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class MockStatsAdapter method sendBatchResponse.
private void sendBatchResponse(ComputeStatsRequest statsRequest, SingleResourceStatsCollectionTaskState statsResponse, Map<String, List<ServiceStat>> statValues, boolean isFinalBatch) {
ComputeStats cStat = new ComputeStats();
cStat.statValues = statValues;
cStat.computeLink = statsRequest.resourceReference.getPath();
cStat.addCustomProperty("prop1", "val1");
statsResponse.statsList = new ArrayList<>();
statsResponse.statsList.add(cStat);
statsResponse.taskStage = SingleResourceTaskCollectionStage.valueOf(statsRequest.nextStage);
statsResponse.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
statsResponse.isFinalBatch = isFinalBatch;
this.sendRequest(Operation.createPatch(statsRequest.taskReference).setBody(statsResponse));
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AWSCostStatsService method createStatsForResource.
private ComputeStats createStatsForResource(String resourceLink, AwsResourceDetailDto resourceDetails) {
ComputeStats resourceStats = new ComputeStats();
resourceStats.statValues = new ConcurrentSkipListMap<>();
resourceStats.computeLink = resourceLink;
List<ServiceStat> resourceServiceStats = new ArrayList<>();
String normalizedStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.COST);
for (Entry<Long, Double> cost : resourceDetails.directCosts.entrySet()) {
ServiceStat resourceStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), normalizedStatKeyValue, cost.getKey(), cost.getValue());
resourceServiceStats.add(resourceStat);
}
resourceStats.statValues.put(normalizedStatKeyValue, resourceServiceStats);
// Create a stat to represent how many hours a resource ran as reserve instance
String normalizedReservedInstanceStatKey = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.RESERVED_INSTANCE_DURATION);
List<ServiceStat> reservedInstanceStats = new ArrayList<>();
for (Entry<Long, Double> entry : resourceDetails.hoursAsReservedPerDay.entrySet()) {
ServiceStat resourceStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(AWSConstants.UNIT_HOURS), normalizedReservedInstanceStatKey, entry.getKey(), entry.getValue());
reservedInstanceStats.add(resourceStat);
}
logFine(() -> String.format("Reserved Instances stats count for %s is %d", resourceLink, reservedInstanceStats.size()));
if (reservedInstanceStats.size() > 0) {
resourceStats.statValues.put(normalizedReservedInstanceStatKey, reservedInstanceStats);
}
return resourceStats;
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostStatsService method createComputeStatsForResource.
private ComputeStats createComputeStatsForResource(String resourceLink, AzureResource azureResource) {
String currencyUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
String costStatName = AzureStatsNormalizer.getNormalizedStatKeyValue(AzureCostConstants.COST);
ComputeStats resourceComputeStats = new ComputeStats();
resourceComputeStats.statValues = new HashMap<>();
resourceComputeStats.computeLink = resourceLink;
azureResource.cost.forEach((dayOfMonth, cost) -> {
List<ServiceStat> vmCostStats = new ArrayList<>();
ServiceStat vmCostStat = AzureCostHelper.createServiceStat(costStatName, cost, currencyUnit, dayOfMonth);
vmCostStats.add(vmCostStat);
resourceComputeStats.statValues.put(costStatName, vmCostStats);
});
return resourceComputeStats;
}
Aggregations