summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-context/context-distribution
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-context/context-distribution')
-rw-r--r--plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java88
1 files changed, 7 insertions, 81 deletions
diff --git a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java
index 803d99adc..1a2076f10 100644
--- a/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java
+++ b/plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java
@@ -20,14 +20,11 @@
package org.onap.policy.apex.plugins.context.distribution.infinispan;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
+import java.io.IOException;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
import org.onap.policy.apex.context.ContextException;
-import org.onap.policy.apex.model.utilities.ResourceUtils;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -53,31 +50,16 @@ public class InfinispanManager {
setSystemProperties(infinispanDistributorParameters);
- // First, try and open a local input stream for Infinispan configuration
- InputStream infinispanConfigStream =
- getLocalInfinispanConfigurationStream(infinispanDistributorParameters.getConfigFile());
-
- // Check if a local file was found, if not then go to the class path
- if (infinispanConfigStream == null) {
- // If a local file is not specified, then check for an infinispan configuration file on
- // the class path
- infinispanConfigStream =
- getClasspathInfinispanConfigurationStream(infinispanDistributorParameters.getConfigFile());
- }
-
- // Check if we found configuration for Infinispan
- if (infinispanConfigStream == null) {
+ try {
+ LOGGER.debug("starting infinispan cache manager using specified configuration . . .");
+ cacheManager = new DefaultCacheManager(infinispanDistributorParameters.getConfigFile());
+ LOGGER.debug("started infinispan cache manager using specified configuration");
+ } catch (final IOException ioException) {
final String errorMessage =
"failed to start infinispan cache manager, no infinispan configuration found on local file system or in classpath, "
+ "try setting Infinspan \"configFile\" parameter";
LOGGER.error(errorMessage);
- throw new ContextException(errorMessage);
- }
-
- try {
- LOGGER.debug("starting infinispan cache manager using specified configuration . . .");
- cacheManager = new DefaultCacheManager(infinispanConfigStream);
- LOGGER.debug("started infinispan cache manager using specified configuration");
+ throw new ContextException(errorMessage, ioException);
} catch (final Exception e) {
LOGGER.error("failed to start infinispan cache manager using specified configuration", e);
throw new ContextException("failed to start infinispan cache manager using specified configuration", e);
@@ -124,62 +106,6 @@ public class InfinispanManager {
}
/**
- * Get an Infinispan configuration stream from the local file system.
- *
- * @param infinispanConfigFileName The file name to open
- * @return The file opened as a stream
- * @throws ContextException If the local file could not be found or is invalid
- */
- private InputStream getLocalInfinispanConfigurationStream(final String infinispanConfigFileName)
- throws ContextException {
- LOGGER.debug("checking infinispan configuration file exists at \"" + infinispanConfigFileName + "\". . .");
-
- // Check if the file exists
- final File infinispanConfigFile = new File(infinispanConfigFileName);
- if (!infinispanConfigFile.exists()) {
- return null;
- }
-
- // Check the file
- if (!infinispanConfigFile.isFile() || !infinispanConfigFile.canRead()) {
- LOGGER.error("infinispan configuration file at \"" + infinispanConfigFileName
- + "\" does not exist or is invalid");
- throw new ContextException("infinispan configuration file at \"" + infinispanConfigFileName
- + "\" does not exist or is invalid");
- }
-
- try {
- final InputStream infinispanConfigStream = new FileInputStream(infinispanConfigFile);
- LOGGER.debug("infinispan configuration file exists at \"" + infinispanConfigFileName + "\"");
- return infinispanConfigStream;
- } catch (final Exception e) {
- LOGGER.error("infinispan configuration file at \"" + infinispanConfigFileName
- + "\" does not exist or is invalid", e);
- throw new ContextException("infinispan configuration file at \"" + infinispanConfigFileName
- + "\" does not exist or is invalid", e);
- }
- }
-
- /**
- * Get an Infinispan configuration stream from the class path.
- *
- * @param apexInfinispanConfigFile the apex infinispan config file
- * @return The file opened as a stream
- */
- private InputStream getClasspathInfinispanConfigurationStream(final String apexInfinispanConfigFile) {
- LOGGER.debug(
- "checking infinispan configuration file exists at resource \"" + apexInfinispanConfigFile + "\". . .");
- final InputStream infinispanConfigStream = ResourceUtils.getResourceAsStream(apexInfinispanConfigFile);
-
- if (infinispanConfigStream != null) {
- LOGGER.debug("infinispan configuration file exists at resource \"" + apexInfinispanConfigFile + "\"");
- } else {
- LOGGER.debug("infinispan configuration file at resource \"" + apexInfinispanConfigFile + "\" not found");
- }
- return infinispanConfigStream;
- }
-
- /**
* Private class to implement the shutdown hook for this infinispan manager.
*/
public class InfinspanManagerShutdownHook extends Thread {