Search in sources :

Example 1 with ManagedJobConfig

use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.

the class JobCleanUpService method scheduleCleanUp.

/**
 * This will schedule a cleanup of expired jobs based on configurable values
 */
private void scheduleCleanUp() {
    if (managedJobConfig == null) {
        managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
        ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(managedJobConfig);
        logger.fine(KernelLoggerInfo.initializingManagedConfigBean);
        bean.addListener(this);
    }
    logger.fine(KernelLoggerInfo.schedulingCleanup);
    // default values to 20 minutes for delayBetweenRuns and initialDelay
    long delayBetweenRuns = 1200000;
    long initialDelay = 1200000;
    delayBetweenRuns = jobManagerService.convert(managedJobConfig.getPollInterval());
    initialDelay = jobManagerService.convert(managedJobConfig.getInitialDelay());
    ScheduledFuture<?> cleanupFuture = scheduler.scheduleAtFixedRate(new JobCleanUpTask(), initialDelay, delayBetweenRuns, TimeUnit.MILLISECONDS);
}
Also used : ManagedJobConfig(com.sun.enterprise.config.serverbeans.ManagedJobConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 2 with ManagedJobConfig

use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.

the class JobManagerService method getExpiredJobs.

/**
 * This will return a list of jobs which have crossed the JOBS_RETENTION_PERIOD
 * and need to be purged
 * @return  list of jobs to be purged
 */
public ArrayList<JobInfo> getExpiredJobs(File file) {
    ArrayList<JobInfo> expiredJobs = new ArrayList<JobInfo>();
    synchronized (file) {
        JobInfos jobInfos = getCompletedJobs(file);
        for (JobInfo job : jobInfos.getJobInfoList()) {
            long executedTime = job.commandExecutionDate;
            long currentTime = System.currentTimeMillis();
            long jobsRetentionPeriod = 86400000;
            managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
            jobsRetentionPeriod = convert(managedJobConfig.getJobRetentionPeriod());
            if (currentTime - executedTime > jobsRetentionPeriod && (job.state.equals(AdminCommandState.State.COMPLETED.name()) || job.state.equals(AdminCommandState.State.REVERTED.name()))) {
                expiredJobs.add(job);
            }
        }
    }
    return expiredJobs;
}
Also used : JobInfo(org.glassfish.api.admin.progress.JobInfo) JobInfos(org.glassfish.api.admin.progress.JobInfos) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ManagedJobConfig(com.sun.enterprise.config.serverbeans.ManagedJobConfig)

Example 3 with ManagedJobConfig

use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.

the class ConfigureManagedJobs method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    Logger logger = context.getLogger();
    ManagedJobConfig managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
    if (managedJobConfig == null) {
        logger.warning(KernelLoggerInfo.getFailManagedJobConfig);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(KernelLoggerInfo.getLogger().getResourceBundle().getString(KernelLoggerInfo.getFailManagedJobConfig));
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<ManagedJobConfig>() {

            @Override
            public Object run(ManagedJobConfig param) throws PropertyVetoException, TransactionFailure {
                if (inMemoryRetentionPeriod != null)
                    param.setInMemoryRetentionPeriod(inMemoryRetentionPeriod);
                if (jobRetentionPeriod != null)
                    param.setJobRetentionPeriod(jobRetentionPeriod);
                if (pollInterval != null)
                    param.setPollInterval(pollInterval);
                if (initialDelay != null)
                    param.setInitialDelay(initialDelay);
                return param;
            }
        }, managedJobConfig);
    } catch (TransactionFailure e) {
        logger.warning(KernelLoggerInfo.configFailManagedJobConfig);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(e.getMessage());
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ManagedJobConfig(com.sun.enterprise.config.serverbeans.ManagedJobConfig) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger)

Example 4 with ManagedJobConfig

use of com.sun.enterprise.config.serverbeans.ManagedJobConfig in project Payara by payara.

the class JobCleanUpService method postConstruct.

@Override
public void postConstruct() {
    logger.log(Level.FINE, KernelLoggerInfo.initializingJobCleanup);
    scheduler = Executors.newScheduledThreadPool(10, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread result = new Thread(r);
            result.setDaemon(true);
            return result;
        }
    });
    if (Version.getFullVersion().contains("Micro")) {
        // if Micro we don't have any jobs to cleanup
        return;
    }
    managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(managedJobConfig);
    logger.fine(KernelLoggerInfo.initializingManagedConfigBean);
    bean.addListener(this);
    scheduleCleanUp();
}
Also used : ManagedJobConfig(com.sun.enterprise.config.serverbeans.ManagedJobConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Aggregations

ManagedJobConfig (com.sun.enterprise.config.serverbeans.ManagedJobConfig)4 ObservableBean (org.jvnet.hk2.config.ObservableBean)2 PropertyVetoException (java.beans.PropertyVetoException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Logger (java.util.logging.Logger)1 ActionReport (org.glassfish.api.ActionReport)1 JobInfo (org.glassfish.api.admin.progress.JobInfo)1 JobInfos (org.glassfish.api.admin.progress.JobInfos)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1