use of com.cloudera.api.swagger.model.ApiEcho 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.model.ApiEcho 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);
}
use of com.cloudera.api.swagger.model.ApiEcho in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsNotConfiguredAndTheGivenUserIsNotAdmin.
@Test
public void testChangeOriginalCredentialsAndCreateCloudbreakUserWhenLdapIsNotConfiguredAndTheGivenUserIsNotAdmin() 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_DISABLED);
verify(clouderaManagerApiClientProvider).getDefaultClient(GATEWAY_PORT, clientConfig, ClouderaManagerApiClientProvider.API_V_31);
verify(usersResourceApi).readUsers2("SUMMARY");
verify(clouderaManagerApiClientProvider).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());
verifyNoMoreInteractions(clouderaManagerApiClientProvider);
}
use of com.cloudera.api.swagger.model.ApiEcho in project cloudbreak by hortonworks.
the class ClouderaManagerStartupListenerTask method doStatusCheck.
@Override
protected boolean doStatusCheck(ClouderaManagerPollerObject pollerObject) throws ApiException {
try {
ToolsResourceApi toolsResourceApi = clouderaManagerApiPojoFactory.getToolsResourceApi(pollerObject.getApiClient());
String testMessage = "test";
ApiEcho testIfRunning = toolsResourceApi.echo(testMessage);
if (testMessage.equals(testIfRunning.getMessage())) {
return true;
} else {
LOGGER.info("test message is different which is strange, returned message: " + testIfRunning.getMessage());
return false;
}
} catch (ApiException e) {
String errorMessage = e.getMessage();
if (ArrayUtils.contains(ERROR_CODES, e.getCode()) || Arrays.stream(CONNECTION_MESSAGES).anyMatch(msg -> containsIgnoreCase(errorMessage, msg))) {
LOGGER.debug("Cloudera Manager is not running.");
return false;
} else {
throw e;
}
}
}
Aggregations