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;
}
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;
}
}
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;
}
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);
}
}
}
Aggregations