Search in sources :

Example 1 with SchedulingService

use of org.ow2.proactive.scheduler.core.SchedulingService in project scheduling by ow2-proactive.

the class SchedulingMethodImpl method updateVariablesForTasksToSchedule.

/**
 * Update all variables for the given scheduled tasks
 */
private void updateVariablesForTasksToSchedule(LinkedList<EligibleTaskDescriptor> tasksToSchedule) {
    for (EligibleTaskDescriptor taskDescriptor : tasksToSchedule) {
        InternalTask internalTask = ((EligibleTaskDescriptorImpl) taskDescriptor).getInternal();
        internalTask.updateVariables(schedulingService);
    }
}
Also used : EligibleTaskDescriptor(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptor) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) EligibleTaskDescriptorImpl(org.ow2.proactive.scheduler.descriptor.EligibleTaskDescriptorImpl)

Example 2 with SchedulingService

use of org.ow2.proactive.scheduler.core.SchedulingService in project scheduling by ow2-proactive.

the class SchedulingMethodImpl method createExecution.

/**
 * Create launcher and try to start the task.
 *
 * @param nodeSet the node set containing every available nodes that can be used for execution
 * @param node the node on which to start the task
 * @param job the job that owns the task to be started
 * @param task the task to be started
 * @param taskDescriptor the descriptor of the task to be started
 */
protected boolean createExecution(NodeSet nodeSet, Node node, InternalJob job, InternalTask task, TaskDescriptor taskDescriptor) throws Exception {
    TaskLauncher launcher = null;
    LiveJobs.JobData jobData = null;
    try {
        jobData = schedulingService.lockJob(job.getId());
        // task is not paused
        if (nodeSet.size() >= task.getNumberOfNodesNeeded() && (task.getStatus() != TaskStatus.PAUSED) && (jobData != null)) {
            // start dataspace app for this job
            DataSpaceServiceStarter dsStarter = schedulingService.getInfrastructure().getDataSpaceServiceStarter();
            job.startDataSpaceApplication(dsStarter.getNamingService(), ImmutableList.of(task));
            NodeSet nodes = new NodeSet();
            try {
                // create launcher
                launcher = task.createLauncher(node);
                activeObjectCreationRetryTimeNumber = ACTIVEOBJECT_CREATION_RETRY_TIME_NUMBER;
                nodeSet.remove(0);
                // we will need to update this code once topology will be allowed for single-node task
                if (task.isParallel()) {
                    nodes = new NodeSet(nodeSet);
                    task.getExecuterInformation().addNodes(nodes);
                    nodeSet.clear();
                }
                // set nodes in the executable container
                task.getExecutableContainer().setNodes(nodes);
                tlogger.debug(task.getId(), "deploying");
                // above 500 parent tasks, it is worth adjusting.
                if (taskDescriptor.getParents().size() > 500) {
                    dotaskActionTimeout = (int) (taskDescriptor.getParents().size() / 500.0 * PASchedulerProperties.SCHEDULER_STARTTASK_TIMEOUT.getValueAsInt());
                } else {
                    // reset the dotaskActionTimeout to its default value otherwise.
                    dotaskActionTimeout = PASchedulerProperties.SCHEDULER_STARTTASK_TIMEOUT.getValueAsInt();
                }
                boolean taskRecoverable = getRMProxiesManager().getRmProxy().areNodesRecoverable(nodes);
                String terminateNotificationNodeURL = PAActiveObject.getActiveObjectNode(terminateNotification).getNodeInformation().getURL();
                TaskRecoveryData taskRecoveryData = new TaskRecoveryData(terminateNotificationNodeURL, taskRecoverable);
                threadPool.submitWithTimeout(new TimedDoTaskAction(job, taskDescriptor, launcher, schedulingService, terminateNotification, corePrivateKey, taskRecoveryData), dotaskActionTimeout, TimeUnit.MILLISECONDS);
                // we advertise here that the task is started, however
                // this is not entirely true: the only thing we are sure
                // about at this point is that we submitted to the thread
                // pool the action that will call the "doTask" of the task
                // launcher. There is thus a small gap here where the task
                // is seen as started whereas it is not yet started. We
                // cannot easily move the task started notification because
                // 1) it makes the job lock acquisition less predictable
                // (because the TimeDoTaskAction will have to compete with
                // the SchedulingMethodImpl)
                // and more importantly 2) the
                // SchedulingMethodImpl#createExecution may happen to be
                // called a second time for the task that is currently being
                // started by the TimedDoTaskAction.
                finalizeStarting(job, task, node, launcher);
                return true;
            } catch (Exception t) {
                try {
                    // if there was a problem, free nodeSet for multi-nodes task
                    nodes.add(node);
                    releaseNodes(job, nodes);
                } catch (Throwable ni) {
                // miam miam
                }
                throw t;
            }
        } else {
            return false;
        }
    } finally {
        if (jobData != null) {
            jobData.unlock();
        }
    }
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) TopologyDisabledException(org.ow2.proactive.resourcemanager.frontend.topology.TopologyDisabledException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) RMProxyCreationException(org.ow2.proactive.scheduler.core.rmproxies.RMProxyCreationException) IOException(java.io.IOException) TaskRecoveryData(org.ow2.proactive.scheduler.task.internal.TaskRecoveryData)

Example 3 with SchedulingService

