use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse in project cloudbreak by hortonworks.
the class SaltJobIdTrackerTest method callWithNotStartedWithAlreadyRunning.
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
@Test
public void callWithNotStartedWithAlreadyRunning() 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);
RunningJobsResponse jobsResponse = new RunningJobsResponse();
jobsResponse.setResult(List.of(Map.of("runningJob", Map.of())));
PowerMockito.when(SaltStates.getRunningJobs(saltConnector)).thenReturn(jobsResponse);
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.getTargetHostnames()).thenReturn(targets);
when(saltJobRunner.getJid()).thenReturn(JobId.jobId(jobId));
when(saltJobRunner.getJobState()).thenReturn(JobState.NOT_STARTED);
when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
try {
saltJobIdTracker.call();
fail("should throw exception");
} catch (CloudbreakOrchestratorInProgressException e) {
assertThat(e.getMessage(), allOf(containsString("There are running job(s) with id:"), containsString("runningJob")));
}
verify(saltJobRunner, times(1)).getJobState();
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse 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);
RunningJobsResponse jobsResponse = new RunningJobsResponse();
jobsResponse.setResult(List.of());
PowerMockito.when(SaltStates.getRunningJobs(saltConnector)).thenReturn(jobsResponse);
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.getTargetHostnames()).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 (CloudbreakOrchestratorInProgressException e) {
assertThat(e.getMessage(), allOf(containsString("Target:"), containsString("10.0.0.1"), containsString("10.0.0.2"), containsString("10.0.0.3")));
}
PowerMockito.verifyStatic(SaltStates.class);
SaltStates.jobIsRunning(any(), eq(jobId));
checkTargets(targets, targetCaptor.getAllValues());
verify(saltJobRunner, times(2)).getJobState();
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse in project cloudbreak by hortonworks.
the class SaltJobIdTrackerTest method callWithNotStartedAndSlsWithError.
@Test
public void callWithNotStartedAndSlsWithError() throws Exception {
String jobId = "1";
try (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.getNodesWithError()).thenCallRealMethod();
doCallRealMethod().when(saltJobRunner).setNodesWithError(any());
when(saltJobRunner.submit(any(SaltConnector.class))).thenReturn(jobId);
saltJobRunner.setJobState(JobState.NOT_STARTED);
Set<String> targets = Sets.newHashSet("10.0.0.1", "10.0.0.2", "10.0.0.3");
when(saltJobRunner.getTargetHostnames()).thenReturn(targets);
PowerMockito.mockStatic(SaltStates.class);
PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(false);
PowerMockito.when(SaltStates.jidInfo(any(SaltConnector.class), anyString(), any())).thenThrow(new RuntimeException("Salt execution went wrong: saltErrorDetails"));
RunningJobsResponse jobsResponse = new RunningJobsResponse();
jobsResponse.setResult(List.of());
PowerMockito.when(SaltStates.getRunningJobs(saltConnector)).thenReturn(jobsResponse);
try {
new SaltJobIdTracker(saltConnector, saltJobRunner).call();
fail("should throw exception");
} catch (CloudbreakOrchestratorFailedException e) {
assertThat(e.getMessage(), containsString("Salt execution went wrong: saltErrorDetails"));
assertThat(e.getMessage(), not(containsString("Exception")));
}
PowerMockito.verifyStatic(SaltStates.class);
SaltStates.jobIsRunning(any(), eq(jobId));
checkTargets(targets, targetCaptor.getAllValues());
}
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse in project cloudbreak by hortonworks.
the class SaltStates method jobIsRunning.
public static boolean jobIsRunning(SaltConnector sc, String jid) {
RunningJobsResponse runningInfo = sc.run("jobs.active", RUNNER, RunningJobsResponse.class);
LOGGER.info("Active salt jobs: {}", runningInfo);
for (Map<String, Map<String, Object>> results : runningInfo.getResult()) {
for (Entry<String, Map<String, Object>> stringMapEntry : results.entrySet()) {
if (stringMapEntry.getKey().equals(jid)) {
return true;
}
}
}
return false;
}
use of com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse in project cloudbreak by hortonworks.
the class SaltStatesTest method jobIsRunningTest.
@Test
public void jobIsRunningTest() throws CloudbreakOrchestratorFailedException {
String jid = "3";
RunningJobsResponse runningJobsResponse = new RunningJobsResponse();
List<Map<String, Map<String, Object>>> result = new ArrayList<>();
Map<String, Map<String, Object>> resultMap = new HashMap<>();
resultMap.put(jid, new HashMap<>());
result.add(resultMap);
runningJobsResponse.setResult(result);
when(saltConnector.run(eq("jobs.active"), any(), eq(RunningJobsResponse.class))).thenReturn(runningJobsResponse);
boolean running = SaltStates.jobIsRunning(saltConnector, jid);
assertTrue(running);
resultMap.clear();
running = SaltStates.jobIsRunning(saltConnector, jid);
assertFalse(running);
}
Aggregations