Search in sources :

Example 1 with CloudbreakUsage

use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.

the class TestUtil method gcpCloudbreakUsage.

public static CloudbreakUsage gcpCloudbreakUsage(Long id) {
    CloudbreakUsage cloudbreakUsage = new CloudbreakUsage();
    cloudbreakUsage.setId(id);
    cloudbreakUsage.setInstanceGroup("master");
    cloudbreakUsage.setAccount("account");
    cloudbreakUsage.setCosts(2d);
    cloudbreakUsage.setDay(new Date());
    cloudbreakUsage.setInstanceHours(1L);
    cloudbreakUsage.setInstanceType("xlarge");
    cloudbreakUsage.setOwner("owner");
    cloudbreakUsage.setProvider(GCP);
    cloudbreakUsage.setRegion("Central US");
    cloudbreakUsage.setStackName("usagestack");
    cloudbreakUsage.setStackId(1L);
    cloudbreakUsage.setBlueprintId(1L);
    cloudbreakUsage.setBlueprintName("blueprint");
    cloudbreakUsage.setInstanceNum(6);
    cloudbreakUsage.setPeak(10);
    cloudbreakUsage.setFlexId("FLEX-1234567");
    cloudbreakUsage.setStackUuid("23423-sdfasdf-23423-2345");
    return cloudbreakUsage;
}
Also used : Date(java.util.Date) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 2 with CloudbreakUsage

use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.

the class CloudbreakUsageRequestToCloudbreakUsageConverter method convert.

@Override
public CloudbreakUsage convert(CloudbreakUsageJson json) {
    CloudbreakUsage entity = new CloudbreakUsage();
    entity.setOwner(json.getOwner());
    entity.setAccount(json.getAccount());
    entity.setProvider(json.getProvider());
    entity.setRegion(json.getRegion());
    entity.setAvailabilityZone(json.getAvailabilityZone());
    entity.setInstanceHours(json.getInstanceHours());
    entity.setStackId(json.getStackId());
    entity.setStackName(json.getStackName());
    entity.setInstanceType(json.getInstanceType());
    entity.setInstanceGroup(json.getInstanceGroup());
    entity.setBlueprintId(json.getBlueprintId());
    entity.setBlueprintName(json.getBlueprintName());
    return entity;
}
Also used : CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 3 with CloudbreakUsage

use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage 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)

Example 4 with CloudbreakUsage

use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.

the class UsageGeneratorService method createClosedUsagesUntilNow.

public Collection<CloudbreakUsage> createClosedUsagesUntilNow(CloudbreakUsage usage) {
    List<CloudbreakUsage> result = Lists.newArrayList();
    long days = usageTimeService.daysBetweenDateAndNow(usage.getDay());
    ZonedDateTime zdt = usage.getDay().toInstant().atZone(ZoneId.systemDefault());
    for (int i = 1; i < days; i++) {
        Date day = Date.from(zdt.plusDays(i).toInstant());
        result.add(createFullClosed(usage, day));
    }
    return result;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Date(java.util.Date) LocalDate(java.time.LocalDate) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 5 with CloudbreakUsage

use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.

the class UsageGeneratorService method createFullClosed.

public CloudbreakUsage createFullClosed(CloudbreakUsage usage, Date day) {
    CloudbreakUsage newUsage = new CloudbreakUsage();
    newUsage.setStackUuid(usage.getStackUuid());
    newUsage.setParentUuid(cloudbreakNodeConfig.getInstanceUUID());
    newUsage.setOwner(usage.getOwner());
    newUsage.setAccount(usage.getAccount());
    newUsage.setProvider(usage.getProvider());
    newUsage.setRegion(usage.getRegion());
    newUsage.setAvailabilityZone(usage.getAvailabilityZone());
    newUsage.setInstanceHours(HOURS_IN_DAY * usage.getInstanceNum());
    newUsage.setDay(day);
    newUsage.setStackId(usage.getStackId());
    newUsage.setStackName(usage.getStackName());
    newUsage.setInstanceType(usage.getInstanceType());
    newUsage.setInstanceNum(usage.getInstanceNum());
    newUsage.setPeak(usage.getInstanceNum());
    newUsage.setInstanceGroup(usage.getInstanceGroup());
    newUsage.setBlueprintId(usage.getBlueprintId());
    newUsage.setBlueprintName(usage.getBlueprintName());
    newUsage.setPeriodStarted(day);
    newUsage.setDuration(Duration.of(HOURS_IN_DAY, ChronoUnit.HOURS).multipliedBy(usage.getInstanceNum()).toString());
    newUsage.setStatus(UsageStatus.CLOSED);
    newUsage.setCosts(usagePriceService.calculateCostOfUsage(newUsage));
    newUsage.setFlexId(usage.getFlexId());
    newUsage.setSmartSenseId(usage.getSmartSenseId());
    return newUsage;
}
Also used : CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Aggregations

CloudbreakUsage (com.sequenceiq.cloudbreak.domain.CloudbreakUsage)18 Date (java.util.Date)4 LocalDate (java.time.LocalDate)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 CloudbreakUsageJson (com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson)1 CloudbreakFlexUsageJson (com.sequenceiq.cloudbreak.api.model.flex.CloudbreakFlexUsageJson)1 FlexUsageHdpInstanceJson (com.sequenceiq.cloudbreak.api.model.flex.FlexUsageHdpInstanceJson)1 Builder (com.sequenceiq.cloudbreak.domain.CbUsageFilterParameters.Builder)1 FlexSubscription (com.sequenceiq.cloudbreak.domain.FlexSubscription)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 Template (com.sequenceiq.cloudbreak.domain.Template)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 LocalDateTime (java.time.LocalDateTime)1 ZonedDateTime (java.time.ZonedDateTime)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1