use of com.sequenceiq.cloudbreak.api.model.flex.FlexUsageHdpInstanceJson in project cloudbreak by hortonworks.
the class FlexUsageGenerator method getFlexUsageHdpInstances.
private List<FlexUsageHdpInstanceJson> getFlexUsageHdpInstances(Iterable<CloudbreakUsage> usages) {
Map<Long, FlexUsageHdpInstanceJson> flexUsageJsonsByStackId = new HashMap<>();
for (CloudbreakUsage usage : usages) {
Long stackId = usage.getStackId();
if (!flexUsageJsonsByStackId.containsKey(stackId)) {
FlexUsageHdpInstanceJson usageJson = new FlexUsageHdpInstanceJson();
usageJson.setGuid(usage.getStackUuid());
usageJson.setParentGuid(usage.getParentUuid());
usageJson.setClusterName(usage.getStackName());
usageJson.setBlueprintName(usage.getBlueprintName());
usageJson.setFlexSubscriptionId(usage.getFlexId());
usageJson.setProvider(usage.getProvider());
usageJson.setRegion(usage.getRegion());
usageJson.setPeakUsage(usage.getPeak());
usageJson.setUsageDate(formatInstant(usage.getDay().toInstant(), FLEX_USAGE_DAY_FORMAT_PATTERN));
StackView stack = stackService.getByIdView(usage.getStackId());
usageJson.setCreationTime(formatInstant(Instant.ofEpochMilli(stack.getCreated()), FLEX_TIME_ZONE_FORMAT_PATTERN));
usageJson.setTerminationTime(getTerminationTime(stack));
flexUsageJsonsByStackId.put(stackId, usageJson);
} else {
FlexUsageHdpInstanceJson usageJson = flexUsageJsonsByStackId.get(stackId);
Integer actPeak = usage.getPeak() != null ? usage.getPeak() : 0;
Integer peak = usageJson.getPeakUsage() != null ? usageJson.getPeakUsage() : 0;
int newPeak = peak + actPeak;
usageJson.setPeakUsage(newPeak);
}
}
return new ArrayList<>(flexUsageJsonsByStackId.values());
}
Aggregations