Search in sources :

Example 6 with NodeType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.

the class NodeRegistrar method checkNonClusteredNodes.

/**
     * There may be either exactly one non-clustered node (and no other nodes), or clustered nodes only.
     * @param result
     */
public void checkNonClusteredNodes(OperationResult result) {
    LOGGER.trace("Checking non-clustered nodes.");
    List<String> clustered = new ArrayList<String>();
    List<String> nonClustered = new ArrayList<String>();
    List<PrismObject<NodeType>> allNodes = clusterManager.getAllNodes(result);
    for (PrismObject<NodeType> nodePrism : allNodes) {
        NodeType n = nodePrism.asObjectable();
        if (isUp(n)) {
            if (n.isClustered()) {
                clustered.add(n.getNodeIdentifier());
            } else {
                nonClustered.add(n.getNodeIdentifier());
            }
        }
    }
    LOGGER.trace("Clustered nodes: " + clustered);
    LOGGER.trace("Non-clustered nodes: " + nonClustered);
    int all = clustered.size() + nonClustered.size();
    if (!taskManager.getConfiguration().isClustered() && all > 1) {
        LOGGER.error("This node is a non-clustered one, mixed with other nodes. In this system, there are " + nonClustered.size() + " non-clustered nodes (" + nonClustered + ") and " + clustered.size() + " clustered ones (" + clustered + "). Stopping this node.");
        registerNodeError(NodeErrorStatusType.NON_CLUSTERED_NODE_WITH_OTHERS);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)

Example 7 with NodeType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.

the class RemoteNodesManager method startRemoteScheduler.

void startRemoteScheduler(String nodeIdentifier, OperationResult result) {
    NodeType node = getNode(nodeIdentifier, result);
    if (node == null) {
        return;
    }
    String nodeName = node.getNodeIdentifier();
    String address = node.getHostname() + ":" + node.getJmxPort();
    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, nodeName, address);
            result.recordFatalError("Cannot connect to the remote node " + nodeName + " at " + address + ": " + e.getMessage(), e);
            return;
        }
        try {
            QuartzSchedulerMBean mbeanProxy = getMBeanProxy(nodeName, mbsc);
            if (mbeanProxy != null) {
                mbeanProxy.start();
                result.recordSuccessIfUnknown();
            } else {
                result.recordFatalError("Cannot start remote scheduler " + nodeName + " at " + address + " because it cannot be found on that node.");
            }
            return;
        } catch (Exception e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot start remote scheduler; remote node {} at {}", e, nodeName, address);
            result.recordFatalError("Cannot start remote scheduler " + nodeName + " at " + address + ": " + e.getMessage());
            return;
        }
    } finally {
        try {
            if (connector != null) {
                connector.close();
            }
        } catch (IOException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot close JMX connection to {}", e, address);
        }
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) 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)

Example 8 with NodeType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType 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 9 with NodeType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.

the class NodeCleaner method cleanupNodes.

/**
 * Cleans up dead nodes older than specified age.
 *
 * @param selector If returns false, the respective node will not be removed.
 */
public void cleanupNodes(@NotNull DeadNodeCleanupPolicyType policy, @NotNull Predicate<NodeType> selector, @NotNull RunningTask task, @NotNull OperationResult result) throws SchemaException, ObjectNotFoundException {
    if (policy.getMaxAge() == null) {
        return;
    }
    TimeBoundary timeBoundary = TimeBoundary.compute(policy.getMaxAge());
    XMLGregorianCalendar deleteNodesNotCheckedInAfter = timeBoundary.getBoundary();
    LOGGER.info("Starting cleanup for stopped nodes not checked in after {} (duration '{}').", deleteNodesNotCheckedInAfter, timeBoundary.getPositiveDuration());
    for (PrismObject<NodeType> node : clusterManager.getAllNodes(result)) {
        if (!task.canRun()) {
            result.recordWarning("Interrupted");
            LOGGER.warn("Node cleanup was interrupted.");
            break;
        }
        if (!clusterManager.isCurrentNode(node) && !clusterManager.isCheckingIn(node.asObjectable()) && XmlTypeConverter.compareMillis(node.asObjectable().getLastCheckInTime(), deleteNodesNotCheckedInAfter) <= 0) {
            // This includes last check in time == null
            LOGGER.info("Deleting dead node {}; last check in time = {}", node, node.asObjectable().getLastCheckInTime());
            IterativeOperationStartInfo iterativeOperationStartInfo = new IterativeOperationStartInfo(new IterationItemInformation(node));
            iterativeOperationStartInfo.setSimpleCaller(true);
            Operation op = task.recordIterativeOperationStart(iterativeOperationStartInfo);
            if (ObjectTypeUtil.isIndestructible(node)) {
                LOGGER.debug("Not deleting dead but indestructible node {}", node);
                op.skipped();
                continue;
            }
            try {
                // Selector testing is in try-catch because of possible exceptions during autz evaluation
                if (!selector.test(node.asObjectable())) {
                    LOGGER.debug("Not deleting node {} because it was rejected by the selector", node);
                    op.skipped();
                    continue;
                }
                repositoryService.deleteObject(NodeType.class, node.getOid(), result);
                op.succeeded();
            } catch (Throwable t) {
                op.failed(t);
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete dead node {}", t, node);
            }
            task.incrementLegacyProgressAndStoreStatisticsIfTimePassed(result);
        }
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) TimeBoundary(com.evolveum.midpoint.task.quartzimpl.util.TimeBoundary) IterativeOperationStartInfo(com.evolveum.midpoint.schema.statistics.IterativeOperationStartInfo) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) Operation(com.evolveum.midpoint.schema.statistics.Operation) IterationItemInformation(com.evolveum.midpoint.schema.statistics.IterationItemInformation)

Example 10 with NodeType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType in project midpoint by Evolveum.

the class TaskStopper method stopTaskRun.

// if clusterwide, csi must not be null
// on entry we do not know if the task is really running
private void stopTaskRun(Task task, ClusterStatusInformation csi, boolean clusterwide, OperationResult parentResult) {
    String oid = task.getOid();
    LOGGER.trace("stopTaskRun: task = {}, csi = {}, clusterwide = {}", task, csi, clusterwide);
    if (!clusterwide) {
        stopLocalTaskIfRunning(oid, parentResult);
    } else {
        NodeType node = csi.findNodeInfoForTask(task.getOid());
        if (node != null) {
            if (taskManager.getClusterManager().isCurrentNode(node.getNodeIdentifier())) {
                stopLocalTaskIfRunning(oid, parentResult);
            } else {
                remoteSchedulers.stopRemoteTaskRun(task.getOid(), node, parentResult);
            }
        }
    }
}
Also used : NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)

Aggregations

NodeType (com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)28 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 SystemException (com.evolveum.midpoint.util.exception.SystemException)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 ClusterStatusInformation (com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation)4 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 List (java.util.List)3 MBeanServerConnection (javax.management.MBeanServerConnection)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 JMXConnector (javax.management.remote.JMXConnector)3 QuartzSchedulerMBean (org.quartz.core.jmx.QuartzSchedulerMBean)3 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 SearchResultList (com.evolveum.midpoint.schema.SearchResultList)2 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)2 LoggingUtils (com.evolveum.midpoint.util.logging.LoggingUtils)2 Trace (com.evolveum.midpoint.util.logging.Trace)2