use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method enterMaintenanceMode.
public void enterMaintenanceMode(Set<String> hostList, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
String currentHostId = null;
int successCount = 0;
List<String> availableHostsIdsFromCm = null;
LOGGER.debug("Attempting to put {} instances into CM maintenance mode", hostList == null ? 0 : hostList.size());
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
availableHostsIdsFromCm = hostRefList.getItems().stream().filter(apiHostRef -> hostList.contains(apiHostRef.getHostname())).parallel().map(ApiHost::getHostId).collect(Collectors.toList());
for (String hostId : availableHostsIdsFromCm) {
currentHostId = hostId;
hostsResourceApi.enterMaintenanceMode(hostId);
successCount++;
}
LOGGER.debug("Finished putting {} instances into CM maintenance mode. Initial request size: {}, CM availableCount: {}", successCount, hostList == null ? 0 : hostList.size(), availableHostsIdsFromCm == null ? "null" : availableHostsIdsFromCm);
} catch (ApiException e) {
LOGGER.error("Failed while putting a node into maintenance mode. nodeId=" + currentHostId + ", successCount=" + successCount, e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClusterStatusService method getDecommissionedHostsFromCM.
@Override
public List<String> getDecommissionedHostsFromCM() {
HostsResourceApi api = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList apiHostList = api.readHosts(null, null, SUMMARY);
LOGGER.trace("Response from CM for readHosts call: {}", apiHostList);
return apiHostList.getItems().stream().filter(host -> Boolean.TRUE.equals(host.getMaintenanceMode())).map(ApiHost::getHostname).collect(toList());
} catch (ApiException e) {
LOGGER.info("Failed to get hosts from CM", e);
throw new RuntimeException("Failed to get hosts from CM due to: " + e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClusterStatusService method getHostsFromCM.
private List<ApiHost> getHostsFromCM() {
HostsResourceApi api = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList apiHostList = api.readHosts(null, null, FULL_WITH_EXPLANATION_VIEW);
LOGGER.trace("Response from CM for readHosts call: {}", apiHostList);
return apiHostList.getItems();
} catch (ApiException e) {
LOGGER.info("Failed to get hosts from CM", e);
throw new RuntimeException("Failed to get hosts from CM due to: " + e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerHostHealthyStatusChecker method fetchGoodHostsFromManager.
private Set<String> fetchGoodHostsFromManager(ClouderaManagerPollerObject pollerObject) throws ApiException {
HostsResourceApi hostsResourceApi = clouderaManagerApiPojoFactory.getHostsResourceApi(pollerObject.getApiClient());
ApiHostList hostList = hostsResourceApi.readHosts(null, null, VIEW_TYPE);
return filterForHealthy(hostList);
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerSecurityServiceTest method testRotateHostCertificates.
@ParameterizedTest(name = "{0}")
@MethodSource("testRotateHostCertificatesWhenBatchExecuteSucceededDataProvider")
public void testRotateHostCertificates(String testCaseName, String subAltName) 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().success().build());
// WHEN
underTest.rotateHostCertificates(null, null, subAltName);
// THEN no exception
verifyBatchRequest(batchRequestArgumentCaptor.getValue(), subAltName, "/api/v31/hosts/host-1/commands/generateHostCerts", "/api/v31/hosts/host%40company.com%202/commands/generateHostCerts");
}
Aggregations