Search in sources :

Example 26 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method modifyObjectDynamically.

@NotNull
@Override
@Experimental
public <T extends ObjectType> ModifyObjectResult<T> modifyObjectDynamically(@NotNull Class<T> type, @NotNull String oid, @Nullable Collection<SelectorOptions<GetOperationOptions>> getOptions, @NotNull ModificationsSupplier<T> modificationsSupplier, RepoModifyOptions modifyOptions, @NotNull OperationResult parentResult) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
    Validate.notNull(type, "Object class in delta must not be null.");
    Validate.notEmpty(oid, "Oid must not null or empty.");
    Validate.notNull(modificationsSupplier, "Modifications supplier must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    // TODO executeAttempts?
    final String operation = "modifying";
    int attempt = 1;
    int restarts = 0;
    boolean noFetchExtensionValueInsertionForbidden = false;
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(OP_MODIFY_OBJECT_DYNAMICALLY, type);
    OperationResult result = parentResult.subresult(MODIFY_OBJECT_DYNAMICALLY).addQualifier(type.getSimpleName()).addParam("type", type.getName()).addParam("oid", oid).build();
    ModifyObjectResult<T> rv = null;
    try {
        while (true) {
            try {
                ModificationsSupplier<T> innerModificationsSupplier = object -> {
                    Collection<? extends ItemDelta<?, ?>> modifications = modificationsSupplier.get(object);
                    checkModifications(modifications);
                    logNameChange(modifications);
                    return modifications;
                };
                rv = objectUpdater.modifyObjectDynamicallyAttempt(type, oid, getOptions, innerModificationsSupplier, modifyOptions, attempt, result, this, noFetchExtensionValueInsertionForbidden);
                invokeConflictWatchers((w) -> w.afterModifyObject(oid));
                rv.setPerformanceRecord(pm.registerOperationFinish(opHandle, attempt));
                return rv;
            } catch (RestartOperationRequestedException ex) {
                // special case: we want to restart but we do not want to count these
                LOGGER.trace("Restarting because of {}", ex.getMessage());
                restarts++;
                if (restarts > RESTART_LIMIT) {
                    throw new IllegalStateException("Too many operation restarts");
                } else if (ex.isForbidNoFetchExtensionValueAddition()) {
                    noFetchExtensionValueInsertionForbidden = true;
                }
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, result);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } catch (Throwable t) {
        LOGGER.debug("Got exception while processing dynamic modifications on {}:{}", type.getSimpleName(), oid, t);
        pm.registerOperationFinish(opHandle, attempt);
        throw t;
    } finally {
        OperationLogger.logModifyDynamically(type, oid, rv, modifyOptions, result);
    }
}
Also used : Connection(java.sql.Connection) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) Autowired(org.springframework.beans.factory.annotation.Autowired) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) PreDestroy(javax.annotation.PreDestroy) ConflictWatcherImpl(com.evolveum.midpoint.repo.sqlbase.ConflictWatcherImpl) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) com.evolveum.midpoint.repo.api(com.evolveum.midpoint.repo.api) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) Experimental(com.evolveum.midpoint.util.annotation.Experimental) OperationLogger(com.evolveum.midpoint.repo.sqlbase.OperationLogger) SessionFactory(org.hibernate.SessionFactory) Collectors(java.util.stream.Collectors) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) Nullable(org.jetbrains.annotations.Nullable) Dialect(org.hibernate.dialect.Dialect) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PostConstruct(javax.annotation.PostConstruct) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) QName(javax.xml.namespace.QName) CollectionUtils.emptyIfNull(org.apache.commons.collections4.CollectionUtils.emptyIfNull) NotNull(org.jetbrains.annotations.NotNull) FocusTypeUtil(com.evolveum.midpoint.schema.util.FocusTypeUtil) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ObjectFilterExpressionEvaluator(com.evolveum.midpoint.repo.api.query.ObjectFilterExpressionEvaluator) CryptoUtil(com.evolveum.midpoint.common.crypto.CryptoUtil) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Session(org.hibernate.Session) ItemDeltaCollectionsUtil(com.evolveum.midpoint.prism.delta.ItemDeltaCollectionsUtil) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) Supplier(java.util.function.Supplier) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) com.evolveum.midpoint.repo.sql.helpers(com.evolveum.midpoint.repo.sql.helpers) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) Consumer(java.util.function.Consumer) Validate(org.apache.commons.lang3.Validate) Driver(java.sql.Driver) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) DriverManager(java.sql.DriverManager) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Experimental(com.evolveum.midpoint.util.annotation.Experimental) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method executeAttempts.

