Search in sources :

Example 31 with Policy

use of org.ow2.proactive.scheduler.policy.Policy in project scheduling by ow2-proactive.

the class ListPolicyCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    Map<String, PluginView> knownPolicyMap = currentContext.getPolicies();
    if (knownPolicyMap == null) {
        HttpGet request = new HttpGet(currentContext.getResourceUrl("policies"));
        HttpResponseWrapper response = execute(request, currentContext);
        if (statusCode(OK) == statusCode(response)) {
            List<PluginView> pluginViewList = readValue(response, new TypeReference<List<PluginView>>() {
            }, currentContext);
            resultStack(currentContext).push(pluginViewList.toArray(new PluginView[pluginViewList.size()]));
            knownPolicyMap = new HashMap<>();
            for (PluginView pluginView : pluginViewList) {
                knownPolicyMap.put(pluginView.getPluginName(), pluginView);
            }
            currentContext.setPolicies(knownPolicyMap);
        } else {
            handleError("An error occurred while retrieving supported policy types:", response, currentContext);
        }
    }
    if (!currentContext.isSilent()) {
        if (knownPolicyMap != null) {
            writeLine(currentContext, "%n%s:%n", "Supported policy types");
            for (PluginView policy : knownPolicyMap.values()) {
                writeLine(currentContext, "%s%n", policy.toString());
            }
        }
    }
}
Also used : HttpResponseWrapper(org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper) HttpGet(org.apache.http.client.methods.HttpGet) PluginView(org.ow2.proactive_grid_cloud_portal.cli.json.PluginView) List(java.util.List)

Example 32 with Policy

use of org.ow2.proactive.scheduler.policy.Policy in project scheduling by ow2-proactive.

the class SchedulingMethodImpl method schedule.

/**
 * Scheduling process. For this implementation, steps are :<br>
 * <ul>
 * 	<li>Select running and pending jobs to be scheduled
 * 	<li>Get an ordered list of the selected tasks to be scheduled
 * 	<li>While returned tasks list is not empty :
 * 		<ul>
 * 			<li>Get n first compatible tasks (same selection script, same node exclusion)
 * 			<li>Ask nodes to RM according to the previous specification
 * 			<li>Try to start each tasks
 * 			<li>Job started event if needed
 * 			<li>Task started event
 * 		</ul>
 * 	<li>Manage exception while deploying tasks on nodes
 * </ul>
 *
 * @return the number of tasks that have been started
 */
public int schedule() {
    Policy currentPolicy = schedulingService.getPolicy();
    // Number of time to retry an active object creation before leaving scheduling loop
    activeObjectCreationRetryTimeNumber = ACTIVEOBJECT_CREATION_RETRY_TIME_NUMBER;
    // get job Descriptor list with eligible jobs (running and pending)
    Map<JobId, JobDescriptor> jobMap = schedulingService.lockJobsToSchedule();
    Map<JobId, JobDescriptor> toUnlock = jobMap;
    logSelectedJobs(jobMap);
    // we wait for next scheduling loop and don't start any task
    if (jobMap.isEmpty()) {
        return 0;
    }
    return startTasks(currentPolicy, jobMap, toUnlock);
}
Also used : Policy(org.ow2.proactive.scheduler.policy.Policy) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 33 with Policy

use of org.ow2.proactive.scheduler.policy.Policy in project scheduling by ow2-proactive.

the class SchedulerFrontend method getTasksToSchedule.

