Package org.glite.ce.creamapi.jobmanagement

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


                    } catch (Throwable e) {
                        logger.error(e.getMessage());
                    }
                } catch (IllegalArgumentException e) {
                    logger.error(e);
                    throw new JobManagementException(e);
                } catch (DatabaseException e) {
                    logger.error(e.getMessage());
                    throw new JobManagementException("database error occurred");
                }
            }
        } else {
            if (lastStatus != null && (lastStatus.getType() == JobStatus.ABORTED || lastStatus.getType() == JobStatus.CANCELLED ||
                    lastStatus.getType() == JobStatus.DONE_OK || lastStatus.getType() == JobStatus.DONE_FAILED)) {
                return statusUpdated;
            }

            switch (status.getType()) {
            case JobStatus.ABORTED:
                setLeaseExpired(job);
                break;

            case JobStatus.CANCELLED:
                status.setDescription("Cancelled by CE admin");
                int cancelType = getCommandType(JobCommandConstant.JOB_CANCEL);

                for (int i = job.getCommandHistoryCount() - 1; i >= 0; i--) {
                    if (job.getCommandHistoryAt(i).getType() == cancelType) {
                        status.setDescription(job.getCommandHistoryAt(i).getDescription());
                        break;
                    }
                }
                setLeaseExpired(job);
                break;

            case JobStatus.DONE_OK:
            case JobStatus.DONE_FAILED:
                if (status.getType() == JobStatus.DONE_FAILED) {
                    int cancelledType = getCommandType(JobCommandConstant.JOB_CANCEL);

                    for (int i = job.getCommandHistoryCount() - 1; i >= 0; i--) {
                        if (job.getCommandHistoryAt(i).getType() == cancelledType) {                        
                            status.setType(JobStatus.CANCELLED);
                            status.setExitCode(null);
                            status.setDescription(job.getCommandHistoryAt(i).getDescription());
                            break;
                        }
                    }                 
                }
               
                if ("W".equalsIgnoreCase(status.getExitCode())) {
                    Calendar time = Calendar.getInstance();
                    time.add(Calendar.MINUTE, 1);
                    timer.schedule(new GetSTDTask(status.getJobId()), time.getTime());
                    timer.purge();
                }              

                setLeaseExpired(job);
                break;

            case JobStatus.REALLY_RUNNING:
                if (lastStatus != null && (lastStatus.getType() == JobStatus.ABORTED || lastStatus.getType() == JobStatus.CANCELLED ||
                        lastStatus.getType() == JobStatus.DONE_OK || lastStatus.getType() == JobStatus.DONE_FAILED)) {
                    return statusUpdated;
                }
                break;

            case JobStatus.RUNNING:
                if (status.getTimestamp().compareTo(lastStatus.getTimestamp()) <= 0) {
                    return statusUpdated;
                }

                if (lastStatus != null && (lastStatus.getType() == JobStatus.REALLY_RUNNING || lastStatus.getType() == JobStatus.ABORTED ||
                        lastStatus.getType() == JobStatus.CANCELLED || lastStatus.getType() == JobStatus.DONE_OK || lastStatus.getType() == JobStatus.DONE_FAILED)) {
                    return statusUpdated;
                }
                try {
                    List<JobStatus> statusList = jobDB.retrieveJobStatusHistory(status.getJobId(), null);

                    if (statusList != null && statusList.size() > 2) {
                        JobStatus oldStatus = statusList.get(statusList.size() - 2);
                        status.setType(oldStatus.getType() == JobStatus.REALLY_RUNNING ? JobStatus.REALLY_RUNNING : JobStatus.RUNNING);
                    }
                } catch (DatabaseException e) {
                    logger.error(e.getMessage());
                    throw new JobManagementException("database error occurred");
                }
                break;

            case JobStatus.HELD:
            case JobStatus.IDLE:
            case JobStatus.PENDING:
            case JobStatus.REGISTERED:
                if (lastStatus != null && (status.getTimestamp().compareTo(lastStatus.getTimestamp()) < 0)) {
                    logger.warn("the timestamp of the new status " + status.getName() + " for the JOB " + status.getJobId() + " is older than the last one");
                    return statusUpdated;
                }

                break;
            }

            try {
                job.addStatus(status);

                logger.debug("inserting new status " + status.getName() + " for the JOB " + status.getJobId());
                jobDB.insertStatus(status, null);

                statusUpdated = true;

                if (LBLogger.isEnabled()) {
                    try {
                        LBLogger.getInstance().statusChanged(job, status, null, LBLogger.START);
                    } catch (Exception e) {
                        logger.warn("LBLogger.statusChanged failed: " + e.getMessage());
                    }
                }

                StringBuffer logInfo = new StringBuffer("JOB ");
                logInfo.append(status.getJobId());

                if (lastStatus == null) {
                    logInfo.append(" STATUS CHANGED: -- => ").append(status.getName());
                } else {
                    logInfo.append(" STATUS CHANGED: ").append(lastStatus.getName()).append(" => ").append(status.getName());
                }

                if (!isEmptyField(status.getDescription())) {
                    logInfo.append(" [description=").append(status.getDescription()).append("]");
                }

                if (!isEmptyField(status.getFailureReason())) {
                    logInfo.append(" [failureReason=" + status.getFailureReason() + "]");
                }

                if (!isEmptyField(status.getExitCode())) {
                    logInfo.append(" [exitCode=").append(status.getExitCode()).append("]");
                }

                if (!isEmptyField(job.getLocalUser())) {
                    logInfo.append(" [localUser=" + job.getLocalUser() + "]");
                }

                if (!isEmptyField(job.getGridJobId())) {
                    logInfo.append(" [gridJobId=" + job.getGridJobId() + "]");
                }

                if (!isEmptyField(job.getLRMSJobId())) {
                    logInfo.append(" [lrmsJobId=").append(job.getLRMSJobId()).append("]");
                }

                if (!isEmptyField(job.getWorkerNode())) {
                    logInfo.append(" [workerNode=").append(job.getWorkerNode()).append("]");
                }

                if (!isEmptyField(job.getDelegationProxyId())) {
                    logInfo.append(" [delegationId=").append(job.getDelegationProxyId()).append("]");
                }

                logger.info(logInfo.toString());
            } catch (IllegalArgumentException e) {
                logger.error(e);
                throw new JobManagementException(e);
            } catch (DatabaseException e) {
                logger.error(e.getMessage());
                throw new JobManagementException("database error occurred");
            }

            try {
                sendNotification(job);
            } catch (Throwable e) {
View Full Code Here


     * @throws JobManagementException
     */
    private void initSocket(String sensorHost, String sensorPort) throws JobManagementException {
        if (socket == null) {
            if (sensorHost == null) {
                throw new JobManagementException("CREAM_JOB_SENSOR_HOST parameter not specified!");
            }

            if (sensorPort == null) {
                throw new JobManagementException("CREAM_JOB_SENSOR_PORT parameter not specified!");
            }

            logger.debug("initSocket: CREAM_JOB_SENSOR_HOST = " + sensorHost + " CREAM_JOB_SENSOR_PORT = " + sensorPort);
            // Create a socket object for communicating
            try {
                int sensorPortNumber = Integer.parseInt(sensorPort);
                socket = new Socket();
                socket.connect(new InetSocketAddress(sensorHost, sensorPortNumber), 500);
                oos = new ObjectOutputStream(socket.getOutputStream());
            } catch (Exception e) {
                throw new JobManagementException(e.getMessage());
            }
            logger.info("initSocket: created socket for host=" + sensorHost + ":" + sensorPort);
        }
    }
View Full Code Here

                    logger.error("sendNotification error: " + e.getMessage());
                    if (socket != null && !socket.isClosed()) {
                        try {
                            socket.close();
                        } catch (IOException e1) {
                            throw new JobManagementException(e1.getMessage());
                        }
                    }
                    socket = null;

                    if (oos != null) {
                        try {
                            oos.close();
                        } catch (IOException e1) {
                            throw new JobManagementException(e1.getMessage());
                        }
                    }
                } finally {
                    if(socket != null) {
                        socket.notifyAll();
                    }
                }
            }
        } else {
            logger.warn("sendNotification: the socket is NOT connected");
            if (socket != null && !socket.isClosed()) {
                try {
                    socket.close();
                } catch (IOException e) {
                    throw new JobManagementException(e.getMessage());
                }
            }
            socket = null;

            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e) {
                    throw new JobManagementException("socket is not connected");
                }
            }
        }
    }
View Full Code Here

        }
        try {
            job = db.retrieveJob((String)jobIdList.get(index), null);
        } catch (DatabaseException e) {
          logger.error("DatabaseException: " + e.getMessage());
            throw new JobManagementException(e.getMessage());
          
        }
        return job;
    }
View Full Code Here

       
        try {
          job = (Job) db.retrieveJob(jobId, null);
        } catch (IllegalArgumentException e) {
            logger.error("IllegalArgumentException: " + e.getMessage());
            throw new JobManagementException(e.getMessage());
        } catch (DatabaseException e) {
          logger.error("DatabaseException: " + e.getMessage());
            throw new JobManagementException(e.getMessage());
        }
       
        return job;
    }
View Full Code Here

TOP

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

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.