Package org.glite.ce.creamapi.jobmanagement

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


        public GetSTDTask(String jobId) {
            this.jobId = jobId;
        }

        public void run() {
            Job job = null;
            try {
                job = jobDB.retrieveJob(jobId, null);
            } catch (IllegalArgumentException e) {
                logger.error("GetSTDTask - IllegalArgumentException: " + e.getMessage());
                return;
            } catch (DatabaseException e) {
                logger.error("GetSTDTask - DatabaseException: " + e.getMessage());
                return;
            }

            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)) {
View Full Code Here


        // cancelling job expired.
        try {
            List<String> jobIdListToCancel = executor.getJobDB().retrieveJobIdLeaseTimeExpired(status, null, null);

            Job job = null;

            for (int jobIndex = 0; jobIndex < jobIdListToCancel.size(); jobIndex++) {
                logger.debug("jobIdListToCancel = " + jobIdListToCancel.get(jobIndex));
                try {
                    job = executor.getJobDB().retrieveJob(jobIdListToCancel.get(jobIndex), null);

                    if (jobCancelByLeaseManager(job, now)) {
                        logger.info("Job has been cancelled. jobId = " + job.getId());
                    } else {
                        logger.warn("Problem to cancel job by LeaseManager. jobId = " + job.getId());
                    }
                } catch (Throwable e) {
                    logger.error(e.getMessage());
                    continue;
                }
View Full Code Here

        logger.info("destroyed!");
    }

    public Job retrieveJob(String jobId) throws 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());
        }
