Search in sources :

Example 6 with ClusterStatusInformation

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

the class TaskManagerQuartzImpl method getTaskAsObject.

private PrismObject<TaskType> getTaskAsObject(String oid, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException, ObjectNotFoundException {
    // returns null if noFetch is set
    ClusterStatusInformation clusterStatusInformation = getClusterStatusInformation(options, TaskType.class, true, result);
    Task task = getTask(oid, result);
    addTransientTaskInformation(task.getTaskPrismObject(), clusterStatusInformation, SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NEXT_RUN_START_TIMESTAMP), options), SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NEXT_RETRY_TIMESTAMP), options), SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NODE_AS_OBSERVED), options), result);
    if (SelectorOptions.hasToLoadPath(TaskType.F_SUBTASK, options)) {
        fillInSubtasks(task, clusterStatusInformation, options, result);
    }
    fillOperationExecutionState(task);
    return task.getTaskPrismObject();
}
Also used : ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with ClusterStatusInformation

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

the class ExecutionManager method addNodeAndTaskInformation.

private void addNodeAndTaskInformation(ClusterStatusInformation info, PrismObject<NodeType> node, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(ExecutionManager.class.getName() + ".addNodeAndTaskInformation");
    result.addParam("node", node);
    if (isCurrentNode(node)) {
        LOGGER.trace("Getting node and task info from the current node ({})", node.asObjectable().getNodeIdentifier());
        List<ClusterStatusInformation.TaskInfo> taskInfoList = new ArrayList<>();
        Set<Task> tasks = localNodeManager.getLocallyRunningTasks(result);
        for (Task task : tasks) {
            taskInfoList.add(new ClusterStatusInformation.TaskInfo(task.getOid()));
        }
        node.asObjectable().setExecutionStatus(localNodeManager.getLocalNodeExecutionStatus());
        node.asObjectable().setErrorStatus(taskManager.getLocalNodeErrorStatus());
        info.addNodeAndTaskInfo(node.asObjectable(), taskInfoList);
    } else {
        // if remote
        LOGGER.debug("Getting running task info from remote node ({}, {})", node.asObjectable().getNodeIdentifier(), node.asObjectable().getHostname());
        remoteNodesManager.addNodeStatusFromRemoteNode(info, node, result);
    }
    result.recordSuccessIfUnknown();
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation)

Example 8 with ClusterStatusInformation

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

the class TaskManagerQuartzImpl method searchTasks.

public SearchResultList<PrismObject<TaskType>> searchTasks(ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    // returns null if noFetch is set
    ClusterStatusInformation clusterStatusInformation = getClusterStatusInformation(options, TaskType.class, true, result);
    List<PrismObject<TaskType>> tasksInRepository;
    try {
        tasksInRepository = repositoryService.searchObjects(TaskType.class, query, options, result);
    } catch (SchemaException e) {
        result.recordFatalError("Couldn't get tasks from repository: " + e.getMessage(), e);
        throw e;
    }
    boolean retrieveNextRunStartTime = SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NEXT_RUN_START_TIMESTAMP), options);
    boolean retrieveRetryTime = SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NEXT_RETRY_TIMESTAMP), options);
    boolean retrieveNodeAsObserved = SelectorOptions.hasToLoadPath(new ItemPath(TaskType.F_NODE_AS_OBSERVED), options);
    List<PrismObject<TaskType>> retval = new ArrayList<>();
    for (PrismObject<TaskType> taskInRepository : tasksInRepository) {
        TaskType taskInResult = addTransientTaskInformation(taskInRepository, clusterStatusInformation, retrieveNextRunStartTime, retrieveRetryTime, retrieveNodeAsObserved, result);
        retval.add(taskInResult.asPrismObject());
    }
    result.computeStatus();
    return new SearchResultList(retval);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 9 with ClusterStatusInformation

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

the class RemoteNodesManager method addNodeStatusFromRemoteNode.

/**
     * Used exclusively for collecting running task information.
     *
     * @param info A structure to which information should be added
     * @param node Node which to query
     */
