Search in sources :

Example 61 with NotConnectedException

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

the class SchedulerFrontendState method getJobState.

synchronized JobState getJobState(JobId jobId) throws NotConnectedException, UnknownJobException, PermissionException {
    checkPermissions("getJobState", getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_STATE_OF_THIS_JOB);
    ClientJobState jobState = jobsMap.get(jobId);
    ClientJobState jobStateCopy;
    synchronized (jobState) {
        try {
            jobStateCopy = (ClientJobState) ProActiveMakeDeepCopy.WithProActiveObjectStream.makeDeepCopy(jobState);
        } catch (Exception e) {
            logger.error("Error when copying job state", e);
            throw new IllegalStateException(e);
        }
    }
    return jobStateCopy;
}
Also used : ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) 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) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException)

Example 62 with NotConnectedException

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

the class SchedulerFrontendState method jobSubmitted.

synchronized void jobSubmitted(InternalJob job, UserIdentificationImpl ident) throws NotConnectedException, PermissionException, SubmissionClosedException, JobCreationException {
    // put the job inside the frontend management list
    jobs.put(job.getId(), new IdentifiedJob(job.getId(), ident, job.getGenericInformation()));
    // increase number of submit for this user
    ident.addSubmit();
    // send update user event
    usersUpdated(new NotificationData<UserIdentification>(SchedulerEvent.USERS_UPDATE, ident));
    jlogger.info(job.getId(), "submitted: name '" + job.getName() + "', tasks '" + job.getTotalNumberOfTasks() + "', owner '" + job.getOwner() + "'");
    try {
        jlogger.info(job.getId(), job.display());
    } catch (Exception e) {
        jlogger.error(job.getId(), "Error while displaying the job :", e);
    }
}
Also used : IdentifiedJob(org.ow2.proactive.scheduler.job.IdentifiedJob) UserIdentification(org.ow2.proactive.scheduler.common.job.UserIdentification) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) 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) IOException(java.io.IOException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException)

Example 63 with NotConnectedException

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

the class SelectionManager method doSelectNodes.

