Search in sources :

Example 1 with CloudbreakUsageJson

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;
}
Also used : CloudbreakUsageJson(com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson) ArrayList(java.util.ArrayList) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage)

Example 2 with CloudbreakUsageJson

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;
}
Also used : CloudbreakUsageJson(com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with CloudbreakUsageJson

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"));
}
Also used : CloudbreakUsageJson(com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson) UserFilterField(com.sequenceiq.cloudbreak.common.service.user.UserFilterField) Test(org.junit.Test)

Example 4 with CloudbreakUsageJson

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"));
}
Also used : CloudbreakUsageJson(com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson) UserFilterField(com.sequenceiq.cloudbreak.common.service.user.UserFilterField) Test(org.junit.Test)

Example 5 with CloudbreakUsageJson

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"));
}
Also used : CloudbreakUsageJson(com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson) UserFilterField(com.sequenceiq.cloudbreak.common.service.user.UserFilterField) Test(org.junit.Test)

Aggregations

CloudbreakUsageJson (com.sequenceiq.cloudbreak.api.model.CloudbreakUsageJson)5 UserFilterField (com.sequenceiq.cloudbreak.common.service.user.UserFilterField)3 Test (org.junit.Test)3 CloudbreakUsage (com.sequenceiq.cloudbreak.domain.CloudbreakUsage)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1