Search in sources :

Example 1 with SearchProducerWorker

use of com.evolveum.midpoint.ninja.action.worker.SearchProducerWorker 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 SearchProducerWorker

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

the class AbstractRepositorySearchAction method createProducers.

private List<SearchProducerWorker> createProducers(BlockingQueue<ObjectType> queue, OperationStatus operation) throws SchemaException, IOException {
    QueryFactory queryFactory = context.getPrismContext().queryFactory();
    List<SearchProducerWorker> producers = new ArrayList<>();
    if (options.getOid() != null) {
        Set<ObjectTypes> types = options.getType();
        ObjectTypes type = types.isEmpty() ? ObjectTypes.OBJECT : types.iterator().next();
        InOidFilter filter = queryFactory.createInOid(options.getOid());
        ObjectQuery query = queryFactory.createQuery(filter);
        producers.add(new SearchProducerWorker(context, options, queue, operation, producers, type, query));
        return producers;
    }
    List<ObjectTypes> types = NinjaUtils.getTypes(options.getType());
    for (ObjectTypes type : types) {
        ObjectFilter filter = NinjaUtils.createObjectFilter(options.getFilter(), context, type.getClassDefinition());
        ObjectQuery query = queryFactory.createQuery(filter);
        if (ObjectTypes.SHADOW.equals(type)) {
            List<SearchProducerWorker> shadowProducers = createProducersForShadows(context, queue, operation, producers, filter);
            producers.addAll(shadowProducers);
            continue;
        }
        producers.add(new SearchProducerWorker(context, options, queue, operation, producers, type, query));
    }
    return producers;
}
Also used : SearchProducerWorker(com.evolveum.midpoint.ninja.action.worker.SearchProducerWorker) ArrayList(java.util.ArrayList) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes)

Example 3 with SearchProducerWorker

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

the class AbstractRepositorySearchAction method createProducersForShadows.

/**
 * The idea is to split shadow per resource. We will get more producer workers in this way, therefore we can
 * run in more threads. No extra special processing is done for shadows. Just to split them to workers for
 * performance reasons.
 */
private List<SearchProducerWorker> createProducersForShadows(NinjaContext context, BlockingQueue<ObjectType> queue, OperationStatus operation, List<SearchProducerWorker> producers, ObjectFilter filter) {
    QueryFactory queryFactory = context.getPrismContext().queryFactory();
    List<SearchProducerWorker> shadowProducers = new ArrayList<>();
    try {
        RepositoryService repository = context.getRepository();
        Collection<SelectorOptions<GetOperationOptions>> opts = SelectorOptions.createCollection(GetOperationOptions.createRaw());
        OperationResult result = new OperationResult(OPERATION_LIST_RESOURCES);
        SearchResultList<PrismObject<ResourceType>> resultList = repository.searchObjects(ResourceType.class, queryFactory.createQuery((ObjectFilter) null), opts, result);
        List<PrismObject<ResourceType>> list = resultList.getList();
        if (list == null || list.isEmpty()) {
            shadowProducers.add(createShadowProducer(queue, operation, producers, filter));
            return shadowProducers;
        }
        List<RefFilter> existingResourceRefs = new ArrayList<>();
        for (PrismObject<ResourceType> obj : list) {
            RefFilter resourceRefFilter = createResourceRefFilter(obj.getOid());
            existingResourceRefs.add(resourceRefFilter);
            ObjectFilter fullFilter = resourceRefFilter;
            if (filter != null) {
                fullFilter = queryFactory.createAnd(fullFilter, filter);
            }
            shadowProducers.add(createShadowProducer(queue, operation, producers, fullFilter));
        }
        // all other shadows (no resourceRef or non-existing resourceRef)
        List<ObjectFilter> notFilters = new ArrayList<>();
        existingResourceRefs.forEach(f -> notFilters.add(queryFactory.createNot(f)));
        ObjectFilter fullFilter = queryFactory.createOr(queryFactory.createAnd(notFilters), createResourceRefFilter(null));
        if (filter != null) {
            fullFilter = queryFactory.createAnd(fullFilter, filter);
        }
        shadowProducers.add(createShadowProducer(queue, operation, producers, fullFilter));
    } catch (Exception ex) {
        shadowProducers.clear();
        shadowProducers.add(createShadowProducer(queue, operation, producers, filter));
    }
    return shadowProducers;
}
Also used : SearchProducerWorker(com.evolveum.midpoint.ninja.action.worker.SearchProducerWorker) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService)

Aggregations

SearchProducerWorker (com.evolveum.midpoint.ninja.action.worker.SearchProducerWorker)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ArrayList (java.util.ArrayList)2 OperationStatus (com.evolveum.midpoint.ninja.util.OperationStatus)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)1 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)1 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 IOException (java.io.IOException)1