use of com.evolveum.midpoint.schema.traces.TraceWriter in project midpoint by Evolveum.
the class EditTraceAction method writeTrace.
private void writeTrace(TracingOutputType trace) throws SchemaException, IOException {
String output = ObjectUtils.defaultIfNull(options.getOutput(), DEFAULT_OUTPUT);
log.info("Starting writing trace to {}", output);
new TraceWriter(context.getPrismContext()).writeTrace(trace, new File(output), true);
log.info("Trace written.");
}
use of com.evolveum.midpoint.schema.traces.TraceWriter in project midpoint by Evolveum.
the class TracerImpl method storeTrace.
@Override
public void storeTrace(Task task, OperationResult result, @Nullable OperationResult parentResult) {
OperationResult thisOpResult;
if (parentResult != null) {
thisOpResult = parentResult.createMinorSubresult(OP_STORE_TRACE);
} else {
thisOpResult = new OperationResult(OP_STORE_TRACE);
}
try {
CompiledTracingProfile compiledTracingProfile = result.getTracingProfile();
TracingProfileType tracingProfile = compiledTracingProfile.getDefinition();
if (!Boolean.FALSE.equals(tracingProfile.isCreateTraceFile())) {
boolean zip = !Boolean.FALSE.equals(tracingProfile.isCompressOutput());
// todo evaluate lazily if needed
Map<String, String> templateParameters = createTemplateParameters(result);
File file = createFileName(zip, tracingProfile, templateParameters);
try {
long start = System.currentTimeMillis();
TracingOutputType tracingOutput = tracingOutputCreator.createTracingOutput(task, result, tracingProfile);
String xml = new TraceWriter(prismContext).writeTrace(tracingOutput, file, zip);
if (zip) {
LOGGER.info("Trace was written to {} ({} chars uncompressed) in {} milliseconds", file, xml.length(), System.currentTimeMillis() - start);
} else {
LOGGER.info("Trace was written to {} ({} chars) in {} milliseconds", file, xml.length(), System.currentTimeMillis() - start);
}
if (!Boolean.FALSE.equals(tracingProfile.isCreateRepoObject())) {
ReportDataType reportDataObject = new ReportDataType(prismContext).name(createObjectName(tracingProfile, templateParameters)).archetypeRef(SystemObjectsType.ARCHETYPE_TRACE.value(), ArchetypeType.COMPLEX_TYPE).filePath(file.getAbsolutePath()).nodeRef(ObjectTypeUtil.createObjectRef(taskManager.getLocalNode(), prismContext));
repositoryService.addObject(reportDataObject.asPrismObject(), null, thisOpResult);
}
} catch (IOException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't write trace ({})", e, file);
throw new SystemException(e);
}
}
} catch (Throwable t) {
thisOpResult.recordFatalError(t);
throw t;
} finally {
thisOpResult.computeStatusIfUnknown();
}
}
Aggregations