Package org.glite.ce.creamapi.cmdmanagement

Examples of org.glite.ce.creamapi.cmdmanagement.CommandException


        logger.debug("Begin retrieveJob for jobId = " + jobId);
        Job job = null;
        try {
            job = jobDB.retrieveJob(jobId, null);
        } catch (Exception e) {
            throw new CommandException(e.getMessage());
        }
               
        logger.debug("End retrieveJob for jobId = " + jobId);
        return job;
    }
View Full Code Here


    public void updateJob(Job job) throws CommandException {
        try {
            jobDB.update(job);
        } catch (Exception e) {
            throw new CommandException(e.getMessage());
        }
    }
View Full Code Here

            compatibleStatusToFindList = compatibleStatusList;
        }
       
        if ((compatibleStatusToFindList == null) || (compatibleStatusToFindList.size() == 0)) {
            logger.error("Status specified not compatible for the request command.");
            throw new CommandException("Status specified not compatible for the request command.");
        }

        int[] compatibleStatusToFind = new int[compatibleStatusToFindList.size()];
        for (int i = 0; i < compatibleStatusToFindList.size(); i++) {
            compatibleStatusToFind[i] = compatibleStatusToFindList.get(i);
        }

        List<String> jobIdFound = null;
        List<JobIdFilterResult> jobIdFilterResultList = new ArrayList<JobIdFilterResult>(0);
        JobIdFilterResult jobIdFilterResult = null;
        List<String> helpJobList = new ArrayList<String>(0);

        try {
            if ((jobList != null) && (jobList.size() > 0)) {
                logger.debug("JobList parameter is not null in jobFilter.");
                // find job not existing.
                helpJobList.addAll(jobList);
                jobIdFound = jobDB.retrieveJobId(jobList, userId);

                helpJobList.removeAll(jobIdFound);
                for (int i = 0; i < helpJobList.size(); i++) {
                    jobIdFilterResult = new JobIdFilterResult();
                    jobIdFilterResult.setJobId(helpJobList.get(i));
                    jobIdFilterResult.setErrorCode(JobIdFilterFailure.JOBID_ERRORCODE);
                    jobIdFilterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.JOBID_ERRORCODE]);
                    jobIdFilterResultList.add(jobIdFilterResult);
                    logger.debug("JobId = " + helpJobList.get(i) + " FailureReason = " + JobIdFilterFailure.failureReason[JobIdFilterFailure.JOBID_ERRORCODE]);
                }
               
                helpJobList.clear();
                helpJobList.addAll(jobIdFound);

                // find job by status.
                if (jobIdFound != null && jobIdFound.size() > 0) {
                    jobIdFound = jobDB.retrieveJobId(jobIdFound, userId, compatibleStatusToFind, fromStatusDate, toStatusDate);
                   
                    helpJobList.removeAll(jobIdFound);
                    for (int i = 0; i < helpJobList.size(); i++) {
                        jobIdFilterResult = new JobIdFilterResult();
                        jobIdFilterResult.setJobId(helpJobList.get(i));
                        jobIdFilterResult.setErrorCode(JobIdFilterFailure.STATUS_ERRORCODE);
                        jobIdFilterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.STATUS_ERRORCODE]);
                        jobIdFilterResultList.add(jobIdFilterResult);
                        logger.debug("JobId = " + helpJobList.get(i) + " FailureReason = " + JobIdFilterFailure.failureReason[JobIdFilterFailure.STATUS_ERRORCODE]);
                    }
                    helpJobList.clear();
                    helpJobList.addAll(jobIdFound);
                }

                // find job by date.
                if ((jobIdFound != null) && jobIdFound.size() > 0 && (fromDate != null || toDate != null)) {
                    jobIdFound = jobDB.retrieveByDate(jobIdFound, userId, fromDate, toDate);
                    helpJobList.removeAll(jobIdFound);
                    for (int i = 0; i < helpJobList.size(); i++) {
                        jobIdFilterResult = new JobIdFilterResult();
                        jobIdFilterResult.setJobId(helpJobList.get(i));
                        jobIdFilterResult.setErrorCode(JobIdFilterFailure.DATE_ERRORCODE);
                        jobIdFilterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.DATE_ERRORCODE]);
                        jobIdFilterResultList.add(jobIdFilterResult);
                        logger.debug("JobId = " + helpJobList.get(i) + " FailureReason = " + JobIdFilterFailure.failureReason[JobIdFilterFailure.DATE_ERRORCODE]);
                    }
                    helpJobList.clear();
                    helpJobList.addAll(jobIdFound);
                }

                // find job by delegationId.
                if ((jobIdFound != null) && jobIdFound.size() > 0 && (delegationId != null)) {
                    jobIdFound = jobDB.retrieveJobId(jobIdFound, delegationId, null, userId);
                    helpJobList.removeAll(jobIdFound);
                    for (int i = 0; i < helpJobList.size(); i++) {
                        jobIdFilterResult = new JobIdFilterResult();
                        jobIdFilterResult.setJobId(helpJobList.get(i));
                        jobIdFilterResult.setErrorCode(JobIdFilterFailure.DELEGATIONID_ERRORCODE);
                        jobIdFilterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.DELEGATIONID_ERRORCODE]);
                        jobIdFilterResultList.add(jobIdFilterResult);
                        logger.debug("JobId = " + helpJobList.get(i) + " FailureReason = " + JobIdFilterFailure.failureReason[JobIdFilterFailure.DELEGATIONID_ERRORCODE]);
                    }
                    helpJobList.clear();
                    helpJobList.addAll(jobIdFound);
                }

                // find job by leaseId.
                if ((jobIdFound != null) && jobIdFound.size() > 0 && (leaseId != null)) {
                    jobIdFound = jobDB.retrieveJobId(jobIdFound, null, leaseId, userId);
                    helpJobList.removeAll(jobIdFound);
                    for (int i = 0; i < helpJobList.size(); i++) {
                        jobIdFilterResult = new JobIdFilterResult();
                        jobIdFilterResult.setJobId(helpJobList.get(i));
                        jobIdFilterResult.setErrorCode(JobIdFilterFailure.LEASEID_ERRORCODE);
                        jobIdFilterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.LEASEID_ERRORCODE]);
                        jobIdFilterResultList.add(jobIdFilterResult);
                        logger.debug("JobId = " + helpJobList.get(i) + " FailureReason = " + JobIdFilterFailure.failureReason[JobIdFilterFailure.LEASEID_ERRORCODE]);
                    }
                }
            } else { // jobList is null or empty.
                logger.debug("JobList parameter is null in jobFilter.");
               /*
                jobIdFound = jobDB.retrieveJobId(null, userId, compatibleStatusToFind, fromStatusDate, toStatusDate);

                if ((jobIdFound != null) && (jobIdFound.size() > 0) && (fromDate != null || toDate != null)) {
                    jobIdFound = jobDB.retrieveByDate(jobIdFound, userId, fromDate, toDate);
                }

                if ((jobIdFound != null) && (jobIdFound.size() > 0) && ((delegationId != null) || (leaseId != null))) {
                    jobIdFound = jobDB.retrieveJobId(jobIdFound, delegationId, leaseId, userId);
                }
               */
                jobIdFound = jobDB.retrieveJobId(userId, delegationId, compatibleStatusToFind, fromStatusDate, toStatusDate, leaseId, fromDate, toDate);
            }
            // job found.
            if (jobIdFound != null) {
                for (int i = 0; i < jobIdFound.size(); i++) {
                    jobIdFilterResult = new JobIdFilterResult();
                    jobIdFilterResult.setJobId(jobIdFound.get(i));
                    jobIdFilterResult.setErrorCode(JobIdFilterFailure.OK_ERRORCODE);
                    jobIdFilterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.OK_ERRORCODE]);
                    jobIdFilterResultList.add(jobIdFilterResult);
                }
            }
        } catch (DatabaseException e) {
            logger.error(e.getMessage());
            throw new CommandException("database error occurred");
        }

        JobEnumeration jobEnum = new JobEnumeration(jobIdFound, jobDB);
        cmd.getResult().addParameter("JOBID_FILTER_RESULT_LIST", jobIdFilterResultList);
        cmd.getResult().addParameter("JOB_ENUM", jobEnum);
