Skip to content

Commit

Permalink
repo old/new/audit/API: fixes of OP_* constant usage, move to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Aug 24, 2021
1 parent 4cb640d commit 1474945
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2020 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.
Expand Down Expand Up @@ -32,6 +32,14 @@ public interface AuditService {
int MAX_MESSAGE_SIZE = 1024;
int MAX_PROPERTY_SIZE = 1024;

String OP_AUDIT = "audit";
String OP_CLEANUP_AUDIT_MAX_AGE = "cleanupAuditMaxAge";
String OP_CLEANUP_AUDIT_MAX_RECORDS = "cleanupAuditMaxRecords";
String OP_COUNT_OBJECTS = "countObjects";
String OP_LIST_RECORDS = "listRecords";
String OP_LOAD_AUDIT_DELTA = "loadAuditDelta";
String OP_SEARCH_OBJECTS = "searchObjects";

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public interface RepositoryService {
String OP_MODIFY_OBJECT = "modifyObject";
String OP_MODIFY_OBJECT_DYNAMICALLY = "modifyObjectDynamically";
String OP_GET_VERSION = "getVersion";
String OP_IS_ANY_SUBORDINATE = "isAnySubordinate"; // TODO remove with old repo, not public op anymore
String OP_IS_DESCENDANT = "isDescendant";
String OP_IS_ANCESTOR = "isAncestor";
String OP_ADVANCE_SEQUENCE = "advanceSequence";
Expand All @@ -136,6 +135,7 @@ public interface RepositoryService {
String OP_REPOSITORY_SELF_TEST = "repositorySelfTest";
String OP_TEST_ORG_CLOSURE_CONSISTENCY = "testOrgClosureConsistency";

// Not used by new repo, instead class specific prefix + OP_* constants are used
String GET_OBJECT = CLASS_NAME_WITH_DOT + OP_GET_OBJECT;
String ADD_OBJECT = CLASS_NAME_WITH_DOT + OP_ADD_OBJECT;
String DELETE_OBJECT = CLASS_NAME_WITH_DOT + OP_DELETE_OBJECT;
Expand All @@ -153,8 +153,6 @@ public interface RepositoryService {
String EXECUTE_QUERY_DIAGNOSTICS = CLASS_NAME_WITH_DOT + OP_EXECUTE_QUERY_DIAGNOSTICS;
String ADD_DIAGNOSTIC_INFORMATION = CLASS_NAME_WITH_DOT + OP_ADD_DIAGNOSTIC_INFORMATION;
String HAS_CONFLICT = CLASS_NAME_WITH_DOT + OP_HAS_CONFLICT;
String REPOSITORY_SELF_TEST = CLASS_NAME_WITH_DOT + OP_REPOSITORY_SELF_TEST;
String TEST_ORG_CLOSURE_CONSISTENCY = CLASS_NAME_WITH_DOT + OP_TEST_ORG_CLOSURE_CONSISTENCY;

String KEY_DIAG_DATA = "repositoryDiagData"; // see GetOperationOptions.attachDiagData
String KEY_ORIGINAL_OBJECT = "repositoryOriginalObject";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public <T extends ObjectType> String getVersion(

LOGGER.debug("Getting version for {} with oid '{}'.", type.getSimpleName(), oid);

OperationResult operationResult = parentResult.subresult(GET_VERSION)
OperationResult operationResult = parentResult.subresult(OP_NAME_PREFIX + OP_GET_VERSION)
.addQualifier(type.getSimpleName())
.addParam("type", type.getName())
.addParam("oid", oid)
Expand Down Expand Up @@ -849,7 +849,7 @@ public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(
Validate.notNull(handler, "Result handler must not be null.");
Validate.notNull(parentResult, "Operation result must not be null.");

OperationResult operationResult = parentResult.subresult(SEARCH_OBJECTS_ITERATIVE)
OperationResult operationResult = parentResult.subresult(OP_NAME_PREFIX + OP_SEARCH_OBJECTS_ITERATIVE)
.addQualifier(type.getSimpleName())
.addParam("type", type.getName())
.addParam("query", query)
Expand Down Expand Up @@ -1272,7 +1272,7 @@ public long advanceSequence(String oid, OperationResult parentResult)

LOGGER.debug("Advancing sequence {}", oid);

OperationResult operationResult = parentResult.subresult(ADVANCE_SEQUENCE)
OperationResult operationResult = parentResult.subresult(OP_NAME_PREFIX + OP_ADVANCE_SEQUENCE)
.addParam("oid", oid)
.build();

Expand Down Expand Up @@ -1358,9 +1358,10 @@ public void returnUnusedValuesToSequence(

LOGGER.debug("Returning unused values of {} to sequence {}", unusedValues, oid);

OperationResult operationResult = parentResult.subresult(RETURN_UNUSED_VALUES_TO_SEQUENCE)
.addParam("oid", oid)
.build();
OperationResult operationResult =
parentResult.subresult(OP_NAME_PREFIX + OP_RETURN_UNUSED_VALUES_TO_SEQUENCE)
.addParam("oid", oid)
.build();

if (unusedValues == null || unusedValues.isEmpty()) {
operationResult.recordSuccess();
Expand Down Expand Up @@ -1506,7 +1507,8 @@ private String getTransactionIsolation(

@Override
public void repositorySelfTest(OperationResult parentResult) {
OperationResult operationResult = parentResult.createSubresult(REPOSITORY_SELF_TEST);
OperationResult operationResult =
parentResult.createSubresult(OP_NAME_PREFIX + OP_REPOSITORY_SELF_TEST);
try (JdbcSession jdbcSession = repositoryContext.newJdbcSession().startTransaction()) {
long startMs = System.currentTimeMillis();
jdbcSession.executeStatement("select 1");
Expand All @@ -1521,9 +1523,10 @@ public void repositorySelfTest(OperationResult parentResult) {

@Override
public void testOrgClosureConsistency(boolean repairIfNecessary, OperationResult parentResult) {
OperationResult operationResult = parentResult.subresult(TEST_ORG_CLOSURE_CONSISTENCY)
.addParam("repairIfNecessary", repairIfNecessary)
.build();
OperationResult operationResult =
parentResult.subresult(OP_NAME_PREFIX + OP_TEST_ORG_CLOSURE_CONSISTENCY)
.addParam("repairIfNecessary", repairIfNecessary)
.build();

try {
long closureCount, expectedCount;
Expand Down Expand Up @@ -1773,11 +1776,12 @@ public <T extends ObjectType> void addDiagnosticInformation(Class<T> type, Strin
DiagnosticInformationType information, OperationResult parentResult)
throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {

OperationResult operationResult = parentResult.subresult(ADD_DIAGNOSTIC_INFORMATION)
.addQualifier(type.getSimpleName())
.addParam("type", type)
.addParam("oid", oid)
.build();
OperationResult operationResult =
parentResult.subresult(OP_NAME_PREFIX + OP_ADD_DIAGNOSTIC_INFORMATION)
.addQualifier(type.getSimpleName())
.addParam("type", type)
.addParam("oid", oid)
.build();
try {
PrismObject<T> object = getObject(type, oid, null, operationResult);
// TODO when on limit this calls modify twice, wouldn't single modify be better?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ public class SqlAuditServiceImpl extends SqlBaseService implements AuditService

private static final String OP_NAME_PREFIX = SqlAuditServiceImpl.class.getSimpleName() + '.';

private static final String OP_CLEANUP_AUDIT_MAX_AGE = "cleanupAuditMaxAge";
private static final String OP_CLEANUP_AUDIT_MAX_RECORDS = "cleanupAuditMaxRecords";
private static final String OP_LIST_RECORDS = "listRecords";
private static final String OP_LIST_RECORDS_ATTEMPT = "listRecordsAttempt";
private static final String OP_LOAD_AUDIT_DELTA = "loadAuditDelta";

private static final Integer CLEANUP_AUDIT_BATCH_SIZE = 500;

Expand Down Expand Up @@ -130,17 +126,16 @@ public void audit(AuditEventRecord record, Task task, OperationResult result) {
Objects.requireNonNull(record, "Audit event record must not be null.");
Objects.requireNonNull(task, "Task must not be null.");

final String operation = "audit";
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(operation, AuditEventRecord.class);
long opHandle = pm.registerOperationStart(OP_AUDIT, AuditEventRecord.class);
int attempt = 1;

while (true) {
try {
auditAttempt(record);
return;
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, result);
attempt = baseHelper.logOperationAttempt(null, OP_AUDIT, attempt, ex, result);
pm.registerOperationNewAttempt(opHandle, attempt);
} finally {
pm.registerOperationFinish(opHandle, attempt);
Expand Down Expand Up @@ -389,9 +384,8 @@ private void insertResourceOids(
@Deprecated
public List<AuditEventRecord> listRecords(
String query, Map<String, Object> params, OperationResult parentResult) {
final String operation = "listRecords";
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(operation, AuditEventRecord.class);
long opHandle = pm.registerOperationStart(OP_LIST_RECORDS, AuditEventRecord.class);
int attempt = 1;

OperationResult result = parentResult.subresult(OP_LIST_RECORDS)
Expand Down Expand Up @@ -424,7 +418,7 @@ public int getProgress() {
listRecordsIterativeAttempt(query, params, handler, attemptResult);
return auditEventRecords;
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(null, operation, attempt, ex, null);
attempt = baseHelper.logOperationAttempt(null, OP_LIST_RECORDS, attempt, ex, null);
pm.registerOperationNewAttempt(opHandle, attempt);
LOGGER.error("Error while trying to list audit records, {}", ex.getMessage(), ex);
attemptResult.recordFatalError(
Expand Down Expand Up @@ -1119,7 +1113,7 @@ public int countObjects(
@Nullable ObjectQuery query,
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult) {
OperationResult operationResult = parentResult.subresult(OP_NAME_PREFIX + "countObjects")
OperationResult operationResult = parentResult.subresult(OP_NAME_PREFIX + OP_COUNT_OBJECTS)
.addParam("query", query)
.build();

Expand All @@ -1145,7 +1139,7 @@ public SearchResultList<AuditEventRecordType> searchObjects(
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult)
throws SchemaException {
OperationResult operationResult = parentResult.subresult(OP_NAME_PREFIX + "searchObjects")
OperationResult operationResult = parentResult.subresult(OP_NAME_PREFIX + OP_SEARCH_OBJECTS)
.addParam("query", query)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class SqlRepositoryServiceImpl extends SqlBaseService implements Reposito

private static final Trace LOGGER = TraceManager.getTrace(SqlRepositoryServiceImpl.class);

public static final String OP_IS_ANY_SUBORDINATE = "isAnySubordinate"; // not part of API anymore

public static final String PERFORMANCE_LOG_NAME = SqlRepositoryServiceImpl.class.getName() + ".performance";
public static final String CONTENTION_LOG_NAME = SqlRepositoryServiceImpl.class.getName() + ".contention";

Expand Down

0 comments on commit 1474945

Please sign in to comment.