private <RV> RV executeAttempts(String oid, String operationName, Class<?> type, String operationVerb, OperationResult subResult, ResultSupplier<RV> supplier) throws ObjectNotFoundException, SchemaException {
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(operationName, type);
    int attempt = 1;
    try {
        while (true) {
            try {
                return supplier.get();
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, operationVerb, attempt, ex, subResult);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)

Example 28 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method advanceSequence.

@Override
public long advanceSequence(String oid, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    Validate.notEmpty(oid, "Oid must not null or empty.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    OperationResult result = parentResult.subresult(ADVANCE_SEQUENCE).addParam("oid", oid).build();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Advancing sequence {}", oid);
    }
    // TODO executeAttempts
    int attempt = 1;
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(OP_ADVANCE_SEQUENCE, SequenceType.class);
    try {
        while (true) {
            try {
                return sequenceHelper.advanceSequenceAttempt(oid, result);
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, "advanceSequence", attempt, ex, null);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 29 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method executeQueryAttempts.

private <RV> RV executeQueryAttempts(ObjectQuery query, String operationName, Class<?> type, String operationVerb, OperationResult subResult, Supplier<RV> emptyQueryResultSupplier, ResultQueryBasedSupplier<RV> supplier) throws SchemaException {
    if (query != null) {
        query = simplify(query, subResult);
        if (query == null) {
            return emptyQueryResultSupplier.get();
        }
    }
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(operationName, type);
    int attempt = 1;
    try {
        while (true) {
            try {
                return supplier.get(query);
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(null, operationVerb, attempt, ex, subResult);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)

Example 30 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqlRepositoryServiceImpl method modifyObject.

@NotNull
@Override
public <T extends ObjectType> ModifyObjectResult<T> modifyObject(@NotNull Class<T> type, @NotNull String oid, @NotNull Collection<? extends ItemDelta<?, ?>> modifications, ModificationPrecondition<T> precondition, RepoModifyOptions options, @NotNull OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException, PreconditionViolationException {
    Validate.notNull(modifications, "Modifications must not be null.");
    Validate.notNull(type, "Object class in delta must not be null.");
    Validate.notEmpty(oid, "Oid must not null or empty.");
    Validate.notNull(result, "Operation result must not be null.");
    OperationResult subResult = result.subresult(MODIFY_OBJECT).addQualifier(type.getSimpleName()).addParam("type", type.getName()).addParam("oid", oid).addArbitraryObjectCollectionAsParam("modifications", modifications).build();
    if (modifications.isEmpty() && !RepoModifyOptions.isForceReindex(options)) {
        LOGGER.debug("Modification list is empty, nothing was modified.");
        subResult.recordStatus(OperationResultStatus.SUCCESS, "Modification list is empty, nothing was modified.");
        return new ModifyObjectResult<>(modifications);
    }
    checkModifications(modifications);
    logNameChange(modifications);
    // TODO executeAttempts?
    final String operation = "modifying";
    int attempt = 1;
    int restarts = 0;
    boolean noFetchExtensionValueInsertionForbidden = false;
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart(OP_MODIFY_OBJECT, type);
    try {
        while (true) {
            try {
                ModifyObjectResult<T> rv = objectUpdater.modifyObjectAttempt(type, oid, modifications, precondition, options, attempt, subResult, this, noFetchExtensionValueInsertionForbidden, null);
                invokeConflictWatchers((w) -> w.afterModifyObject(oid));
                rv.setPerformanceRecord(pm.registerOperationFinish(opHandle, attempt));
                return rv;
            } catch (RestartOperationRequestedException ex) {
                // special case: we want to restart but we do not want to count these
                LOGGER.trace("Restarting because of {}", ex.getMessage());
                restarts++;
                if (restarts > RESTART_LIMIT) {
                    throw new IllegalStateException("Too many operation restarts");
                } else if (ex.isForbidNoFetchExtensionValueAddition()) {
                    noFetchExtensionValueInsertionForbidden = true;
                }
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, subResult);
                pm.registerOperationNewAttempt(opHandle, attempt);
            }
        }
    } catch (Throwable t) {
        LOGGER.debug("Got exception while processing modifications on {}:{}:\n{}", type.getSimpleName(), oid, DebugUtil.debugDump(modifications), t);
        pm.registerOperationFinish(opHandle, attempt);
        throw t;
    } finally {
        OperationLogger.logModify(type, oid, modifications, precondition, options, subResult);
    }
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SqlPerformanceMonitorImpl (com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)34 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)25 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)16 Test (org.testng.annotations.Test)16 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 QUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser)5 NotNull (org.jetbrains.annotations.NotNull)5 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)3 com.evolveum.midpoint.prism.query (com.evolveum.midpoint.prism.query)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 Collectors (java.util.stream.Collectors)3 Nullable (org.jetbrains.annotations.Nullable)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ChangeType (com.evolveum.midpoint.prism.delta.ChangeType)2