Search in sources :

Example 1 with ExistingStackPatchService

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

the class ExistingStackPatcherJob method executeTracedJob.

@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
    Stack stack = stackService.getByIdWithListsInTransaction(getStackId());
    Status stackStatus = stack.getStatus();
    String stackPatchTypeName = context.getJobDetail().getJobDataMap().getString(STACK_PATCH_TYPE_NAME);
    try {
        ExistingStackPatchService existingStackPatchService = existingStackPatcherServiceProvider.provide(stackPatchTypeName);
        StackPatchType stackPatchType = existingStackPatchService.getStackPatchType();
        StackPatch stackPatch = stackPatchService.getOrCreate(stack, stackPatchType);
        if (!Status.getUnschedulableStatuses().contains(stackStatus)) {
            boolean success = applyStackPatch(existingStackPatchService, stackPatch);
            if (success) {
                unscheduleJob(context, stackPatch);
            }
        } else {
            LOGGER.debug("Existing stack patching will be unscheduled, because stack {} status is {}", stack.getResourceCrn(), stackStatus);
            stackPatchService.updateStatus(stackPatch, StackPatchStatus.UNSCHEDULED);
            unscheduleJob(context, stackPatch);
        }
    } catch (UnknownStackPatchTypeException e) {
        String message = "Unknown stack patch type: " + stackPatchTypeName;
        unscheduleAndFailJob(message, context, new StackPatch(stack, StackPatchType.UNKNOWN));
    } catch (Exception e) {
        LOGGER.error("Failed", e);
        throw e;
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) StackPatchStatus(com.sequenceiq.cloudbreak.domain.stack.StackPatchStatus) ExistingStackPatchService(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchService) StackPatch(com.sequenceiq.cloudbreak.domain.stack.StackPatch) StackPatchType(com.sequenceiq.cloudbreak.domain.stack.StackPatchType) ExistingStackPatchApplyException(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException) JobExecutionException(org.quartz.JobExecutionException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with ExistingStackPatchService

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

the class ExistingStackPatcherServiceProviderTest method shouldReturnServiceWithValidName.

@Test
void shouldReturnServiceWithValidName() throws UnknownStackPatchTypeException {
    String stackPatchTypeName = STACK_PATCH_TYPE.name();
    ExistingStackPatchService stackPatchService = underTest.provide(stackPatchTypeName);
    assertThat(stackPatchService).isEqualTo(this.existingStackPatchService);
}
Also used : ExistingStackPatchService(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchService) Test(org.junit.jupiter.api.Test)

Example 3 with ExistingStackPatchService

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

the class ExistingStackPatcherServiceProviderTest method shouldReturnServiceWithValidType.

@Test
void shouldReturnServiceWithValidType() throws UnknownStackPatchTypeException {
    ExistingStackPatchService stackPatchService = underTest.provide(STACK_PATCH_TYPE);
    assertThat(stackPatchService).isEqualTo(this.existingStackPatchService);
}
Also used : ExistingStackPatchService(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchService) Test(org.junit.jupiter.api.Test)

Example 4 with ExistingStackPatchService

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

the class ExistingStackPatcherJobService method schedule.

public void schedule(ExistingStackPatcherJobAdapter resource) {
    JobDetail jobDetail = buildJobDetail(resource);
    JobKey jobKey = jobDetail.getKey();
    StackPatchType stackPatchType = resource.getStackPatchType();
    try {
        ExistingStackPatchService existingStackPatchService = existingStackPatcherServiceProvider.provide(stackPatchType);
        Trigger trigger = buildJobTrigger(jobDetail, existingStackPatchService);
        if (scheduler.getJobDetail(jobKey) != null) {
            LOGGER.info("Unscheduling stack patcher job for stack with key: '{}' and group: '{}'", jobKey.getName(), jobKey.getGroup());
            unschedule(jobKey);
        }
        LOGGER.info("Scheduling stack patcher {} job for stack with key: '{}' and group: '{}'", stackPatchType, jobKey.getName(), jobKey.getGroup());
        scheduler.scheduleJob(jobDetail, trigger);
    } catch (UnknownStackPatchTypeException e) {
        LOGGER.error("Failed to get stack patcher for type {}", stackPatchType, e);
    } catch (SchedulerException e) {
        LOGGER.error("Error during scheduling stack patcher job: {}", jobDetail, e);
    }
}
Also used : ExistingStackPatchService(com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchService) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) StackPatchType(com.sequenceiq.cloudbreak.domain.stack.StackPatchType)

Aggregations

ExistingStackPatchService (com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchService)4 StackPatchType (com.sequenceiq.cloudbreak.domain.stack.StackPatchType)2 Test (org.junit.jupiter.api.Test)2 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 StackPatch (com.sequenceiq.cloudbreak.domain.stack.StackPatch)1 StackPatchStatus (com.sequenceiq.cloudbreak.domain.stack.StackPatchStatus)1 ExistingStackPatchApplyException (com.sequenceiq.cloudbreak.service.stackpatch.ExistingStackPatchApplyException)1 JobDetail (org.quartz.JobDetail)1 JobExecutionException (org.quartz.JobExecutionException)1 JobKey (org.quartz.JobKey)1 SchedulerException (org.quartz.SchedulerException)1 Trigger (org.quartz.Trigger)1