improved debug logs for autoassignment (#1253)

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch.io>
This commit is contained in:
Bondar Bogdan
2022-05-16 08:53:43 +02:00
committed by GitHub
parent 59932b1d6f
commit f15cc690f0
2 changed files with 18 additions and 11 deletions

View File

@@ -65,37 +65,43 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
@Override @Override
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public void check() { public void check() {
LOGGER.debug("Auto assigned check call"); LOGGER.debug("Auto assign check call for tenant {} started", getTenantAware().getCurrentTenant());
forEachFilterWithAutoAssignDS(this::checkByTargetFilterQueryAndAssignDS); forEachFilterWithAutoAssignDS(this::checkByTargetFilterQueryAndAssignDS);
LOGGER.debug("Auto assign check call for tenant {} finished", getTenantAware().getCurrentTenant());
} }
/** /**
* Fetches the distribution set, gets all controllerIds and assigns the DS to * Fetches the distribution set, gets all controllerIds and assigns the DS
* them. Catches PersistenceException and own exceptions derived from * to them. Catches PersistenceException and own exceptions derived from
* AbstractServerRtException * AbstractServerRtException
* *
* @param targetFilterQuery * @param targetFilterQuery
* the target filter query * the target filter query
*/ */
private void checkByTargetFilterQueryAndAssignDS(final TargetFilterQuery targetFilterQuery) { private void checkByTargetFilterQueryAndAssignDS(final TargetFilterQuery targetFilterQuery) {
LOGGER.debug("Auto assign check call for tenant {} and target filter query id {} started",
getTenantAware().getCurrentTenant(), targetFilterQuery.getId());
try { try {
int count; int count;
do { do {
final List<String> controllerIds = targetManagement final List<String> controllerIds = targetManagement
.findByTargetFilterQueryAndNonDSAndCompatible( .findByTargetFilterQueryAndNonDSAndCompatible(
PageRequest.of(0, Constants.MAX_ENTRIES_IN_STATEMENT), PageRequest.of(0, Constants.MAX_ENTRIES_IN_STATEMENT),
targetFilterQuery.getAutoAssignDistributionSet().getId(), targetFilterQuery.getQuery()) targetFilterQuery.getAutoAssignDistributionSet().getId(), targetFilterQuery.getQuery())
.getContent().stream().map(Target::getControllerId).collect(Collectors.toList()); .getContent().stream().map(Target::getControllerId).collect(Collectors.toList());
LOGGER.debug(
"Retrieved {} auto assign targets for tenant {} and target filter query id {}, starting with assignment",
controllerIds.size(), getTenantAware().getCurrentTenant(), targetFilterQuery.getId());
count = runTransactionalAssignment(targetFilterQuery, controllerIds); count = runTransactionalAssignment(targetFilterQuery, controllerIds);
LOGGER.debug(
"Assignment for {} auto assign targets for tenant {} and target filter query id {} finished",
controllerIds.size(), getTenantAware().getCurrentTenant(), targetFilterQuery.getId());
} while (count == Constants.MAX_ENTRIES_IN_STATEMENT); } while (count == Constants.MAX_ENTRIES_IN_STATEMENT);
} catch (final PersistenceException | AbstractServerRtException e) { } catch (final PersistenceException | AbstractServerRtException e) {
LOGGER.error("Error during auto assign check of target filter query " + targetFilterQuery.getId(), e); LOGGER.error("Error during auto assign check of target filter query id {}", targetFilterQuery.getId(), e);
} }
LOGGER.debug("Auto assign check call for tenant {} and target filter query id {} finished",
getTenantAware().getCurrentTenant(), targetFilterQuery.getId());
} }
} }

View File

@@ -63,7 +63,6 @@ public class AutoAssignScheduler {
*/ */
@Scheduled(initialDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER) @Scheduled(initialDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER)
public void autoAssignScheduler() { public void autoAssignScheduler() {
LOGGER.debug("auto assign schedule checker has been triggered.");
// run this code in system code privileged to have the necessary // run this code in system code privileged to have the necessary
// permission to query and create entities. // permission to query and create entities.
systemSecurityContext.runAsSystem(this::executeAutoAssign); systemSecurityContext.runAsSystem(this::executeAutoAssign);
@@ -83,9 +82,11 @@ public class AutoAssignScheduler {
} }
try { try {
LOGGER.debug("Auto assign scheduled execution has aquired lock and started for each tenant.");
systemManagement.forEachTenant(tenant -> autoAssignExecutor.check()); systemManagement.forEachTenant(tenant -> autoAssignExecutor.check());
} finally { } finally {
lock.unlock(); lock.unlock();
LOGGER.debug("Auto assign scheduled execution has released lock and finished.");
} }
return null; return null;