use of com.cloudera.api.swagger.model.ApiHostNameList in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method decommissionNodesStopStart.
public Set<String> decommissionNodesStopStart(Stack stack, Map<String, InstanceMetaData> hostsToRemove, ApiClient client, long pollingTimeout) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
LOGGER.trace("Target decommissionNodes: count={}, hosts=[{}]", hostsToRemove.size(), hostsToRemove.keySet());
LOGGER.debug("hostsAvailableFromCM: count={}, hosts=[{}]", hostRefList.getItems().size(), hostRefList.getItems().stream().map(ApiHost::getHostname));
List<String> stillAvailableRemovableHosts = hostRefList.getItems().stream().filter(apiHostRef -> hostsToRemove.containsKey(apiHostRef.getHostname())).parallel().map(ApiHost::getHostname).collect(Collectors.toList());
Set<String> hostsAvailableForDecommissionSet = new HashSet<>(stillAvailableRemovableHosts);
List<String> cmHostsUnavailableForDecommission = hostsToRemove.keySet().stream().filter(h -> !hostsAvailableForDecommissionSet.contains(h)).collect(Collectors.toList());
if (cmHostsUnavailableForDecommission.size() != 0) {
LOGGER.info("Some decommission targets are unavailable in CM: TotalDecommissionTargetCount={}, unavailableInCMCount={}, unavailableInCm=[{}]", hostsToRemove.size(), cmHostsUnavailableForDecommission.size(), cmHostsUnavailableForDecommission);
}
ClouderaManagerResourceApi apiInstance = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
ApiHostNameList body = new ApiHostNameList().items(stillAvailableRemovableHosts);
ApiCommand apiCommand = apiInstance.hostsDecommissionCommand(body);
ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmHostsDecommission(stack, client, apiCommand.getId(), pollingTimeout);
if (pollingResult.isExited()) {
throw new CancellationException("Cluster was terminated while waiting for host decommission");
} else if (pollingResult.isTimeout()) {
String warningMessage = "Cloudera Manager decommission host command {} polling timed out, " + "thus we are aborting the decommission and we are retrying it for lost nodes once again.";
abortDecommissionWithWarningMessage(apiCommand, client, warningMessage);
throw new CloudbreakServiceException(String.format("Timeout while Cloudera Manager decommissioned host. CM command Id: %s", apiCommand.getId()));
}
return stillAvailableRemovableHosts.stream().map(hostsToRemove::get).filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null).map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toSet());
} catch (ApiException e) {
LOGGER.error("Failed to decommission hosts: {}", hostsToRemove.keySet(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.model.ApiHostNameList in project cloudbreak by hortonworks.
the class ClouderaManagerDecomissioner method decommissionNodes.
public Set<String> decommissionNodes(Stack stack, Map<String, InstanceMetaData> hostsToRemove, ApiClient client) {
HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
try {
ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
List<String> stillAvailableRemovableHosts = hostRefList.getItems().stream().filter(apiHostRef -> hostsToRemove.containsKey(apiHostRef.getHostname())).parallel().map(ApiHost::getHostname).collect(Collectors.toList());
LOGGER.debug("Decommissioning nodes: [{}]", stillAvailableRemovableHosts);
boolean onlyLostNodesAffected = hostsToRemove.values().stream().allMatch(InstanceMetaData::isDeletedOnProvider);
String hostGroupName = hostsToRemove.values().stream().map(instanceMetaData -> instanceMetaData.getInstanceGroup().getGroupName()).findFirst().get();
ClouderaManagerResourceApi apiInstance = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
ApiHostNameList body = new ApiHostNameList().items(stillAvailableRemovableHosts);
ApiCommand apiCommand = apiInstance.hostsDecommissionCommand(body);
ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmHostDecommissioning(stack, client, apiCommand.getId(), onlyLostNodesAffected, stillAvailableRemovableHosts.size());
if (pollingResult.isExited()) {
throw new CancellationException("Cluster was terminated while waiting for host decommission");
} else if (pollingResult.isTimeout()) {
if (onlyLostNodesAffected) {
String warningMessage = "Cloudera Manager decommission host command {} polling timed out, " + "thus we are aborting the decommission and we are retrying it for lost nodes once again.";
abortDecommissionWithWarningMessage(apiCommand, client, warningMessage);
retryDecommissionNodes(apiInstance, body, stack, client, stillAvailableRemovableHosts, hostGroupName);
} else {
throw new CloudbreakServiceException("Timeout while Cloudera Manager decommissioned host.");
}
}
return stillAvailableRemovableHosts.stream().map(hostsToRemove::get).filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null).map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toSet());
} catch (ApiException e) {
LOGGER.error("Failed to decommission hosts: {}", hostsToRemove.keySet(), e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
use of com.cloudera.api.swagger.model.ApiHostNameList in project cloudbreak by hortonworks.
the class ClouderaManagerCommissioner method recommissionHosts.
/**
* Attempts to recommission the provided list of hosts
* @param stack the stack under consideration
* @param hostsToRecommission hosts to recommission
* @param client api client to communicate with ClouderaManager
* @throws CloudbreakServiceException when it fails to recommission due to timeout or cancellation
*/
public void recommissionHosts(Stack stack, ApiClient client, List<String> hostsToRecommission) {
ClouderaManagerResourceApi apiInstance = clouderaManagerApiFactory.getClouderaManagerResourceApi(client);
ApiHostNameList body = new ApiHostNameList().items(hostsToRecommission);
ApiCommand apiCommand;
try {
apiCommand = apiInstance.hostsRecommissionAndExitMaintenanceModeCommand("recommission_with_start", body);
ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmHostsRecommission(stack, client, apiCommand.getId());
if (pollingResult.isExited()) {
throw new CancellationException("Cluster was terminated while waiting for host commission");
} else if (pollingResult.isTimeout()) {
String warningMessage = "Cloudera Manager recommission host command {} polling timed out, " + "thus we are aborting the recommission operation.";
abortRecommissionWithWarnMessage(apiCommand, client, warningMessage);
// - We could go and STOP all instances, which essentially means re-trying the recommission the next time around.
throw new CloudbreakServiceException(String.format("Timeout while Cloudera Manager recommissioned hosts. CM command Id: %s", apiCommand.getId()));
}
} catch (ApiException e) {
// TODO CB-15132: Evaluate whether it is possible to figure out if a partial commission succeeded.
// Retry / STOP other nodes where it may have failed.
LOGGER.error("Failed to recommission hosts: {}", hostsToRecommission, e);
throw new CloudbreakServiceException(e.getMessage(), e);
}
}
Aggregations