Search in sources :

Example 1 with ToolsResourceApi

use of com.cloudera.api.swagger.ToolsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityService method createApiClient.

private ApiClient createApiClient() throws ClusterClientInitException, ClouderaManagerClientInitException, CloudbreakException {
    try {
        ApiClient client = clouderaManagerApiClientProvider.getDefaultClient(stack.getGatewayPort(), clientConfig, ClouderaManagerApiClientProvider.API_V_31);
        ToolsResourceApi toolsResourceApi = clouderaManagerApiFactory.getToolsResourceApi(client);
        toolsResourceApi.echo("TEST");
        LOGGER.debug("Cloudera Manager already running, old admin user's password has not been changed yet.");
        return client;
    } catch (ClouderaManagerClientInitException e) {
        throw new ClusterClientInitException(e);
    } catch (ApiException e) {
        if (org.springframework.http.HttpStatus.UNAUTHORIZED.value() == e.getCode()) {
            return createClientWithNewPassword();
        }
        LOGGER.debug("Cloudera Manager is not running.", e);
        throw new CloudbreakException("Cloudera Manager is not running. " + e.getMessage());
    }
}
Also used : ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 2 with ToolsResourceApi

use of com.cloudera.api.swagger.ToolsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSetupService method createApiClient.

private ApiClient createApiClient() throws ClusterClientInitException {
    ApiClient client = null;
    try {
        client = clouderaManagerApiClientProvider.getDefaultClient(stack.getGatewayPort(), clientConfig, ClouderaManagerApiClientProvider.API_V_31);
        ToolsResourceApi toolsResourceApi = clouderaManagerApiFactory.getToolsResourceApi(client);
        toolsResourceApi.echo("TEST");
        LOGGER.debug("Cloudera Manager already running, old admin user's password has not been changed yet.");
        return client;
    } catch (ClouderaManagerClientInitException e) {
        throw new ClusterClientInitException(e);
    } catch (ApiException e) {
        return returnClientBasedOnApiError(client, e);
    }
}
Also used : ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiClient(com.cloudera.api.swagger.client.ApiClient) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 3 with ToolsResourceApi

use of com.cloudera.api.swagger.ToolsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndAdminUserIsProvided.

