aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-context
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@ericsson.com>2018-06-07 16:01:35 +0100
committerwaqas.ikram <waqas.ikram@ericsson.com>2018-06-08 11:48:06 +0100
commit6a9b54b275feff5369419a86997e94d0a95fc48e (patch)
tree8366bfb005057388b99c5639ed17496c881667f1 /plugins/plugins-context
parent9289ac0afefe62f6c8e9cebddb611a8571bf5642 (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')
-rw-r--r--plugins/plugins-context/context-distribution/context-distribution-infinispan/src/main/java/org/onap/policy/apex/plugins/context/distribution/infinispan/InfinispanManager.java88
-rw-r--r--plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java2
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java2
-rw-r--r--plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java2
4 files changed, 11 insertions, 83 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 {
diff --git a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java
index d0cc842fd..477a010fa 100644
--- a/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java
+++ b/plugins/plugins-context/context-locking/context-locking-curator/src/main/java/org/onap/policy/apex/plugins/context/locking/curator/CuratorLockManager.java
@@ -105,6 +105,8 @@ public class CuratorLockManager extends AbstractLockManager {
lockParameters.getZookeeperConnectSleepTime() * lockParameters.getZookeeperContextRetries(),
TimeUnit.MILLISECONDS);
} catch (final InterruptedException e) {
+ // restore the interrupt status
+ Thread.currentThread().interrupt();
LOGGER.warn("could not connect to Zookeeper server at \"" + curatorZookeeperAddress
+ "\", wait for connection timed out");
throw new ContextException("could not connect to Zookeeper server at \"" + curatorZookeeperAddress
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java
index dd55f447d..22152a8da 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroObjectMapperFactory.java
@@ -90,7 +90,7 @@ public class AvroObjectMapperFactory {
if (Schema.Type.NULL.equals(schema.getType())) {
schema = types.get(1);
}
- if (Schema.Type.NULL.equals(schema.getType()) || Schema.Type.NULL.equals(schema.getType())) {
+ if (Schema.Type.NULL.equals(schema.getType())) {
final String resultSting = userKey.getID()
+ ": Apex currently only supports UNION schema2 with 2 options, only one can be NULL, and the other cannot be another UNION";
LOGGER.warn(resultSting);
diff --git a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
index 2543dd154..831962042 100644
--- a/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
+++ b/plugins/plugins-context/context-schema/context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
@@ -153,7 +153,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper {
objectString = (String) object;
}
} catch (final ClassCastException e) {
- final String returnString = getUserKey().getID() + ": object \"" + object.toString() + "\" of type \""
+ final String returnString = getUserKey().getID() + ": object \"" + object + "\" of type \""
+ object.getClass().getCanonicalName() + "\" must be assignable to \""
+ getSchemaClass().getCanonicalName()
+ "\" or be a Json string representation of it for Avro unmarshalling";