Search in sources :

Example 1 with SaltAction

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"));
}
Also used : HashMap(java.util.HashMap) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) Test(org.junit.Test)

Example 2 with SaltAction

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;
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) SaltAuth(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAuth) Set(java.util.Set) SaltMaster(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltMaster) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) HttpStatus(org.springframework.http.HttpStatus) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) List(java.util.List) Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) SaltStates(com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Map(java.util.Map) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) Glob(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Glob) Collections(java.util.Collections) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) SaltActionType(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltActionType) SaltAuth(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAuth) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) SaltMaster(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltMaster) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 3 with 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;
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) HashSet(java.util.HashSet)

Example 4 with SaltAction

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);
}
Also used : Minion(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction)

Aggregations

SaltAction (com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction)4 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 GenericResponse (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)2 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)2 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)2 Minion (com.sequenceiq.cloudbreak.orchestrator.salt.domain.Minion)2 HashSet (java.util.HashSet)2 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 SaltActionType (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltActionType)1 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)1 Glob (com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Glob)1 SaltAuth (com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAuth)1 SaltMaster (com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltMaster)1 SaltStates (com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1