Fix sonar issues for static variable names (#12111)

Co-authored-by: Mihir Rao <mihir@MacBook-Pro-76.local>
This commit is contained in:
MihirR123 2023-06-22 20:32:49 -07:00 committed by GitHub
parent 35ed33af5f
commit 0ceb856aeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 218 additions and 216 deletions

View File

@ -4,17 +4,17 @@ import org.openmetadata.api.configuration.ChangeEventConfiguration;
public class ChangeEventConfig { public class ChangeEventConfig {
private static ChangeEventConfiguration INSTANCE; private static ChangeEventConfiguration instance;
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
public static void initialize(OpenMetadataApplicationConfig config) { public static void initialize(OpenMetadataApplicationConfig config) {
if (!INITIALIZED) { if (!initialized) {
INSTANCE = config.getChangeEventConfiguration(); instance = config.getChangeEventConfiguration();
INITIALIZED = true; initialized = true;
} }
} }
public static ChangeEventConfiguration getInstance() { public static ChangeEventConfiguration getInstance() {
return INSTANCE; return instance;
} }
} }

View File

@ -49,8 +49,8 @@ public class ReportsHandler {
private final SearchClient searchClient; private final SearchClient searchClient;
private final DataInsightChartRepository chartRepository; private final DataInsightChartRepository chartRepository;
private static ReportsHandler INSTANCE; private static ReportsHandler instance;
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
private final Scheduler reportScheduler = new StdSchedulerFactory().getScheduler(); private final Scheduler reportScheduler = new StdSchedulerFactory().getScheduler();
private static final ConcurrentHashMap<UUID, JobDetail> reportJobKeyMap = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<UUID, JobDetail> reportJobKeyMap = new ConcurrentHashMap<>();
@ -61,7 +61,7 @@ public class ReportsHandler {
} }
public static ReportsHandler getInstance() { public static ReportsHandler getInstance() {
if (INITIALIZED) return INSTANCE; if (initialized) return instance;
throw new DataInsightJobException("Reports Job Handler is not Initialized"); 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 { public static void initialize(CollectionDAO dao, SearchClient searchClient) throws SchedulerException {
if (!INITIALIZED) { if (!initialized) {
INSTANCE = new ReportsHandler(dao, searchClient); instance = new ReportsHandler(dao, searchClient);
INITIALIZED = true; initialized = true;
} else { } else {
LOG.info("Reindexing Handler is already initialized"); LOG.info("Reindexing Handler is already initialized");
} }
@ -133,8 +133,8 @@ public class ReportsHandler {
} }
public static void shutDown() throws SchedulerException { public static void shutDown() throws SchedulerException {
if (INSTANCE != null) { if (instance != null) {
INSTANCE.reportScheduler.shutdown(); instance.reportScheduler.shutdown();
} }
} }

View File

@ -16,20 +16,20 @@ import org.openmetadata.service.jdbi3.EventSubscriptionRepository;
@Slf4j @Slf4j
public class ActivityFeedAlertCache { public class ActivityFeedAlertCache {
private static final ActivityFeedAlertCache INSTANCE = new ActivityFeedAlertCache(); private static final ActivityFeedAlertCache INSTANCE = new ActivityFeedAlertCache();
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
protected static LoadingCache<String, EventSubscription> EVENT_SUB_CACHE; protected static LoadingCache<String, EventSubscription> eventSubCache;
protected static EventSubscriptionRepository EVENT_SUB_REPOSITORY; protected static EventSubscriptionRepository eventSubscriptionRepository;
private static String activityFeedAlertName; private static String activityFeedAlertName;
public static void initialize(String alertName, EventSubscriptionRepository repo) { public static void initialize(String alertName, EventSubscriptionRepository repo) {
if (!INITIALIZED) { if (!initialized) {
EVENT_SUB_CACHE = eventSubCache =
CacheBuilder.newBuilder() CacheBuilder.newBuilder()
.maximumSize(1000) .maximumSize(1000)
.expireAfterWrite(3, TimeUnit.MINUTES) .expireAfterWrite(3, TimeUnit.MINUTES)
.build(new ActivityFeedAlertLoader()); .build(new ActivityFeedAlertLoader());
EVENT_SUB_REPOSITORY = repo; eventSubscriptionRepository = repo;
INITIALIZED = true; initialized = true;
activityFeedAlertName = alertName; activityFeedAlertName = alertName;
} }
} }
@ -40,7 +40,7 @@ public class ActivityFeedAlertCache {
public EventSubscription getActivityFeedAlert() throws EntityNotFoundException { public EventSubscription getActivityFeedAlert() throws EntityNotFoundException {
try { try {
return EVENT_SUB_CACHE.get(activityFeedAlertName); return eventSubCache.get(activityFeedAlertName);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw new EntityNotFoundException(ex.getMessage()); throw new EntityNotFoundException(ex.getMessage());
} }
@ -49,7 +49,8 @@ public class ActivityFeedAlertCache {
static class ActivityFeedAlertLoader extends CacheLoader<String, EventSubscription> { static class ActivityFeedAlertLoader extends CacheLoader<String, EventSubscription> {
@Override @Override
public EventSubscription load(@CheckForNull String alertName) throws IOException { 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); LOG.debug("Loaded Alert {}", alert);
return alert; return alert;
} }

View File

@ -5,20 +5,20 @@ import org.openmetadata.service.OpenMetadataApplicationConfig;
import org.openmetadata.service.jdbi3.locator.ConnectionType; import org.openmetadata.service.jdbi3.locator.ConnectionType;
public class DatasourceConfig { public class DatasourceConfig {
private static DatasourceConfig INSTANCE; private static DatasourceConfig instance;
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
private static DataSourceFactory dataSourceFactory; private static DataSourceFactory dataSourceFactory;
public static void initialize(OpenMetadataApplicationConfig config) { public static void initialize(OpenMetadataApplicationConfig config) {
if (!INITIALIZED) { if (!initialized) {
INSTANCE = new DatasourceConfig(); instance = new DatasourceConfig();
dataSourceFactory = config.getDataSourceFactory(); dataSourceFactory = config.getDataSourceFactory();
INITIALIZED = true; initialized = true;
} }
} }
public static DatasourceConfig getInstance() { public static DatasourceConfig getInstance() {
return INSTANCE; return instance;
} }
public Boolean isMySQL() { public Boolean isMySQL() {

View File

@ -35,17 +35,17 @@ import org.openmetadata.service.util.JsonUtils;
@Slf4j @Slf4j
public class SettingsCache { public class SettingsCache {
private static final SettingsCache INSTANCE = new SettingsCache(); private static final SettingsCache INSTANCE = new SettingsCache();
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
protected static LoadingCache<String, Settings> SETTINGS_CACHE; protected static LoadingCache<String, Settings> settingsCache;
protected static SystemRepository systemRepository; protected static SystemRepository systemRepository;
// Expected to be called only once from the DefaultAuthorizer // Expected to be called only once from the DefaultAuthorizer
public static void initialize(CollectionDAO dao, OpenMetadataApplicationConfig config) { public static void initialize(CollectionDAO dao, OpenMetadataApplicationConfig config) {
if (!INITIALIZED) { if (!initialized) {
SETTINGS_CACHE = settingsCache =
CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new SettingsLoader()); CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new SettingsLoader());
systemRepository = new SystemRepository(dao.systemDAO()); systemRepository = new SystemRepository(dao.systemDAO());
INITIALIZED = true; initialized = true;
createDefaultConfiguration(config); createDefaultConfiguration(config);
} }
} }
@ -78,7 +78,7 @@ public class SettingsCache {
public <T> T getSetting(SettingsType settingName, Class<T> clazz) { public <T> T getSetting(SettingsType settingName, Class<T> clazz) {
try { 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); return JsonUtils.readValue(json, clazz);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to fetch Settings . Setting {}", settingName, ex); LOG.error("Failed to fetch Settings . Setting {}", settingName, ex);
@ -88,7 +88,7 @@ public class SettingsCache {
public Settings getSetting(SettingsType settingName) { public Settings getSetting(SettingsType settingName) {
try { try {
return SETTINGS_CACHE.get(settingName.toString()); return settingsCache.get(settingName.toString());
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to fetch Settings . Setting {}", settingName, ex); LOG.error("Failed to fetch Settings . Setting {}", settingName, ex);
throw new EntityNotFoundException("Setting not found"); throw new EntityNotFoundException("Setting not found");
@ -96,13 +96,13 @@ public class SettingsCache {
} }
public static void cleanUp() { public static void cleanUp() {
SETTINGS_CACHE.invalidateAll(); settingsCache.invalidateAll();
INITIALIZED = false; initialized = false;
} }
public void invalidateSettings(String settingsName) { public void invalidateSettings(String settingsName) {
try { try {
SETTINGS_CACHE.invalidate(settingsName); settingsCache.invalidate(settingsName);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to invalidate cache for settings {}", settingsName, ex); LOG.error("Failed to invalidate cache for settings {}", settingsName, ex);
} }

View File

@ -44,41 +44,43 @@ import org.openmetadata.service.util.FullyQualifiedName;
@Slf4j @Slf4j
public class TagLabelCache { public class TagLabelCache {
private static final TagLabelCache INSTANCE = new 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 TagRepository tagRepository;
protected static ClassificationRepository TAG_CLASSIFICATION_REPOSITORY; protected static ClassificationRepository tagClassificationRepository;
protected static LoadingCache<String, Tag> TAG_CACHE; // Tag fqn to Tag protected static LoadingCache<String, Tag> tagCache; // Tag fqn to Tag
protected static LoadingCache<String, Classification> CLASSIFICATION_CACHE; // Classification name to Classification protected static LoadingCache<String, Classification> classificationCache; // Classification name to Classification
protected static GlossaryTermRepository GLOSSARY_TERM_REPOSITORY; protected static GlossaryTermRepository glossaryTermRepository;
protected static GlossaryRepository GLOSSARY_REPOSITORY; protected static GlossaryRepository glossaryRepository;
protected static LoadingCache<String, GlossaryTerm> GLOSSARY_TERM_CACHE; // Glossary term fqn to GlossaryTerm // Glossary term fqn to GlossaryTerm
protected static LoadingCache<String, Glossary> GLOSSARY_CACHE; // Glossary fqn to Glossary protected static LoadingCache<String, GlossaryTerm> glossaryTermCache;
protected static LoadingCache<String, Glossary> glossaryCache; // Glossary fqn to Glossary
// Expected to be called only once from the TagResource during initialization // Expected to be called only once from the TagResource during initialization
public static void initialize() { public static void initialize() {
if (!INITIALIZED) { if (!initialized) {
CLASSIFICATION_CACHE = classificationCache =
CacheBuilder.newBuilder() CacheBuilder.newBuilder()
.maximumSize(25) .maximumSize(25)
.expireAfterWrite(2, TimeUnit.MINUTES) .expireAfterWrite(2, TimeUnit.MINUTES)
.build(new ClassificationLoader()); .build(new ClassificationLoader());
TAG_CACHE = tagCache =
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(2, TimeUnit.MINUTES).build(new TagLoader()); CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(2, TimeUnit.MINUTES).build(new TagLoader());
TAG_REPOSITORY = (TagRepository) Entity.getEntityRepository(Entity.TAG); tagRepository = (TagRepository) Entity.getEntityRepository(Entity.TAG);
TAG_CLASSIFICATION_REPOSITORY = (ClassificationRepository) Entity.getEntityRepository(Entity.CLASSIFICATION); tagClassificationRepository = (ClassificationRepository) Entity.getEntityRepository(Entity.CLASSIFICATION);
GLOSSARY_CACHE = glossaryCache =
CacheBuilder.newBuilder().maximumSize(25).expireAfterWrite(2, TimeUnit.MINUTES).build(new GlossaryLoader()); CacheBuilder.newBuilder().maximumSize(25).expireAfterWrite(2, TimeUnit.MINUTES).build(new GlossaryLoader());
GLOSSARY_TERM_CACHE = glossaryTermCache =
CacheBuilder.newBuilder() CacheBuilder.newBuilder()
.maximumSize(100) .maximumSize(100)
.expireAfterWrite(2, TimeUnit.MINUTES) .expireAfterWrite(2, TimeUnit.MINUTES)
.build(new GlossaryTermLoader()); .build(new GlossaryTermLoader());
GLOSSARY_TERM_REPOSITORY = (GlossaryTermRepository) Entity.getEntityRepository(Entity.GLOSSARY_TERM); glossaryTermRepository = (GlossaryTermRepository) Entity.getEntityRepository(Entity.GLOSSARY_TERM);
GLOSSARY_REPOSITORY = (GlossaryRepository) Entity.getEntityRepository(Entity.GLOSSARY); glossaryRepository = (GlossaryRepository) Entity.getEntityRepository(Entity.GLOSSARY);
INITIALIZED = true; initialized = true;
} else { } else {
LOG.info("Subject cache is already initialized"); LOG.info("Subject cache is already initialized");
} }
@ -89,16 +91,16 @@ public class TagLabelCache {
} }
public static void cleanUp() { public static void cleanUp() {
CLASSIFICATION_CACHE.cleanUp(); classificationCache.cleanUp();
TAG_CACHE.cleanUp(); tagCache.cleanUp();
GLOSSARY_CACHE.cleanUp(); glossaryCache.cleanUp();
GLOSSARY_TERM_CACHE.cleanUp(); glossaryTermCache.cleanUp();
INITIALIZED = false; initialized = false;
} }
public Classification getClassification(String classificationName) { public Classification getClassification(String classificationName) {
try { try {
return CLASSIFICATION_CACHE.get(classificationName); return classificationCache.get(classificationName);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage( throw EntityNotFoundException.byMessage(
CatalogExceptionMessage.entityNotFound(Entity.CLASSIFICATION, classificationName)); CatalogExceptionMessage.entityNotFound(Entity.CLASSIFICATION, classificationName));
@ -107,7 +109,7 @@ public class TagLabelCache {
public Tag getTag(String tagFqn) { public Tag getTag(String tagFqn) {
try { try {
return TAG_CACHE.get(tagFqn); return tagCache.get(tagFqn);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TAG, tagFqn)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TAG, tagFqn));
} }
@ -115,7 +117,7 @@ public class TagLabelCache {
public Glossary getGlossary(String glossaryName) { public Glossary getGlossary(String glossaryName) {
try { try {
return GLOSSARY_CACHE.get(glossaryName); return glossaryCache.get(glossaryName);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.GLOSSARY, glossaryName)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.GLOSSARY, glossaryName));
} }
@ -123,7 +125,7 @@ public class TagLabelCache {
public GlossaryTerm getGlossaryTerm(String glossaryTermFqn) { public GlossaryTerm getGlossaryTerm(String glossaryTermFqn) {
try { try {
return GLOSSARY_TERM_CACHE.get(glossaryTermFqn); return glossaryTermCache.get(glossaryTermFqn);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage( throw EntityNotFoundException.byMessage(
CatalogExceptionMessage.entityNotFound(Entity.GLOSSARY_TERM, glossaryTermFqn)); CatalogExceptionMessage.entityNotFound(Entity.GLOSSARY_TERM, glossaryTermFqn));
@ -161,7 +163,7 @@ public class TagLabelCache {
static class TagLoader extends CacheLoader<String, Tag> { static class TagLoader extends CacheLoader<String, Tag> {
@Override @Override
public Tag load(@CheckForNull String tagName) throws IOException { 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()); LOG.info("Loaded tag {}:{}", tag.getName(), tag.getId());
return tag; return tag;
} }
@ -171,7 +173,7 @@ public class TagLabelCache {
@Override @Override
public Classification load(@CheckForNull String classificationName) throws IOException { public Classification load(@CheckForNull String classificationName) throws IOException {
Classification classification = 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()); LOG.info("Loaded classification {}:{}", classification.getName(), classification.getId());
return classification; return classification;
} }
@ -180,7 +182,7 @@ public class TagLabelCache {
static class GlossaryTermLoader extends CacheLoader<String, GlossaryTerm> { static class GlossaryTermLoader extends CacheLoader<String, GlossaryTerm> {
@Override @Override
public GlossaryTerm load(@CheckForNull String glossaryTermName) throws IOException { 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()); LOG.info("Loaded glossaryTerm {}:{}", glossaryTerm.getName(), glossaryTerm.getId());
return glossaryTerm; return glossaryTerm;
} }
@ -189,7 +191,7 @@ public class TagLabelCache {
static class GlossaryLoader extends CacheLoader<String, Glossary> { static class GlossaryLoader extends CacheLoader<String, Glossary> {
@Override @Override
public Glossary load(@CheckForNull String glossaryName) throws IOException { 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()); LOG.info("Loaded glossary {}:{}", glossary.getName(), glossary.getId());
return glossary; return glossary;
} }

View File

@ -25,9 +25,7 @@ import software.amazon.awssdk.services.ssm.model.ParameterType;
import software.amazon.awssdk.services.ssm.model.PutParameterRequest; import software.amazon.awssdk.services.ssm.model.PutParameterRequest;
public class AWSSSMSecretsManager extends AWSBasedSecretsManager { public class AWSSSMSecretsManager extends AWSBasedSecretsManager {
private static AWSSSMSecretsManager instance = null;
private static AWSSSMSecretsManager INSTANCE = null;
private SsmClient ssmClient; private SsmClient ssmClient;
private AWSSSMSecretsManager(SecretsManagerConfiguration config, String clusterPrefix) { private AWSSSMSecretsManager(SecretsManagerConfiguration config, String clusterPrefix) {
@ -80,8 +78,8 @@ public class AWSSSMSecretsManager extends AWSBasedSecretsManager {
} }
public static AWSSSMSecretsManager getInstance(SecretsManagerConfiguration config, String clusterPrefix) { public static AWSSSMSecretsManager getInstance(SecretsManagerConfiguration config, String clusterPrefix) {
if (INSTANCE == null) INSTANCE = new AWSSSMSecretsManager(config, clusterPrefix); if (instance == null) instance = new AWSSSMSecretsManager(config, clusterPrefix);
return INSTANCE; return instance;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -27,9 +27,7 @@ import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueReques
import software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest; import software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest;
public class AWSSecretsManager extends AWSBasedSecretsManager { public class AWSSecretsManager extends AWSBasedSecretsManager {
private static AWSSecretsManager instance = null;
private static AWSSecretsManager INSTANCE = null;
private SecretsManagerClient secretsClient; private SecretsManagerClient secretsClient;
private AWSSecretsManager(SecretsManagerConfiguration config, String clusterPrefix) { private AWSSecretsManager(SecretsManagerConfiguration config, String clusterPrefix) {
@ -82,8 +80,10 @@ public class AWSSecretsManager extends AWSBasedSecretsManager {
} }
public static AWSSecretsManager getInstance(SecretsManagerConfiguration config, String clusterPrefix) { public static AWSSecretsManager getInstance(SecretsManagerConfiguration config, String clusterPrefix) {
if (INSTANCE == null) INSTANCE = new AWSSecretsManager(config, clusterPrefix); if (instance == null) {
return INSTANCE; instance = new AWSSecretsManager(config, clusterPrefix);
}
return instance;
} }
@VisibleForTesting @VisibleForTesting

View File

@ -21,9 +21,7 @@ import org.openmetadata.service.exception.SecretsManagerException;
/** Secret Manager used for testing */ /** Secret Manager used for testing */
public class InMemorySecretsManager extends ExternalSecretsManager { public class InMemorySecretsManager extends ExternalSecretsManager {
private static InMemorySecretsManager instance;
private static InMemorySecretsManager INSTANCE;
@Getter private final Map<String, String> secretsMap = new HashMap<>(); @Getter private final Map<String, String> secretsMap = new HashMap<>();
protected InMemorySecretsManager(String clusterPrefix) { protected InMemorySecretsManager(String clusterPrefix) {
@ -31,8 +29,10 @@ public class InMemorySecretsManager extends ExternalSecretsManager {
} }
public static InMemorySecretsManager getInstance(String clusterPrefix) { public static InMemorySecretsManager getInstance(String clusterPrefix) {
if (INSTANCE == null) INSTANCE = new InMemorySecretsManager(clusterPrefix); if (instance == null) {
return INSTANCE; instance = new InMemorySecretsManager(clusterPrefix);
}
return instance;
} }
@Override @Override

View File

@ -16,16 +16,17 @@ package org.openmetadata.service.secrets;
import org.openmetadata.schema.security.secrets.SecretsManagerProvider; import org.openmetadata.schema.security.secrets.SecretsManagerProvider;
public class NoopSecretsManager extends SecretsManager { public class NoopSecretsManager extends SecretsManager {
private static NoopSecretsManager instance;
private static NoopSecretsManager INSTANCE;
private NoopSecretsManager(String clusterPrefix, SecretsManagerProvider secretsManagerProvider) { private NoopSecretsManager(String clusterPrefix, SecretsManagerProvider secretsManagerProvider) {
super(secretsManagerProvider, clusterPrefix); super(secretsManagerProvider, clusterPrefix);
} }
public static NoopSecretsManager getInstance(String clusterPrefix, SecretsManagerProvider secretsManagerProvider) { public static NoopSecretsManager getInstance(String clusterPrefix, SecretsManagerProvider secretsManagerProvider) {
if (INSTANCE == null) INSTANCE = new NoopSecretsManager(clusterPrefix, secretsManagerProvider); if (instance == null) {
return INSTANCE; instance = new NoopSecretsManager(clusterPrefix, secretsManagerProvider);
}
return instance;
} }
@Override @Override

View File

@ -24,7 +24,7 @@ import org.openmetadata.service.util.JsonUtils;
@Slf4j @Slf4j
public class BotTokenCache { public class BotTokenCache {
public static final String EMPTY_STRING = ""; public static final String EMPTY_STRING = "";
private static BotTokenCache INSTANCE; private static BotTokenCache instance;
private final LoadingCache<String, String> BOTS_TOKEN_CACHE; private final LoadingCache<String, String> BOTS_TOKEN_CACHE;
public BotTokenCache() { public BotTokenCache() {
@ -52,10 +52,10 @@ public class BotTokenCache {
} }
public static BotTokenCache getInstance() { public static BotTokenCache getInstance() {
if (INSTANCE == null) { if (instance == null) {
INSTANCE = new BotTokenCache(); instance = new BotTokenCache();
} }
return INSTANCE; return instance;
} }
static class BotTokenLoader extends CacheLoader<String, String> { static class BotTokenLoader extends CacheLoader<String, String> {

View File

@ -26,21 +26,21 @@ import org.openmetadata.service.util.EntityUtil;
@Slf4j @Slf4j
public class UserTokenCache { public class UserTokenCache {
private static UserTokenCache INSTANCE; private static UserTokenCache instance;
private static LoadingCache<String, HashSet<String>> USER_TOKEN_CACHE; private static LoadingCache<String, HashSet<String>> userTokenCache;
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
private static TokenRepository tokenRepository; private static TokenRepository tokenRepository;
public static void initialize(CollectionDAO dao) { public static void initialize(CollectionDAO dao) {
if (!INITIALIZED) { if (!initialized) {
USER_TOKEN_CACHE = userTokenCache =
CacheBuilder.newBuilder() CacheBuilder.newBuilder()
.maximumSize(1000) .maximumSize(1000)
.expireAfterWrite(2, TimeUnit.MINUTES) .expireAfterWrite(2, TimeUnit.MINUTES)
.build(new UserTokenLoader()); .build(new UserTokenLoader());
tokenRepository = new TokenRepository(dao); tokenRepository = new TokenRepository(dao);
INSTANCE = new UserTokenCache(); instance = new UserTokenCache();
INITIALIZED = true; initialized = true;
LOG.info("User Token cache is initialized"); LOG.info("User Token cache is initialized");
} else { } else {
LOG.info("User Token cache is already initialized"); LOG.info("User Token cache is already initialized");
@ -49,7 +49,7 @@ public class UserTokenCache {
public HashSet<String> getToken(String userName) { public HashSet<String> getToken(String userName) {
try { try {
return USER_TOKEN_CACHE.get(userName); return userTokenCache.get(userName);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
LOG.error("Token not found", ex); LOG.error("Token not found", ex);
return null; return null;
@ -58,14 +58,14 @@ public class UserTokenCache {
public void invalidateToken(String userName) { public void invalidateToken(String userName) {
try { try {
USER_TOKEN_CACHE.invalidate(userName); userTokenCache.invalidate(userName);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to invalidate User token cache for User {}", userName, ex); LOG.error("Failed to invalidate User token cache for User {}", userName, ex);
} }
} }
public static UserTokenCache getInstance() { public static UserTokenCache getInstance() {
return INSTANCE; return instance;
} }
static class UserTokenLoader extends CacheLoader<String, HashSet<String>> { static class UserTokenLoader extends CacheLoader<String, HashSet<String>> {

View File

@ -36,11 +36,11 @@ import org.openmetadata.service.util.EntityUtil.Fields;
@Slf4j @Slf4j
public class PolicyCache { public class PolicyCache {
private static final PolicyCache INSTANCE = new PolicyCache(); private static final PolicyCache INSTANCE = new PolicyCache();
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
protected static LoadingCache<UUID, List<CompiledRule>> POLICY_CACHE; protected static LoadingCache<UUID, List<CompiledRule>> policyCache;
private static PolicyRepository POLICY_REPOSITORY; private static PolicyRepository policyRepository;
private static Fields FIELDS; private static Fields fields;
public static PolicyCache getInstance() { public static PolicyCache getInstance() {
return INSTANCE; return INSTANCE;
@ -48,18 +48,18 @@ public class PolicyCache {
/** To be called during application startup by Default Authorizer */ /** To be called during application startup by Default Authorizer */
public static void initialize() { public static void initialize() {
if (!INITIALIZED) { if (!initialized) {
POLICY_CACHE = policyCache =
CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new PolicyLoader()); CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new PolicyLoader());
POLICY_REPOSITORY = (PolicyRepository) Entity.getEntityRepository(Entity.POLICY); policyRepository = (PolicyRepository) Entity.getEntityRepository(Entity.POLICY);
FIELDS = POLICY_REPOSITORY.getFields("rules"); fields = policyRepository.getFields("rules");
INITIALIZED = true; initialized = true;
} }
} }
public List<CompiledRule> getPolicyRules(UUID policyId) { public List<CompiledRule> getPolicyRules(UUID policyId) {
try { try {
return POLICY_CACHE.get(policyId); return policyCache.get(policyId);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw new EntityNotFoundException(ex.getMessage()); throw new EntityNotFoundException(ex.getMessage());
} }
@ -67,7 +67,7 @@ public class PolicyCache {
public void invalidatePolicy(UUID policyId) { public void invalidatePolicy(UUID policyId) {
try { try {
POLICY_CACHE.invalidate(policyId); policyCache.invalidate(policyId);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to invalidate cache for policy {}", policyId, ex); LOG.error("Failed to invalidate cache for policy {}", policyId, ex);
} }
@ -82,14 +82,14 @@ public class PolicyCache {
} }
public static void cleanUp() { public static void cleanUp() {
POLICY_CACHE.cleanUp(); policyCache.cleanUp();
INITIALIZED = false; initialized = false;
} }
static class PolicyLoader extends CacheLoader<UUID, List<CompiledRule>> { static class PolicyLoader extends CacheLoader<UUID, List<CompiledRule>> {
@Override @Override
public List<CompiledRule> load(@CheckForNull UUID policyId) throws IOException { public List<CompiledRule> 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()); LOG.info("Loaded policy {}:{}", policy.getName(), policy.getId());
return PolicyCache.getInstance().getRules(policy); return PolicyCache.getInstance().getRules(policy);
} }

View File

@ -35,11 +35,11 @@ import org.openmetadata.service.util.EntityUtil.Fields;
@Slf4j @Slf4j
public class RoleCache { public class RoleCache {
private static final RoleCache INSTANCE = new RoleCache(); private static final RoleCache INSTANCE = new RoleCache();
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
protected static LoadingCache<String, Role> ROLE_CACHE; protected static LoadingCache<String, Role> roleCache;
protected static LoadingCache<UUID, Role> ROLE_CACHE_WITH_ID; protected static LoadingCache<UUID, Role> roleCacheWithId;
private static RoleRepository ROLE_REPOSITORY; private static RoleRepository roleRepository;
private static Fields FIELDS; private static Fields fields;
public static RoleCache getInstance() { public static RoleCache getInstance() {
return INSTANCE; return INSTANCE;
@ -47,23 +47,23 @@ public class RoleCache {
/** To be called only once during the application start from DefaultAuthorizer */ /** To be called only once during the application start from DefaultAuthorizer */
public static void initialize() { public static void initialize() {
if (!INITIALIZED) { if (!initialized) {
ROLE_CACHE = roleCache =
CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new RoleLoader()); CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new RoleLoader());
ROLE_CACHE_WITH_ID = roleCacheWithId =
CacheBuilder.newBuilder() CacheBuilder.newBuilder()
.maximumSize(100) .maximumSize(100)
.expireAfterWrite(3, TimeUnit.MINUTES) .expireAfterWrite(3, TimeUnit.MINUTES)
.build(new RoleLoaderWithId()); .build(new RoleLoaderWithId());
ROLE_REPOSITORY = (RoleRepository) Entity.getEntityRepository(Entity.ROLE); roleRepository = (RoleRepository) Entity.getEntityRepository(Entity.ROLE);
FIELDS = ROLE_REPOSITORY.getFields("policies"); fields = roleRepository.getFields("policies");
INITIALIZED = true; initialized = true;
} }
} }
public Role getRole(String roleName) { public Role getRole(String roleName) {
try { try {
return ROLE_CACHE.get(roleName); return roleCache.get(roleName);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(entityNotFound(Entity.ROLE, roleName)); throw EntityNotFoundException.byMessage(entityNotFound(Entity.ROLE, roleName));
} }
@ -71,7 +71,7 @@ public class RoleCache {
public Role getRoleById(UUID roleId) { public Role getRoleById(UUID roleId) {
try { try {
return ROLE_CACHE_WITH_ID.get(roleId); return roleCacheWithId.get(roleId);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(entityNotFound(Entity.ROLE, roleId)); throw EntityNotFoundException.byMessage(entityNotFound(Entity.ROLE, roleId));
} }
@ -79,7 +79,7 @@ public class RoleCache {
public void invalidateRole(UUID roleId) { public void invalidateRole(UUID roleId) {
try { try {
ROLE_CACHE_WITH_ID.invalidate(roleId); roleCacheWithId.invalidate(roleId);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to invalidate cache for role {}", roleId, ex); LOG.error("Failed to invalidate cache for role {}", roleId, ex);
} }
@ -88,7 +88,7 @@ public class RoleCache {
static class RoleLoader extends CacheLoader<String, Role> { static class RoleLoader extends CacheLoader<String, Role> {
@Override @Override
public Role load(@CheckForNull String roleName) throws IOException { 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()); LOG.info("Loaded role {}:{}", role.getName(), role.getId());
return role; return role;
} }
@ -97,14 +97,14 @@ public class RoleCache {
static class RoleLoaderWithId extends CacheLoader<UUID, Role> { static class RoleLoaderWithId extends CacheLoader<UUID, Role> {
@Override @Override
public Role load(@CheckForNull UUID roleId) throws IOException { 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()); LOG.info("Loaded role {}:{}", role.getName(), role.getId());
return role; return role;
} }
} }
public static void cleanUp() { public static void cleanUp() {
ROLE_CACHE_WITH_ID.cleanUp(); roleCacheWithId.cleanUp();
INITIALIZED = false; initialized = false;
} }
} }

View File

@ -44,40 +44,40 @@ import org.openmetadata.service.util.EntityUtil.Fields;
/** Subject context used for Access Control Policies */ /** Subject context used for Access Control Policies */
@Slf4j @Slf4j
public class SubjectCache { public class SubjectCache {
private static SubjectCache INSTANCE; private static SubjectCache instance;
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
protected static LoadingCache<String, SubjectContext> USER_CACHE; protected static LoadingCache<String, SubjectContext> userCache;
protected static LoadingCache<UUID, SubjectContext> USER_CACHE_WIH_ID; protected static LoadingCache<UUID, SubjectContext> userCacheWihId;
protected static LoadingCache<String, Team> TEAM_CACHE; protected static LoadingCache<String, Team> teamCache;
protected static LoadingCache<UUID, Team> TEAM_CACHE_WITH_ID; protected static LoadingCache<UUID, Team> teamCacheWithId;
protected static UserRepository USER_REPOSITORY; protected static UserRepository userRepository;
protected static Fields USER_FIELDS; protected static Fields userFields;
protected static TeamRepository TEAM_REPOSITORY; protected static TeamRepository teamRepository;
protected static Fields TEAM_FIELDS; protected static Fields teamFields;
// Expected to be called only once from the DefaultAuthorizer // Expected to be called only once from the DefaultAuthorizer
public static void initialize() { public static void initialize() {
if (!INITIALIZED) { if (!initialized) {
USER_CACHE = userCache =
CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new UserLoader()); CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new UserLoader());
USER_CACHE_WIH_ID = userCacheWihId =
CacheBuilder.newBuilder() CacheBuilder.newBuilder()
.maximumSize(1000) .maximumSize(1000)
.expireAfterWrite(3, TimeUnit.MINUTES) .expireAfterWrite(3, TimeUnit.MINUTES)
.build(new UserLoaderWithId()); .build(new UserLoaderWithId());
TEAM_CACHE = teamCache =
CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new TeamLoader()); CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(3, TimeUnit.MINUTES).build(new TeamLoader());
TEAM_CACHE_WITH_ID = teamCacheWithId =
CacheBuilder.newBuilder() CacheBuilder.newBuilder()
.maximumSize(1000) .maximumSize(1000)
.expireAfterWrite(3, TimeUnit.MINUTES) .expireAfterWrite(3, TimeUnit.MINUTES)
.build(new TeamLoaderWithId()); .build(new TeamLoaderWithId());
USER_REPOSITORY = (UserRepository) Entity.getEntityRepository(Entity.USER); userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
USER_FIELDS = USER_REPOSITORY.getFields("roles, teams, isAdmin, profile"); userFields = userRepository.getFields("roles, teams, isAdmin, profile");
TEAM_REPOSITORY = (TeamRepository) Entity.getEntityRepository(Entity.TEAM); teamRepository = (TeamRepository) Entity.getEntityRepository(Entity.TEAM);
TEAM_FIELDS = TEAM_REPOSITORY.getFields("defaultRoles, policies, parents, profile"); teamFields = teamRepository.getFields("defaultRoles, policies, parents, profile");
INSTANCE = new SubjectCache(); instance = new SubjectCache();
INITIALIZED = true; initialized = true;
LOG.info("Subject cache is initialized"); LOG.info("Subject cache is initialized");
} else { } else {
LOG.info("Subject cache is already initialized"); LOG.info("Subject cache is already initialized");
@ -85,12 +85,12 @@ public class SubjectCache {
} }
public static SubjectCache getInstance() { public static SubjectCache getInstance() {
return INSTANCE; return instance;
} }
public SubjectContext getSubjectContext(String userName) throws EntityNotFoundException { public SubjectContext getSubjectContext(String userName) throws EntityNotFoundException {
try { try {
return USER_CACHE.get(userName); return userCache.get(userName);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userName)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userName));
} }
@ -98,7 +98,7 @@ public class SubjectCache {
public SubjectContext getSubjectContext(UUID userId) throws EntityNotFoundException { public SubjectContext getSubjectContext(UUID userId) throws EntityNotFoundException {
try { try {
return USER_CACHE_WIH_ID.get(userId); return userCacheWihId.get(userId);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId));
} }
@ -106,7 +106,7 @@ public class SubjectCache {
public User getUser(String userName) throws EntityNotFoundException { public User getUser(String userName) throws EntityNotFoundException {
try { try {
return USER_CACHE.get(userName).getUser(); return userCache.get(userName).getUser();
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userName)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userName));
} }
@ -118,7 +118,7 @@ public class SubjectCache {
public User getUserById(UUID userId) throws EntityNotFoundException { public User getUserById(UUID userId) throws EntityNotFoundException {
try { try {
return USER_CACHE_WIH_ID.get(userId).getUser(); return userCacheWihId.get(userId).getUser();
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.USER, userId));
} }
@ -126,7 +126,7 @@ public class SubjectCache {
public Team getTeam(UUID teamId) throws EntityNotFoundException { public Team getTeam(UUID teamId) throws EntityNotFoundException {
try { try {
return TEAM_CACHE_WITH_ID.get(teamId); return teamCacheWithId.get(teamId);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TEAM, teamId)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TEAM, teamId));
} }
@ -134,7 +134,7 @@ public class SubjectCache {
public Team getTeamByName(String teamName) throws EntityNotFoundException { public Team getTeamByName(String teamName) throws EntityNotFoundException {
try { try {
return TEAM_CACHE.get(teamName); return teamCache.get(teamName);
} catch (ExecutionException | UncheckedExecutionException ex) { } catch (ExecutionException | UncheckedExecutionException ex) {
throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TEAM, teamName)); throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(Entity.TEAM, teamName));
} }
@ -178,14 +178,14 @@ public class SubjectCache {
public static void cleanUp() { public static void cleanUp() {
LOG.info("Subject cache is cleaned up"); LOG.info("Subject cache is cleaned up");
USER_CACHE.invalidateAll(); userCache.invalidateAll();
TEAM_CACHE_WITH_ID.invalidateAll(); teamCacheWithId.invalidateAll();
INITIALIZED = false; initialized = false;
} }
public void invalidateUser(String userName) { public void invalidateUser(String userName) {
try { try {
USER_CACHE.invalidate(userName); userCache.invalidate(userName);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to invalidate cache for user {}", userName, ex); LOG.error("Failed to invalidate cache for user {}", userName, ex);
} }
@ -193,7 +193,7 @@ public class SubjectCache {
public void invalidateTeam(UUID teamId) { public void invalidateTeam(UUID teamId) {
try { try {
TEAM_CACHE_WITH_ID.invalidate(teamId); teamCacheWithId.invalidate(teamId);
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Failed to invalidate cache for team {}", teamId, ex); LOG.error("Failed to invalidate cache for team {}", teamId, ex);
} }
@ -214,7 +214,7 @@ public class SubjectCache {
static class UserLoader extends CacheLoader<String, SubjectContext> { static class UserLoader extends CacheLoader<String, SubjectContext> {
@Override @Override
public SubjectContext load(@CheckForNull String userName) throws IOException { 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()); LOG.info("Loaded user {}:{}", user.getName(), user.getId());
return new SubjectContext(user); return new SubjectContext(user);
} }
@ -223,7 +223,7 @@ public class SubjectCache {
static class UserLoaderWithId extends CacheLoader<UUID, SubjectContext> { static class UserLoaderWithId extends CacheLoader<UUID, SubjectContext> {
@Override @Override
public SubjectContext load(@CheckForNull UUID uid) throws IOException { 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()); LOG.info("Loaded user {}:{}", user.getName(), user.getId());
return new SubjectContext(user); return new SubjectContext(user);
} }
@ -232,7 +232,7 @@ public class SubjectCache {
static class TeamLoader extends CacheLoader<String, Team> { static class TeamLoader extends CacheLoader<String, Team> {
@Override @Override
public Team load(@CheckForNull String userName) throws IOException { 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()); LOG.info("Loaded user {}:{}", team.getName(), team.getId());
return team; return team;
} }
@ -241,7 +241,7 @@ public class SubjectCache {
static class TeamLoaderWithId extends CacheLoader<UUID, Team> { static class TeamLoaderWithId extends CacheLoader<UUID, Team> {
@Override @Override
public Team load(@NonNull UUID teamId) throws IOException { 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()); LOG.info("Loaded team {}:{}", team.getName(), team.getId());
return team; return team;
} }

View File

@ -30,7 +30,7 @@ import org.openmetadata.common.utils.CommonUtil;
import org.openmetadata.service.OpenMetadataApplicationConfig; import org.openmetadata.service.OpenMetadataApplicationConfig;
public class SamlSettingsHolder { public class SamlSettingsHolder {
private static SamlSettingsHolder INSTANCE; private static SamlSettingsHolder instance;
private Map<String, Object> samlData; private Map<String, Object> samlData;
private SettingsBuilder builder; private SettingsBuilder builder;
@Getter private Saml2Settings saml2Settings; @Getter private Saml2Settings saml2Settings;
@ -44,8 +44,10 @@ public class SamlSettingsHolder {
} }
public static SamlSettingsHolder getInstance() { public static SamlSettingsHolder getInstance() {
if (INSTANCE == null) INSTANCE = new SamlSettingsHolder(); if (instance == null) {
return INSTANCE; instance = new SamlSettingsHolder();
}
return instance;
} }
public void initDefaultSettings(OpenMetadataApplicationConfig catalogApplicationConfig) public void initDefaultSettings(OpenMetadataApplicationConfig catalogApplicationConfig)

View File

@ -17,7 +17,7 @@ import org.openmetadata.service.security.policyevaluator.SubjectCache;
@Slf4j @Slf4j
public class WebSocketManager { public class WebSocketManager {
private static WebSocketManager INSTANCE; private static WebSocketManager instance;
@Getter private final EngineIoServer engineIoServer; @Getter private final EngineIoServer engineIoServer;
@Getter private final SocketIoServer socketIoServer; @Getter private final SocketIoServer socketIoServer;
public static final String FEED_BROADCAST_CHANNEL = "activityFeed"; public static final String FEED_BROADCAST_CHANNEL = "activityFeed";
@ -87,7 +87,7 @@ public class WebSocketManager {
} }
public static WebSocketManager getInstance() { public static WebSocketManager getInstance() {
return INSTANCE; return instance;
} }
public void broadCastMessageToAll(String event, String message) { public void broadCastMessageToAll(String event, String message) {
@ -123,7 +123,7 @@ public class WebSocketManager {
private WebSocketManagerBuilder() {} private WebSocketManagerBuilder() {}
public static void build(EngineIoServerOptions eiOptions) { public static void build(EngineIoServerOptions eiOptions) {
INSTANCE = new WebSocketManager(eiOptions); instance = new WebSocketManager(eiOptions);
} }
} }
} }

View File

@ -84,18 +84,18 @@ public class EmailUtil {
private static final String REPORT_SUBJECT = "%s: Data Insights Weekly - %s"; private static final String REPORT_SUBJECT = "%s: Data Insights Weekly - %s";
public static final String DATA_INSIGHT_REPORT_TEMPLATE = "dataInsightReport.ftl"; 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 SmtpSettings STORED_SMTP_SETTINGS;
private static Mailer MAILER; private static Mailer mailer;
private static Configuration TEMPLATE_CONFIGURATION; private static Configuration templateConfiguration;
private static final String EMAIL_IGNORE_MSG = "Email was not sent to %s as SMTP setting is not enabled"; private static final String EMAIL_IGNORE_MSG = "Email was not sent to %s as SMTP setting is not enabled";
private EmailUtil() { private EmailUtil() {
try { try {
STORED_SMTP_SETTINGS = getSmtpSettings(); STORED_SMTP_SETTINGS = getSmtpSettings();
MAILER = createMailer(STORED_SMTP_SETTINGS); mailer = createMailer(STORED_SMTP_SETTINGS);
TEMPLATE_CONFIGURATION = new Configuration(VERSION_2_3_28); templateConfiguration = new Configuration(VERSION_2_3_28);
LOG.info("Email Util cache is initialized"); LOG.info("Email Util cache is initialized");
} catch (Exception ex) { } catch (Exception ex) {
LOG.warn("[MAILER] Smtp Configurations are missing : Reason {} ", ex.getMessage(), ex); LOG.warn("[MAILER] Smtp Configurations are missing : Reason {} ", ex.getMessage(), ex);
@ -128,10 +128,10 @@ public class EmailUtil {
} }
public static EmailUtil getInstance() { public static EmailUtil getInstance() {
if (INSTANCE == null) { if (instance == null) {
INSTANCE = new EmailUtil(); instance = new EmailUtil();
} }
return INSTANCE; return instance;
} }
public void sendAccountStatus(User user, String action, String status) throws IOException, TemplateException { public void sendAccountStatus(User user, String action, String status) throws IOException, TemplateException {
@ -238,8 +238,8 @@ public class EmailUtil {
emailBuilder.to(to); emailBuilder.to(to);
emailBuilder.from(getSmtpSettings().getSenderMail()); emailBuilder.from(getSmtpSettings().getSenderMail());
TEMPLATE_CONFIGURATION.setClassForTemplateLoading(getClass(), baseTemplatePackage); templateConfiguration.setClassForTemplateLoading(getClass(), baseTemplatePackage);
Template template = TEMPLATE_CONFIGURATION.getTemplate(templatePath); Template template = templateConfiguration.getTemplate(templatePath);
// write the freemarker output to a StringWriter // write the freemarker output to a StringWriter
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
@ -261,8 +261,8 @@ public class EmailUtil {
emailBuilder.toMultiple(to); emailBuilder.toMultiple(to);
emailBuilder.from(getSmtpSettings().getSenderMail()); emailBuilder.from(getSmtpSettings().getSenderMail());
TEMPLATE_CONFIGURATION.setClassForTemplateLoading(getClass(), baseTemplatePackage); templateConfiguration.setClassForTemplateLoading(getClass(), baseTemplatePackage);
Template template = TEMPLATE_CONFIGURATION.getTemplate(templatePath); Template template = templateConfiguration.getTemplate(templatePath);
// write the freemarker output to a StringWriter // write the freemarker output to a StringWriter
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
@ -274,8 +274,8 @@ public class EmailUtil {
} }
public void sendMail(Email email) { public void sendMail(Email email) {
if (MAILER != null && getSmtpSettings().getEnableSmtpServer()) { if (mailer != null && getSmtpSettings().getEnableSmtpServer()) {
MAILER.sendMail(email, true); mailer.sendMail(email, true);
} }
} }
@ -366,7 +366,7 @@ public class EmailUtil {
} }
public void testConnection() { public void testConnection() {
MAILER.testConnection(); mailer.testConnection();
} }
private String getEmailVerificationSubject() { private String getEmailVerificationSubject() {
@ -419,7 +419,7 @@ public class EmailUtil {
SettingsCache.getInstance().getSetting(SettingsType.EMAIL_CONFIGURATION, SmtpSettings.class); SettingsCache.getInstance().getSetting(SettingsType.EMAIL_CONFIGURATION, SmtpSettings.class);
if (!emailConfig.equals(STORED_SMTP_SETTINGS)) { if (!emailConfig.equals(STORED_SMTP_SETTINGS)) {
STORED_SMTP_SETTINGS = emailConfig; STORED_SMTP_SETTINGS = emailConfig;
MAILER = createMailer(emailConfig); mailer = createMailer(emailConfig);
} }
return emailConfig; return emailConfig;
} }

View File

@ -19,20 +19,20 @@ import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.openmetadata.service.monitoring.EventMonitorConfiguration; import org.openmetadata.service.monitoring.EventMonitorConfiguration;
public class MicrometerBundleSingleton { public class MicrometerBundleSingleton {
private static MicrometerBundle INSTANCE; private static MicrometerBundle instance;
public static Timer webAnalyticEvents; public static Timer webAnalyticEvents;
public static PrometheusMeterRegistry prometheusMeterRegistry; public static PrometheusMeterRegistry prometheusMeterRegistry;
private MicrometerBundleSingleton() {} private MicrometerBundleSingleton() {}
public static MicrometerBundle getInstance() { public static MicrometerBundle getInstance() {
if (INSTANCE == null) { if (instance == null) {
INSTANCE = new MicrometerBundle(); instance = new MicrometerBundle();
// We'll use this registry to add monitoring around Ingestion Pipelines // We'll use this registry to add monitoring around Ingestion Pipelines
prometheusMeterRegistry = MicrometerBundle.prometheusRegistry; prometheusMeterRegistry = MicrometerBundle.prometheusRegistry;
} }
return INSTANCE; return instance;
} }
public static Timer latencyTimer(EventMonitorConfiguration configuration) { public static Timer latencyTimer(EventMonitorConfiguration configuration) {

View File

@ -40,7 +40,6 @@ import org.openmetadata.schema.system.EventPublisherJob;
import org.openmetadata.schema.system.Failure; import org.openmetadata.schema.system.Failure;
import org.openmetadata.schema.system.Stats; import org.openmetadata.schema.system.Stats;
import org.openmetadata.service.Entity; import org.openmetadata.service.Entity;
import org.openmetadata.service.elasticsearch.ElasticSearchIndexDefinition;
import org.openmetadata.service.exception.CustomExceptionMessage; import org.openmetadata.service.exception.CustomExceptionMessage;
import org.openmetadata.service.exception.UnhandledServerException; import org.openmetadata.service.exception.UnhandledServerException;
import org.openmetadata.service.jdbi3.CollectionDAO; import org.openmetadata.service.jdbi3.CollectionDAO;
@ -51,11 +50,10 @@ import org.openmetadata.service.workflows.searchIndex.SearchIndexWorkflow;
@Slf4j @Slf4j
public class ReIndexingHandler { public class ReIndexingHandler {
public static final String REINDEXING_JOB_EXTENSION = "reindexing.eventPublisher"; public static final String REINDEXING_JOB_EXTENSION = "reindexing.eventPublisher";
private static ReIndexingHandler INSTANCE; private static ReIndexingHandler instance;
private static volatile boolean INITIALIZED = false; private static volatile boolean initialized = false;
private static CollectionDAO dao; private static CollectionDAO dao;
private static SearchClient searchClient; private static SearchClient searchClient;
private static ElasticSearchIndexDefinition esIndexDefinition;
private static ExecutorService threadScheduler; private static ExecutorService threadScheduler;
private final Map<UUID, SearchIndexWorkflow> REINDEXING_JOB_MAP = new LinkedHashMap<>(); private final Map<UUID, SearchIndexWorkflow> REINDEXING_JOB_MAP = new LinkedHashMap<>();
private static BlockingQueue<Runnable> taskQueue; private static BlockingQueue<Runnable> taskQueue;
@ -63,17 +61,17 @@ public class ReIndexingHandler {
private ReIndexingHandler() {} private ReIndexingHandler() {}
public static ReIndexingHandler getInstance() { public static ReIndexingHandler getInstance() {
return INSTANCE; return instance;
} }
public static void initialize(SearchClient client, CollectionDAO daoObject) { public static void initialize(SearchClient client, CollectionDAO daoObject) {
if (!INITIALIZED) { if (!initialized) {
searchClient = client; searchClient = client;
dao = daoObject; dao = daoObject;
taskQueue = new ArrayBlockingQueue<>(5); taskQueue = new ArrayBlockingQueue<>(5);
threadScheduler = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, taskQueue); threadScheduler = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, taskQueue);
INSTANCE = new ReIndexingHandler(); instance = new ReIndexingHandler();
INITIALIZED = true; initialized = true;
} else { } else {
LOG.info("Reindexing Handler is already initialized"); LOG.info("Reindexing Handler is already initialized");
} }

View File

@ -57,7 +57,7 @@ public final class TablesInitializer {
private static final String OPTION_CONFIG_FILE_PATH = "config"; private static final String OPTION_CONFIG_FILE_PATH = "config";
private static final String DISABLE_VALIDATE_ON_MIGRATE = "disable-validate-on-migrate"; private static final String DISABLE_VALIDATE_ON_MIGRATE = "disable-validate-on-migrate";
private static final Options OPTIONS; private static final Options OPTIONS;
private static boolean DEBUG_MODE = false; private static boolean debugMode = false;
static { static {
OPTIONS = new Options(); OPTIONS = new Options();
@ -108,7 +108,7 @@ public final class TablesInitializer {
System.exit(1); System.exit(1);
} }
if (commandLine.hasOption(DEBUG_MODE_ENABLED)) { if (commandLine.hasOption(DEBUG_MODE_ENABLED)) {
DEBUG_MODE = true; debugMode = true;
} }
boolean isSchemaMigrationOptionSpecified = false; boolean isSchemaMigrationOptionSpecified = false;
SchemaMigrationOption schemaMigrationOptionSpecified = null; SchemaMigrationOption schemaMigrationOptionSpecified = null;
@ -303,7 +303,7 @@ public final class TablesInitializer {
} }
private static void printToConsoleInDebug(String message) { private static void printToConsoleInDebug(String message) {
if (DEBUG_MODE) { if (debugMode) {
System.out.println(message); System.out.println(message);
} }
} }

View File

@ -258,7 +258,7 @@ class RuleEvaluatorTest {
Team parentTeam = SubjectCache.getInstance().getTeam(parentId); Team parentTeam = SubjectCache.getInstance().getTeam(parentId);
team.setParents(listOf(parentTeam.getEntityReference())); team.setParents(listOf(parentTeam.getEntityReference()));
} }
SubjectCache.TEAM_CACHE_WITH_ID.put(team.getId(), team); SubjectCache.teamCacheWithId.put(team.getId(), team);
return team; return team;
} }
@ -278,7 +278,7 @@ class RuleEvaluatorTest {
private Role createRole(String roleName) { private Role createRole(String roleName) {
UUID roleId = UUID.nameUUIDFromBytes(roleName.getBytes(StandardCharsets.UTF_8)); UUID roleId = UUID.nameUUIDFromBytes(roleName.getBytes(StandardCharsets.UTF_8));
Role role = new Role().withName(roleName).withId(roleId); 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; return role;
} }

View File

@ -111,7 +111,7 @@ public class SubjectContextTest {
userRoles = getRoles("user"); userRoles = getRoles("user");
List<EntityReference> userRolesRef = toEntityReferences(userRoles); List<EntityReference> userRolesRef = toEntityReferences(userRoles);
user = new User().withName("user").withRoles(userRolesRef).withTeams(List.of(team111.getEntityReference())); 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 @AfterAll
@ -201,7 +201,7 @@ public class SubjectContextTest {
String name = prefix + "_role_" + i; String name = prefix + "_role_" + i;
List<EntityReference> policies = toEntityReferences(getPolicies(name)); List<EntityReference> policies = toEntityReferences(getPolicies(name));
Role role = new Role().withName(name).withId(UUID.randomUUID()).withPolicies(policies); 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); roles.add(role);
} }
return roles; return roles;
@ -213,7 +213,7 @@ public class SubjectContextTest {
String name = prefix + "_policy_" + i; String name = prefix + "_policy_" + i;
Policy policy = new Policy().withName(name).withId(UUID.randomUUID()).withRules(getRules(name)); Policy policy = new Policy().withName(name).withId(UUID.randomUUID()).withRules(getRules(name));
policies.add(policy); policies.add(policy);
PolicyCache.POLICY_CACHE.put(policy.getId(), PolicyCache.getInstance().getRules(policy)); PolicyCache.policyCache.put(policy.getId(), PolicyCache.getInstance().getRules(policy));
} }
return policies; return policies;
} }
@ -268,7 +268,7 @@ public class SubjectContextTest {
.withDefaultRoles(toEntityReferences(roles)) .withDefaultRoles(toEntityReferences(roles))
.withPolicies(toEntityReferences(policies)) .withPolicies(toEntityReferences(policies))
.withParents(parentList); .withParents(parentList);
SubjectCache.TEAM_CACHE_WITH_ID.put(team.getId(), team); SubjectCache.teamCacheWithId.put(team.getId(), team);
return team; return team;
} }