View Full Code Here

            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) {
View Full Code Here

        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

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

            Job job = makeJobFromCmd(cmd);
           
            JobStatus status = new JobStatus(JobStatus.REGISTERED, job.getId());

            job.setUserId(userId);
            job.setLocalUser(cmd.getParameterAsString("LOCAL_USER"));
            job.setJDL(cmd.getParameterAsString("JDL"));
            job.setICEId(cmd.getParameterAsString("ICE_ID"));
            job.addCommandHistory(jobCmd);
           
            if (cmd.containsParameterKey("USER_VO")) {
                job.setVirtualOrganization(cmd.getParameterAsString("USER_VO"));
            }

            if (isEmptyField(job.getBatchSystem())) {
                throw new CommandException("\"BatchSystem\" attribute not defined into the JDL");
            }

            if (isEmptyField(job.getQueue())) {
                throw new CommandException("\"QueueName\" attribute not defined into the JDL");
            }

            if (!isBatchSystemSupported(job.getBatchSystem())) {
                throw new CommandException("Batch System " + job.getBatchSystem() + " not supported!");
            }

            String cream_sandbox_dir = getParameterValueAsString("CREAM_SANDBOX_DIR");
            if (cream_sandbox_dir == null) {
                throw new CommandException("parameter \"CREAM_SANDBOX_DIR\" not defined!");
            }

            job.setCreamURL(cmd.getParameterAsString("CREAM_URL"));
            job.setDelegationProxyId(cmd.getParameterAsString("DELEGATION_PROXY_ID"));
            job.setDelegationProxyInfo(cmd.getParameterAsString("DELEGATION_PROXY_INFO"));
            job.setDelegationProxyCertPath(cmd.getParameterAsString("DELEGATION_PROXY_PATH"));
            job.setLRMSAbsLayerJobId(Job.NOT_AVAILABLE_VALUE);
            job.setLRMSJobId(Job.NOT_AVAILABLE_VALUE);
            job.setWorkerNode(Job.NOT_AVAILABLE_VALUE);
            job.setWorkingDirectory(Job.NOT_AVAILABLE_VALUE);

            if (cmd.containsParameterKey("USER_DN")) {
                job.addExtraAttribute("USER_DN", cmd.getParameterAsString("USER_DN").replaceAll("\\s+", "\\\\ "));
            }

            if (cmd.containsParameterKey("USER_DN_X500")) {
                job.addExtraAttribute("USER_DN_X500", cmd.getParameterAsString("USER_DN_X500").replaceAll("\\s+", "\\\\ "));
            }

            if (cmd.containsParameterKey("LOCAL_USER_GROUP")) {
                job.addExtraAttribute("LOCAL_USER_GROUP", cmd.getParameterAsString("LOCAL_USER_GROUP"));
            }

            if (cmd.containsParameterKey("USER_FQAN")) {
                List<String> fqanList = cmd.getParameterMultivalue("USER_FQAN");
               
                if (fqanList != null && fqanList.size() > 0) {                   
                    StringBuffer fqanBuffer = new StringBuffer();
                   
                    for (String fqan : fqanList) {
                        fqanBuffer.append("\\\"userFQAN=").append(fqan.replaceAll("\\s+", "\\\\ ")).append("\\\"\\ ");
                    }

                    fqanBuffer.deleteCharAt(fqanBuffer.length() - 1);
                    fqanBuffer.deleteCharAt(fqanBuffer.length() - 1);
                   
                    job.addExtraAttribute("USER_FQAN", fqanBuffer.toString());
                }
            }
            
            if (this.containsParameterKey("LRMS_EVENT_LISTENER_PORT")) {
                job.setLoggerDestURI(InetAddress.getLocalHost().getHostAddress() + ":" + getParameterValueAsString("LRMS_EVENT_LISTENER_PORT"));
            }

            if (job.getCreamURL() != null) {
                try {
                    URL url = new URL(job.getCreamURL());
                    job.setCeId(url.getHost() + ":" + url.getPort() + "/cream-" + job.getBatchSystem() + "-" + job.getQueue());
                } catch (MalformedURLException e) {
                }
            }

            if (cmd.containsParameterKey("LEASE_ID")) {
                String leaseId = cmd.getParameterAsString("LEASE_ID");

                if (leaseId != null && leaseId.length() > 0) {
                    Lease lease = jobDB.retrieveJobLease(leaseId, userId);
                    if (lease != null) {
                        logger.debug("found lease \"" + leaseId + "\" = " + lease.getLeaseTime().getTime());
                        job.setLease(lease);
                    } else {
                        throw new CommandException("lease id \"" + leaseId + "\" not found!");
                    }
                }
            }

            boolean jobInserted = false;
            int count = 0;

            while (!jobInserted && count < 5) {
                try {
                    jobDB.insert(job);
                    jobInserted = true;
                } catch (DatabaseException de) {
                    if (de.getMessage().indexOf("Duplicate entry") > -1) {
                        job.setId(job.generateJobId());
                        count++;
                    } else {
                        logger.error(de.getMessage());
                        throw new CommandException("database error occurred");
                    }
                } catch (IllegalArgumentException ie) {
                    throw new CommandException(ie.getMessage());
                }
            }

            if (!jobInserted) {
                throw new CommandException("Duplicate jobId error: cannot insert the new job (" + job.getId() + ") into the database");
            }

            jobCmd.setJobId(job.getId());
            jobCmd.setStatus(JobCommand.SUCCESSFULL);
          
            if (LBLogger.isEnabled()) {
                try {
                    LBLogger.getInstance().register(job);
View Full Code Here

        }

        jobAd.setLocalAccess(false);
        jobAd.checkAll(new String[] { Jdl.EXECUTABLE, Jdl.QUEUENAME, Jdl.JOBTYPE, "BatchSystem" });

        Job job = new Job();
        job.setLRMSAbsLayerJobId("N/A");
        job.setLRMSJobId("N/A");
        job.setWorkerNode("N/A");

        // if (creamURL == null) {
        // setCREAMJobId(getId());
        // } else {
        // setCREAMJobId(creamURL + (creamURL.endsWith("/") ? "" : "/")
        // + getId());
        // }

        // setId(getAttributeValue(job, Jdl.JOBID));
        job.setType(getAttributeValue(jobAd, Jdl.JOBTYPE));
        job.setBatchSystem(getAttributeValue(jobAd, "BatchSystem"));
        job.setQueue(getAttributeValue(jobAd, Jdl.QUEUENAME));
        job.setVirtualOrganization(getAttributeValue(jobAd, Jdl.VIRTUAL_ORGANISATION));
        job.setStandardError(getAttributeValue(jobAd, Jdl.STDERROR));
        job.setStandardInput(getAttributeValue(jobAd, Jdl.STDINPUT));
        job.setStandardOutput(getAttributeValue(jobAd, Jdl.STDOUTPUT));
        job.setExecutable(getAttributeValue(jobAd, Jdl.EXECUTABLE));
        job.setCeRequirements(getAttributeValue(jobAd, Jdl.CE_REQUIREMENTS));
        job.setInputSandboxBaseURI(getBaseURL(jobAd, "InputSandboxBaseURI"));
        job.setOutputSandboxBaseDestURI(getBaseURL(jobAd, "OutputSandboxBaseDestURI"));
        job.setOutputSandboxDestURI(getBaseURLs(jobAd, "OutputSandboxDestURI"));
        job.setInputFiles(getFiles(jobAd, Jdl.INPUTSB));
        job.setOutputFiles(getFiles(jobAd, Jdl.OUTPUTSB));
        job.setHlrLocation(getAttributeValue(jobAd, Jdl.HLR_LOCATION));
        job.setMyProxyServer(getAttributeValue(jobAd, Jdl.MYPROXY));
        job.setPrologue(getAttributeValue(jobAd, "Prologue"));
        job.setPrologueArguments(getAttributeValue(jobAd, "PrologueArguments"));
        job.setEpilogue(getAttributeValue(jobAd, "Epilogue"));
        job.setEpilogueArguments(getAttributeValue(jobAd, "EpilogueArguments"));
        job.setSequenceCode(getAttributeValue(jobAd, "LB_sequence_code"));
        job.setTokenURL(getAttributeValue(jobAd, "ReallyRunningToken"));

        String mwVersion = getAttributeValue(jobAd, Jdl.MW_VERSION);
        if (mwVersion != null) {
            job.addExtraAttribute(Jdl.MW_VERSION, mwVersion);
        }

        String lbAddress = getAttributeValue(jobAd, Jdl.LB_ADDRESS);
        if (lbAddress != null) {
            job.addVolatileProperty(Job.LB_ADDRESS, lbAddress);
        }

        ArrayList<OutputDataRecord> outputData = getOutputData(jobAd, Jdl.OUTPUTDATA);
        if (outputData != null){
            job.addVolatileProperty(Job.OUTPUT_DATA, outputData);
        }

        String wmsHostname = getAttributeValue(jobAd, Jdl.WMS_HOSTNAME);
        if (wmsHostname != null) {
            job.addVolatileProperty(Job.WMS_HOSTNAME, wmsHostname);
        }

        String maxOutputSandboxSize = getAttributeValue(jobAd, Jdl.MAX_OUTPUT_SANDBOX_SIZE);
        if (maxOutputSandboxSize != null) {
            job.addVolatileProperty(Job.MAX_OUTPUT_SANDBOX_SIZE, maxOutputSandboxSize);
        }

        if (job.getOutputFiles().size() > 0) {
            if (job.getOutputSandboxBaseDestURI() != null && job.getOutputSandboxBaseDestURI().length() > 0) {
                if (job.getOutputSandboxDestURI().size() > 0) {    
                    throw new Exception("the OutputSandboxDestURI and OutputSandboxBaseDestURI attributes cannot be specified together in the same JDL");
                }
            } else {
                if (job.getOutputSandboxDestURI().size() == 0) {           
                    throw new Exception("the OutputSandbox attribute requires the specification in the same JDL of one of the following attributes: OutputSandboxDestURI or OutputSandboxBaseDestURI");
                } else if (job.getOutputSandboxDestURI().size() != job.getOutputFiles().size()) {
                    throw new Exception("the OutputSandbox and OutputSandboxDestURI attributes must have the same cardinality");
                }
            }
        }

        String args = getAttributeValue(jobAd, Jdl.ARGUMENTS);
        if (args != null && args.length() > 0) {
            List<String> argsList = new ArrayList<String>(1);
            argsList.add(args);
           
            job.setArguments(argsList);
        }

        String edg_jobid = getAttributeValue(jobAd, "edg_jobid");
        if (edg_jobid == null) {
            edg_jobid = "N/A";
        }
        job.setGridJobId(edg_jobid);

        if (job.getType() == null) {
            job.setType("normal");
        }

        Expr expression = jobAd.lookup(Jdl.ENVIRONMENT);

        if (expression != null && expression instanceof ListExpr) {
            Iterator item = ((ListExpr) expression).iterator();

            while (item.hasNext()) {
                String tmps = ((Constant) item.next()).stringValue();
                String[] tokens = tmps.split("=", 2);
                job.addEnvironmentAttribute(tokens[0].trim(), tokens[1].trim());
            }
        }

        job.setNodeNumber(1);

        expression = jobAd.lookup(Jdl.CPUNUMB);
        if (expression != null) {
            if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
                 throw new Exception("wrong value for " + Jdl.CPUNUMB + ": it must be >=1");
            }

            job.setNodeNumber(expression.intValue());
        } else {
            expression = jobAd.lookup(Jdl.NODENUMB);
           
            if (expression != null) {
                if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
                    throw new Exception("wrong value for " + Jdl.NODENUMB + ": it must be >=1");
                }

                job.setNodeNumber(expression.intValue());
            }
        }

        boolean wholeNodes = false;
        expression = jobAd.lookup(Jdl.WHOLE_NODES);
        if (expression != null && expression.type == Expr.BOOLEAN && expression.isTrue()) {
            wholeNodes = true;
        }

        job.addExtraAttribute(Jdl.WHOLE_NODES, Boolean.toString(wholeNodes));

        expression = jobAd.lookup(Jdl.SMP_GRANULARITY);
        if (expression != null) {
            if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
                 throw new Exception("wrong value for " + Jdl.SMP_GRANULARITY + ": it must be >=1");
            }

            job.addExtraAttribute(Jdl.SMP_GRANULARITY, "" + expression.intValue());
        }

        expression = jobAd.lookup(Jdl.HOST_NUMBER);
        if (expression != null) {
            if (expression.type != Expr.INTEGER || expression.intValue() <= 0) {
                 throw new Exception("wrong value for " + Jdl.HOST_NUMBER + ": it must be >=1");
            }

            job.addExtraAttribute(Jdl.HOST_NUMBER, "" + expression.intValue());
        }

        if (!wholeNodes && job.containsExtraAttribute(Jdl.SMP_GRANULARITY) && job.containsExtraAttribute(Jdl.HOST_NUMBER)) {
            throw new Exception("the SMPGranularity and HostNumber attributes cannot be specified together when WholeNodes=false");
        }

        expression = jobAd.lookup("PerusalFileEnable");
        if (expression != null && expression.type == Expr.BOOLEAN && expression.isTrue()) {
            expression = jobAd.lookup("PerusalTimeInterval");
            if (expression != null && expression instanceof Constant) {
                job.setPerusalTimeInterval(expression.intValue());
            } else {
                job.setPerusalTimeInterval(5);
            }
            job.setPerusalFilesDestURI(getAttributeValue(jobAd, "PerusalFilesDestURI"));
            job.setPerusalListFileURI(getAttributeValue(jobAd, "PerusalListFileURI"));
        } else {
            job.setPerusalFilesDestURI(null);
        }

        return job;
    }
