Search in sources :

Example 11 with CloudbreakUsage

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);
}
Also used : Builder(com.sequenceiq.cloudbreak.domain.CbUsageFilterParameters.Builder) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage) Before(org.junit.Before)

Example 12 with CloudbreakUsage

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;
}
Also used : CloudbreakFlexUsageJson(com.sequenceiq.cloudbreak.api.model.flex.CloudbreakFlexUsageJson) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 13 with CloudbreakUsage

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;
}
Also used : Date(java.util.Date) LocalDate(java.time.LocalDate) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 14 with CloudbreakUsage

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;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) FlexSubscription(com.sequenceiq.cloudbreak.domain.FlexSubscription) Date(java.util.Date) LocalDate(java.time.LocalDate) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 15 with CloudbreakUsage

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);
    }
}
Also used : Duration(java.time.Duration) 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