use of sirius.kernel.health.HandledException in project sirius-db by scireum.
the class LowLevelClient method resolveIndexForAlias.
/**
* Returns the actual index for the given alias
*
* @param aliasName the alias the resolve
* @return the index name to which this alias points or an empty optional if the alias is unknown
* @throws HandledException if the alias points to more than one index as this pattern is unused by
* out schema evolution tools (which always redirects an index access via an alias).
*/
public Optional<String> resolveIndexForAlias(String aliasName) {
List<String> indexNames = new ArrayList<>();
performGet().withCustomErrorHandler(error -> {
// JSON object, otherwise the error and its status code will be reported as indices...
if (error.getResponse().getStatusLine().getStatusCode() == 404) {
return new StringEntity("{}", StandardCharsets.UTF_8);
} else {
return null;
}
}).execute(API_ALIAS + "/" + aliasName).response().forEach((indexName, info) -> indexNames.add(indexName));
if (indexNames.isEmpty()) {
return Optional.empty();
}
if (indexNames.size() > 1) {
throw Exceptions.handle().to(Elastic.LOG).withSystemErrorMessage("The alias %s points to more than one index: %s", aliasName, Strings.join(indexNames, ", ")).handle();
}
return Optional.of(indexNames.get(0));
}
use of sirius.kernel.health.HandledException in project sirius-biz by scireum.
the class EventRecorder method process.
/**
* Processes the queued events by creating a {@link BatchContext} and batch-inserting all events.
*
* @return the number of inserted events
*/
protected int process() {
lastProcessed = LocalDateTime.now();
int processedEvents = 0;
try (BatchContext ctx = new BatchContext(() -> "Process recorded events.", Duration.ofMinutes(1))) {
Map<Class<? extends Event>, InsertQuery<Event>> queries = new HashMap<>();
Event nextEvent = fetchBufferedEvent();
while (nextEvent != null) {
processEvent(ctx, queries, nextEvent);
if (++processedEvents >= MAX_EVENTS_PER_PROCESS) {
return processedEvents;
}
nextEvent = fetchBufferedEvent();
}
} catch (HandledException e) {
Exceptions.ignore(e);
} catch (Exception e) {
Exceptions.handle(Log.BACKGROUND, e);
}
return processedEvents;
}
use of sirius.kernel.health.HandledException in project sirius-biz by scireum.
the class JobSchedulerLoop method executeJobInProcess.
private <J extends SchedulerEntry> void executeJobInProcess(SchedulerEntryProvider<J> provider, J entry, LocalDateTime now, ProcessContext ctx) {
if (ctx.isDebugging()) {
ctx.debug(ProcessLog.info().withFormattedMessage("Starting scheduled job %s (%s) for user %s.", entry, entry.getJobConfigData().getJobName(), UserContext.getCurrentUser().getUserName()));
}
try {
String processId = entry.getJobConfigData().getJobFactory().startInBackground(entry.getJobConfigData()::fetchParameter);
if (processId != null) {
processes.log(processId, ProcessLog.info().withNLSKey("JobSchedulerLoop.scheduledExecutionInfo").withContext("entry", entry.toString()));
processes.addLink(processId, new ProcessLink().withLabel("$JobSchedulerLoop.jobLink").withUri("/jobs/scheduler/entry/" + entry.getIdAsString()));
processes.addReference(processId, entry.getUniqueName());
}
provider.markExecuted(entry, now);
} catch (HandledException exception) {
ctx.log(ProcessLog.error().withFormattedMessage("Failed to start scheduled job %s (%s) for user %s: %s", entry, entry.getJobConfigData().getJobName(), UserContext.getCurrentUser().getUserName(), exception.getMessage()));
}
}
use of sirius.kernel.health.HandledException in project sirius-biz by scireum.
the class ProcessEnvironment method handle.
@Override
public HandledException handle(Exception e) {
HandledException handledException = Exceptions.handle(Log.BACKGROUND, e);
log(ProcessLog.error().withHandledException(handledException));
return handledException;
}
use of sirius.kernel.health.HandledException in project sirius-biz by scireum.
the class Scripting method handleExecTask.
private void handleExecTask(JSONObject event) {
String nodeName = event.getString(TASK_NODE);
String jobNumber = event.getString(TASK_JOB);
if (!ALL_NODES.equals(nodeName) && !Strings.areEqual(CallContext.getNodeName(), nodeName)) {
return;
}
Watch watch = Watch.start();
logInTranscript(jobNumber, Strings.apply("Starting execution on %s (Thread Id: %s / Thread Name: %s)", CallContext.getNodeName(), Thread.currentThread().getId(), Thread.currentThread().getName()));
try {
Callable callable = compileScript(event);
TaskContext.get().setAdapter(new JobTaskContextAdapter(this, jobNumber));
callable.call(new SimpleEnvironment());
} catch (CompileException | ScriptingException | HandledException e) {
logInTranscript(jobNumber, e.getMessage());
} catch (Exception e) {
logInTranscript(jobNumber, Exceptions.handle(Pasta.LOG, e).getMessage());
}
logInTranscript(jobNumber, Strings.apply("Execution completed (%s)", watch.duration()));
}
Aggregations