mneethiraj commented on code in PR #447: URL: https://github.com/apache/ranger/pull/447#discussion_r1881149862
########## tagsync/src/main/java/org/apache/ranger/tagsync/model/AbstractTagSource.java: ########## @@ -25,61 +25,52 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractTagSource implements TagSource { - private static final Logger LOG = LoggerFactory.getLogger(AbstractTagSource.class); - private TagSink tagSink; - private String name; +public abstract class AbstractTagSource implements TagSource { + private static final Logger LOG = LoggerFactory.getLogger(AbstractTagSource.class); + private TagSink tagSink; + private String name; - @Override - public void setTagSink(TagSink sink) { - if (sink == null) { - LOG.error("Sink is null!!!"); - } else { - this.tagSink = sink; - } - } + @Override + public void setTagSink(TagSink sink) { + if (sink == null) { + LOG.error("Sink is null!!!"); + } else { + this.tagSink = sink; + } + } - @Override - public void setName(String name) { - this.name = name; - } + @Override + public String getName() { + return name; + } - @Override - public String getName() { - return name; - } + @Override + public void setName(String name) { + this.name = name; + } - @Override - public String toString( ) { - return this.name; - } - - protected void updateSink(final ServiceTags toUpload) throws Exception { - try { - if (toUpload == null) { - if (LOG.isDebugEnabled()) { - LOG.debug("No ServiceTags to upload"); - } - } else { - if (!TagSyncConfig.isTagSyncServiceActive()) { - LOG.error("This TagSync server is not in active state. Cannot commit transaction!"); - throw new RuntimeException("This TagSync server is not in active state. Cannot commit transaction!"); - } - if (LOG.isDebugEnabled()) { - String toUploadJSON = JsonUtils.objectToJson(toUpload); - LOG.debug("Uploading serviceTags=" + toUploadJSON); - } - ServiceTags uploaded = tagSink.upload(toUpload); - if (LOG.isDebugEnabled()) { - String uploadedJSON = JsonUtils.objectToJson(uploaded); - LOG.debug("Uploaded serviceTags=" + uploadedJSON); - } - } - } catch (Exception exception) { - LOG.error("Failed to upload serviceTags: " + JsonUtils.objectToJson(toUpload)); - LOG.error("Exception : ", exception); - throw exception; - } - } + @Override + public String toString() { + return this.name; + } + protected void updateSink(final ServiceTags toUpload) throws Exception { + try { + if (toUpload == null) { + LOG.debug("No ServiceTags to upload"); + } else { + if (!TagSyncConfig.isTagSyncServiceActive()) { + LOG.error("This TagSync server is not in active state. Cannot commit transaction!"); + throw new RuntimeException("This TagSync server is not in active state. Cannot commit transaction!"); + } + LOG.debug("Uploading serviceTags={}", JsonUtils.objectToJson(toUpload)); Review Comment: LOG calls with potential expensive arguments (like `JsonUtils.objectToJson(toUpload)` here) should be surrounded by `LOG.isDebugEnabled()`, to avoid unnecessary overheads. Please review for other such instances and update. ########## tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasResourceMapper.java: ########## @@ -19,104 +19,101 @@ package org.apache.ranger.tagsync.source.atlas; -import java.util.Properties; - import org.apache.commons.lang.StringUtils; import org.apache.ranger.plugin.model.RangerServiceResource; import org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Properties; + public abstract class AtlasResourceMapper { - private static final Logger LOG = LoggerFactory.getLogger(AtlasResourceMapper.class); - - public static final String TAGSYNC_DEFAULT_CLUSTER_NAME = "ranger.tagsync.atlas.default.cluster.name"; - public static final String ENTITY_ATTRIBUTE_QUALIFIED_NAME = "qualifiedName"; - public static final String QUALIFIED_NAME_DELIMITER = "\\."; - public static final Character QUALIFIED_NAME_DELIMITER_CHAR = '.'; - - public static final String TAGSYNC_SERVICENAME_MAPPER_PROP_PREFIX = "ranger.tagsync.atlas."; - public static final String TAGSYNC_SERVICENAME_MAPPER_PROP_SUFFIX = ".ranger.service"; - public static final String TAGSYNC_ATLAS_CLUSTER_IDENTIFIER = ".instance."; - public static final String TAGSYNC_DEFAULT_CLUSTERNAME_AND_COMPONENTNAME_SEPARATOR = "_"; - public static final String CLUSTER_DELIMITER = "@"; - - protected final String componentName; - protected final String[] supportedEntityTypes; - - protected Properties properties; - protected String defaultClusterName; - - public AtlasResourceMapper(String componentName, String[] supportedEntityTypes) { - this.componentName = componentName; - this.supportedEntityTypes = supportedEntityTypes; - } - - public final String getComponentName() { - return componentName; - } - - public final String[] getSupportedEntityTypes() { - return supportedEntityTypes; - } - - public String getRangerServiceName(String clusterName) { - String ret = getCustomRangerServiceName(clusterName); - - if (StringUtils.isBlank(ret)) { - ret = clusterName + TAGSYNC_DEFAULT_CLUSTERNAME_AND_COMPONENTNAME_SEPARATOR + componentName; - } - return ret; - } - - public void initialize(Properties properties) { - this.properties = properties; - this.defaultClusterName = properties != null ? properties.getProperty(TAGSYNC_DEFAULT_CLUSTER_NAME) : null; - } - - abstract public RangerServiceResource buildResource(final RangerAtlasEntity entity) throws Exception; - - protected String getCustomRangerServiceName(String atlasInstanceName) { - if(properties != null) { - String propName = TAGSYNC_SERVICENAME_MAPPER_PROP_PREFIX + componentName - + TAGSYNC_ATLAS_CLUSTER_IDENTIFIER + atlasInstanceName - + TAGSYNC_SERVICENAME_MAPPER_PROP_SUFFIX; - - return properties.getProperty(propName); - } else { - return null; - } - } - - protected String getResourceNameFromQualifiedName(String qualifiedName) { - if(StringUtils.isNotBlank(qualifiedName)) { - int idx = qualifiedName.lastIndexOf(CLUSTER_DELIMITER); - - if(idx != -1) { - return qualifiedName.substring(0, idx); - } else { - return qualifiedName; - } - } - - return null; - } - - protected String getClusterNameFromQualifiedName(String qualifiedName) { - if(StringUtils.isNotBlank(qualifiedName)) { - int idx = qualifiedName.lastIndexOf(CLUSTER_DELIMITER); - - if(idx != -1 && qualifiedName.length() > idx) { - return qualifiedName.substring(idx + 1); - } - } - - return null; - } - - protected void throwExceptionWithMessage(String msg) throws Exception { - LOG.error(msg); - - throw new Exception(msg); - } + public static final String TAGSYNC_DEFAULT_CLUSTER_NAME = "ranger.tagsync.atlas.default.cluster.name"; + public static final String ENTITY_ATTRIBUTE_QUALIFIED_NAME = "qualifiedName"; + public static final String QUALIFIED_NAME_DELIMITER = "\\."; + public static final Character QUALIFIED_NAME_DELIMITER_CHAR = '.'; + public static final String TAGSYNC_SERVICENAME_MAPPER_PROP_PREFIX = "ranger.tagsync.atlas."; + public static final String TAGSYNC_SERVICENAME_MAPPER_PROP_SUFFIX = ".ranger.service"; + public static final String TAGSYNC_ATLAS_CLUSTER_IDENTIFIER = ".instance."; + public static final String TAGSYNC_DEFAULT_CLUSTERNAME_AND_COMPONENTNAME_SEPARATOR = "_"; + public static final String CLUSTER_DELIMITER = "@"; + private static final Logger LOG = LoggerFactory.getLogger(AtlasResourceMapper.class); Review Comment: To be consistent, keep Logger LOG initialization as the first line. ########## tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasOzoneResourceMapper.java: ########## @@ -32,259 +32,238 @@ import java.util.Properties; public class AtlasOzoneResourceMapper extends AtlasResourceMapper { - private static final Logger LOG = LoggerFactory.getLogger(AtlasOzoneResourceMapper.class); - - public static final String ENTITY_TYPE_OZONE_VOLUME = "ozone_volume"; - public static final String ENTITY_TYPE_OZONE_BUCKET = "ozone_bucket"; - public static final String ENTITY_TYPE_OZONE_KEY = "ozone_key"; - - public static final String RANGER_TYPE_OZONE_VOLUME = "volume"; - public static final String RANGER_TYPE_OZONE_BUCKET = "bucket"; - public static final String RANGER_TYPE_OZONE_KEY = "key"; - - public static final String[] SUPPORTED_ENTITY_TYPES = { ENTITY_TYPE_OZONE_VOLUME, ENTITY_TYPE_OZONE_BUCKET, ENTITY_TYPE_OZONE_KEY }; - - private static final String SEP_PROTOCOL = "://"; - private static final String SEP_RELATIVE_PATH = "/"; - private static final int IDX_VOLUME = 0; - private static final int IDX_BUCKET = 1; - private static final int IDX_KEY = 2; - private static final int IDX_CLUSTER_NAME = 3; - private static final int RESOURCE_COUNT = 4; - - // This flag results in ofs atlas qualifiedName to parse paths similar to o3fs - public static final String PROP_LEGACY_PARSING = "ranger.tagsync.atlas.ozone.legacy.parsing.enabled"; - public static final String PROP_OFS_KEY_DELIMITER = "ranger.tagsync.atlas.ozone.ofs.key_entity.separator"; - public static final String PROP_OFS_BUCKET_DELIMITER = "ranger.tagsync.atlas.ozone.ofs.bucket_entity.separator"; - - public static final String PROP_OFS_KEY_RECURSIVE_ENABLED = "ranger.tagsync.atlas.ozone.ofs.key.is.recursive.enabled"; - public static final String PROP_O3FS_KEY_RECURSIVE_ENABLED = "ranger.tagsync.atlas.ozone.o3fs.key.is.recursive.enabled"; - - private String ofsKeyDelimiter = "/"; - private String ofsBucketDelimiter = "\\."; - private boolean legacyParsingEnabled = false; - // keeping it true for ofs since it is new support from tagsync - private boolean isRecursiveEnabledOFSKey = true; - // Setting to true by default. Causes behavior change for customer with existing deployments. Configurable if required otherwise - private boolean isRecursiveEnabledO3FSKey = true; - - public AtlasOzoneResourceMapper() { - super("ozone", SUPPORTED_ENTITY_TYPES); - } - @Override - public void initialize(Properties properties) { - super.initialize(properties); - - if (this.properties != null) { - this.legacyParsingEnabled = Boolean.parseBoolean((String) this.properties.getOrDefault(PROP_LEGACY_PARSING, Boolean.toString(legacyParsingEnabled))); - this.ofsKeyDelimiter = (String) this.properties.getOrDefault(PROP_OFS_KEY_DELIMITER, this.ofsKeyDelimiter); - this.ofsBucketDelimiter = (String) this.properties.getOrDefault(PROP_OFS_BUCKET_DELIMITER, this.ofsBucketDelimiter); - this.isRecursiveEnabledOFSKey = Boolean.parseBoolean((String) this.properties.getOrDefault(PROP_OFS_KEY_RECURSIVE_ENABLED, Boolean.toString(isRecursiveEnabledOFSKey))); - this.isRecursiveEnabledO3FSKey = Boolean.parseBoolean((String) this.properties.getOrDefault(PROP_O3FS_KEY_RECURSIVE_ENABLED, Boolean.toString(isRecursiveEnabledO3FSKey))); - } - - LOG.info("ofsKeyDelimiter={}", this.ofsKeyDelimiter); - LOG.info("ofsBucketDelimiter={}", this.ofsBucketDelimiter); - LOG.info("legacyParsingEnabled={}",this.legacyParsingEnabled); - } - @Override - public RangerServiceResource buildResource(final RangerAtlasEntity entity) throws Exception { - String qualifiedName = (String)entity.getAttributes().get(AtlasResourceMapper.ENTITY_ATTRIBUTE_QUALIFIED_NAME); - - if (StringUtils.isEmpty(qualifiedName)) { - throw new Exception("attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "' not found in entity"); - } - - if (LOG.isDebugEnabled()) { - LOG.debug("ENTITY_ATTRIBUTE_QUALIFIED_NAME = " + qualifiedName); - } - - String entityType = entity.getTypeName(); - String entityGuid = entity.getGuid(); - String[] resources = parseQualifiedName(qualifiedName, entityType); - String volName = resources[IDX_VOLUME]; - String bktName = resources[IDX_BUCKET]; - String keyName = resources[IDX_KEY]; - String clusterName = resources[IDX_CLUSTER_NAME]; - - if (LOG.isDebugEnabled()) { - LOG.debug("Ozone resources for entityType " + entityType + " are " + Arrays.toString(resources)); - } - - if (StringUtils.isEmpty(clusterName)) { - throwExceptionWithMessage("cluster-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); - } - - String serviceName = getRangerServiceName(clusterName); - Map<String, RangerPolicyResource> elements = new HashMap<>(); - - if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_VOLUME)) { - if (StringUtils.isEmpty(volName)) { - throwExceptionWithMessage("volume-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); - } - - elements.put(RANGER_TYPE_OZONE_VOLUME, new RangerPolicyResource(volName)); - } else if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_BUCKET)) { - if (StringUtils.isEmpty(volName)) { - throwExceptionWithMessage("volume-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); - } else if (StringUtils.isEmpty(bktName)) { - throwExceptionWithMessage("bucket-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); - } - - elements.put(RANGER_TYPE_OZONE_VOLUME, new RangerPolicyResource(volName)); - elements.put(RANGER_TYPE_OZONE_BUCKET, new RangerPolicyResource(bktName)); - } else if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_KEY)) { - if (StringUtils.isEmpty(volName)) { - throwExceptionWithMessage("volume-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); - } else if (StringUtils.isEmpty(bktName)) { - throwExceptionWithMessage("bucket-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); - } else if (StringUtils.isEmpty(keyName)) { - throwExceptionWithMessage("key-name not found in attribute '" + ENTITY_ATTRIBUTE_QUALIFIED_NAME + "': " + qualifiedName); - } - boolean isRecursive = isRecursiveEnabledO3FSKey; - if (qualifiedName.startsWith("ofs://")){ - isRecursive = isRecursiveEnabledOFSKey; - } - elements.put(RANGER_TYPE_OZONE_VOLUME, new RangerPolicyResource(volName)); - elements.put(RANGER_TYPE_OZONE_BUCKET, new RangerPolicyResource(bktName)); - elements.put(RANGER_TYPE_OZONE_KEY, new RangerPolicyResource(keyName, false, isRecursive)); - } else { - throwExceptionWithMessage("unrecognized entity-type: " + entityType); - } - - if (elements.isEmpty()) { - throwExceptionWithMessage("invalid qualifiedName for entity-type '" + entityType + "': " + qualifiedName); - } - - RangerServiceResource ret = new RangerServiceResource(entityGuid, serviceName, elements); - - return ret; - } - - /* qualifiedName can be of format, depending upon the entity-type: - * o3fs://<volume name>@cm (ozone_key) - * o3fs://<volume name>.<bucket name>@<clusterName> (ozone_bucket) - * o3fs://<bucket name>.<volume name>.<ozone service id>/<key path>@<clusterName> (ozone_key) - * ofs://myvolume@cl1 - * ofs://myvolume.mybucket@cl1 - * ofs://ozone1/myvolume/mybucket/key1@cl1 - * ofs://ozone1/myvolume/mybucket/mykey/key1/@cl1 - */ - private String[] parseQualifiedName(String qualifiedName, String entityType) { - int idxProtocolSep = qualifiedName.indexOf(SEP_PROTOCOL); - String prefix = idxProtocolSep != -1 ? qualifiedName.substring(0, idxProtocolSep) : ""; - - if (LOG.isDebugEnabled()) { - LOG.debug("Prefix for qualifiedName={} is {}", qualifiedName, prefix); - } - - if (this.legacyParsingEnabled){ - return parseQualifiedNameO3FS(qualifiedName, entityType); - } else if (prefix.equals("ofs")) { - return parseQualifiedNameOFS(qualifiedName, entityType); - } else { - return parseQualifiedNameO3FS(qualifiedName, entityType); - } - } - - private String[] parseQualifiedNameOFS(String qualifiedName, String entityType) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> parseQualifiedNameOFS(qualifiedName={}, entityType={})", qualifiedName, entityType); - } - - String[] ret = new String[RESOURCE_COUNT]; - - if(StringUtils.isNotBlank(qualifiedName)) { - int idxClusterNameSep = qualifiedName.lastIndexOf(CLUSTER_DELIMITER); - - if (idxClusterNameSep != -1) { - ret[IDX_CLUSTER_NAME] = qualifiedName.substring(idxClusterNameSep + CLUSTER_DELIMITER.length()); - - int idxProtocolSep = qualifiedName.indexOf(SEP_PROTOCOL); - - if (idxProtocolSep != -1) { - int idxResourceStart = idxProtocolSep + SEP_PROTOCOL.length(); - - if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_VOLUME)) { // ofs://vol1@cl1 - ret[IDX_VOLUME] = qualifiedName.substring(idxResourceStart, idxClusterNameSep); - } else if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_BUCKET)) { // ofs://vol1.buck1@cl1 - // anything before first "." is volume name, after that is bucket name. So, "." in volume name is invalid when tagging buckets - String[] resources = qualifiedName.substring(idxResourceStart, idxClusterNameSep).split(this.ofsBucketDelimiter,2); - - ret[IDX_VOLUME] = resources.length > 0 ? resources[0] : null; - ret[IDX_BUCKET] = resources.length > 1 ? resources[1] : null; - } else if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_KEY)) { // ofs://svcid/vol1/buck1/d1/d2/key1@cl1 - // This is a special case wherein the delimiter is a "/" instead of a "." in the qualifiedName in ofs path - idxResourceStart = qualifiedName.indexOf(this.ofsKeyDelimiter, idxProtocolSep + SEP_PROTOCOL.length()) + 1; - - String resourceString = qualifiedName.substring(idxResourceStart, idxClusterNameSep); - String[] resources = resourceString.split(this.ofsKeyDelimiter, 3); - - ret[IDX_VOLUME] = resources.length > 0 ? resources[0] : null; - ret[IDX_BUCKET] = resources.length > 1 ? resources[1] : null; - ret[IDX_KEY] = resources.length > 2 ? resources[2] : null; - } - } - } - } - - if (LOG.isDebugEnabled()) { - LOG.debug("<== parseQualifiedNameOFS(qualifiedName={}, entityType={}): volume={}, bucket={}, key={}, clusterName={}", qualifiedName, entityType, ret[IDX_VOLUME], ret[IDX_BUCKET], ret[IDX_KEY], ret[IDX_CLUSTER_NAME]); - } - - return ret; - } - - private String[] parseQualifiedNameO3FS(String qualifiedName, String entityType){ - if (LOG.isDebugEnabled()) { - LOG.debug("==> parseQualifiedNameO3FS(qualifiedName={}, entityType={})", qualifiedName, entityType); - } - - String[] ret = new String[RESOURCE_COUNT]; - - if(StringUtils.isNotBlank(qualifiedName)) { - int idxClusterNameSep = qualifiedName.lastIndexOf(CLUSTER_DELIMITER); - - if (idxClusterNameSep != -1) { - ret[IDX_CLUSTER_NAME] = qualifiedName.substring(idxClusterNameSep + CLUSTER_DELIMITER.length()); - - int idxProtocolSep = qualifiedName.indexOf(SEP_PROTOCOL); - - if (idxProtocolSep != -1) { - int idxResourceStart = idxProtocolSep + SEP_PROTOCOL.length(); - - if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_VOLUME)) { // o3fs://vol1@cl1 - ret[IDX_VOLUME] = qualifiedName.substring(idxResourceStart, idxClusterNameSep); - } else if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_BUCKET)) { // o3fs://vol1.buck1@cl1 - String[] resources = qualifiedName.substring(idxResourceStart, idxClusterNameSep).split(QUALIFIED_NAME_DELIMITER); - - ret[IDX_VOLUME] = resources.length > 0 ? resources[0] : null; - ret[IDX_BUCKET] = resources.length > 1 ? resources[1] : null; - } else if (StringUtils.equals(entityType, ENTITY_TYPE_OZONE_KEY)) { // o3fs://buck1.vol1.svc1/d1/d2/key1@cl1 - String[] resources = qualifiedName.substring(idxResourceStart, idxClusterNameSep).split(QUALIFIED_NAME_DELIMITER, 3); - - ret[IDX_BUCKET] = resources.length > 0 ? resources[0] : null; - ret[IDX_VOLUME] = resources.length > 1 ? resources[1] : null; - ret[IDX_KEY] = resources.length > 2 ? resources[2] : null; - - if (ret[IDX_KEY] != null) { // skip svcid - int idxKeySep = ret[IDX_KEY].indexOf(SEP_RELATIVE_PATH); - - if (idxKeySep != -1) { - ret[IDX_KEY] = ret[IDX_KEY].substring(idxKeySep + SEP_RELATIVE_PATH.length()); - } else { - ret[IDX_KEY] = null; - } - } - } - } - } - } - - if (LOG.isDebugEnabled()) { - LOG.debug("<== parseQualifiedNameO3FS(qualifiedName={}, entityType={}): volume={}, bucket={}, key={}, clusterName={}", qualifiedName, entityType, ret[IDX_VOLUME], ret[IDX_BUCKET], ret[IDX_KEY], ret[IDX_CLUSTER_NAME]); - } + public static final String ENTITY_TYPE_OZONE_VOLUME = "ozone_volume"; + public static final String ENTITY_TYPE_OZONE_BUCKET = "ozone_bucket"; + public static final String ENTITY_TYPE_OZONE_KEY = "ozone_key"; + public static final String RANGER_TYPE_OZONE_VOLUME = "volume"; + public static final String RANGER_TYPE_OZONE_BUCKET = "bucket"; + public static final String RANGER_TYPE_OZONE_KEY = "key"; + public static final String[] SUPPORTED_ENTITY_TYPES = {ENTITY_TYPE_OZONE_VOLUME, ENTITY_TYPE_OZONE_BUCKET, ENTITY_TYPE_OZONE_KEY}; + // This flag results in ofs atlas qualifiedName to parse paths similar to o3fs + public static final String PROP_LEGACY_PARSING = "ranger.tagsync.atlas.ozone.legacy.parsing.enabled"; + public static final String PROP_OFS_KEY_DELIMITER = "ranger.tagsync.atlas.ozone.ofs.key_entity.separator"; + public static final String PROP_OFS_BUCKET_DELIMITER = "ranger.tagsync.atlas.ozone.ofs.bucket_entity.separator"; + public static final String PROP_OFS_KEY_RECURSIVE_ENABLED = "ranger.tagsync.atlas.ozone.ofs.key.is.recursive.enabled"; + public static final String PROP_O3FS_KEY_RECURSIVE_ENABLED = "ranger.tagsync.atlas.ozone.o3fs.key.is.recursive.enabled"; + private static final Logger LOG = LoggerFactory.getLogger(AtlasOzoneResourceMapper.class); Review Comment: To be consistent, keep `Logger LOG` initialization as the first line. ########## tagsync/src/main/java/org/apache/ranger/tagsync/source/atlas/AtlasTagSource.java: ########## @@ -45,288 +45,250 @@ import java.util.Properties; public class AtlasTagSource extends AbstractTagSource { - private static final Logger LOG = LoggerFactory.getLogger(AtlasTagSource.class); - - public static final String TAGSYNC_ATLAS_PROPERTIES_FILE_NAME = "atlas-application.properties"; - - public static final String TAGSYNC_ATLAS_KAFKA_ENDPOINTS = "atlas.kafka.bootstrap.servers"; - public static final String TAGSYNC_ATLAS_ZOOKEEPER_ENDPOINT = "atlas.kafka.zookeeper.connect"; - public static final String TAGSYNC_ATLAS_CONSUMER_GROUP = "atlas.kafka.entities.group.id"; - - public static final int MAX_WAIT_TIME_IN_MILLIS = 1000; - - private int maxBatchSize; - - private ConsumerRunnable consumerTask; - private Thread myThread = null; - - @Override - public boolean initialize(Properties properties) { - if (LOG.isDebugEnabled()) { - LOG.debug("==> AtlasTagSource.initialize()"); - } - - Properties atlasProperties = new Properties(); - - boolean ret = AtlasResourceMapperUtil.initializeAtlasResourceMappers(properties); - - if (ret) { - - InputStream inputStream = getClass().getClassLoader().getResourceAsStream(TAGSYNC_ATLAS_PROPERTIES_FILE_NAME); - - if (inputStream != null) { - try { - atlasProperties.load(inputStream); - } catch (Exception exception) { - ret = false; - LOG.error("Cannot load Atlas application properties file, file-name:" + TAGSYNC_ATLAS_PROPERTIES_FILE_NAME, exception); - } finally { - try { - inputStream.close(); - } catch (IOException ioException) { - LOG.error("Cannot close Atlas application properties file, file-name:" + TAGSYNC_ATLAS_PROPERTIES_FILE_NAME, ioException); - } - } - } else { - ret = false; - LOG.error("Cannot find Atlas application properties file"); - } - } - - if (ret) { - if (StringUtils.isBlank(atlasProperties.getProperty(TAGSYNC_ATLAS_KAFKA_ENDPOINTS))) { - ret = false; - LOG.error("Value of property '" + TAGSYNC_ATLAS_KAFKA_ENDPOINTS + "' is not specified!"); - } - if (StringUtils.isBlank(atlasProperties.getProperty(TAGSYNC_ATLAS_ZOOKEEPER_ENDPOINT))) { - ret = false; - LOG.error("Value of property '" + TAGSYNC_ATLAS_ZOOKEEPER_ENDPOINT + "' is not specified!"); - } - if (StringUtils.isBlank(atlasProperties.getProperty(TAGSYNC_ATLAS_CONSUMER_GROUP))) { - ret = false; - LOG.error("Value of property '" + TAGSYNC_ATLAS_CONSUMER_GROUP + "' is not specified!"); - } - } - - if (ret) { - NotificationInterface notification = NotificationProvider.get(); - List<NotificationConsumer<EntityNotification>> iterators = notification.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1); - - consumerTask = new ConsumerRunnable(iterators.get(0)); - } - - maxBatchSize = TagSyncConfig.getSinkMaxBatchSize(properties); - - if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasTagSource.initialize(), result=" + ret); - } - return ret; - } - - @Override - public boolean start() { - if (LOG.isDebugEnabled()) { - LOG.debug("==> AtlasTagSource.start()"); - } - if (consumerTask == null) { - LOG.error("No consumerTask!!!"); - } else { - myThread = new Thread(consumerTask); - myThread.setDaemon(true); - myThread.start(); - } - if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasTagSource.start()"); - } - return myThread != null; - } - - @Override - public void stop() { - if (myThread != null && myThread.isAlive()) { - myThread.interrupt(); - } - } - - private static String getPrintableEntityNotification(EntityNotificationWrapper notification) { - StringBuilder sb = new StringBuilder(); - - sb.append("{ Notification-Type: ").append(notification.getOpType()).append(", "); + public static final String TAGSYNC_ATLAS_PROPERTIES_FILE_NAME = "atlas-application.properties"; + public static final String TAGSYNC_ATLAS_KAFKA_ENDPOINTS = "atlas.kafka.bootstrap.servers"; + public static final String TAGSYNC_ATLAS_ZOOKEEPER_ENDPOINT = "atlas.kafka.zookeeper.connect"; + public static final String TAGSYNC_ATLAS_CONSUMER_GROUP = "atlas.kafka.entities.group.id"; + public static final int MAX_WAIT_TIME_IN_MILLIS = 1000; + private static final Logger LOG = LoggerFactory.getLogger(AtlasTagSource.class); Review Comment: To be consistent, keep Logger LOG initialization as the first line. Please review all files and update. ########## tagsync/src/main/java/org/apache/ranger/tagsync/process/TagSyncConfig.java: ########## @@ -38,534 +40,495 @@ import java.util.Enumeration; import java.util.Properties; -import org.apache.ranger.credentialapi.CredentialReader; -import org.apache.ranger.plugin.util.RangerCommonConstants; - public class TagSyncConfig extends Configuration { - private static final Logger LOG = LoggerFactory.getLogger(TagSyncConfig.class); - - private static TagSyncConfig instance = null; - private static final String CONFIG_FILE = "ranger-tagsync-site.xml"; - - private static final String DEFAULT_CONFIG_FILE = "ranger-tagsync-default.xml"; - - private static final String CORE_SITE_FILE = "core-site.xml"; - - public static final String TAGSYNC_ENABLED_PROP = "ranger.tagsync.enabled"; - - public static final String TAGSYNC_LOGDIR_PROP = "ranger.tagsync.logdir"; - - private static final String TAGSYNC_TAGADMIN_REST_URL_PROP = "ranger.tagsync.dest.ranger.endpoint"; - - private static final String TAGSYNC_TAGADMIN_REST_SSL_CONFIG_FILE_PROP = "ranger.tagsync.dest.ranger.ssl.config.filename"; - - private static final String TAGSYNC_SINK_CLASS_PROP = "ranger.tagsync.dest.ranger.impl.class"; - - private static final String TAGSYNC_DEST_RANGER_PASSWORD_ALIAS = "tagadmin.user.password"; - private static final String TAGSYNC_SOURCE_ATLASREST_PASSWORD_ALIAS = "atlas.user.password"; - - private static final String TAGSYNC_TAGADMIN_USERNAME_PROP = "ranger.tagsync.dest.ranger.username"; - private static final String TAGSYNC_ATLASREST_USERNAME_PROP = "ranger.tagsync.source.atlasrest.username"; - - private static final String TAGSYNC_TAGADMIN_PASSWORD_PROP = "ranger.tagsync.dest.ranger.password"; - private static final String TAGSYNC_ATLASREST_PASSWORD_PROP = "ranger.tagsync.source.atlasrest.password"; - - private static final String TAGSYNC_TAGADMIN_CONNECTION_CHECK_INTERVAL_PROP = "ranger.tagsync.dest.ranger.connection.check.interval"; - - private static final String TAGSYNC_SOURCE_ATLAS_CUSTOM_RESOURCE_MAPPERS_PROP = "ranger.tagsync.atlas.custom.resource.mappers"; - - private static final String TAGSYNC_ATLASSOURCE_ENDPOINT_PROP = "ranger.tagsync.source.atlasrest.endpoint"; - - private static final String TAGSYNC_ATLAS_REST_SOURCE_DOWNLOAD_INTERVAL_PROP = "ranger.tagsync.source.atlasrest.download.interval.millis"; - - private static final String TAGSYNC_ATLAS_REST_SSL_CONFIG_FILE_PROP = "ranger.tagsync.source.atlasrest.ssl.config.filename"; - - public static final String TAGSYNC_FILESOURCE_FILENAME_PROP = "ranger.tagsync.source.file.filename"; - - private static final String TAGSYNC_FILESOURCE_MOD_TIME_CHECK_INTERVAL_PROP = "ranger.tagsync.source.file.check.interval.millis"; - - private static final String TAGSYNC_KEYSTORE_TYPE_PROP = "ranger.keystore.file.type"; - private static final String TAGSYNC_TAGADMIN_KEYSTORE_PROP = "ranger.tagsync.keystore.filename"; - private static final String TAGSYNC_ATLASREST_KEYSTORE_PROP = "ranger.tagsync.source.atlasrest.keystore.filename"; - - private static final String TAGSYNC_SOURCE_RETRY_INITIALIZATION_INTERVAL_PROP = "ranger.tagsync.source.retry.initialization.interval.millis"; - - public static final String TAGSYNC_RANGER_COOKIE_ENABLED_PROP = "ranger.tagsync.cookie.enabled"; - public static final String TAGSYNC_TAGADMIN_COOKIE_NAME_PROP = "ranger.tagsync.dest.ranger.session.cookie.name"; - - private static final String DEFAULT_TAGADMIN_USERNAME = "rangertagsync"; - private static final String DEFAULT_ATLASREST_USERNAME = "admin"; - private static final String DEFAULT_ATLASREST_PASSWORD = "admin"; - - private static final int DEFAULT_TAGSYNC_TAGADMIN_CONNECTION_CHECK_INTERVAL = 15000; - private static final long DEFAULT_TAGSYNC_ATLASREST_SOURCE_DOWNLOAD_INTERVAL = 900000; - public static final int DEFAULT_TAGSYNC_ATLASREST_SOURCE_ENTITIES_BATCH_SIZE = 10000; - private static final long DEFAULT_TAGSYNC_FILESOURCE_MOD_TIME_CHECK_INTERVAL = 60000; - private static final long DEFAULT_TAGSYNC_SOURCE_RETRY_INITIALIZATION_INTERVAL = 10000; - - private static final String AUTH_TYPE = "hadoop.security.authentication"; - private static final String NAME_RULES = "hadoop.security.auth_to_local"; - private static final String TAGSYNC_KERBEROS_PRICIPAL = "ranger.tagsync.kerberos.principal"; - private static final String TAGSYNC_KERBEROS_KEYTAB = "ranger.tagsync.kerberos.keytab"; - - public static final String TAGSYNC_KERBEROS_IDENTITY = "tagsync.kerberos.identity"; - - private static String LOCAL_HOSTNAME = "unknown"; - - private static final String TAGSYNC_METRICS_FILEPATH = "ranger.tagsync.metrics.filepath"; - private static final String DEFAULT_TAGSYNC_METRICS_FILEPATH = "/tmp/"; - private static final String TAGSYNC_METRICS_FILENAME = "ranger.tagsync.metrics.filename"; - private static final String DEFAULT_TAGSYNC_METRICS_FILENAME = "ranger_tagsync_metric.json"; - private static final String TAGSYNC_METRICS_FREQUENCY_TIME_IN_MILLIS_PARAM = "ranger.tagsync.metrics.frequencytimeinmillis"; - private static final long DEFAULT_TAGSYNC_METRICS_FREQUENCY__TIME_IN_MILLIS = 10000L; - private static final String TAGSYNC_METRICS_ENABLED_PROP = "ranger.tagsync.metrics.enabled"; - - private static final int DEFAULT_TAGSYNC_SINK_MAX_BATCH_SIZE = 1; - private static final String TAGSYNC_SINK_MAX_BATCH_SIZE_PROP = "ranger.tagsync.dest.ranger.max.batch.size"; - - private static final String TAGSYNC_ATLASREST_SOURCE_ENTITIES_BATCH_SIZE = "ranger.tagsync.source.atlasrest.entities.batch.size"; - public static final String TAGSYNC_SERVER_HA_ENABLED_PARAM = "ranger-tagsync.server.ha.enabled"; - - private Properties props; - - static { - try { - LOCAL_HOSTNAME = java.net.InetAddress.getLocalHost().getCanonicalHostName(); - } catch (UnknownHostException e) { - LOCAL_HOSTNAME = "unknown"; - } - } - - public static TagSyncConfig getInstance() { - if(instance == null ){ - synchronized (TagSyncConfig.class){ - if(instance == null ){ - instance = new TagSyncConfig(); - } - } - } - return instance; - } - - public Properties getProperties() { - return props; - } - - public static InputStream getFileInputStream(String path) throws FileNotFoundException { - - InputStream ret = null; - - File f = new File(path); - - if (f.exists() && f.isFile() && f.canRead()) { - ret = new FileInputStream(f); - } else { - ret = TagSyncConfig.class.getResourceAsStream(path); - - if (ret == null) { - if (! path.startsWith("/")) { - ret = TagSyncConfig.class.getResourceAsStream("/" + path); - } - } - - if (ret == null) { - ret = ClassLoader.getSystemClassLoader().getResourceAsStream(path); - if (ret == null) { - if (! path.startsWith("/")) { - ret = ClassLoader.getSystemResourceAsStream("/" + path); - } - } - } - } - - return ret; - } - - public static String getResourceFileName(String path) { - - String ret = null; - - if (StringUtils.isNotBlank(path)) { - - File f = new File(path); - - if (f.exists() && f.isFile() && f.canRead()) { - ret = path; - } else { - - URL fileURL = TagSyncConfig.class.getResource(path); - if (fileURL == null) { - if (!path.startsWith("/")) { - fileURL = TagSyncConfig.class.getResource("/" + path); - } - } - - if (fileURL == null) { - fileURL = ClassLoader.getSystemClassLoader().getResource(path); - if (fileURL == null) { - if (!path.startsWith("/")) { - fileURL = ClassLoader.getSystemClassLoader().getResource("/" + path); - } - } - } - - if (fileURL != null) { - try { - ret = fileURL.getFile(); - } catch (Exception exception) { - LOG.error(path + " is not a file", exception); - } - } else { - LOG.warn("URL not found for " + path + " or no privilege for reading file " + path); - } - } - } - - return ret; - } - - synchronized static public boolean isTagSyncServiceActive() { - return TagSyncHAInitializerImpl.getInstance(TagSyncConfig.getInstance()).isActive(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - - sb.append("DEFAULT_CONFIG_FILE=").append(DEFAULT_CONFIG_FILE).append(", ") - .append("CONFIG_FILE=").append(CONFIG_FILE).append("\n\n"); - - return sb.toString() + super.toString(); - } - - static public String getTagsyncKeyStoreType(Properties prop) { - return prop.getProperty(TAGSYNC_KEYSTORE_TYPE_PROP); - } - - static public boolean isTagSyncRangerCookieEnabled(Properties prop) { - String val = prop.getProperty(TAGSYNC_RANGER_COOKIE_ENABLED_PROP); - return val == null || Boolean.valueOf(val.trim()); - } - - static public String getRangerAdminCookieName(Properties prop) { - String ret = RangerCommonConstants.DEFAULT_COOKIE_NAME; - String val = prop.getProperty(TAGSYNC_TAGADMIN_COOKIE_NAME_PROP); - if (StringUtils.isNotBlank(val)) { - ret = val; - } - return ret; - } - - static public String getTagSyncLogdir(Properties prop) { - return prop.getProperty(TAGSYNC_LOGDIR_PROP); - } - - static public long getTagSourceFileModTimeCheckIntervalInMillis(Properties prop) { - String val = prop.getProperty(TAGSYNC_FILESOURCE_MOD_TIME_CHECK_INTERVAL_PROP); - long ret = DEFAULT_TAGSYNC_FILESOURCE_MOD_TIME_CHECK_INTERVAL; - if (StringUtils.isNotBlank(val)) { - try { - ret = Long.valueOf(val); - } catch (NumberFormatException exception) { - // Ignore - } - } - return ret; - } - - static public long getTagSourceAtlasDownloadIntervalInMillis(Properties prop) { - String val = prop.getProperty(TAGSYNC_ATLAS_REST_SOURCE_DOWNLOAD_INTERVAL_PROP); - long ret = DEFAULT_TAGSYNC_ATLASREST_SOURCE_DOWNLOAD_INTERVAL; - if (StringUtils.isNotBlank(val)) { - try { - ret = Long.valueOf(val); - } catch (NumberFormatException exception) { - // Ignore - } - } - return ret; - } - - static public String getTagSinkClassName(Properties prop) { - String val = prop.getProperty(TAGSYNC_SINK_CLASS_PROP); - if (StringUtils.equalsIgnoreCase(val, "ranger")) { - return "org.apache.ranger.tagsync.sink.tagadmin.TagAdminRESTSink"; - } else - return val; - } - - static public String getTagAdminRESTUrl(Properties prop) { - return prop.getProperty(TAGSYNC_TAGADMIN_REST_URL_PROP); - } - - static public boolean isTagSyncEnabled(Properties prop) { - String val = prop.getProperty(TAGSYNC_ENABLED_PROP); - return val == null || Boolean.valueOf(val.trim()); - } - - static public String getTagAdminPassword(Properties prop) { - //update credential from keystore - String password = null; - if (prop != null && prop.containsKey(TAGSYNC_TAGADMIN_PASSWORD_PROP)) { - password = prop.getProperty(TAGSYNC_TAGADMIN_PASSWORD_PROP); - if (password != null && !password.isEmpty()) { - return password; - } - } - if (prop != null && prop.containsKey(TAGSYNC_TAGADMIN_KEYSTORE_PROP)) { - String path = prop.getProperty(TAGSYNC_TAGADMIN_KEYSTORE_PROP); - if (path != null) { - if (!path.trim().isEmpty()) { - try { - password = CredentialReader.getDecryptedString(path.trim(), TAGSYNC_DEST_RANGER_PASSWORD_ALIAS, getTagsyncKeyStoreType(prop)); - } catch (Exception ex) { - password = null; - } - if (password != null && !password.trim().isEmpty() && !password.trim().equalsIgnoreCase("none")) { - return password; - } - } - } - } - return null; - } - - static public String getTagAdminUserName(Properties prop) { - String userName=null; - if(prop!=null && prop.containsKey(TAGSYNC_TAGADMIN_USERNAME_PROP)){ - userName=prop.getProperty(TAGSYNC_TAGADMIN_USERNAME_PROP); - } - if(StringUtils.isBlank(userName)){ - userName=DEFAULT_TAGADMIN_USERNAME; - } - return userName; - } - - static public String getTagAdminRESTSslConfigFile(Properties prop) { - return prop.getProperty(TAGSYNC_TAGADMIN_REST_SSL_CONFIG_FILE_PROP); - } - - static public String getTagSourceFileName(Properties prop) { - return prop.getProperty(TAGSYNC_FILESOURCE_FILENAME_PROP); - } - - static public String getAtlasRESTEndpoint(Properties prop) { - return prop.getProperty(TAGSYNC_ATLASSOURCE_ENDPOINT_PROP); - } - - static public String getAtlasRESTPassword(Properties prop) { - //update credential from keystore - String password = null; - if (prop != null && prop.containsKey(TAGSYNC_ATLASREST_PASSWORD_PROP)) { - password = prop.getProperty(TAGSYNC_ATLASREST_PASSWORD_PROP); - if (password != null && !password.isEmpty()) { - return password; - } - } - if (prop != null && prop.containsKey(TAGSYNC_ATLASREST_KEYSTORE_PROP)) { - String path = prop.getProperty(TAGSYNC_ATLASREST_KEYSTORE_PROP); - if (path != null) { - if (!path.trim().isEmpty()) { - try { - password = CredentialReader.getDecryptedString(path.trim(), TAGSYNC_SOURCE_ATLASREST_PASSWORD_ALIAS, getTagsyncKeyStoreType(prop)); - } catch (Exception ex) { - password = null; - } - if (password != null && !password.trim().isEmpty() && !password.trim().equalsIgnoreCase("none")) { - return password; - } - } - } - } - if(StringUtils.isBlank(password)){ - return DEFAULT_ATLASREST_PASSWORD; - } - return null; - } - - static public String getAtlasRESTUserName(Properties prop) { - String userName=null; - if(prop!=null && prop.containsKey(TAGSYNC_ATLASREST_USERNAME_PROP)){ - userName=prop.getProperty(TAGSYNC_ATLASREST_USERNAME_PROP); - } - if(StringUtils.isBlank(userName)){ - userName=DEFAULT_ATLASREST_USERNAME; - } - return userName; - } - - static public String getAtlasRESTSslConfigFile(Properties prop) { - return prop.getProperty(TAGSYNC_ATLAS_REST_SSL_CONFIG_FILE_PROP); - } - - static public String getCustomAtlasResourceMappers(Properties prop) { - return prop.getProperty(TAGSYNC_SOURCE_ATLAS_CUSTOM_RESOURCE_MAPPERS_PROP); - } - - static public String getAuthenticationType(Properties prop){ - return prop.getProperty(AUTH_TYPE, "simple"); - } - - static public String getNameRules(Properties prop){ - return prop.getProperty(NAME_RULES, "DEFAULT"); - } - - static public String getKerberosPrincipal(Properties prop){ -// return prop.getProperty(TAGSYNC_KERBEROS_PRICIPAL); - String principal = null; - try { - principal = SecureClientLogin.getPrincipal(prop.getProperty(TAGSYNC_KERBEROS_PRICIPAL, ""), LOCAL_HOSTNAME); - } catch (IOException ignored) { - // do nothing - } - return principal; - } - - static public String getKerberosKeytab(Properties prop){ - return prop.getProperty(TAGSYNC_KERBEROS_KEYTAB, ""); - } - - static public long getTagAdminConnectionCheckInterval(Properties prop) { - long ret = DEFAULT_TAGSYNC_TAGADMIN_CONNECTION_CHECK_INTERVAL; - String val = prop.getProperty(TAGSYNC_TAGADMIN_CONNECTION_CHECK_INTERVAL_PROP); - if (StringUtils.isNotBlank(val)) { - try { - ret = Long.valueOf(val); - } catch (NumberFormatException exception) { - // Ignore - } - } - return ret; - } - - static public long getTagSourceRetryInitializationInterval(Properties prop) { - long ret = DEFAULT_TAGSYNC_SOURCE_RETRY_INITIALIZATION_INTERVAL; - String val = prop.getProperty(TAGSYNC_SOURCE_RETRY_INITIALIZATION_INTERVAL_PROP); - if (StringUtils.isNotBlank(val)) { - try { - ret = Long.valueOf(val); - } catch (NumberFormatException exception) { - // Ignore - } - } - return ret; - } - - static public String getTagsyncKerberosIdentity(Properties prop) { - return prop.getProperty(TAGSYNC_KERBEROS_IDENTITY); - } - - public static int getSinkMaxBatchSize(Properties prop) { - int ret = DEFAULT_TAGSYNC_SINK_MAX_BATCH_SIZE; - - String maxBatchSizeStr = prop.getProperty(TAGSYNC_SINK_MAX_BATCH_SIZE_PROP); - - if (StringUtils.isNotEmpty(maxBatchSizeStr)) { - try { - ret = Integer.valueOf(maxBatchSizeStr); - } catch (Exception e) { - } - } - return ret; - } - - private TagSyncConfig() { - super(false); - init(); - } - - private void init() { - - readConfigFile(CORE_SITE_FILE); - readConfigFile(DEFAULT_CONFIG_FILE); - readConfigFile(CONFIG_FILE); - - props = getProps(); - - @SuppressWarnings("unchecked") - Enumeration<String> propertyNames = (Enumeration<String>)props.propertyNames(); - - while (propertyNames.hasMoreElements()) { - String propertyName = propertyNames.nextElement(); - String systemPropertyValue = System.getProperty(propertyName); - if (systemPropertyValue != null) { - props.setProperty(propertyName, systemPropertyValue); - } - } - - } - - private void readConfigFile(String fileName) { - - if (StringUtils.isNotBlank(fileName)) { - String fName = getResourceFileName(fileName); - if (StringUtils.isBlank(fName)) { - LOG.warn("Cannot find configuration file " + fileName + " in the classpath"); - } else { - LOG.info("Loading configuration from " + fName); - addResource(fileName); - } - } else { - LOG.error("Configuration fileName is null"); - } - } - - public String getTagSyncMetricsFileName() { - String val = getProperties().getProperty(TAGSYNC_METRICS_FILEPATH); - if (StringUtils.isBlank(val)) { - if (StringUtils.isBlank(System.getProperty("logdir"))) { - val = DEFAULT_TAGSYNC_METRICS_FILEPATH; - } else { - val = System.getProperty("logdir"); - } - } - - if (Files.notExists(Paths.get(val))) { - return null; - } - - StringBuilder pathAndFileName = new StringBuilder(val); - if (!val.endsWith("/")) { - pathAndFileName.append("/"); - } - String fileName = getProperties().getProperty(TAGSYNC_METRICS_FILENAME); - if (StringUtils.isBlank(fileName)) { - fileName = DEFAULT_TAGSYNC_METRICS_FILENAME; - } - pathAndFileName.append(fileName); - return pathAndFileName.toString(); - } - - public long getTagSyncMetricsFrequency() { - long ret = DEFAULT_TAGSYNC_METRICS_FREQUENCY__TIME_IN_MILLIS; - String val = getProperties().getProperty(TAGSYNC_METRICS_FREQUENCY_TIME_IN_MILLIS_PARAM); - if (StringUtils.isNotBlank(val)) { - try { - ret = Long.valueOf(val); - } catch (NumberFormatException exception) { - // Ignore - } - } - return ret; - } - - public static boolean isTagSyncMetricsEnabled(Properties prop) { - String val = prop.getProperty(TAGSYNC_METRICS_ENABLED_PROP); - return "true".equalsIgnoreCase(StringUtils.trimToEmpty(val)); - } - - static public int getAtlasRestSourceEntitiesBatchSize(Properties prop) { - String val = prop.getProperty(TAGSYNC_ATLASREST_SOURCE_ENTITIES_BATCH_SIZE); - int ret = DEFAULT_TAGSYNC_ATLASREST_SOURCE_ENTITIES_BATCH_SIZE; - - if (StringUtils.isNotBlank(val)) { - try { - ret = Integer.valueOf(val); - } catch (NumberFormatException exception) { - // Ignore - } - } - - return ret; - } + public static final String TAGSYNC_ENABLED_PROP = "ranger.tagsync.enabled"; + public static final String TAGSYNC_LOGDIR_PROP = "ranger.tagsync.logdir"; + public static final String TAGSYNC_FILESOURCE_FILENAME_PROP = "ranger.tagsync.source.file.filename"; + public static final String TAGSYNC_RANGER_COOKIE_ENABLED_PROP = "ranger.tagsync.cookie.enabled"; + public static final String TAGSYNC_TAGADMIN_COOKIE_NAME_PROP = "ranger.tagsync.dest.ranger.session.cookie.name"; + public static final int DEFAULT_TAGSYNC_ATLASREST_SOURCE_ENTITIES_BATCH_SIZE = 10000; + public static final String TAGSYNC_KERBEROS_IDENTITY = "tagsync.kerberos.identity"; + public static final String TAGSYNC_SERVER_HA_ENABLED_PARAM = "ranger-tagsync.server.ha.enabled"; + private static final Logger LOG = LoggerFactory.getLogger(TagSyncConfig.class); Review Comment: To be consistent, `Logger LOG` initialization should be the first line in a class. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@ranger.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org