Search in sources :

Example 6 with CloudbreakUsage

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

the class UsageService method startUsagesForStack.

public void startUsagesForStack(Stack stack) {
    List<CloudbreakUsage> usages = usageRepository.findStoppedForStack(stack.getId());
    for (CloudbreakUsage usage : usages) {
        usage.setStatus(UsageStatus.OPEN);
        usage.setPeriodStarted(Date.from(ZonedDateTime.now().toInstant()));
        usageRepository.save(usage);
    }
}
Also used : CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 7 with CloudbreakUsage

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

the class UsageService method openNewIfNotFound.

private void openNewIfNotFound() {
    List<CloudbreakUsage> usages = usageRepository.findAllOpenAndStopped(Date.from(ZonedDateTime.now().toInstant()));
    Set<Long> stackIdsForOpenUsages = usages.stream().map(CloudbreakUsage::getStackId).collect(Collectors.toSet());
    List<Stack> stacks = stackRepository.findAllAliveAndProvisioned();
    for (Stack stack : stacks) {
        if (!stackIdsForOpenUsages.contains(stack.getId())) {
            Stack fullStack = stackRepository.findOneWithLists(stack.getId());
            openUsagesForStack(fullStack);
            if (fullStack.getStatus() == Status.STOPPED) {
                stopUsagesForStack(fullStack);
            }
        }
    }
}
Also used : CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 8 with CloudbreakUsage

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

the class UsageService method reopenOldUsages.

private void reopenOldUsages() {
    List<CloudbreakUsage> usages = usageRepository.findAllOpenAndStopped(Date.from(ZonedDateTime.now().minusDays(1).toInstant()));
    List<CloudbreakUsage> newUsages = Lists.newArrayList();
    for (CloudbreakUsage usage : usages) {
        newUsages.addAll(usageGeneratorService.createClosedUsagesUntilNow(usage));
        newUsages.add(closeUsageIfStackKilled(usageGeneratorService.createNewFromUsage(usage)));
        closeUsage(usage);
        usageRepository.save(usage);
    }
    usageRepository.save(newUsages);
}
Also used : CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 9 with CloudbreakUsage

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

the class UsageService method scaleUsagesForStack.

public void scaleUsagesForStack(Long stackId, String instanceGroupName, int nodeCount) {
    CloudbreakUsage usage = usageRepository.getOpenUsageByStackAndGroupName(stackId, instanceGroupName);
    if (usage != null) {
        Duration newDuration = usageTimeService.calculateNewDuration(usage);
        usage.setInstanceHours(usageTimeService.convertToInstanceHours(newDuration));
        usage.setDuration(newDuration.toString());
        usage.setPeriodStarted(Date.from(ZonedDateTime.now().toInstant()));
        if (usage.getPeak() < nodeCount) {
            usage.setPeak(nodeCount);
        }
        usage.setInstanceNum(nodeCount);
        usageRepository.save(usage);
    }
}
Also used : Duration(java.time.Duration) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 10 with CloudbreakUsage

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

the class StackResponseUsageProvider method providerEntriesToStackResponse.

@Override
public StackResponse providerEntriesToStackResponse(Stack stack, StackResponse stackResponse) {
    List<CloudbreakUsage> openCloudbreakUsages = cloudbreakUsageRepository.findOpensForStack(stack.getId());
    List<CloudbreakUsage> closedCloudbreakUsages = cloudbreakUsageRepository.findStoppedForStack(stack.getId());
    List<CloudbreakUsageJson> cloudbreakUsagesJsons = new ArrayList<>();
    for (CloudbreakUsage openCloudbreakUsage : openCloudbreakUsages) {
        cloudbreakUsagesJsons.add(conversionService.convert(openCloudbreakUsage, CloudbreakUsageJson.class));
    }
    for (CloudbreakUsage closedCloudbreakUsage : closedCloudbreakUsages) {
        cloudbreakUsagesJsons.add(conversionService.convert(closedCloudbreakUsage, CloudbreakUsageJson.class));
    }
    stackResponse.setCloudbreakUsages(cloudbreakUsagesJsons);
    return stackResponse;
}
Also used : CloudbreakUsageJson(com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson) ArrayList(java.util.ArrayList) 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