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;
}
}
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);
}
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;
}
}
Aggregations