use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltOrchestrator method bootstrapNewNodes.
@Override
public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
GatewayConfig primaryGateway = getPrimaryGatewayConfig(allGatewayConfigs);
Set<String> gatewayTargets = allGatewayConfigs.stream().filter(gc -> targets.stream().anyMatch(n -> gc.getPrivateAddress().equals(n.getPrivateIp()))).map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet());
try (SaltConnector sc = new SaltConnector(primaryGateway, restDebug)) {
if (!gatewayTargets.isEmpty()) {
uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel);
}
uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel);
// if there is a new salt master then re-bootstrap all nodes
Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes;
OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, nodes);
Callable<Boolean> saltBootstrapRunner = runner(saltBootstrap, exitCriteria, exitModel);
Future<Boolean> saltBootstrapRunnerFuture = parallelOrchestratorComponentRunner.submit(saltBootstrapRunner);
saltBootstrapRunnerFuture.get();
} catch (Exception e) {
LOGGER.error("Error occurred during salt upscale", e);
throw new CloudbreakOrchestratorFailedException(e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltOrchestrator method tearDown.
@Override
public void tearDown(List<GatewayConfig> allGatewayConfigs, Map<String, String> privateIPsByFQDN) throws CloudbreakOrchestratorException {
GatewayConfig primaryGateway = getPrimaryGatewayConfig(allGatewayConfigs);
try (SaltConnector saltConnector = new SaltConnector(primaryGateway, restDebug)) {
SaltStates.stopMinions(saltConnector, privateIPsByFQDN);
} catch (Exception e) {
LOGGER.error("Error occurred during salt minion tear down", e);
throw new CloudbreakOrchestratorFailedException(e);
}
List<GatewayConfig> liveGateways = allGatewayConfigs.stream().filter(gw -> !privateIPsByFQDN.values().contains(gw.getPrivateAddress())).collect(Collectors.toList());
for (GatewayConfig gatewayConfig : liveGateways) {
try (SaltConnector sc = new SaltConnector(gatewayConfig, restDebug)) {
sc.wheel("key.delete", privateIPsByFQDN.keySet(), Object.class);
} catch (Exception e) {
LOGGER.error("Error occurred during salt minion tear down", e);
throw new CloudbreakOrchestratorFailedException(e);
}
}
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltOrchestrator method executeRecipes.
@SuppressFBWarnings("REC_CATCH_EXCEPTION")
private void executeRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel, RecipeExecutionPhase phase) throws CloudbreakOrchestratorFailedException {
try (SaltConnector sc = new SaltConnector(gatewayConfig, restDebug)) {
// add 'recipe' grain to all nodes
Set<String> targets = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
runSaltCommand(sc, new GrainAddRunner(targets, allNodes, "recipes", phase.value(), CompoundType.IP), exitCriteriaModel);
// Add Deprecated 'PRE/POST' recipe execution for backward compatibility (since version 2.2.0)
boolean postRecipe = phase.isPostRecipe();
if (postRecipe) {
runSaltCommand(sc, new GrainAddRunner(targets, allNodes, "recipes", RecipeExecutionPhase.POST.value(), CompoundType.IP), exitCriteriaModel);
} else {
runSaltCommand(sc, new GrainAddRunner(targets, allNodes, "recipes", RecipeExecutionPhase.PRE.value(), CompoundType.IP), exitCriteriaModel);
}
Set<String> all = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
runSaltCommand(sc, new SyncGrainsRunner(all, allNodes), exitCriteriaModel);
runNewService(sc, new HighStateRunner(all, allNodes), exitCriteriaModel, maxRetryRecipe, false);
// remove 'recipe' grain from all nodes
targets = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
runSaltCommand(sc, new GrainRemoveRunner(targets, allNodes, "recipes", phase.value(), CompoundType.IP), exitCriteriaModel);
// Remove Deprecated 'PRE/POST' recipe execution for backward compatibility (since version 2.2.0)
if (postRecipe) {
runSaltCommand(sc, new GrainRemoveRunner(targets, allNodes, "recipes", RecipeExecutionPhase.POST.value(), CompoundType.IP), exitCriteriaModel);
} else {
runSaltCommand(sc, new GrainRemoveRunner(targets, allNodes, "recipes", RecipeExecutionPhase.PRE.value(), CompoundType.IP), exitCriteriaModel);
}
} catch (Exception e) {
LOGGER.error("Error occurred during recipe execution", e);
throw new CloudbreakOrchestratorFailedException(e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltOrchestrator method bootstrap.
@Override
public void bootstrap(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
LOGGER.info("Start SaltBootstrap on nodes: {}", targets);
GatewayConfig primaryGateway = getPrimaryGatewayConfig(allGatewayConfigs);
Set<String> gatewayTargets = getGatewayPrivateIps(allGatewayConfigs);
try (SaltConnector sc = new SaltConnector(primaryGateway, restDebug)) {
uploadSaltConfig(sc, gatewayTargets, exitModel);
uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel);
OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, targets);
Callable<Boolean> saltBootstrapRunner = runner(saltBootstrap, exitCriteria, exitModel);
Future<Boolean> saltBootstrapRunnerFuture = parallelOrchestratorComponentRunner.submit(saltBootstrapRunner);
saltBootstrapRunnerFuture.get();
} catch (Exception e) {
LOGGER.error("Error occurred during the salt bootstrap", e);
throw new CloudbreakOrchestratorFailedException(e);
}
LOGGER.info("SaltBootstrap finished");
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException in project cloudbreak by hortonworks.
the class SaltOrchestrator method uploadSignKey.
private void uploadSignKey(SaltConnector saltConnector, GatewayConfig gateway, Set<String> gatewayTargets, Set<String> targets, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorFailedException {
try {
String saltSignPrivateKey = gateway.getSaltSignPrivateKey();
if (!gatewayTargets.isEmpty() && saltSignPrivateKey != null) {
LOGGER.info("Upload master_sign.pem to gateways");
byte[] privateKeyContent = saltSignPrivateKey.getBytes();
uploadFileToGateways(saltConnector, gatewayTargets, exitCriteriaModel, "/etc/salt/pki/master", "master_sign.pem", privateKeyContent);
}
String saltSignPublicKey = gateway.getSaltSignPublicKey();
if (!targets.isEmpty() && saltSignPublicKey != null) {
byte[] publicKeyContent = saltSignPublicKey.getBytes();
LOGGER.info("Upload master_sign.pub to nodes: " + targets);
uploadFileToGateways(saltConnector, targets, exitCriteriaModel, "/etc/salt/pki/minion", "master_sign.pub", publicKeyContent);
}
} catch (SecurityException se) {
throw new CloudbreakOrchestratorFailedException("Failed to read salt sign key: " + se.getMessage());
}
}
Aggregations