use of com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson 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;
}
use of com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson in project cloudbreak by hortonworks.
the class CloudbreakUsageToCloudbreakUsageJsonConverter method convert.
@Override
public CloudbreakUsageJson convert(CloudbreakUsage entity) {
CloudbreakUsageJson json = new CloudbreakUsageJson();
String day = new SimpleDateFormat(DATE_FORMAT).format(entity.getDay());
String cbUser;
try {
cbUser = userDetailsService.getDetails(entity.getOwner(), UserFilterField.USERID).getUsername();
} catch (Exception ignored) {
LOGGER.warn(String.format("Expected user was not found with '%s' id. Maybe it was deleted by the admin user.", entity.getOwner()));
cbUser = entity.getOwner();
}
json.setOwner(entity.getOwner());
json.setAccount(entity.getAccount());
json.setProvider(entity.getProvider());
json.setRegion(entity.getRegion());
json.setAvailabilityZone(entity.getAvailabilityZone());
json.setInstanceHours(getInstanceHours(entity));
json.setDuration(getDuration(entity));
json.setDay(day);
json.setStackId(entity.getStackId());
json.setStackName(entity.getStackName());
json.setUsername(cbUser);
json.setCosts(entity.getCosts());
json.setInstanceType(entity.getInstanceType());
json.setInstanceGroup(entity.getInstanceGroup());
json.setBlueprintId(entity.getBlueprintId());
json.setBlueprintName(entity.getBlueprintName());
json.setInstanceNum(entity.getInstanceNum());
json.setPeak(entity.getPeak());
json.setFlexId(entity.getFlexId());
json.setStackUuid(entity.getStackUuid());
return json;
}
use of com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson in project cloudbreak by hortonworks.
the class CloudbreakUsageToCloudbreakUsageJsonConverterTest method testConvertWithAwsProvider.
@Test
public void testConvertWithAwsProvider() {
// GIVEN
getSource().setProvider(AWS);
getSource().setRegion("us_east_1");
given(userDetailsService.getDetails(anyString(), any(UserFilterField.class))).willReturn(user);
// WHEN
CloudbreakUsageJson result = underTest.convert(getSource());
// THEN
assertEquals(AWS, result.getProvider());
assertEquals("john.smith@example.com", result.getUsername());
assertAllFieldsNotNull(result, Lists.newArrayList("availabilityZone", "duration"));
}
use of com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson in project cloudbreak by hortonworks.
the class CloudbreakUsageToCloudbreakUsageJsonConverterTest method testConvertWithGcpProvider.
@Test
public void testConvertWithGcpProvider() {
// GIVEN
getSource().setProvider(GCP);
getSource().setRegion("us_central1");
getSource().setAvailabilityZone("us_central1_a");
given(userDetailsService.getDetails(anyString(), any(UserFilterField.class))).willReturn(user);
// WHEN
CloudbreakUsageJson result = underTest.convert(getSource());
// THEN
assertEquals(GCP, result.getProvider());
assertEquals("john.smith@example.com", result.getUsername());
assertAllFieldsNotNull(result, Lists.newArrayList("availabilityZone", "duration"));
}
use of com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson in project cloudbreak by hortonworks.
the class CloudbreakUsageToCloudbreakUsageJsonConverterTest method testConvert.
@Test
public void testConvert() {
// GIVEN
given(userDetailsService.getDetails(anyString(), any(UserFilterField.class))).willReturn(user);
// WHEN
CloudbreakUsageJson result = underTest.convert(getSource());
// THEN
assertEquals(GCP, result.getProvider());
assertEquals("john.smith@example.com", result.getUsername());
assertAllFieldsNotNull(result, Lists.newArrayList("availabilityZone", "duration"));
}
Aggregations