Refactoring/Improving source: repository 4 (slf4j) (#1604)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-02-03 17:50:06 +02:00
committed by GitHub
parent 5821c2543c
commit 990d1a7545
11 changed files with 84 additions and 108 deletions

View File

@@ -16,14 +16,13 @@ import java.util.Map;
import jakarta.transaction.TransactionManager; import jakarta.transaction.TransactionManager;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.eclipse.hawkbit.exception.GenericSpServerException; import org.eclipse.hawkbit.exception.GenericSpServerException;
import org.eclipse.hawkbit.repository.exception.ConcurrentModificationException; import org.eclipse.hawkbit.repository.exception.ConcurrentModificationException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.DuplicateKeyException;
@@ -36,11 +35,10 @@ import org.springframework.transaction.TransactionSystemException;
* specific exceptions Additionally it checks and prevents access to certain * specific exceptions Additionally it checks and prevents access to certain
* packages. Logging aspect which logs the call stack * packages. Logging aspect which logs the call stack
*/ */
@Slf4j
@Aspect @Aspect
public class ExceptionMappingAspectHandler implements Ordered { public class ExceptionMappingAspectHandler implements Ordered {
private static final Logger LOG = LoggerFactory.getLogger(ExceptionMappingAspectHandler.class);
private static final Map<String, String> EXCEPTION_MAPPING = new HashMap<>(4); private static final Map<String, String> EXCEPTION_MAPPING = new HashMap<>(4);
/** /**
@@ -98,7 +96,7 @@ public class ExceptionMappingAspectHandler implements Ordered {
.getConstructor(Throwable.class).newInstance(ex); .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); throw new GenericSpServerException(ex);
} }

View File

@@ -14,6 +14,7 @@ import java.util.List;
import jakarta.persistence.PersistenceException; import jakarta.persistence.PersistenceException;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.ContextAware; import org.eclipse.hawkbit.ContextAware;
import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.repository.DeploymentManagement; 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.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Propagation; 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 * 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. * and that don't have the auto assign DS in their action history.
*/ */
@Slf4j
public class AutoAssignChecker extends AbstractAutoAssignExecutor { public class AutoAssignChecker extends AbstractAutoAssignExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger(AutoAssignChecker.class);
private final TargetManagement targetManagement; private final TargetManagement targetManagement;
/** /**
@@ -66,17 +64,17 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
@Override @Override
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public void checkAllTargets() { 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); 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 @Override
public void checkSingleTarget(String controllerId) { 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); controllerId);
forEachFilterWithAutoAssignDS(filter -> checkForDevice(controllerId, filter)); 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); controllerId);
} }
@@ -89,7 +87,7 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
* 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", log.debug("Auto assign check call for tenant {} and target filter query id {} started",
getContextAware().getCurrentTenant(), targetFilterQuery.getId()); getContextAware().getCurrentTenant(), targetFilterQuery.getId());
try { try {
int count; int count;
@@ -99,24 +97,24 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
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).toList(); .getContent().stream().map(Target::getControllerId).toList();
LOGGER.debug( log.debug(
"Retrieved {} auto assign targets for tenant {} and target filter query id {}, starting with assignment", "Retrieved {} auto assign targets for tenant {} and target filter query id {}, starting with assignment",
controllerIds.size(), getContextAware().getCurrentTenant(), targetFilterQuery.getId()); controllerIds.size(), getContextAware().getCurrentTenant(), targetFilterQuery.getId());
count = runTransactionalAssignment(targetFilterQuery, controllerIds); count = runTransactionalAssignment(targetFilterQuery, controllerIds);
LOGGER.debug( log.debug(
"Assignment for {} auto assign targets for tenant {} and target filter query id {} finished", "Assignment for {} auto assign targets for tenant {} and target filter query id {} finished",
controllerIds.size(), getContextAware().getCurrentTenant(), targetFilterQuery.getId()); controllerIds.size(), getContextAware().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 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()); getContextAware().getCurrentTenant(), targetFilterQuery.getId());
} }
private void checkForDevice(final String controllerId, final TargetFilterQuery targetFilterQuery) { 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); getContextAware().getCurrentTenant(), targetFilterQuery.getId(), controllerId);
try { try {
final boolean controllerIdMatches = targetManagement.isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable( final boolean controllerIdMatches = targetManagement.isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(
@@ -128,9 +126,9 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
} }
} catch (final PersistenceException | AbstractServerRtException e) { } 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()); getContextAware().getCurrentTenant(), targetFilterQuery.getId());
} }
} }

View File

@@ -12,20 +12,18 @@ package org.eclipse.hawkbit.repository.jpa.autocleanup;
import java.util.List; import java.util.List;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.support.locks.LockRegistry; import org.springframework.integration.support.locks.LockRegistry;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
/** /**
* A scheduler to invoke a set of cleanup handlers periodically. * A scheduler to invoke a set of cleanup handlers periodically.
*/ */
@Slf4j
public class AutoCleanupScheduler { public class AutoCleanupScheduler {
private static final Logger LOGGER = LoggerFactory.getLogger(AutoCleanupScheduler.class);
private static final String AUTO_CLEANUP = "auto-cleanup"; private static final String AUTO_CLEANUP = "auto-cleanup";
private static final String SEP = "."; private static final String SEP = ".";
private static final String PROP_AUTO_CLEANUP_INTERVAL = "${hawkbit.autocleanup.scheduler.fixedDelay:86400000}"; 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) @Scheduled(initialDelayString = PROP_AUTO_CLEANUP_INTERVAL, fixedDelayString = PROP_AUTO_CLEANUP_INTERVAL)
public void run() { 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 // run this code in system code privileged to have the necessary
// permission to query and create entities // permission to query and create entities
if (!cleanupTasks.isEmpty()) { if (!cleanupTasks.isEmpty()) {
@@ -83,7 +81,7 @@ public class AutoCleanupScheduler {
try { try {
task.run(); task.run();
} catch (final RuntimeException e) { } catch (final RuntimeException e) {
LOGGER.error("Cleanup task failed.", e); log.error("Cleanup task failed.", e);
} finally { } finally {
lock.unlock(); lock.unlock();
} }

View File

@@ -17,6 +17,7 @@ import java.util.Set;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.RepositoryProperties; 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.Target;
import org.eclipse.hawkbit.repository.model.TargetWithActionType; import org.eclipse.hawkbit.repository.model.TargetWithActionType;
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; 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.CollectionUtils;
import org.springframework.util.StringUtils; 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 DistributionSet} to {@link Target} assignment strategy as utility for
* {@link JpaDeploymentManagement}. * {@link JpaDeploymentManagement}.
*
*/ */
@Slf4j
public abstract class AbstractDsAssignmentStrategy { public abstract class AbstractDsAssignmentStrategy {
private static final Logger LOG = LoggerFactory.getLogger(AbstractDsAssignmentStrategy.class);
protected final TargetRepository targetRepository; protected final TargetRepository targetRepository;
protected final AfterTransactionCommitExecutor afterCommit; protected final AfterTransactionCommitExecutor afterCommit;
protected final EventPublisherHolder eventPublisherHolder; protected final EventPublisherHolder eventPublisherHolder;
@@ -267,7 +264,7 @@ public abstract class AbstractDsAssignmentStrategy {
actionForTarget.setInitiatedBy(initiatedBy); actionForTarget.setInitiatedBy(initiatedBy);
return actionForTarget; return actionForTarget;
}).orElseGet(() -> { }).orElseGet(() -> {
LOG.warn("Cannot find target for targetWithActionType '{}'.", targetWithActionType.getControllerId()); log.warn("Cannot find target for targetWithActionType '{}'.", targetWithActionType.getControllerId());
return null; return null;
}); });
} }

View File

@@ -14,6 +14,7 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties; import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; 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.Action;
import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; 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.PageRequest;
import org.springframework.data.domain.Sort; 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 * Implements utility methods for managing {@link Action}s
*/ */
@Slf4j
public class JpaActionManagement { public class JpaActionManagement {
private static final Logger LOG = LoggerFactory.getLogger(JpaActionManagement.class);
protected final ActionRepository actionRepository; protected final ActionRepository actionRepository;
protected final ActionStatusRepository actionStatusRepository; protected final ActionStatusRepository actionStatusRepository;
protected final QuotaManagement quotaManagement; protected final QuotaManagement quotaManagement;
@@ -99,7 +97,7 @@ public class JpaActionManagement {
return handleAddUpdateActionStatus(actionStatus, action); 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()); actionStatus.getStatus(), action.getId());
return action; return action;
} }

View File

@@ -16,6 +16,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.ConfirmationManagement; import org.eclipse.hawkbit.repository.ConfirmationManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.QuotaManagement; 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.Action.Status;
import org.eclipse.hawkbit.repository.model.AutoConfirmationStatus; import org.eclipse.hawkbit.repository.model.AutoConfirmationStatus;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable; import org.springframework.retry.annotation.Retryable;
@@ -51,16 +50,14 @@ import org.springframework.validation.annotation.Validated;
/** /**
* JPA implementation for {@link ConfirmationManagement}. * JPA implementation for {@link ConfirmationManagement}.
*
*/ */
@Slf4j
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Validated @Validated
public class JpaConfirmationManagement extends JpaActionManagement implements ConfirmationManagement { public class JpaConfirmationManagement extends JpaActionManagement implements ConfirmationManagement {
public static final String CONFIRMATION_CODE_MSG_PREFIX = "Confirmation status code: %d"; 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 EntityFactory entityFactory;
private final TargetRepository targetRepository; private final TargetRepository targetRepository;
@@ -85,11 +82,11 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
@Transactional @Transactional
public AutoConfirmationStatus activateAutoConfirmation(final String controllerId, final String initiator, public AutoConfirmationStatus activateAutoConfirmation(final String controllerId, final String initiator,
final String remark) { 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); controllerId, initiator, remark);
final JpaTarget target = getTargetByControllerIdAndThrowIfNotFound(controllerId); final JpaTarget target = getTargetByControllerIdAndThrowIfNotFound(controllerId);
if (target.getAutoConfirmationStatus() != null) { 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); controllerId);
throw new AutoConfirmationAlreadyActiveException(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. " 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.", + "Cannot proceed with giving confirmations for active actions for device %s with initiator %s.",
controllerId, initiator); controllerId, initiator);
LOG.error("message"); log.error("message");
throw new IllegalStateException(message); throw new IllegalStateException(message);
} }
giveConfirmationForActiveActions(autoConfStatus); giveConfirmationForActiveActions(autoConfStatus);
@@ -129,7 +126,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
@Retryable(include = { @Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) 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<String> deviceMessages) { public Action confirmAction(final long actionId, final Integer code, final Collection<String> 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); final Action action = getActionAndThrowExceptionIfNotFound(actionId);
assertActionCanAcceptFeedback(action); assertActionCanAcceptFeedback(action);
final List<String> messages = new ArrayList<>(); final List<String> messages = new ArrayList<>();
@@ -148,7 +145,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
@Retryable(include = { @Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) 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<String> deviceMessages) { public Action denyAction(final long actionId, final Integer code, final Collection<String> 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); final Action action = getActionAndThrowExceptionIfNotFound(actionId);
assertActionCanAcceptFeedback(action); assertActionCanAcceptFeedback(action);
final List<String> messages = new ArrayList<>(); final List<String> messages = new ArrayList<>();
@@ -179,13 +176,13 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
if (!action.isActive()) { if (!action.isActive()) {
final String msg = String.format( final String msg = String.format(
"Confirming action %s is not possible since the action is not active anymore.", action.getId()); "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, throw new InvalidConfirmationFeedbackException(InvalidConfirmationFeedbackException.Reason.ACTION_CLOSED,
msg); msg);
} else if (!action.isWaitingConfirmation()) { } 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()); final String msg = String.format("Action %s is not waiting for confirmation.", action.getId());
LOG.warn(msg); log.warn(msg);
throw new InvalidConfirmationFeedbackException( throw new InvalidConfirmationFeedbackException(
InvalidConfirmationFeedbackException.Reason.NOT_AWAITING_CONFIRMATION, msg); 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) { private Action autoConfirmAction(final JpaAction action, final AutoConfirmationStatus autoConfirmationStatus) {
if (!action.isWaitingConfirmation()) { 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()); action.getId());
return action; return action;
} }
final JpaActionStatus actionStatus = (JpaActionStatus) entityFactory.actionStatus().create(action.getId()) final JpaActionStatus actionStatus = (JpaActionStatus) entityFactory.actionStatus().create(action.getId())
.status(Status.RUNNING) .status(Status.RUNNING)
.messages(Collections.singletonList(autoConfirmationStatus.constructActionMessage())).build(); .messages(Collections.singletonList(autoConfirmationStatus.constructActionMessage())).build();
LOG.debug( log.debug(
"Automatically confirm actionId '{}' due to active auto-confirmation initiated by '{}' and rollouts system user '{}'", "Automatically confirm actionId '{}' due to active auto-confirmation initiated by '{}' and rollouts system user '{}'",
action.getId(), autoConfirmationStatus.getInitiator(), autoConfirmationStatus.getCreatedBy()); action.getId(), autoConfirmationStatus.getInitiator(), autoConfirmationStatus.getCreatedBy());
@@ -224,7 +221,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
@Override @Override
@Transactional @Transactional
public void deactivateAutoConfirmation(String controllerId) { 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); final JpaTarget target = getTargetByControllerIdAndThrowIfNotFound(controllerId);
target.setAutoConfirmationStatus(null); target.setAutoConfirmationStatus(null);
targetRepository.save(target); targetRepository.save(target);

View File

@@ -40,6 +40,7 @@ import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.Root;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.eclipse.hawkbit.repository.ConfirmationManagement; import org.eclipse.hawkbit.repository.ConfirmationManagement;
import org.eclipse.hawkbit.repository.ControllerManagement; 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.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; 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.beans.factory.annotation.Autowired;
import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -115,12 +114,11 @@ import org.springframework.validation.annotation.Validated;
/** /**
* JPA based {@link ControllerManagement} implementation. * JPA based {@link ControllerManagement} implementation.
*
*/ */
@Slf4j
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Validated @Validated
public class JpaControllerManagement extends JpaActionManagement implements ControllerManagement { public class JpaControllerManagement extends JpaActionManagement implements ControllerManagement {
private static final Logger LOG = LoggerFactory.getLogger(JpaControllerManagement.class);
private final BlockingDeque<TargetPoll> queue; private final BlockingDeque<TargetPoll> 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) { 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() JpaTarget jpaTarget = (JpaTarget) entityFactory.target().create()
.controllerId(controllerId).description("Plug and Play target: " + controllerId) .controllerId(controllerId).description("Plug and Play target: " + controllerId)
.name((StringUtils.hasText(name) ? name : controllerId)).status(TargetUpdateStatus.REGISTERED) .name((StringUtils.hasText(name) ? name : controllerId)).status(TargetUpdateStatus.REGISTERED)
@@ -414,10 +412,10 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
if (StringUtils.hasText(type)) { if (StringUtils.hasText(type)) {
var targetTypeOptional = getTargetType(type); var targetTypeOptional = getTargetType(type);
if (targetTypeOptional.isPresent()) { 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()); jpaTarget.setTargetType(targetTypeOptional.get());
} else { } 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); " \"{}\" without target type assignment", type, controllerId);
} }
} }
@@ -439,14 +437,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
* {@link Target#getLastTargetQuery()}. * {@link Target#getLastTargetQuery()}.
*/ */
private void flushUpdateQueue() { private void flushUpdateQueue() {
LOG.debug("Run flushUpdateQueue."); log.debug("Run flushUpdateQueue.");
final int size = queue.size(); final int size = queue.size();
if (size <= 0) { if (size <= 0) {
return; return;
} }
LOG.debug("{} events in flushUpdateQueue.", size); log.debug("{} events in flushUpdateQueue.", size);
final Set<TargetPoll> events = new HashSet<>(queue.size()); final Set<TargetPoll> events = new HashSet<>(queue.size());
final int drained = queue.drainTo(events); final int drained = queue.drainTo(events);
@@ -462,15 +460,15 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
() -> DeploymentHelper.runInNewTransaction(txManager, "flushUpdateQueue", createTransaction)); () -> DeploymentHelper.runInNewTransaction(txManager, "flushUpdateQueue", createTransaction));
}); });
} catch (final RuntimeException ex) { } catch (final RuntimeException ex) {
LOG.error("Failed to persist UpdateQueue content.", ex); log.error("Failed to persist UpdateQueue content.", ex);
return; return;
} }
LOG.debug("{} events persisted.", drained); log.debug("{} events persisted.", drained);
} }
private Void updateLastTargetQueries(final String tenant, final List<TargetPoll> polls) { private Void updateLastTargetQueries(final String tenant, final List<TargetPoll> polls) {
LOG.debug("Persist {} targetqueries.", polls.size()); log.debug("Persist {} targetqueries.", polls.size());
final List<List<String>> pollChunks = ListUtils.partition( final List<List<String>> pollChunks = ListUtils.partition(
polls.stream().map(TargetPoll::getControllerId).collect(Collectors.toList()), polls.stream().map(TargetPoll::getControllerId).collect(Collectors.toList()),
@@ -508,7 +506,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
final int updated = updateQuery.executeUpdate(); final int updated = updateQuery.executeUpdate();
if (updated < chunk.size()) { 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)) { if (StringUtils.hasText(type)) {
var targetTypeOptional = getTargetType(type); var targetTypeOptional = getTargetType(type);
if (targetTypeOptional.isPresent()) { 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()); toUpdate.setTargetType(targetTypeOptional.get());
} else { } 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()); " \"{}\" will not be updated", type, toUpdate.getControllerId());
} }
} else { } 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 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<String> messages = actionStatusRepository.findMessagesByActionIdAndMessageNotLike(pageable, actionId, final Page<String> messages = actionStatusRepository.findMessagesByActionIdAndMessageNotLike(pageable, actionId,
RepositoryConstants.SERVER_MESSAGE_PREFIX + "%"); 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); actionId);
return messages.getContent(); return messages.getContent();
@@ -1027,7 +1025,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Modifying @Modifying
@Transactional(isolation = Isolation.READ_COMMITTED) @Transactional(isolation = Isolation.READ_COMMITTED)
public Action cancelAction(final long actionId) { public Action cancelAction(final long actionId) {
LOG.debug("cancelAction({})", actionId); log.debug("cancelAction({})", actionId);
final JpaAction action = actionRepository.findById(actionId) final JpaAction action = actionRepository.findById(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
@@ -1037,7 +1035,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
} }
if (action.isActive()) { 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); action.setStatus(Status.CANCELING);
// document that the status has been retrieved // document that the status has been retrieved

View File

@@ -36,6 +36,7 @@ import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.Root; import jakarta.persistence.criteria.Root;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionFields;
import org.eclipse.hawkbit.repository.DeploymentManagement; 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.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.utils.TenantConfigHelper; import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.AuditorAware;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -114,14 +113,12 @@ import org.springframework.validation.annotation.Validated;
/** /**
* JPA implementation for {@link DeploymentManagement}. * JPA implementation for {@link DeploymentManagement}.
*
*/ */
@Slf4j
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Validated @Validated
public class JpaDeploymentManagement extends JpaActionManagement implements DeploymentManagement { 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. * 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); actionRepository.switchStatus(Status.CANCELED, targetIds, false, Status.SCHEDULED);
} else { } 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 = { @Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action cancelAction(final long actionId) { public Action cancelAction(final long actionId) {
LOG.debug("cancelAction({})", actionId); log.debug("cancelAction({})", actionId);
final JpaAction action = actionRepository.findById(actionId) final JpaAction action = actionRepository.findById(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
@@ -587,7 +584,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
assertTargetUpdateAllowed(action); assertTargetUpdateAllowed(action);
if (action.isActive()) { 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); action.setStatus(Status.CANCELING);
// document that the status has been retrieved // document that the status has been retrieved
@@ -622,7 +619,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
assertTargetUpdateAllowed(action); 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 // document that the status has been retrieved
actionStatusRepository.save(new JpaActionStatus(action, Status.CANCELED, System.currentTimeMillis(), 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())) { && action.getDistributionSet().getId().equals(target.getAssignedDistributionSet().getId())) {
// the target has already the distribution set assigned, we don't // the target has already the distribution set assigned, we don't
// need to start the scheduled action, just finish it. // 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.getDistributionSet().getName());
action.setStatus(Status.FINISHED); action.setStatus(Status.FINISHED);
action.setActive(false); action.setActive(false);
@@ -964,7 +961,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
deleteQuery.setParameter("tenant", tenantAware.getCurrentTenant().toUpperCase()); deleteQuery.setParameter("tenant", tenantAware.getCurrentTenant().toUpperCase());
deleteQuery.setParameter("last_modified_at", lastModified); 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(); return deleteQuery.executeUpdate();
} }
@@ -1036,11 +1033,11 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
try { try {
assertTargetUpdateAllowed(action); assertTargetUpdateAllowed(action);
cancelAction(action.getId()); cancelAction(action.getId());
LOG.debug("Action {} canceled", action.getId()); log.debug("Action {} canceled", action.getId());
} catch (final InsufficientPermissionException e) { } 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) { } 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) { if (cancelationType == CancelationType.FORCE) {
@@ -1049,11 +1046,11 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
try { try {
assertTargetUpdateAllowed(action); assertTargetUpdateAllowed(action);
forceQuitAction(action.getId()); forceQuitAction(action.getId());
LOG.debug("Action {} force canceled", action.getId()); log.debug("Action {} force canceled", action.getId());
} catch (final InsufficientPermissionException e) { } 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) { } 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); e);
} }
}); });