use of org.ow2.proactive.scheduler.core.SchedulingService in project scheduling by ow2-proactive.

the class TerminationData method terminateRunningTask.

private void terminateRunningTask(SchedulingService service, TaskTerminationData taskToTerminate, RunningTaskData taskData) {
    Map<String, String> genericInformation = new HashMap<>();
    VariablesMap variables = null;
    if (taskToTerminate.internalJob != null) {
        genericInformation = taskData.getTask().getRuntimeGenericInformation();
    }
    try {
        variables = getStringSerializableMap(service, taskToTerminate);
    } catch (Exception e) {
        logger.error("Exception occurred, fail to get variables into the cleaning script: ", e);
    }
    try {
        if (taskToTerminate.terminationStatus == ABORTED) {
            taskData.getLauncher().kill();
        }
    } catch (Throwable t) {
        logger.info("Cannot terminate task launcher for task '" + taskData.getTask().getId() + "'", t);
        try {
            logger.info("Task launcher that cannot be terminated is identified by " + taskData.getLauncher().toString());
        } catch (Throwable ignore) {
            logger.info("Getting information about Task launcher failed (remote object not accessible?)");
        }
    }
    try {
        logger.debug("Releasing nodes for task '" + taskData.getTask().getId() + "'");
        RMProxiesManager proxiesManager = service.getInfrastructure().getRMProxiesManager();
        proxiesManager.getUserRMProxy(taskData.getUser(), taskData.getCredentials()).releaseNodes(taskData.getNodes(), taskToTerminate.terminationStatus != NODEFAILED ? taskData.getTask().getCleaningScript() : null, variables, genericInformation, taskToTerminate.taskData.getTask().getId(), service.addThirdPartyCredentials(taskData.getCredentials()));
    } catch (Throwable t) {
        logger.info("Failed to release nodes for task '" + taskData.getTask().getId() + "'", t);
    }
}
Also used : HashMap(java.util.HashMap) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) IOException(java.io.IOException) RMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.RMProxiesManager)

Example 4 with SchedulingService

use of org.ow2.proactive.scheduler.core.SchedulingService in project scheduling by ow2-proactive.

the class TerminationData method getStringSerializableMap.

public VariablesMap getStringSerializableMap(SchedulingService service, TaskTerminationData taskToTerminate) throws Exception {
    VariablesMap variablesMap = new VariablesMap();
    RunningTaskData taskData = taskToTerminate.taskData;
    TaskResultImpl taskResult = taskToTerminate.taskResult;
    InternalJob internalJob = taskToTerminate.internalJob;
    if (taskToTerminate.terminationStatus == ABORTED || taskResult == null) {
        List<InternalTask> iDependences = taskData.getTask().getIDependences();
        if (iDependences != null) {
            Set<TaskId> parentIds = new HashSet<>(iDependences.size());
            for (InternalTask parentTask : iDependences) {
                parentIds.addAll(InternalTaskParentFinder.getInstance().getFirstNotSkippedParentTaskIds(parentTask));
            }
            // Batch fetching of parent tasks results
            Map<TaskId, TaskResult> taskResults = new HashMap<>();
            for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds), PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
                taskResults.putAll(service.getInfrastructure().getDBManager().loadTasksResults(taskData.getTask().getJobId(), parentsSubList));
            }
            getResultsFromListOfTaskResults(variablesMap.getInheritedMap(), taskResults);
        } else {
            if (internalJob != null) {
                for (Map.Entry<String, JobVariable> jobVariableEntry : internalJob.getVariables().entrySet()) {
                    variablesMap.getInheritedMap().put(jobVariableEntry.getKey(), jobVariableEntry.getValue().getValue());
                }
            }
        }
        variablesMap.getInheritedMap().put(SchedulerVars.PA_TASK_SUCCESS.toString(), Boolean.toString(false));
    } else if (taskResult.hadException()) {
        variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, false));
    } else {
        variablesMap.setInheritedMap(fillMapWithTaskResult(taskResult, true));
    }
    variablesMap.setScopeMap(getNonInheritedScopeVariables(variablesMap.getInheritedMap(), taskData.getTask().getScopeVariables(), taskData.getTask().getVariables()));
    return variablesMap;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) HashMap(java.util.HashMap) Map(java.util.Map) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) HashSet(java.util.HashSet)

Example 5 with SchedulingService

use of org.ow2.proactive.scheduler.core.SchedulingService in project scheduling by ow2-proactive.

the class BaseServiceTest method init.

@Before
public void init() throws Exception {
    dbManager = SchedulerDBManager.createInMemorySchedulerDBManager();
    infrastructure = new MockSchedulingInfrastructure(dbManager);
    listener = new MockSchedulingListener();
    service = new SchedulingService(infrastructure, listener, null, DefaultPolicy.class.getName(), Mockito.mock(SchedulingMethod.class));
}
Also used : SchedulingService(org.ow2.proactive.scheduler.core.SchedulingService) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 SchedulingService (org.ow2.proactive.scheduler.core.SchedulingService)2 RMProxiesManager (org.ow2.proactive.scheduler.core.rmproxies.RMProxiesManager)2 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)2 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)2 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)2 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)2 KeyException (java.security.KeyException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 Test (org.junit.Test)1 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)1 PAActiveObject (org.objectweb.proactive.api.PAActiveObject)1