Search in sources :

Example 1 with TraceWriter

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.");
}
Also used : TraceWriter(com.evolveum.midpoint.schema.traces.TraceWriter) File(java.io.File)

Example 2 with TraceWriter

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();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) IOException(java.io.IOException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CompiledTracingProfile(com.evolveum.midpoint.schema.result.CompiledTracingProfile) TraceWriter(com.evolveum.midpoint.schema.traces.TraceWriter) File(java.io.File) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

TraceWriter (com.evolveum.midpoint.schema.traces.TraceWriter)2 File (java.io.File)2 CompiledTracingProfile (com.evolveum.midpoint.schema.result.CompiledTracingProfile)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 IOException (java.io.IOException)1