@Test
public void testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndAdminUserIsProvided() throws CloudbreakException, ApiException, ClouderaManagerClientInitException {
    initTestInput(ADMIN);
    UsersResourceApi usersResourceApi = mock(UsersResourceApi.class);
    ToolsResourceApi toolsResourceApi = mock(ToolsResourceApi.class);
    ApiUser2List oldUserList = createApiUser2List();
    when(clouderaManagerApiClientProvider.getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
    when(clouderaManagerApiFactory.getUserResourceApi(any())).thenReturn(usersResourceApi);
    when(usersResourceApi.readUsers2("SUMMARY")).thenReturn(oldUserList);
    when(clouderaManagerApiFactory.getToolsResourceApi(any())).thenReturn(toolsResourceApi);
    when(toolsResourceApi.echo("TEST")).thenReturn(new ApiEcho());
    underTest.changeOriginalCredentialsAndCreateCloudbreakUser(LDAP_ENABLED);
    verify(clouderaManagerApiFactory).getUserResourceApi(apiClient);
    verify(usersResourceApi).readUsers2("SUMMARY");
    ArgumentCaptor<ApiUser2List> argumentCaptor = ArgumentCaptor.forClass(ApiUser2List.class);
    verify(usersResourceApi, times(2)).createUsers2(argumentCaptor.capture());
    List<ApiUser2List> createdUsers = argumentCaptor.getAllValues();
    assertEquals(stack.getCluster().getCloudbreakAmbariUser(), createdUsers.get(0).getItems().get(0).getName());
    assertEquals(stack.getCluster().getCloudbreakAmbariPassword(), createdUsers.get(0).getItems().get(0).getPassword());
    assertEquals(stack.getCluster().getDpAmbariUser(), createdUsers.get(1).getItems().get(0).getName());
    assertEquals(stack.getCluster().getDpAmbariPassword(), createdUsers.get(1).getItems().get(0).getPassword());
    verify(usersResourceApi).updateUser2(oldUserList.getItems().get(0).getName(), oldUserList.getItems().get(0));
}
Also used : UsersResourceApi(com.cloudera.api.swagger.UsersResourceApi) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ApiEcho(com.cloudera.api.swagger.model.ApiEcho) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ToolsResourceApi

use of com.cloudera.api.swagger.ToolsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method setUpApiClientCredentialAlreadyChanged.

private void setUpApiClientCredentialAlreadyChanged() throws ApiException {
    ToolsResourceApi toolsResourceApi = mock(ToolsResourceApi.class);
    when(clouderaManagerApiFactory.getToolsResourceApi(any())).thenReturn(toolsResourceApi);
    when(toolsResourceApi.echo("TEST")).thenThrow(new ApiException(HttpStatus.UNAUTHORIZED.value(), "Bad credentials"));
}
Also used : ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 5 with ToolsResourceApi

use of com.cloudera.api.swagger.ToolsResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndTheGivenUserIsNotAdmin.

@Test
public void testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsConfiguredAndTheGivenUserIsNotAdmin() throws CloudbreakException, ApiException, ClouderaManagerClientInitException {
    initTestInput("ambariUser");
    UsersResourceApi usersResourceApi = mock(UsersResourceApi.class);
    UsersResourceApi newUsersResourceApi = mock(UsersResourceApi.class);
    ToolsResourceApi toolsResourceApi = mock(ToolsResourceApi.class);
    ApiClient newApiClient = mock(ApiClient.class);
    ApiUser2List oldUserList = createApiUser2List();
    when(clouderaManagerApiClientProvider.getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
    when(clouderaManagerApiFactory.getUserResourceApi(apiClient)).thenReturn(usersResourceApi);
    when(usersResourceApi.readUsers2("SUMMARY")).thenReturn(oldUserList);
    when(clouderaManagerApiFactory.getToolsResourceApi(any())).thenReturn(toolsResourceApi);
    when(toolsResourceApi.echo("TEST")).thenReturn(new ApiEcho());
    when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(newApiClient);
    when(clouderaManagerApiFactory.getUserResourceApi(newApiClient)).thenReturn(newUsersResourceApi);
    underTest.changeOriginalCredentialsAndCreateCloudbreakUser(LDAP_ENABLED);
    verify(clouderaManagerApiClientProvider).getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31);
    verify(usersResourceApi).readUsers2("SUMMARY");
    verify(clouderaManagerApiClientProvider, times(2)).getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31);
    ArgumentCaptor<ApiUser2List> createUserCaptor = ArgumentCaptor.forClass(ApiUser2List.class);
    verify(usersResourceApi, times(2)).createUsers2(createUserCaptor.capture());
    List<ApiUser2List> createdUsers = createUserCaptor.getAllValues();
    assertEquals(stack.getCluster().getCloudbreakAmbariUser(), createdUsers.get(0).getItems().get(0).getName());
    assertEquals(stack.getCluster().getCloudbreakAmbariPassword(), createdUsers.get(0).getItems().get(0).getPassword());
    assertEquals(stack.getCluster().getDpAmbariUser(), createdUsers.get(1).getItems().get(0).getName());
    assertEquals(stack.getCluster().getDpAmbariPassword(), createdUsers.get(1).getItems().get(0).getPassword());
    ArgumentCaptor<ApiUser2List> createNewUserCaptor = ArgumentCaptor.forClass(ApiUser2List.class);
    verify(newUsersResourceApi).createUsers2(createNewUserCaptor.capture());
    List<ApiUser2List> createdNewUser = createNewUserCaptor.getAllValues();
    assertEquals(stack.getCluster().getUserName(), createdNewUser.get(0).getItems().get(0).getName());
    assertEquals(stack.getCluster().getPassword(), createdNewUser.get(0).getItems().get(0).getPassword());
    verify(newUsersResourceApi).deleteUser2(ADMIN);
}
Also used : UsersResourceApi(com.cloudera.api.swagger.UsersResourceApi) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ApiEcho(com.cloudera.api.swagger.model.ApiEcho) ToolsResourceApi(com.cloudera.api.swagger.ToolsResourceApi) ApiClient(com.cloudera.api.swagger.client.ApiClient) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ToolsResourceApi (com.cloudera.api.swagger.ToolsResourceApi)7 ApiClient (com.cloudera.api.swagger.client.ApiClient)4 ApiException (com.cloudera.api.swagger.client.ApiException)4 ApiEcho (com.cloudera.api.swagger.model.ApiEcho)4 UsersResourceApi (com.cloudera.api.swagger.UsersResourceApi)3 ApiUser2List (com.cloudera.api.swagger.model.ApiUser2List)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ClusterClientInitException (com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException)2 ClouderaManagerClientInitException (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException)2 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1