Search in sources :

Example 6 with StackPatchType

use of com.sequenceiq.cloudbreak.domain.stack.StackPatchType 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

StackPatchType (com.sequenceiq.cloudbreak.domain.stack.StackPatchType)6 ExistingStackPatchApplyException (com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException)3 JobExecutionException (org.quartz.JobExecutionException)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 StackPatch (com.sequenceiq.cloudbreak.domain.stack.StackPatch)2 ExistingStackPatchService (com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchService)2 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 StackPatchStatus (com.sequenceiq.cloudbreak.domain.stack.StackPatchStatus)1 AbstractStackJobInitializer (com.sequenceiq.cloudbreak.job.AbstractStackJobInitializer)1 ExistingStackPatcherConfig (com.sequenceiq.cloudbreak.job.stackpatcher.config.ExistingStackPatcherConfig)1 JobResource (com.sequenceiq.cloudbreak.quartz.model.JobResource)1 StackPatchService (com.sequenceiq.cloudbreak.service.stackpatch.StackPatchService)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Test (org.junit.jupiter.api.Test)1 JobDetail (org.quartz.JobDetail)1 JobKey (org.quartz.JobKey)1