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