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"));
}
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"));
}
}
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")));
}
}
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);
}
}
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);
}
Aggregations