Skip to content

Commit

Permalink
feat: Add default log manager property [backport release-5.6.0] (#5507)
Browse files Browse the repository at this point in the history
feat: Add default log manager property (#5499)

* Added default log manager property in System service

Signed-off-by: pierantoniomerlino <[email protected]>

* Added logic for selecting default LogManager in web2

Signed-off-by: pierantoniomerlino <[email protected]>

* Aligned kura.properties

Signed-off-by: pierantoniomerlino <[email protected]>

---------

Signed-off-by: pierantoniomerlino <[email protected]>
(cherry picked from commit 11218d4)

Co-authored-by: Pierantonio Merlino <[email protected]>
  • Loading branch information
eclipse-kura-bot and pierantoniomerlino authored Nov 4, 2024
1 parent 132eded commit f43a382
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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


## -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


## -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


## -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


## -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


## -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


## -----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


## -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -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.
*
Expand All @@ -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<String> getDefaultLogManager();

}
2 changes: 1 addition & 1 deletion kura/org.eclipse.kura.core.system/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -1529,4 +1522,9 @@ public String getJdkVendorVersion() {
return System.getProperty(KEY_JDK_VENDOR_VERSION);
}

@Override
public Optional<String> getDefaultLogManager() {
return getProperty(KEY_DEFAULT_LOG_MANAGER);
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -39,6 +41,8 @@ public class GwtLogServiceImpl extends OsgiRemoteServiceServlet implements GwtLo
private static final LogEntriesCache cache = new LogEntriesCache();
private static final List<String> registeredLogProviders = new LinkedList<>();

private static SystemService systemService;

@Override
public List<String> initLogProviders(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
Expand Down Expand Up @@ -90,6 +94,16 @@ private void loadLogProviders() {
logger.info("LogProvider {} no more available.", pid);
}
}

Optional<String> 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.");
}
Expand All @@ -105,6 +119,19 @@ private String getFormattedTimestamp(LogEntry entry) {
}
}

private Optional<String> getDefaultLogManager() {
Optional<String> 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<GwtLogEntry> cache = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -368,4 +369,10 @@ public void getSerialNumber() throws NoSuchFieldException {
}
}

@TestTarget(targetPlatforms = { TestTarget.PLATFORM_ALL })
@Test
public void shouldGetDefaultLogManagerProperty() {
assertFalse(systemService.getDefaultLogManager().isPresent());
}

}

0 comments on commit f43a382

Please sign in to comment.