Search in sources :

Example 1 with ImportRepositoryConsumerWorker

use of com.evolveum.midpoint.ninja.action.worker.ImportRepositoryConsumerWorker in project midpoint by Evolveum.

the class ImportRepositoryAction method execute.

@Override
public void execute() throws Exception {
    OperationResult result = new OperationResult(OPERATION_IMPORT);
    OperationStatus progress = new OperationStatus(context, result);
    BlockingQueue<ObjectType> queue = new LinkedBlockingQueue<>(QUEUE_CAPACITY_PER_THREAD * options.getMultiThread());
    // "+ 2" will be used for producer and progress reporter
    ExecutorService executor = Executors.newFixedThreadPool(options.getMultiThread() + 2);
    ImportProducerWorker<ObjectType> producer;
    if (options.getOid() != null) {
        InOidFilter filter = context.getPrismContext().queryFactory().createInOid(options.getOid());
        producer = importByFilter(filter, true, queue, progress);
    } else {
        ObjectFilter filter = NinjaUtils.createObjectFilter(options.getFilter(), context, ObjectType.class);
        producer = importByFilter(filter, false, queue, progress);
    }
    executor.execute(producer);
    Thread.sleep(CONSUMERS_WAIT_FOR_START);
    executor.execute(new ProgressReporterWorker<>(context, options, queue, progress));
    List<ImportRepositoryConsumerWorker> consumers = createConsumers(queue, progress);
    consumers.forEach(c -> executor.execute(c));
    executor.shutdown();
    boolean awaitResult = executor.awaitTermination(NinjaUtils.WAIT_FOR_EXECUTOR_FINISH, TimeUnit.DAYS);
    if (!awaitResult) {
        log.error("Executor did not finish before timeout");
    }
    handleResultOnFinish(progress, "Import finished");
}
Also used : InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ImportRepositoryConsumerWorker(com.evolveum.midpoint.ninja.action.worker.ImportRepositoryConsumerWorker) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus)

Aggregations

ImportRepositoryConsumerWorker (com.evolveum.midpoint.ninja.action.worker.ImportRepositoryConsumerWorker)1 OperationStatus (com.evolveum.midpoint.ninja.util.OperationStatus)1 InOidFilter (com.evolveum.midpoint.prism.query.InOidFilter)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1