Commit 420983d5 by Deep Singh Committed by Sarath Subramanian

ATLAS-3966 Consider newer value for atlas.metadata.namespace if defined multiple times

parent cbc34271
......@@ -28,6 +28,7 @@ import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasConfigurationUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
......@@ -222,7 +223,7 @@ public class HBaseBridge {
}
private String getMetadataNamespace(Configuration config) {
return config.getString(HBASE_METADATA_NAMESPACE, getClusterName(config));
return AtlasConfigurationUtil.getRecentString(config, HBASE_METADATA_NAMESPACE, getClusterName(config));
}
private String getClusterName(Configuration config) {
......
......@@ -36,6 +36,7 @@ import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.utils.AtlasPathExtractorUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.HdfsNameServiceResolver;
import org.apache.atlas.utils.AtlasConfigurationUtil;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
......@@ -264,7 +265,7 @@ public class HiveMetaStoreBridge {
}
public String getMetadataNamespace(Configuration config) {
return config.getString(HIVE_METADATA_NAMESPACE, getClusterName(config));
return AtlasConfigurationUtil.getRecentString(config, HIVE_METADATA_NAMESPACE, getClusterName(config));
}
private String getClusterName(Configuration config) {
......
......@@ -26,6 +26,7 @@ import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.utils.AtlasConfigurationUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.atlas.utils.KafkaUtils;
import org.apache.commons.cli.BasicParser;
......@@ -167,7 +168,7 @@ public class KafkaBridge {
}
private String getMetadataNamespace(Configuration config) {
return config.getString(KAFKA_METADATA_NAMESPACE, getClusterName(config));
return AtlasConfigurationUtil.getRecentString(config, KAFKA_METADATA_NAMESPACE, getClusterName(config));
}
private String getClusterName(Configuration config) {
......
......@@ -33,6 +33,7 @@ import org.apache.atlas.model.notification.HookNotification.EntityCreateRequestV
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.sqoop.model.SqoopDataTypes;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasConfigurationUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang3.StringUtils;
import org.apache.sqoop.SqoopJobDataPublisher;
......@@ -86,7 +87,8 @@ public class SqoopHook extends SqoopJobDataPublisher {
public void publish(SqoopJobDataPublisher.Data data) throws AtlasHookException {
try {
Configuration atlasProperties = ApplicationProperties.get();
String metadataNamespace = atlasProperties.getString(ATLAS_METADATA_NAMESPACE, getClusterName(atlasProperties));
String metadataNamespace =
AtlasConfigurationUtil.getRecentString(atlasProperties, ATLAS_METADATA_NAMESPACE, getClusterName(atlasProperties));
AtlasEntity entDbStore = toSqoopDBStoreEntity(data);
AtlasEntity entHiveDb = toHiveDatabaseEntity(metadataNamespace, data.getHiveDB());
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.utils;
import org.apache.commons.configuration.Configuration;
public class AtlasConfigurationUtil {
public static String getRecentString(Configuration config, String key) {
return getRecentString(config, key, null);
}
public static String getRecentString(Configuration config, String key, String defaultValue) {
String ret = defaultValue;
String[] arr = config.getStringArray(key);
if (arr.length > 0) {
ret = arr[arr.length-1];
}
return ret;
}
}
......@@ -18,14 +18,10 @@
package org.apache.atlas;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.AbstractMap;
import com.sun.jersey.json.impl.provider.entity.JSONArrayProvider;
import org.apache.atlas.utils.AtlasConfigurationUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.springframework.cache.interceptor.SimpleKey;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
......@@ -147,4 +143,13 @@ public class ApplicationPropertiesTest {
aProps.setDefault(defaultKV, "");
assertEquals(props.getString(someKey), defaultValue);
}
@Test
public void verifyGetLatesttString () throws AtlasException {
String key="atlas.metadata.namespace", old_val = "nm-sp-1", new_val = "nm-sp-2";
Configuration atlasConf = ApplicationProperties.get("test.properties");
assertEquals(atlasConf.getString(key), old_val);
assertEquals(AtlasConfigurationUtil.getRecentString(atlasConf, key, old_val), new_val);
assertEquals(AtlasConfigurationUtil.getRecentString(atlasConf, "garbage", old_val), old_val);
}
}
......@@ -17,3 +17,6 @@
#
jaas.properties.file=atlas-jaas.properties
atlas.metadata.namespace=nm-sp-1
atlas.metadata.namespace=nm-sp-2
......@@ -26,7 +26,7 @@ import org.apache.atlas.kafka.NotificationProvider;
import org.apache.atlas.model.notification.HookNotification;
import org.apache.atlas.notification.NotificationException;
import org.apache.atlas.notification.NotificationInterface;
import org.apache.atlas.security.InMemoryJAASConfiguration;
import org.apache.atlas.utils.AtlasConfigurationUtil;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.security.UserGroupInformation;
......@@ -292,7 +292,7 @@ public abstract class AtlasHook {
}
private static String getMetadataNamespace(Configuration config) {
return config.getString(CONF_METADATA_NAMESPACE, getClusterName(config));
return AtlasConfigurationUtil.getRecentString(config, CONF_METADATA_NAMESPACE, getClusterName(config));
}
private static String getClusterName(Configuration config) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment