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