Examples of JobStatus


Examples of org.apache.sling.bgservlets.JobStatus

       
        private void processCommands(HttpServletRequest req, PrintWriter pw, Session s, JobConsole console) {
            // TODO should use POST
            final String jobPath = req.getParameter("jobPath");
            if (jobPath != null) {
                final JobStatus job = console.getJobStatus(s, jobPath);
                if (job != null) {
                    final String action = req.getParameter("action");
                    if ("suspend".equals(action)) {
                        job.requestStateChange(JobStatus.State.SUSPENDED);
                    } else if ("stop".equals(action)) {
                        job.requestStateChange(JobStatus.State.STOPPED);
                    } else if ("resume".equals(action)) {
                        job.requestStateChange(JobStatus.State.RUNNING);
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.sling.bgservlets.JobStatus

        final Session session = request.getResourceResolver().adaptTo(Session.class);
        if(session == null) {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "ResourceResolver does not adapt to a Session");
            return;
        }
        final JobStatus j = jobConsole.getJobStatus(session, request.getResource().getPath());
        final JobStatus.State oldState = j.getState();
        j.requestStateChange(desiredState);
        final JobStatus.State newState = j.getState();
       
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        final JSONWriter w = new JSONWriter(response.getWriter());
        try {
            w.object();
            w.key("info").value("Requested state change");
            w.key(PARAM_STATE).value(desiredState.toString());
            w.key("path").value(j.getPath());
            w.key("currentState").value(newState);
            w.key("stateChanged").value(newState != oldState);
            w.endObject();
        } catch(JSONException je) {
            throw new ServletException("JSONException in doPost", je);
View Full Code Here

Examples of org.apache.sling.bgservlets.JobStatus

        public Date getCreationTime() {
            return creationTime;
        }

        public State getState() {
            final JobStatus j = getActiveJob();
            if(j == null) {
                log.debug("Job {} not found by getActiveJob, assuming status==DONE", path);
                return State.DONE;
            }
            return j.getState();
        }
View Full Code Here

Examples of org.apache.sling.bgservlets.JobStatus

            }
            return j.getState();
        }
   
        public void requestStateChange(State s) {
            final JobStatus j = getActiveJob();
            if(j == null) {
                log.debug("Job {} is not active, cannot change state", path);
            } else {
                j.requestStateChange(s);
            }
        }
View Full Code Here

Examples of org.apache.sling.bgservlets.JobStatus

            }
        }
       
        /** @inheritDoc */
        public State [] getAllowedHumanStateChanges() {
            final JobStatus j = getActiveJob();
            if(j == null) {
                return new State[] {};
            }
            return j.getAllowedHumanStateChanges();
        }
View Full Code Here