@Override
public List<TaskDescriptor> getTasksToSchedule() throws NotConnectedException, PermissionException {
    Policy policy = null;
    List<TaskDescriptor> eligibleTasks = new ArrayList<>();
    Map<JobId, JobDescriptor> jobMap = null;
    try {
        jobMap = schedulingService.lockJobsToSchedule();
        policy = (Policy) Class.forName(getCurrentPolicy()).newInstance();
        // we wait for next scheduling loop
        if (jobMap.isEmpty()) {
            return eligibleTasks;
        }
        List<JobDescriptor> descriptors = new ArrayList<>(jobMap.values());
        LinkedList<EligibleTaskDescriptor> taskRetrievedFromPolicy = policy.getOrderedTasks(descriptors);
        // if there is no task to scheduled, return
        if (taskRetrievedFromPolicy.isEmpty()) {
            return eligibleTasks;
        }
        eligibleTasks = (List) taskRetrievedFromPolicy;
    } catch (Exception e) {
        logger.error("Error Loading Current Policy:", e);
    } finally {
        schedulingService.unlockJobsToSchedule(jobMap.values());
    }
    return eligibleTasks;
}
Also used : Policy(org.ow2.proactive.scheduler.policy.Policy) ClientsPolicy(org.ow2.proactive.policy.ClientsPolicy) TaskDescriptor(org.ow2.proactive.scheduler.common.TaskDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) JobDescriptor(org.ow2.proactive.scheduler.common.JobDescriptor) EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) ArrayList(java.util.ArrayList) JobId(org.ow2.proactive.scheduler.common.job.JobId) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) TaskCouldNotRestartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotRestartException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AlreadyConnectedException(org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskCouldNotStartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotStartException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) TaskSkippedException(org.ow2.proactive.scheduler.common.exception.TaskSkippedException)

Example 34 with Policy

use of org.ow2.proactive.scheduler.policy.Policy in project scheduling by ow2-proactive.

the class SchedulerFrontend method initActivity.

/**
 * @see org.objectweb.proactive.InitActive#initActivity(org.objectweb.proactive.Body)
 */
