Search in sources :

Example 1 with RangerCloudIdentitySyncStatus

use of com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus in project cloudbreak by hortonworks.

the class CloudIdSyncStatusListenerTask method checkStatus.

@Override
public boolean checkStatus(CloudIdSyncPollerObject pollerObject) {
    RangerCloudIdentitySyncStatus syncStatus = sdxEndpoint.getRangerCloudIdentitySyncStatus(pollerObject.getEnvironmentCrn(), pollerObject.getCommandId());
    LOGGER.info("syncStatus = {}", syncStatus);
    switch(syncStatus.getState()) {
        case SUCCESS:
            LOGGER.info("Successfully synced cloud identity, envCrn = {}", pollerObject.getEnvironmentCrn());
            return true;
        case NOT_APPLICABLE:
            LOGGER.info("Cloud identity sync not applicable, envCrn = {}", pollerObject.getEnvironmentCrn());
            return true;
        case FAILED:
            LOGGER.error("Failed to sync cloud identity, envCrn = {}", pollerObject.getEnvironmentCrn());
            throw new CloudbreakServiceException("Failed to sync cloud identity");
        case ACTIVE:
            LOGGER.info("Sync is still in progress");
            return false;
        default:
            LOGGER.error("Encountered unknown cloud identity sync state");
            throw new CloudbreakServiceException("Failed to sync cloud identity");
    }
}
Also used : RangerCloudIdentitySyncStatus(com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 2 with RangerCloudIdentitySyncStatus

use of com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus in project cloudbreak by hortonworks.

the class RangerCloudIdentityService method toRangerCloudIdentitySyncStatus.

private RangerCloudIdentitySyncStatus toRangerCloudIdentitySyncStatus(ApiCommand apiCommand) {
    RangerCloudIdentitySyncStatus status = new RangerCloudIdentitySyncStatus();
    status.setCommandId(apiCommand.getId().longValue());
    status.setStatusReason(apiCommand.getResultMessage());
    status.setState(toRangerCloudIdentitySyncState(apiCommand));
    return status;
}
Also used : RangerCloudIdentitySyncStatus(com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus)

Example 3 with RangerCloudIdentitySyncStatus

use of com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus in project cloudbreak by hortonworks.

the class RangerCloudIdentityServiceTest method testSetAzureCloudIdentityMappingNoDatalake.

@Test
public void testSetAzureCloudIdentityMappingNoDatalake() throws ApiException {
    when(sdxService.listSdxByEnvCrn(anyString())).thenReturn(Collections.emptyList());
    Map<String, String> userMapping = Map.of("user", "val1");
    RangerCloudIdentitySyncStatus status = underTest.setAzureCloudIdentityMapping("env-crn", userMapping);
    assertEquals(RangerCloudIdentitySyncState.NOT_APPLICABLE, status.getState());
    verify(clouderaManagerRangerUtil, never()).setAzureCloudIdentityMapping(eq("stack-crn"), eq(userMapping));
}
Also used : RangerCloudIdentitySyncStatus(com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with RangerCloudIdentitySyncStatus

use of com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus in project cloudbreak by hortonworks.

the class RangerCloudIdentityServiceTest method testSetAzureCloudIdentityMappingDatalakNotRunning.

@Test
public void testSetAzureCloudIdentityMappingDatalakNotRunning() throws ApiException {
    when(sdxService.listSdxByEnvCrn(anyString())).thenReturn(List.of(mock(SdxCluster.class)));
    SdxStatusEntity sdxStatus = mockSdxStatus(DatalakeStatusEnum.PROVISIONING_FAILED);
    when(sdxStatusService.getActualStatusForSdx(any())).thenReturn(sdxStatus);
    Map<String, String> userMapping = Map.of("user", "val1");
    RangerCloudIdentitySyncStatus status = underTest.setAzureCloudIdentityMapping("env-crn", userMapping);
    assertEquals(RangerCloudIdentitySyncState.NOT_APPLICABLE, status.getState());
    verify(clouderaManagerRangerUtil, never()).setAzureCloudIdentityMapping(eq("stack-crn"), eq(userMapping));
}
Also used : RangerCloudIdentitySyncStatus(com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus) SdxStatusEntity(com.sequenceiq.datalake.entity.SdxStatusEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 5 with RangerCloudIdentitySyncStatus

use of com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus in project cloudbreak by hortonworks.

the class RangerCloudIdentityServiceTest method testSetAzureCloudIdentityMapping.

private void testSetAzureCloudIdentityMapping(Optional<ApiCommand> apiCommand, RangerCloudIdentitySyncState expectedStatus) throws ApiException {
    SdxCluster cluster = mock(SdxCluster.class);
    when(cluster.getStackCrn()).thenReturn("stack-crn");
    when(sdxService.listSdxByEnvCrn(anyString())).thenReturn(List.of(cluster));
    when(clouderaManagerRangerUtil.isCloudIdMappingSupported(any())).thenReturn(true);
    when(clouderaManagerRangerUtil.setAzureCloudIdentityMapping(any(), any())).thenReturn(apiCommand);
    Map<String, String> userMapping = Map.of("user", "val1");
    RangerCloudIdentitySyncStatus status = underTest.setAzureCloudIdentityMapping("env-crn", userMapping);
    assertEquals(expectedStatus, status.getState());
    verify(clouderaManagerRangerUtil, times(1)).setAzureCloudIdentityMapping(eq("stack-crn"), eq(userMapping));
}
Also used : RangerCloudIdentitySyncStatus(com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

RangerCloudIdentitySyncStatus (com.sequenceiq.sdx.api.model.RangerCloudIdentitySyncStatus)11 Test (org.junit.jupiter.api.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxStatusEntity (com.sequenceiq.datalake.entity.SdxStatusEntity)1 CloudIdSyncPollerObject (com.sequenceiq.freeipa.service.polling.usersync.CloudIdSyncPollerObject)1 SetRangerCloudIdentityMappingRequest (com.sequenceiq.sdx.api.model.SetRangerCloudIdentityMappingRequest)1