Examples of org.apache.sling.bgservlets.JobStatus

        }

        public JobProgressInfo getProgressInfo() {
            // If job is active, return its info, else
            // return info from our job node
            final JobStatus active = getActiveJob();
            if(active != null) {
                return active.getProgressInfo();
            } else {
                return new JobProgressInfo() {
                    public String getProgressMessage() {
                        return getState().toString();
                    }
View Full Code Here

Examples of org.candlepin.pinsetter.core.model.JobStatus

    public void unPauseTest() throws JobExecutionException, PinsetterException {
        JobDetail jd = newJob(KingpinJob.class)
            .withIdentity("Kayfabe", "Deluxe")
            .build();

        JobStatus js = new JobStatus(jd, true);
        List<JobStatus> jl = new ArrayList<JobStatus>();
        jl.add(js);
        when(j.findWaitingJobs()).thenReturn(jl);
        unpauseJob.execute(ctx);
        try {
View Full Code Here

Examples of org.glite.ce.creamapi.jobmanagement.JobStatus

            if (job == null) {
                return;
            }

            JobStatus lastStatus = job.getLastStatus();
            if (lastStatus == null) {
                return;
            }

            boolean update = false;

            if ("W".equalsIgnoreCase(lastStatus.getExitCode())) {
                try {
                    String exitCode = getExitCode(job.getWorkingDirectory() + "/StandardOutput", job.getLocalUser());
                    lastStatus.setExitCode(exitCode);
                } catch (Exception e) {
                    lastStatus.setExitCode(Job.NOT_AVAILABLE_VALUE);
                } finally {
                    update = true;
                }
            }

            if (lastStatus.getType() == JobStatus.DONE_FAILED || lastStatus.getType() == JobStatus.CANCELLED) {
                try {
                    String stdErrorMessage = readFile(job.getWorkingDirectory() + "/StandardError", job.getLocalUser());
                    String errorMessage = null;
                    if (stdErrorMessage != null && !stdErrorMessage.equals("")) {
                        errorMessage = lastStatus.getFailureReason();
                       
                        if (errorMessage != null && !stdErrorMessage.equals(stdErrorMessage)) {
                            errorMessage += "; " + stdErrorMessage;
                        } else {
                            errorMessage = stdErrorMessage;
                        }   
                    } else {
                        errorMessage = Job.NOT_AVAILABLE_VALUE;
                    }

                    lastStatus.setFailureReason(errorMessage);
                } catch (Exception e) {
                    if (lastStatus.getFailureReason() == null || lastStatus.getFailureReason().length() == 0) {
                        lastStatus.setFailureReason(Job.NOT_AVAILABLE_VALUE);
                    }
                } finally {
                    update = true;
                }
            }

            if(update) {
                Command statusCmd = new Command(JobCommandConstant.SET_JOB_STATUS, getCategory());
                //statusCmd.setCommandExecutorName(blahExec.getName());
                statusCmd.setAsynchronous(true);
                statusCmd.setUserId("admin");
                statusCmd.addParameter("JOB_ID", lastStatus.getJobId());
                statusCmd.addParameter("STATUS_TYPE", ""+lastStatus.getType());
               // statusCmd.addParameter("STATUS_CHANGE_TIME", lastStatus.getTimestamp());
               // statusCmd.addParameter("WORKER_NODE", workerNode);
               // statusCmd.addParameter("LRMS_JOB_ID", batchJobId);
                statusCmd.addParameter("IS_ADMIN", "true");
                statusCmd.addParameter("EXIT_CODE", lastStatus.getExitCode());
                statusCmd.addParameter("FAILURE_REASON", lastStatus.getFailureReason());
                statusCmd.setPriorityLevel(Command.MEDIUM_PRIORITY);
                statusCmd.setExecutionMode(Command.ExecutionModeValues.SERIAL);
                statusCmd.setCommandGroupId(lastStatus.getJobId());

                if (lastStatus.getTimestamp() != null) {
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                    statusCmd.addParameter("STATUS_CHANGE_TIME", dateFormat.format(lastStatus.getTimestamp().getTime()));
                }

                try {
                    getCommandManager().execute(statusCmd);
                } catch (Throwable e) {
View Full Code Here

Examples of org.glite.ce.creamapi.jobmanagement.JobStatus

                } catch (ParseException e) {
                    logger.error(e.getMessage());
                }
            }

            JobStatus status = new JobStatus(statusType, jobId, changeTime);
            status.setExitCode(exitCode);
            status.setFailureReason(failureReason);

            Job job = null;
            try {
                job = jobDB.retrieveJob(status.getJobId(), null);
            } catch (Exception e) {
                logger.warn("job " + status.getJobId() + " not found!");
                return;
            }

            try {
                if(doOnJobStatusChanged(status, job)) {
                    boolean updateJob = false;
                    if (lrmsJobId != null && (job.getLRMSJobId() == null || job.getLRMSJobId().equalsIgnoreCase("N/A"))) {
                        job.setLRMSJobId(lrmsJobId);
                        updateJob = true;
                    }

                    if (workerNode != null) {
                        boolean isReallyRunning = false;

                        if(job.getWorkerNode() != null && !job.getWorkerNode().equals("N/A") && status.getType() != JobStatus.REALLY_RUNNING) {
                            for(JobStatus oldStatus : job.getStatusHistory()) {
                                if(oldStatus.getType() == JobStatus.REALLY_RUNNING) {
                                    isReallyRunning = true;
                                    break;
                                }
                            }
                        }

                        if(!isReallyRunning) {
                            job.setWorkerNode(workerNode);
                            updateJob = true;
                        }
                    }

                    if (updateJob) {
                        try {
                            jobDB.update(job);
                        } catch (Throwable e) {
                            logger.error(e);
                        }
                    }
                }
            } catch (JobManagementException e) {
                logger.error(e.getMessage());
            }
        } else if (JobCommandConstant.JOB_LIST.equals(command.getName())) {
            logger.debug("Calling jobList.");
            try {
                String user = null;

                if (!isAdmin) {
                    user = userId;
                }

                List<String> jobIdFound = jobDB.retrieveJobId(user);
                JobEnumeration jobEnum = new JobEnumeration(jobIdFound, jobDB);
                command.getResult().addParameter("JOB_ENUM", jobEnum);
            } catch (DatabaseException e) {
                logger.error(e.getMessage());
                throw new CommandException("database error occurred");
            }
        } else {
            JobEnumeration jobEnum = getJobList(command);
           
            try {
                List<Job> jobList = new ArrayList<Job>(0);
                Calendar now = Calendar.getInstance();
               
                while (jobEnum.hasMoreJobs()) {
                    Job job = jobEnum.nextJob();

                    JobCommand jobCmd = new JobCommand();
                    jobCmd.setJobId(job.getId());
                    jobCmd.setCreationTime(command.getCreationTime());
                    jobCmd.setDescription(command.getDescription());
                    jobCmd.setStartSchedulingTime(command.getStartProcessingTime());
                    jobCmd.setStartProcessingTime(now);
                    jobCmd.setType(cmdType);
                    jobCmd.setCommandExecutorName(getName());

                    if (!isAdmin || job.getUserId().equals(command.getUserId())) {
                        jobCmd.setUserId(command.getUserId());
                    }

                    if ((JobCommandConstant.JOB_CANCEL.equals(command.getName())) && (jobCmd.getDescription() == null)) {
                        if (!isAdmin || job.getUserId().equals(command.getUserId())) {
                            jobCmd.setDescription("Cancelled by user");
                        } else {
                            jobCmd.setDescription("Cancelled by CE admin");
                        }
                    }
                   
                    logger.debug("Calling jobDB.insertJobCommand.");
                    try {
                        jobDB.insertJobCommand(jobCmd);
                    } catch (Throwable e) {
                        logger.error(e.getMessage());
                        continue;
                    }

                    logger.debug("jobDB.insertJobCommand has been executed.");

                    if (jobCmd.getStatus() != JobCommand.ERROR) {
                        job.addCommandHistory(jobCmd);
                        jobList.add(job);
                    }
                }

                for (Job j : jobList) {
                    JobCommand jobCmd = j.getLastCommand();
                    if (jobCmd == null) {
                        continue;
                    }

                    jobCmd.setStatus(JobCommand.PROCESSING);

                    if (LBLogger.isEnabled()) {
                        try {
                            LBLogger.getInstance().execute(j, command, LBLogger.START, null, null);
                        } catch (Throwable t) {
                            logger.warn("LBLogger.execute() failed: " + t.getMessage());
                        }
                    }

                    try {
                        if (JobCommandConstant.JOB_CANCEL.equals(command.getName())) {
                            if (j.getLastStatus() != null && j.getLastStatus().getType() == JobStatus.REGISTERED) {
                                JobStatus status = new JobStatus(JobStatus.CANCELLED, j.getId(), now);
                                status.setDescription(jobCmd.getDescription());
                                doOnJobStatusChanged(status, j);
                            } else {
                                cancel(j);
                            }
View Full Code Here

Examples of org.glite.ce.creamapi.jobmanagement.JobStatus

                      
        Job job = (Job)command.getParameter("JOB");
       
        logger.debug("Begin jobStart for job " + job.getId());

        JobStatus status = new JobStatus(JobStatus.PENDING, job.getId());
        try {
            doOnJobStatusChanged(status, job);
        } catch (Throwable t) {
          throw new CommandException(t.getMessage());
        }

        Calendar now = Calendar.getInstance();
        CommandResult cr = null;
        String failureReason = null;
       
        for (int i=1; i<4 && cr == null; i++) {
            failureReason = null;

            try {
                cr = submit(job);
            } catch (CommandException ce) {
                failureReason = ce.getMessage();
                logger.warn("submission to BLAH failed [jobId=" + job.getId() + "; reason=" + failureReason + "; retry count=" + i + "/3]");

                synchronized(now) {
                    try {
                        logger.debug("sleeping 10 sec...");
                        now.wait(10000);
                        logger.debug("sleeping 10 sec... done");
                    } catch (InterruptedException e) {
                        logger.warn(e.getMessage());
                    }
                }
            }
        }
       
        if (cr == null) {
            status = new JobStatus(JobStatus.ABORTED, job.getId());
            status.setDescription("submission to BLAH failed [retry count=3]");
            status.setFailureReason(failureReason);

            try {
                doOnJobStatusChanged(status, job);
            } catch (Throwable te) {
                throw new CommandException(te.getMessage());
            }

            setLeaseExpired(job);

            throw new CommandException("submission to BLAH failed [retry count=3]" + (failureReason != null ? ": " + failureReason : ""));
        }

        job.setLRMSJobId(cr.getParameterAsString("LRMS_JOB_ID"));
        job.setLRMSAbsLayerJobId(cr.getParameterAsString("LRMS_ABS_JOB_ID"));

        try {
            if (isEmptyField(job.getLRMSAbsLayerJobId())) {
                status = new JobStatus(JobStatus.ABORTED, job.getId());
                status.setFailureReason("LRMSAbsLayerJobId not found!");

                doOnJobStatusChanged(status, job);

                setLeaseExpired(job);
            } else {
                jobDB.update(job);

                JobStatus lastStatus = jobDB.retrieveLastJobStatus(job.getId(), command.getUserId());
                if (lastStatus.getType() == JobStatus.PENDING) {
                    status = new JobStatus(JobStatus.IDLE, job.getId(), now);

                    doOnJobStatusChanged(status, job);
                }
            }
        } catch (Throwable te) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.