@Override
public void initActivity(Body body) {
    try {
        // setting up the policy
        logger.debug("Setting up scheduler security policy");
        ClientsPolicy.init();
        // creating the scheduler authentication interface.
        // if this fails then it will not continue.
        logger.debug("Creating scheduler authentication interface...");
        authentication = PAActiveObject.newActive(SchedulerAuthentication.class, new Object[] { PAActiveObject.getStubOnThis() });
        // creating scheduler core
        DataSpaceServiceStarter dsServiceStarter = DataSpaceServiceStarter.getDataSpaceServiceStarter();
        dsServiceStarter.startNamingService();
        ExecutorService clientThreadPool = Executors.newFixedThreadPool(PASchedulerProperties.SCHEDULER_CLIENT_POOL_NBTHREAD.getValueAsInt(), new NamedThreadFactory("ClientRequestsThreadPool"));
        ExecutorService internalThreadPool = Executors.newFixedThreadPool(PASchedulerProperties.SCHEDULER_INTERNAL_POOL_NBTHREAD.getValueAsInt(), new NamedThreadFactory("InternalOperationsThreadPool"));
        ExecutorService taskPingerThreadPool = Executors.newFixedThreadPool(PASchedulerProperties.SCHEDULER_TASK_PINGER_POOL_NBTHREAD.getValueAsInt(), new NamedThreadFactory("TaskPingerThreadPool"));
        ScheduledExecutorService scheduledThreadPool = new ScheduledThreadPoolExecutor(PASchedulerProperties.SCHEDULER_SCHEDULED_POOL_NBTHREAD.getValueAsInt(), new NamedThreadFactory("SchedulingServiceTimerThread"));
        // at this point we must wait the resource manager
        RMConnection.waitAndJoin(rmURL.toString());
        RMProxiesManager rmProxiesManager = RMProxiesManager.createRMProxiesManager(rmURL);
        RMProxy rmProxy = rmProxiesManager.getRmProxy();
        long loadJobPeriod = -1;
        if (PASchedulerProperties.SCHEDULER_DB_LOAD_JOB_PERIOD.isSet()) {
            String periodStr = PASchedulerProperties.SCHEDULER_DB_LOAD_JOB_PERIOD.getValueAsString();
            if (periodStr != null && !periodStr.isEmpty()) {
                try {
                    loadJobPeriod = Tools.parsePeriod(periodStr);
                } catch (IllegalArgumentException e) {
                    logger.warn("Invalid load job period string: " + periodStr + ", this setting is ignored", e);
                }
            }
        }
        logger.debug("Booting jmx...");
        this.jmxHelper.boot(authentication);
        RecoveredSchedulerState recoveredState = new SchedulerStateRecoverHelper(dbManager).recover(loadJobPeriod, rmProxy);
        this.frontendState = new SchedulerFrontendState(recoveredState.getSchedulerState(), jmxHelper);
        SchedulingInfrastructure infrastructure = new SchedulingInfrastructureImpl(dbManager, rmProxiesManager, dsServiceStarter, clientThreadPool, internalThreadPool, taskPingerThreadPool, scheduledThreadPool);
        this.spacesSupport = infrastructure.getSpacesSupport();
        this.corePublicKey = Credentials.getPublicKey(PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PUBKEY_PATH.getValueAsString()));
        this.schedulingService = new SchedulingService(infrastructure, frontendState, recoveredState, policyFullName, null);
        recoveredState.enableLiveLogsForRunningTasks(schedulingService);
        releaseBusyNodesWithNoRunningTask(rmProxy, recoveredState);
        logger.debug("Registering scheduler...");
        PAActiveObject.registerByName(authentication, SchedulerConstants.SCHEDULER_DEFAULT_NAME);
        authentication.setActivated(true);
        Tools.logAvailableScriptEngines(logger);
        if (PASchedulerProperties.SCHEDULER_MEM_MONITORING_FREQ.isSet()) {
            logger.debug("Starting the memory monitoring process...");
            metricsMonitorScheduler = new it.sauronsoftware.cron4j.Scheduler();
            String cronExpr = PASchedulerProperties.SCHEDULER_MEM_MONITORING_FREQ.getValueAsString();
            metricsMonitorScheduler.schedule(cronExpr, new TableSizeMonitorRunner(dbManager.getTransactionHelper()));
            metricsMonitorScheduler.schedule(cronExpr, new JobsMemoryMonitorRunner(dbManager.getSessionFactory().getStatistics(), recoveredState.getSchedulerState()));
            metricsMonitorScheduler.start();
        }
    } catch (Exception e) {
        logger.error("Failed to start Scheduler", e);
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NamedThreadFactory(org.objectweb.proactive.utils.NamedThreadFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SchedulerAuthentication(org.ow2.proactive.scheduler.authentication.SchedulerAuthentication) KeyException(java.security.KeyException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) TaskCouldNotRestartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotRestartException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AlreadyConnectedException(org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) TaskCouldNotStartException(org.ow2.proactive.scheduler.common.exception.TaskCouldNotStartException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) DatabaseManagerException(org.ow2.proactive.db.DatabaseManagerException) TaskSkippedException(org.ow2.proactive.scheduler.common.exception.TaskSkippedException) RecoveredSchedulerState(org.ow2.proactive.scheduler.core.db.RecoveredSchedulerState) RMProxy(org.ow2.proactive.scheduler.core.rmproxies.RMProxy) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) TableSizeMonitorRunner(org.ow2.proactive.scheduler.core.helpers.TableSizeMonitorRunner) ActiveObject(org.objectweb.proactive.extensions.annotation.ActiveObject) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) JobsMemoryMonitorRunner(org.ow2.proactive.scheduler.core.helpers.JobsMemoryMonitorRunner) RMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.RMProxiesManager)

Aggregations

Node (org.objectweb.proactive.core.node.Node)7 Test (org.junit.Test)6 NodeSet (org.ow2.proactive.utils.NodeSet)5 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)4 KeyException (java.security.KeyException)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)4 RMState (org.ow2.proactive.resourcemanager.common.RMState)4 RMException (org.ow2.proactive.resourcemanager.exception.RMException)4 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)4 HttpResponseWrapper (org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)3 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)2 File (java.io.File)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 LoginException (javax.security.auth.login.LoginException)2 UniqueID (org.objectweb.proactive.core.UniqueID)2