From 0ceb856aeb4bd55af714a1f4162b5a3f05c3c801 Mon Sep 17 00:00:00 2001 From: MihirR123 <136401045+MihirR123@users.noreply.github.com> Date: Thu, 22 Jun 2023 20:32:49 -0700 Subject: [PATCH] Fix sonar issues for static variable names (#12111) Co-authored-by: Mihir Rao --- .../service/ChangeEventConfig.java | 12 +-- .../events/scheduled/ReportsHandler.java | 16 ++-- .../subscription/ActivityFeedAlertCache.java | 19 ++--- .../resources/databases/DatasourceConfig.java | 12 +-- .../resources/settings/SettingsCache.java | 20 ++--- .../service/resources/tags/TagLabelCache.java | 66 +++++++++-------- .../service/secrets/AWSSSMSecretsManager.java | 8 +- .../service/secrets/AWSSecretsManager.java | 10 +-- .../secrets/InMemorySecretsManager.java | 10 +-- .../service/secrets/NoopSecretsManager.java | 9 ++- .../service/security/auth/BotTokenCache.java | 8 +- .../service/security/auth/UserTokenCache.java | 20 ++--- .../security/policyevaluator/PolicyCache.java | 28 +++---- .../security/policyevaluator/RoleCache.java | 36 ++++----- .../policyevaluator/SubjectCache.java | 74 +++++++++---------- .../security/saml/SamlSettingsHolder.java | 8 +- .../service/socket/WebSocketManager.java | 6 +- .../openmetadata/service/util/EmailUtil.java | 32 ++++---- .../util/MicrometerBundleSingleton.java | 8 +- .../service/util/ReIndexingHandler.java | 14 ++-- .../service/util/TablesInitializer.java | 6 +- .../policyevaluator/RuleEvaluatorTest.java | 4 +- .../policyevaluator/SubjectContextTest.java | 8 +- 23 files changed, 218 insertions(+), 216 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/ChangeEventConfig.java b/openmetadata-service/src/main/java/org/openmetadata/service/ChangeEventConfig.java index a6bb937b124..8754d8fd7c6 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/ChangeEventConfig.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/ChangeEventConfig.java @@ -4,17 +4,17 @@ import org.openmetadata.api.configuration.ChangeEventConfiguration; public class ChangeEventConfig { - private static ChangeEventConfiguration INSTANCE; - private static volatile boolean INITIALIZED = false; + private static ChangeEventConfiguration instance; + private static volatile boolean initialized = false; public static void initialize(OpenMetadataApplicationConfig config) { - if (!INITIALIZED) { - INSTANCE = config.getChangeEventConfiguration(); - INITIALIZED = true; + if (!initialized) { + instance = config.getChangeEventConfiguration(); + initialized = true; } } public static ChangeEventConfiguration getInstance() { - return INSTANCE; + return instance; } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/ReportsHandler.java b/openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/ReportsHandler.java index 53a846b21e7..1f5699f442c 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/ReportsHandler.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/ReportsHandler.java @@ -49,8 +49,8 @@ public class ReportsHandler { private final SearchClient searchClient; private final DataInsightChartRepository chartRepository; - private static ReportsHandler INSTANCE; - private static volatile boolean INITIALIZED = false; + private static ReportsHandler instance; + private static volatile boolean initialized = false; private final Scheduler reportScheduler = new StdSchedulerFactory().getScheduler(); private static final ConcurrentHashMap reportJobKeyMap = new ConcurrentHashMap<>(); @@ -61,7 +61,7 @@ public class ReportsHandler { } public static ReportsHandler getInstance() { - if (INITIALIZED) return INSTANCE; + if (initialized) return instance; throw new DataInsightJobException("Reports Job Handler is not Initialized"); } @@ -70,9 +70,9 @@ public class ReportsHandler { } public static void initialize(CollectionDAO dao, SearchClient searchClient) throws SchedulerException { - if (!INITIALIZED) { - INSTANCE = new ReportsHandler(dao, searchClient); - INITIALIZED = true; + if (!initialized) { + instance = new ReportsHandler(dao, searchClient); + initialized = true; } else { LOG.info("Reindexing Handler is already initialized"); } @@ -133,8 +133,8 @@ public class ReportsHandler { } public static void shutDown() throws SchedulerException { - if (INSTANCE != null) { - INSTANCE.reportScheduler.shutdown(); + if (instance != null) { + instance.reportScheduler.shutdown(); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ActivityFeedAlertCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ActivityFeedAlertCache.java index 22c2314232a..25472697bfd 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ActivityFeedAlertCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/events/subscription/ActivityFeedAlertCache.java @@ -16,20 +16,20 @@ import org.openmetadata.service.jdbi3.EventSubscriptionRepository; @Slf4j public class ActivityFeedAlertCache { private static final ActivityFeedAlertCache INSTANCE = new ActivityFeedAlertCache(); - private static volatile boolean INITIALIZED = false; - protected static LoadingCache EVENT_SUB_CACHE; - protected static EventSubscriptionRepository EVENT_SUB_REPOSITORY; + private static volatile boolean initialized = false; + protected static LoadingCache eventSubCache; + protected static EventSubscriptionRepository eventSubscriptionRepository; private static String activityFeedAlertName; public static void initialize(String alertName, EventSubscriptionRepository repo) { - if (!INITIALIZED) { - EVENT_SUB_CACHE = + if (!initialized) { + eventSubCache = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(3, TimeUnit.MINUTES) .build(new ActivityFeedAlertLoader()); - EVENT_SUB_REPOSITORY = repo; - INITIALIZED = true; + eventSubscriptionRepository = repo; + initialized = true; activityFeedAlertName = alertName; } } @@ -40,7 +40,7 @@ public class ActivityFeedAlertCache { public EventSubscription getActivityFeedAlert() throws EntityNotFoundException { try { - return EVENT_SUB_CACHE.get(activityFeedAlertName); + return eventSubCache.get(activityFeedAlertName); } catch (ExecutionException | UncheckedExecutionException ex) { throw new EntityNotFoundException(ex.getMessage()); } @@ -49,7 +49,8 @@ public class ActivityFeedAlertCache { static class ActivityFeedAlertLoader extends CacheLoader { @Override public EventSubscription load(@CheckForNull String alertName) throws IOException { - EventSubscription alert = EVENT_SUB_REPOSITORY.getByName(null, alertName, EVENT_SUB_REPOSITORY.getFields("*")); + EventSubscription alert = + eventSubscriptionRepository.getByName(null, alertName, eventSubscriptionRepository.getFields("*")); LOG.debug("Loaded Alert {}", alert); return alert; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/databases/DatasourceConfig.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/databases/DatasourceConfig.java index 927f0b7af98..397f9c56291 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/databases/DatasourceConfig.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/databases/DatasourceConfig.java @@ -5,20 +5,20 @@ import org.openmetadata.service.OpenMetadataApplicationConfig; import org.openmetadata.service.jdbi3.locator.ConnectionType; public class DatasourceConfig { - private static DatasourceConfig INSTANCE; - private static volatile boolean INITIALIZED = false; + private static DatasourceConfig instance; + private static volatile boolean initialized = false; private static DataSourceFactory dataSourceFactory; public static void initialize(OpenMetadataApplicationConfig config) { - if (!INITIALIZED) { - INSTANCE = new DatasourceConfig(); + if (!initialized) { + instance = new DatasourceConfig(); dataSourceFactory = config.getDataSourceFactory(); - INITIALIZED = true; + initialized = true; } } public static DatasourceConfig getInstance() { - return INSTANCE; + return instance; } public Boolean isMySQL() { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java index 080168b77f3..b1046c0035e 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/settings/SettingsCache.java @@ -35,17 +35,17 @@ import org.openmetadata.service.util.JsonUtils; @Slf4j public class SettingsCache { private static final SettingsCache INSTANCE = new SettingsCache(); - private static volatile boolean INITIALIZED = false; - protected static LoadingCache SETTINGS_CACHE; + private static volatile boolean initialized = false; + protected static LoadingCache settingsCache; protected static SystemRepository systemRepository; // Expected to be called only once from the DefaultAuthorizer public static void initialize(CollectionDAO dao, OpenMetadataApplicationConfig config) { - if (!INITIALIZED) { - SETTINGS_CACHE = + if (!initialized) { + settingsCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new SettingsLoader()); systemRepository = new SystemRepository(dao.systemDAO()); - INITIALIZED = true; + initialized = true; createDefaultConfiguration(config); } } @@ -78,7 +78,7 @@ public class SettingsCache { public T getSetting(SettingsType settingName, Class clazz) { try { - String json = JsonUtils.pojoToJson(SETTINGS_CACHE.get(settingName.toString()).getConfigValue()); + String json = JsonUtils.pojoToJson(settingsCache.get(settingName.toString()).getConfigValue()); return JsonUtils.readValue(json, clazz); } catch (Exception ex) { LOG.error("Failed to fetch Settings . Setting {}", settingName, ex); @@ -88,7 +88,7 @@ public class SettingsCache { public Settings getSetting(SettingsType settingName) { try { - return SETTINGS_CACHE.get(settingName.toString()); + return settingsCache.get(settingName.toString()); } catch (Exception ex) { LOG.error("Failed to fetch Settings . Setting {}", settingName, ex); throw new EntityNotFoundException("Setting not found"); @@ -96,13 +96,13 @@ public class SettingsCache { } public static void cleanUp() { - SETTINGS_CACHE.invalidateAll(); - INITIALIZED = false; + settingsCache.invalidateAll(); + initialized = false; } public void invalidateSettings(String settingsName) { try { - SETTINGS_CACHE.invalidate(settingsName); + settingsCache.invalidate(settingsName); } catch (Exception ex) { LOG.error("Failed to invalidate cache for settings {}", settingsName, ex); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagLabelCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagLabelCache.java index a41a37c0f50..f4ce8539f07 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagLabelCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagLabelCache.java @@ -44,41 +44,43 @@ import org.openmetadata.service.util.FullyQualifiedName; @Slf4j public class TagLabelCache { private static final TagLabelCache INSTANCE = new TagLabelCache(); - private static volatile boolean INITIALIZED = false; + private static volatile boolean initialized = false; - protected static TagRepository TAG_REPOSITORY; - protected static ClassificationRepository TAG_CLASSIFICATION_REPOSITORY; - protected static LoadingCache TAG_CACHE; // Tag fqn to Tag - protected static LoadingCache CLASSIFICATION_CACHE; // Classification name to Classification + protected static TagRepository tagRepository; + protected static ClassificationRepository tagClassificationRepository; + protected static LoadingCache tagCache; // Tag fqn to Tag + protected static LoadingCache classificationCache; // Classification name to Classification - protected static GlossaryTermRepository GLOSSARY_TERM_REPOSITORY; - protected static GlossaryRepository GLOSSARY_REPOSITORY; - protected static LoadingCache GLOSSARY_TERM_CACHE; // Glossary term fqn to GlossaryTerm - protected static LoadingCache GLOSSARY_CACHE; // Glossary fqn to Glossary + protected static GlossaryTermRepository glossaryTermRepository; + protected static GlossaryRepository glossaryRepository; + // Glossary term fqn to GlossaryTerm + protected static LoadingCache glossaryTermCache; + + protected static LoadingCache glossaryCache; // Glossary fqn to Glossary // Expected to be called only once from the TagResource during initialization public static void initialize() { - if (!INITIALIZED) { - CLASSIFICATION_CACHE = + if (!initialized) { + classificationCache = CacheBuilder.newBuilder() .maximumSize(25) .expireAfterWrite(2, TimeUnit.MINUTES) .build(new ClassificationLoader()); - TAG_CACHE = + tagCache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(2, TimeUnit.MINUTES).build(new TagLoader()); - TAG_REPOSITORY = (TagRepository) Entity.getEntityRepository(Entity.TAG); - TAG_CLASSIFICATION_REPOSITORY = (ClassificationRepository) Entity.getEntityRepository(Entity.CLASSIFICATION); + tagRepository = (TagRepository) Entity.getEntityRepository(Entity.TAG); + tagClassificationRepository = (ClassificationRepository) Entity.getEntityRepository(Entity.CLASSIFICATION); - GLOSSARY_CACHE = + glossaryCache = CacheBuilder.newBuilder().maximumSize(25).expireAfterWrite(2, TimeUnit.MINUTES).build(new GlossaryLoader()); - GLOSSARY_TERM_CACHE = + glossaryTermCache = CacheBuilder.newBuilder() .maximumSize(100) .expireAfterWrite(2, TimeUnit.MINUTES) .build(new GlossaryTermLoader()); - GLOSSARY_TERM_REPOSITORY = (GlossaryTermRepository) Entity.getEntityRepository(Entity.GLOSSARY_TERM); - GLOSSARY_REPOSITORY = (GlossaryRepository) Entity.getEntityRepository(Entity.GLOSSARY); - INITIALIZED = true; + glossaryTermRepository = (GlossaryTermRepository) Entity.getEntityRepository(Entity.GLOSSARY_TERM); + glossaryRepository = (GlossaryRepository) Entity.getEntityRepository(Entity.GLOSSARY); + initialized = true; } else { LOG.info("Subject cache is already initialized"); } @@ -89,16 +91,16 @@ public class TagLabelCache { } public static void cleanUp() { - CLASSIFICATION_CACHE.cleanUp(); - TAG_CACHE.cleanUp(); - GLOSSARY_CACHE.cleanUp(); - GLOSSARY_TERM_CACHE.cleanUp(); - INITIALIZED = false; + classificationCache.cleanUp(); + tagCache.cleanUp(); + glossaryCache.cleanUp(); + glossaryTermCache.cleanUp(); + initialized = false; } public Classification getClassification(String classificationName) { try { - return CLASSIFICATION_CACHE.get(classificationName); + return classificationCache.get(classificationName); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage( CatalogExceptionMessage.entityNotFound(Entity.CLASSIFICATION, classificationName)); @@ -107,7 +109,7 @@ public class TagLabelCache { public Tag getTag(String tagFqn) { try { - return TAG_CACHE.get(tagFqn); + return tagCache.get(tagFqn); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TAG, tagFqn)); } @@ -115,7 +117,7 @@ public class TagLabelCache { public Glossary getGlossary(String glossaryName) { try { - return GLOSSARY_CACHE.get(glossaryName); + return glossaryCache.get(glossaryName); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.GLOSSARY, glossaryName)); } @@ -123,7 +125,7 @@ public class TagLabelCache { public GlossaryTerm getGlossaryTerm(String glossaryTermFqn) { try { - return GLOSSARY_TERM_CACHE.get(glossaryTermFqn); + return glossaryTermCache.get(glossaryTermFqn); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage( CatalogExceptionMessage.entityNotFound(Entity.GLOSSARY_TERM, glossaryTermFqn)); @@ -161,7 +163,7 @@ public class TagLabelCache { static class TagLoader extends CacheLoader { @Override public Tag load(@CheckForNull String tagName) throws IOException { - Tag tag = TAG_REPOSITORY.getByName(null, tagName, Fields.EMPTY_FIELDS); + Tag tag = tagRepository.getByName(null, tagName, Fields.EMPTY_FIELDS); LOG.info("Loaded tag {}:{}", tag.getName(), tag.getId()); return tag; } @@ -171,7 +173,7 @@ public class TagLabelCache { @Override public Classification load(@CheckForNull String classificationName) throws IOException { Classification classification = - TAG_CLASSIFICATION_REPOSITORY.getByName(null, classificationName, Fields.EMPTY_FIELDS); + tagClassificationRepository.getByName(null, classificationName, Fields.EMPTY_FIELDS); LOG.info("Loaded classification {}:{}", classification.getName(), classification.getId()); return classification; } @@ -180,7 +182,7 @@ public class TagLabelCache { static class GlossaryTermLoader extends CacheLoader { @Override public GlossaryTerm load(@CheckForNull String glossaryTermName) throws IOException { - GlossaryTerm glossaryTerm = GLOSSARY_TERM_REPOSITORY.getByName(null, glossaryTermName, Fields.EMPTY_FIELDS); + GlossaryTerm glossaryTerm = glossaryTermRepository.getByName(null, glossaryTermName, Fields.EMPTY_FIELDS); LOG.info("Loaded glossaryTerm {}:{}", glossaryTerm.getName(), glossaryTerm.getId()); return glossaryTerm; } @@ -189,7 +191,7 @@ public class TagLabelCache { static class GlossaryLoader extends CacheLoader { @Override public Glossary load(@CheckForNull String glossaryName) throws IOException { - Glossary glossary = GLOSSARY_REPOSITORY.getByName(null, glossaryName, Fields.EMPTY_FIELDS); + Glossary glossary = glossaryRepository.getByName(null, glossaryName, Fields.EMPTY_FIELDS); LOG.info("Loaded glossary {}:{}", glossary.getName(), glossary.getId()); return glossary; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSSMSecretsManager.java b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSSMSecretsManager.java index 4d632f11c36..7612ca9c3ea 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSSMSecretsManager.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSSMSecretsManager.java @@ -25,9 +25,7 @@ import software.amazon.awssdk.services.ssm.model.ParameterType; import software.amazon.awssdk.services.ssm.model.PutParameterRequest; public class AWSSSMSecretsManager extends AWSBasedSecretsManager { - - private static AWSSSMSecretsManager INSTANCE = null; - + private static AWSSSMSecretsManager instance = null; private SsmClient ssmClient; private AWSSSMSecretsManager(SecretsManagerConfiguration config, String clusterPrefix) { @@ -80,8 +78,8 @@ public class AWSSSMSecretsManager extends AWSBasedSecretsManager { } public static AWSSSMSecretsManager getInstance(SecretsManagerConfiguration config, String clusterPrefix) { - if (INSTANCE == null) INSTANCE = new AWSSSMSecretsManager(config, clusterPrefix); - return INSTANCE; + if (instance == null) instance = new AWSSSMSecretsManager(config, clusterPrefix); + return instance; } @VisibleForTesting diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSecretsManager.java b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSecretsManager.java index c2d6f16bf0e..019041e6137 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSecretsManager.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/AWSSecretsManager.java @@ -27,9 +27,7 @@ import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueReques import software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest; public class AWSSecretsManager extends AWSBasedSecretsManager { - - private static AWSSecretsManager INSTANCE = null; - + private static AWSSecretsManager instance = null; private SecretsManagerClient secretsClient; private AWSSecretsManager(SecretsManagerConfiguration config, String clusterPrefix) { @@ -82,8 +80,10 @@ public class AWSSecretsManager extends AWSBasedSecretsManager { } public static AWSSecretsManager getInstance(SecretsManagerConfiguration config, String clusterPrefix) { - if (INSTANCE == null) INSTANCE = new AWSSecretsManager(config, clusterPrefix); - return INSTANCE; + if (instance == null) { + instance = new AWSSecretsManager(config, clusterPrefix); + } + return instance; } @VisibleForTesting diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/InMemorySecretsManager.java b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/InMemorySecretsManager.java index 0096aaffc64..3727b4d0cb7 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/InMemorySecretsManager.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/InMemorySecretsManager.java @@ -21,9 +21,7 @@ import org.openmetadata.service.exception.SecretsManagerException; /** Secret Manager used for testing */ public class InMemorySecretsManager extends ExternalSecretsManager { - - private static InMemorySecretsManager INSTANCE; - + private static InMemorySecretsManager instance; @Getter private final Map secretsMap = new HashMap<>(); protected InMemorySecretsManager(String clusterPrefix) { @@ -31,8 +29,10 @@ public class InMemorySecretsManager extends ExternalSecretsManager { } public static InMemorySecretsManager getInstance(String clusterPrefix) { - if (INSTANCE == null) INSTANCE = new InMemorySecretsManager(clusterPrefix); - return INSTANCE; + if (instance == null) { + instance = new InMemorySecretsManager(clusterPrefix); + } + return instance; } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/NoopSecretsManager.java b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/NoopSecretsManager.java index ecd2d35145c..75aed6b9f90 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/secrets/NoopSecretsManager.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/secrets/NoopSecretsManager.java @@ -16,16 +16,17 @@ package org.openmetadata.service.secrets; import org.openmetadata.schema.security.secrets.SecretsManagerProvider; public class NoopSecretsManager extends SecretsManager { - - private static NoopSecretsManager INSTANCE; + private static NoopSecretsManager instance; private NoopSecretsManager(String clusterPrefix, SecretsManagerProvider secretsManagerProvider) { super(secretsManagerProvider, clusterPrefix); } public static NoopSecretsManager getInstance(String clusterPrefix, SecretsManagerProvider secretsManagerProvider) { - if (INSTANCE == null) INSTANCE = new NoopSecretsManager(clusterPrefix, secretsManagerProvider); - return INSTANCE; + if (instance == null) { + instance = new NoopSecretsManager(clusterPrefix, secretsManagerProvider); + } + return instance; } @Override diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BotTokenCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BotTokenCache.java index 15b66a5d88c..b9ac82200b7 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BotTokenCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BotTokenCache.java @@ -24,7 +24,7 @@ import org.openmetadata.service.util.JsonUtils; @Slf4j public class BotTokenCache { public static final String EMPTY_STRING = ""; - private static BotTokenCache INSTANCE; + private static BotTokenCache instance; private final LoadingCache BOTS_TOKEN_CACHE; public BotTokenCache() { @@ -52,10 +52,10 @@ public class BotTokenCache { } public static BotTokenCache getInstance() { - if (INSTANCE == null) { - INSTANCE = new BotTokenCache(); + if (instance == null) { + instance = new BotTokenCache(); } - return INSTANCE; + return instance; } static class BotTokenLoader extends CacheLoader { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java index ae50bf8b668..f83352d2f94 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java @@ -26,21 +26,21 @@ import org.openmetadata.service.util.EntityUtil; @Slf4j public class UserTokenCache { - private static UserTokenCache INSTANCE; - private static LoadingCache> USER_TOKEN_CACHE; - private static volatile boolean INITIALIZED = false; + private static UserTokenCache instance; + private static LoadingCache> userTokenCache; + private static volatile boolean initialized = false; private static TokenRepository tokenRepository; public static void initialize(CollectionDAO dao) { - if (!INITIALIZED) { - USER_TOKEN_CACHE = + if (!initialized) { + userTokenCache = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(2, TimeUnit.MINUTES) .build(new UserTokenLoader()); tokenRepository = new TokenRepository(dao); - INSTANCE = new UserTokenCache(); - INITIALIZED = true; + instance = new UserTokenCache(); + initialized = true; LOG.info("User Token cache is initialized"); } else { LOG.info("User Token cache is already initialized"); @@ -49,7 +49,7 @@ public class UserTokenCache { public HashSet getToken(String userName) { try { - return USER_TOKEN_CACHE.get(userName); + return userTokenCache.get(userName); } catch (ExecutionException | UncheckedExecutionException ex) { LOG.error("Token not found", ex); return null; @@ -58,14 +58,14 @@ public class UserTokenCache { public void invalidateToken(String userName) { try { - USER_TOKEN_CACHE.invalidate(userName); + userTokenCache.invalidate(userName); } catch (Exception ex) { LOG.error("Failed to invalidate User token cache for User {}", userName, ex); } } public static UserTokenCache getInstance() { - return INSTANCE; + return instance; } static class UserTokenLoader extends CacheLoader> { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/PolicyCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/PolicyCache.java index d70c76171dd..a69a0a8e63a 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/PolicyCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/PolicyCache.java @@ -36,11 +36,11 @@ import org.openmetadata.service.util.EntityUtil.Fields; @Slf4j public class PolicyCache { private static final PolicyCache INSTANCE = new PolicyCache(); - private static volatile boolean INITIALIZED = false; + private static volatile boolean initialized = false; - protected static LoadingCache> POLICY_CACHE; - private static PolicyRepository POLICY_REPOSITORY; - private static Fields FIELDS; + protected static LoadingCache> policyCache; + private static PolicyRepository policyRepository; + private static Fields fields; public static PolicyCache getInstance() { return INSTANCE; @@ -48,18 +48,18 @@ public class PolicyCache { /** To be called during application startup by Default Authorizer */ public static void initialize() { - if (!INITIALIZED) { - POLICY_CACHE = + if (!initialized) { + policyCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new PolicyLoader()); - POLICY_REPOSITORY = (PolicyRepository) Entity.getEntityRepository(Entity.POLICY); - FIELDS = POLICY_REPOSITORY.getFields("rules"); - INITIALIZED = true; + policyRepository = (PolicyRepository) Entity.getEntityRepository(Entity.POLICY); + fields = policyRepository.getFields("rules"); + initialized = true; } } public List getPolicyRules(UUID policyId) { try { - return POLICY_CACHE.get(policyId); + return policyCache.get(policyId); } catch (ExecutionException | UncheckedExecutionException ex) { throw new EntityNotFoundException(ex.getMessage()); } @@ -67,7 +67,7 @@ public class PolicyCache { public void invalidatePolicy(UUID policyId) { try { - POLICY_CACHE.invalidate(policyId); + policyCache.invalidate(policyId); } catch (Exception ex) { LOG.error("Failed to invalidate cache for policy {}", policyId, ex); } @@ -82,14 +82,14 @@ public class PolicyCache { } public static void cleanUp() { - POLICY_CACHE.cleanUp(); - INITIALIZED = false; + policyCache.cleanUp(); + initialized = false; } static class PolicyLoader extends CacheLoader> { @Override public List load(@CheckForNull UUID policyId) throws IOException { - Policy policy = POLICY_REPOSITORY.get(null, policyId, FIELDS); + Policy policy = policyRepository.get(null, policyId, fields); LOG.info("Loaded policy {}:{}", policy.getName(), policy.getId()); return PolicyCache.getInstance().getRules(policy); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/RoleCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/RoleCache.java index 7bd57c7b418..37b0d4e769a 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/RoleCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/RoleCache.java @@ -35,11 +35,11 @@ import org.openmetadata.service.util.EntityUtil.Fields; @Slf4j public class RoleCache { private static final RoleCache INSTANCE = new RoleCache(); - private static volatile boolean INITIALIZED = false; - protected static LoadingCache ROLE_CACHE; - protected static LoadingCache ROLE_CACHE_WITH_ID; - private static RoleRepository ROLE_REPOSITORY; - private static Fields FIELDS; + private static volatile boolean initialized = false; + protected static LoadingCache roleCache; + protected static LoadingCache roleCacheWithId; + private static RoleRepository roleRepository; + private static Fields fields; public static RoleCache getInstance() { return INSTANCE; @@ -47,23 +47,23 @@ public class RoleCache { /** To be called only once during the application start from DefaultAuthorizer */ public static void initialize() { - if (!INITIALIZED) { - ROLE_CACHE = + if (!initialized) { + roleCache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new RoleLoader()); - ROLE_CACHE_WITH_ID = + roleCacheWithId = CacheBuilder.newBuilder() .maximumSize(100) .expireAfterWrite(3, TimeUnit.MINUTES) .build(new RoleLoaderWithId()); - ROLE_REPOSITORY = (RoleRepository) Entity.getEntityRepository(Entity.ROLE); - FIELDS = ROLE_REPOSITORY.getFields("policies"); - INITIALIZED = true; + roleRepository = (RoleRepository) Entity.getEntityRepository(Entity.ROLE); + fields = roleRepository.getFields("policies"); + initialized = true; } } public Role getRole(String roleName) { try { - return ROLE_CACHE.get(roleName); + return roleCache.get(roleName); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(entityNotFound(Entity.ROLE, roleName)); } @@ -71,7 +71,7 @@ public class RoleCache { public Role getRoleById(UUID roleId) { try { - return ROLE_CACHE_WITH_ID.get(roleId); + return roleCacheWithId.get(roleId); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(entityNotFound(Entity.ROLE, roleId)); } @@ -79,7 +79,7 @@ public class RoleCache { public void invalidateRole(UUID roleId) { try { - ROLE_CACHE_WITH_ID.invalidate(roleId); + roleCacheWithId.invalidate(roleId); } catch (Exception ex) { LOG.error("Failed to invalidate cache for role {}", roleId, ex); } @@ -88,7 +88,7 @@ public class RoleCache { static class RoleLoader extends CacheLoader { @Override public Role load(@CheckForNull String roleName) throws IOException { - Role role = ROLE_REPOSITORY.getByName(null, roleName, FIELDS); + Role role = roleRepository.getByName(null, roleName, fields); LOG.info("Loaded role {}:{}", role.getName(), role.getId()); return role; } @@ -97,14 +97,14 @@ public class RoleCache { static class RoleLoaderWithId extends CacheLoader { @Override public Role load(@CheckForNull UUID roleId) throws IOException { - Role role = ROLE_REPOSITORY.get(null, roleId, FIELDS); + Role role = roleRepository.get(null, roleId, fields); LOG.info("Loaded role {}:{}", role.getName(), role.getId()); return role; } } public static void cleanUp() { - ROLE_CACHE_WITH_ID.cleanUp(); - INITIALIZED = false; + roleCacheWithId.cleanUp(); + initialized = false; } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/SubjectCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/SubjectCache.java index d6fa37ad8c1..b14fc91b1e8 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/SubjectCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/SubjectCache.java @@ -44,40 +44,40 @@ import org.openmetadata.service.util.EntityUtil.Fields; /** Subject context used for Access Control Policies */ @Slf4j public class SubjectCache { - private static SubjectCache INSTANCE; - private static volatile boolean INITIALIZED = false; - protected static LoadingCache USER_CACHE; - protected static LoadingCache USER_CACHE_WIH_ID; - protected static LoadingCache TEAM_CACHE; - protected static LoadingCache TEAM_CACHE_WITH_ID; - protected static UserRepository USER_REPOSITORY; - protected static Fields USER_FIELDS; - protected static TeamRepository TEAM_REPOSITORY; - protected static Fields TEAM_FIELDS; + private static SubjectCache instance; + private static volatile boolean initialized = false; + protected static LoadingCache userCache; + protected static LoadingCache userCacheWihId; + protected static LoadingCache teamCache; + protected static LoadingCache teamCacheWithId; + protected static UserRepository userRepository; + protected static Fields userFields; + protected static TeamRepository teamRepository; + protected static Fields teamFields; // Expected to be called only once from the DefaultAuthorizer public static void initialize() { - if (!INITIALIZED) { - USER_CACHE = + if (!initialized) { + userCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new UserLoader()); - USER_CACHE_WIH_ID = + userCacheWihId = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(3, TimeUnit.MINUTES) .build(new UserLoaderWithId()); - TEAM_CACHE = + teamCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new TeamLoader()); - TEAM_CACHE_WITH_ID = + teamCacheWithId = CacheBuilder.newBuilder() .maximumSize(1000) .expireAfterWrite(3, TimeUnit.MINUTES) .build(new TeamLoaderWithId()); - USER_REPOSITORY = (UserRepository) Entity.getEntityRepository(Entity.USER); - USER_FIELDS = USER_REPOSITORY.getFields("roles, teams, isAdmin, profile"); - TEAM_REPOSITORY = (TeamRepository) Entity.getEntityRepository(Entity.TEAM); - TEAM_FIELDS = TEAM_REPOSITORY.getFields("defaultRoles, policies, parents, profile"); - INSTANCE = new SubjectCache(); - INITIALIZED = true; + userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER); + userFields = userRepository.getFields("roles, teams, isAdmin, profile"); + teamRepository = (TeamRepository) Entity.getEntityRepository(Entity.TEAM); + teamFields = teamRepository.getFields("defaultRoles, policies, parents, profile"); + instance = new SubjectCache(); + initialized = true; LOG.info("Subject cache is initialized"); } else { LOG.info("Subject cache is already initialized"); @@ -85,12 +85,12 @@ public class SubjectCache { } public static SubjectCache getInstance() { - return INSTANCE; + return instance; } public SubjectContext getSubjectContext(String userName) throws EntityNotFoundException { try { - return USER_CACHE.get(userName); + return userCache.get(userName); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userName)); } @@ -98,7 +98,7 @@ public class SubjectCache { public SubjectContext getSubjectContext(UUID userId) throws EntityNotFoundException { try { - return USER_CACHE_WIH_ID.get(userId); + return userCacheWihId.get(userId); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId)); } @@ -106,7 +106,7 @@ public class SubjectCache { public User getUser(String userName) throws EntityNotFoundException { try { - return USER_CACHE.get(userName).getUser(); + return userCache.get(userName).getUser(); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userName)); } @@ -118,7 +118,7 @@ public class SubjectCache { public User getUserById(UUID userId) throws EntityNotFoundException { try { - return USER_CACHE_WIH_ID.get(userId).getUser(); + return userCacheWihId.get(userId).getUser(); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId)); } @@ -126,7 +126,7 @@ public class SubjectCache { public Team getTeam(UUID teamId) throws EntityNotFoundException { try { - return TEAM_CACHE_WITH_ID.get(teamId); + return teamCacheWithId.get(teamId); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TEAM, teamId)); } @@ -134,7 +134,7 @@ public class SubjectCache { public Team getTeamByName(String teamName) throws EntityNotFoundException { try { - return TEAM_CACHE.get(teamName); + return teamCache.get(teamName); } catch (ExecutionException | UncheckedExecutionException ex) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TEAM, teamName)); } @@ -178,14 +178,14 @@ public class SubjectCache { public static void cleanUp() { LOG.info("Subject cache is cleaned up"); - USER_CACHE.invalidateAll(); - TEAM_CACHE_WITH_ID.invalidateAll(); - INITIALIZED = false; + userCache.invalidateAll(); + teamCacheWithId.invalidateAll(); + initialized = false; } public void invalidateUser(String userName) { try { - USER_CACHE.invalidate(userName); + userCache.invalidate(userName); } catch (Exception ex) { LOG.error("Failed to invalidate cache for user {}", userName, ex); } @@ -193,7 +193,7 @@ public class SubjectCache { public void invalidateTeam(UUID teamId) { try { - TEAM_CACHE_WITH_ID.invalidate(teamId); + teamCacheWithId.invalidate(teamId); } catch (Exception ex) { LOG.error("Failed to invalidate cache for team {}", teamId, ex); } @@ -214,7 +214,7 @@ public class SubjectCache { static class UserLoader extends CacheLoader { @Override public SubjectContext load(@CheckForNull String userName) throws IOException { - User user = USER_REPOSITORY.getByName(null, EntityInterfaceUtil.quoteName(userName), USER_FIELDS); + User user = userRepository.getByName(null, EntityInterfaceUtil.quoteName(userName), userFields); LOG.info("Loaded user {}:{}", user.getName(), user.getId()); return new SubjectContext(user); } @@ -223,7 +223,7 @@ public class SubjectCache { static class UserLoaderWithId extends CacheLoader { @Override public SubjectContext load(@CheckForNull UUID uid) throws IOException { - User user = USER_REPOSITORY.get(null, uid, USER_FIELDS); + User user = userRepository.get(null, uid, userFields); LOG.info("Loaded user {}:{}", user.getName(), user.getId()); return new SubjectContext(user); } @@ -232,7 +232,7 @@ public class SubjectCache { static class TeamLoader extends CacheLoader { @Override public Team load(@CheckForNull String userName) throws IOException { - Team team = TEAM_REPOSITORY.getByName(null, userName, TEAM_FIELDS); + Team team = teamRepository.getByName(null, userName, teamFields); LOG.info("Loaded user {}:{}", team.getName(), team.getId()); return team; } @@ -241,7 +241,7 @@ public class SubjectCache { static class TeamLoaderWithId extends CacheLoader { @Override public Team load(@NonNull UUID teamId) throws IOException { - Team team = TEAM_REPOSITORY.get(null, teamId, TEAM_FIELDS); + Team team = teamRepository.get(null, teamId, teamFields); LOG.info("Loaded team {}:{}", team.getName(), team.getId()); return team; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/saml/SamlSettingsHolder.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/saml/SamlSettingsHolder.java index 568c43f6f74..75849c8dc97 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/saml/SamlSettingsHolder.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/saml/SamlSettingsHolder.java @@ -30,7 +30,7 @@ import org.openmetadata.common.utils.CommonUtil; import org.openmetadata.service.OpenMetadataApplicationConfig; public class SamlSettingsHolder { - private static SamlSettingsHolder INSTANCE; + private static SamlSettingsHolder instance; private Map samlData; private SettingsBuilder builder; @Getter private Saml2Settings saml2Settings; @@ -44,8 +44,10 @@ public class SamlSettingsHolder { } public static SamlSettingsHolder getInstance() { - if (INSTANCE == null) INSTANCE = new SamlSettingsHolder(); - return INSTANCE; + if (instance == null) { + instance = new SamlSettingsHolder(); + } + return instance; } public void initDefaultSettings(OpenMetadataApplicationConfig catalogApplicationConfig) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/socket/WebSocketManager.java b/openmetadata-service/src/main/java/org/openmetadata/service/socket/WebSocketManager.java index 398d58b6999..748285679e9 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/socket/WebSocketManager.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/socket/WebSocketManager.java @@ -17,7 +17,7 @@ import org.openmetadata.service.security.policyevaluator.SubjectCache; @Slf4j public class WebSocketManager { - private static WebSocketManager INSTANCE; + private static WebSocketManager instance; @Getter private final EngineIoServer engineIoServer; @Getter private final SocketIoServer socketIoServer; public static final String FEED_BROADCAST_CHANNEL = "activityFeed"; @@ -87,7 +87,7 @@ public class WebSocketManager { } public static WebSocketManager getInstance() { - return INSTANCE; + return instance; } public void broadCastMessageToAll(String event, String message) { @@ -123,7 +123,7 @@ public class WebSocketManager { private WebSocketManagerBuilder() {} public static void build(EngineIoServerOptions eiOptions) { - INSTANCE = new WebSocketManager(eiOptions); + instance = new WebSocketManager(eiOptions); } } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/EmailUtil.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/EmailUtil.java index 537ccbf8959..674167fcfee 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/EmailUtil.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/EmailUtil.java @@ -84,18 +84,18 @@ public class EmailUtil { private static final String REPORT_SUBJECT = "%s: Data Insights Weekly - %s"; public static final String DATA_INSIGHT_REPORT_TEMPLATE = "dataInsightReport.ftl"; - private static EmailUtil INSTANCE; + private static EmailUtil instance; private static SmtpSettings STORED_SMTP_SETTINGS; - private static Mailer MAILER; - private static Configuration TEMPLATE_CONFIGURATION; + private static Mailer mailer; + private static Configuration templateConfiguration; private static final String EMAIL_IGNORE_MSG = "Email was not sent to %s as SMTP setting is not enabled"; private EmailUtil() { try { STORED_SMTP_SETTINGS = getSmtpSettings(); - MAILER = createMailer(STORED_SMTP_SETTINGS); - TEMPLATE_CONFIGURATION = new Configuration(VERSION_2_3_28); + mailer = createMailer(STORED_SMTP_SETTINGS); + templateConfiguration = new Configuration(VERSION_2_3_28); LOG.info("Email Util cache is initialized"); } catch (Exception ex) { LOG.warn("[MAILER] Smtp Configurations are missing : Reason {} ", ex.getMessage(), ex); @@ -128,10 +128,10 @@ public class EmailUtil { } public static EmailUtil getInstance() { - if (INSTANCE == null) { - INSTANCE = new EmailUtil(); + if (instance == null) { + instance = new EmailUtil(); } - return INSTANCE; + return instance; } public void sendAccountStatus(User user, String action, String status) throws IOException, TemplateException { @@ -238,8 +238,8 @@ public class EmailUtil { emailBuilder.to(to); emailBuilder.from(getSmtpSettings().getSenderMail()); - TEMPLATE_CONFIGURATION.setClassForTemplateLoading(getClass(), baseTemplatePackage); - Template template = TEMPLATE_CONFIGURATION.getTemplate(templatePath); + templateConfiguration.setClassForTemplateLoading(getClass(), baseTemplatePackage); + Template template = templateConfiguration.getTemplate(templatePath); // write the freemarker output to a StringWriter StringWriter stringWriter = new StringWriter(); @@ -261,8 +261,8 @@ public class EmailUtil { emailBuilder.toMultiple(to); emailBuilder.from(getSmtpSettings().getSenderMail()); - TEMPLATE_CONFIGURATION.setClassForTemplateLoading(getClass(), baseTemplatePackage); - Template template = TEMPLATE_CONFIGURATION.getTemplate(templatePath); + templateConfiguration.setClassForTemplateLoading(getClass(), baseTemplatePackage); + Template template = templateConfiguration.getTemplate(templatePath); // write the freemarker output to a StringWriter StringWriter stringWriter = new StringWriter(); @@ -274,8 +274,8 @@ public class EmailUtil { } public void sendMail(Email email) { - if (MAILER != null && getSmtpSettings().getEnableSmtpServer()) { - MAILER.sendMail(email, true); + if (mailer != null && getSmtpSettings().getEnableSmtpServer()) { + mailer.sendMail(email, true); } } @@ -366,7 +366,7 @@ public class EmailUtil { } public void testConnection() { - MAILER.testConnection(); + mailer.testConnection(); } private String getEmailVerificationSubject() { @@ -419,7 +419,7 @@ public class EmailUtil { SettingsCache.getInstance().getSetting(SettingsType.EMAIL_CONFIGURATION, SmtpSettings.class); if (!emailConfig.equals(STORED_SMTP_SETTINGS)) { STORED_SMTP_SETTINGS = emailConfig; - MAILER = createMailer(emailConfig); + mailer = createMailer(emailConfig); } return emailConfig; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/MicrometerBundleSingleton.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/MicrometerBundleSingleton.java index d56dd964e53..ac06d0effc0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/MicrometerBundleSingleton.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/MicrometerBundleSingleton.java @@ -19,20 +19,20 @@ import io.micrometer.prometheus.PrometheusMeterRegistry; import org.openmetadata.service.monitoring.EventMonitorConfiguration; public class MicrometerBundleSingleton { - private static MicrometerBundle INSTANCE; + private static MicrometerBundle instance; public static Timer webAnalyticEvents; public static PrometheusMeterRegistry prometheusMeterRegistry; private MicrometerBundleSingleton() {} public static MicrometerBundle getInstance() { - if (INSTANCE == null) { - INSTANCE = new MicrometerBundle(); + if (instance == null) { + instance = new MicrometerBundle(); // We'll use this registry to add monitoring around Ingestion Pipelines prometheusMeterRegistry = MicrometerBundle.prometheusRegistry; } - return INSTANCE; + return instance; } public static Timer latencyTimer(EventMonitorConfiguration configuration) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/ReIndexingHandler.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/ReIndexingHandler.java index 116baa4a456..26969937a71 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/ReIndexingHandler.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/ReIndexingHandler.java @@ -40,7 +40,6 @@ import org.openmetadata.schema.system.EventPublisherJob; import org.openmetadata.schema.system.Failure; import org.openmetadata.schema.system.Stats; import org.openmetadata.service.Entity; -import org.openmetadata.service.elasticsearch.ElasticSearchIndexDefinition; import org.openmetadata.service.exception.CustomExceptionMessage; import org.openmetadata.service.exception.UnhandledServerException; import org.openmetadata.service.jdbi3.CollectionDAO; @@ -51,11 +50,10 @@ import org.openmetadata.service.workflows.searchIndex.SearchIndexWorkflow; @Slf4j public class ReIndexingHandler { public static final String REINDEXING_JOB_EXTENSION = "reindexing.eventPublisher"; - private static ReIndexingHandler INSTANCE; - private static volatile boolean INITIALIZED = false; + private static ReIndexingHandler instance; + private static volatile boolean initialized = false; private static CollectionDAO dao; private static SearchClient searchClient; - private static ElasticSearchIndexDefinition esIndexDefinition; private static ExecutorService threadScheduler; private final Map REINDEXING_JOB_MAP = new LinkedHashMap<>(); private static BlockingQueue taskQueue; @@ -63,17 +61,17 @@ public class ReIndexingHandler { private ReIndexingHandler() {} public static ReIndexingHandler getInstance() { - return INSTANCE; + return instance; } public static void initialize(SearchClient client, CollectionDAO daoObject) { - if (!INITIALIZED) { + if (!initialized) { searchClient = client; dao = daoObject; taskQueue = new ArrayBlockingQueue<>(5); threadScheduler = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, taskQueue); - INSTANCE = new ReIndexingHandler(); - INITIALIZED = true; + instance = new ReIndexingHandler(); + initialized = true; } else { LOG.info("Reindexing Handler is already initialized"); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java index d249e85de11..f06276a84e5 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java @@ -57,7 +57,7 @@ public final class TablesInitializer { private static final String OPTION_CONFIG_FILE_PATH = "config"; private static final String DISABLE_VALIDATE_ON_MIGRATE = "disable-validate-on-migrate"; private static final Options OPTIONS; - private static boolean DEBUG_MODE = false; + private static boolean debugMode = false; static { OPTIONS = new Options(); @@ -108,7 +108,7 @@ public final class TablesInitializer { System.exit(1); } if (commandLine.hasOption(DEBUG_MODE_ENABLED)) { - DEBUG_MODE = true; + debugMode = true; } boolean isSchemaMigrationOptionSpecified = false; SchemaMigrationOption schemaMigrationOptionSpecified = null; @@ -303,7 +303,7 @@ public final class TablesInitializer { } private static void printToConsoleInDebug(String message) { - if (DEBUG_MODE) { + if (debugMode) { System.out.println(message); } } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/RuleEvaluatorTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/RuleEvaluatorTest.java index 406fc616064..ac579f65783 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/RuleEvaluatorTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/RuleEvaluatorTest.java @@ -258,7 +258,7 @@ class RuleEvaluatorTest { Team parentTeam = SubjectCache.getInstance().getTeam(parentId); team.setParents(listOf(parentTeam.getEntityReference())); } - SubjectCache.TEAM_CACHE_WITH_ID.put(team.getId(), team); + SubjectCache.teamCacheWithId.put(team.getId(), team); return team; } @@ -278,7 +278,7 @@ class RuleEvaluatorTest { private Role createRole(String roleName) { UUID roleId = UUID.nameUUIDFromBytes(roleName.getBytes(StandardCharsets.UTF_8)); Role role = new Role().withName(roleName).withId(roleId); - RoleCache.ROLE_CACHE_WITH_ID.put(role.getId(), role); + RoleCache.roleCacheWithId.put(role.getId(), role); return role; } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/SubjectContextTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/SubjectContextTest.java index 83fa481241d..f645c2578e7 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/SubjectContextTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/security/policyevaluator/SubjectContextTest.java @@ -111,7 +111,7 @@ public class SubjectContextTest { userRoles = getRoles("user"); List userRolesRef = toEntityReferences(userRoles); user = new User().withName("user").withRoles(userRolesRef).withTeams(List.of(team111.getEntityReference())); - SubjectCache.USER_CACHE.put("user", new SubjectContext(user)); + SubjectCache.userCache.put("user", new SubjectContext(user)); } @AfterAll @@ -201,7 +201,7 @@ public class SubjectContextTest { String name = prefix + "_role_" + i; List policies = toEntityReferences(getPolicies(name)); Role role = new Role().withName(name).withId(UUID.randomUUID()).withPolicies(policies); - RoleCache.ROLE_CACHE_WITH_ID.put(role.getId(), role); + RoleCache.roleCacheWithId.put(role.getId(), role); roles.add(role); } return roles; @@ -213,7 +213,7 @@ public class SubjectContextTest { String name = prefix + "_policy_" + i; Policy policy = new Policy().withName(name).withId(UUID.randomUUID()).withRules(getRules(name)); policies.add(policy); - PolicyCache.POLICY_CACHE.put(policy.getId(), PolicyCache.getInstance().getRules(policy)); + PolicyCache.policyCache.put(policy.getId(), PolicyCache.getInstance().getRules(policy)); } return policies; } @@ -268,7 +268,7 @@ public class SubjectContextTest { .withDefaultRoles(toEntityReferences(roles)) .withPolicies(toEntityReferences(policies)) .withParents(parentList); - SubjectCache.TEAM_CACHE_WITH_ID.put(team.getId(), team); + SubjectCache.teamCacheWithId.put(team.getId(), team); return team; }