Search in sources :

Example 6 with JobInfo

use of org.glassfish.api.admin.progress.JobInfo 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)

Example 7 with JobInfo

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

the class AttachCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    eventBroker = context.getEventBroker();
    attached = registry.get(jobID);
    JobInfo jobInfo = null;
    String jobName = null;
    if (attached == null) {
        // try for completed jobs
        if (registry.getCompletedJobs(registry.getJobsFile()) != null) {
            jobInfo = (JobInfo) registry.getCompletedJobForId(jobID);
        }
        if (jobInfo != null) {
            jobName = jobInfo.jobName;
        }
    }
    attach(attached, jobInfo, context, jobName);
}
Also used : JobInfo(org.glassfish.api.admin.progress.JobInfo)

Example 8 with JobInfo

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

the class JobAuthorizationAttributeProcessor method describeAuthorization.

@Override
public void describeAuthorization(Subject subject, String resourceName, String action, AdminCommand command, Map<String, Object> context, Map<String, String> subjectAttributes, Map<String, String> resourceAttributes, Map<String, String> actionAttributes) {
    final Matcher m = JOB_PATTERN.matcher(resourceName);
    if (!m.matches()) {
        return;
    }
    if (m.groupCount() == 0) {
        /*
             * The resource name pattern did not match for including a job ID, 
             * so we will not be able to attach a user attribute to the resource.
             */
        return;
    }
    final String jobID = m.group(1);
    final Job job = jobManager.get(jobID);
    String userID = null;
    /*
         * This logic might run before any validation in the command has run,
         * in which case the job ID would be invalid and the job manager and/or
         * the completed jobs store might not know about the job.
         */
    if (job != null && job.getSubjectUsernames().size() > 0) {
        userID = job.getSubjectUsernames().get(0);
    } else {
        if (jobManager.getCompletedJobs(jobManager.getJobsFile()) != null) {
            final JobInfo jobInfo = (JobInfo) jobManager.getCompletedJobForId(jobID);
            if (jobInfo != null) {
                userID = jobInfo.user;
            }
        }
    }
    if (userID != null) {
        resourceAttributes.put(USER_ATTRIBUTE_NAME, userID);
    }
}
Also used : Matcher(java.util.regex.Matcher) JobInfo(org.glassfish.api.admin.progress.JobInfo) Job(org.glassfish.api.admin.Job)

Example 9 with JobInfo

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

the class JobCleanUpService method cleanUpExpiredJobs.

/**
 * This will periodically purge expired jobs
 */
private void cleanUpExpiredJobs(File file) {
    ArrayList<JobInfo> expiredJobs = jobManagerService.getExpiredJobs(file);
    if (expiredJobs.size() > 0) {
        for (JobInfo job : expiredJobs) {
            // remove from Job registy
            jobManagerService.purgeJob(job.jobId);
            // remove from jobs.xml file
            jobManagerService.purgeCompletedJobForId(job.jobId, file);
            // remove from local cache for completed jobs
            jobManagerService.removeFromCompletedJobs(job.jobId);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, KernelLoggerInfo.cleaningJob, job.jobId);
            }
        }
    }
}
Also used : JobInfo(org.glassfish.api.admin.progress.JobInfo)

Example 10 with JobInfo

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

the class JobPersistenceService method persist.

@Override
public void persist(Object obj) {
    JobInfo jobInfo = (JobInfo) obj;
    jobInfos = jobManager.getCompletedJobs(jobManager.getJobsFile());
    doPersist(jobInfos, jobInfo);
}
Also used : JobInfo(org.glassfish.api.admin.progress.JobInfo)

Aggregations

JobInfo (org.glassfish.api.admin.progress.JobInfo)10 JobInfos (org.glassfish.api.admin.progress.JobInfos)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 File (java.io.File)2 JAXBException (javax.xml.bind.JAXBException)2 ManagedJobConfig (com.sun.enterprise.config.serverbeans.ManagedJobConfig)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 ActionReport (org.glassfish.api.ActionReport)1 MessagePart (org.glassfish.api.ActionReport.MessagePart)1 Job (org.glassfish.api.admin.Job)1 JobPersistence (org.glassfish.api.admin.progress.JobPersistence)1