summaryrefslogtreecommitdiffstats
path: root/common-app-api/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-07-13 13:59:35 +0100
committerMichael Morris <michael.morris@est.tech>2023-07-13 15:01:24 +0000
commit669052a080343c36e565638d13275074f630db2a (patch)
treed63c76367d02eb10d7358150e5b54528a98a48c8 /common-app-api/src
parent0278649141c9247b2ec56bb76998c3b9aa412874 (diff)
Replace outdated dependency - org.apache.commons:commons-jci-core:jar:1.1
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I5b34fff0600f1343a4ca9e00cf737946e3737214 Issue-ID: SDC-4569
Diffstat (limited to 'common-app-api/src')
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java8
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/impl/ExternalConfiguration.java31
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java3
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java21
4 files changed, 25 insertions, 38 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java
index 4efc43d675..ca923b53cd 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ConfigFileChangeListener.java
@@ -25,7 +25,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.jci.listeners.FileChangeListener;
+import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.openecomp.sdc.common.api.BasicConfiguration;
import org.openecomp.sdc.common.api.ConfigurationListener;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
@@ -33,7 +33,8 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.YamlToObjectConverter;
import org.openecomp.sdc.exception.YamlConversionException;
-public class ConfigFileChangeListener extends FileChangeListener {
+
+public class ConfigFileChangeListener extends FileAlterationListenerAdaptor {
private static final Logger LOGGER = Logger.getLogger(ConfigFileChangeListener.class.getName());
private Map<String, List<ConfigurationListener>> fileChangeToCallBack = new HashMap<>();
@@ -42,7 +43,6 @@ public class ConfigFileChangeListener extends FileChangeListener {
@Override
public void onFileChange(File pFile) {
- super.onFileChange(pFile);
if (pFile == null) {
LOGGER.debug("Invalid file '{}'.", pFile);
return;
@@ -68,7 +68,7 @@ public class ConfigFileChangeListener extends FileChangeListener {
basicConfiguration = yamlToObjectConverter.convert(pFile.getAbsolutePath(), configClass);
} catch (final YamlConversionException e) {
LOGGER.warn(EcompLoggerErrorCode.SCHEMA_ERROR, "Configuration", "Configuration",
- "Cannot update the listeners for file Change since the file content is invalid: {}", e.getLocalizedMessage());
+ "Cannot update the listeners for file Change since the file content is invalid: {}", e.getLocalizedMessage());
continue;
}
LOGGER.debug("Loaded configuration after converting is {}", basicConfiguration);
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ExternalConfiguration.java b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ExternalConfiguration.java
index 7c665c61cd..def72b7d56 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ExternalConfiguration.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/ExternalConfiguration.java
@@ -20,9 +20,11 @@
package org.openecomp.sdc.common.impl;
import java.io.File;
-import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
+import org.apache.commons.io.monitor.FileAlterationMonitor;
+import org.apache.commons.io.monitor.FileAlterationObserver;
import org.openecomp.sdc.common.api.ConfigurationSource;
+
/**
* Save the
*
@@ -34,7 +36,7 @@ public class ExternalConfiguration {
private static String appVersion;
private static String configDir;
private static ConfigurationSource configurationSource;
- private static FilesystemAlterationMonitor fam = null;
+ private static FileAlterationMonitor monitor;
private static ConfigFileChangeListener changeListener = new ConfigFileChangeListener();
private static boolean enableReconfigure = true;
@@ -75,23 +77,28 @@ public class ExternalConfiguration {
}
public static void listenForChanges() {
- String watchingDir = configDir + File.separator + appName;
if (enableReconfigure) {
- if (fam == null) {
- fam = new FilesystemAlterationMonitor();
- fam.setInterval(1000);
- fam.addListener(new File(watchingDir), changeListener);
- fam.start();
+ monitor = new FileAlterationMonitor();
+ final String watchingDir = configDir + File.separator + appName;
+ final FileAlterationObserver observer = new FileAlterationObserver(watchingDir);
+ observer.addListener(changeListener);
+ monitor.addObserver(observer);
+ try {
+ monitor.start();
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
}
}
}
public static void stopListenForFileChanges() {
- if (enableReconfigure) {
- if (fam != null) {
- fam.stop();
- fam = null;
+ if (enableReconfigure && monitor != null) {
+ try {
+ monitor.stop();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
+ monitor = null;
}
}
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java b/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java
index 70a94fd460..a4e615690b 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/listener/AppContextListener.java
@@ -39,6 +39,7 @@ public class AppContextListener implements ServletContextListener {
private static Logger log = Logger.getLogger(AppContextListener.class.getName());
+ @Override
public void contextInitialized(ServletContextEvent context) {
log.debug("ServletContextListener initialized ");
log.debug("After read values from Manifest {}", getManifestInfo(context.getServletContext()));
@@ -50,13 +51,13 @@ public class AppContextListener implements ServletContextListener {
String configHome = System.getProperty(Constants.CONFIG_HOME);
ExternalConfiguration.setConfigDir(configHome);
String appConfigDir = configHome + File.separator + appName;
- // ChangeListener changeListener = new ChangeListener();
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
context.getServletContext().setAttribute(Constants.CONFIGURATION_SOURCE_ATTR, configurationSource);
ExternalConfiguration.setConfigurationSource(configurationSource);
ExternalConfiguration.listenForChanges();
}
+ @Override
public void contextDestroyed(ServletContextEvent context) {
log.debug("ServletContextListener destroyed");
ExternalConfiguration.stopListenForFileChanges();
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java
index 0d5cf62cb1..38d1e65b67 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/ConfigurationManager.java
@@ -102,26 +102,5 @@ public class ConfigurationManager implements FileChangeCallback, IEcompConfigura
}
public void reconfigure(BasicConfiguration obj) {
- //
-
- // if (obj != null) {
-
- //
-
- // if (obj instanceof Configuration) {
-
- // configurations.put(getKey(Configuration.class), obj);
-
- // }
-
- //
-
- // if (obj instanceof EcompErrorConfiguration) {
-
- // configurations.put(getKey(EcompErrorConfiguration.class), obj);
-
- // }
-
- // }
}
}