Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 8, 2021
2 parents d76fe43 + 33a6867 commit 7055b56
Show file tree
Hide file tree
Showing 17 changed files with 434 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
/*
* Copyright (c) 2010-2019 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.audit.api;

import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;

/**
* Handler interface for {@link AuditService#searchObjectsIterative}.
*/
@FunctionalInterface
@Experimental
public interface AuditResultHandler {

@Deprecated
default boolean handle(AuditEventRecord auditRecord){
return true;
}

boolean handle(AuditEventRecordType auditRecord);

int getProgress();
/**
* Handle a single audit event record.
*
* @param eventRecord audit event record to process
* @return true if the operation should proceed, false if it should stop
*/
boolean handle(AuditEventRecordType eventRecord, OperationResult parentResult);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SearchResultMetadata;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType;
Expand All @@ -35,6 +37,8 @@ public interface AuditService {
String OP_CLEANUP_AUDIT_MAX_RECORDS = "cleanupAuditMaxRecords";
String OP_COUNT_OBJECTS = "countObjects";
String OP_SEARCH_OBJECTS = "searchObjects";
String OP_SEARCH_OBJECTS_ITERATIVE = "searchObjectsIterative";
String OP_SEARCH_OBJECTS_ITERATIVE_PAGE = "searchObjectsIterativePage";

void audit(AuditEventRecord record, Task task, OperationResult result);

Expand Down Expand Up @@ -87,4 +91,20 @@ SearchResultList<AuditEventRecordType> searchObjects(
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult)
throws SchemaException;

/**
* Executes iterative search using the provided `handler` to process each object.
*
* @param query search query
* @param handler result handler
* @param options get options to use for the search
* @param parentResult parent OperationResult (in/out)
* @return summary information about the search result
*/
@Experimental
SearchResultMetadata searchObjectsIterative(
@Nullable ObjectQuery query,
@NotNull AuditResultHandler handler,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult) throws SchemaException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
import org.slf4j.LoggerFactory;

import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.audit.api.AuditResultHandler;
import com.evolveum.midpoint.audit.api.AuditService;
import com.evolveum.midpoint.common.LoggingConfigurationManager;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.SearchResultList;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
Expand Down Expand Up @@ -169,4 +168,13 @@ public SearchResultList<AuditEventRecordType> searchObjects(
@NotNull OperationResult parentResult) {
throw new UnsupportedOperationException("searchObjects not supported");
}

@Override
public SearchResultMetadata searchObjectsIterative(
@Nullable ObjectQuery query,
@NotNull AuditResultHandler handler,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult) throws SchemaException {
throw new UnsupportedOperationException("searchObjectsIterative not supported");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -390,24 +390,29 @@ <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
OperationResult parentResult) throws SchemaException;

/**
* <p>Search for objects in the repository in an iterative fashion.</p>
* <p>Searches through all object types. Calls a specified handler for each object found.
* If no search criteria specified, list of all objects of specified type is returned.</p>
* <p>
* Search for objects in the repository in an iterative fashion.
*
* Searches through all object types. Calls a specified handler for each object found.
* If no search criteria specified, list of all objects of specified type is returned.
*
* Searches through all object types.
* Returns a list of objects that match search criteria.
* </p><p>
*
* Returns empty list if object type is correct but there are no objects of
* that type. The ordering of the results is not significant and may be arbitrary
* unless sorting in the paging is used.
* </p><p>
*
* Should fail if object type is wrong. Should fail if unknown property is
* specified in the query.
* </p>
* <p>
* A note related to iteration method:
* <p>
* There are three iteration methods (see IterationMethodType):
*
* [NOTE]
* ====
* New repository uses single reliable iteration method similar to strictly sequential paging
* and supports custom ordering (currently only one).
* New repository ignores strictlySequential parameter and related get options completely.
*
* In old repository there are three iteration methods (see IterationMethodType):
*
* - SINGLE_TRANSACTION: Fetches objects in single DB transaction. Not supported for all DBMSs.
* - SIMPLE_PAGING: Uses the "simple paging" method: takes objects (e.g.) numbered 0 to 49, then 50 to 99,
* then 100 to 149, and so on. The disadvantage is that if the order of objects is changed
Expand All @@ -416,25 +421,26 @@ <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
* - STRICTLY_SEQUENTIAL_PAGING: Uses the "strictly sequential paging" method: sorting returned objects by OID. This
* is (almost) reliable in such a way that no object would be skipped. However, custom
* paging cannot be used in this mode.
* <p>
*
* If GetOperationOptions.iterationMethod is specified, it is used without any further considerations.
* Otherwise, the repository configuration determines whether to use SINGLE_TRANSACTION or a paging. In the latter case,
* strictlySequential flag determines between SIMPLE_PAGING (if false) and STRICTLY_SEQUENTIAL_PAGING (if true).
* <p>
*
* If explicit GetOperationOptions.iterationMethod is not provided, and paging is prescribed, and strictlySequential flag
* is true and client-provided paging conflicts with the paging used by the iteration method, a warning is issued, and
* iteration method is switched to SIMPLE_PAGING.
* <p>
* ====
*
* Sources of conflicts:
* - ordering is specified
* - offset is specified
* (limit is not a problem)
*
* @param query search query
* @param handler result handler
* @param strictlySequential takes care not to skip any object nor to process objects more than once; see below
* @param strictlySequential takes care not to skip any object nor to process objects more than once
* @param parentResult parent OperationResult (in/out)
* @return all objects of specified type that match search criteria (subject to paging)
* @return summary information about the search result
* @throws IllegalArgumentException wrong object type
* @throws SchemaException unknown property used in search query
*/
Expand Down
1 change: 0 additions & 1 deletion repo/repo-sqale/sql/pgnew-repo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,6 @@ BEGIN
END IF;
END; $$;
-- endregion
-- endregion

-- region OTHER object tables
-- Represents ResourceType, see https://wiki.evolveum.com/display/midPoint/Resource+Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ private <T extends ObjectType> SearchResultMetadata executeSearchObjectsIterativ
prismContext()));

