Package org.rhq.core.domain.operation.bean

Examples of org.rhq.core.domain.operation.bean.ResourceOperationSchedule


        }
    }

    private ResourceOperationSchedule createScheduleForResource(GroupOperationSchedule schedule, String jobGroup,
        Subject user, Resource resource) throws Exception {
        ResourceOperationSchedule resourceSchedule;

        // We need to provide a unique job name for the group member.
        // The job name will be unique but it will have a job group name of the group job.
        // NOTE! This job-name/job-group combination will NOT have a Quartz scheduled job in the Quartz tables.
        // This is an invocation that JON spawns when Quartz triggers the group job.  Quartz does not trigger
        // these group member resource jobs.
        String resourceJobName = ResourceOperationJob.createUniqueJobName(resource, schedule.getOperationName());

        resourceSchedule = new ResourceOperationSchedule();
        resourceSchedule.setJobName(resourceJobName);
        resourceSchedule.setJobGroup(jobGroup);
        resourceSchedule.setDescription(schedule.getDescription());
        resourceSchedule.setOperationName(schedule.getOperationName());
        resourceSchedule.setParameters(schedule.getParameters());
        resourceSchedule.setSubject(user);
        resourceSchedule.setResource(resource);

        return resourceSchedule;
    }
View Full Code Here


    @Override
    public int scheduleResourceOperation(Subject subject, ResourceOperationSchedule schedule) throws ScheduleException {
        JobTrigger jobTrigger = schedule.getJobTrigger();
        Trigger trigger = convertToTrigger(jobTrigger);
        try {
            ResourceOperationSchedule resourceOperationSchedule = scheduleResourceOperation(subject, schedule
                .getResource().getId(), schedule.getOperationName(), schedule.getParameters(), trigger,
                schedule.getDescription());
            return resourceOperationSchedule.getId();
        } catch (SchedulerException e) {
            throw new ScheduleException(e);
        }
    }
View Full Code Here

        updateOperationHistory(subject, history);

        // Now actually schedule it.
        Date next = scheduler.scheduleJob(jobDetail, trigger);
        ResourceOperationSchedule newSchedule = getResourceOperationSchedule(subject, jobDetail);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Scheduled Resource operation [" + newSchedule + "] - next fire time is [" + next + "]");
        }
View Full Code Here

            Resource resource = getResourceIfAuthorized(subject, resourceId);

            ensureControlPermission(subject, resource);

            // while unscheduling, be aware that the job could complete at any time
            ResourceOperationSchedule schedule;
            try {
                schedule = getResourceOperationSchedule(subject, jobId);
            } catch (SchedulerException e) {
                // The schedule must have completed, so ignore the request to unschedule it.
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Assuming job [" + jobId
                        + "] has completed, ignoring request to unschedule resource operation for resource ["
                        + resourceId + "]");
                }
                return;
            }

            if (schedule.getParameters() != null) {
                Integer configId = schedule.getParameters().getId();
                Configuration parameters = configurationManager.getConfigurationById(configId);
                if (null != parameters) {
                    entityManager.remove(parameters);
                }
            }
