use of com.cloudera.api.swagger.HostsResourceApi 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());
}
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerCommissioner method collectHostsToCommission.
public Map<String, InstanceMetaData> collectHostsToCommission(Stack stack, HostGroup hostGroup, Set<String> hostNames, ApiClient client) {
Set<InstanceMetaData> hostsInHostGroup = hostGroup.getInstanceGroup().getNotTerminatedAndNotZombieInstanceMetaDataSet();
Map<String, InstanceMetaData> hostsToCommission = hostsInHostGroup.stream().filter(hostMetadata -> hostNames.contains(hostMetadata.getDiscoveryFQDN())).collect(Collectors.toMap(InstanceMetaData::getDiscoveryFQDN, hostMetadata -> hostMetadata));
if (hostsToCommission.size() != hostNames.size()) {
List<String> missingHosts = hostNames.stream().filter(h -> !hostsToCommission.containsKey(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CB for host group: {}. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", hostGroup.getName(), missingHosts.size(), missingHosts, hostNames);
}
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
List<String> cmHostNames = hostRefList.getItems().stream().map(ApiHost::getHostname).collect(Collectors.toList());
List<String> matchingCmHosts = hostsToCommission.keySet().stream().filter(hostName -> cmHostNames.contains(hostName)).collect(Collectors.toList());
Set<String> matchingCmHostSet = new HashSet<>(matchingCmHosts);
if (matchingCmHosts.size() != hostsToCommission.size()) {
List<String> missingHostsInCm = hostsToCommission.keySet().stream().filter(h -> !matchingCmHostSet.contains(h)).collect(Collectors.toList());
LOGGER.debug("Not all requested hosts found in CM. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", missingHostsInCm.size(), missingHostsInCm, hostsToCommission.keySet());
}
Sets.newHashSet(hostsToCommission.keySet()).stream().filter(hostName -> !matchingCmHostSet.contains(hostName)).forEach(hostsToCommission::remove);
LOGGER.debug("Collected hosts to commission: [{}]", hostsToCommission);
return hostsToCommission;
} catch (ApiException e) {
// TODO: CB-14929: This exception has to be handled properly. Situations where CM communications fails. There's no retries here right now.
LOGGER.error("Failed to get host list for cluster: {}", stack.getName(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClientActions method checkCmServicesStartedSuccessfully.
public DistroXTestDto checkCmServicesStartedSuccessfully(DistroXTestDto testDto, String user, String password) {
String serverIp = testDto.getResponse().getCluster().getServerIp();
ApiClient apiClient = getCmApiClientWithTimeoutDisabledDirect(serverIp, testDto.getName(), V_43, user, password);
// CHECKSTYLE:OFF
HostsResourceApi hostsResourceApi = new HostsResourceApi(apiClient);
// CHECKSTYLE:ON
try {
Set<String> masterHostnames = testDto.getResponse().getInstanceGroups().stream().filter(ig -> "master".equals(ig.getName())).flatMap(ig -> ig.getMetadata().stream()).map(InstanceMetaDataV4Response::getDiscoveryFQDN).collect(Collectors.toSet());
List<ApiHost> apiHosts = hostsResourceApi.readHosts(null, null, "FULL_WITH_HEALTH_CHECK_EXPLANATION").getItems();
Set<String> servicesNotStarted = apiHosts.stream().filter(apiHost -> masterHostnames.contains(apiHost.getHostname())).flatMap(apiHost -> collectNotStartedServicesOnHost(apiHost).stream()).filter(serviceName -> REQUIRED_SERVICES.contains(serviceName)).collect(Collectors.toSet());
if (!servicesNotStarted.isEmpty()) {
LOGGER.error("There are not started required services: {}", servicesNotStarted);
throw new TestFailException(String.format("There are not started required services: %s", servicesNotStarted));
}
} catch (ApiException e) {
LOGGER.error("Exception when calling HostsResourceApi#readHosts. Response: {}", e.getResponseBody(), e);
String message = format("Exception when calling HostsResourceApi#readHosts at %s. Response: %s", apiClient.getBasePath(), e.getResponseBody());
throw new TestFailException(message, e);
} catch (Exception e) {
LOGGER.error("Can't read host statuses at: '{}'!", apiClient.getBasePath());
throw new TestFailException("Can't read host statuses at: " + apiClient.getBasePath(), e);
}
return testDto;
}
use of com.cloudera.api.swagger.HostsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method enterMaintenanceMode.
public void enterMaintenanceMode(Stack stack, 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);
}
}
Aggregations