diff options
Diffstat (limited to 'appc-common/src/main/java')
13 files changed, 204 insertions, 79 deletions
diff --git a/appc-common/src/main/java/org/openecomp/appc/Constants.java b/appc-common/src/main/java/org/openecomp/appc/Constants.java index c5315edd7..5e59971ac 100644 --- a/appc-common/src/main/java/org/openecomp/appc/Constants.java +++ b/appc-common/src/main/java/org/openecomp/appc/Constants.java @@ -168,10 +168,10 @@ public final class Constants { @SuppressWarnings("nls") public static final String STATUS_GETTER = "status-getter"; - @SuppressWarnings("nls") + @SuppressWarnings("nls") public static final String VM_FUSION_STATUS_GETTER = "fusion-vm-status-getter"; - /** + /** * The name for the status vm attribute to be set in the context when executing a vmstatuscheck. */ diff --git a/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategies.java b/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategies.java index 7f63e00bf..196b645a9 100644 --- a/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategies.java +++ b/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategies.java @@ -24,7 +24,9 @@ package org.openecomp.appc.cache; - +/** + * Enum of CacheStrategies + */ public enum CacheStrategies { - LRU; + LRU } diff --git a/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategy.java b/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategy.java index aa0a5d785..e07708119 100644 --- a/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategy.java +++ b/appc-common/src/main/java/org/openecomp/appc/cache/CacheStrategy.java @@ -24,8 +24,23 @@ package org.openecomp.appc.cache; - -public interface CacheStrategy <K,V>{ +/** + * Interface of CacheStrategy + * @param <K> key + * @param <V> value + */ +public interface CacheStrategy <K,V> { + /** + * Get object + * @param key of the object + * @return value of the object + */ V getObject(K key); + + /** + * Put object + * @param key of the object + * @param value of the object + */ void putObject(K key,V value); } diff --git a/appc-common/src/main/java/org/openecomp/appc/cache/MetadataCache.java b/appc-common/src/main/java/org/openecomp/appc/cache/MetadataCache.java index d5b1d7b93..8196e8e3d 100644 --- a/appc-common/src/main/java/org/openecomp/appc/cache/MetadataCache.java +++ b/appc-common/src/main/java/org/openecomp/appc/cache/MetadataCache.java @@ -24,8 +24,23 @@ package org.openecomp.appc.cache; - -public interface MetadataCache <K,V>{ +/** + * Interface of MetadataCache + * @param <K> key + * @param <V> value + */ +public interface MetadataCache <K,V> { + /** + * Get object + * @param key of the object + * @return value of the object + */ V getObject(K key); + + /** + * Put object + * @param key of the object + * @param value of the object + */ void putObject(K key,V value); } diff --git a/appc-common/src/main/java/org/openecomp/appc/cache/impl/LRUCache.java b/appc-common/src/main/java/org/openecomp/appc/cache/impl/LRUCache.java index 5cb8ef534..b97a5f642 100644 --- a/appc-common/src/main/java/org/openecomp/appc/cache/impl/LRUCache.java +++ b/appc-common/src/main/java/org/openecomp/appc/cache/impl/LRUCache.java @@ -29,12 +29,17 @@ import java.util.Map; import org.openecomp.appc.cache.CacheStrategy; +/** + * LRU cache implements CacheStategy<K, V> + * @param <K> Key + * @param <V> Value + */ public class LRUCache<K,V> implements CacheStrategy<K,V> { private Map<K,V> map; LRUCache(final Integer capacity){ - map = new LinkedHashMap<K,V>(capacity, 0.75F, true){ + map = new LinkedHashMap<K,V>(capacity, 0.75F, true) { @Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest){ return size() > capacity; diff --git a/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheFactory.java b/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheFactory.java index 306a23a99..91ad48f9b 100644 --- a/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheFactory.java +++ b/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheFactory.java @@ -25,16 +25,23 @@ package org.openecomp.appc.cache.impl; import org.openecomp.appc.cache.CacheStrategies; -import org.openecomp.appc.cache.CacheStrategy; import org.openecomp.appc.cache.MetadataCache; +/** + * Metadata Cache Factory + */ public class MetadataCacheFactory { - private static class ReferenceHolder{ + private static class ReferenceHolder { + private ReferenceHolder() { + throw new IllegalAccessError("ReferenceHolder"); + } + private static final MetadataCacheFactory FACTORY = new MetadataCacheFactory(); } - private MetadataCacheFactory(){ + private MetadataCacheFactory() { + // do nothing } public static MetadataCacheFactory getInstance(){ @@ -44,7 +51,13 @@ public class MetadataCacheFactory { public MetadataCache getMetadataCache(){ return new MetadataCacheImpl(); } - public MetadataCache getMetadataCache(CacheStrategies cacheStrategy){ + + /** + * Get MetadataCache + * @param cacheStrategy the CacheStrategies to be used to build MetadataCacheImpl + * @return a new instance of MetadataCacheImpl + */ + public MetadataCache getMetadataCache(CacheStrategies cacheStrategy) { return new MetadataCacheImpl(cacheStrategy); } diff --git a/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheImpl.java b/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheImpl.java index 966100666..249a97c3c 100644 --- a/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheImpl.java +++ b/appc-common/src/main/java/org/openecomp/appc/cache/impl/MetadataCacheImpl.java @@ -28,7 +28,11 @@ import org.openecomp.appc.cache.CacheStrategies; import org.openecomp.appc.cache.CacheStrategy; import org.openecomp.appc.cache.MetadataCache; - +/** + * Implementation of MetadataCache + * @param <K> Key + * @param <V> Value + */ public class MetadataCacheImpl<K,V> implements MetadataCache<K,V> { private CacheStrategy strategy; @@ -42,9 +46,13 @@ public class MetadataCacheImpl<K,V> implements MetadataCache<K,V> { } private CacheStrategy initializeStrategy(CacheStrategies strategy) { - switch (strategy){ - case LRU: - return new LRUCache<>(50); + if (strategy != null) { + switch (strategy) { + case LRU: + return new LRUCache<>(50); + default: + // do nothing + } } return null; } diff --git a/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java b/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java index 96d9be86c..635384952 100644 --- a/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java +++ b/appc-common/src/main/java/org/openecomp/appc/configuration/DefaultConfiguration.java @@ -24,7 +24,6 @@ package org.openecomp.appc.configuration; - import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -64,7 +63,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { /** * Construct the configuration object. */ - public DefaultConfiguration() { + DefaultConfiguration() { // do nothing } @@ -97,22 +96,20 @@ public final class DefaultConfiguration implements Configuration, Cloneable { */ @SuppressWarnings("nls") private static String decrypt(String value) { - if (value != null) { - if (value.startsWith(EncryptionTool.ENCRYPTED_VALUE_PREFIX)) { - try { - return EncryptionTool.getInstance().decrypt(value); - } catch (Exception e) { - StringBuilder out = new StringBuilder(); - for (Provider p : Security.getProviders()) { - for (Service s : p.getServices()) { - String algo = s.getAlgorithm(); - out.append(String.format("\n==Found Algorithm [ %s ] in provider [ %s ] and service [ %s ]", - algo, p.getName(), s.getClassName())); - } + if (value != null && value.startsWith(EncryptionTool.ENCRYPTED_VALUE_PREFIX)) { + try { + return EncryptionTool.getInstance().decrypt(value); + } catch (Exception e) { + StringBuilder out = new StringBuilder(); + for (Provider p : Security.getProviders()) { + for (Service s : p.getServices()) { + String algo = s.getAlgorithm(); + out.append(String.format("\n==Found Algorithm [ %s ] in provider [ %s ] and service [ %s ]", + algo, p.getName(), s.getClassName())); } - logger.debug(out.toString()); - logger.warn(String.format("Could not decrypt the configuration value [%s]", value), e); } + logger.debug(out.toString()); + logger.warn(String.format("Could not decrypt the configuration value [%s]", value), e); } } return value; @@ -172,9 +169,9 @@ public final class DefaultConfiguration implements Configuration, Cloneable { // template = decrypt(template); DH: Do not assign values to parameters, bad form! Also, Sonar complains // bitterly - StringBuffer buffer = new StringBuffer(decrypt(template)); + StringBuilder builder = new StringBuilder(decrypt(template)); Pattern pattern = Pattern.compile("\\$\\{([^\\}]+)\\}"); - Matcher matcher = pattern.matcher(buffer); + Matcher matcher = pattern.matcher(builder); while (matcher.find()) { String variable = matcher.group(1); String value = properties.getProperty(variable); @@ -184,11 +181,11 @@ public final class DefaultConfiguration implements Configuration, Cloneable { if (value == null) { value = ""; } - buffer.replace(matcher.start(), matcher.end(), value); + builder.replace(matcher.start(), matcher.end(), value); matcher.reset(); } - return buffer.toString().trim(); + return builder.toString().trim(); } /** @@ -379,7 +376,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { */ @Override public int hashCode() { - return (properties == null ? 0 : properties.hashCode()); + return properties == null ? 0 : properties.hashCode(); } /** @@ -487,7 +484,7 @@ public final class DefaultConfiguration implements Configuration, Cloneable { try { properties.load(is); } catch (IOException e) { - e.printStackTrace(); + logger.warn("setProperties with inputStream got exception", e); } } @@ -524,8 +521,8 @@ public final class DefaultConfiguration implements Configuration, Cloneable { @SuppressWarnings("nls") @Override public String toString() { - return String.format("Configuration: %d properties, keys:[%s]", properties.size(), properties.keySet() - .toString()); + return String.format("Configuration: %d properties, keys:[%s]", + properties.size(), properties.keySet().toString()); } /** diff --git a/appc-common/src/main/java/org/openecomp/appc/exceptions/APPCException.java b/appc-common/src/main/java/org/openecomp/appc/exceptions/APPCException.java index 808434d62..314d0a601 100644 --- a/appc-common/src/main/java/org/openecomp/appc/exceptions/APPCException.java +++ b/appc-common/src/main/java/org/openecomp/appc/exceptions/APPCException.java @@ -22,8 +22,6 @@ * ============LICENSE_END========================================================= */ - - package org.openecomp.appc.exceptions; /** diff --git a/appc-common/src/main/java/org/openecomp/appc/exceptions/UnknownProviderException.java b/appc-common/src/main/java/org/openecomp/appc/exceptions/UnknownProviderException.java index 1551f48d1..f3eb8a486 100644 --- a/appc-common/src/main/java/org/openecomp/appc/exceptions/UnknownProviderException.java +++ b/appc-common/src/main/java/org/openecomp/appc/exceptions/UnknownProviderException.java @@ -22,8 +22,6 @@ * ============LICENSE_END========================================================= */ - - package org.openecomp.appc.exceptions; /** @@ -100,7 +98,10 @@ public class UnknownProviderException extends APPCException { * @param writableStackTrace * whether or not the stack trace should be writable */ - public UnknownProviderException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + public UnknownProviderException(String message, + Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingConstants.java b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingConstants.java index 9d6a32fe9..5c6d7b2b7 100644 --- a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingConstants.java +++ b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingConstants.java @@ -24,9 +24,21 @@ package org.openecomp.appc.logging; +/** + * Constant definition of logging + */ public class LoggingConstants { + private LoggingConstants() { + throw new IllegalAccessError("LoggingConstants"); + } + /** + * Constants of MDC property keys + */ public static class MDCKeys { + private MDCKeys() { + throw new IllegalAccessError("MDCKeys"); + } public static final String ERROR_CODE = "ErrorCode"; public static final String ERROR_DESCRIPTION = "ErrorDescription"; @@ -44,12 +56,24 @@ public class LoggingConstants { public static final String TARGET_VIRTUAL_ENTITY = "TargetVirtualEntity"; } + /** + * Constants of status code values + */ public static class StatusCodes { + private StatusCodes() { + throw new IllegalAccessError("StatusCodes"); + } public static final String COMPLETE = "COMPLETE"; public static final String ERROR = "ERROR"; } + /** + * Constants of APPC target names + */ public static class TargetNames { + private TargetNames() { + throw new IllegalAccessError("TargetNames"); + } public static final String APPC = "APPC"; public static final String AAI = "A&AI"; public static final String DB = "DataBase"; @@ -62,9 +86,21 @@ public class LoggingConstants { public static final String REQUEST_HANDLER = "RequestHandler"; } - public static class TargetServiceNames{ + /** + * Constants of targeted service names + */ + public static class TargetServiceNames { + private TargetServiceNames() { + throw new IllegalAccessError("TargetServiceNames"); + } - public static class AAIServiceNames{ + /** + * Constants of AAI service names + */ + public static class AAIServiceNames { + private AAIServiceNames() { + throw new IllegalAccessError("AAIServiceNames"); + } public static final String QUERY = "query"; public static final String GET_VNF_DATA = "getVnfData"; } diff --git a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java index 70c7fb1d2..65ea7893f 100644 --- a/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java +++ b/appc-common/src/main/java/org/openecomp/appc/logging/LoggingUtils.java @@ -41,33 +41,43 @@ import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.TimeZone; - - +/** + * Logging utilities + */ public class LoggingUtils { private final static EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); private final static EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger(); private final static EELFLogger metricLogger = EELFManager.getInstance().getMetricsLogger(); - public static void logErrorMessage(String errorCode, String errorDescription, String targetEntity, String targetServiceName, String additionalMessage, String className) { + private LoggingUtils() { + throw new IllegalAccessError("LoggingUtils"); + } + + public static void logErrorMessage(String errorCode, String errorDescription, String targetEntity, + String targetServiceName, String additionalMessage, String className) { logError(errorCode, errorDescription, targetEntity, targetServiceName, additionalMessage, className); } - public static void logErrorMessage(String targetEntity, String targetServiceName, String additionalMessage, String className) { + public static void logErrorMessage(String targetEntity, String targetServiceName, String additionalMessage, + String className) { logError("", "", targetEntity, targetServiceName, additionalMessage, className); } public static void logErrorMessage(String targetServiceName, String additionalMessage, String className) { - logError("", "", LoggingConstants.TargetNames.APPC, targetServiceName, additionalMessage, className); + logError("", "", LoggingConstants.TargetNames.APPC, targetServiceName, + additionalMessage, className); } - private static void logError(String errorCode, String errorDescription, String targetEntity, String targetServiceName, String additionalMessage, String className) { + private static void logError(String errorCode, String errorDescription, String targetEntity, + String targetServiceName, String additionalMessage, String className) { populateErrorLogContext(errorCode, errorDescription, targetEntity, targetServiceName, className); errorLogger.error(additionalMessage == null ? "" : additionalMessage); cleanErrorLogContext(); } - public static void logAuditMessage(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className) { + public static void logAuditMessage(Instant beginTimeStamp, Instant endTimeStamp, String code, + String responseDescription, String className) { populateAuditLogContext(beginTimeStamp, endTimeStamp, code, responseDescription, className); auditLogger.info(EELFResourceManager.format(Msg.APPC_AUDIT_MSG, MDC.get(MDC_SERVICE_NAME), @@ -80,13 +90,15 @@ public class LoggingUtils { cleanAuditErrorContext(); } - public static void auditInfo(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className,EELFResolvableErrorEnum resourceId, String... arguments) { + public static void auditInfo(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, + String className,EELFResolvableErrorEnum resourceId, String... arguments) { populateAuditLogContext(beginTimeStamp, endTimeStamp, code, responseDescription, className); auditLogger.info(resourceId,arguments); cleanAuditErrorContext(); } - public static void auditWarn(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className,EELFResolvableErrorEnum resourceId, String... arguments) { + public static void auditWarn(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, + String className,EELFResolvableErrorEnum resourceId, String... arguments) { populateAuditLogContext(beginTimeStamp, endTimeStamp, code, responseDescription, className); auditLogger.warn(resourceId,arguments); cleanAuditErrorContext(); @@ -94,8 +106,11 @@ public class LoggingUtils { - public static void logMetricsMessage(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) { - populateMetricLogContext(beginTimeStamp, endTimeStamp, targetEntity, targetServiceName, statusCode, responseCode, responseDescription, className); + public static void logMetricsMessage(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, + String targetServiceName, String statusCode, String responseCode, + String responseDescription, String className) { + populateMetricLogContext(beginTimeStamp, endTimeStamp, targetEntity, targetServiceName, statusCode, + responseCode, responseDescription, className); metricLogger.info(EELFResourceManager.format(Msg.APPC_METRIC_MSG, MDC.get(MDC_SERVICE_NAME), MDC.get(LoggingConstants.MDCKeys.TARGET_VIRTUAL_ENTITY), @@ -108,10 +123,11 @@ public class LoggingUtils { cleanMetricContext(); } - private static void populateAuditLogContext(Instant beginTimeStamp, Instant endTimeStamp, String code, String responseDescription, String className) { + private static void populateAuditLogContext(Instant beginTimeStamp, Instant endTimeStamp, String code, + String responseDescription, String className) { populateTimeContext(beginTimeStamp, endTimeStamp); MDC.put(LoggingConstants.MDCKeys.RESPONSE_CODE, code); - MDC.put(LoggingConstants.MDCKeys.STATUS_CODE, code.equals("100") || code.equals("400") ? + MDC.put(LoggingConstants.MDCKeys.STATUS_CODE, "100".equals(code) || "400".equals(code) ? LoggingConstants.StatusCodes.COMPLETE : LoggingConstants.StatusCodes.ERROR); MDC.put(LoggingConstants.MDCKeys.RESPONSE_DESCRIPTION, responseDescription!=null?responseDescription:""); @@ -126,7 +142,8 @@ public class LoggingUtils { MDC.remove(LoggingConstants.MDCKeys.CLASS_NAME); } - private static void populateErrorLogContext(String errorCode, String errorDescription, String targetEntity, String targetServiceName, String className) { + private static void populateErrorLogContext(String errorCode, String errorDescription, String targetEntity, + String targetServiceName, String className) { populateErrorContext(errorCode, errorDescription); populateTargetContext(targetEntity, targetServiceName!=null?targetServiceName:""); MDC.put(LoggingConstants.MDCKeys.CLASS_NAME, className!=null?className:""); @@ -138,7 +155,9 @@ public class LoggingUtils { MDC.remove(LoggingConstants.MDCKeys.CLASS_NAME); } - private static void populateMetricLogContext(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, String targetServiceName, String statusCode, String responseCode, String responseDescription, String className) { + private static void populateMetricLogContext(Instant beginTimeStamp, Instant endTimeStamp, String targetEntity, + String targetServiceName, String statusCode, String responseCode, + String responseDescription, String className) { populateTimeContext(beginTimeStamp, endTimeStamp); populateTargetContext(targetEntity, targetServiceName); populateResponseContext(statusCode, responseCode, responseDescription); diff --git a/appc-common/src/main/java/org/openecomp/appc/metadata/objects/DependencyModelIdentifier.java b/appc-common/src/main/java/org/openecomp/appc/metadata/objects/DependencyModelIdentifier.java index f76823308..8b1b5870a 100644 --- a/appc-common/src/main/java/org/openecomp/appc/metadata/objects/DependencyModelIdentifier.java +++ b/appc-common/src/main/java/org/openecomp/appc/metadata/objects/DependencyModelIdentifier.java @@ -24,51 +24,67 @@ package org.openecomp.appc.metadata.objects; - +/** + * Object of identifier for dependency model. + * Currently uses VNF type and catalog version + */ public class DependencyModelIdentifier { + static final String TO_STRING_FORMAT = "DependencyModelIdentifier : vnfType = %s , catalogVersion = %s"; + static final int prime = 31; + private String vnfType; private String catalogVersion; - public DependencyModelIdentifier(String vnfType, String catalogVersion){ + /** + * Constructor + * @param vnfType String of the VNF type + * @param catalogVersion String of the catalog version + */ + public DependencyModelIdentifier(String vnfType, String catalogVersion) { this.vnfType = vnfType; this.catalogVersion = catalogVersion; } - public int hashCode(){ - final int prime = 31; + @Override + public int hashCode() { int result = 1; result = result * prime + (this.vnfType == null ? 0 :this.vnfType.hashCode()); result = result * prime + (this.catalogVersion == null ? 0 :this.catalogVersion.hashCode()); return result; } - public boolean equals(Object obj){ - if(obj ==null) + @Override + public boolean equals(Object obj) { + if (obj ==null) { return false; - if(!(obj instanceof DependencyModelIdentifier)) + } + if (!(obj instanceof DependencyModelIdentifier)) { return false; + } DependencyModelIdentifier modelIdentifier = (DependencyModelIdentifier)obj; - if(this.vnfType == null){ - if(modelIdentifier.vnfType !=null) + if (this.vnfType == null) { + if (modelIdentifier.vnfType !=null) { return false; - } - else if(!this.vnfType.equals(modelIdentifier.vnfType)) + } + } else if (!this.vnfType.equals(modelIdentifier.vnfType)) { return false; + } - if(this.catalogVersion == null){ - if(modelIdentifier.catalogVersion !=null) + if (this.catalogVersion == null) { + if (modelIdentifier.catalogVersion !=null) { return false; - } - else if(!this.catalogVersion.equals(modelIdentifier.catalogVersion)) + } + } else if (!this.catalogVersion.equals(modelIdentifier.catalogVersion)) { return false; + } return true; } @Override public String toString() { - return "DependencyModelIdentifier : vnfType = "+vnfType + " , catalogVersion = " +catalogVersion; + return String.format(TO_STRING_FORMAT, vnfType, catalogVersion); } public String getVnfType() { |