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 {
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;
}
}

View File

@ -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<UUID, JobDetail> 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();
}
}

View File

@ -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<String, EventSubscription> EVENT_SUB_CACHE;
protected static EventSubscriptionRepository EVENT_SUB_REPOSITORY;
private static volatile boolean initialized = false;
protected static LoadingCache<String, EventSubscription> 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<String, EventSubscription> {
@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;
}

View File

@ -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() {

View File

@ -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<String, Settings> SETTINGS_CACHE;
private static volatile boolean initialized = false;
protected static LoadingCache<String, Settings> 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> T getSetting(SettingsType settingName, Class<T> 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);
}

View File

@ -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<String, Tag> TAG_CACHE; // Tag fqn to Tag
protected static LoadingCache<String, Classification> CLASSIFICATION_CACHE; // Classification name to Classification
protected static TagRepository tagRepository;
protected static ClassificationRepository tagClassificationRepository;
protected static LoadingCache<String, Tag> tagCache; // Tag fqn to Tag
protected static LoadingCache<String, Classification> classificationCache; // Classification name to Classification
protected static GlossaryTermRepository GLOSSARY_TERM_REPOSITORY;
protected static GlossaryRepository GLOSSARY_REPOSITORY;
protected static LoadingCache<String, GlossaryTerm> GLOSSARY_TERM_CACHE; // Glossary term fqn to GlossaryTerm
protected static LoadingCache<String, Glossary> GLOSSARY_CACHE; // Glossary fqn to Glossary
protected static GlossaryTermRepository glossaryTermRepository;
protected static GlossaryRepository glossaryRepository;
// Glossary term fqn to GlossaryTerm
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
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<String, Tag> {
@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<String, GlossaryTerm> {
@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<String, Glossary> {
@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;
}

View File

@ -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

View File

@ -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

View File

@ -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<String, String> 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

View File

@ -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

View File

@ -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<String, String> 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<String, String> {

View File

@ -26,21 +26,21 @@ import org.openmetadata.service.util.EntityUtil;
@Slf4j
public class UserTokenCache {
private static UserTokenCache INSTANCE;
private static LoadingCache<String, HashSet<String>> USER_TOKEN_CACHE;
private static volatile boolean INITIALIZED = false;
private static UserTokenCache instance;
private static LoadingCache<String, HashSet<String>> 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<String> 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<String, HashSet<String>> {

View File

@ -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<UUID, List<CompiledRule>> POLICY_CACHE;
private static PolicyRepository POLICY_REPOSITORY;
private static Fields FIELDS;
protected static LoadingCache<UUID, List<CompiledRule>> 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<CompiledRule> 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<UUID, List<CompiledRule>> {
@Override
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());
return PolicyCache.getInstance().getRules(policy);
}

View File

@ -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<String, Role> ROLE_CACHE;
protected static LoadingCache<UUID, Role> ROLE_CACHE_WITH_ID;
private static RoleRepository ROLE_REPOSITORY;
private static Fields FIELDS;
private static volatile boolean initialized = false;
protected static LoadingCache<String, Role> roleCache;
protected static LoadingCache<UUID, Role> 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<String, Role> {
@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<UUID, Role> {
@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;
}
}

View File

@ -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<String, SubjectContext> USER_CACHE;
protected static LoadingCache<UUID, SubjectContext> USER_CACHE_WIH_ID;
protected static LoadingCache<String, Team> TEAM_CACHE;
protected static LoadingCache<UUID, Team> 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<String, SubjectContext> userCache;
protected static LoadingCache<UUID, SubjectContext> userCacheWihId;
protected static LoadingCache<String, Team> teamCache;
protected static LoadingCache<UUID, Team> 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<String, SubjectContext> {
@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<UUID, SubjectContext> {
@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<String, Team> {
@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<UUID, Team> {
@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;
}

View File

@ -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<String, Object> 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)

View File

@ -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);
}
}
}

View File

@ -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;
}

View File

@ -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) {

View File

@ -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<UUID, SearchIndexWorkflow> REINDEXING_JOB_MAP = new LinkedHashMap<>();
private static BlockingQueue<Runnable> 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");
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -111,7 +111,7 @@ public class SubjectContextTest {
userRoles = getRoles("user");
List<EntityReference> 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<EntityReference> 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;
}