Search in sources :

Example 1 with TaskManagerInitializationException

use of com.evolveum.midpoint.task.api.TaskManagerInitializationException 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)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)1 TaskManagerInitializationException (com.evolveum.midpoint.task.api.TaskManagerInitializationException)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 NodeType (com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)1