View Full Code Here

    public abstract boolean isBatchSystemSupported(String bs);


    public boolean doOnJobStatusChanged(JobStatus status) throws IllegalArgumentException, JobManagementException {
        Job job = null;
        try {
            job = jobDB.retrieveJob(status.getJobId(), null);
        } catch (Exception e) {
         //   logger.error(e.getMessage());
View Full Code Here

        LBLogger.setJobDB(jobDB);
        EventManagerFactory.addEventManager("JOB_STATUS_EVENT_MANAGER", new JobStatusEventManager(jobDB, 500));
       
        try {
            Job job = null;
            List<String> jobPendingList = jobDB.retrieveJobId(new int[] { JobStatus.PENDING }, null, null, null);

            for (String jobId : jobPendingList) {
                job = jobDB.retrieveJob(jobId, null);

                if (job != null && (job.getLRMSAbsLayerJobId() == null || Job.NOT_AVAILABLE_VALUE.equals(job.getLRMSAbsLayerJobId()))) {
                    if (isEmptyField(job.getLRMSAbsLayerJobId())) {
                        if (job.getCommandHistoryCount() > 1) {
                            JobCommand cmd = job.getCommandHistoryAt(1);
                            cmd.setStatus(JobCommand.ABORTED);
                            cmd.setFailureReason("command aborted because its execution has been interrupted by the CREAM shutdown");

                            if ("ADMINISTRATOR".equals(cmd.getUserId())) {
                                cmd.setUserId(job.getUserId());
                            }

                            jobDB.updateJobCommand(cmd);
                            logger.info(cmd.toString());
                        }

                        JobStatus status = job.getLastStatus();
                        status.setType(JobStatus.ABORTED);
                        status.setFailureReason("job aborted because the execution of the JOB_START command has been interrupted by the CREAM shutdown");
                        status.setTimestamp(job.getLastCommand().getExecutionCompletedTime());

                        jobDB.updateStatus(status, null);
                        logger.info("job " + job.getId() + " aborted because the execution of the JOB_START command has been interrupted by the CREAM shutdown");

                        try {
                            sendNotification(job);
                        } catch (JobManagementException e) {
                            logger.error(e.getMessage());
View Full Code Here


    public static Job makeJob(String classad) throws Exception {
        JDL jdl = new JDL(classad);

        Job job = new Job();
        job.setLRMSAbsLayerJobId("N/A");
        job.setLRMSJobId("N/A");
        job.setWorkerNode("N/A");
        job.setType(jdl.getJobType());
        job.setExecutable(jdl.getExecutable());
        job.setBatchSystem(jdl.getBatchSystem());
        job.setQueue(jdl.getQueueName());
        job.setVirtualOrganization(jdl.getVirtualOrganisation());
        job.setNodeNumber(jdl.getNodeNumber());
        job.setGridJobId(jdl.getEDGJobId());
        job.setEnvironment(jdl.getEnvironment());
        job.setCeRequirements(jdl.getCERequirements());
        job.setHlrLocation(jdl.getHLRLocation());
        job.setMyProxyServer(jdl.getMyProxyServer());
        job.setPrologue(jdl.getPrologue());
        job.setPrologueArguments(jdl.getPrologueArguments());
        job.setEpilogue(jdl.getEpilogue());
        job.setEpilogueArguments(jdl.getEpilogueArguments());
        job.setSequenceCode(jdl.getSequenceCode());
        job.setTokenURL(jdl.getTokenURL());
        job.setInputFiles(jdl.getInputSandbox());
        job.setOutputFiles(jdl.getOutputSandbox());
        job.setInputSandboxBaseURI(jdl.getInputSandboxBaseURI());
        job.setOutputSandboxBaseDestURI(jdl.getOutputSandboxBaseDestURI());
        job.setOutputSandboxDestURI(jdl.getOutputSandboxDestURI());
        job.setStandardInput(jdl.getStandardInput());
        job.setStandardOutput(jdl.getStandardOutput());
        job.setStandardError(jdl.getStandardError());

        String args = jdl.getArguments();
        if (args != null) {
           ArrayList<String> arguments = new ArrayList<String>(1);
           arguments.add(args);
           job.setArguments(arguments);
        }

        /*
         * INPUTSANDBOX / EXECUTABLE cross-check
         */
        String filename = job.getExecutable();
        if (filename != null && !(filename.startsWith("$") || filename.startsWith(File.separator)) && new File(filename).getName().equals(filename)) {
            if (!checkFileSandbox(filename, job.getInputFiles())) {
                throw new Exception(JDL.INPUTSANDBOX + ": the executable file is not listed in the InputSandbox");
            }
        }

        /*
         * INPUTSANDBOX / STDINPUT cross-check
         */
        filename = job.getStandardInput();
        if (filename != null && !(filename.startsWith("$") || filename.startsWith(File.separator)) && new File(filename).getName().equals(filename)) {
            if (!checkFileSandbox(filename, job.getInputFiles())) {
                throw new Exception(JDL.INPUTSANDBOX + ": the stdInput file is not listed in the InputSandbox");
            }
        }

        /*
         * STDERROR / STDOUTPUT cross-check
         */
        if (job.getStandardOutput() != null && job.getStandardError() != null) {
            File stdOutput = new File(job.getStandardOutput());
            File stdError = new File(job.getStandardError());

            if (stdOutput.getName().equals(stdError.getName()) && !stdOutput.getPath().equals(stdError.getPath())) {
                throw new Exception(JDL.STDOUTPUT + " & " + JDL.STDERROR + ": the values specified for StdError and StdOutput are the same but with different paths");
            }
        }

        if (job.getOutputFiles().size() > 0) {
            if (job.getOutputSandboxBaseDestURI() == null && job.getOutputSandboxDestURI().size() == 0) {
                // job.setOutputSandboxBaseDestURI("gsiftp://localhost");
                throw new Exception(JDL.OUTPUTSANDBOX + ": one of the following attributes OutputSandboxDestURI or OutputSandboxBaseDestURI must be specified");
            }

            /*
             * OUTPUTSANDBOX / OUTPUTSANDBOX_BASEDESTURI cross-check
             */
            if (job.getOutputSandboxBaseDestURI() == null && job.getOutputFiles().size() != job.getOutputSandboxDestURI().size()) {
                throw new Exception(JDL.OUTPUTSANDBOX_DESTURI + ": the OutputSandboxDestURI list must have the same cardinality as the OutputSandbox list");
            }

            /*
             * OUTPUTSANDBOX_DESTURI / OUTPUTSANDBOX_BASEDESTURI cross-check
             */
            if (job.getOutputSandboxBaseDestURI() != null && job.getOutputSandboxDestURI().size() > 0) {
                throw new Exception(JDL.OUTPUTSANDBOX_DESTURI + " & " + JDL.OUTPUTSANDBOX_BASEDESTURI + ": one (and only one) among the OutputSandboxDestURI and OutputSandboxBaseDestURI attributes is allowed");
            }
        }

        boolean isWholeNodes = jdl.isWholeNodes();
        job.addExtraAttribute(JDL.WHOLENODES, "" + isWholeNodes);

        int smpGranularity = jdl.getSMPGranularity();
        if (smpGranularity > 0) {
            job.addExtraAttribute(JDL.SMPGRANULARITY, "" + smpGranularity);
        }

        int hostNumber = jdl.getHostNumber();
        if (hostNumber > 0) {
            job.addExtraAttribute(JDL.HOSTNUMBER, "" + hostNumber);
        }

        if (!isWholeNodes && smpGranularity > 0 && hostNumber > 0) {
            throw new Exception("the SMPGranularity and HostNumber attributes cannot be specified together when WholeNodes=false");
        }

        if (jdl.isPerusalFileEnable()) {
            job.setPerusalTimeInterval(jdl.getPerusalTimeInterval());
            job.setPerusalFilesDestURI(jdl.getPerusalFilesDestURI().toString());
            job.setPerusalListFileURI(jdl.getPerusalListFileURI().toString());
        } else {
            job.setPerusalFilesDestURI(null);
        }

        String mwVersion = jdl.getMWVersion();
        if (mwVersion != null) {
            job.addExtraAttribute(JDL.MWVERSION, mwVersion);
        }

        String lbAddress = jdl.getLBAddress();
        if (lbAddress != null) {
            job.addVolatileProperty(Job.LB_ADDRESS, lbAddress);
        }

        String wmsHostname = jdl.getWMSHostName();
        if (wmsHostname != null) {
            job.addVolatileProperty(Job.WMS_HOSTNAME, wmsHostname);
        }

        String maxOutputSandboxSize = jdl.getMaxOutputSandboxSize();
        if (maxOutputSandboxSize != null) {
            job.addVolatileProperty(Job.MAX_OUTPUT_SANDBOX_SIZE, maxOutputSandboxSize);
        }

        ArrayList<OutputDataRecord> outputData = jdl.getOutputData();
        if (outputData != null) {
            job.addVolatileProperty(Job.OUTPUT_DATA, outputData);
        }

        return job;
    }
View Full Code Here

TOP

Related Classes of org.glite.ce.creamapi.jobmanagement.Job

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.