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