// we don't call public searchObject to avoid subresults and query simplification
logSearchInputParameters(type, pagedQuery, "Search object iterative page ");
logSearchInputParameters(type, pagedQuery, "Search object iterative page");
List<PrismObject<T>> objects = executeSearchObject(
type, pagedQuery, options, OP_SEARCH_OBJECTS_ITERATIVE_PAGE);

Expand Down Expand Up @@ -1201,33 +1201,6 @@ private <T extends Containerable> SearchResultList<T> executeSearchContainers(Cl
registerOperationFinish(opHandle, 1);
}
}

private <T> void logSearchInputParameters(Class<T> type, ObjectQuery query, String operation) {
ObjectPaging paging = query != null ? query.getPaging() : null;
logger.debug(
"{} of type '{}', query on trace level, offset {}, limit {}.",
operation, type.getSimpleName(),
paging != null ? paging.getOffset() : "undefined",
paging != null ? paging.getMaxSize() : "undefined");

logger.trace("Full query\n{}",
query == null ? "undefined" : query.debugDumpLazily());
}

private ObjectQuery simplifyQuery(ObjectQuery query) {
if (query != null) {
// simplify() creates new filter instance which can be modified
ObjectFilter filter = ObjectQueryUtil.simplify(query.getFilter(), prismContext());
query = query.cloneWithoutFilter();
query.setFilter(filter instanceof AllFilter ? null : filter);
}

return query;
}

private boolean isNoneQuery(ObjectQuery query) {
return query != null && query.getFilter() instanceof NoneFilter;
}
// endregion

@Override
Expand Down Expand Up @@ -1910,8 +1883,4 @@ private <T extends ObjectType> boolean pruneDiagnosticInformation(
public SqlPerformanceMonitorImpl getPerformanceMonitor() {
return performanceMonitor;
}

private PrismContext prismContext() {
return sqlRepoContext.prismContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.repo.api.SqlPerformanceMonitorsCollection;
import com.evolveum.midpoint.repo.sqlbase.JdbcRepositoryConfiguration;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -59,6 +61,10 @@ protected JdbcRepositoryConfiguration repositoryConfiguration() {
return sqlRepoContext.getJdbcRepositoryConfiguration();
}

protected PrismContext prismContext() {
return sqlRepoContext.prismContext();
}

// region exception handling

/**
Expand Down Expand Up @@ -128,6 +134,35 @@ protected boolean isFatalException(Throwable ex) {
}
// endregion

// region search support methods
protected <T> void logSearchInputParameters(Class<T> type, ObjectQuery query, String operation) {
ObjectPaging paging = query != null ? query.getPaging() : null;
logger.debug(
"{} of type '{}' (full query on trace level), offset {}, limit {}.",
operation, type.getSimpleName(),
paging != null ? paging.getOffset() : "undefined",
paging != null ? paging.getMaxSize() : "undefined");

logger.trace("Full query\n{}",
query == null ? "undefined" : query.debugDumpLazily());
}

protected ObjectQuery simplifyQuery(ObjectQuery query) {
if (query != null) {
// simplify() creates new filter instance which can be modified
ObjectFilter filter = ObjectQueryUtil.simplify(query.getFilter(), prismContext());
query = query.cloneWithoutFilter();
query.setFilter(filter instanceof AllFilter ? null : filter);
}

return query;
}

protected boolean isNoneQuery(ObjectQuery query) {
return query != null && query.getFilter() instanceof NoneFilter;
}
// endregion

// region perf monitoring

/**
Expand Down
Loading

0 comments on commit 7055b56

Please sign in to comment.