Search in sources :

Example 1 with FlexUsageHdpInstanceJson

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());
}
Also used : FlexUsageHdpInstanceJson(com.sequenceiq.cloudbreak.api.model.flex.FlexUsageHdpInstanceJson) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Aggregations

FlexUsageHdpInstanceJson (com.sequenceiq.cloudbreak.api.model.flex.FlexUsageHdpInstanceJson)1 CloudbreakUsage (com.sequenceiq.cloudbreak.domain.CloudbreakUsage)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1