use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction in project cloudbreak by hortonworks.
the class SaltStatesTest method stopMinionsTest.
@Test
public void stopMinionsTest() {
Map<String, String> privateIpsByFQDN = new HashMap<>();
privateIpsByFQDN.put("10-0-0-1.example.com", "10.0.0.1");
privateIpsByFQDN.put("10-0-0-2.example.com", "10.0.0.2");
privateIpsByFQDN.put("10-0-0-3.example.com", "10.0.0.3");
SaltStates.stopMinions(saltConnector, privateIpsByFQDN);
ArgumentCaptor<SaltAction> saltActionArgumentCaptor = ArgumentCaptor.forClass(SaltAction.class);
verify(saltConnector, times(1)).action(saltActionArgumentCaptor.capture());
SaltAction saltAction = saltActionArgumentCaptor.getValue();
assertEquals(SaltActionType.STOP, saltAction.getAction());
assertThat(saltAction.getMinions(), hasSize(3));
Set<String> minionAddresses = saltAction.getMinions().stream().map(Minion::getAddress).collect(Collectors.toSet());
assertThat(minionAddresses, containsInAnyOrder("10.0.0.1", "10.0.0.2", "10.0.0.3"));
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction in project cloudbreak by hortonworks.
the class SaltBootstrap method createBootstrap.
private SaltAction createBootstrap() {
SaltAction saltAction = new SaltAction(SaltActionType.RUN);
SaltAuth auth = new SaltAuth();
auth.setPassword(sc.getSaltPassword());
List<String> targetIps = targets.stream().map(Node::getPrivateIp).collect(Collectors.toList());
for (GatewayConfig gatewayConfig : allGatewayConfigs) {
String gatewayAddress = gatewayConfig.getPrivateAddress();
if (targetIps.contains(gatewayAddress)) {
Node saltMaster = targets.stream().filter(n -> n.getPrivateIp().equals(gatewayAddress)).findFirst().get();
SaltMaster master = new SaltMaster();
master.setAddress(gatewayAddress);
master.setAuth(auth);
master.setDomain(saltMaster.getDomain());
master.setHostName(saltMaster.getHostname());
// set due to compatibility reasons
saltAction.setServer(gatewayAddress);
saltAction.setMaster(master);
saltAction.addMinion(createMinion(saltMaster));
saltAction.addMaster(master);
}
}
for (Node minion : targets.stream().filter(node -> !getGatewayPrivateIps().contains(node.getPrivateIp())).collect(Collectors.toList())) {
saltAction.addMinion(createMinion(minion));
}
return saltAction;
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction in project cloudbreak by hortonworks.
the class SaltBootstrap method call.
@Override
public Boolean call() throws Exception {
LOGGER.info("Bootstrapping of nodes [{}/{}]", originalTargets.size() - targets.size(), originalTargets.size());
if (!targets.isEmpty()) {
LOGGER.info("Missing targets for SaltBootstrap: {}", targets);
SaltAction saltAction = createBootstrap();
GenericResponses responses = sc.action(saltAction);
Set<Node> failedTargets = new HashSet<>();
LOGGER.info("SaltBootstrap responses: {}", responses);
for (GenericResponse genericResponse : responses.getResponses()) {
if (genericResponse.getStatusCode() != HttpStatus.OK.value()) {
LOGGER.info("Failed to distributed salt run to: " + genericResponse.getAddress());
String address = genericResponse.getAddress().split(":")[0];
failedTargets.addAll(originalTargets.stream().filter(a -> a.getPrivateIp().equals(address)).collect(Collectors.toList()));
}
}
targets = failedTargets;
if (!targets.isEmpty()) {
LOGGER.info("Missing nodes to run saltbootstrap: {}", targets);
throw new CloudbreakOrchestratorFailedException("There are missing nodes from saltbootstrap: " + targets);
}
}
String iFace = SaltStates.defaultRoute(sc, Glob.ALL).getGatewayInterfaceName();
Map<String, String> networkResult = SaltStates.networkInterfaceIP(sc, Glob.ALL, iFace).getResultGroupByIP();
originalTargets.forEach(node -> {
if (!networkResult.containsKey(node.getPrivateIp())) {
LOGGER.info("Salt-minion is not responding on host: {}, yet", node);
targets.add(node);
}
});
if (!targets.isEmpty()) {
throw new CloudbreakOrchestratorFailedException("There are missing nodes from salt network response: " + targets);
}
LOGGER.info("Bootstrapping of nodes completed: {}", originalTargets.size());
return true;
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction in project cloudbreak by hortonworks.
the class SaltStates method stopMinions.
public static void stopMinions(SaltConnector sc, Map<String, String> privateIPsByFQDN) {
SaltAction saltAction = new SaltAction(SaltActionType.STOP);
for (Entry<String, String> entry : privateIPsByFQDN.entrySet()) {
Minion minion = new Minion();
minion.setAddress(entry.getValue());
saltAction.addMinion(minion);
}
sc.action(saltAction);
}
Aggregations