Search in sources :

Example 21 with NodeType

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

the class NodeRegistrar method createNodeObject.

/**
     * Executes node startup registration: if Node object with a give name (node ID) exists, deletes it.
     * Then creates a new Node with the information relevant to this node.
     *
     * @param result Node prism to be used for periodic re-registrations.
     */
PrismObject<NodeType> createNodeObject(OperationResult result) throws TaskManagerInitializationException {
    nodePrism = createNodePrism(taskManager.getConfiguration());
    NodeType node = nodePrism.asObjectable();
    LOGGER.info("Registering this node in the repository as " + node.getNodeIdentifier() + " at " + node.getHostname() + ":" + node.getJmxPort());
    List<PrismObject<NodeType>> nodes;
    try {
        nodes = findNodesWithGivenName(result, node.getName());
    } catch (SchemaException e) {
        throw new TaskManagerInitializationException("Node registration failed because of schema exception", e);
    }
    for (PrismObject<NodeType> n : nodes) {
        LOGGER.trace("Removing existing NodeType with oid = {}, name = {}", n.getOid(), n.getElementName());
        try {
            getRepositoryService().deleteObject(NodeType.class, n.getOid(), result);
        } catch (ObjectNotFoundException e) {
            LoggingUtils.logException(LOGGER, "Cannot remove NodeType with oid = {}, name = {}, because it does not exist.", e, n.getOid(), n.getElementName());
        // continue, because the error is not that severe (we hope so)
        }
    }
    try {
        String oid = getRepositoryService().addObject(nodePrism, null, result);
        nodePrism.setOid(oid);
    } catch (ObjectAlreadyExistsException e) {
        taskManager.setNodeErrorStatus(NodeErrorStatusType.NODE_REGISTRATION_FAILED);
        throw new TaskManagerInitializationException("Cannot register this node, because it already exists (this should not happen, as nodes with such a name were just removed)", e);
    } catch (SchemaException e) {
        taskManager.setNodeErrorStatus(NodeErrorStatusType.NODE_REGISTRATION_FAILED);
        throw new TaskManagerInitializationException("Cannot register this node because of schema exception", e);
    }
    LOGGER.trace("Node was successfully registered in the repository.");
    return nodePrism;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TaskManagerInitializationException(com.evolveum.midpoint.task.api.TaskManagerInitializationException) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 22 with NodeType

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

the class ExecutionManager 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 {
                remoteNodesManager.stopRemoteTaskRun(task.getOid(), node, parentResult);
            }
        }
    }
}
Also used : NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)

Example 23 with NodeType

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

the class NodeRetriever method searchNodes.

/**
 * Gets nodes from repository and adds runtime information to them (taken from ClusterStatusInformation).
 */
@NotNull
public SearchResultList<PrismObject<NodeType>> searchNodes(ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    ClusterStatusInformation csi = clusterStatusInformationRetriever.getClusterStatusInformation(options, NodeType.class, true, result);
    List<PrismObject<NodeType>> nodesInRepository;
    try {
        nodesInRepository = repositoryService.searchObjects(NodeType.class, query, options, result);
    } catch (SchemaException e) {
        result.recordFatalError("Couldn't get nodes from repository: " + e.getMessage());
        throw e;
    }
    List<PrismObject<NodeType>> list = new ArrayList<>();
    if (csi != null) {
        for (PrismObject<NodeType> nodeInRepositoryPrism : nodesInRepository) {
            NodeType returnedNode = nodeInRepositoryPrism.asObjectable();
            NodeType nodeRuntimeInfo = csi.findNodeById(returnedNode.getNodeIdentifier());
            if (nodeRuntimeInfo != null) {
                returnedNode.setExecutionState(nodeRuntimeInfo.getExecutionState());
                returnedNode.setErrorState(nodeRuntimeInfo.getErrorState());
                returnedNode.setConnectionResult(nodeRuntimeInfo.getConnectionResult());
            } else {
                // node is in repo, but no information on it is present in CSI
                // (should not occur except for some temporary conditions, because CSI contains info on all nodes from repo)
                returnedNode.setExecutionState(NodeExecutionStateType.COMMUNICATION_ERROR);
                OperationResult r = new OperationResult("connect");
                r.recordFatalError("Node not known at this moment");
                returnedNode.setConnectionResult(r.createOperationResultType());
            }
            list.add(returnedNode.asPrismObject());
        }
    } else {
        list = nodesInRepository;
    }
    LOGGER.trace("searchNodes returning {}", list);
    return new SearchResultList<>(list);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchResultList(com.evolveum.midpoint.schema.SearchResultList) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ClusterStatusInformation(com.evolveum.midpoint.task.quartzimpl.cluster.ClusterStatusInformation) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with NodeType

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

the class ClusterExecutionHelperImpl method execute.

@Override
public void execute(@NotNull ClientCode code, ClusterExecutionOptions options, String context, OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(DOT_CLASS + "execute");
    if (!taskManager.isClustered()) {
        LOGGER.trace("Node is not part of a cluster, skipping remote code execution");
        result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Node not in cluster");
        return;
    }
    SearchResultList<PrismObject<NodeType>> otherClusterNodes = searchOtherClusterNodes(context, result);
    if (otherClusterNodes == null) {
        return;
    }
    for (PrismObject<NodeType> node : otherClusterNodes.getList()) {
        try {
            execute(node.asObjectable(), code, options, context, result);
        } catch (SchemaException | RuntimeException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute operation ({}) on node {}", e, context, node);
        }
    }
    result.computeStatus();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 25 with NodeType

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

the class LocalNodeState method getLocalNode.

/**
 * @return current local node information, updated with local node execution and error status.
 * Returned value is fresh, so it can be modified as needed.
 */
@Nullable
public NodeType getLocalNode() {
    PrismObject<NodeType> localNode = clusterManager.getLocalNodeObject();
    if (localNode == null) {
        return null;
    }
    NodeType node = localNode.clone().asObjectable();
    node.setExecutionState(getExecutionState());
    node.setErrorState(errorState);
    return node;
}
Also used : NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) Nullable(org.jetbrains.annotations.Nullable)

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