From 11218d4f99c146b2584953ce55523c19c9bb4912 Mon Sep 17 00:00:00 2001 From: Pierantonio Merlino Date: Sun, 3 Nov 2024 16:20:09 +0100 Subject: [PATCH] feat: Add default log manager property (#5499) * Added default log manager property in System service Signed-off-by: pierantoniomerlino * Added logic for selecting default LogManager in web2 Signed-off-by: pierantoniomerlino * Aligned kura.properties Signed-off-by: pierantoniomerlino --------- Signed-off-by: pierantoniomerlino --- .../docker-x86_64-nn/kura.properties | 1 + .../generic-aarch64-nn/kura.properties | 1 + .../resources/generic-aarch64/kura.properties | 1 + .../generic-arm32-nn/kura.properties | 1 + .../resources/generic-arm32/kura.properties | 1 + .../generic-x86_64-nn/kura.properties | 1 + .../resources/generic-x86_64/kura.properties | 1 + .../org.eclipse.kura.api/META-INF/MANIFEST.MF | 2 +- .../eclipse/kura/system/SystemService.java | 19 ++++++++-- .../META-INF/MANIFEST.MF | 2 +- .../kura/core/system/SystemServiceImpl.java | 16 ++++----- .../kura/web/server/GwtLogServiceImpl.java | 29 ++++++++++++++- .../core/system/test/SystemServiceTest.java | 35 +++++++++++-------- 13 files changed, 81 insertions(+), 29 deletions(-) diff --git a/kura/distrib/src/main/resources/docker-x86_64-nn/kura.properties b/kura/distrib/src/main/resources/docker-x86_64-nn/kura.properties index cb3a64c4397..5903ea418ca 100644 --- a/kura/distrib/src/main/resources/docker-x86_64-nn/kura.properties +++ b/kura/distrib/src/main/resources/docker-x86_64-nn/kura.properties @@ -56,6 +56,7 @@ os.distribution.version=20.04 kura.command.user=kura kura.legacy.bluetooth.beacon.scan=false kura.legacy.ppp.logging.enabled=true +kura.default.log.manager=filesystem-kura-log ## ----------------------------------------------------------------------------- diff --git a/kura/distrib/src/main/resources/generic-aarch64-nn/kura.properties b/kura/distrib/src/main/resources/generic-aarch64-nn/kura.properties index 6afc9a353cf..dc1357604f2 100644 --- a/kura/distrib/src/main/resources/generic-aarch64-nn/kura.properties +++ b/kura/distrib/src/main/resources/generic-aarch64-nn/kura.properties @@ -56,6 +56,7 @@ os.distribution.version=N/A kura.command.user=kura kura.legacy.bluetooth.beacon.scan=false kura.legacy.ppp.logging.enabled=true +kura.default.log.manager=filesystem-kura-log ## ----------------------------------------------------------------------------- diff --git a/kura/distrib/src/main/resources/generic-aarch64/kura.properties b/kura/distrib/src/main/resources/generic-aarch64/kura.properties index 00204a9dcaa..adff21f471e 100644 --- a/kura/distrib/src/main/resources/generic-aarch64/kura.properties +++ b/kura/distrib/src/main/resources/generic-aarch64/kura.properties @@ -56,6 +56,7 @@ os.distribution.version=N/A kura.command.user=kura kura.legacy.bluetooth.beacon.scan=false kura.legacy.ppp.logging.enabled=true +kura.default.log.manager=filesystem-kura-log ## ----------------------------------------------------------------------------- diff --git a/kura/distrib/src/main/resources/generic-arm32-nn/kura.properties b/kura/distrib/src/main/resources/generic-arm32-nn/kura.properties index 1f856020d33..2be127c77b7 100644 --- a/kura/distrib/src/main/resources/generic-arm32-nn/kura.properties +++ b/kura/distrib/src/main/resources/generic-arm32-nn/kura.properties @@ -56,6 +56,7 @@ os.distribution.version=N/A kura.command.user=kura kura.legacy.bluetooth.beacon.scan=false kura.legacy.ppp.logging.enabled=true +kura.default.log.manager=filesystem-kura-log ## ----------------------------------------------------------------------------- diff --git a/kura/distrib/src/main/resources/generic-arm32/kura.properties b/kura/distrib/src/main/resources/generic-arm32/kura.properties index 4d821f45f16..e20c710914e 100644 --- a/kura/distrib/src/main/resources/generic-arm32/kura.properties +++ b/kura/distrib/src/main/resources/generic-arm32/kura.properties @@ -56,6 +56,7 @@ os.distribution.version=N/A kura.command.user=kura kura.legacy.bluetooth.beacon.scan=false kura.legacy.ppp.logging.enabled=true +kura.default.log.manager=filesystem-kura-log ## ----------------------------------------------------------------------------- diff --git a/kura/distrib/src/main/resources/generic-x86_64-nn/kura.properties b/kura/distrib/src/main/resources/generic-x86_64-nn/kura.properties index 248b30f37de..d91e42b8343 100644 --- a/kura/distrib/src/main/resources/generic-x86_64-nn/kura.properties +++ b/kura/distrib/src/main/resources/generic-x86_64-nn/kura.properties @@ -56,6 +56,7 @@ os.distribution.version=N/A kura.command.user=kura kura.legacy.bluetooth.beacon.scan=false kura.legacy.ppp.logging.enabled=true +kura.default.log.manager=filesystem-kura-log ## ----------------------------------------------------------------------------- diff --git a/kura/distrib/src/main/resources/generic-x86_64/kura.properties b/kura/distrib/src/main/resources/generic-x86_64/kura.properties index eab684412d0..0d1ca228570 100644 --- a/kura/distrib/src/main/resources/generic-x86_64/kura.properties +++ b/kura/distrib/src/main/resources/generic-x86_64/kura.properties @@ -56,6 +56,7 @@ os.distribution.version=N/A kura.command.user=kura kura.legacy.bluetooth.beacon.scan=false kura.legacy.ppp.logging.enabled=true +kura.default.log.manager=filesystem-kura-log ## ----------------------------------------------------------------------------- diff --git a/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF index a2e73678689..45cc542e232 100644 --- a/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.api/META-INF/MANIFEST.MF @@ -76,7 +76,7 @@ Export-Package: org.eclipse.kura;version="1.7.0", org.eclipse.kura.security.tamper.detection;version="1.0.0", org.eclipse.kura.ssl;version="2.1.0", org.eclipse.kura.status;version="1.0.2", - org.eclipse.kura.system;version="1.7.0", + org.eclipse.kura.system;version="1.8.0", org.eclipse.kura.type;version="1.1.0", org.eclipse.kura.usb;version="1.3.0", org.eclipse.kura.watchdog;version="1.0.2", diff --git a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/system/SystemService.java b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/system/SystemService.java index 92e4d5af864..21d71584a9a 100644 --- a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/system/SystemService.java +++ b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/system/SystemService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2021 Eurotech and/or its affiliates and others + * Copyright (c) 2011, 2024 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -115,7 +115,7 @@ public interface SystemService { * @since 2.2 */ public static final String KEY_LEGACY_BT_BEACON_SCAN = "kura.legacy.bluetooth.beacon.scan"; - + /** * @since 2.3 */ @@ -131,6 +131,11 @@ public interface SystemService { */ public static final String KEY_JDK_VENDOR_VERSION = "jdk.vendor.version"; + /** + * @since 2.8 + */ + public static final String KEY_DEFAULT_LOG_MANAGER = "kura.default.log.manager"; + /** * @deprecated */ @@ -579,7 +584,7 @@ public interface SystemService { * @return if the legacy beacon scan has to be used */ public boolean isLegacyBluetoothBeaconScan(); - + /** * Returns true (default) if the PPP logging in separate log file in /var/log is enabled. * @@ -606,4 +611,12 @@ public interface SystemService { */ public String getJdkVendorVersion(); + /** + * Returns the name of the default LogManager, if any. + * + * @since 2.8 + * @return the optional default LogManager + */ + public Optional getDefaultLogManager(); + } diff --git a/kura/org.eclipse.kura.core.system/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.core.system/META-INF/MANIFEST.MF index e050abf0f52..3451af7b08b 100644 --- a/kura/org.eclipse.kura.core.system/META-INF/MANIFEST.MF +++ b/kura/org.eclipse.kura.core.system/META-INF/MANIFEST.MF @@ -12,7 +12,7 @@ Import-Package: org.eclipse.kura;version="[1.0,2.0)", org.eclipse.kura.executor;version="[1.0,2.0)", org.eclipse.kura.net;version="[2.0,3.0)", - org.eclipse.kura.system;version="[1.7,1.8)", + org.eclipse.kura.system;version="[1.8,1.9)", org.osgi.framework;version="1.5.0", org.osgi.service.component;version="1.2.0", org.slf4j;version="1.6.4" diff --git a/kura/org.eclipse.kura.core.system/src/main/java/org/eclipse/kura/core/system/SystemServiceImpl.java b/kura/org.eclipse.kura.core.system/src/main/java/org/eclipse/kura/core/system/SystemServiceImpl.java index 38c32500584..d914c29d201 100644 --- a/kura/org.eclipse.kura.core.system/src/main/java/org/eclipse/kura/core/system/SystemServiceImpl.java +++ b/kura/org.eclipse.kura.core.system/src/main/java/org/eclipse/kura/core/system/SystemServiceImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2021 Eurotech and/or its affiliates and others + * Copyright (c) 2011, 2024 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -65,20 +65,13 @@ public class SystemServiceImpl extends SuperSystemService implements SystemService { + private static final Logger logger = LoggerFactory.getLogger(SystemServiceImpl.class); private static final String PROPERTY_PROVIDER_SUFFIX = ".provider"; - private static final String DMIDECODE_COMMAND = "dmidecode -t system"; - private static final String SPACES_REGEX = ":\\s+"; - private static final String BIN_SH = "/bin/sh"; - private static final String LINUX_2_6_34_12_WR4_3_0_0_STANDARD = "2.6.34.12-WR4.3.0.0_standard"; - private static final String LINUX_2_6_34_9_WR4_2_0_0_STANDARD = "2.6.34.9-WR4.2.0.0_standard"; - - private static final Logger logger = LoggerFactory.getLogger(SystemServiceImpl.class); - private static final String CLOUDBEES_SECURITY_SETTINGS_PATH = "/private/eurotech/settings-security.xml"; private static final String LOG4J_CONFIGURATION = "log4j.configuration"; private static final String DPA_CONFIGURATION = "dpa.configuration"; @@ -1529,4 +1522,9 @@ public String getJdkVendorVersion() { return System.getProperty(KEY_JDK_VENDOR_VERSION); } + @Override + public Optional getDefaultLogManager() { + return getProperty(KEY_DEFAULT_LOG_MANAGER); + } + } diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtLogServiceImpl.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtLogServiceImpl.java index bf637142c8b..70364ad4071 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtLogServiceImpl.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/GwtLogServiceImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others + * Copyright (c) 2021, 2024 Eurotech and/or its affiliates and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -17,10 +17,12 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import org.eclipse.kura.configuration.ConfigurationService; import org.eclipse.kura.log.LogEntry; import org.eclipse.kura.log.LogProvider; +import org.eclipse.kura.system.SystemService; import org.eclipse.kura.web.server.util.ServiceLocator; import org.eclipse.kura.web.shared.GwtKuraException; import org.eclipse.kura.web.shared.model.GwtLogEntry; @@ -39,6 +41,8 @@ public class GwtLogServiceImpl extends OsgiRemoteServiceServlet implements GwtLo private static final LogEntriesCache cache = new LogEntriesCache(); private static final List registeredLogProviders = new LinkedList<>(); + private static SystemService systemService; + @Override public List initLogProviders(GwtXSRFToken xsrfToken) throws GwtKuraException { checkXSRFToken(xsrfToken); @@ -90,6 +94,16 @@ private void loadLogProviders() { logger.info("LogProvider {} no more available.", pid); } } + + Optional defaultLogManager = getDefaultLogManager(); + if (defaultLogManager.isPresent() && !registeredLogProviders.isEmpty() + && !registeredLogProviders.get(0).equals(defaultLogManager.get())) { + String logManager = defaultLogManager.get(); + if (registeredLogProviders.contains(logManager)) { + registeredLogProviders.remove(logManager); + registeredLogProviders.add(0, logManager); + } + } } catch (GwtKuraException e) { logger.error("Error loading log providers."); } @@ -105,6 +119,19 @@ private String getFormattedTimestamp(LogEntry entry) { } } + private Optional getDefaultLogManager() { + Optional defaultLogManager = Optional.empty(); + try { + SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class); + if (systemService != null) { + defaultLogManager = systemService.getDefaultLogManager(); + } + } catch (GwtKuraException e) { + logger.error("Error retrieving default LogManager name", e); + } + return defaultLogManager; + } + private static final class LogEntriesCache { private static final LinkedList cache = new LinkedList<>(); diff --git a/kura/test/org.eclipse.kura.core.system.test/src/main/java/org/eclipse/kura/core/system/test/SystemServiceTest.java b/kura/test/org.eclipse.kura.core.system.test/src/main/java/org/eclipse/kura/core/system/test/SystemServiceTest.java index 557ecd75223..9076abf248f 100644 --- a/kura/test/org.eclipse.kura.core.system.test/src/main/java/org/eclipse/kura/core/system/test/SystemServiceTest.java +++ b/kura/test/org.eclipse.kura.core.system.test/src/main/java/org/eclipse/kura/core/system/test/SystemServiceTest.java @@ -12,14 +12,13 @@ *******************************************************************************/ package org.eclipse.kura.core.system.test; -import org.eclipse.kura.core.testutil.TestUtil; -import org.eclipse.kura.executor.Command; -import org.eclipse.kura.executor.CommandExecutorService; -import org.eclipse.kura.executor.CommandStatus; -import org.eclipse.kura.system.SystemService; -import org.eclipse.kura.test.annotation.TestTarget; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.BufferedReader; import java.io.File; @@ -31,12 +30,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.eclipse.kura.core.testutil.TestUtil; +import org.eclipse.kura.executor.Command; +import org.eclipse.kura.executor.CommandExecutorService; +import org.eclipse.kura.executor.CommandStatus; +import org.eclipse.kura.system.SystemService; +import org.eclipse.kura.test.annotation.TestTarget; +import org.junit.BeforeClass; +import org.junit.Test; public class SystemServiceTest { @@ -368,4 +369,10 @@ public void getSerialNumber() throws NoSuchFieldException { } } + @TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL }) + @Test + public void shouldGetDefaultLogManagerProperty() { + assertFalse(systemService.getDefaultLogManager().isPresent()); + } + }