void addNodeStatusFromRemoteNode(ClusterStatusInformation info, PrismObject<NodeType> node, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(RemoteNodesManager.class.getName() + ".addNodeStatusFromRemoteNode");
    result.addParam("node", node);
    NodeType nodeInfo = node.asObjectable();
    String nodeIdentifier = nodeInfo.getNodeIdentifier();
    String address = nodeInfo.getHostname() + ":" + nodeInfo.getJmxPort();
    if (!taskManager.getClusterManager().isUp(nodeInfo)) {
        nodeInfo.setExecutionStatus(NodeExecutionStatusType.DOWN);
        info.addNodeInfo(nodeInfo);
        result.recordStatus(OperationResultStatus.SUCCESS, "Node is down");
        return;
    }
    JMXConnector connector = null;
    try {
        MBeanServerConnection mbsc;
        try {
            connector = connectViaJmx(address);
            mbsc = connector.getMBeanServerConnection();
        } catch (IOException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot connect to the remote node {} at {}", e, nodeIdentifier, address);
            result.recordWarning("Cannot connect to the remote node " + nodeIdentifier + " at " + address + ": " + e.getMessage(), e);
            nodeInfo.setExecutionStatus(NodeExecutionStatusType.COMMUNICATION_ERROR);
            nodeInfo.setConnectionResult(result.createOperationResultType());
            info.addNodeInfo(nodeInfo);
            return;
        }
        try {
            QuartzSchedulerMBean mbeanProxy = getMBeanProxy(nodeIdentifier, mbsc);
            boolean running = false, down = true;
            if (mbeanProxy != null) {
                try {
                    running = mbeanProxy.isStarted() && !mbeanProxy.isShutdown() && !mbeanProxy.isStandbyMode();
                    down = mbeanProxy.isShutdown();
                } catch (Exception e) {
                    // was: InstanceNotFoundException but it does not seem to work
                    String message = "Cannot get information from scheduler " + nodeIdentifier + " because it does not exist or is shut down.";
                    LoggingUtils.logUnexpectedException(LOGGER, message, e);
                    result.recordWarning(message, e);
                    nodeInfo.setConnectionResult(result.createOperationResultType());
                }
            } else {
                result.recordWarning("Cannot get information from node " + nodeIdentifier + " at " + address + " because the JMX object for scheduler cannot be found on that node.");
                nodeInfo.setConnectionResult(result.createOperationResultType());
            }
            LOGGER.trace(" - scheduler found = " + (mbeanProxy != null) + ", running = " + running + ", shutdown = " + down);
            if (down) {
                // this is a mark of error situation (we expect that during ordinary shutdown the node quickly goes down so there is little probability of getting this status on that occasion)
                nodeInfo.setExecutionStatus(NodeExecutionStatusType.ERROR);
            } else if (running) {
                nodeInfo.setExecutionStatus(NodeExecutionStatusType.RUNNING);
            } else {
                nodeInfo.setExecutionStatus(NodeExecutionStatusType.PAUSED);
            }
            List<ClusterStatusInformation.TaskInfo> taskInfoList = new ArrayList<ClusterStatusInformation.TaskInfo>();
            if (mbeanProxy != null) {
                TabularData jobs = mbeanProxy.getCurrentlyExecutingJobs();
                for (CompositeData job : (Collection<CompositeData>) jobs.values()) {
                    String oid = (String) job.get("jobName");
                    LOGGER.trace(" - task oid = " + oid);
                    taskInfoList.add(new ClusterStatusInformation.TaskInfo(oid));
                }
            }
            if (result.isUnknown()) {
                result.recordStatus(OperationResultStatus.SUCCESS, "Node " + nodeIdentifier + ": status = " + nodeInfo.getExecutionStatus() + ", # of running tasks: " + taskInfoList.size());
            }
            info.addNodeAndTaskInfo(nodeInfo, taskInfoList);
        } catch (Exception e) {
            // unfortunately, mbeanProxy.getCurrentlyExecutingJobs is declared to throw an Exception
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot get information from the remote node {} at {}", e, nodeIdentifier, address);
            result.recordWarning("Cannot get information from the remote node " + nodeIdentifier + " at " + address + ": " + e.getMessage(), e);
            nodeInfo.setExecutionStatus(NodeExecutionStatusType.COMMUNICATION_ERROR);
            nodeInfo.setConnectionResult(result.createOperationResultType());
            info.addNodeInfo(nodeInfo);
            return;
        }
    } finally {
        try {
            if (connector != null) {
                connector.close();
            }
        } catch (IOException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot close JMX connection to {}", e, address);
        }
        result.recordSuccessIfUnknown();
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IOException(java.io.IOException) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) SystemException(com.evolveum.midpoint.util.exception.SystemException) QuartzSchedulerMBean(org.quartz.core.jmx.QuartzSchedulerMBean) TabularData(javax.management.openmbean.TabularData) JMXConnector(javax.management.remote.JMXConnector) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 10 with ClusterStatusInformation

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

the class TaskStopper method waitForTaskRunCompletion.

// returns true if tasks are down
private boolean waitForTaskRunCompletion(Collection<? extends Task> tasks, long maxWaitTime, boolean clusterwide, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(OP_WAIT_FOR_TASK_RUN_COMPLETION);
    result.addArbitraryObjectCollectionAsParam("tasks", tasks);
    result.addParam("maxWaitTime", maxWaitTime);
    result.addParam("clusterwide", clusterwide);
    boolean interruptExecuted = false;
    LOGGER.trace("Waiting for task(s) {} to complete, at most for {} ms.", tasks, maxWaitTime);
    Set<String> oids = new HashSet<>();
    for (Task t : tasks) {
        if (t.getOid() != null) {
            oids.add(t.getOid());
        }
    }
    long singleWait = WAIT_FOR_COMPLETION_INITIAL;
    long started = System.currentTimeMillis();
    while (true) {
        boolean isAnythingExecuting = false;
        ClusterStatusInformation rtinfo = clusterStatusInformationRetriever.getClusterStatusInformation(clusterwide, false, result);
        for (String oid : oids) {
            if (rtinfo.findNodeInfoForTask(oid) != null) {
                isAnythingExecuting = true;
                break;
            }
        }
        if (!isAnythingExecuting) {
            String message = "The task(s), for which we have been waiting for, have finished.";
            LOGGER.trace(message);
            result.recordStatus(OperationResultStatus.SUCCESS, message);
            return true;
        }
        if (maxWaitTime > 0 && System.currentTimeMillis() - started >= maxWaitTime) {
            String message = "Wait time has elapsed without (some of) tasks being stopped. Finishing waiting for task(s) completion.";
            LOGGER.trace(message);
            result.recordWarning(message);
            return false;
        }
        if (configuration.getUseThreadInterrupt() == UseThreadInterrupt.WHEN_NECESSARY && !interruptExecuted && System.currentTimeMillis() - started >= INTERRUPT_TASK_THREAD_AFTER) {
            LOGGER.info("Some tasks have not completed yet, sending their threads the 'interrupt' signal (if running locally).");
            for (String oid : oids) {
                localScheduler.stopLocalTaskRunByInterrupt(oid);
            }
            interruptExecuted = true;
        }
        LOGGER.trace("Some tasks have not completed yet, waiting for " + singleWait + " ms (max: " + maxWaitTime + ")");
        try {
            Thread.sleep(singleWait);
        } catch (InterruptedException e) {
            LOGGER.trace("Waiting interrupted" + e);
        }
        if (singleWait < WAIT_FOR_COMPLETION_MAX) {
            singleWait *= 2;
        }
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation)

Aggregations

ClusterStatusInformation (com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 NotNull (org.jetbrains.annotations.NotNull)5 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)4 ArrayList (java.util.ArrayList)4 Task (com.evolveum.midpoint.task.api.Task)3 NodeType (com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 TaskQuartzImpl (com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)1 com.evolveum.midpoint.task.api (com.evolveum.midpoint.task.api)1 TaskRunResultStatus (com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus)1 TaskManagerQuartzImpl (com.evolveum.midpoint.task.quartzimpl.TaskManagerQuartzImpl)1 TaskQuartzImplUtil (com.evolveum.midpoint.task.quartzimpl.TaskQuartzImplUtil)1 LoggingUtils (com.evolveum.midpoint.util.logging.LoggingUtils)1