Search in sources :

Example 1 with JobInfos

use of org.glassfish.api.admin.progress.JobInfos in project Payara by payara.

the class ListJobsCommand method chooseJobs.

private List<JobInfo> chooseJobs() {
    List<JobInfo> jobsToReport = new ArrayList<JobInfo>();
    if (jobID != null) {
        Job oneJob = jobManagerService.get(jobID);
        JobInfo info = null;
        if (isSingleJobOK(oneJob)) {
            List<String> userList = oneJob.getSubjectUsernames();
            ActionReport actionReport = oneJob.getActionReport();
            String message = actionReport == null ? "" : actionReport.getMessage();
            if (!StringUtils.ok(message)) {
                message = ProgressStatusClient.composeMessageForPrint(oneJob.getCommandProgress());
            }
            String exitCode = actionReport == null ? "" : actionReport.getActionExitCode().name();
            info = new JobInfo(oneJob.getId(), oneJob.getName(), oneJob.getCommandExecutionDate(), exitCode, userList.get(0), message, oneJob.getJobsFile(), oneJob.getState().name(), 0);
        } else {
            if (getCompletedJobs() != null) {
                info = getCompletedJobForId(jobID);
            }
        }
        if (info != null && !skipJob(info.jobName)) {
            jobsToReport.add(info);
        }
    } else {
        for (Iterator<Job> iterator = jobManagerService.getJobs(); iterator.hasNext(); ) {
            Job job = iterator.next();
            if (isJobEligible(job)) {
                List<String> userList = job.getSubjectUsernames();
                ActionReport actionReport = job.getActionReport();
                String message = actionReport == null ? "" : actionReport.getMessage();
                if (!StringUtils.ok(message)) {
                    message = ProgressStatusClient.composeMessageForPrint(job.getCommandProgress());
                }
                String exitCode = actionReport == null ? "" : actionReport.getActionExitCode().name();
                String user = DEFAULT_USER_STRING;
                if (userList.size() > 0) {
                    user = userList.get(0);
                }
                jobsToReport.add(new JobInfo(job.getId(), job.getName(), job.getCommandExecutionDate(), exitCode, user, message, job.getJobsFile(), job.getState().name(), 0));
            }
        }
        JobInfos completedJobs = getCompletedJobs();
        if (completedJobs != null) {
            for (JobInfo info : completedJobs.getJobInfoList()) {
                if (!skipJob(info.jobName)) {
                    jobsToReport.add(info);
                }
            }
        }
    }
    return jobsToReport;
}
Also used : JobInfo(org.glassfish.api.admin.progress.JobInfo) JobInfos(org.glassfish.api.admin.progress.JobInfos) ActionReport(org.glassfish.api.ActionReport)

Example 2 with JobInfos

use of org.glassfish.api.admin.progress.JobInfos in project Payara by payara.

the class JobManagerService method purgeCompletedJobForId.

/**
 * This method looks for the completed jobs
 * and purges a job which is marked with the jobId
 * @param jobId the job to purge
 * @return  the new list of completed jobs
 */
public JobInfos purgeCompletedJobForId(String jobId, File file) {
    JobInfos completedJobInfos = getCompletedJobs(file);
    synchronized (file) {
        CopyOnWriteArrayList<JobInfo> jobList = new CopyOnWriteArrayList<JobInfo>();
        if (completedJobInfos != null) {
            jobList.addAll(completedJobInfos.getJobInfoList());
            for (JobInfo jobInfo : jobList) {
                if (jobInfo.jobId.equals(jobId)) {
                    jobList.remove(jobInfo);
                }
            }
        }
        JobInfos jobInfos = new JobInfos();
        // if (jobList.size() > 0)    {
        try {
            if (jaxbContext == null)
                jaxbContext = JAXBContext.newInstance(JobInfos.class);
            jobInfos.setJobInfoList(jobList);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
            jaxbMarshaller.marshal(jobInfos, file);
        } catch (JAXBException e) {
            throw new RuntimeException(adminStrings.getLocalString("error.purging.completed.job", "Error purging completed job ", jobId, e.getLocalizedMessage()), e);
        }
        // }
        return jobInfos;
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JobInfos(org.glassfish.api.admin.progress.JobInfos) JobInfo(org.glassfish.api.admin.progress.JobInfo) JAXBException(javax.xml.bind.JAXBException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 3 with JobInfos

use of org.glassfish.api.admin.progress.JobInfos 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 4 with JobInfos

use of org.glassfish.api.admin.progress.JobInfos in project Payara by payara.

the class JobPersistenceService method doPersist.

public void doPersist(JobInfos jobInfos, JobInfo jobInfo) {
    File file = jobInfo.getJobsFile();
    synchronized (file) {
        if (jobInfos == null) {
            jobInfos = new JobInfos();
        }
        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(JobInfos.class);
            jaxbMarshaller = jaxbContext.createMarshaller();
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            CopyOnWriteArrayList<JobInfo> jobList = new CopyOnWriteArrayList<JobInfo>(jobInfos.getJobInfoList());
            jobInfos.setJobInfoList(jobList);
            jobList.add(jobInfo);
            jaxbMarshaller.marshal(jobInfos, file);
            jobManager.addToCompletedJobs(new CompletedJob(jobInfo.jobId, jobInfo.commandCompletionDate, jobInfo.getJobsFile()));
            jobManager.purgeJob(jobInfo.jobId);
        } catch (JAXBException e) {
            throw new RuntimeException(adminStrings.getLocalString("error.persisting.jobs", "Error while persisting jobs", jobInfo.jobId, e.getLocalizedMessage()), e);
        }
    }
}
Also used : JobInfos(org.glassfish.api.admin.progress.JobInfos) JobInfo(org.glassfish.api.admin.progress.JobInfo) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) File(java.io.File) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

JobInfo (org.glassfish.api.admin.progress.JobInfo)4 JobInfos (org.glassfish.api.admin.progress.JobInfos)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 JAXBException (javax.xml.bind.JAXBException)2 ManagedJobConfig (com.sun.enterprise.config.serverbeans.ManagedJobConfig)1 File (java.io.File)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 ActionReport (org.glassfish.api.ActionReport)1