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);
}
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);
}
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);
}
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()));
}
});
}
Aggregations