View Full Code Here

        return -1;
    }

    private void insertJobCommand(JobCommand jobCommand, String delegationId, int[] statusType) throws CommandException {
        if (jobCommand == null) {
            throw new CommandException("jobCommand not defined!");
        }
       
        try {
            jobDB.insertJobCommand(jobCommand, delegationId, statusType);

            logger.debug("insertJobCommand local user " + jobCommand.getUserId() + " delegId = " + delegationId);
        } catch (DatabaseException de) {
            logger.error(de.getMessage());
            throw new CommandException("database error occurred");
        } catch (IllegalArgumentException ie) {
            throw new CommandException(ie.getMessage());
        }
    }
View Full Code Here

        }

        logger.debug("executing command: " + command.toString());
       
        if (!command.getCategory().equalsIgnoreCase(getCategory())) {
            throw new CommandException("command category mismatch: found \"" + command.getCategory() + "\" required \"" + getCategory() + "\"");
        }

        if (command.isAsynchronous() && command.getCommandGroupId() != null && "COMPOUND".equals(command.getCommandGroupId())) {
            List<String> jobIdList = null;

            if (command.containsParameterKey("JOB_ID_LIST")) {
                jobIdList = command.getParameterMultivalue("JOB_ID_LIST");

                command.deleteParameter("JOB_ID_LIST");
            } else {
                jobIdList = getJobList(command).getJobIdList();
            }

            if (command.containsParameterKey("EXECUTION_MODE")) {
                if (Command.EXECUTION_MODE_SERIAL.equals(command.getParameterAsString("EXECUTION_MODE"))) {
                    command.setExecutionMode(Command.ExecutionModeValues.SERIAL);
                } else {
                    command.setExecutionMode(Command.ExecutionModeValues.PARALLEL);
                }
            }

            if (command.containsParameterKey("PRIORITY_LEVEL")) {
                command.setPriorityLevel(Integer.parseInt(command.getParameterAsString("PRIORITY_LEVEL")));
            }

            if (jobIdList != null) {
                for (String jobId : jobIdList) {
                    command.addParameter("JOB_ID", jobId);
                    command.setCommandGroupId(jobId);

                    try {
                        getCommandManager().execute(command);
                    } catch (CommandManagerException e) {
                        logger.error(e.getMessage());
                        throw new CommandExecutorException(e.getMessage());
                    }
                }
            }

            if (command.getExecutionCompletedTime() == null) {
                command.setExecutionCompletedTime(Calendar.getInstance());
            }

            logger.debug("END execute");
            return;
        }

        String userId = command.getUserId();

        if (userId == null) {
            throw new CommandException("userId not defined!");
        }

        boolean isAdmin = command.getParameterAsString("IS_ADMIN") != null && command.getParameterAsString("IS_ADMIN").equalsIgnoreCase("true");

        int cmdType = getCommandType(command.getName());

        if (JobCommandConstant.GET_SERVICE_INFO.equals(command.getName())) {
            JobSubmissionManagerInfo jobSubmissionManagerInfo = JobSubmissionManager.getInstance().getJobSubmissionManagerInfo();
            command.getResult().addParameter("ACCEPT_NEW_JOBS", "" + jobSubmissionManagerInfo.isAcceptNewJobs());
            command.getResult().addParameter("SUBMISSION_THRESHOLD_MESSAGE", jobSubmissionManagerInfo.getShowMessage());
            command.getResult().addParameter("SUBMISSION_ERROR_MESSAGE", jobSubmissionManagerInfo.getTestErrorMessage());
            command.getResult().addParameter("SUBMISSION_EXECUTION_TIMESTAMP", jobSubmissionManagerInfo.getExecutionTimestamp());
           
            String sensorHost = getParameterValueAsString(CREAM_JOB_SENSOR_HOST);
            if (sensorHost != null && !"changeme".equals(sensorHost)) {
                command.getResult().addParameter("CEMON_URL", "https://" + sensorHost + ":8443/ce-monitor/services/CEMonitor");
            }

            jobSubmissionManagerInfo = null; //gc

        } else if (JobCommandConstant.SET_ACCEPT_NEW_JOBS.equals(command.getName())) {
            String accept = command.getParameterAsString("ACCEPT_NEW_JOBS");
            if (accept == null) {
                throw new CommandException("ACCEPT_NEW_JOBS value not specified!");
            }
            if (!isAdmin) {
                throw new CommandException("Operation reserved only to administrator!");
            }
            try {
                jobSubmissionManager.enableAcceptNewJobs(Integer.parseInt(accept));
            } catch (NumberFormatException nfe) {
                throw new CommandException("ACCEPT_NEW_JOBS value not valid!");
            }

        } else if (JobCommandConstant.PROXY_RENEW.equals(command.getName())) {
            logger.debug("Calling updateProxyToSandbox.");

            String delegId = command.getParameterAsString("DELEGATION_PROXY_ID");
            if (delegId == null) {              
                throw new CommandException("parameter \"DELEGATION_PROXY_ID\" not defined!");
            }

            String delegProxyInfo = command.getParameterAsString("DELEGATION_PROXY_INFO");
            if (delegProxyInfo == null) {              
                throw new CommandException("parameter \"DELEGATION_PROXY_INFO\" not defined!");
            }

            Calendar now = Calendar.getInstance();
            int[] statusType = new int[] {JobStatus.REGISTERED, JobStatus.HELD, JobStatus.IDLE, JobStatus.PENDING, JobStatus.REALLY_RUNNING, JobStatus.RUNNING};

            JobCommand jobCmd = new JobCommand();
            jobCmd.setCreationTime(command.getCreationTime());
            //jobCmd.setDescription(command.getDescription());
            jobCmd.setDescription(delegProxyInfo);
            jobCmd.setStartSchedulingTime(command.getStartProcessingTime());
            jobCmd.setStartProcessingTime(now);
            jobCmd.setExecutionCompletedTime(now);
            jobCmd.setType(cmdType);
            jobCmd.setStatus(JobCommand.SUCCESSFULL);
            jobCmd.setCommandExecutorName(getName());
            jobCmd.setUserId(userId);

            insertJobCommand(jobCmd, delegId, statusType);

        } else if (JobCommandConstant.JOB_REGISTER.equals(command.getName())) {
            logger.debug("Calling jobRegister.");
            jobRegister(command);

        } else if (JobCommandConstant.JOB_SET_LEASEID.equals(command.getName())) {
            logger.debug("Calling jobSetLeaseId.");
            jobSetLeaseId(command);

        } else if (JobCommandConstant.DELETE_LEASE.equals(command.getName())) {
            logger.debug("Calling deleteLease.");
            deleteLease(command);

        } else if (JobCommandConstant.SET_LEASE.equals(command.getName())) {
            logger.debug("Calling setLease.");
            setLease(command);

        } else if (JobCommandConstant.GET_LEASE.equals(command.getName())) {
            logger.debug("Calling getLease.");
            getLease(command);

        } else if (JobCommandConstant.JOB_INFO.equals(command.getName())) {
            logger.debug("Calling jobInfo.");
            getJobList(command);

        } else if (JobCommandConstant.JOB_STATUS.equals(command.getName())) {
            logger.debug("Calling jobStatus.");
            JobEnumeration jobEnum = getJobList(command);
            String user = null;

            if (!isAdmin) {
                user = userId;
            }

            try {
                List<JobStatus> jobStatusList = jobDB.retrieveLastJobStatus(jobEnum.getJobIdList(), user);
                command.getResult().addParameter("JOB_STATUS_LIST", jobStatusList);

                if (command.containsParameterKey("JOB_ID") || command.containsParameterKey("JOB_ID_LIST")) {
                    if (jobStatusList.size() < jobEnum.getJobIdList().size()) {               
                        List<String> jobIdList = new ArrayList<String>(jobStatusList.size());

                        for (JobStatus status : jobStatusList) {
                            jobIdList.add(status.getJobId());
                        }

                        jobEnum.getJobIdList().removeAll(jobIdList);

                        int found = 0;

                        List<JobIdFilterResult> jobIdFilterResultList = (List<JobIdFilterResult>) command.getResult().getParameter("JOBID_FILTER_RESULT_LIST");

                        for (JobIdFilterResult filterResult : jobIdFilterResultList) {
                            if (jobEnum.getJobIdList().contains(filterResult.getJobId())) {
                                filterResult.setErrorCode(JobIdFilterFailure.JOBID_ERRORCODE);
                                filterResult.setFailureReason(JobIdFilterFailure.failureReason[JobIdFilterFailure.JOBID_ERRORCODE]);

                                if (++found == jobEnum.getJobIdList().size()) {
                                    break;
                                }
                            }
                        }

                        command.getResult().addParameter("JOB_ENUM", new JobEnumeration(jobIdList, jobDB));
                    }
                }
            } catch (DatabaseException e) {
                logger.error(e.getMessage());
                throw new CommandException("database error occurred");
            }
        } else if (JobCommandConstant.QUERY_EVENT.equals(command.getName())) {
            logger.debug("Calling queryEvent.");
            int maxEvents = 100;
           
            try {
                maxEvents = Integer.parseInt(command.getParameterAsString("MAX_QUERY_EVENT_RESULT_SIZE"));
            } catch (Throwable t) {
                logger.warn("queryEvent: wrong value for MAX_QUERY_EVENT_RESULT_SIZE");
            }
           
            int[] jobStatusTypeArray = null;
            if (command.containsParameterKey("statusList")) {
                List<String> statusList = command.getParameterMultivalue("statusList");
               
                jobStatusTypeArray = new int[statusList.size()];

                for (int i = 0; i < statusList.size(); i++) {
                    jobStatusTypeArray[i] = -1;
                   
                    for (int x = 0; x < JobStatus.statusName.length; x++) {
                        if (statusList.get(i).equals(JobStatus.getNameByType(x))) {
                            jobStatusTypeArray[i] = x;
                            continue;
                        }
                    }
                }
            }
           
            JobStatusEventManagerInterface jobStatusEventManager = (JobStatusEventManagerInterface) EventManagerFactory.getEventManager("JOB_STATUS_EVENT_MANAGER");
            List<Event> eventList = null;
           
            try {
                eventList = jobStatusEventManager.getEvents(command.getParameterAsString("FROM_EVENT_ID"), command.getParameterAsString("TO_EVENT_ID"),
                        makeDate(command.getParameterAsString("FROM_DATE")), makeDate(command.getParameterAsString("TO_DATE")), jobStatusTypeArray,
                        maxEvents, userId);               
            } catch (EventManagerException e) {
                throw new CommandException(e.getMessage());
            }

            command.getResult().addParameter("EVENT_LIST", eventList);
        } else if (JobCommandConstant.SET_JOB_STATUS.equals(command.getName())) {
            logger.debug("Calling setJobStatus.");

            int statusType = Integer.valueOf(command.getParameterAsString("STATUS_TYPE"));
            String jobId = command.getParameterAsString("JOB_ID");
            String workerNode = command.getParameterAsString("WORKER_NODE");
            String lrmsJobId = command.getParameterAsString("LRMS_JOB_ID");
            String exitCode = command.getParameterAsString("EXIT_CODE");
            String failureReason = command.getParameterAsString("FAILURE_REASON");
            Calendar changeTime = null;
            if (command.containsParameterKey("STATUS_CHANGE_TIME")) {
                changeTime = new GregorianCalendar();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                dateFormat.setCalendar(changeTime);
                try {
                     dateFormat.parse(command.getParameterAsString("STATUS_CHANGE_TIME"));
                } 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);
                            }

                        } else if (JobCommandConstant.JOB_PURGE.equals(command.getName())) {
                            purge(j);
                       
                        } else if (JobCommandConstant.JOB_SUSPEND.equals(command.getName())) {
                            suspend(j);
                       
                        } else if (JobCommandConstant.JOB_RESUME.equals(command.getName())) {
                            resume(j);
                       
                        } else if (JobCommandConstant.JOB_START.equals(command.getName())) {
                            command.addParameter("JOB", j);
                            jobStart(command);

                            StringBuffer sb = new StringBuffer(command.toString());

                            if (j.getLRMSAbsLayerJobId() != null) {
                                sb.append(" lrmsAbsJobId=").append(j.getLRMSAbsLayerJobId()).append(";");
                            }

                            if (j.getLRMSJobId() != null) {
                                sb.append(" lrmsJobId=").append(j.getLRMSJobId()).append(";");
                            }

                            logger.info(sb.toString());
                            sb = null;
                            break;
//                        case JobCommandConstant.UPDATE_PROXY_TO_SANDBOX.equals(command.getName())) {
//                            logger.info(logInfo + jobCmd.toString() + " delegationId=" + j.getDelegationProxyId() + ";");
//
//                            String attr = j.getExtraAttribute("PROXY_RENEWAL");
//                            if (attr.equals("ENABLED")) {
//                                String delegationProxyInfo = command.getParameterAsString("DELEGATION_PROXY_INFO");
//                                if (delegationProxyInfo != null) {
//                                    j.setDelegationProxyInfo(delegationProxyInfo);
//                                    jobDB.update(j);
//                                }
//                            }
                        }

                        if (!JobCommandConstant.JOB_PURGE.equals(command.getName())) {
                            jobCmd.setStatus(JobCommand.SUCCESSFULL);

                            jobDB.updateJobCommand(jobCmd);
                        }

                        if (LBLogger.isEnabled()) {
                            try {
                                LBLogger.getInstance().execute(j, command, LBLogger.OK, j.getLRMSAbsLayerJobId(), null);
                            } catch (Throwable t) {
                                logger.warn("LBLogger.execute() failed: " + t.getMessage());
                            }
                        }
                    } catch (CommandException ce) {
                        jobCmd.setStatus(JobCommand.ERROR);
                        jobCmd.setFailureReason(ce.getMessage());

                        jobDB.updateJobCommand(jobCmd);

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

                List<String> invalidJobIdlist = (List<String>) command.getResult().getParameter("JOB_ID_LIST_STATUS_NOT_COMPATIBLE_FOUND");

                if (invalidJobIdlist != null) {
                    for (String jobId : invalidJobIdlist) {
                        try {
                            JobCommand jobCmd = new JobCommand(cmdType, jobId);
                            jobCmd.setCreationTime(command.getCreationTime());
                            jobCmd.setDescription(command.getDescription());
                            jobCmd.setStartSchedulingTime(command.getStartProcessingTime());
                            jobCmd.setStatus(JobCommand.ERROR);
                            jobCmd.setFailureReason("status not compatible with the specified command!");

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

                            jobDB.insertJobCommand(jobCmd);
                        } catch (DatabaseException e) {
                            logger.error(e.getMessage());
                        }
                    }
                }
            } catch (DatabaseException e) {
                logger.error(e.getMessage());
                throw new CommandException("database error occurred");
            } catch (JobManagementException e) {
                throw new CommandException(e.getMessage());
            }
        }

        if (command.getExecutionCompletedTime() == null) {
            command.setExecutionCompletedTime(Calendar.getInstance());
View Full Code Here

        return null;
    }
   
    private void jobStart(Command command) throws CommandException {
        if (command == null) {
            throw new CommandException("command not defined!");
        }
       
        if (!command.containsParameterKey("JOB")) {
            throw new CommandException("job not defined!");
        }

        String userDN = command.getParameterAsString("USER_DN");
        if (userDN == null) {
            throw new CommandException("parameter \"USER_DN\" not defined!");
        }
                      
        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) {
            throw new CommandException(te.getMessage());
        }

        logger.debug("End jobStart for job " + job.getId());
    }
