use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostStatsService method createMonthlyStats.
private void createMonthlyStats(Context context, Stages next) {
context.billProcessedTimeMillis = context.billParsedMillis;
if (AzureCostHelper.isCurrentMonth(new LocalDate(context.billParsedMillis, DateTimeZone.UTC))) {
context.currentMonthBillParsedMillis = context.billParsedMillis;
}
context.allSubscriptionsCost.values().forEach(subscription -> createAzureSubscriptionStats(context, subscription));
List<ComputeStats> eaAccountStats = AzureCostHelper.createEaAccountStats(context.eaAcCost, context.computeHostDesc, context.currentMonthBillParsedMillis, context.billParsedMillis, context.oldestBillProcessedMillis, context.auth.privateKey);
if (eaAccountStats.size() > 0) {
context.statsResponse.statsList.addAll(eaAccountStats);
logInfo(() -> String.format("Finished collecting cost stats for the month of %s " + "for endpoint %s ", context.billMonthToDownload, context.computeHostDesc.endpointLink));
postStats(context);
}
cleanUpMonthlyData(context);
context.stage = next;
handleRequest(context);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostStatsService method createServiceStatsForSubscription.
private void createServiceStatsForSubscription(Context context, AzureSubscription subscription) {
Consumer<List<ComputeState>> serviceStatsProcessor = (subscriptionComputeStates) -> subscriptionComputeStates.forEach(subscriptionComputeState -> {
List<ComputeStats> resourceStatsList = new ArrayList<>();
ComputeStats subscriptionStats = new ComputeStats();
subscriptionStats.statValues = new ConcurrentHashMap<>();
subscriptionStats.computeLink = subscriptionComputeState.documentSelfLink;
subscriptionStats.addCustomProperty(PhotonModelConstants.DOES_CONTAIN_SERVICE_STATS, Boolean.TRUE.toString());
for (AzureService service : subscription.getServices().values()) {
List<ComputeStats> resourcesCostStats = new ArrayList<>();
Map<String, List<ServiceStat>> statsForAzureService = createStatsForAzureService(context, service, resourcesCostStats);
subscriptionStats.statValues.putAll(statsForAzureService);
resourceStatsList.addAll(resourcesCostStats);
}
if (!subscriptionStats.statValues.isEmpty()) {
context.statsResponse.statsList.add(subscriptionStats);
}
if (!resourceStatsList.isEmpty()) {
context.statsResponse.statsList.addAll(resourceStatsList);
}
});
processSubscriptionStats(context, subscription, serviceStatsProcessor);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class AzureCostHelper method createBillProcessedTimeStat.
static ComputeStats createBillProcessedTimeStat(ComputeStateWithDescription computeHostDesc, long billProcessedTimeMillis) {
// Create bill processed time stat: will be linked with the EA account's compute state
// since the bill is obtained and processed at the EA account level.
ComputeStats accountStats = new ComputeStats();
accountStats.computeLink = computeHostDesc.documentSelfLink;
accountStats.statValues = new ConcurrentSkipListMap<>();
accountStats.addCustomProperty(PhotonModelConstants.CONTAINS_BILL_PROCESSED_TIME_STAT, Boolean.TRUE.toString());
ServiceStat billProcessedTimeStat = AzureCostHelper.createServiceStat(PhotonModelConstants.CLOUD_ACCOUNT_COST_SYNC_MARKER_MILLIS, billProcessedTimeMillis, PhotonModelConstants.UNIT_MILLISECONDS, billProcessedTimeMillis);
accountStats.statValues.put(billProcessedTimeStat.name, Collections.singletonList(billProcessedTimeStat));
return accountStats;
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class TestAWSCostAdapterService method issueStatsRequest.
private void issueStatsRequest(ComputeState account) throws Throwable {
List<ComputeStats> allStats = new ArrayList<>();
// spin up a stateless service that acts as the parent link to patch back to
StatelessService parentService = new StatelessService() {
@Override
public void handleRequest(Operation op) {
if (op.getAction() == Action.PATCH) {
if (TestAWSCostAdapterService.this.isMock) {
SingleResourceStatsCollectionTaskState resp = op.getBody(SingleResourceStatsCollectionTaskState.class);
allStats.addAll(resp.statsList);
if (resp.isFinalBatch) {
verifyCollectedStats(allStats);
TestAWSCostAdapterService.this.host.completeIteration();
}
} else {
TestAWSCostAdapterService.this.host.completeIteration();
}
}
}
};
sendStatsRequest(account, parentService);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.
the class SingleResourceStatsCollectionTaskService method updateAndPersistStats.
private void updateAndPersistStats(SingleResourceStatsCollectionTaskState currentState) {
if (currentState.statsAdapterReference == null) {
throw new IllegalStateException("stats adapter reference should not be null");
}
if (currentState.statsList.size() == 0) {
// If there are no stats reported and if it's a final batch, just finish the task.
if (currentState.isFinalBatch) {
SingleResourceStatsCollectionTaskState nextStatePatch = new SingleResourceStatsCollectionTaskState();
nextStatePatch.taskInfo = TaskUtils.createTaskState(TaskStage.FINISHED);
TaskUtils.sendPatch(this, nextStatePatch);
}
return;
}
long expirationTime = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(EXPIRATION_INTERVAL);
List<Operation> operations = new ArrayList<>();
List<ResourceMetrics> metricsList = new ArrayList<>();
List<InMemoryResourceMetric> inMemoryMetricsList = new ArrayList<>();
// Push the last collection metric to the in memory stats available at the
// compute-link/stats URI.
ServiceStats.ServiceStat minuteStats = new ServiceStats.ServiceStat();
String statsLink = getAdapterLinkFromURI(currentState.statsAdapterReference);
minuteStats.name = getLastCollectionMetricKeyForAdapterLink(statsLink, true);
minuteStats.latestValue = Utils.getNowMicrosUtc();
minuteStats.sourceTimeMicrosUtc = Utils.getNowMicrosUtc();
minuteStats.unit = PhotonModelConstants.UNIT_MICROSECONDS;
URI inMemoryStatsUri = UriUtils.buildStatsUri(UriUtils.extendUri(UriUtils.buildUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE)), currentState.computeLink));
operations.add(Operation.createPost(inMemoryStatsUri).setBody(minuteStats));
populateResourceMetrics(metricsList, getLastCollectionMetricKeyForAdapterLink(statsLink, false), minuteStats, currentState.computeLink, expirationTime, null);
for (ComputeStats stats : currentState.statsList) {
// TODO: https://jira-hzn.eng.vmware.com/browse/VSYM-330
InMemoryResourceMetric hourlyMemoryState = new InMemoryResourceMetric();
if (currentState.publishInMemory) {
String computeId = UriUtils.getLastPathSegment(stats.computeLink);
hourlyMemoryState.timeSeriesStats = new HashMap<>();
hourlyMemoryState.documentSelfLink = computeId + StatsConstants.HOUR_SUFFIX;
inMemoryMetricsList.add(hourlyMemoryState);
}
for (Entry<String, List<ServiceStat>> entries : stats.statValues.entrySet()) {
// sort stats by source time
entries.getValue().sort(Comparator.comparing(o -> o.sourceTimeMicrosUtc));
// Persist every data point
for (ServiceStat serviceStat : entries.getValue()) {
String computeLink = stats.computeLink;
if (computeLink == null) {
computeLink = currentState.computeLink;
}
if (currentState.publishInMemory) {
// update in-memory stats
updateInMemoryStats(hourlyMemoryState, entries.getKey(), serviceStat, StatsConstants.BUCKET_SIZE_HOURS_IN_MILLIS);
}
populateResourceMetrics(metricsList, entries.getKey(), serviceStat, computeLink, expirationTime, stats.getCustomProperties());
}
}
}
for (ResourceMetrics metrics : metricsList) {
operations.add(Operation.createPost(UriUtils.buildUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.METRIC_SERVICE), ResourceMetricsService.FACTORY_LINK)).setBodyNoCloning(metrics));
}
if (currentState.publishInMemory) {
for (InMemoryResourceMetric metric : inMemoryMetricsList) {
operations.add(Operation.createPost(getHost(), InMemoryResourceMetricService.FACTORY_LINK).setBodyNoCloning(metric));
}
}
// Save each data point sequentially to create time based monotonically increasing sequence.
batchPersistStats(operations, 0, currentState.isFinalBatch);
}
Aggregations