Search in sources :

Example 1 with RunningTaskQuartzImpl

use of com.evolveum.midpoint.task.quartzimpl.RunningTaskQuartzImpl in project midpoint by Evolveum.

the class ConcurrentExecutionChecker method check.

public void check(OperationResult result) throws ObjectNotFoundException, SchemaException, StopJobException {
    task.refresh(result);
    String executingAtNode = task.getNode();
    if (executingAtNode == null) {
        LOGGER.trace("Current node is null, we assume no concurrent execution");
        return;
    }
    LOGGER.debug("Task {} seems to be executing on node {}", task, executingAtNode);
    if (executingAtNode.equals(beans.configuration.getNodeId())) {
        RunningTaskQuartzImpl locallyRunningTask = beans.localNodeState.getLocallyRunningTaskByIdentifier(task.getTaskIdentifier());
        if (locallyRunningTask != null) {
            throw new StopJobException(ERROR, "Current task %s seems to be already running in thread %s on the" + " local node. We will NOT start it here.", null, task, locallyRunningTask.getExecutingThread());
        } else {
            LOGGER.warn("Current task {} seemed to be already running on the local node but it cannot be found" + " there now. Therefore we continue with the Quartz job execution.", task);
        }
    } else {
        ObjectQuery query = beans.prismContext.queryFor(NodeType.class).item(NodeType.F_NODE_IDENTIFIER).eq(executingAtNode).build();
        SearchResultList<PrismObject<NodeType>> nodes = beans.nodeRetriever.searchNodes(query, null, result);
        if (nodes.size() > 1) {
            throw new IllegalStateException("More than one node with identifier " + executingAtNode + ": " + nodes);
        } else if (nodes.size() == 1) {
            NodeType remoteNode = nodes.get(0).asObjectable();
            if (beans.clusterManager.isCheckingIn(remoteNode)) {
                // But let's keep things simple for the time being.
                throw new StopJobException(ERROR, "Current task %s seems to be already running at node %s that is alive or starting. " + "We will NOT start it here.", null, task, remoteNode.getNodeIdentifier());
            } else {
                LOGGER.warn("Current task {} seems to be already running at node {} but this node is not currently " + "checking in (last: {}). So we will start the task here.", task, remoteNode.getNodeIdentifier(), remoteNode.getLastCheckInTime());
            }
        } else {
            LOGGER.warn("Current task {} seems to be already running at node {} but this node cannot be found" + "in the repository. So we will start the task here.", task, executingAtNode);
        }
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) RunningTaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.RunningTaskQuartzImpl) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 RunningTaskQuartzImpl (com.evolveum.midpoint.task.quartzimpl.RunningTaskQuartzImpl)1 NodeType (com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)1