View Full Code Here

        List<String> jobIdList = null;
        String leaseId = command.getParameterAsString("NEW_LEASE_ID");
        String userId = command.getUserId();

        if (userId == null) {
            throw new CommandException("userId not specified!");
        }

        JobEnumeration jobEnum = getJobList(command);
        jobIdList = jobEnum.getJobIdList();
        int commandType = getCommandType(JobCommandConstant.JOB_SET_LEASEID);
View Full Code Here

            }

            command.getResult().addParameter("LEASE_LIST", leaseList);
        } catch (DatabaseException e) {
            logger.error(e.getMessage());
            throw new CommandException("database error occurred");
        }
        logger.debug("End getLease");
    }
View Full Code Here

    }

    private void deleteLease(final Command command) throws CommandException {
        logger.debug("Begin deleteLease");
        if (!command.containsParameterKey("LEASE_ID")) {
            throw new CommandException("lease id not specified!");
        }

        String leaseId = command.getParameterAsString("LEASE_ID");
        String userId = command.getUserId();

        if (userId == null) {
            throw new CommandException("userId not specified!");
        }

        leaseManager.deleteLease(leaseId, userId);
        logger.debug("End deleteLease");
    }
View Full Code Here

    }

    private void setLease(final Command command) throws CommandException {
        logger.debug("BEGIN setLease");
        if (!command.containsParameterKey("LEASE_ID")) {
            throw new CommandException("lease id not specified!");
        }
        if (!command.containsParameterKey("LEASE_TIME")) {
            throw new CommandException("lease time not specified!");
        }

        String userId = command.getUserId();
        String leaseId = command.getParameterAsString("LEASE_ID");

        Calendar leaseTime = null;
        Calendar boundedLeaseTime = null;
        try {
            Long timestamp = Long.parseLong(command.getParameterAsString("LEASE_TIME"));
            leaseTime = Calendar.getInstance();
            leaseTime.setTimeInMillis(timestamp);
            logger.debug("leaseTime = " + leaseTime.getTime());
            Lease lease = new Lease();
            lease.setLeaseId(leaseId);
            lease.setUserId(userId);
            lease.setLeaseTime(leaseTime);
            boundedLeaseTime = leaseManager.setLease(lease);
            command.getResult().addParameter("LEASE_TIME", boundedLeaseTime);
            logger.debug("boundedLeaseTime = " + boundedLeaseTime);
        } catch (IllegalArgumentException e) {
            logger.error(e.getMessage());
            throw new CommandException(e.getMessage());
        } catch (CommandException e) {
            logger.error(e.getMessage());
            throw e;
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new CommandException(e.getMessage());
        }

        logger.debug("END setLease");
    }
View Full Code Here

TOP

Related Classes of org.glite.ce.creamapi.cmdmanagement.CommandException

Copyright © 2018 www.massapicom. 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.