Search in sources :

Example 86 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class TaskManagerQuartzImpl method startLightweightTask.

//endregion
//region Transient and lightweight tasks
//    public void registerTransientSubtask(TaskQuartzImpl subtask, TaskQuartzImpl parent) {
//        Validate.notNull(subtask, "Subtask is null");
//        Validate.notNull(parent, "Parent task is null");
//        if (parent.isTransient()) {
//            registerTransientTask(parent);
//        }
//        registerTransientTask(subtask);
//    }
//
//    public void registerTransientTask(TaskQuartzImpl task) {
//        Validate.notNull(task, "Task is null");
//        Validate.notNull(task.getTaskIdentifier(), "Task identifier is null");
//        registeredTransientTasks.put(task.getTaskIdentifier(), task);
//    }
public void startLightweightTask(final TaskQuartzImpl task) {
    if (task.isPersistent()) {
        throw new IllegalStateException("An attempt to start LightweightTaskHandler in a persistent task; task = " + task);
    }
    final LightweightTaskHandler lightweightTaskHandler = task.getLightweightTaskHandler();
    if (lightweightTaskHandler == null) {
        // nothing to do
        return;
    }
    synchronized (task) {
        if (task.lightweightHandlerStartRequested()) {
            throw new IllegalStateException("Handler for the lightweight task " + task + " has already been started.");
        }
        if (task.getExecutionStatus() != TaskExecutionStatus.RUNNABLE) {
            throw new IllegalStateException("Handler for lightweight task " + task + " couldn't be started because the task's state is " + task.getExecutionStatus());
        }
        Runnable r = new Runnable() {

            @Override
            public void run() {
                LOGGER.debug("Lightweight task handler shell starting execution; task = {}", task);
                try {
                    // Setup Spring Security context
                    securityEnforcer.setupPreAuthenticatedSecurityContext(task.getOwner());
                } catch (SchemaException e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't set up task security context {}", e, task);
                    throw new SystemException(e.getMessage(), e);
                }
                try {
                    task.setLightweightHandlerExecuting(true);
                    lightweightTaskHandler.run(task);
                } catch (Throwable t) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Lightweight task handler has thrown an exception; task = {}", t, task);
                } finally {
                    task.setLightweightHandlerExecuting(false);
                }
                LOGGER.debug("Lightweight task handler shell finishing; task = {}", task);
                try {
                    // TODO what about concurrency here??!
                    closeTask(task, task.getResult());
                // commented out, as currently LATs cannot participate in dependency relationships
                //task.checkDependentTasksOnClose(task.getResult());
                // task.updateStoredTaskResult();   // has perhaps no meaning for transient tasks
                } catch (Exception e) {
                    // todo
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't correctly close task {}", e, task);
                }
            }
        };
        Future future = lightweightHandlersExecutor.submit(r);
        task.setLightweightHandlerFuture(future);
        LOGGER.debug("Lightweight task handler submitted to start; task = {}", task);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) Future(java.util.concurrent.Future) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ParseException(java.text.ParseException) CancellationException(java.util.concurrent.CancellationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) SchedulerException(org.quartz.SchedulerException) BeansException(org.springframework.beans.BeansException)

Example 87 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class TaskQuartzImpl method setResultImmediate.

@Override
public void setResultImmediate(OperationResult result, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    try {
        processModificationNow(setResultAndPrepareDelta(result), parentResult);
        setResultStatusTypeImmediate(result != null ? result.getStatus().createStatusType() : null, parentResult);
    } catch (ObjectAlreadyExistsException ex) {
        throw new SystemException(ex);
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 88 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class ClusterManager method getNodeById.

public PrismObject<NodeType> getNodeById(String nodeIdentifier, OperationResult result) throws ObjectNotFoundException {
    try {
        //            QueryType q = QueryUtil.createNameQuery(nodeIdentifier);        // TODO change to query-by-node-id
        ObjectQuery q = ObjectQueryUtil.createNameQuery(NodeType.class, taskManager.getPrismContext(), nodeIdentifier);
        List<PrismObject<NodeType>> nodes = taskManager.getRepositoryService().searchObjects(NodeType.class, q, null, result);
        if (nodes.isEmpty()) {
            //                result.recordFatalError("A node with identifier " + nodeIdentifier + " does not exist.");
            throw new ObjectNotFoundException("A node with identifier " + nodeIdentifier + " does not exist.");
        } else if (nodes.size() > 1) {
            throw new SystemException("Multiple nodes with the same identifier '" + nodeIdentifier + "' in the repository.");
        } else {
            return nodes.get(0);
        }
    } catch (SchemaException e) {
        // should not occur
        throw new SystemException("Cannot get the list of nodes from the repository", e);
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 89 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class NodeRegistrar method deleteNode.

public void deleteNode(String nodeOid, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
    OperationResult result = parentResult.createSubresult(NodeRegistrar.class.getName() + ".deleteNode");
    result.addParam("nodeOid", nodeOid);
    PrismObject<NodeType> nodePrism = clusterManager.getNode(nodeOid, result);
    if (isUp(nodePrism.asObjectable())) {
        result.recordFatalError("Node " + nodeOid + " cannot be deleted, because it is currently up.");
    } else {
        try {
            taskManager.getRepositoryService().deleteObject(NodeType.class, nodePrism.getOid(), result);
            result.recordSuccess();
        } catch (ObjectNotFoundException e) {
            throw new SystemException("Unexpected ObjectNotFoundException when deleting a node", e);
        }
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 90 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.

the class NodeRegistrar method createNodePrism.

private PrismObject<NodeType> createNodePrism(TaskManagerConfiguration configuration) {
    PrismObjectDefinition<NodeType> nodeTypeDef = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(NodeType.class);
    PrismObject<NodeType> nodePrism;
    try {
        nodePrism = nodeTypeDef.instantiate();
    } catch (SchemaException e) {
        throw new SystemException(e.getMessage(), e);
    }
    NodeType node = nodePrism.asObjectable();
    node.setNodeIdentifier(configuration.getNodeId());
    node.setName(new PolyStringType(configuration.getNodeId()));
    node.setHostname(getMyAddress());
    node.setJmxPort(configuration.getJmxPort());
    node.setClustered(configuration.isClustered());
    node.setRunning(true);
    node.setLastCheckInTime(getCurrentTime());
    node.setBuild(getBuildInformation());
    generateInternalNodeIdentifier(node);
    return nodePrism;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) NodeType(com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12