Search in sources :

Example 11 with JobExecutionContext

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));
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) Consumer(org.candlepin.model.Consumer) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) HypervisorId(org.candlepin.model.HypervisorId) JobExecutionContext(org.quartz.JobExecutionContext) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 12 with JobExecutionContext

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);
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) JobExecutionContext(org.quartz.JobExecutionContext) Test(org.junit.Test)

Example 13 with JobExecutionContext

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);
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) JobExecutionContext(org.quartz.JobExecutionContext) EvaluatorContext(com.sequenceiq.periscope.monitor.evaluator.EvaluatorContext) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) LoggerFactory(org.slf4j.LoggerFactory) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) Set(java.util.Set) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ApplicationContext(org.springframework.context.ApplicationContext) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator) Status(com.sequenceiq.cloudbreak.api.model.Status) List(java.util.List) Component(org.springframework.stereotype.Component) JobDataMap(org.quartz.JobDataMap) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) ExecutorService(java.util.concurrent.ExecutorService) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ClusterCreationEvaluatorContext(com.sequenceiq.periscope.model.ClusterCreationEvaluatorContext) Cluster(com.sequenceiq.periscope.domain.Cluster) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) ClusterCreationEvaluator(com.sequenceiq.periscope.monitor.evaluator.ClusterCreationEvaluator)

Example 14 with JobExecutionContext

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);
    }
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) JobExecutionContext(org.quartz.JobExecutionContext)

Example 15 with JobExecutionContext

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";
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) JobExecutionContext(org.quartz.JobExecutionContext)

Aggregations

JobExecutionContext (org.quartz.JobExecutionContext)47 Test (org.junit.Test)20 JobDetail (org.quartz.JobDetail)20 JobDataMap (org.quartz.JobDataMap)13 Set (java.util.Set)10 JobExecutionException (org.quartz.JobExecutionException)10 List (java.util.List)8 SchedulerException (org.quartz.SchedulerException)8 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)7 Job (org.quartz.Job)6 ArrayList (java.util.ArrayList)5 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)5 Consumer (org.candlepin.model.Consumer)4 InterruptableJob (org.quartz.InterruptableJob)4 Scheduler (org.quartz.Scheduler)4 Date (java.util.Date)3 Map (java.util.Map)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2