use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class HypervisorUpdateJobTest method hypervisorUpdateExecUpdate.
@Test
public void hypervisorUpdateExecUpdate() throws JobExecutionException {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
Consumer hypervisor = new Consumer();
String hypervisorId = "uuid_999";
hypervisor.setHypervisorId(new HypervisorId(hypervisorId));
VirtConsumerMap vcm = new VirtConsumerMap();
vcm.add(hypervisorId, hypervisor);
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(vcm);
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
verify(consumerResource).checkForFactsUpdate(any(Consumer.class), any(Consumer.class));
verify(consumerCurator).update(any(Consumer.class), eq(false));
}
use of org.quartz.JobExecutionContext in project candlepin by candlepin.
the class HypervisorUpdateJobTest method hypervisorUpdateIgnoresEmptyGuestIds.
@Test
public void hypervisorUpdateIgnoresEmptyGuestIds() throws Exception {
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
hypervisorJson = "{\"hypervisors\":" + "[{" + "\"hypervisorId\" : {\"hypervisorId\" : \"hypervisor_999\"}," + "\"name\" : \"hypervisor_999\"," + "\"guestIds\" : [{\"guestId\" : \"guestId_1_999\"}, {\"guestId\" : \"\"}]" + "}]}";
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
job.execute(ctx);
}
use of org.quartz.JobExecutionContext in project cloudbreak by hortonworks.
the class ClusterMonitor method execute.
@Override
public void execute(JobExecutionContext context) {
evalContext(context);
try {
CloudbreakClient cloudbreakClient = applicationContext.getBean(CloudbreakClientConfiguration.class).cloudbreakClient();
ClusterService clusterService = applicationContext.getBean(ClusterService.class);
List<Cluster> clusters = clusterService.findAll();
Set<AutoscaleStackResponse> allStacks = cloudbreakClient.stackV1Endpoint().getAllForAutoscale();
for (AutoscaleStackResponse stack : allStacks) {
Status clusterStatus = stack.getClusterStatus();
if (clusterStatus != null && AVAILABLE.equals(clusterStatus)) {
String ambariIp = stack.getAmbariServerIp();
Optional<Cluster> clusterOptional = clusters.stream().filter(c -> c.getStackId() != null && c.getStackId().equals(stack.getStackId())).findFirst();
if (ambariIp != null) {
ClusterCreationEvaluator clusterCreationEvaluator = applicationContext.getBean(ClusterCreationEvaluator.class);
clusterCreationEvaluator.setContext(new ClusterCreationEvaluatorContext(stack, clusterOptional));
executorService.submit(clusterCreationEvaluator);
} else {
LOGGER.info("Could not find Ambari for stack: {}(ID:{})", stack.getName(), stack.getStackId());
}
} else {
LOGGER.info("Do not create or update cluster while the Cloudbreak cluster {}(ID:{}) is in '{}' state instead of 'AVAILABLE'!", stack.getName(), stack.getStackId(), stack.getClusterStatus());
}
}
} catch (Exception ex) {
LOGGER.error("New clusters could not be synchronized from Cloudbreak.", ex);
}
}
use of org.quartz.JobExecutionContext in project deltaspike by apache.
the class AbstractQuartzScheduler method isExecutingJob.
@Override
public boolean isExecutingJob(Class<? extends T> jobClass) {
try {
JobKey jobKey = createJobKey(jobClass);
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
return false;
}
for (JobExecutionContext jobExecutionContext : this.scheduler.getCurrentlyExecutingJobs()) {
if (jobKey.equals(jobExecutionContext.getJobDetail().getKey())) {
return true;
}
}
return false;
} catch (SchedulerException e) {
throw ExceptionUtils.throwAsRuntimeException(e);
}
}
use of org.quartz.JobExecutionContext in project openolat by klemens.
the class NotificationsAdminWebService method getJobStatus.
private String getJobStatus() {
try {
Scheduler scheduler = CoreSpringFactory.getImpl(Scheduler.class);
List<JobExecutionContext> jobs = scheduler.getCurrentlyExecutingJobs();
for (JobExecutionContext job : jobs) {
if ("org.olat.notifications.job.enabled".equals(job.getJobDetail().getKey().getName())) {
return "running";
}
}
return "stopped";
} catch (SchedulerException e) {
log.error("", e);
return "error";
}
}
Aggregations