use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException 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.exception.CloudbreakOrchestratorInProgressException 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.exception.CloudbreakOrchestratorInProgressException 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.getTargetHostnames()).thenReturn(targets);
PowerMockito.mockStatic(SaltStates.class);
PowerMockito.when(SaltStates.jobIsRunning(any(), any())).thenReturn(true);
SaltJobIdTracker saltJobIdTracker = new SaltJobIdTracker(saltConnector, saltJobRunner);
try {
saltJobIdTracker.call();
} 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());
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException in project cloudbreak by hortonworks.
the class OrchestratorBootstrapRunner method doCall.
private Boolean doCall() throws CloudbreakOrchestratorCancelledException, CloudbreakOrchestratorFailedException, CloudbreakOrchestratorTimeoutException {
Boolean success = null;
int retryCount = 1;
int errorCount = 1;
Exception actualException = null;
String type = orchestratorBootstrap.getClass().getSimpleName().replace("Bootstrap", "");
long initialStartTime = System.currentTimeMillis();
while (success == null && belowAttemptThreshold(retryCount, errorCount)) {
if (isExitNeeded()) {
LOGGER.debug(exitCriteria.exitMessage());
throw new CloudbreakOrchestratorCancelledException(exitCriteria.exitMessage());
}
long startTime = System.currentTimeMillis();
try {
LOGGER.debug("Calling orchestrator bootstrap: {}, additional info: {}", type, orchestratorBootstrap);
orchestratorBootstrap.call();
success = Boolean.TRUE;
String elapsedTimeLog = createElapseTimeLog(initialStartTime, startTime);
LOGGER.debug("Orchestrator component {} successfully started! {}, " + "additional info: {}", type, elapsedTimeLog, orchestratorBootstrap);
} catch (CloudbreakOrchestratorTerminateException te) {
actualException = te;
success = Boolean.FALSE;
String elapsedTimeLog = createElapseTimeLog(initialStartTime, startTime);
LOGGER.info("Failed to execute orchestrator component {}! {}, " + "additional info: {}", type, elapsedTimeLog, orchestratorBootstrap);
} catch (CloudbreakOrchestratorInProgressException ex) {
actualException = ex;
String elapsedTimeLog = createElapseTimeLog(initialStartTime, startTime);
LOGGER.debug("Orchestrator component {} start in progress, retrying [{}/{}] {}, Reason: {}, additional info: {}", type, retryCount, maxRetryCount, elapsedTimeLog, actualException, orchestratorBootstrap);
retryCount++;
if (retryCount <= maxRetryCount) {
trySleeping();
} else {
success = Boolean.FALSE;
}
} catch (Exception ex) {
actualException = ex;
String elapsedTimeLog = createElapseTimeLog(initialStartTime, startTime);
LOGGER.debug("Orchestrator component {} failed to start, retrying [{}/{}], error count [{}/{}]. {}, Reason: {}, additional info: {}", type, retryCount, maxRetryCount, errorCount, maxRetryOnError, elapsedTimeLog, actualException, orchestratorBootstrap, actualException);
retryCount++;
errorCount++;
if (belowAttemptThreshold(retryCount, errorCount)) {
trySleeping();
} else {
success = Boolean.FALSE;
}
}
}
return checkResult(success, retryCount, actualException);
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException in project cloudbreak by hortonworks.
the class SaltJobIdTracker method checkIsOtherJobRunning.
private void checkIsOtherJobRunning() throws CloudbreakOrchestratorFailedException, CloudbreakOrchestratorInProgressException {
RunningJobsResponse runningJobs = SaltStates.getRunningJobs(saltConnector);
List<String> runningJobIds = mapToRunningJobIds(runningJobs);
if (!runningJobIds.isEmpty()) {
LOGGER.warn("There are running job(s) with id: {}. Postpone starting the new job until these are finished.", runningJobIds);
throw new CloudbreakOrchestratorInProgressException("There are running job(s) with id: " + runningJobIds, saltJobRunner.getNodesWithError());
}
}
Aggregations