Search in sources :

Example 21 with EnvironmentTelemetry

use of com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testInitEditDto.

@Test
void testInitEditDto() {
    EnvironmentEditRequest request = createEditEnvironmentRequest();
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentEditDto actual = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.initEditDto(request));
    assertEquals("test-aws", actual.getAccountId());
    assertEquals(request.getDescription(), actual.getDescription());
    assertEquals(environmentTelemetry, actual.getTelemetry());
    assertAuthentication(request.getAuthentication(), actual.getAuthentication());
    assertEquals(request.getAdminGroupName(), actual.getAdminGroupName());
    assertSecurityAccess(request.getSecurityAccess(), actual.getSecurityAccess());
    verify(accountTelemetry).getFeatures();
    verify(accountTelemetryService).getOrDefault(any());
    verify(telemetryApiConverter).convert(eq(request.getTelemetry()), any(), anyString());
    verify(networkRequestToDtoConverter).convert(request.getNetwork());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentEditRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentEditRequest) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with EnvironmentTelemetry

use of com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testAzureSingleRgEnabledAndAzureRequestWithoutUsageAndWithName.

@Test
void testAzureSingleRgEnabledAndAzureRequestWithoutUsageAndWithName() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withName("myResourceGroup").build()).build());
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertNull(actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern());
    assertEquals("myResourceGroup", actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getName());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with EnvironmentTelemetry

use of com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testAzureResourceEncryptionParametersAndAzureRequest.

@Test
void testAzureResourceEncryptionParametersAndAzureRequest() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(AzureEnvironmentParameters.builder().withResourceEncryptionParameters(AzureResourceEncryptionParameters.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(KEY_URL_RESOURCE_GROUP).build()).build());
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(KEY_URL, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
    assertEquals(KEY_URL_RESOURCE_GROUP, actual.getParameters().getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with EnvironmentTelemetry

use of com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testChangeTelemetryFeaturesByEnvironmentCrn.

@Test
public void testChangeTelemetryFeaturesByEnvironmentCrn() {
    String accountId = "myAccountId";
    String envCrn = "myEnvCrn";
    EnvironmentFeatures featuresInput = new EnvironmentFeatures();
    featuresInput.addCloudStorageLogging(false);
    featuresInput.addClusterLogsCollection(true);
    Environment environment = new Environment();
    environment.setTelemetry(new EnvironmentTelemetry());
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(envCrn, accountId)).thenReturn(Optional.of(environment));
    when(environmentService.save(environment)).thenReturn(environment);
    when(environmentDtoConverter.environmentToDto(environment)).thenReturn(new EnvironmentDto());
    environmentModificationServiceUnderTest.changeTelemetryFeaturesByEnvironmentCrn(accountId, envCrn, featuresInput);
    verify(environmentService).save(any());
    assertFalse(environment.getTelemetry().getFeatures().getCloudStorageLogging().isEnabled());
    assertTrue(environment.getTelemetry().getFeatures().getClusterLogsCollection().isEnabled());
}
Also used : EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentFeatures(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentFeatures) Test(org.junit.jupiter.api.Test)

Example 25 with EnvironmentTelemetry

use of com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry in project cloudbreak by hortonworks.

the class EnvironmentModificationService method changeTelemetryFeatures.

private EnvironmentDto changeTelemetryFeatures(EnvironmentFeatures features, Environment environment) {
    EnvironmentTelemetry telemetry = environment.getTelemetry();
    if (telemetry != null) {
        EnvironmentFeatures actualFeatures = telemetry.getFeatures();
        if (actualFeatures != null) {
            if (features.getClusterLogsCollection() != null) {
                actualFeatures.setClusterLogsCollection(features.getClusterLogsCollection());
                LOGGER.debug("Updating cluster log collection (environment telemetry feature): {}.", features.getClusterLogsCollection().isEnabled());
            }
            if (features.getWorkloadAnalytics() != null) {
                actualFeatures.setWorkloadAnalytics(features.getWorkloadAnalytics());
                LOGGER.debug("Updating workload analytics (environment telemetry feature): {}.", features.getWorkloadAnalytics().isEnabled());
            }
            if (features.getCloudStorageLogging() != null) {
                actualFeatures.setCloudStorageLogging(features.getCloudStorageLogging());
                LOGGER.debug("Updating cloud storage logging (environment telemetry feature): {}.", features.getCloudStorageLogging().isEnabled());
            }
            telemetry.setFeatures(actualFeatures);
            // required to re-set as telemetry is saved as a JSON string
            environment.setTelemetry(telemetry);
        } else if (features != null) {
            telemetry.setFeatures(features);
            // required to re-set as telemetry is saved as a JSON string
            environment.setTelemetry(telemetry);
            LOGGER.debug("Adding new feature object for environment level telemetry.");
        } else {
            LOGGER.debug("No telemetry feature related changes has been made.");
        }
    }
    Environment saved = environmentService.save(environment);
    return environmentDtoConverter.environmentToDto(saved);
}
Also used : EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentFeatures(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentFeatures)

Aggregations

EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)27 Test (org.junit.jupiter.api.Test)22 Features (com.sequenceiq.common.api.telemetry.model.Features)16 EnvironmentFeatures (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentFeatures)12 TelemetryRequest (com.sequenceiq.common.api.telemetry.request.TelemetryRequest)10 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 ExperimentalFeatures (com.sequenceiq.environment.environment.domain.ExperimentalFeatures)8 AccountTelemetry (com.sequenceiq.environment.telemetry.domain.AccountTelemetry)8 EnvironmentRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest)7 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 FreeIpaCreationDto (com.sequenceiq.environment.environment.dto.FreeIpaCreationDto)7 FeaturesRequest (com.sequenceiq.common.api.telemetry.request.FeaturesRequest)6 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)6 Environment (com.sequenceiq.environment.environment.domain.Environment)5 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)3 EnvironmentLogging (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentLogging)3 S3CloudStorageParameters (com.sequenceiq.environment.environment.dto.telemetry.S3CloudStorageParameters)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)2