Search in sources :

Example 1 with RangerRazEnabledV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response in project cloudbreak by hortonworks.

the class SdxServiceTest method testUpdateRangerRazIsIgnoredIfRangerRazIsInstalledAndFlagAlreadySet.

@Test
void testUpdateRangerRazIsIgnoredIfRangerRazIsInstalledAndFlagAlreadySet() {
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setEnvName("env");
    sdxCluster.setClusterName(CLUSTER_NAME);
    sdxCluster.setRangerRazEnabled(true);
    sdxCluster.setCrn("test-crn");
    sdxCluster.setRuntime("7.2.11");
    RangerRazEnabledV4Response response = mock(RangerRazEnabledV4Response.class);
    when(stackV4Endpoint.rangerRazEnabledInternal(anyLong(), anyString(), anyString())).thenReturn(response);
    when(response.isRangerRazEnabled()).thenReturn(true);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.updateRangerRazEnabled(sdxCluster));
    verify(sdxClusterRepository, times(0)).save(sdxCluster);
}
Also used : RangerRazEnabledV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with RangerRazEnabledV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response in project cloudbreak by hortonworks.

the class SdxServiceTest method testUpdateRangerRazEnabledForSdxClusterWhenRangerRazIsPresent.

@Test
void testUpdateRangerRazEnabledForSdxClusterWhenRangerRazIsPresent() {
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setEnvName("env");
    sdxCluster.setEnvCrn(ENVIRONMENT_CRN);
    sdxCluster.setClusterName(CLUSTER_NAME);
    sdxCluster.setCrn("test-crn");
    sdxCluster.setRuntime("7.2.11");
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCreator(USER_CRN);
    environmentResponse.setCloudPlatform("AWS");
    RangerRazEnabledV4Response response = mock(RangerRazEnabledV4Response.class);
    when(stackV4Endpoint.rangerRazEnabledInternal(anyLong(), anyString(), anyString())).thenReturn(response);
    when(response.isRangerRazEnabled()).thenReturn(true);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.updateRangerRazEnabled(sdxCluster));
    assertTrue(sdxCluster.isRangerRazEnabled());
    verify(sdxClusterRepository, times(1)).save(sdxCluster);
}
Also used : RangerRazEnabledV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with RangerRazEnabledV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response in project cloudbreak by hortonworks.

the class SdxServiceTest method testUpdateRangerRazThrowsExceptionForSdxClusterWhenRangerRazIsNotPresent.

@Test
void testUpdateRangerRazThrowsExceptionForSdxClusterWhenRangerRazIsNotPresent() {
    SdxCluster sdxCluster = new SdxCluster();
    sdxCluster.setEnvName("env");
    sdxCluster.setClusterName(CLUSTER_NAME);
    sdxCluster.setCrn("test-crn");
    sdxCluster.setRuntime("7.2.11");
    RangerRazEnabledV4Response response = mock(RangerRazEnabledV4Response.class);
    when(stackV4Endpoint.rangerRazEnabledInternal(anyLong(), anyString(), anyString())).thenReturn(response);
    when(response.isRangerRazEnabled()).thenReturn(false);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.updateRangerRazEnabled(sdxCluster)));
    assertEquals(String.format("Ranger raz is not installed on the datalake: %s!", CLUSTER_NAME), exception.getMessage());
    verify(sdxClusterRepository, times(0)).save(sdxCluster);
}
Also used : RangerRazEnabledV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with RangerRazEnabledV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response in project cloudbreak by hortonworks.

the class SdxService method updateRangerRazEnabled.

public void updateRangerRazEnabled(SdxCluster sdxCluster) {
    String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
    ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> {
        RangerRazEnabledV4Response response = stackV4Endpoint.rangerRazEnabledInternal(WORKSPACE_ID_DEFAULT, sdxCluster.getCrn(), initiatorUserCrn);
        if (response.isRangerRazEnabled()) {
            if (!sdxCluster.isRangerRazEnabled()) {
                validateRazEnablement(sdxCluster.getRuntime(), response.isRangerRazEnabled(), environmentClientService.getByCrn(sdxCluster.getEnvCrn()));
                sdxCluster.setRangerRazEnabled(true);
                save(sdxCluster);
            }
        } else {
            throw new BadRequestException(String.format("Ranger raz is not installed on the datalake: %s!", sdxCluster.getClusterName()));
        }
    });
}
Also used : RangerRazEnabledV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Aggregations

RangerRazEnabledV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.RangerRazEnabledV4Response)4 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1