use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.
the class DefaultCloudbreakUsagesRetrievalHostServiceTypeTest method setUp.
@Before
public void setUp() {
underTest = new CloudbreakUsagesRetrievalService();
filterParameters = new Builder().setFilterEndDate(DUMMY_END_DATE).setAccount(DUMMY_ACCOUNT).setSince(DUMMY_SINCE).setOwner(DUMMY_OWNER).setRegion(DUMMY_REGION).setCloud(DUMMY_CLOUD).build();
usage = new CloudbreakUsage();
usage.setAccount(DUMMY_ACCOUNT);
MockitoAnnotations.initMocks(this);
}
use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.
the class FlexUsageGenerator method getUsages.
public CloudbreakFlexUsageJson getUsages(List<CloudbreakUsage> usages, Long fromDate) {
LOGGER.info("Generating Cloudbreak Flex related usages.");
CloudbreakFlexUsageJson result = new CloudbreakFlexUsageJson();
Optional<CloudbreakUsage> aUsage = usages.stream().findFirst();
result.setController(getFlexUsageControllerJson(usages, aUsage));
result.setProducts(Collections.emptyList());
if (controllerCreated == null || isValidFrom(fromDate)) {
result.setProducts(getFlexUsageProductJsons(usages, fromDate));
}
return result;
}
use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.
the class UsageGeneratorService method createNewFromUsage.
public CloudbreakUsage createNewFromUsage(CloudbreakUsage usage) {
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(0L);
newUsage.setCosts(0.0);
Date day = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
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.setStatus(usage.getStatus());
newUsage.setFlexId(usage.getFlexId());
newUsage.setSmartSenseId(usage.getSmartSenseId());
return newUsage;
}
use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.
the class UsageGeneratorService method openNewUsage.
public CloudbreakUsage openNewUsage(Stack stack, String instanceType, Integer instanceNum, String groupName, TemporalAccessor started) {
CloudbreakUsage usage = new CloudbreakUsage();
usage.setStackUuid(stack.getUuid());
usage.setParentUuid(cloudbreakNodeConfig.getInstanceUUID());
usage.setOwner(stack.getOwner());
usage.setAccount(stack.getAccount());
usage.setProvider(stack.cloudPlatform());
usage.setRegion(stack.getRegion());
usage.setAvailabilityZone(stack.getAvailabilityZone());
usage.setInstanceHours(0L);
usage.setCosts(0.0);
Date day = Date.from(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant());
usage.setDay(day);
usage.setStackId(stack.getId());
usage.setStackName(stack.getName());
usage.setInstanceType(instanceType);
usage.setInstanceNum(instanceNum);
usage.setPeak(instanceNum);
usage.setInstanceGroup(groupName);
if (stack.getCluster() != null && stack.getCluster().getBlueprint() != null) {
Blueprint bp = stack.getCluster().getBlueprint();
usage.setBlueprintId(bp.getId());
usage.setBlueprintName(bp.getAmbariName());
}
usage.setPeriodStarted(Date.from(LocalDateTime.from(started).atZone(ZoneId.systemDefault()).toInstant()));
usage.setStatus(UsageStatus.OPEN);
FlexSubscription flexSubscription = stack.getFlexSubscription();
if (flexSubscription != null && flexSubscription.getSmartSenseSubscription() != null) {
usage.setFlexId(flexSubscription.getSubscriptionId());
usage.setSmartSenseId(flexSubscription.getSmartSenseSubscription().getSubscriptionId());
}
return usage;
}
use of com.sequenceiq.cloudbreak.domain.CloudbreakUsage in project cloudbreak by hortonworks.
the class UsageService method stopUsagesForStack.
public void stopUsagesForStack(Stack stack) {
List<CloudbreakUsage> usages = usageRepository.findOpensForStack(stack.getId());
for (CloudbreakUsage usage : usages) {
usage.setStatus(UsageStatus.STOPPED);
Duration newDuration = usageTimeService.calculateNewDuration(usage);
usage.setInstanceHours(usageTimeService.convertToInstanceHours(newDuration));
usage.setDuration(newDuration.toString());
usage.setPeriodStarted(null);
usageRepository.save(usage);
}
}
Aggregations