Search in sources :

Example 1 with Log

use of com.evolveum.midpoint.ninja.util.Log in project midpoint by Evolveum.

the class SearchProducerWorker method run.

@Override
public void run() {
    Log log = context.getLog();
    try {
        GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
        if (options.isRaw()) {
            optionsBuilder = optionsBuilder.raw();
        }
        optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, type.getClassDefinition());
        ResultHandler<?> handler = (object, parentResult) -> {
            try {
                queue.put(object.asObjectable());
            } catch (InterruptedException ex) {
                log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
            }
            return true;
        };
        RepositoryService repository = context.getRepository();
        repository.searchObjectsIterative(type.getClassDefinition(), query, handler, optionsBuilder.build(), true, operation.getResult());
    } catch (SchemaException ex) {
        log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
    } catch (NinjaException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        markDone();
        if (isWorkersDone()) {
            if (!operation.isFinished()) {
                operation.producerFinish();
            }
        }
    }
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) ExportOptions(com.evolveum.midpoint.ninja.opts.ExportOptions) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) BlockingQueue(java.util.concurrent.BlockingQueue) NinjaContext(com.evolveum.midpoint.ninja.impl.NinjaContext) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) List(java.util.List) Log(com.evolveum.midpoint.ninja.util.Log) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Log(com.evolveum.midpoint.ninja.util.Log) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Example 2 with Log

use of com.evolveum.midpoint.ninja.util.Log in project midpoint by Evolveum.

the class ExportAuditProducerWorker method run.

@Override
public void run() {
    Log log = context.getLog();
    try {
        GetOperationOptionsBuilder optionsBuilder = context.getSchemaService().getOperationOptionsBuilder();
        optionsBuilder = NinjaUtils.addIncludeOptionsForExport(optionsBuilder, AuditEventRecordType.class);
        AuditResultHandler handler = (object, parentResult) -> {
            try {
                queue.put(object);
            } catch (InterruptedException ex) {
                log.error("Couldn't queue object {}, reason: {}", ex, object, ex.getMessage());
            }
            return true;
        };
        AuditService auditService = context.getAuditService();
        auditService.searchObjectsIterative(query, handler, optionsBuilder.build(), operation.getResult());
    } catch (SchemaException ex) {
        log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
    } catch (NinjaException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        markDone();
        if (isWorkersDone()) {
            if (!operation.isFinished()) {
                operation.producerFinish();
            }
        }
    }
}
Also used : AuditService(com.evolveum.midpoint.audit.api.AuditService) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) BlockingQueue(java.util.concurrent.BlockingQueue) NinjaContext(com.evolveum.midpoint.ninja.impl.NinjaContext) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) List(java.util.List) Log(com.evolveum.midpoint.ninja.util.Log) BaseWorker(com.evolveum.midpoint.ninja.action.worker.BaseWorker) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Log(com.evolveum.midpoint.ninja.util.Log) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) AuditResultHandler(com.evolveum.midpoint.audit.api.AuditResultHandler) GetOperationOptionsBuilder(com.evolveum.midpoint.schema.GetOperationOptionsBuilder) AuditService(com.evolveum.midpoint.audit.api.AuditService)

Example 3 with Log

use of com.evolveum.midpoint.ninja.util.Log in project midpoint by Evolveum.

the class Action method init.

public void init(NinjaContext context, O options) {
    this.context = context;
    this.options = options;
    LogTarget target = getInfoLogTarget();
    log = new Log(target, this.context);
    this.context.setLog(log);
    ConnectionOptions connection = Objects.requireNonNull(NinjaUtils.getOptions(this.context.getJc(), ConnectionOptions.class));
    this.context.init(connection);
}
Also used : Log(com.evolveum.midpoint.ninja.util.Log) ConnectionOptions(com.evolveum.midpoint.ninja.opts.ConnectionOptions) LogTarget(com.evolveum.midpoint.ninja.impl.LogTarget)

Example 4 with Log

use of com.evolveum.midpoint.ninja.util.Log in project midpoint by Evolveum.

the class AbstractWriterConsumerWorker method run.

@Override
public void run() {
    Log log = context.getLog();
    // todo handle split option
    init();
    try (Writer writer = createWriter()) {
        while (!shouldConsumerStop()) {
            T object = null;
            try {
                object = queue.poll(CONSUMER_POLL_TIMEOUT, TimeUnit.SECONDS);
                if (object == null) {
                    continue;
                }
                write(writer, object);
                writer.flush();
                operation.incrementTotal();
            } catch (Exception ex) {
                log.error("Couldn't store object {}, reason: {}", ex, object, ex.getMessage());
                operation.incrementError();
            }
        }
        finalizeWriter(writer);
    } catch (IOException ex) {
        log.error("Unexpected exception, reason: {}", ex, ex.getMessage());
    } catch (NinjaException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        markDone();
        if (isWorkersDone()) {
            operation.finish();
        }
    }
}
Also used : Log(com.evolveum.midpoint.ninja.util.Log) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) IOException(java.io.IOException) Writer(java.io.Writer) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException)

Example 5 with Log

use of com.evolveum.midpoint.ninja.util.Log in project midpoint by Evolveum.

the class ImportProducerWorker method run.

@Override
public void run() {
    Log log = context.getLog();
    log.info("Starting import");
    operation.start();
    try (InputStream input = openInputStream()) {
        if (!options.isZip()) {
            processStream(input);
        } else {
            ZipInputStream zis = new ZipInputStream(input);
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                if (entry.isDirectory()) {
                    continue;
                }
                if (!StringUtils.endsWith(entry.getName().toLowerCase(), ".xml")) {
                    continue;
                }
                log.info("Processing file {}", entry.getName());
                processStream(zis);
            }
        }
    } catch (IOException ex) {
        log.error("Unexpected error occurred, reason: {}", ex, ex.getMessage());
    } catch (NinjaException ex) {
        log.error(ex.getMessage(), ex);
    } finally {
        markDone();
        if (isWorkersDone()) {
            if (!operation.isFinished()) {
                operation.producerFinish();
            }
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) Log(com.evolveum.midpoint.ninja.util.Log) ZipInputStream(java.util.zip.ZipInputStream) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) ZipEntry(java.util.zip.ZipEntry) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException)

Aggregations

Log (com.evolveum.midpoint.ninja.util.Log)5 NinjaException (com.evolveum.midpoint.ninja.impl.NinjaException)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 NinjaContext (com.evolveum.midpoint.ninja.impl.NinjaContext)2 NinjaUtils (com.evolveum.midpoint.ninja.util.NinjaUtils)2 OperationStatus (com.evolveum.midpoint.ninja.util.OperationStatus)2 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 GetOperationOptionsBuilder (com.evolveum.midpoint.schema.GetOperationOptionsBuilder)2 List (java.util.List)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)1 AuditService (com.evolveum.midpoint.audit.api.AuditService)1 BaseWorker (com.evolveum.midpoint.ninja.action.worker.BaseWorker)1 LogTarget (com.evolveum.midpoint.ninja.impl.LogTarget)1 ConnectionOptions (com.evolveum.midpoint.ninja.opts.ConnectionOptions)1 ExportOptions (com.evolveum.midpoint.ninja.opts.ExportOptions)1 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)1 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)1 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)1 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)1