use of com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware in project cloudbreak by hortonworks.
the class SaltOrchestrator method tearDown.
@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
@Override
public void tearDown(OrchestratorAware stack, List<GatewayConfig> allGatewayConfigs, Map<String, String> removeNodePrivateIPsByFQDN, Set<Node> remainingNodes, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
LOGGER.debug("Tear down hosts: {},", removeNodePrivateIPsByFQDN);
LOGGER.debug("Gateway config for tear down: {}", allGatewayConfigs);
Set<String> remainingIps = remainingNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
LOGGER.debug("Remaining IPs: {}", remainingIps);
Set<String> minionsToStop = removeNodePrivateIPsByFQDN.values().stream().filter(not(remainingIps::contains)).collect(Collectors.toSet());
LOGGER.debug("Minions to stop: {}", minionsToStop);
GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs);
Set<String> gatewayTargetIpAddresses = getGatewayPrivateIps(allGatewayConfigs);
try (SaltConnector saltConnector = saltService.createSaltConnector(primaryGateway)) {
SaltStates.stopMinions(saltConnector, minionsToStop);
if (!CollectionUtils.isEmpty(remainingNodes)) {
saveHostsPillar(stack, exitModel, gatewayTargetIpAddresses, saltConnector);
}
} catch (Exception e) {
LOGGER.info("Error occurred during salt minion tear down", e);
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
List<GatewayConfig> liveGateways = allGatewayConfigs.stream().filter(gw -> remainingIps.contains(gw.getPrivateAddress())).collect(Collectors.toList());
for (GatewayConfig gatewayConfig : liveGateways) {
try (SaltConnector sc = saltService.createSaltConnector(gatewayConfig)) {
sc.wheel("key.delete", removeNodePrivateIPsByFQDN.keySet(), Object.class);
removeDeadSaltMinions(gatewayConfig);
} catch (Exception e) {
LOGGER.info("Error occurred during salt minion tear down", e);
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
}
use of com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware in project cloudbreak by hortonworks.
the class SaltOrchestrator method stopClusterManagerAgent.
@Override
public void stopClusterManagerAgent(OrchestratorAware stack, GatewayConfig gatewayConfig, Set<Node> allNodes, Set<Node> nodesUnderStopping, ExitCriteriaModel exitCriteriaModel, CmAgentStopFlags flags) throws CloudbreakOrchestratorFailedException {
try (SaltConnector sc = saltService.createSaltConnector(gatewayConfig)) {
NodeReachabilityResult nodeReachabilityResult = getResponsiveNodes(allNodes, sc);
Set<Node> responsiveNodes = nodeReachabilityResult.getReachableNodes();
Set<String> nodesUnderStoppingIPs = nodesUnderStopping.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
Set<Node> responsiveNodesUnderStopping = responsiveNodes.stream().filter(responsiveNode -> nodesUnderStoppingIPs.contains(responsiveNode.getPrivateIp())).collect(Collectors.toSet());
if (!responsiveNodesUnderStopping.isEmpty()) {
LOGGER.debug("Applying role 'cloudera_manager_agent_stop' on nodes: [{}]", responsiveNodesUnderStopping);
Set<String> targetHostnames = responsiveNodesUnderStopping.stream().map(Node::getHostname).collect(Collectors.toSet());
saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(targetHostnames, responsiveNodesUnderStopping, "roles", "cloudera_manager_agent_stop"), exitCriteriaModel, exitCriteria);
if (flags.isAdJoinable() || flags.isIpaJoinable()) {
String identityRole = flags.isAdJoinable() ? "ad_leave" : "ipa_leave";
LOGGER.debug("Applying role '{}' on nodes: [{}]", identityRole, responsiveNodesUnderStopping);
saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(targetHostnames, responsiveNodesUnderStopping, "roles", identityRole), exitCriteriaModel, exitCriteria);
String removeIdentityRole = flags.isAdJoinable() ? "ad_member" : "ipa_member";
LOGGER.debug("Removing role '{}' on nodes: [{}]", removeIdentityRole, responsiveNodesUnderStopping);
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(targetHostnames, responsiveNodesUnderStopping, "roles", removeIdentityRole), exitCriteriaModel, exitCriteria);
}
Set<String> allHostnames = responsiveNodesUnderStopping.stream().map(Node::getHostname).collect(Collectors.toSet());
runSyncAll(sc, allHostnames, responsiveNodesUnderStopping, exitCriteriaModel);
saveHostsPillar(stack, exitCriteriaModel, getGatewayPrivateIps(Collections.singleton(gatewayConfig)), sc);
runNewService(sc, new HighStateRunner(allHostnames, responsiveNodesUnderStopping), exitCriteriaModel, maxRetry, true);
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(targetHostnames, responsiveNodesUnderStopping, "roles", "cloudera_manager_agent_stop"), exitCriteriaModel, exitCriteria);
if (flags.isAdJoinable() || flags.isIpaJoinable()) {
String identityRole = flags.isAdJoinable() ? "ad_leave" : "ipa_leave";
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(targetHostnames, responsiveNodesUnderStopping, "roles", identityRole), exitCriteriaModel, exitCriteria);
}
}
} catch (Exception e) {
LOGGER.info("Error occurred during executing highstate (for cluster manager agent stop).", e);
throwExceptionIfNotForced(flags.isForced(), e);
}
}
use of com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware in project cloudbreak by hortonworks.
the class SaltOrchestrator method formatAndMountDisksOnNodes.
@Override
@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public Map<String, Map<String, String>> formatAndMountDisksOnNodes(OrchestratorAware stack, List<GatewayConfig> allGateway, Set<Node> nodesWithDiskData, Set<Node> allNodes, ExitCriteriaModel exitModel, String platformVariant) throws CloudbreakOrchestratorFailedException {
GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway);
Set<String> gatewayTargetIpAddresses = getGatewayPrivateIps(allGateway);
Target<String> allHosts = new HostList(nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toSet()));
try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) {
saveHostsPillar(stack, exitModel, gatewayTargetIpAddresses, sc);
Callable<Boolean> saltPillarRunner;
Map<String, String> dataVolumeMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getDataVolumes()));
Map<String, String> serialIdMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getSerialIds()));
Map<String, String> fstabMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getFstab()));
Map<String, String> temporaryStorageMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getTemporaryStorage().name()));
Map<String, Integer> dataBaseVolumeIndexMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getDatabaseVolumeIndex()));
Map<String, Object> hostnameDiskMountMap = nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toMap(hn -> hn, hn -> Map.of("attached_volume_name_list", dataVolumeMap.getOrDefault(hn, ""), "attached_volume_serial_list", serialIdMap.getOrDefault(hn, ""), "cloud_platform", platformVariant, "previous_fstab", fstabMap.getOrDefault(hn, ""), "database_volume_index", dataBaseVolumeIndexMap.getOrDefault(hn, -1), "temporary_storage", temporaryStorageMap.getOrDefault(hn, TemporaryStorage.ATTACHED_VOLUMES.name()))));
SaltPillarProperties mounDiskProperties = new SaltPillarProperties("/mount/disk.sls", Collections.singletonMap("mount_data", hostnameDiskMountMap));
OrchestratorBootstrap pillarSave = PillarSave.createCustomPillar(sc, gatewayTargetIpAddresses, mounDiskProperties);
saltPillarRunner = saltRunner.runner(pillarSave, exitCriteria, exitModel);
saltPillarRunner.call();
saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(hostnameDiskMountMap.keySet(), allNodes, "mount_disks"), exitModel, exitCriteria);
StateAllRunner stateAllRunner = new StateAllRunner(gatewayTargetIpAddresses, allNodes, "disks.format-and-mount");
OrchestratorBootstrap saltJobIdTracker = new SaltJobIdTracker(sc, stateAllRunner);
Callable<Boolean> saltJobRunBootstrapRunner = saltRunner.runner(saltJobIdTracker, exitCriteria, exitModel);
saltJobRunBootstrapRunner.call();
Map<String, String> uuidResponse = SaltStates.getUuidList(sc);
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(hostnameDiskMountMap.keySet(), allNodes, "mount_disks"), exitModel, exitCriteria);
Map<String, String> fstabResponse = SaltStates.runCommandOnHosts(retry, sc, allHosts, "cat /etc/fstab");
return nodesWithDiskData.stream().map(node -> {
String fstab = fstabResponse.getOrDefault(node.getHostname(), "");
String uuidList = uuidResponse.getOrDefault(node.getHostname(), "");
return new SimpleImmutableEntry<>(node.getHostname(), Map.of("uuids", uuidList, "fstab", fstab));
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
} catch (Exception e) {
LOGGER.info("Error occurred during the salt bootstrap", e);
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
Aggregations