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
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void check() {
LOGGER.debug("Auto assigned check call");
LOGGER.debug("Auto assign check call for tenant {} started", getTenantAware().getCurrentTenant());
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
* them. Catches PersistenceException and own exceptions derived from
* Fetches the distribution set, gets all controllerIds and assigns the DS
* to them. Catches PersistenceException and own exceptions derived from
* AbstractServerRtException
*
* @param targetFilterQuery
* the target filter query
*/
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 {
int count;
do {
final List<String> controllerIds = targetManagement
.findByTargetFilterQueryAndNonDSAndCompatible(
PageRequest.of(0, Constants.MAX_ENTRIES_IN_STATEMENT),
targetFilterQuery.getAutoAssignDistributionSet().getId(), targetFilterQuery.getQuery())
.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);
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);
} 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)
public void autoAssignScheduler() {
LOGGER.debug("auto assign schedule checker has been triggered.");
// run this code in system code privileged to have the necessary
// permission to query and create entities.
systemSecurityContext.runAsSystem(this::executeAutoAssign);
@@ -83,9 +82,11 @@ public class AutoAssignScheduler {
}
try {
LOGGER.debug("Auto assign scheduled execution has aquired lock and started for each tenant.");
systemManagement.forEachTenant(tenant -> autoAssignExecutor.check());
} finally {
lock.unlock();
LOGGER.debug("Auto assign scheduled execution has released lock and finished.");
}
return null;