Search in sources :

Example 1 with InternalException

use of org.ow2.proactive.scheduler.common.exception.InternalException in project scheduling by ow2-proactive.

the class SchedulingService method changePolicy.

public boolean changePolicy(String newPolicyClassName) {
    try {
        if (status.isShuttingDown()) {
            logger.warn("Policy can only be changed when Scheduler is up, current state : " + status);
            return false;
        }
        // TODO class loading ? (for now, class must be in scheduler classpath or addons)
        Policy newPolicy = (Policy) Class.forName(newPolicyClassName).newInstance();
        // newPolicy.setCore(this);
        if (!newPolicy.reloadConfig()) {
            return false;
        }
        // if success, change current policy
        policy = newPolicy;
        listener.schedulerStateUpdated(SchedulerEvent.POLICY_CHANGED);
        logger.info("Policy changed ! new policy name : " + newPolicyClassName);
        return true;
    } catch (InstantiationException e) {
        logger.error("", e);
        throw new InternalException("Exception occurs while instanciating the policy !", e);
    } catch (IllegalAccessException e) {
        logger.error("", e);
        throw new InternalException("Exception occurs while accessing the policy !", e);
    } catch (ClassNotFoundException e) {
        logger.error("", e);
        throw new InternalException("Exception occurs while loading the policy class !", e);
    }
}
Also used : Policy(org.ow2.proactive.scheduler.policy.Policy) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 2 with InternalException

use of org.ow2.proactive.scheduler.common.exception.InternalException in project scheduling by ow2-proactive.

the class InternalJobFactory method createJob.

/**
 * Create a new internal job with the given job (user).
 *
 * @param job the user job that will be used to create the internal job.
 * @return the created internal job.
 * @throws JobCreationException an exception if the factory cannot create the given job.
 */
public static InternalJob createJob(Job job, Credentials cred) throws JobCreationException {
    InternalJob iJob;
    if (logger.isDebugEnabled()) {
        logger.debug("Create job '" + job.getName() + "' - " + job.getClass().getName());
    }
    switch(job.getType()) {
        case PARAMETER_SWEEPING:
            logger.error("The type of the given job is not yet implemented !");
            throw new JobCreationException("The type of the given job is not yet implemented !");
        case TASKSFLOW:
            iJob = createJob((TaskFlowJob) job);
            break;
        default:
            logger.error("The type of the given job is unknown !");
            throw new JobCreationException("The type of the given job is unknown !");
    }
    try {
        // set the job common properties
        iJob.setCredentials(cred);
        setJobCommonProperties(job, iJob);
        return iJob;
    } catch (Exception e) {
        logger.error("", e);
        throw new InternalException("Error while creating the internalJob !", e);
    }
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 3 with InternalException

use of org.ow2.proactive.scheduler.common.exception.InternalException in project scheduling by ow2-proactive.

the class EnabledListenJobLogsSupport method listenJobLogs.

@Override
public synchronized void listenJobLogs(JobId jobId, AppenderProvider appenderProvider) throws UnknownJobException {
    jlogger.info(jobId, "listening logs");
    // create the appender to the remote listener
    Appender clientAppender = null;
    try {
        clientAppender = appenderProvider.getAppender();
    } catch (LogForwardingException e) {
        jlogger.error(jobId, "cannot create an appender", e);
        throw new InternalException("Cannot create an appender for job " + jobId, e);
    }
    boolean logIsAlreadyInitialized = jobsToBeLogged.contains(jobId);
    initJobLogging(jobId, clientAppender);
    JobResult result = dbManager.loadJobResult(jobId);
    if (result == null) {
        throw new UnknownJobException(jobId);
    }
    // for finished tasks, add logs events "manually"
    Collection<TaskResult> allRes = result.getAllResults().values();
    for (TaskResult tr : allRes) {
        this.flushTaskLogs(tr, clientAppender, jobId);
    }
    for (RunningTaskData taskData : liveJobs.getRunningTasks(jobId)) {
        jlogger.debug(jobId, "Handling log initialization for task " + taskData.getTask().getName());
        try {
            TaskLauncher taskLauncher = taskData.getLauncher();
            if (logIsAlreadyInitialized) {
                jlogger.debug(jobId, "Call getStoredLogs");
                taskLauncher.getStoredLogs(appenderProvider);
            } else {
                jlogger.debug(jobId, "Call activateLogs");
                taskLauncher.activateLogs(lfs.getAppenderProvider());
            }
        } catch (Exception e) {
            tlogger.error(taskData.getTask().getId(), "cannot create an appender provider", e);
        }
    }
    if (!result.getJobInfo().getStatus().isJobAlive()) {
        jlogger.info(jobId, "cleaning loggers for already finished job");
        cleanLoggers(jobId);
    }
}
Also used : Appender(org.apache.log4j.Appender) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) LogForwardingException(org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 4 with InternalException

use of org.ow2.proactive.scheduler.common.exception.InternalException in project scheduling by ow2-proactive.

the class SchedulingService method linkResourceManager.

public boolean linkResourceManager(String rmURL) {
    try {
        // re-link the RM
        getInfrastructure().getRMProxiesManager().rebindRMProxiesManager(new URI(rmURL.trim()));
        logger.info("New resource manager has been linked to the scheduler");
        if (status == SchedulerStatus.UNLINKED) {
            logger.info("Resume to continue the scheduling.");
            listener.schedulerStateUpdated(SchedulerEvent.RM_UP);
            // restart the scheduler
            status = SchedulerStatus.STARTED;
            listener.schedulerStateUpdated(SchedulerEvent.STARTED);
        }
        return true;
    } catch (Exception e) {
        throw new InternalException("Error while connecting the new Resource Manager !", e);
    }
}
Also used : URI(java.net.URI) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) ExecutionException(java.util.concurrent.ExecutionException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Aggregations

InternalException (org.ow2.proactive.scheduler.common.exception.InternalException)4 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)2 URI (java.net.URI)1 KeyException (java.security.KeyException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Appender (org.apache.log4j.Appender)1 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)1 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)1 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)1 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)1 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)1 LogForwardingException (org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException)1 Policy (org.ow2.proactive.scheduler.policy.Policy)1 TaskLauncher (org.ow2.proactive.scheduler.task.TaskLauncher)1 InvalidScriptException (org.ow2.proactive.scripting.InvalidScriptException)1