Add deprecation log utility - easy way to log usage of deprecated methods (#2741)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -11,23 +11,17 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import static org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility.sanitizeActionSortParam;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtActionMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.LogUtility;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
@@ -45,28 +39,13 @@ public class MgmtActionResource implements MgmtActionRestApi {
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("DEPRECATED_USAGE");
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtAction>> getActions(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam,
|
||||
final String representationModeParam) {
|
||||
try {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
final HttpServletRequest httpServletRequest = RequestResponseContextHolder.getHttpServletRequest();
|
||||
final String remoteHost = httpServletRequest.getRemoteHost();
|
||||
final String refererOrOrigin = Optional.ofNullable(httpServletRequest.getHeader("Referer"))
|
||||
.map(referer -> "Referer: " + referer)
|
||||
.orElseGet(() -> "Origin: " + httpServletRequest.getHeader("Origin"));
|
||||
if (rsqlParam != null && rsqlParam.contains("status")) {
|
||||
LOGGER.debug("[DEPRECATED] [{}/{}] Usage of getActions with RSQL that is up to modification: rsql='{}'.",
|
||||
remoteHost, refererOrOrigin, rsqlParam);
|
||||
} else {
|
||||
LOGGER.debug("[DEPRECATED] [{}/{}] Usage of getActions:result that is up to modification.", remoteHost, refererOrOrigin);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
LOGGER.error("[DEPRECATED] Unexpected logging exception!", e);
|
||||
}
|
||||
LogUtility.logDeprecated(rsqlParam != null && rsqlParam.contains("status")
|
||||
? "Usage of getActions with RSQL that is up to modification: rsql=" + rsqlParam
|
||||
: "Usage of getActions:result that is up to modification.");
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeActionSortParam(sortParam));
|
||||
|
||||
final Slice<Action> actions;
|
||||
@@ -85,6 +64,7 @@ public class MgmtActionResource implements MgmtActionRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtAction> getAction(final Long actionId) {
|
||||
LogUtility.logDeprecated("Usage of getActions:result that is up to modification.");
|
||||
final Action action = deploymentManagement.findAction(actionId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTagMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.LogUtility;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
@@ -33,8 +34,6 @@ import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.utils.TenantConfigHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -159,10 +158,10 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("DEPRECATED_USAGE");
|
||||
@Override
|
||||
public ResponseEntity<Void> assignTargetsPut(final Long targetTagId, final List<String> controllerIds, final OnNotFoundPolicy onNotFoundPolicy) {
|
||||
LOGGER.debug("[DEPRECATED] Deprecated usage of assignTargetsPut. Use assignTargetsPut (POST) instead.");
|
||||
public ResponseEntity<Void> assignTargetsPut(
|
||||
final Long targetTagId, final List<String> controllerIds, final OnNotFoundPolicy onNotFoundPolicy) {
|
||||
LogUtility.logDeprecated("Deprecated usage of assignTargetsPut. Use assignTargetsPut (POST) instead.");
|
||||
return assignTargets(targetTagId, controllerIds, onNotFoundPolicy);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Contributors to the Eclipse Foundation
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource.util;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class LogUtility {
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("DEPRECATED_USAGE");
|
||||
|
||||
public static void logDeprecated(final String message) {
|
||||
try {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
final HttpServletRequest httpServletRequest = RequestResponseContextHolder.getHttpServletRequest();
|
||||
final String remoteHost = httpServletRequest.getRemoteHost();
|
||||
final String refererOrOrigin = Optional.ofNullable(httpServletRequest.getHeader("Referer"))
|
||||
.map(referer -> "Referer: " + referer)
|
||||
.orElseGet(() -> "Origin: " + httpServletRequest.getHeader("Origin"));
|
||||
LOGGER.debug("[DEPRECATED] [{}/{}] {}", remoteHost, refererOrOrigin, message);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
LOGGER.error("[DEPRECATED] Unexpected logging exception!", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user