use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector 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.salt.client.SaltConnector in project cloudbreak by hortonworks.
the class SaltJobIdTrackerTest method callWithInProgressAndJobIsRunning.
@Test
public void callWithInProgressAndJobIsRunning() throws Exception {
String jobId = "1";
SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
SaltJobRunner saltJobRunner = Mockito.mock(BaseSaltJobRunner.class);
when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
when(saltJobRunner.getJobState()).thenCallRealMethod();
doCallRealMethod().when(saltJobRunner).setJobState(any());
when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
saltJobRunner.setJobState(JobState.IN_PROGRESS);
Set<String> targets = new HashSet<>();
targets.add("10.0.0.1");
targets.add("10.0.0.2");
targets.add("10.0.0.3");
when(saltJobRunner.getTarget()).thenReturn(targets);
PowerMockito.mockStatic(SaltStates.class);
PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(true);
SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
try {
saltJobIdTracker.call();
} catch (CloudbreakOrchestratorFailedException e) {
assertThat(e.getMessage(), both(containsString("jobId='" + jobId + '\'')).and(containsString("is running")));
}
PowerMockito.verifyStatic();
SaltStates.jobIsRunning(any(), eq(jobId));
checkTargets(targets, targetCaptor.getAllValues());
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.
the class SaltJobIdTrackerTest method callWithInProgressAndJobIsFinished.
@Test
public void callWithInProgressAndJobIsFinished() throws Exception {
String jobId = "1";
SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
SaltJobRunner saltJobRunner = Mockito.mock(BaseSaltJobRunner.class);
when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
when(saltJobRunner.getJobState()).thenCallRealMethod();
doCallRealMethod().when(saltJobRunner).setJobState(any());
when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
saltJobRunner.setJobState(JobState.IN_PROGRESS);
Set<String> targets = new HashSet<>();
targets.add("10.0.0.1");
targets.add("10.0.0.2");
targets.add("10.0.0.3");
when(saltJobRunner.getTarget()).thenReturn(targets);
PowerMockito.mockStatic(SaltStates.class);
PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(false);
Multimap<String, String> missingNodesWithReason = ArrayListMultimap.create();
PowerMockito.when(SaltStates.jidInfo(any(), any(), any(), any())).thenReturn(missingNodesWithReason);
SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
assertTrue(saltJobIdTracker.call());
assertEquals(JobState.FINISHED, saltJobRunner.getJobState());
PowerMockito.verifyStatic();
SaltStates.jobIsRunning(any(), eq(jobId));
checkTargets(targets, targetCaptor.getAllValues());
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.
the class SaltJobIdTrackerTest method callWithNotStarted.
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
@Test
public void callWithNotStarted() throws Exception {
String jobId = "1";
SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
SaltJobRunner saltJobRunner = Mockito.mock(SaltJobRunner.class);
PowerMockito.mockStatic(SaltStates.class);
PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(true);
Set<String> targets = new HashSet<>();
targets.add("10.0.0.1");
targets.add("10.0.0.2");
targets.add("10.0.0.3");
when(saltJobRunner.getTarget()).thenReturn(targets);
when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
when(saltJobRunner.getJobState()).thenReturn(JobState.NOT_STARTED, JobState.IN_PROGRESS);
when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
try {
saltJobIdTracker.call();
fail("should throw exception");
} catch (CloudbreakOrchestratorFailedException e) {
assertThat(e.getMessage(), both(containsString("jobId='" + jobId + '\'')).and(containsString("is running")));
}
PowerMockito.verifyStatic();
SaltStates.jobIsRunning(any(), eq(jobId));
checkTargets(targets, targetCaptor.getAllValues());
verify(saltJobRunner, times(2)).getJobState();
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.
the class SaltJobIdTrackerTest method callWithInProgressAndMissingNodes.
@Test
public void callWithInProgressAndMissingNodes() throws Exception {
String jobId = "1";
SaltConnector saltConnector = Mockito.mock(SaltConnector.class);
SaltJobRunner saltJobRunner = Mockito.mock(BaseSaltJobRunner.class);
when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
when(saltJobRunner.getJobState()).thenCallRealMethod();
doCallRealMethod().when(saltJobRunner).setJobState(any());
when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
saltJobRunner.setJobState(JobState.IN_PROGRESS);
Set<String> targets = new HashSet<>();
targets.add("10.0.0.1");
targets.add("10.0.0.2");
targets.add("10.0.0.3");
when(saltJobRunner.getTarget()).thenReturn(targets);
PowerMockito.mockStatic(SaltStates.class);
PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(false);
Multimap<String, String> missingNodesWithReason = ArrayListMultimap.create();
String missingMachine = "10.0.0.1";
String errorMessage = "error happened";
missingNodesWithReason.put(missingMachine, errorMessage);
when(saltJobRunner.getNodesWithError()).thenReturn(missingNodesWithReason);
SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
try {
saltJobIdTracker.call();
fail("should throw exception");
} catch (CloudbreakOrchestratorFailedException e) {
assertThat(e.getMessage(), both(containsString(missingMachine)).and(containsString(errorMessage)));
}
PowerMockito.verifyStatic();
SaltStates.jobIsRunning(any(), eq(jobId));
checkTargets(targets, targetCaptor.getAllValues());
}
Aggregations