use of com.sequenceiq.cloudbreak.domain.stack.StackPatchType 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.domain.stack.StackPatchType 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.domain.stack.StackPatchType in project cloudbreak by hortonworks.
the class ExistingStackPatcherServiceProviderTest method shouldFailWithTypeWithoutService.
@Test
void shouldFailWithTypeWithoutService() {
StackPatchType stackPatchType = StackPatchType.LOGGING_AGENT_AUTO_RESTART;
assertThatThrownBy(() -> underTest.provide(stackPatchType)).isInstanceOf(UnknownStackPatchTypeException.class).hasMessage("No stack patcher implementation found for type " + stackPatchType);
}
use of com.sequenceiq.cloudbreak.domain.stack.StackPatchType in project cloudbreak by hortonworks.
the class ExistingStackPatcherJobInitializer method initJobs.
@Override
public void initJobs() {
Set<StackPatchType> enabledStackPatchTypes = getEnabledStackPatchTypes();
LOGGER.info("Existing stack patch types enabled: {}", enabledStackPatchTypes);
List<JobResource> stacks = getAliveJobResources();
Set<Long> stackIds = stacks.stream().map(JobResource::getLocalId).map(Long::valueOf).collect(Collectors.toSet());
enabledStackPatchTypes.forEach(stackPatchType -> {
LOGGER.info("Scheduling stack patcher jobs for {}", stackPatchType);
Map<Long, List<StackPatch>> stackPatchesByStack = stackPatchService.findAllByTypeForStackIds(stackPatchType, stackIds).stream().collect(Collectors.groupingBy(StackPatch::getStackId));
for (JobResource stack : stacks) {
Long stackId = Long.valueOf(stack.getLocalId());
List<StackPatch> stackPatches = stackPatchesByStack.get(stackId);
boolean stackPatchIsFinalized = stackPatches != null && stackPatches.stream().anyMatch(stackPatch -> stackPatch.getStatus().isFinal());
if (!stackPatchIsFinalized) {
ExistingStackPatcherJobAdapter jobAdapter = new ExistingStackPatcherJobAdapter(stack, stackPatchType);
stackPatchService.getOrCreate(stackId, stackPatchType);
jobService.schedule(jobAdapter);
}
}
});
}
use of com.sequenceiq.cloudbreak.domain.stack.StackPatchType 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