Search in sources :

Example 6 with NinjaException

use of com.evolveum.midpoint.ninja.impl.NinjaException 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 7 with NinjaException

use of com.evolveum.midpoint.ninja.impl.NinjaException 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)

Example 8 with NinjaException

use of com.evolveum.midpoint.ninja.impl.NinjaException in project midpoint by Evolveum.

the class ImportProducerWorker method openInputStream.

private InputStream openInputStream() throws IOException {
    File input = options.getInput();
    InputStream is;
    if (input != null) {
        if (!input.exists()) {
            throw new NinjaException("Import file '" + input.getPath() + "' doesn't exist");
        }
        is = new FileInputStream(input);
    } else {
        is = System.in;
    }
    return is;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException)

Aggregations

NinjaException (com.evolveum.midpoint.ninja.impl.NinjaException)8 Log (com.evolveum.midpoint.ninja.util.Log)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)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 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)2 GetOperationOptionsBuilder (com.evolveum.midpoint.schema.GetOperationOptionsBuilder)2 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 List (java.util.List)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 ZipEntry (java.util.zip.ZipEntry)2 ZipInputStream (java.util.zip.ZipInputStream)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)1 AuditService (com.evolveum.midpoint.audit.api.AuditService)1 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)1 LegacyValidator (com.evolveum.midpoint.common.validator.LegacyValidator)1