From 990d1a754544949047cd792956b1a61d21d67772 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Sat, 3 Feb 2024 17:50:06 +0200 Subject: [PATCH] Refactoring/Improving source: repository 4 (slf4j) (#1604) Signed-off-by: Marinov Avgustin --- .../ExceptionMappingAspectHandler.java | 8 ++--- .../jpa/autoassign/AutoAssignChecker.java | 30 ++++++++-------- .../jpa/autocleanup/AutoCleanupScheduler.java | 10 +++--- .../AbstractDsAssignmentStrategy.java | 9 ++--- .../jpa/management/JpaActionManagement.java | 8 ++--- .../management/JpaConfirmationManagement.java | 29 +++++++-------- .../management/JpaControllerManagement.java | 36 +++++++++---------- .../management/JpaDeploymentManagement.java | 31 ++++++++-------- .../jpa/management/JpaRolloutManagement.java | 11 +++--- .../repository/BaseEntityRepositoryACM.java | 8 ++--- ...artNextGroupRolloutGroupSuccessAction.java | 12 +++---- 11 files changed, 84 insertions(+), 108 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java index a76b485b0..e0c57a634 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java @@ -16,14 +16,13 @@ import java.util.Map; import jakarta.transaction.TransactionManager; +import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; import org.eclipse.hawkbit.exception.GenericSpServerException; import org.eclipse.hawkbit.repository.exception.ConcurrentModificationException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.Ordered; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DuplicateKeyException; @@ -36,11 +35,10 @@ import org.springframework.transaction.TransactionSystemException; * specific exceptions Additionally it checks and prevents access to certain * packages. Logging aspect which logs the call stack */ +@Slf4j @Aspect public class ExceptionMappingAspectHandler implements Ordered { - private static final Logger LOG = LoggerFactory.getLogger(ExceptionMappingAspectHandler.class); - private static final Map EXCEPTION_MAPPING = new HashMap<>(4); /** @@ -98,7 +96,7 @@ public class ExceptionMappingAspectHandler implements Ordered { .getConstructor(Throwable.class).newInstance(ex); } - LOG.error("there is no mapping configured for exception class {}", mappedEx.getName()); + log.error("there is no mapping configured for exception class {}", mappedEx.getName()); throw new GenericSpServerException(ex); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java index 67171efea..37bb100a2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignChecker.java @@ -14,6 +14,7 @@ import java.util.List; import jakarta.persistence.PersistenceException; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.ContextAware; import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.repository.DeploymentManagement; @@ -22,8 +23,6 @@ import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Propagation; @@ -36,10 +35,9 @@ import org.springframework.transaction.annotation.Transactional; * retrieved. All targets get listed per target filter query, that match the TFQ * and that don't have the auto assign DS in their action history. */ +@Slf4j public class AutoAssignChecker extends AbstractAutoAssignExecutor { - private static final Logger LOGGER = LoggerFactory.getLogger(AutoAssignChecker.class); - private final TargetManagement targetManagement; /** @@ -66,17 +64,17 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor { @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void checkAllTargets() { - LOGGER.debug("Auto assign check call for tenant {} started", getContextAware().getCurrentTenant()); + log.debug("Auto assign check call for tenant {} started", getContextAware().getCurrentTenant()); forEachFilterWithAutoAssignDS(this::checkByTargetFilterQueryAndAssignDS); - LOGGER.debug("Auto assign check call for tenant {} finished", getContextAware().getCurrentTenant()); + log.debug("Auto assign check call for tenant {} finished", getContextAware().getCurrentTenant()); } @Override public void checkSingleTarget(String controllerId) { - LOGGER.debug("Auto assign check call for tenant {} and device {} started", getContextAware().getCurrentTenant(), + log.debug("Auto assign check call for tenant {} and device {} started", getContextAware().getCurrentTenant(), controllerId); forEachFilterWithAutoAssignDS(filter -> checkForDevice(controllerId, filter)); - LOGGER.debug("Auto assign check call for tenant {} and device {} finished", getContextAware().getCurrentTenant(), + log.debug("Auto assign check call for tenant {} and device {} finished", getContextAware().getCurrentTenant(), controllerId); } @@ -89,7 +87,7 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor { * the target filter query */ private void checkByTargetFilterQueryAndAssignDS(final TargetFilterQuery targetFilterQuery) { - LOGGER.debug("Auto assign check call for tenant {} and target filter query id {} started", + log.debug("Auto assign check call for tenant {} and target filter query id {} started", getContextAware().getCurrentTenant(), targetFilterQuery.getId()); try { int count; @@ -99,24 +97,24 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor { PageRequest.of(0, Constants.MAX_ENTRIES_IN_STATEMENT), targetFilterQuery.getAutoAssignDistributionSet().getId(), targetFilterQuery.getQuery()) .getContent().stream().map(Target::getControllerId).toList(); - LOGGER.debug( + log.debug( "Retrieved {} auto assign targets for tenant {} and target filter query id {}, starting with assignment", controllerIds.size(), getContextAware().getCurrentTenant(), targetFilterQuery.getId()); count = runTransactionalAssignment(targetFilterQuery, controllerIds); - LOGGER.debug( + log.debug( "Assignment for {} auto assign targets for tenant {} and target filter query id {} finished", controllerIds.size(), getContextAware().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 id {}", targetFilterQuery.getId(), e); + log.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", + log.debug("Auto assign check call for tenant {} and target filter query id {} finished", getContextAware().getCurrentTenant(), targetFilterQuery.getId()); } private void checkForDevice(final String controllerId, final TargetFilterQuery targetFilterQuery) { - LOGGER.debug("Auto assign check call for tenant {} and target filter query id {} for device {} started", + log.debug("Auto assign check call for tenant {} and target filter query id {} for device {} started", getContextAware().getCurrentTenant(), targetFilterQuery.getId(), controllerId); try { final boolean controllerIdMatches = targetManagement.isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable( @@ -128,9 +126,9 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor { } } catch (final PersistenceException | AbstractServerRtException e) { - LOGGER.error("Error during auto assign check of target filter query id {}", targetFilterQuery.getId(), e); + log.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", + log.debug("Auto assign check call for tenant {} and target filter query id {} finished", getContextAware().getCurrentTenant(), targetFilterQuery.getId()); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoCleanupScheduler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoCleanupScheduler.java index c077789c1..0b9c6168c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoCleanupScheduler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autocleanup/AutoCleanupScheduler.java @@ -12,20 +12,18 @@ package org.eclipse.hawkbit.repository.jpa.autocleanup; import java.util.List; import java.util.concurrent.locks.Lock; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.integration.support.locks.LockRegistry; import org.springframework.scheduling.annotation.Scheduled; /** * A scheduler to invoke a set of cleanup handlers periodically. */ +@Slf4j public class AutoCleanupScheduler { - private static final Logger LOGGER = LoggerFactory.getLogger(AutoCleanupScheduler.class); - private static final String AUTO_CLEANUP = "auto-cleanup"; private static final String SEP = "."; private static final String PROP_AUTO_CLEANUP_INTERVAL = "${hawkbit.autocleanup.scheduler.fixedDelay:86400000}"; @@ -62,7 +60,7 @@ public class AutoCleanupScheduler { */ @Scheduled(initialDelayString = PROP_AUTO_CLEANUP_INTERVAL, fixedDelayString = PROP_AUTO_CLEANUP_INTERVAL) public void run() { - LOGGER.debug("Auto cleanup scheduler has been triggered."); + log.debug("Auto cleanup scheduler has been triggered."); // run this code in system code privileged to have the necessary // permission to query and create entities if (!cleanupTasks.isEmpty()) { @@ -83,7 +81,7 @@ public class AutoCleanupScheduler { try { task.run(); } catch (final RuntimeException e) { - LOGGER.error("Cleanup task failed.", e); + log.error("Cleanup task failed.", e); } finally { lock.unlock(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java index f7d4c1226..04c0a3be4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractDsAssignmentStrategy.java @@ -17,6 +17,7 @@ import java.util.Set; import java.util.function.BooleanSupplier; import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RepositoryProperties; @@ -44,8 +45,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetWithActionType; import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -54,12 +53,10 @@ import jakarta.persistence.criteria.JoinType; /** * {@link DistributionSet} to {@link Target} assignment strategy as utility for * {@link JpaDeploymentManagement}. - * */ +@Slf4j public abstract class AbstractDsAssignmentStrategy { - private static final Logger LOG = LoggerFactory.getLogger(AbstractDsAssignmentStrategy.class); - protected final TargetRepository targetRepository; protected final AfterTransactionCommitExecutor afterCommit; protected final EventPublisherHolder eventPublisherHolder; @@ -267,7 +264,7 @@ public abstract class AbstractDsAssignmentStrategy { actionForTarget.setInitiatedBy(initiatedBy); return actionForTarget; }).orElseGet(() -> { - LOG.warn("Cannot find target for targetWithActionType '{}'.", targetWithActionType.getControllerId()); + log.warn("Cannot find target for targetWithActionType '{}'.", targetWithActionType.getControllerId()); return null; }); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java index b289c2629..b4e4e5fe8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java @@ -14,6 +14,7 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.RepositoryProperties; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -28,8 +29,6 @@ import org.eclipse.hawkbit.repository.jpa.utils.QuotaHelper; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -39,10 +38,9 @@ import static org.eclipse.hawkbit.repository.model.Action.Status.FINISHED; /** * Implements utility methods for managing {@link Action}s */ +@Slf4j public class JpaActionManagement { - private static final Logger LOG = LoggerFactory.getLogger(JpaActionManagement.class); - protected final ActionRepository actionRepository; protected final ActionStatusRepository actionStatusRepository; protected final QuotaManagement quotaManagement; @@ -99,7 +97,7 @@ public class JpaActionManagement { return handleAddUpdateActionStatus(actionStatus, action); } - LOG.debug("Update of actionStatus {} for action {} not possible since action not active anymore.", + log.debug("Update of actionStatus {} for action {} not possible since action not active anymore.", actionStatus.getStatus(), action.getId()); return action; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java index ccef3a405..a1f91f717 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.repository.ConfirmationManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.QuotaManagement; @@ -39,8 +40,6 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.AutoConfirmationStatus; import org.eclipse.hawkbit.repository.model.Target; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.dao.ConcurrencyFailureException; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; @@ -51,16 +50,14 @@ import org.springframework.validation.annotation.Validated; /** * JPA implementation for {@link ConfirmationManagement}. - * */ +@Slf4j @Transactional(readOnly = true) @Validated public class JpaConfirmationManagement extends JpaActionManagement implements ConfirmationManagement { public static final String CONFIRMATION_CODE_MSG_PREFIX = "Confirmation status code: %d"; - private static final Logger LOG = LoggerFactory.getLogger(JpaConfirmationManagement.class); - private final EntityFactory entityFactory; private final TargetRepository targetRepository; @@ -85,11 +82,11 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co @Transactional public AutoConfirmationStatus activateAutoConfirmation(final String controllerId, final String initiator, final String remark) { - LOG.trace("'activateAutoConfirmation' was called with values: controllerId={}; initiator={}; remark={}", + log.trace("'activateAutoConfirmation' was called with values: controllerId={}; initiator={}; remark={}", controllerId, initiator, remark); final JpaTarget target = getTargetByControllerIdAndThrowIfNotFound(controllerId); if (target.getAutoConfirmationStatus() != null) { - LOG.debug("'activateAutoConfirmation' was called for an controller id {} with active auto confirmation.", + log.debug("'activateAutoConfirmation' was called for an controller id {} with active auto confirmation.", controllerId); throw new AutoConfirmationAlreadyActiveException(controllerId); } @@ -101,7 +98,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co final String message = String.format("Persisted auto confirmation status is null. " + "Cannot proceed with giving confirmations for active actions for device %s with initiator %s.", controllerId, initiator); - LOG.error("message"); + log.error("message"); throw new IllegalStateException(message); } giveConfirmationForActiveActions(autoConfStatus); @@ -129,7 +126,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public Action confirmAction(final long actionId, final Integer code, final Collection deviceMessages) { - LOG.trace("Action with id {} confirm request is triggered.", actionId); + log.trace("Action with id {} confirm request is triggered.", actionId); final Action action = getActionAndThrowExceptionIfNotFound(actionId); assertActionCanAcceptFeedback(action); final List messages = new ArrayList<>(); @@ -148,7 +145,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public Action denyAction(final long actionId, final Integer code, final Collection deviceMessages) { - LOG.trace("Action with id {} deny request is triggered.", actionId); + log.trace("Action with id {} deny request is triggered.", actionId); final Action action = getActionAndThrowExceptionIfNotFound(actionId); assertActionCanAcceptFeedback(action); final List messages = new ArrayList<>(); @@ -179,13 +176,13 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co if (!action.isActive()) { final String msg = String.format( "Confirming action %s is not possible since the action is not active anymore.", action.getId()); - LOG.warn(msg); + log.warn(msg); throw new InvalidConfirmationFeedbackException(InvalidConfirmationFeedbackException.Reason.ACTION_CLOSED, msg); } else if (!action.isWaitingConfirmation()) { - LOG.debug("Action is not waiting for confirmation, deny request."); + log.debug("Action is not waiting for confirmation, deny request."); final String msg = String.format("Action %s is not waiting for confirmation.", action.getId()); - LOG.warn(msg); + log.warn(msg); throw new InvalidConfirmationFeedbackException( InvalidConfirmationFeedbackException.Reason.NOT_AWAITING_CONFIRMATION, msg); } @@ -199,14 +196,14 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co private Action autoConfirmAction(final JpaAction action, final AutoConfirmationStatus autoConfirmationStatus) { if (!action.isWaitingConfirmation()) { - LOG.debug("Auto-confirming action is not necessary, since action {} is in RUNNING state already.", + log.debug("Auto-confirming action is not necessary, since action {} is in RUNNING state already.", action.getId()); return action; } final JpaActionStatus actionStatus = (JpaActionStatus) entityFactory.actionStatus().create(action.getId()) .status(Status.RUNNING) .messages(Collections.singletonList(autoConfirmationStatus.constructActionMessage())).build(); - LOG.debug( + log.debug( "Automatically confirm actionId '{}' due to active auto-confirmation initiated by '{}' and rollouts system user '{}'", action.getId(), autoConfirmationStatus.getInitiator(), autoConfirmationStatus.getCreatedBy()); @@ -224,7 +221,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co @Override @Transactional public void deactivateAutoConfirmation(String controllerId) { - LOG.debug("Deactivate auto confirmation for controllerId '{}'", controllerId); + log.debug("Deactivate auto confirmation for controllerId '{}'", controllerId); final JpaTarget target = getTargetByControllerIdAndThrowIfNotFound(controllerId); target.setAutoConfirmationStatus(null); targetRepository.save(target); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java index 0fd1b50d6..6211928c2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java @@ -40,6 +40,7 @@ import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; import jakarta.validation.constraints.NotEmpty; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.ListUtils; import org.eclipse.hawkbit.repository.ConfirmationManagement; import org.eclipse.hawkbit.repository.ControllerManagement; @@ -93,8 +94,6 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.Page; @@ -115,12 +114,11 @@ import org.springframework.validation.annotation.Validated; /** * JPA based {@link ControllerManagement} implementation. - * */ +@Slf4j @Transactional(readOnly = true) @Validated public class JpaControllerManagement extends JpaActionManagement implements ControllerManagement { - private static final Logger LOG = LoggerFactory.getLogger(JpaControllerManagement.class); private final BlockingDeque queue; @@ -404,7 +402,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont private Target createTarget(final String controllerId, final URI address, final String name, final String type) { - LOG.debug("Creating target for thing ID \"{}\".", controllerId); + log.debug("Creating target for thing ID \"{}\".", controllerId); JpaTarget jpaTarget = (JpaTarget) entityFactory.target().create() .controllerId(controllerId).description("Plug and Play target: " + controllerId) .name((StringUtils.hasText(name) ? name : controllerId)).status(TargetUpdateStatus.REGISTERED) @@ -414,10 +412,10 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont if (StringUtils.hasText(type)) { var targetTypeOptional = getTargetType(type); if (targetTypeOptional.isPresent()) { - LOG.debug("Setting target type for thing ID \"{}\" to \"{}\".", controllerId, type); + log.debug("Setting target type for thing ID \"{}\" to \"{}\".", controllerId, type); jpaTarget.setTargetType(targetTypeOptional.get()); } else { - LOG.error("Target type with the provided name \"{}\" was not found. Creating target for thing ID" + + log.error("Target type with the provided name \"{}\" was not found. Creating target for thing ID" + " \"{}\" without target type assignment", type, controllerId); } } @@ -439,14 +437,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont * {@link Target#getLastTargetQuery()}. */ private void flushUpdateQueue() { - LOG.debug("Run flushUpdateQueue."); + log.debug("Run flushUpdateQueue."); final int size = queue.size(); if (size <= 0) { return; } - LOG.debug("{} events in flushUpdateQueue.", size); + log.debug("{} events in flushUpdateQueue.", size); final Set events = new HashSet<>(queue.size()); final int drained = queue.drainTo(events); @@ -462,15 +460,15 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont () -> DeploymentHelper.runInNewTransaction(txManager, "flushUpdateQueue", createTransaction)); }); } catch (final RuntimeException ex) { - LOG.error("Failed to persist UpdateQueue content.", ex); + log.error("Failed to persist UpdateQueue content.", ex); return; } - LOG.debug("{} events persisted.", drained); + log.debug("{} events persisted.", drained); } private Void updateLastTargetQueries(final String tenant, final List polls) { - LOG.debug("Persist {} targetqueries.", polls.size()); + log.debug("Persist {} targetqueries.", polls.size()); final List> pollChunks = ListUtils.partition( polls.stream().map(TargetPoll::getControllerId).collect(Collectors.toList()), @@ -508,7 +506,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont final int updated = updateQuery.executeUpdate(); if (updated < chunk.size()) { - LOG.error("Targets polls could not be applied completely ({} instead of {}).", updated, chunk.size()); + log.error("Targets polls could not be applied completely ({} instead of {}).", updated, chunk.size()); } } @@ -535,14 +533,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont if (StringUtils.hasText(type)) { var targetTypeOptional = getTargetType(type); if (targetTypeOptional.isPresent()) { - LOG.debug("Updating target type for thing ID \"{}\" to \"{}\".", toUpdate.getControllerId(), type); + log.debug("Updating target type for thing ID \"{}\" to \"{}\".", toUpdate.getControllerId(), type); toUpdate.setTargetType(targetTypeOptional.get()); } else { - LOG.error("Target type with the provided name \"{}\" was not found. Target type for thing ID" + + log.error("Target type with the provided name \"{}\" was not found. Target type for thing ID" + " \"{}\" will not be updated", type, toUpdate.getControllerId()); } } else { - LOG.debug("Removing target type assignment for thing ID \"{}\".", toUpdate.getControllerId()); + log.debug("Removing target type assignment for thing ID \"{}\".", toUpdate.getControllerId()); toUpdate.setTargetType(null); //unassign target type if "" target type name was provided } } @@ -926,7 +924,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont final Page messages = actionStatusRepository.findMessagesByActionIdAndMessageNotLike(pageable, actionId, RepositoryConstants.SERVER_MESSAGE_PREFIX + "%"); - LOG.debug("Retrieved {} message(s) from action history for action {}.", messages.getNumberOfElements(), + log.debug("Retrieved {} message(s) from action history for action {}.", messages.getNumberOfElements(), actionId); return messages.getContent(); @@ -1027,7 +1025,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont @Modifying @Transactional(isolation = Isolation.READ_COMMITTED) public Action cancelAction(final long actionId) { - LOG.debug("cancelAction({})", actionId); + log.debug("cancelAction({})", actionId); final JpaAction action = actionRepository.findById(actionId) .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); @@ -1037,7 +1035,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont } if (action.isActive()) { - LOG.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING); + log.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING); action.setStatus(Status.CANCELING); // document that the status has been retrieved diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java index 473f9894a..4f9ce769e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java @@ -36,6 +36,7 @@ import jakarta.persistence.criteria.JoinType; import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.Root; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.ListUtils; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.DeploymentManagement; @@ -90,8 +91,6 @@ import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.utils.TenantConfigHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; @@ -114,14 +113,12 @@ import org.springframework.validation.annotation.Validated; /** * JPA implementation for {@link DeploymentManagement}. - * */ +@Slf4j @Transactional(readOnly = true) @Validated public class JpaDeploymentManagement extends JpaActionManagement implements DeploymentManagement { - private static final Logger LOG = LoggerFactory.getLogger(JpaDeploymentManagement.class); - /** * Maximum amount of Actions that are started at once. */ @@ -492,7 +489,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl }); actionRepository.switchStatus(Status.CANCELED, targetIds, false, Status.SCHEDULED); } else { - LOG.debug("The Multi Assignments feature is enabled: No need to cancel inactive scheduled actions."); + log.debug("The Multi Assignments feature is enabled: No need to cancel inactive scheduled actions."); } } @@ -575,7 +572,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public Action cancelAction(final long actionId) { - LOG.debug("cancelAction({})", actionId); + log.debug("cancelAction({})", actionId); final JpaAction action = actionRepository.findById(actionId) .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); @@ -587,7 +584,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl assertTargetUpdateAllowed(action); if (action.isActive()) { - LOG.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING); + log.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING); action.setStatus(Status.CANCELING); // document that the status has been retrieved @@ -622,7 +619,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl assertTargetUpdateAllowed(action); - LOG.warn("action ({}) was still active and has been force quite.", action); + log.warn("action ({}) was still active and has been force quite.", action); // document that the status has been retrieved actionStatusRepository.save(new JpaActionStatus(action, Status.CANCELED, System.currentTimeMillis(), @@ -703,7 +700,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl && action.getDistributionSet().getId().equals(target.getAssignedDistributionSet().getId())) { // the target has already the distribution set assigned, we don't // need to start the scheduled action, just finish it. - LOG.debug("Target {} has distribution set {} assigned. Closing action...", target.getControllerId(), + log.debug("Target {} has distribution set {} assigned. Closing action...", target.getControllerId(), action.getDistributionSet().getName()); action.setStatus(Status.FINISHED); action.setActive(false); @@ -964,7 +961,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl deleteQuery.setParameter("tenant", tenantAware.getCurrentTenant().toUpperCase()); deleteQuery.setParameter("last_modified_at", lastModified); - LOG.debug("Action cleanup: Executing the following (native) query: {}", deleteQuery); + log.debug("Action cleanup: Executing the following (native) query: {}", deleteQuery); return deleteQuery.executeUpdate(); } @@ -1036,11 +1033,11 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl try { assertTargetUpdateAllowed(action); cancelAction(action.getId()); - LOG.debug("Action {} canceled", action.getId()); + log.debug("Action {} canceled", action.getId()); } catch (final InsufficientPermissionException e) { - LOG.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e); + log.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e); } catch (final EntityNotFoundException e) { - LOG.trace("Could not cancel action {} due to entity not found exception.", action.getId(), e); + log.trace("Could not cancel action {} due to entity not found exception.", action.getId(), e); } }); if (cancelationType == CancelationType.FORCE) { @@ -1049,11 +1046,11 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl try { assertTargetUpdateAllowed(action); forceQuitAction(action.getId()); - LOG.debug("Action {} force canceled", action.getId()); + log.debug("Action {} force canceled", action.getId()); } catch (final InsufficientPermissionException e) { - LOG.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e); + log.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e); } catch (final EntityNotFoundException e) { - LOG.trace("Could not cancel action {} due to entity not found exception.", action.getId(), + log.trace("Could not cancel action {} due to entity not found exception.", action.getId(), e); } }); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java index bd6c830b9..76d23176c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import jakarta.validation.ConstraintDeclarationException; import jakarta.validation.ValidationException; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.RepositoryProperties; @@ -73,8 +74,6 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.eclipse.hawkbit.security.SystemSecurityContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.Page; @@ -96,10 +95,10 @@ import org.springframework.validation.annotation.Validated; /** * JPA implementation of {@link RolloutManagement}. */ +@Slf4j @Validated @Transactional(readOnly = true) public class JpaRolloutManagement implements RolloutManagement { - private static final Logger LOGGER = LoggerFactory.getLogger(JpaRolloutManagement.class); private static final List ACTIVE_ROLLOUTS = Arrays.asList(RolloutStatus.CREATING, RolloutStatus.DELETING, RolloutStatus.STARTING, RolloutStatus.READY, RolloutStatus.RUNNING, @@ -382,7 +381,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) { - LOGGER.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision); + log.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision); final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId); RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL); switch (decision) { @@ -407,7 +406,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public Rollout start(final long rolloutId) { - LOGGER.debug("startRollout called for rollout {}", rolloutId); + log.debug("startRollout called for rollout {}", rolloutId); final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId); RolloutHelper.checkIfRolloutCanStarted(rollout, rollout); @@ -644,7 +643,7 @@ public class JpaRolloutManagement implements RolloutManagement { final JpaRollout jpaRollout = (JpaRollout) rollout; jpaRollout.setStatus(RolloutStatus.STOPPING); rolloutRepository.save(jpaRollout); - LOGGER.debug("Rollout {} stopped", jpaRollout.getId()); + log.debug("Rollout {} stopped", jpaRollout.getId()); }); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepositoryACM.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepositoryACM.java index 0afa3a515..87615a114 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepositoryACM.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/BaseEntityRepositoryACM.java @@ -9,12 +9,11 @@ */ package org.eclipse.hawkbit.repository.jpa.repository; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTenantAwareBaseEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; @@ -35,10 +34,9 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; +@Slf4j public class BaseEntityRepositoryACM implements BaseEntityRepository { - private static final Logger LOGGER = LoggerFactory.getLogger(BaseEntityRepositoryACM.class); - private final BaseEntityRepository repository; private final AccessController accessController; @@ -95,7 +93,7 @@ public class BaseEntityRepositoryACM throw e.getCause() == null ? e : e.getCause(); } }); - LOGGER.info("Proxy created -> {}", acmProxy); + log.info("Proxy created -> {}", acmProxy); return acmProxy; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java index d79c389ee..70297af42 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rollout.condition; import java.util.List; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.jpa.repository.RolloutGroupRepository; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; @@ -18,16 +19,13 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.security.SystemSecurityContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Success action which starts the next following {@link RolloutGroup}. */ +@Slf4j public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActionEvaluator { - private static final Logger logger = LoggerFactory.getLogger(StartNextGroupRolloutGroupSuccessAction.class); - private final RolloutGroupRepository rolloutGroupRepository; private final DeploymentManagement deploymentManagement; @@ -60,13 +58,13 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi // started. final long countOfStartedActions = deploymentManagement.startScheduledActionsByRolloutGroupParent( rollout.getId(), rollout.getDistributionSet().getId(), rolloutGroup.getId()); - logger.debug("{} Next actions started for rollout {} and parent group {}", countOfStartedActions, rollout, + log.debug("{} Next actions started for rollout {} and parent group {}", countOfStartedActions, rollout, rolloutGroup); if (countOfStartedActions > 0) { // get all next scheduled groups and set them in state running rolloutGroupRepository.setStatusForCildren(RolloutGroupStatus.RUNNING, rolloutGroup); } else { - logger.debug("No actions to start for next rolloutgroup of parent {} {}", rolloutGroup.getId(), + log.debug("No actions to start for next rolloutgroup of parent {} {}", rolloutGroup.getId(), rolloutGroup.getName()); // nothing for next group, just finish the group, this can happen // e.g. if targets has been deleted after the group has been @@ -78,7 +76,7 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi if (nextGroup.isDynamic()) { nextGroup.setStatus(RolloutGroupStatus.RUNNING); } else { - logger.debug("Rolloutgroup {} is finished, starting next group", nextGroup); + log.debug("Rolloutgroup {} is finished, starting next group", nextGroup); nextGroup.setStatus(RolloutGroupStatus.FINISHED); rolloutGroupRepository.save(nextGroup); // find the next group to set in running state