Search in sources :

Example 1 with AccountTelemetry

use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method testAzureSingleRgEnabledAndEmptyAzureRequest.

@Test
void testAzureSingleRgEnabledAndEmptyAzureRequest() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(null);
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.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(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(ResourceGroupUsagePattern.USE_MULTIPLE, actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) 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 2 with AccountTelemetry

use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.

the class AccountTelemetryService method createDefaultAccuontTelemetry.

public AccountTelemetry createDefaultAccuontTelemetry() {
    AccountTelemetry defaultTelemetry = new AccountTelemetry();
    List<AnonymizationRule> defaultEncodedRules = defaultRules.stream().map(rule -> {
        AnonymizationRule encodedRule = new AnonymizationRule();
        encodedRule.setValue(Base64.getEncoder().encodeToString(rule.getValue().getBytes()));
        encodedRule.setReplacement(rule.getReplacement());
        return encodedRule;
    }).collect(Collectors.toList());
    Features defaultFeatures = new Features();
    defaultFeatures.addClusterLogsCollection(false);
    defaultFeatures.addCloudStorageLogging(true);
    defaultTelemetry.setRules(defaultEncodedRules);
    defaultTelemetry.setFeatures(defaultFeatures);
    return defaultTelemetry;
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) Features(com.sequenceiq.common.api.telemetry.model.Features) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) PatternSyntaxException(jregex.PatternSyntaxException) Pattern(jregex.Pattern) Logger(org.slf4j.Logger) AccountTelemetryConfig(com.sequenceiq.environment.configuration.telemetry.AccountTelemetryConfig) AccountTelemetryRepository(com.sequenceiq.environment.telemetry.repository.AccountTelemetryRepository) LoggerFactory(org.slf4j.LoggerFactory) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) Base64(java.util.Base64) List(java.util.List) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) Replacer(jregex.Replacer) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) Features(com.sequenceiq.common.api.telemetry.model.Features)

Example 3 with AccountTelemetry

use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.

the class AccountTelemetryService method updateFeatures.

public Features updateFeatures(String accountId, Features newFeatures) {
    try {
        LOGGER.debug("Update account telemetry features for account: {}", accountId);
        Optional<AccountTelemetry> telemetryOpt = accountTelemetryRepository.findByAccountId(accountId);
        AccountTelemetry telemetry = telemetryOpt.orElse(createDefaultAccuontTelemetry());
        Features features = telemetry.getFeatures();
        Features finalFeatures = null;
        if (features != null && newFeatures != null) {
            finalFeatures = new Features();
            finalFeatures.setClusterLogsCollection(features.getClusterLogsCollection());
            finalFeatures.setWorkloadAnalytics(features.getWorkloadAnalytics());
            finalFeatures.setMonitoring(features.getMonitoring());
            finalFeatures.setCloudStorageLogging(features.getCloudStorageLogging());
            if (newFeatures.getClusterLogsCollection() != null) {
                LOGGER.debug("Account telemetry feature request contains log collection feature " + "for account {} (set: {})", accountId, newFeatures.getClusterLogsCollection().isEnabled());
                finalFeatures.setClusterLogsCollection(newFeatures.getClusterLogsCollection());
            }
            if (newFeatures.getWorkloadAnalytics() != null) {
                LOGGER.debug("Account telemetry feature request contains workload analytics feature " + "for account {} (set: {})", accountId, newFeatures.getWorkloadAnalytics().isEnabled());
                finalFeatures.setWorkloadAnalytics(newFeatures.getWorkloadAnalytics());
            }
            if (newFeatures.getMonitoring() != null) {
                LOGGER.debug("Account telemetry feature request contains monitoring feature " + "for account {} (set: {})", accountId, newFeatures.getMonitoring().isEnabled());
                finalFeatures.setMonitoring(newFeatures.getMonitoring());
            }
            if (newFeatures.getCloudStorageLogging() != null) {
                LOGGER.debug("Account telemetry feature request contains cloud storage logging feature " + "for account {} (set: {})", accountId, newFeatures.getCloudStorageLogging().isEnabled());
                finalFeatures.setMonitoring(newFeatures.getCloudStorageLogging());
            }
        }
        telemetry.setFeatures(finalFeatures);
        return create(telemetry, accountId).getFeatures();
    } catch (DataIntegrityViolationException e) {
        throw new AccessDeniedException("Access denied", e);
    }
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) Features(com.sequenceiq.common.api.telemetry.model.Features) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 4 with AccountTelemetry

use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.

the class AccountTelemetryController method update.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public AccountTelemetryResponse update(AccountTelemetryRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    AccountTelemetry telemetry = accountTelemetryConverter.convert(request);
    return accountTelemetryConverter.convert(accountTelemetryService.create(telemetry, accountId));
}
Also used : AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 5 with AccountTelemetry

use of com.sequenceiq.environment.telemetry.domain.AccountTelemetry in project cloudbreak by hortonworks.

the class AccountTelemetryServiceTest method testValidateRulesWithoutRules.

@Test
public void testValidateRulesWithoutRules() {
    // GIVEN
    AccountTelemetry telemetry = new AccountTelemetry();
    // WHEN
    underTest.validateAnonymizationRules(telemetry);
}
Also used : AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) Test(org.junit.jupiter.api.Test)

Aggregations

AccountTelemetry (com.sequenceiq.environment.telemetry.domain.AccountTelemetry)17 Test (org.junit.jupiter.api.Test)11 Features (com.sequenceiq.common.api.telemetry.model.Features)10 ExperimentalFeatures (com.sequenceiq.environment.environment.domain.ExperimentalFeatures)8 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)8 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)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 AnonymizationRule (com.sequenceiq.common.api.telemetry.model.AnonymizationRule)4 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)4 ArrayList (java.util.ArrayList)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)1 CrnResourceDescriptor (com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor)1 RegionAwareCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 EnvironmentEditRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentEditRequest)1