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());
}
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;
}
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;
}
Aggregations