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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
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;
}
Aggregations