use of com.cloudera.api.swagger.BatchResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificatesWhenPollingTimedOut.
@Test
public void testRotateHostCertificatesWhenPollingTimedOut() throws Exception {
// GIVEN
initTestInput("user");
when(clouderaManagerApiClientProvider.getClouderaManagerClient(clientConfig, GATEWAY_PORT, stack.getCluster().getCloudbreakAmbariUser(), stack.getCluster().getCloudbreakAmbariPassword(), ClouderaManagerApiClientProvider.API_V_31)).thenReturn(apiClient);
HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
BatchResourceApi batchResourceApi = mock(BatchResourceApi.class);
when(clouderaManagerApiFactory.getHostsResourceApi(apiClient)).thenReturn(hostsResourceApi);
when(clouderaManagerApiFactory.getBatchResourceApi(apiClient)).thenReturn(batchResourceApi);
ApiHostList hostList = createApiHostList();
when(hostsResourceApi.readHosts(null, null, "SUMMARY")).thenReturn(hostList);
ArgumentCaptor<ApiBatchRequest> batchRequestArgumentCaptor = ArgumentCaptor.forClass(ApiBatchRequest.class);
when(batchResourceApi.execute(batchRequestArgumentCaptor.capture())).thenReturn(createApiBatchResponse(hostList, true));
when(clouderaManagerPollingServiceProvider.startPollingCommandList(eq(stack), eq(apiClient), any(List.class), eq("Rotate host certificates"))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().timeout().build());
// WHEN
ClouderaManagerOperationFailedException exception = assertThrows(ClouderaManagerOperationFailedException.class, () -> underTest.rotateHostCertificates(null, null, null));
// THEN exception
assertThat(exception).hasMessage("Timeout while Cloudera Manager rotates the host certificates.");
}
use of com.cloudera.api.swagger.BatchResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityService method rotateHostCertificates.
@Override
public void rotateHostCertificates(String sshUser, KeyPair sshKeyPair, String subAltName) throws CloudbreakException {
Cluster cluster = stack.getCluster();
String user = cluster.getCloudbreakAmbariUser();
String password = cluster.getCloudbreakAmbariPassword();
try {
ApiClient client = getClient(stack.getGatewayPort(), user, password, clientConfig);
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
BatchResourceApi batchResourceApi = clouderaManagerApiFactory.getBatchResourceApi(client);
ApiHostList hostList = hostsResourceApi.readHosts(null, null, "SUMMARY");
ApiBatchRequest batchRequest = createHostCertsBatchRequest(hostList, sshUser, sshKeyPair, subAltName);
ApiBatchResponse apiBatchResponse = batchResourceApi.execute(batchRequest);
processHostCertsBatchResponse(client, apiBatchResponse);
} catch (ApiException | ClouderaManagerClientInitException e) {
LOGGER.warn("Can't rotate the host certificates", e);
throw new CloudbreakException("Can't rotate the host certificates due to: " + e.getMessage());
}
}
Aggregations