Search in sources :

Example 6 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class BaseSaltJobRunnerTest method collectNodesTest.

@Test
public void collectNodesTest() {
    Set<Node> allNode = allNodeWithPostFix();
    baseSaltJobRunner = new BaseSaltJobRunner(targets, allNode) {

        @Override
        public String submit(SaltConnector saltConnector) {
            return "";
        }
    };
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> resultList = new ArrayList<>();
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("host-10-0-0-1.example.com", "10.0.0.1");
    resultMap.put("host-10-0-0-2.example.com", "10.0.0.2");
    resultMap.put("host-10-0-0-3.example.com", "10.0.0.3");
    resultList.add(resultMap);
    applyResponse.setResult(resultList);
    Set<String> collectedNodes = baseSaltJobRunner.collectNodes(applyResponse);
    Assert.assertEquals(3, collectedNodes.size());
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-1.example.com"));
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-2.example.com"));
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-3.example.com"));
}
Also used : HashMap(java.util.HashMap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Map(java.util.Map) HashMap(java.util.HashMap) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse) Test(org.junit.Test)

Example 7 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class PillarSaveTest method testDiscovery.

@Test
public void testDiscovery() throws Exception {
    SaltConnector saltConnector = mock(SaltConnector.class);
    GenericResponses responses = new GenericResponses();
    GenericResponse response = new GenericResponse();
    response.setStatusCode(HttpStatus.OK.value());
    response.setAddress("10.0.0.2");
    responses.setResponses(Collections.singletonList(response));
    when(saltConnector.pillar(any(), any(Pillar.class))).thenReturn(responses);
    Set<Node> nodes = new HashSet<>();
    nodes.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
    nodes.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
    nodes.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
    PillarSave pillarSave = new PillarSave(saltConnector, Sets.newHashSet("10.0.0.1"), nodes);
    pillarSave.call();
    ArgumentCaptor<Pillar> pillarCaptor = ArgumentCaptor.forClass(Pillar.class);
    ArgumentCaptor<Set> targetCaptor = ArgumentCaptor.forClass(Set.class);
    verify(saltConnector).pillar(targetCaptor.capture(), pillarCaptor.capture());
    Pillar pillar = pillarCaptor.getValue();
    Map<String, Map<String, Map<String, Object>>> pillarJson = (Map<String, Map<String, Map<String, Object>>>) pillar.getJson();
    Map<String, Map<String, Object>> hostMap = pillarJson.entrySet().iterator().next().getValue();
    for (Node node : nodes) {
        Assert.assertEquals(node.getHostname(), hostMap.get(node.getPrivateIp()).get("fqdn"));
        Assert.assertEquals(node.getHostname().split("\\.")[0], hostMap.get(node.getPrivateIp()).get("hostname"));
        Assert.assertEquals(Boolean.TRUE, hostMap.get(node.getPrivateIp()).get("public_address"));
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class SaltBootstrapTest method callFailTest.

@Test
public void callFailTest() {
    networkMap.clear();
    networkMap.put("host-10-0-0-1.example.com", "10.0.0.1");
    networkMap.put("host-10-0-0-2.example.com", "10.0.0.2");
    Set<Node> targets = new HashSet<>();
    targets.add(new Node("10.0.0.1", null, null, "hg"));
    targets.add(new Node("10.0.0.2", null, null, "hg"));
    String missingNodeIp = "10.0.0.3";
    targets.add(new Node(missingNodeIp, null, null, "hg"));
    SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, Collections.singletonList(gatewayConfig), targets);
    try {
        saltBootstrap.call();
        fail("should throw exception");
    } catch (Exception e) {
        assertTrue(CloudbreakOrchestratorFailedException.class.getSimpleName().equals(e.getClass().getSimpleName()));
        assertThat(e.getMessage(), containsString("10.0.0.3"));
        assertThat(e.getMessage(), not(containsString("10.0.0.2")));
        assertThat(e.getMessage(), not(containsString("10.0.0.1")));
    }
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class SaltBootstrapTest method callTest.

@Test
public void callTest() {
    Set<Node> targets = new HashSet<>();
    targets.add(new Node("10.0.0.1", null, null, "hg"));
    targets.add(new Node("10.0.0.2", null, null, "hg"));
    targets.add(new Node("10.0.0.3", null, null, "hg"));
    SaltBootstrap saltBootstrap = new SaltBootstrap(saltConnector, Collections.singletonList(gatewayConfig), targets);
    try {
        saltBootstrap.call();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Node

use of com.sequenceiq.cloudbreak.orchestrator.model.Node in project cloudbreak by hortonworks.

the class GrainAddRunnerTest method submitTest.

@Test
public void submitTest() {
    Set<String> targets = new HashSet<>();
    targets.add("10.0.0.1");
    targets.add("10.0.0.2");
    targets.add("10.0.0.3");
    Set<Node> allNode = new HashSet<>();
    allNode.add(new Node("10.0.0.1", "5.5.5.1", "10-0-0-1.example.com", "hg"));
    allNode.add(new Node("10.0.0.2", "5.5.5.2", "10-0-0-2.example.com", "hg"));
    allNode.add(new Node("10.0.0.3", "5.5.5.3", "10-0-0-3.example.com", "hg"));
    PowerMockito.mockStatic(SaltStates.class);
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> result = new ArrayList<>();
    Map<String, Object> nodes = new HashMap<>();
    nodes.put("10-0-0-1.example.com", "something");
    nodes.put("10-0-0-2.example.com", "something");
    result.add(nodes);
    applyResponse.setResult(result);
    PowerMockito.when(SaltStates.addGrain(any(), any(), anyString(), any())).thenReturn(applyResponse);
    GrainAddRunner addRoleChecker = new GrainAddRunner(targets, allNode, "ambari_server");
    SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
    String missingIps = addRoleChecker.submit(saltConnector);
    assertThat(addRoleChecker.getTarget(), hasItems("10.0.0.3"));
    assertEquals("[10.0.0.3]", missingIps);
}
Also used : HashMap(java.util.HashMap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)25 HashSet (java.util.HashSet)13 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)12 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)11 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)10 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)7 Map (java.util.Map)7 Set (java.util.Set)7 Test (org.junit.Test)7 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)6 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)5 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)5 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)5 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)5 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)5 SyncGrainsRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner)5