use of com.sequenceiq.cloudbreak.polling.PollingResult in project cloudbreak by hortonworks.
the class RemoveHostsHandler method removeHostsFromOrchestrator.
private PollingResult removeHostsFromOrchestrator(Stack stack, List<String> hostNames, HostOrchestrator hostOrchestrator, List<GatewayConfig> allGatewayConfigs) throws CloudbreakException {
LOGGER.debug("Remove hosts from orchestrator: {}", hostNames);
try {
Map<String, String> removeNodePrivateIPsByFQDN = new HashMap<>();
stack.getNotTerminatedInstanceMetaDataSet().stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null).filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.equals(instanceMetaData.getDiscoveryFQDN()))).forEach(instanceMetaData -> removeNodePrivateIPsByFQDN.put(instanceMetaData.getDiscoveryFQDN(), instanceMetaData.getPrivateIp()));
Set<Node> remainingNodes = stackUtil.collectNodes(stack).stream().filter(node -> !removeNodePrivateIPsByFQDN.containsValue(node.getPrivateIp())).collect(Collectors.toSet());
ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId());
hostOrchestrator.tearDown(stack, allGatewayConfigs, removeNodePrivateIPsByFQDN, remainingNodes, exitCriteriaModel);
} catch (CloudbreakOrchestratorException e) {
LOGGER.error("Failed to delete orchestrator components while decommissioning: ", e);
throw new CloudbreakException("Removing selected nodes from master node failed, " + "please check if selected nodes are still reachable from master node using terminal and " + "nodes are in sync between CM, CDP and provider side or you can remove selected nodes forcefully.");
}
return SUCCESS;
}
use of com.sequenceiq.cloudbreak.polling.PollingResult in project cloudbreak by hortonworks.
the class RemoveHostsHandler method accept.
@Override
public void accept(Event<RemoveHostsRequest> removeHostsRequestEvent) {
RemoveHostsRequest request = removeHostsRequestEvent.getData();
Set<String> hostNames = request.getHostNames();
Selectable result;
try {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
if (stack.getPrimaryGatewayInstance() != null && stack.getPrimaryGatewayInstance().isReachable()) {
List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames), hostOrchestrator, allGatewayConfigs);
if (!orchestratorRemovalPollingResult.isSuccess()) {
LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames);
}
} else {
LOGGER.warn("Primary gateway is not reachable, can't remove hosts from orchestrator");
}
result = new RemoveHostsSuccess(request.getResourceId(), request.getHostGroupNames(), hostNames);
} catch (Exception e) {
result = new RemoveHostsFailed(removeHostsRequestEvent.getData().getResourceId(), e, request.getHostGroupNames(), hostNames);
}
eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.polling.PollingResult in project cloudbreak by hortonworks.
the class ClouderaManagerModificationService method doRestartServicesIfNeeded.
private int doRestartServicesIfNeeded(ClustersResourceApi clustersResourceApi, boolean waitForCommandExecutionOnly) throws ApiException, CloudbreakException {
ApiCommandList apiCommandList = clustersResourceApi.listActiveCommands(stack.getName(), SUMMARY);
Optional<ApiCommand> optionalRestartCommand = apiCommandList.getItems().stream().filter(cmd -> "Restart".equals(cmd.getName())).findFirst();
ApiCommand restartCommand = null;
if (optionalRestartCommand.isPresent()) {
restartCommand = optionalRestartCommand.get();
LOGGER.debug("Restart for Cluster services is already running with id: [{}]", restartCommand.getId());
} else if (!waitForCommandExecutionOnly) {
LOGGER.info("Restarting cluster services.");
ApiRestartClusterArgs restartClusterArgs = new ApiRestartClusterArgs();
restartClusterArgs.setRedeployClientConfiguration(true);
restartCommand = clustersResourceApi.restartCommand(stack.getName(), restartClusterArgs);
eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), CLUSTER_CM_CLUSTER_SERVICES_RESTARTING);
}
if (restartCommand != null) {
ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClient, restartCommand.getId());
handlePollingResult(pollingResult, "Cluster was terminated while restarting services.", "Timeout happened while restarting services.");
}
return getCommandId(restartCommand);
}
use of com.sequenceiq.cloudbreak.polling.PollingResult in project cloudbreak by hortonworks.
the class RemoveHostsHandler method removeHostsFromOrchestrator.
private PollingResult removeHostsFromOrchestrator(Stack stack, List<String> hostNames) throws CloudbreakException {
LOGGER.debug("Remove hosts from orchestrator: [{}]", hostNames);
try {
Map<String, String> removeNodePrivateIPsByFQDN = stack.getAllInstanceMetaDataList().stream().filter(instanceMetaData -> Objects.nonNull(instanceMetaData.getDiscoveryFQDN())).filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.equals(instanceMetaData.getDiscoveryFQDN()))).collect(Collectors.toMap(instanceMetaData -> instanceMetaData.getDiscoveryFQDN(), instanceMeataData -> instanceMeataData.getPrivateIp()));
Set<InstanceMetaData> remainingInstanceMetaDatas = stack.getNotDeletedInstanceMetaDataList().stream().filter(instanceMetaData -> !shouldRemove(instanceMetaData, removeNodePrivateIPsByFQDN)).collect(Collectors.toSet());
Set<InstanceMetaData> invalidInstanceMetadata = remainingInstanceMetaDatas.stream().filter(instanceMetaData -> Objects.isNull(instanceMetaData.getDiscoveryFQDN())).collect(Collectors.toSet());
Set<InstanceMetaData> validRemainingNodes = remainingInstanceMetaDatas.stream().filter(instanceMetaData -> Objects.nonNull(instanceMetaData.getDiscoveryFQDN())).collect(Collectors.toSet());
Set<Node> remainingNodes = validRemainingNodes.stream().map(im -> new Node(im.getPrivateIp(), im.getPublicIp(), im.getInstanceId(), im.getInstanceGroup().getTemplate().getInstanceType(), im.getDiscoveryFQDN(), im.getInstanceGroup().getGroupName())).collect(Collectors.toSet());
List<GatewayConfig> remainingGatewayConfigs = gatewayConfigService.getGatewayConfigs(stack, validRemainingNodes);
LOGGER.debug("Tearing down [{}]. The following were dropped because they did not contain a FQDN [{}]. The remaining nodes are [{}].", removeNodePrivateIPsByFQDN, invalidInstanceMetadata, remainingNodes);
hostOrchestrator.tearDown(stack, remainingGatewayConfigs, removeNodePrivateIPsByFQDN, remainingNodes, new StackBasedExitCriteriaModel(stack.getId()));
} catch (CloudbreakOrchestratorException e) {
LOGGER.info("Failed to delete orchestrator components while decommissioning: ", e);
throw new CloudbreakException("Failed to delete orchestrator components while decommissioning: ", e);
}
return SUCCESS;
}
use of com.sequenceiq.cloudbreak.polling.PollingResult in project cloudbreak by hortonworks.
the class RemoveHostsHandler method accept.
@Override
public void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent) {
RemoveHostsFromOrchestrationRequest request = removeHostsRequestEvent.getData();
Set<String> hostNames = request.getHosts();
Selectable result;
try {
if (!hostNames.isEmpty()) {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames));
if (!orchestratorRemovalPollingResult.isSuccess()) {
LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames);
}
// rebootstrap to update the minion's multi-master configuration
List<String> remainingInstanceIds = stack.getNotDeletedInstanceMetaDataList().stream().filter(metadata -> Objects.nonNull(metadata.getDiscoveryFQDN())).filter(metadata -> !hostNames.contains(metadata.getDiscoveryFQDN())).map(InstanceMetaData::getInstanceId).collect(Collectors.toList());
bootstrapService.bootstrap(stack.getId(), remainingInstanceIds);
}
result = new RemoveHostsFromOrchestrationSuccess(request.getResourceId());
} catch (Exception e) {
LOGGER.error("Failed to remove hosts from orchestration", e);
result = new DownscaleFailureEvent(REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT.event(), request.getResourceId(), "Removing host from orchestration", Set.of(), Map.of(), e);
}
eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result));
}
Aggregations