Search in sources :

Example 1 with CloudbreakOrchestratorInProgressException

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();
}
Also used : CloudbreakOrchestratorInProgressException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RunningJobsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with CloudbreakOrchestratorInProgressException

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();
}
Also used : CloudbreakOrchestratorInProgressException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RunningJobsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with CloudbreakOrchestratorInProgressException

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());
}
Also used : CloudbreakOrchestratorInProgressException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with CloudbreakOrchestratorInProgressException

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);
}
Also used : CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CloudbreakOrchestratorInProgressException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorInProgressException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException) CloudbreakOrchestratorTerminateException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTerminateException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) CloudbreakOrchestratorTerminateException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTerminateException)

Example 5 with CloudbreakOrchestratorInProgressException

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());
    }
}
Also used : CloudbreakOrchestratorInProgressException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException) RunningJobsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse)

Aggregations

CloudbreakOrchestratorInProgressException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorInProgressException)5 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)3 RunningJobsResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.RunningJobsResponse)3 HashSet (java.util.HashSet)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)1 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)1 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)1 CloudbreakOrchestratorTerminateException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTerminateException)1 CloudbreakOrchestratorTimeoutException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException)1