Search in sources :

Example 1 with OperationStatus

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

the class AbstractRepositorySearchAction method execute.

@Override
public void execute() throws Exception {
    OperationResult result = new OperationResult(getOperationName());
    OperationStatus operation = new OperationStatus(context, result);
    // "+ 2" will be used for consumer and progress reporter
    ExecutorService executor = Executors.newFixedThreadPool(options.getMultiThread() + 2);
    BlockingQueue<ObjectType> queue = new LinkedBlockingQueue<>(QUEUE_CAPACITY_PER_THREAD * options.getMultiThread());
    List<SearchProducerWorker> producers = createProducers(queue, operation);
    log.info("Starting " + getOperationShortName());
    operation.start();
    // execute as many producers as there are threads for them
    for (int i = 0; i < producers.size() && i < options.getMultiThread(); i++) {
        executor.execute(producers.get(i));
    }
    Thread.sleep(CONSUMERS_WAIT_FOR_START);
    executor.execute(new ProgressReporterWorker<>(context, options, queue, operation));
    Runnable consumer = createConsumer(queue, operation);
    executor.execute(consumer);
    // execute rest of the producers
    for (int i = options.getMultiThread(); i < producers.size(); i++) {
        executor.execute(producers.get(i));
    }
    executor.shutdown();
    boolean awaitResult = executor.awaitTermination(NinjaUtils.WAIT_FOR_EXECUTOR_FINISH, TimeUnit.DAYS);
    if (!awaitResult) {
        log.error("Executor did not finish before timeout");
    }
    handleResultOnFinish(operation, "Finished " + getOperationShortName());
}
Also used : SearchProducerWorker(com.evolveum.midpoint.ninja.action.worker.SearchProducerWorker) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 2 with OperationStatus

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

the class ExportAuditRepositoryAction method execute.

@Override
public void execute() throws Exception {
    OperationResult result = new OperationResult(OPERATION_NAME);
    OperationStatus operation = new OperationStatus(context, result);
    // "+ 2" will be used for consumer and progress reporter
    ExecutorService executor = Executors.newFixedThreadPool(options.getMultiThread() + 2);
    BlockingQueue<AuditEventRecordType> queue = new LinkedBlockingQueue<>(QUEUE_CAPACITY_PER_THREAD * options.getMultiThread());
    List<ExportAuditProducerWorker> producers = createProducers(queue, operation);
    log.info("Starting " + OPERATION_SHORT_NAME);
    operation.start();
    // execute as many producers as there are threads for them
    for (int i = 0; i < producers.size() && i < options.getMultiThread(); i++) {
        executor.execute(producers.get(i));
    }
    Thread.sleep(CONSUMERS_WAIT_FOR_START);
    executor.execute(new ProgressReporterWorker<>(context, options, queue, operation));
    Runnable consumer = createConsumer(queue, operation);
    executor.execute(consumer);
    // execute rest of the producers
    for (int i = options.getMultiThread(); i < producers.size(); i++) {
        executor.execute(producers.get(i));
    }
    executor.shutdown();
    boolean awaitResult = executor.awaitTermination(NinjaUtils.WAIT_FOR_EXECUTOR_FINISH, TimeUnit.DAYS);
    if (!awaitResult) {
        log.error("Executor did not finish before timeout");
    }
    handleResultOnFinish(operation, "Finished " + OPERATION_SHORT_NAME);
}
Also used : AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 3 with OperationStatus

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

Example 4 with OperationStatus

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

the class ImportAuditRepositoryAction method execute.

@Override
public void execute() throws Exception {
    OperationResult result = new OperationResult(OPERATION_NAME);
    OperationStatus progress = new OperationStatus(context, result);
    BlockingQueue<AuditEventRecordType> 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<AuditEventRecordType> producer;
    ObjectFilter filter = NinjaUtils.createObjectFilter(options.getFilter(), context, AuditEventRecordType.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<ImportAuditConsumerWorker> 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, "Audit import finished");
}
Also used : AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 5 with OperationStatus

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

the class DeleteRepositoryAction method deleteByFilter.

private void deleteByFilter(ObjectTypes type, ObjectQuery query, OperationStatus operation, OperationResult result) throws SchemaException {
    ResultHandler<?> handler = (prismObject, operationResult) -> {
        try {
            State state = options.isAsk() ? askForState(prismObject) : State.DELETE;
            switch(state) {
                case SKIP:
                    operation.incrementSkipped();
                    return true;
                case STOP:
                    return false;
                case DELETE:
                default:
            }
            RepositoryService repository = context.getRepository();
            repository.deleteObject(prismObject.getCompileTimeClass(), prismObject.getOid(), operationResult);
            operation.incrementTotal();
        } catch (ObjectNotFoundException ex) {
        // object was already gone
        } catch (IOException ex) {
            context.getLog().error("Couldn't delete object {}, reason: {}", ex, prismObject, ex.getMessage());
            operation.incrementError();
        }
        return true;
    };
    Collection<SelectorOptions<GetOperationOptions>> opts = new ArrayList<>();
    if (options.isRaw()) {
        opts.add(new SelectorOptions<>(GetOperationOptions.createRaw()));
    }
    RepositoryService repository = context.getRepository();
    repository.searchObjectsIterative(type.getClassDefinition(), query, handler, opts, true, result);
}
Also used : ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QueryFactory(com.evolveum.midpoint.prism.query.QueryFactory) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationStatus(com.evolveum.midpoint.ninja.util.OperationStatus) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) NinjaUtils(com.evolveum.midpoint.ninja.util.NinjaUtils) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) PrismObject(com.evolveum.midpoint.prism.PrismObject) DeleteOptions(com.evolveum.midpoint.ninja.opts.DeleteOptions) InputStreamReader(java.io.InputStreamReader) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) InOidFilter(com.evolveum.midpoint.prism.query.InOidFilter) Modifier(java.lang.reflect.Modifier) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) BufferedReader(java.io.BufferedReader) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Aggregations

OperationStatus (com.evolveum.midpoint.ninja.util.OperationStatus)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 InOidFilter (com.evolveum.midpoint.prism.query.InOidFilter)2 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)2 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)2 ImportRepositoryConsumerWorker (com.evolveum.midpoint.ninja.action.worker.ImportRepositoryConsumerWorker)1 SearchProducerWorker (com.evolveum.midpoint.ninja.action.worker.SearchProducerWorker)1 DeleteOptions (com.evolveum.midpoint.ninja.opts.DeleteOptions)1 NinjaUtils (com.evolveum.midpoint.ninja.util.NinjaUtils)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 QueryFactory (com.evolveum.midpoint.prism.query.QueryFactory)1 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1