Search in sources :

Example 6 with HostsResourceApi

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);
    }
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiHost(com.cloudera.api.swagger.model.ApiHost) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 7 with HostsResourceApi

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);
    }
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 8 with HostsResourceApi

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);
    }
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 9 with HostsResourceApi

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);
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi)

Example 10 with HostsResourceApi

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");
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) List(java.util.List) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiUser2List(com.cloudera.api.swagger.model.ApiUser2List) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)34 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)29 ApiClient (com.cloudera.api.swagger.client.ApiClient)19 ApiException (com.cloudera.api.swagger.client.ApiException)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)15 ApiHost (com.cloudera.api.swagger.model.ApiHost)13 List (java.util.List)13 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)11 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)11 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Test (org.junit.jupiter.api.Test)10 HostTemplatesResourceApi (com.cloudera.api.swagger.HostTemplatesResourceApi)9 ApiHostTemplateList (com.cloudera.api.swagger.model.ApiHostTemplateList)9 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)9 ClouderaManagerApiFactory (com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory)9 ClouderaManagerPollingServiceProvider (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider)9 HashSet (java.util.HashSet)9