View File

@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
import jakarta.validation.ConstraintDeclarationException; import jakarta.validation.ConstraintDeclarationException;
import jakarta.validation.ValidationException; import jakarta.validation.ValidationException;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties; 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.model.helper.EventPublisherHolder;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -96,10 +95,10 @@ import org.springframework.validation.annotation.Validated;
/** /**
* JPA implementation of {@link RolloutManagement}. * JPA implementation of {@link RolloutManagement}.
*/ */
@Slf4j
@Validated @Validated
@Transactional(readOnly = true) @Transactional(readOnly = true)
public class JpaRolloutManagement implements RolloutManagement { public class JpaRolloutManagement implements RolloutManagement {
private static final Logger LOGGER = LoggerFactory.getLogger(JpaRolloutManagement.class);
private static final List<RolloutStatus> ACTIVE_ROLLOUTS = Arrays.asList(RolloutStatus.CREATING, private static final List<RolloutStatus> ACTIVE_ROLLOUTS = Arrays.asList(RolloutStatus.CREATING,
RolloutStatus.DELETING, RolloutStatus.STARTING, RolloutStatus.READY, RolloutStatus.RUNNING, RolloutStatus.DELETING, RolloutStatus.STARTING, RolloutStatus.READY, RolloutStatus.RUNNING,
@@ -382,7 +381,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(include = { @Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) 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) { 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); final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL); RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL);
switch (decision) { switch (decision) {
@@ -407,7 +406,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(include = { @Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout start(final long rolloutId) { 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); final JpaRollout rollout = getRolloutAndThrowExceptionIfNotFound(rolloutId);
RolloutHelper.checkIfRolloutCanStarted(rollout, rollout); RolloutHelper.checkIfRolloutCanStarted(rollout, rollout);
@@ -644,7 +643,7 @@ public class JpaRolloutManagement implements RolloutManagement {
final JpaRollout jpaRollout = (JpaRollout) rollout; final JpaRollout jpaRollout = (JpaRollout) rollout;
jpaRollout.setStatus(RolloutStatus.STOPPING); jpaRollout.setStatus(RolloutStatus.STOPPING);
rolloutRepository.save(jpaRollout); rolloutRepository.save(jpaRollout);
LOGGER.debug("Rollout {} stopped", jpaRollout.getId()); log.debug("Rollout {} stopped", jpaRollout.getId());
}); });
} }

View File

@@ -9,12 +9,11 @@
*/ */
package org.eclipse.hawkbit.repository.jpa.repository; 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.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTenantAwareBaseEntity; 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.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice; import org.springframework.data.domain.Slice;
@@ -35,10 +34,9 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
@Slf4j
public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity> implements BaseEntityRepository<T> { public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity> implements BaseEntityRepository<T> {
private static final Logger LOGGER = LoggerFactory.getLogger(BaseEntityRepositoryACM.class);
private final BaseEntityRepository<T> repository; private final BaseEntityRepository<T> repository;
private final AccessController<T> accessController; private final AccessController<T> accessController;
@@ -95,7 +93,7 @@ public class BaseEntityRepositoryACM<T extends AbstractJpaTenantAwareBaseEntity>
throw e.getCause() == null ? e : e.getCause(); throw e.getCause() == null ? e : e.getCause();
} }
}); });
LOGGER.info("Proxy created -> {}", acmProxy); log.info("Proxy created -> {}", acmProxy);
return acmProxy; return acmProxy;
} }

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rollout.condition;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.jpa.repository.RolloutGroupRepository; import org.eclipse.hawkbit.repository.jpa.repository.RolloutGroupRepository;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; 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;
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus;
import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Success action which starts the next following {@link RolloutGroup}. * Success action which starts the next following {@link RolloutGroup}.
*/ */
@Slf4j
public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActionEvaluator<RolloutGroup.RolloutGroupSuccessAction> { public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActionEvaluator<RolloutGroup.RolloutGroupSuccessAction> {
private static final Logger logger = LoggerFactory.getLogger(StartNextGroupRolloutGroupSuccessAction.class);
private final RolloutGroupRepository rolloutGroupRepository; private final RolloutGroupRepository rolloutGroupRepository;
private final DeploymentManagement deploymentManagement; private final DeploymentManagement deploymentManagement;
@@ -60,13 +58,13 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi
// started. // started.
final long countOfStartedActions = deploymentManagement.startScheduledActionsByRolloutGroupParent( final long countOfStartedActions = deploymentManagement.startScheduledActionsByRolloutGroupParent(
rollout.getId(), rollout.getDistributionSet().getId(), rolloutGroup.getId()); 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); rolloutGroup);
if (countOfStartedActions > 0) { if (countOfStartedActions > 0) {
// get all next scheduled groups and set them in state running // get all next scheduled groups and set them in state running
rolloutGroupRepository.setStatusForCildren(RolloutGroupStatus.RUNNING, rolloutGroup); rolloutGroupRepository.setStatusForCildren(RolloutGroupStatus.RUNNING, rolloutGroup);
} else { } 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()); rolloutGroup.getName());
// nothing for next group, just finish the group, this can happen // nothing for next group, just finish the group, this can happen
// e.g. if targets has been deleted after the group has been // e.g. if targets has been deleted after the group has been
@@ -78,7 +76,7 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi
if (nextGroup.isDynamic()) { if (nextGroup.isDynamic()) {
nextGroup.setStatus(RolloutGroupStatus.RUNNING); nextGroup.setStatus(RolloutGroupStatus.RUNNING);
} else { } else {
logger.debug("Rolloutgroup {} is finished, starting next group", nextGroup); log.debug("Rolloutgroup {} is finished, starting next group", nextGroup);
nextGroup.setStatus(RolloutGroupStatus.FINISHED); nextGroup.setStatus(RolloutGroupStatus.FINISHED);
rolloutGroupRepository.save(nextGroup); rolloutGroupRepository.save(nextGroup);
// find the next group to set in running state // find the next group to set in running state