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);
}
}
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);
}
}
}
}
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);
}
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);
}
}
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;
}
Aggregations