diff options
author | waqas.ikram <waqas.ikram@ericsson.com> | 2018-06-07 16:01:35 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@ericsson.com> | 2018-06-08 11:48:06 +0100 |
commit | 6a9b54b275feff5369419a86997e94d0a95fc48e (patch) | |
tree | 8366bfb005057388b99c5639ed17496c881667f1 /plugins/plugins-context/context-distribution/context-distribution-infinispan | |
parent | 9289ac0afefe62f6c8e9cebddb611a8571bf5642 (diff) |
Fixing Sonar bugs and Vulnerabilities
Change-Id: Id5a95f23f1308dbb9f7f0c0f5567e238ecf830af
Issue-ID: POLICY-859
Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
Diffstat (limited to 'plugins/plugins-context/context-distribution/context-distribution-infinispan')
-rw-r--r-- | plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java | 88 |
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 { |