private NodeSet doSelectNodes(Criteria criteria, Client client) {
    boolean hasScripts = criteria.getScripts() != null && criteria.getScripts().size() > 0;
    boolean loggerIsDebugEnabled = logger.isDebugEnabled();
    if (loggerIsDebugEnabled) {
        logger.debug(client + " requested " + criteria.getSize() + " nodes with " + criteria.getTopology());
        if (hasScripts) {
            logger.debug("Selection scripts:");
            for (SelectionScript s : criteria.getScripts()) {
                logger.debug(s);
            }
        }
        if (criteria.getBlackList() != null && criteria.getBlackList().size() > 0) {
            logger.debug("Black list nodes:");
            for (Node n : criteria.getBlackList()) {
                logger.debug(n);
            }
        }
    }
    // can throw Exception if topology is disabled
    TopologyHandler handler = RMCore.topologyManager.getHandler(criteria.getTopology());
    int totalNumberOfAliveNodesRightNow = rmcore.getTotalAliveNodesNumber();
    List<RMNode> freeNodes = rmcore.getFreeNodes();
    // filtering out the "free node list"
    // removing exclusion and checking permissions
    List<RMNode> filteredNodes = filterOut(freeNodes, criteria, client);
    if (filteredNodes.size() == 0) {
        if (loggerIsDebugEnabled) {
            logger.debug(client + " will get 0 nodes");
        }
        return new NodeSet();
    }
    // arranging nodes according to the selection policy
    // if could be shuffling or node source priorities
    List<RMNode> afterPolicyNodes = selectionPolicy.arrangeNodes(criteria.getSize(), filteredNodes, client);
    List<Node> matchedNodes;
    if (hasScripts) {
        // checking if all scripts are authorized
        checkAuthorizedScripts(criteria.getScripts());
        // arranging nodes for script execution
        List<RMNode> arrangedNodes = arrangeNodesForScriptExecution(afterPolicyNodes, criteria.getScripts(), criteria.getBindings());
        List<RMNode> arrangedFilteredNodes = arrangedNodes;
        if (criteria.getTopology().isTopologyBased()) {
            arrangedFilteredNodes = topologyNodesFilter.filterNodes(criteria, arrangedNodes);
        }
        if (arrangedFilteredNodes.isEmpty()) {
            matchedNodes = new LinkedList<>();
        } else if (electedToRunOnAllNodes(criteria)) {
            // run scripts on all available nodes
            matchedNodes = runScripts(arrangedFilteredNodes, criteria);
        } else {
            // run scripts not on all nodes, but always on missing number of
            // nodes
            // until required node set is found
            matchedNodes = new LinkedList<>();
            while (matchedNodes.size() < criteria.getSize()) {
                int numberOfNodesForScriptExecution = criteria.getSize() - matchedNodes.size();
                if (numberOfNodesForScriptExecution < PAResourceManagerProperties.RM_SELECTION_MAX_THREAD_NUMBER.getValueAsInt()) {
                    // we can run
                    // "PAResourceManagerProperties.RM_SELECTION_MAX_THREAD_NUMBER.getValueAsInt()"
                    // scripts in parallel
                    // in case when we need less nodes it still useful to
                    // the full capacity of the thread pool to find nodes
                    // quicker
                    // it is not important if we find more nodes than needed
                    // subset will be selected later (topology handlers)
                    numberOfNodesForScriptExecution = PAResourceManagerProperties.RM_SELECTION_MAX_THREAD_NUMBER.getValueAsInt();
                }
                List<RMNode> subset = arrangedFilteredNodes.subList(0, Math.min(numberOfNodesForScriptExecution, arrangedFilteredNodes.size()));
                matchedNodes.addAll(runScripts(subset, criteria));
                // removing subset of arrangedNodes
                subset.clear();
                if (arrangedFilteredNodes.size() == 0) {
                    break;
                }
            }
            if (loggerIsDebugEnabled) {
                logger.debug(matchedNodes.size() + " nodes found after scripts execution for " + client);
            }
        }
    } else {
        matchedNodes = new LinkedList<>();
        for (RMNode node : afterPolicyNodes) {
            matchedNodes.add(node.getNode());
        }
    }
    if (criteria.getTopology().isTopologyBased() && loggerIsDebugEnabled) {
        logger.debug("Filtering nodes with topology " + criteria.getTopology());
    }
    NodeSet selectedNodes = handler.select(criteria.getSize(), matchedNodes);
    if (selectedNodes.size() < criteria.getSize() && !criteria.isBestEffort()) {
        selectedNodes.clear();
        if (selectedNodes.getExtraNodes() != null) {
            selectedNodes.getExtraNodes().clear();
        }
    }
    // the nodes are selected, now mark them as busy.
    for (Node node : selectedNodes) {
        try {
            // Synchronous call
            rmcore.setBusyNode(node.getNodeInformation().getURL(), client);
        } catch (NotConnectedException e) {
            // client has disconnected during getNodes request
            logger.warn(e.getMessage(), e);
            return null;
        }
    }
    // marking extra selected nodes as busy
    if (selectedNodes.size() > 0 && selectedNodes.getExtraNodes() != null) {
        for (Node node : new LinkedList<>(selectedNodes.getExtraNodes())) {
            try {
                // synchronous call
                rmcore.setBusyNode(node.getNodeInformation().getURL(), client);
            } catch (NotConnectedException e) {
                // client has disconnected during getNodes request
                logger.warn(e.getMessage(), e);
                return null;
            }
        }
    }
    if (logger.isInfoEnabled()) {
        String extraNodes = selectedNodes.getExtraNodes() != null && selectedNodes.getExtraNodes().size() > 0 ? " and " + selectedNodes.getExtraNodes().size() + " extra nodes" : "";
        logger.info(client + " requested " + criteria.getSize() + " nodes with " + criteria.getTopology() + " and will get " + selectedNodes.size() + " nodes " + extraNodes + " [totalNumberOfAliveNodesRightNow:" + totalNumberOfAliveNodesRightNow + ";freeNodes:" + freeNodes.size() + ";filteredNodes:" + filteredNodes.size() + ";reordered after policy:" + afterPolicyNodes.size() + ";selection script present:" + hasScripts + ";nodes filtered by selection script:" + matchedNodes.size() + ";selectedNodes:" + selectedNodes.size() + "]");
    }
    if (loggerIsDebugEnabled) {
        for (Node n : selectedNodes) {
            logger.debug(n.getNodeInformation().getURL());
        }
    }
    return selectedNodes;
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Node(org.objectweb.proactive.core.node.Node) TopologyHandler(org.ow2.proactive.resourcemanager.selection.topology.TopologyHandler) LinkedList(java.util.LinkedList) SelectionScript(org.ow2.proactive.scripting.SelectionScript) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 64 with NotConnectedException

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

the class SchedulerStateRest method taskResultByTag.

/**
 * Returns the task results of the set of task filtered by a given tag and
 * owned by the job <code>jobId</code>
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskTag
 *            the tag used to filter the tasks.
 * @return the task results of the set of tasks filtered by the given tag.
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/tag/{tasktag}/result")
@Produces("application/json")
public List<TaskResultData> taskResultByTag(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("tasktag") String taskTag) throws NotConnectedRestException, UnknownJobRestException, PermissionRestException {
    try {
        Scheduler s = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskTag + "/result");
        List<TaskResult> taskResults = s.getTaskResultsByTag(jobId, taskTag);
        ArrayList<TaskResultData> results = new ArrayList<TaskResultData>(taskResults.size());
        for (TaskResult current : taskResults) {
            TaskResultData r = buildTaskResultData(PAFuture.getFutureValue(current));
            results.add(r);
        }
        return results;
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskResultData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData) ArrayList(java.util.ArrayList) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 65 with NotConnectedException

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

the class SchedulerStateRest method taskFullLogs.

/**
 * Returns full logs generated by the task from user data spaces if task was
 * run using the precious logs option. Otherwise, logs are retrieved from
 * the database. In this last case they may be truncated.
 *
 * @param sessionId
 *            a valid session id
 * @param jobId
 *            the id of the job
 * @param taskname
 *            the name of the task
 * @return all the logs generated by the task (either stdout and stderr) or
 *         an empty string if the result is not yet available
 */
@Override
@GET
@GZIP
@Path("jobs/{jobid}/tasks/{taskname}/result/log/full")
@Produces("application/json")
public InputStream taskFullLogs(@HeaderParam("sessionid") String sessionId, @PathParam("jobid") String jobId, @PathParam("taskname") String taskname, @QueryParam("sessionid") String session) throws NotConnectedRestException, UnknownJobRestException, UnknownTaskRestException, PermissionRestException, IOException {
    try {
        if (sessionId == null) {
            sessionId = session;
        }
        Scheduler scheduler = checkAccess(sessionId, "jobs/" + jobId + "/tasks/" + taskname + "/result/log/all");
        TaskResult taskResult = scheduler.getTaskResult(jobId, taskname);
        if (taskResult != null) {
            JobState jobState = scheduler.getJobState(taskResult.getTaskId().getJobId());
            boolean hasPreciousLogs = false;
            for (Task task : jobState.getTasks()) {
                if (task.getName().equals(taskname)) {
                    hasPreciousLogs = task.isPreciousLogs();
                    break;
                }
            }
            if (hasPreciousLogs) {
                return retrieveTaskLogsUsingDataspaces(sessionId, jobId, taskResult.getTaskId());
            } else {
                logger.warn("Retrieving truncated logs for task '" + taskname + "'");
                return IOUtils.toInputStream(retrieveTaskLogsUsingDatabase(sessionId, jobId, taskname));
            }
        } else {
            return null;
        }
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    } catch (UnknownJobException e) {
        throw new UnknownJobRestException(e);
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (UnknownTaskException e) {
        throw new UnknownTaskRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) Task(org.ow2.proactive.scheduler.common.task.Task) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) UnknownJobRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) UnknownTaskRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownTaskRestException) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobState(org.ow2.proactive.scheduler.common.job.JobState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Aggregations

NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)68 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)64 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)51 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)48 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)46 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)40 Path (javax.ws.rs.Path)39 Produces (javax.ws.rs.Produces)37 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)36 GET (javax.ws.rs.GET)28 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)27 JobState (org.ow2.proactive.scheduler.common.job.JobState)21 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)19 GZIP (org.jboss.resteasy.annotations.GZIP)18 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)18 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)17 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)16 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)16