Search in sources :

Example 1 with ExistingStackPatchApplyException

use of com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException in project cloudbreak by hortonworks.

the class ExistingStackPatcherJob method applyStackPatch.

private boolean applyStackPatch(ExistingStackPatchService existingStackPatchService, StackPatch stackPatch) throws JobExecutionException {
    Stack stack = stackPatch.getStack();
    StackPatchType stackPatchType = existingStackPatchService.getStackPatchType();
    if (!StackPatchStatus.FIXED.equals(stackPatch.getStatus())) {
        try {
            if (existingStackPatchService.isAffected(stack)) {
                LOGGER.debug("Stack {} needs patch for {}", stack.getResourceCrn(), stackPatchType);
                stackPatchService.updateStatusAndReportUsage(stackPatch, StackPatchStatus.AFFECTED);
                boolean success = existingStackPatchService.apply(stack);
                if (success) {
                    stackPatchService.updateStatusAndReportUsage(stackPatch, StackPatchStatus.FIXED);
                } else {
                    stackPatchService.updateStatus(stackPatch, StackPatchStatus.SKIPPED);
                }
                return success;
            } else {
                LOGGER.debug("Stack {} is not affected by {}", stack.getResourceCrn(), stackPatchType);
                stackPatchService.updateStatus(stackPatch, StackPatchStatus.NOT_AFFECTED);
                return true;
            }
        } catch (ExistingStackPatchApplyException e) {
            String message = String.format("Failed to patch stack %s for %s", stack.getResourceCrn(), stackPatchType);
            LOGGER.error(message, e);
            stackPatchService.updateStatusAndReportUsage(stackPatch, StackPatchStatus.FAILED, e.getMessage());
            throw new JobExecutionException(message, e);
        }
    } else {
        LOGGER.debug("Stack {} was already patched for {}", stack.getResourceCrn(), stackPatchType);
        return true;
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) ExistingStackPatchApplyException(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException) StackPatchType(com.sequenceiq.cloudbreak.domain.stack.StackPatchType) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with ExistingStackPatchApplyException

use of com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException in project cloudbreak by hortonworks.

the class ExistingStackPatcherJobTest method shouldNotUnscheduleWhenApplyFails.

@Test
void shouldNotUnscheduleWhenApplyFails() throws ExistingStackPatchApplyException {
    when(existingStackPatchService.isAffected(stack)).thenReturn(true);
    String errorMessage = "error message";
    doThrow(new ExistingStackPatchApplyException(errorMessage)).when(existingStackPatchService).apply(stack);
    Assertions.assertThatThrownBy(() -> underTest.executeTracedJob(context)).isInstanceOf(JobExecutionException.class).hasMessageStartingWith("Failed to patch stack");
    verify(jobService, never()).unschedule(any());
    verify(stackPatchService).updateStatusAndReportUsage(stackPatch, StackPatchStatus.AFFECTED);
    verify(stackPatchService).updateStatusAndReportUsage(stackPatch, StackPatchStatus.FAILED, errorMessage);
}
Also used : JobExecutionException(org.quartz.JobExecutionException) ExistingStackPatchApplyException(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with ExistingStackPatchApplyException

use of com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException in project cloudbreak by hortonworks.

the class ExistingStackPatcherJob method applyStackPatch.

private boolean applyStackPatch(ExistingStackPatchService existingStackPatchService, Stack stack) throws JobExecutionException {
    StackPatchType stackPatchType = existingStackPatchService.getStackPatchType();
    if (!existingStackPatchService.isStackAlreadyFixed(stack)) {
        try {
            if (existingStackPatchService.isAffected(stack)) {
                LOGGER.debug("Stack {} needs patch for {}", stack.getResourceCrn(), stackPatchType);
                stackPatchUsageReporterService.reportAffected(stack, stackPatchType);
                boolean success = existingStackPatchService.apply(stack);
                if (success) {
                    stackPatchUsageReporterService.reportSuccess(stack, stackPatchType);
                }
                return success;
            } else {
                LOGGER.debug("Stack {} is not affected by {}", stack.getResourceCrn(), stackPatchType);
                return true;
            }
        } catch (ExistingStackPatchApplyException e) {
            String message = String.format("Failed to patch stack %s for %s", stack.getResourceCrn(), stackPatchType);
            LOGGER.error(message, e);
            stackPatchUsageReporterService.reportFailure(stack, stackPatchType, e.getMessage());
            throw new JobExecutionException(message, e);
        }
    } else {
        LOGGER.debug("Stack {} was already patched for {}", stack.getResourceCrn(), stackPatchType);
        return true;
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) ExistingStackPatchApplyException(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException) StackPatchType(com.sequenceiq.cloudbreak.domain.stack.StackPatchType)

Aggregations

ExistingStackPatchApplyException (com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException)3 JobExecutionException (org.quartz.JobExecutionException)3 StackPatchType (com.sequenceiq.cloudbreak.domain.stack.StackPatchType)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1