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