View Full Code Here

        String groupName = createJobGroupName(resource);
        String[] jobNames = scheduler.getJobNames(groupName);

        for (String jobName : jobNames) {
            JobDetail jobDetail = scheduler.getJobDetail(jobName, groupName);
            ResourceOperationSchedule sched = getResourceOperationSchedule(subject, jobDetail);

            if (sched != null) {
                if (resourceId != sched.getResource().getId()) {
                    throw new IllegalStateException("Somehow a different resource [" + sched.getResource()
                        + "] was scheduled in the same job group as resource [" + resource + "]");
                }

                operationSchedules.add(sched);
            }
View Full Code Here

    @Override
    public ResourceOperationSchedule getResourceOperationSchedule(Subject whoami, int scheduleId) {
        OperationScheduleEntity operationScheduleEntity = entityManager.find(OperationScheduleEntity.class, scheduleId);
        try {
            ResourceOperationSchedule resourceOperationSchedule = getResourceOperationSchedule(whoami,
                operationScheduleEntity.getJobId().toString());
            return resourceOperationSchedule;
        } catch (SchedulerException e) {
            throw new RuntimeException("Failed to retrieve ResourceOperationSchedule with id [" + scheduleId + "].", e);
        }
View Full Code Here

        // this is by design to avoid a malicious user creating a dummy subject in the database,
        // scheduling a very bad operation, and deleting that subject thus removing all traces
        // of the user.  If the user has been removed from the system, all of that users schedules
        // will need to be deleted and rescheduled.

        ResourceOperationSchedule sched = new ResourceOperationSchedule();
        sched.setId(entityId);
        sched.setJobName(jobName);
        sched.setJobGroup(jobGroup);
        sched.setResource(resource);
        sched.setOperationName(operationName);
        sched.setOperationDisplayName(displayName);
        Subject subject = subjectManager.getSubjectById(subjectId);
        sched.setSubject(subject);
        sched.setParameters(parameters);
        sched.setDescription(description);

        Trigger trigger = getTriggerOfJob(jobDetail);
        if (trigger == null) {
            // The job must have run for the last time - return null to inform the user the job is defunct.
            return null;
        }

        JobTrigger jobTrigger = convertToJobTrigger(trigger);
        sched.setJobTrigger(jobTrigger);
        sched.setNextFireTime(trigger.getNextFireTime());

        return sched;
    }
View Full Code Here

    public ResourceOperationSchedule getResourceOperationSchedule(Subject subject, String jobId)
        throws SchedulerException {

        JobId jobIdObject = new JobId(jobId);
        JobDetail jobDetail = scheduler.getJobDetail(jobIdObject.getJobName(), jobIdObject.getJobGroup());
        ResourceOperationSchedule resourceOperationSchedule = getResourceOperationSchedule(subject, jobDetail);
        if (resourceOperationSchedule == null) {
            throw new SchedulerException("The job with ID [" + jobId + "] is no longer scheduled.");
        }
        return resourceOperationSchedule;
    }
View Full Code Here

        // not take long becaues the callers of this method normally limit the number of operations
        // returned to something very small (i.e. less than 10).
        Subject overlord = subjectManager.getOverlord();
        for (ResourceOperationScheduleComposite composite : results) {
            try {
                ResourceOperationSchedule sched = getResourceOperationSchedule(subject, composite.getJobId().toString());
                OperationDefinition def = getSupportedResourceOperation(overlord, composite.getResourceId(),
                    sched.getOperationName(), false);
                composite.setOperationName((def.getDisplayName() != null) ? def.getDisplayName() : sched
                    .getOperationName());
            } catch (SchedulerException se) {
                LOG.error("A schedule entity is out of sync with the scheduler - there is no job scheduled: "
                    + composite, se);
            } catch (Exception e) {
View Full Code Here

     * history item will be created.
     *
     * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
     */
    public void execute(JobExecutionContext context) throws JobExecutionException {
        ResourceOperationSchedule schedule = null;
        Subject loggedInSubject = null;

        try {
            JobDetail jobDetail = context.getJobDetail();
            int triggerTimes = 1;
            if (context.getTrigger() instanceof SimpleTrigger) {
                SimpleTrigger trigger = (SimpleTrigger) context.getTrigger();
                triggerTimes = trigger.getTimesTriggered();
            } else {
                // Cron Trigger
            }
            OperationManagerLocal operationManager = LookupUtil.getOperationManager();

            updateOperationScheduleEntity(jobDetail, context.getNextFireTime(), operationManager);

            // retrieve the stored schedule using the overlord so it succeeds no matter what
            schedule = operationManager.getResourceOperationSchedule(getOverlord(), jobDetail);

            // Login the schedule's subject so its assigned a session, so our security tests pass.
            // Create a new session even if user is logged in elsewhere, we don't want to attach to that user's session
            loggedInSubject = getUserWithSession(schedule.getSubject(), false);
            schedule.setSubject(loggedInSubject);

            // for the security check, can the user who scheduled the operation in the first
            // place still have the authority to execute it against the resource in question
            operationManager.getResourceOperationSchedule(schedule.getSubject(), jobDetail);

            ResourceOperationHistory resourceHistory = null;
            if (triggerTimes==1) { // On 1st fire use the already provided history.
                resourceHistory = findOperationHistory(jobDetail.getName(),jobDetail.getGroup(),operationManager, schedule);
                if (resourceHistory.getStartedTime()>0) {
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.operation.bean.ResourceOperationSchedule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.