You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/09/27 04:25:25 UTC
[1/7] atlas git commit: ATLAS-2179: Split Atlas client library to
avoid unnecessary dependencies
Repository: atlas
Updated Branches:
refs/heads/master 049c5120e -> 187730dd7
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
index ba5465d..cf44d4a 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
@@ -27,9 +27,7 @@ import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.kafka.NotificationProvider;
import org.apache.atlas.model.legacy.EntityResult;
-import org.apache.atlas.notification.NotificationConsumer;
import org.apache.atlas.notification.NotificationInterface;
-import org.apache.atlas.notification.entity.EntityNotification;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct;
import org.apache.atlas.typesystem.TypesDef;
@@ -195,7 +193,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
databaseInstance.set("location", "/tmp");
JSONObject response = atlasClientV1
- .callAPIWithBody(AtlasClient.API.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true));
+ .callAPIWithBody(AtlasClient.API_V1.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true));
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -345,7 +343,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String description = "bar table - new desc";
addProperty(guid, "description", description);
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
Assert.assertNotNull(response);
referenceable.set("description", description);
@@ -363,7 +361,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
// updating date attribute as string not supported in v2
// addProperty(guid, "createTime", currentTime);
- response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
+ response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
Assert.assertNotNull(response);
referenceable.set("createTime", currentTime);
@@ -483,7 +481,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class)
public void testGetInvalidEntityDefinition() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, "blah");
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, "blah");
Assert.assertNotNull(response);
@@ -516,7 +514,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", "blah");
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.ERROR));
}
@@ -529,7 +527,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", typeName);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GET_ENTITY, queryParams);
assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -716,7 +714,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String traitInstanceAsJSON = InstanceSerialization$.MODULE$.toJson(traitInstance, true);
LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
- atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS);
+ atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS);
}
@Test
@@ -835,7 +833,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
instance.set(attrName, attrValue);
Id guid = createInstance(instance);
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid._getId());
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.getString(AtlasClient.DEFINITION), true);
Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
@@ -1029,7 +1027,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId());
queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId());
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.DELETE_ENTITIES, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.DELETE_ENTITIES, queryParams);
List<String> deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities();
Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
index 55c56c2..3811390 100644
--- a/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
@@ -21,6 +21,7 @@ package org.apache.atlas.web.integration;
import com.google.common.collect.ImmutableList;
import com.google.gson.Gson;
import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasBaseClient;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.lineage.AtlasLineageInfo;
@@ -37,19 +38,17 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import static org.apache.atlas.AtlasBaseClient.APIInfo;
-
/**
* Entity Lineage v2 Integration Tests.
*/
public class EntityLineageJerseyResourceIT extends DataSetLineageJerseyResourceIT {
- private static final String BASE_URI = "api/atlas/v2/lineage";
- private static final APIInfo LINEAGE_V2_API = new APIInfo(BASE_URI, "GET", Response.Status.OK);
- private static final String INPUT_DIRECTION = "INPUT";
- private static final String OUTPUT_DIRECTION = "OUTPUT";
- private static final String BOTH_DIRECTION = "BOTH";
- private static final String DIRECTION_PARAM = "direction";
- private static final String DEPTH_PARAM = "depth";
+ private static final String BASE_URI = "api/atlas/v2/lineage";
+ private static final AtlasBaseClient.API LINEAGE_V2_API = new AtlasBaseClient.API(BASE_URI, "GET", Response.Status.OK);
+ private static final String INPUT_DIRECTION = "INPUT";
+ private static final String OUTPUT_DIRECTION = "OUTPUT";
+ private static final String BOTH_DIRECTION = "BOTH";
+ private static final String DIRECTION_PARAM = "direction";
+ private static final String DEPTH_PARAM = "depth";
private String salesFactTable;
private String salesMonthlyTable;
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
index 3fa85b1..a13f069 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
@@ -69,7 +69,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -92,7 +92,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from "+ DATABASE_TYPE + " name=\"" + dbName + "\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
assertNotNull(response);
//higher limit, all results returned
@@ -141,7 +141,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String dslQuery = "from blah";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", dslQuery);
- atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams);
+ atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_DSL, queryParams);
}
@Test
@@ -150,7 +150,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GREMLIN_SEARCH, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.GREMLIN_SEARCH, queryParams);
assertNotNull(response);
assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -165,7 +165,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "from "+ DATABASE_TYPE + " name=\"" + dbName +"\"";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -179,7 +179,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = "*";
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -211,7 +211,7 @@ public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
String query = dbName;
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("query", query);
- response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_FULL_TEXT, queryParams);
+ response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.SEARCH_FULL_TEXT, queryParams);
results = response.getJSONArray(AtlasClient.RESULTS);
assertEquals(results.length(), 1);
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
index 54db3c0..351e5ae 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
@@ -81,7 +81,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
String typesAsJSON = TypesSerialization.toJson(typeDefinition, false);
System.out.println("typesAsJSON = " + typesAsJSON);
- JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.CREATE_TYPE, typesAsJSON);
+ JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API_V1.CREATE_TYPE, typesAsJSON);
Assert.assertNotNull(response);
@@ -142,7 +142,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
System.out.println("typeName = " + typeDefinition.typeName);
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName);
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, typeDefinition.typeName);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
@@ -164,12 +164,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class)
public void testGetDefinitionForNonexistentType() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, "blah");
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, "blah");
}
@Test(dependsOnMethods = "testSubmit")
public void testGetTypeNames() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, (String[]) null);
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.LIST_TYPES, null, (String[]) null);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
@@ -190,7 +190,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("type", DataTypes.TypeCategory.TRAIT.name());
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.LIST_TYPES, queryParams);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API_V1.LIST_TYPES, queryParams);
Assert.assertNotNull(response);
Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
[3/7] atlas git commit: ATLAS-2179: Split Atlas client library to
avoid unnecessary dependencies
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/security/SecureClientUtils.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/security/SecureClientUtils.java b/client/src/main/java/org/apache/atlas/security/SecureClientUtils.java
deleted file mode 100644
index d5392b2..0000000
--- a/client/src/main/java/org/apache/atlas/security/SecureClientUtils.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * 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.security;
-
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
-import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
-import org.apache.atlas.AtlasException;
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hadoop.security.alias.CredentialProviderFactory;
-import org.apache.hadoop.security.authentication.client.Authenticator;
-import org.apache.hadoop.security.authentication.client.ConnectionConfigurator;
-import org.apache.hadoop.security.ssl.SSLFactory;
-import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL;
-import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticator;
-import org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSocketFactory;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.GeneralSecurityException;
-import java.security.PrivilegedExceptionAction;
-
-import static org.apache.atlas.security.SecurityProperties.CERT_STORES_CREDENTIAL_PROVIDER_PATH;
-import static org.apache.atlas.security.SecurityProperties.CLIENT_AUTH_KEY;
-import static org.apache.atlas.security.SecurityProperties.KEYSTORE_FILE_KEY;
-import static org.apache.atlas.security.SecurityProperties.TRUSTSTORE_FILE_KEY;
-
-/**
- *
- */
-public class SecureClientUtils {
-
- public final static int DEFAULT_SOCKET_TIMEOUT_IN_MSECS = 1 * 60 * 1000; // 1 minute
- private static final Logger LOG = LoggerFactory.getLogger(SecureClientUtils.class);
-
-
- public static URLConnectionClientHandler getClientConnectionHandler(DefaultClientConfig config,
- org.apache.commons.configuration.Configuration clientConfig, String doAsUser,
- final UserGroupInformation ugi) {
- config.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
- Configuration conf = new Configuration();
- conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, SecurityProperties.SSL_CLIENT_PROPERTIES));
- UserGroupInformation.setConfiguration(conf);
- final ConnectionConfigurator connConfigurator = newConnConfigurator(conf);
-
- Authenticator authenticator = new KerberosDelegationTokenAuthenticator();
-
- authenticator.setConnectionConfigurator(connConfigurator);
- final DelegationTokenAuthenticator finalAuthenticator = (DelegationTokenAuthenticator) authenticator;
- final DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token();
- HttpURLConnectionFactory httpURLConnectionFactory = null;
- try {
- UserGroupInformation ugiToUse = ugi != null ? ugi : UserGroupInformation.getCurrentUser();
- final UserGroupInformation actualUgi =
- (ugiToUse.getAuthenticationMethod() == UserGroupInformation.AuthenticationMethod.PROXY)
- ? ugiToUse.getRealUser() : ugiToUse;
- LOG.info("Real User: {}, is from ticket cache? {}", actualUgi, actualUgi.isLoginTicketBased());
- if (StringUtils.isEmpty(doAsUser)) {
- doAsUser = actualUgi.getShortUserName();
- }
- LOG.info("doAsUser: {}", doAsUser);
- final String finalDoAsUser = doAsUser;
- httpURLConnectionFactory = new HttpURLConnectionFactory() {
- @Override
- public HttpURLConnection getHttpURLConnection(final URL url) throws IOException {
- try {
- return actualUgi.doAs(new PrivilegedExceptionAction<HttpURLConnection>() {
- @Override
- public HttpURLConnection run() throws Exception {
- try {
- return new DelegationTokenAuthenticatedURL(finalAuthenticator, connConfigurator)
- .openConnection(url, token, finalDoAsUser);
- } catch (Exception e) {
- throw new IOException(e);
- }
- }
- });
- } catch (Exception e) {
- if (e instanceof IOException) {
- throw (IOException) e;
- } else {
- throw new IOException(e);
- }
- }
- }
- };
- } catch (IOException e) {
- LOG.warn("Error obtaining user", e);
- }
-
- return new URLConnectionClientHandler(httpURLConnectionFactory);
- }
-
- private final static ConnectionConfigurator DEFAULT_TIMEOUT_CONN_CONFIGURATOR = new ConnectionConfigurator() {
- @Override
- public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
- setTimeouts(conn, DEFAULT_SOCKET_TIMEOUT_IN_MSECS);
- return conn;
- }
- };
-
- private static ConnectionConfigurator newConnConfigurator(Configuration conf) {
- try {
- return newSslConnConfigurator(DEFAULT_SOCKET_TIMEOUT_IN_MSECS, conf);
- } catch (Exception e) {
- LOG.debug("Cannot load customized ssl related configuration. " + "Fallback to system-generic settings.", e);
- return DEFAULT_TIMEOUT_CONN_CONFIGURATOR;
- }
- }
-
- private static ConnectionConfigurator newSslConnConfigurator(final int timeout, Configuration conf)
- throws IOException, GeneralSecurityException {
- final SSLFactory factory;
- final SSLSocketFactory sf;
- final HostnameVerifier hv;
-
- factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
- factory.init();
- sf = factory.createSSLSocketFactory();
- hv = factory.getHostnameVerifier();
-
- return new ConnectionConfigurator() {
- @Override
- public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
- if (conn instanceof HttpsURLConnection) {
- HttpsURLConnection c = (HttpsURLConnection) conn;
- c.setSSLSocketFactory(sf);
- c.setHostnameVerifier(hv);
- }
- setTimeouts(conn, timeout);
- return conn;
- }
- };
- }
-
- private static void setTimeouts(URLConnection connection, int socketTimeout) {
- connection.setConnectTimeout(socketTimeout);
- connection.setReadTimeout(socketTimeout);
- }
-
- private static File getSSLClientFile() throws AtlasException {
- String confLocation = System.getProperty("atlas.conf");
- File sslDir;
- try {
- if (confLocation == null) {
- String persistDir = null;
- URL resource = SecureClientUtils.class.getResource("/");
- if (resource != null) {
- persistDir = resource.toURI().getPath();
- }
- assert persistDir != null;
- sslDir = new File(persistDir);
- } else {
- sslDir = new File(confLocation);
- }
- LOG.info("ssl-client.xml will be created in {}", sslDir);
- } catch (Exception e) {
- throw new AtlasException("Failed to find client configuration directory", e);
- }
- return new File(sslDir, SecurityProperties.SSL_CLIENT_PROPERTIES);
- }
-
- public static void persistSSLClientConfiguration(org.apache.commons.configuration.Configuration clientConfig)
- throws AtlasException, IOException {
- //trust settings
- Configuration configuration = new Configuration(false);
- File sslClientFile = getSSLClientFile();
- if (!sslClientFile.exists()) {
- configuration.set("ssl.client.truststore.type", "jks");
- configuration.set("ssl.client.truststore.location", clientConfig.getString(TRUSTSTORE_FILE_KEY));
- if (clientConfig.getBoolean(CLIENT_AUTH_KEY, false)) {
- // need to get client key properties
- configuration.set("ssl.client.keystore.location", clientConfig.getString(KEYSTORE_FILE_KEY));
- configuration.set("ssl.client.keystore.type", "jks");
- }
- // add the configured credential provider
- configuration.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
- clientConfig.getString(CERT_STORES_CREDENTIAL_PROVIDER_PATH));
- String hostnameVerifier = clientConfig.getString(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY);
- if (hostnameVerifier != null) {
- configuration.set(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, hostnameVerifier);
- }
-
- configuration.writeXml(new FileWriter(sslClientFile));
- }
- }
-
- public static URLConnectionClientHandler getUrlConnectionClientHandler() {
- return new URLConnectionClientHandler(new HttpURLConnectionFactory() {
- @Override
- public HttpURLConnection getHttpURLConnection(URL url)
- throws IOException {
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-
- if (connection instanceof HttpsURLConnection) {
- LOG.debug("Attempting to configure HTTPS connection using client "
- + "configuration");
- final SSLFactory factory;
- final SSLSocketFactory sf;
- final HostnameVerifier hv;
-
- try {
- Configuration conf = new Configuration();
- conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, SecurityProperties.SSL_CLIENT_PROPERTIES));
- UserGroupInformation.setConfiguration(conf);
-
- HttpsURLConnection c = (HttpsURLConnection) connection;
- factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
- factory.init();
- sf = factory.createSSLSocketFactory();
- hv = factory.getHostnameVerifier();
- c.setSSLSocketFactory(sf);
- c.setHostnameVerifier(hv);
- } catch (Exception e) {
- LOG.info("Unable to configure HTTPS connection from "
- + "configuration. Leveraging JDK properties.");
- }
- }
- return connection;
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/test/java/org/apache/atlas/AtlasClientTest.java
----------------------------------------------------------------------
diff --git a/client/src/test/java/org/apache/atlas/AtlasClientTest.java b/client/src/test/java/org/apache/atlas/AtlasClientTest.java
deleted file mode 100644
index c33906a..0000000
--- a/client/src/test/java/org/apache/atlas/AtlasClientTest.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * 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;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import org.apache.atlas.model.legacy.EntityResult;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.json.InstanceSerialization;
-import org.apache.commons.configuration.Configuration;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.codehaus.jettison.json.JSONObject;
-import org.mockito.Matchers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import java.net.ConnectException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-public class AtlasClientTest {
-
- @Mock
- private WebResource service;
- @Mock
- private WebResource.Builder resourceBuilderMock;
-
- @Mock
- private Configuration configuration;
-
- @Mock
- private Client client;
-
- @BeforeMethod
- public void setup() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void shouldVerifyServerIsReady() throws AtlasServiceException {
- setupRetryParams();
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- when(response.getEntity(String.class)).thenReturn("{\"Version\":\"version-rrelease\",\"Name\":\"apache-atlas\"," +
- "\"Description\":\"Metadata Management and Data Governance Platform over Hadoop\"}");
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
-
- assertTrue(atlasClient.isServerReady());
- }
-
- @Test
- public void testCreateEntity() throws Exception {
- setupRetryParams();
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- WebResource.Builder builder = setupBuilder(AtlasClient.API.CREATE_ENTITY, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
-
- JSONObject jsonResponse = new JSONObject(new EntityResult(Arrays.asList("id"), null, null).toString());
- when(response.getEntity(String.class)).thenReturn(jsonResponse.toString());
- when(response.getLength()).thenReturn(jsonResponse.length());
- String entityJson = InstanceSerialization.toJson(new Referenceable("type"), true);
- when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response);
-
- List<String> ids = atlasClient.createEntity(entityJson);
- assertEquals(ids.size(), 1);
- assertEquals(ids.get(0), "id");
- }
-
- private WebResource.Builder setupBuilder(AtlasClient.API api, WebResource webResource) {
- when(webResource.path(api.getPath())).thenReturn(service);
- return getBuilder(service);
- }
-
- @Test
- public void shouldReturnFalseIfServerIsNotReady() throws AtlasServiceException {
- setupRetryParams();
- AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenThrow(
- new ClientHandlerException());
- assertFalse(atlasClient.isServerReady());
- }
-
- @Test
- public void shouldReturnFalseIfServiceIsUnavailable() throws AtlasServiceException {
- setupRetryParams();
- AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
- when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.SERVICE_UNAVAILABLE);
-
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
-
- assertFalse(atlasClient.isServerReady());
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void shouldThrowErrorIfAnyResponseOtherThanServiceUnavailable() throws AtlasServiceException {
- setupRetryParams();
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
- when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.INTERNAL_SERVER_ERROR);
-
- when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
-
- atlasClient.isServerReady();
- fail("Should throw exception");
- }
-
- @Test
- public void shouldGetAdminStatus() throws AtlasServiceException {
- setupRetryParams();
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String activeStatus = "{\"Status\":\"Active\"}";
- when(response.getEntity(String.class)).thenReturn(activeStatus);
- when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
-
-// Fix after AtlasBaseClient
-// atlasClient.setService();
-
-
- String status = atlasClient.getAdminStatus();
- assertEquals(status, "Active");
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void shouldReturnStatusAsUnknownOnException() throws AtlasServiceException {
- setupRetryParams();
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
- when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.INTERNAL_SERVER_ERROR);
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
-
- String status = atlasClient.getAdminStatus();
- fail("Should fail with AtlasServiceException");
- }
-
- @Test
- public void shouldReturnStatusAsUnknownIfJSONIsInvalid() throws AtlasServiceException {
- setupRetryParams();
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- when(response.getEntity(String.class)).thenReturn("{\"status\":\"Active\"}");
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
-
- String status = atlasClient.getAdminStatus();
- assertEquals(status, AtlasClient.UNKNOWN_STATUS);
- }
-
- @Test
- public void shouldReturnBaseURLAsPassedInURL() {
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- String serviceURL = atlasClient.determineActiveServiceURL(new String[]{"http://localhost:21000"}, client);
- assertEquals(serviceURL, "http://localhost:21000");
- }
-
- @Test
- public void shouldSelectActiveAmongMultipleServersIfHAIsEnabled() {
- setupRetryParams();
-
- when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
- when(client.resource(UriBuilder.fromUri("http://localhost:41000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
- ClientResponse firstResponse = mock(ClientResponse.class);
- when(firstResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String passiveStatus = "{\"Status\":\"PASSIVE\"}";
- when(firstResponse.getEntity(String.class)).thenReturn(passiveStatus);
- when(firstResponse.getLength()).thenReturn(passiveStatus.length());
- ClientResponse secondResponse = mock(ClientResponse.class);
- when(secondResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String activeStatus = "{\"Status\":\"ACTIVE\"}";
- when(secondResponse.getEntity(String.class)).thenReturn(activeStatus);
- when(secondResponse.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
- thenReturn(firstResponse).thenReturn(firstResponse).thenReturn(firstResponse).
- thenReturn(secondResponse);
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- String serviceURL = atlasClient.determineActiveServiceURL(
- new String[]{"http://localhost:31000", "http://localhost:41000"},
- client);
- assertEquals(serviceURL, "http://localhost:41000");
- }
-
- @Test
- public void shouldRetryUntilServiceBecomesActive() {
- setupRetryParams();
-
- when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
- ClientResponse nextResponse = mock(ClientResponse.class);
- when(nextResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String activeStatus = "{\"Status\":\"ACTIVE\"}";
- when(response.getEntity(String.class)).thenReturn(activeStatus);
- when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
- thenReturn(response).thenReturn(response).thenReturn(nextResponse);
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- String serviceURL = atlasClient.determineActiveServiceURL(
- new String[] {"http://localhost:31000","http://localhost:41000"},
- client);
- assertEquals(serviceURL, "http://localhost:31000");
- }
-
- @Test
- public void shouldRetryIfCannotConnectToServiceInitially() {
- setupRetryParams();
-
- when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
- ClientResponse nextResponse = mock(ClientResponse.class);
- when(nextResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String activeStatus = "{\"Status\":\"ACTIVE\"}";
- when(response.getEntity(String.class)).thenReturn(activeStatus);
- when(response.getLength()).thenReturn(activeStatus.length());
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
- thenThrow(new ClientHandlerException("Simulating connection exception")).
- thenReturn(response).
- thenReturn(nextResponse);
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
- atlasClient.setService(service);
- atlasClient.setConfiguration(configuration);
-
- String serviceURL = atlasClient.determineActiveServiceURL(
- new String[] {"http://localhost:31000","http://localhost:41000"},
- client);
- assertEquals(serviceURL, "http://localhost:31000");
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void shouldThrowExceptionIfActiveServerIsNotFound() {
- setupRetryParams();
-
- when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
- WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service);
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
- when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).
- thenThrow(new ClientHandlerException("Simulating connection exception")).
- thenReturn(response).
- thenReturn(response);
-
- AtlasClient atlasClient = new AtlasClient(service, configuration);
-
- String serviceURL = atlasClient.determineActiveServiceURL(
- new String[] {"http://localhost:31000","http://localhost:41000"},
- client);
- assertNull(serviceURL);
- }
-
- @Test
- public void shouldRetryAPICallsOnClientHandlerException() throws AtlasServiceException, URISyntaxException {
- setupRetryParams();
-
- ResourceCreator resourceCreator = mock(ResourceCreator.class);
- WebResource resourceObject = mock(WebResource.class);
- when(resourceObject.getURI()).
- thenReturn(new URI("http://localhost:31000/api/atlas/types")).
- thenReturn(new URI("http://localhost:41000/api/atlas/types")).
- thenReturn(new URI("http://localhost:41000/api/atlas/types"));
-
- WebResource.Builder builder = getBuilder(resourceObject);
-
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String activeStatus = "{\"Status\":\"ACTIVE\"}";
- when(response.getEntity(String.class)).thenReturn(activeStatus);
- when(response.getLength()).thenReturn(activeStatus.length());
-
- when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).
- thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
- thenReturn(response);
-
- when(resourceCreator.createResource()).thenReturn(resourceObject);
-
- AtlasClient atlasClient = getClientForTest("http://localhost:31000","http://localhost:41000");
-
- atlasClient.setService(service);
- atlasClient.setConfiguration(configuration);
-
- atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
-
- verify(client).destroy();
- verify(client).resource(UriBuilder.fromUri("http://localhost:31000").build());
- verify(client).resource(UriBuilder.fromUri("http://localhost:41000").build());
- }
-
- @Test
- public void shouldRetryWithSameClientIfSingleAddressIsUsed() throws URISyntaxException, AtlasServiceException {
- setupRetryParams();
-
- ResourceCreator resourceCreator = mock(ResourceCreator.class);
- WebResource resourceObject = mock(WebResource.class);
- when(resourceObject.getURI()).
- thenReturn(new URI("http://localhost:31000/api/atlas/types"));
-
- WebResource.Builder builder = getBuilder(resourceObject);
-
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String activeStatus = "{\"Status\":\"ACTIVE\"}";
- when(response.getEntity(String.class)).thenReturn(activeStatus);
- when(response.getLength()).thenReturn(activeStatus.length());
-
- when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).
- thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
- thenReturn(response);
-
- when(resourceCreator.createResource()).thenReturn(resourceObject);
- when(configuration.getString("atlas.http.authentication.type", "simple")).thenReturn("simple");
-
- AtlasClient atlasClient = getClientForTest("http://localhost:31000");
-
- atlasClient.setService(resourceObject);
- atlasClient.setConfiguration(configuration);
-
- atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
-
- verify(client).destroy();
- verify(client, times(2)).resource(UriBuilder.fromUri("http://localhost:31000").build());
- }
-
- @Test
- public void shouldRetryAPICallsOnServiceUnavailable() throws AtlasServiceException, URISyntaxException {
- setupRetryParams();
-
- ResourceCreator resourceCreator = mock(ResourceCreator.class);
- WebResource resourceObject = mock(WebResource.class);
- when(resourceObject.getURI()).
- thenReturn(new URI("http://localhost:31000/api/atlas/types")).
- thenReturn(new URI("http://localhost:41000/api/atlas/types")).
- thenReturn(new URI("http://localhost:41000/api/atlas/types"));
-
- WebResource.Builder builder = getBuilder(resourceObject);
-
- ClientResponse firstResponse = mock(ClientResponse.class);
- when(firstResponse.getStatus()).thenReturn(Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
- when(firstResponse.getClientResponseStatus()).thenReturn(ClientResponse.Status.SERVICE_UNAVAILABLE);
-
- ClientResponse response = mock(ClientResponse.class);
- when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
- String activeStatus = "{\"Status\":\"ACTIVE\"}";
- when(response.getEntity(String.class)).thenReturn(activeStatus);
- when(response.getLength()).thenReturn(activeStatus.length());
-
- when(builder.method(AtlasClient.API.LIST_TYPES.getMethod(), ClientResponse.class, null)).
- thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
- thenReturn(firstResponse).
- thenReturn(response);
-
- when(resourceCreator.createResource()).thenReturn(resourceObject);
-
- AtlasClient atlasClient = getClientForTest("http://localhost:31000","http://localhost:41000");
- atlasClient.setService(resourceObject);
- atlasClient.setConfiguration(configuration);
-
- atlasClient.callAPIWithRetries(AtlasClient.API.LIST_TYPES, null, resourceCreator);
-
-
- verify(client).destroy();
- verify(client).resource(UriBuilder.fromUri("http://localhost:31000").build());
- verify(client).resource(UriBuilder.fromUri("http://localhost:41000").build());
- }
-
- private WebResource.Builder getBuilder(WebResource resourceObject) {
- when(resourceObject.getRequestBuilder()).thenReturn(resourceBuilderMock);
- when(resourceObject.path(anyString())).thenReturn(resourceObject);
- when(resourceBuilderMock.accept(AtlasBaseClient.JSON_MEDIA_TYPE)).thenReturn(resourceBuilderMock);
- when(resourceBuilderMock.type(AtlasBaseClient.JSON_MEDIA_TYPE)).thenReturn(resourceBuilderMock);
- return resourceBuilderMock;
- }
-
- private void setupRetryParams() {
- when(configuration.getInt(AtlasClient.ATLAS_CLIENT_HA_RETRIES_KEY, AtlasClient.DEFAULT_NUM_RETRIES)).
- thenReturn(3);
- when(configuration.getInt(AtlasClient.ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY,
- AtlasClient.DEFAULT_SLEEP_BETWEEN_RETRIES_MS)).
- thenReturn(1);
- }
-
- private AtlasClient getClientForTest(final String... baseUrls) {
- return new AtlasClient((UserGroupInformation)null, (String)null, baseUrls) {
- boolean firstCall = true;
- @Override
- protected String determineActiveServiceURL(String[] baseUrls, Client client) {
- String returnUrl = baseUrls[0];
- if (baseUrls.length > 1 && !firstCall) {
- returnUrl = baseUrls[1];
- }
- firstCall = false;
- return returnUrl;
- }
-
- @Override
- protected Configuration getClientProperties() {
- return configuration;
- }
-
- @Override
- protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
- return client;
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/pom.xml
----------------------------------------------------------------------
diff --git a/common/pom.xml b/common/pom.xml
index 7178bfa..c2e5da6 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -77,5 +77,10 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-intg</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/main/java/org/apache/atlas/ApplicationProperties.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/ApplicationProperties.java b/common/src/main/java/org/apache/atlas/ApplicationProperties.java
deleted file mode 100644
index a35bdfe..0000000
--- a/common/src/main/java/org/apache/atlas/ApplicationProperties.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/**
- * 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;
-
-import org.apache.atlas.security.InMemoryJAASConfiguration;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Iterator;
-
-/**
- * Application properties used by Atlas.
- */
-public final class ApplicationProperties extends PropertiesConfiguration {
- public static final String ATLAS_CONFIGURATION_DIRECTORY_PROPERTY = "atlas.conf";
-
- private static final Logger LOG = LoggerFactory.getLogger(ApplicationProperties.class);
-
- public static final String APPLICATION_PROPERTIES = "atlas-application.properties";
-
- private static volatile Configuration instance = null;
-
- private ApplicationProperties(URL url) throws ConfigurationException {
- super(url);
- }
-
- public static void forceReload() {
- if (instance != null) {
- synchronized (ApplicationProperties.class) {
- if (instance != null) {
- instance = null;
- }
- }
- }
- }
-
- public static Configuration get() throws AtlasException {
- if (instance == null) {
- synchronized (ApplicationProperties.class) {
- if (instance == null) {
- instance = get(APPLICATION_PROPERTIES);
- InMemoryJAASConfiguration.init(instance);
- }
- }
- }
- return instance;
- }
-
- public static Configuration get(String fileName) throws AtlasException {
- String confLocation = System.getProperty(ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
- try {
- URL url = null;
-
- if (confLocation == null) {
- LOG.info("Looking for {} in classpath", fileName);
-
- url = ApplicationProperties.class.getClassLoader().getResource(fileName);
-
- if (url == null) {
- LOG.info("Looking for /{} in classpath", fileName);
-
- url = ApplicationProperties.class.getClassLoader().getResource("/" + fileName);
- }
- } else {
- url = new File(confLocation, fileName).toURI().toURL();
- }
-
- LOG.info("Loading {} from {}", fileName, url);
-
- Configuration configuration = new ApplicationProperties(url).interpolatedConfiguration();
- logConfiguration(configuration);
- return configuration;
- } catch (Exception e) {
- throw new AtlasException("Failed to load application properties", e);
- }
- }
-
- private static void logConfiguration(Configuration configuration) {
- if (LOG.isDebugEnabled()) {
- Iterator<String> keys = configuration.getKeys();
- LOG.debug("Configuration loaded:");
- while (keys.hasNext()) {
- String key = keys.next();
- LOG.debug("{} = {}", key, configuration.getProperty(key));
- }
- }
- }
-
- public static Configuration getSubsetConfiguration(Configuration inConf, String prefix) {
- return inConf.subset(prefix);
- }
-
- public static Class getClass(Configuration configuration, String propertyName, String defaultValue,
- Class assignableClass) throws AtlasException {
- try {
- String propertyValue = configuration.getString(propertyName, defaultValue);
- Class<?> clazz = Class.forName(propertyValue);
- if (assignableClass == null || assignableClass.isAssignableFrom(clazz)) {
- return clazz;
- } else {
- String message = "Class " + clazz.getName() + " specified in property " + propertyName
- + " is not assignable to class " + assignableClass.getName();
- LOG.error(message);
- throw new AtlasException(message);
- }
- } catch (Exception e) {
- throw new AtlasException(e);
- }
- }
-
- /**
- * Get the specified property as an {@link InputStream}.
- * If the property is not set, then the specified default filename
- * is searched for in the following locations, in order of precedence:
- * 1. Atlas configuration directory specified by the {@link #ATLAS_CONFIGURATION_DIRECTORY_PROPERTY} system property
- * 2. relative to the working directory if {@link #ATLAS_CONFIGURATION_DIRECTORY_PROPERTY} is not set
- * 3. as a classloader resource
- *
- * @param configuration
- * @param propertyName
- * @param defaultFileName name of file to use by default if specified property is not set in the configuration- if null,
- * an {@link AtlasException} is thrown if the property is not set
- * @return an {@link InputStream}
- * @throws AtlasException if no file was found or if there was an error loading the file
- */
- public static InputStream getFileAsInputStream(Configuration configuration, String propertyName, String defaultFileName) throws AtlasException {
- File fileToLoad = null;
- String fileName = configuration.getString(propertyName);
- if (fileName == null) {
- if (defaultFileName == null) {
- throw new AtlasException(propertyName + " property not set and no default value specified");
- }
- fileName = defaultFileName;
- String atlasConfDir = System.getProperty(ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
- if (atlasConfDir != null) {
- // Look for default filename in Atlas config directory
- fileToLoad = new File(atlasConfDir, fileName);
- }
- else {
- // Look for default filename under the working directory
- fileToLoad = new File(fileName);
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("{} property not set - defaulting to {}", propertyName, fileToLoad.getPath());
- }
- }
- else {
- // Look for configured filename
- fileToLoad = new File(fileName);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Using {} property setting: {}", propertyName, fileToLoad.getPath());
- }
- }
-
- InputStream inStr = null;
- if (fileToLoad.exists()) {
- try {
- inStr = new FileInputStream(fileToLoad);
- } catch (FileNotFoundException e) {
- throw new AtlasException("Error loading file " + fileName, e);
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Loaded file from : {}", fileToLoad.getPath());
- }
- }
- else {
- // Look for file as class loader resource
- inStr = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
- if (inStr == null) {
- String msg = fileName + " not found in file system or as class loader resource";
- LOG.error(msg);
- throw new AtlasException(msg);
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Loaded {} as resource from : {}", fileName, Thread.currentThread().getContextClassLoader().getResource(fileName).toString());
- }
- }
- return inStr;
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/main/java/org/apache/atlas/AtlasException.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/AtlasException.java b/common/src/main/java/org/apache/atlas/AtlasException.java
deleted file mode 100644
index 45d91d4..0000000
--- a/common/src/main/java/org/apache/atlas/AtlasException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * 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;
-
-/**
- * Base Exception class for Atlas API.
- */
-public class AtlasException extends Exception {
-
- public AtlasException() {
- }
-
- public AtlasException(String message) {
- super(message);
- }
-
- public AtlasException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public AtlasException(Throwable cause) {
- super(cause);
- }
-
- public AtlasException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java b/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java
index a6e1689..fff104b 100644
--- a/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java
+++ b/common/src/main/java/org/apache/atlas/groovy/ArithmeticExpression.java
@@ -17,10 +17,10 @@
*/
package org.apache.atlas.groovy;
-import java.util.List;
-
import org.apache.atlas.AtlasException;
+import java.util.List;
+
/**
* Represents an arithmetic expression such as a+b.
*/
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java b/common/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java
deleted file mode 100644
index 936311b..0000000
--- a/common/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java
+++ /dev/null
@@ -1,401 +0,0 @@
-/**
- * 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.security;
-
-import org.apache.atlas.AtlasException;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.configuration.ConfigurationConverter;
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.hadoop.security.SecurityUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.SortedSet;
-import java.util.StringTokenizer;
-import java.util.TreeSet;
-
-
-/**
- * InMemoryJAASConfiguration
- * <p>
- * An utility class - which has a static method init to load all JAAS configuration from Application
- * properties file (eg: atlas.properties) and set it as part of the default lookup configuration for
- * all JAAS configuration lookup.
- * <p>
- * Example settings in jaas-application.properties:
- *
- * <pre class=code>
- * atlas.jaas.KafkaClient.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
- * atlas.jaas.KafkaClient.loginModuleControlFlag = required
- * atlas.jaas.KafkaClient.option.useKeyTab = true
- * atlas.jaas.KafkaClient.option.storeKey = true
- * atlas.jaas.KafkaClient.option.serviceName = kafka
- * atlas.jaas.KafkaClient.option.keyTab = /etc/security/keytabs/kafka_client.keytab
- * atlas.jaas.KafkaClient.option.principal = kafka-client-1@EXAMPLE.COM
-
- * atlas.jaas.MyClient.0.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
- * atlas.jaas.MyClient.0.loginModuleControlFlag = required
- * atlas.jaas.MyClient.0.option.useKeyTab = true
- * atlas.jaas.MyClient.0.option.storeKey = true
- * atlas.jaas.MyClient.0.option.serviceName = kafka
- * atlas.jaas.MyClient.0.option.keyTab = /etc/security/keytabs/kafka_client.keytab
- * atlas.jaas.MyClient.0.option.principal = kafka-client-1@EXAMPLE.COM
- * atlas.jaas.MyClient.1.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
- * atlas.jaas.MyClient.1.loginModuleControlFlag = optional
- * atlas.jaas.MyClient.1.option.useKeyTab = true
- * atlas.jaas.MyClient.1.option.storeKey = true
- * atlas.jaas.MyClient.1.option.serviceName = kafka
- * atlas.jaas.MyClient.1.option.keyTab = /etc/security/keytabs/kafka_client.keytab
- * atlas.jaas.MyClient.1.option.principal = kafka-client-1@EXAMPLE.COM </pre>
- *
- * <p>
- * This will set the JAAS configuration - equivalent to the jaas.conf file entries:
- *
- * <pre class=code>
- * KafkaClient {
- * com.sun.security.auth.module.Krb5LoginModule required
- * useKeyTab=true
- * storeKey=true
- * serviceName=kafka
- * keyTab="/etc/security/keytabs/kafka_client.keytab"
- * principal="kafka-client-1@EXAMPLE.COM";
- * };
- * MyClient {
- * com.sun.security.auth.module.Krb5LoginModule required
- * useKeyTab=true
- * storeKey=true
- * serviceName=kafka keyTab="/etc/security/keytabs/kafka_client.keytab"
- * principal="kafka-client-1@EXAMPLE.COM";
- * };
- * MyClient {
- * com.sun.security.auth.module.Krb5LoginModule optional
- * useKeyTab=true
- * storeKey=true
- * serviceName=kafka
- * keyTab="/etc/security/keytabs/kafka_client.keytab"
- * principal="kafka-client-1@EXAMPLE.COM";
- * }; </pre>
- * <p>
- * Here is the syntax for atlas.properties to add JAAS configuration:
- * <p>
- * The property name has to begin with 'atlas.jaas.' + clientId (in case of Kafka client,
- * it expects the clientId to be KafkaClient).
- * <p>
- * The following property must be there to specify the JAAS loginModule name
- * <pre> 'atlas.jaas.' + clientId + '.loginModuleName' </pre>
- * <p>
- * The following optional property should be set to specify the loginModuleControlFlag
- * <pre> 'atlas.jaas.' + clientId + '.loginModuleControlFlag'
- * Default value : required , Possible values: required, optional, sufficient, requisite </pre>
- * <p>
- * Then you can add additional optional parameters as options for the configuration using the following
- * syntax:
- * <pre> 'atlas.jaas.' + clientId + '.option.' + <optionName> = <optionValue> </pre>
- * <p>
- * The current setup will lookup JAAS configration from the atlas-application.properties first,
- * if not available, it will delegate to the original configuration
- *
- */
-
-
-public final class InMemoryJAASConfiguration extends Configuration {
-
- private static final Logger LOG = LoggerFactory.getLogger(InMemoryJAASConfiguration.class);
-
- private static final String JAAS_CONFIG_PREFIX_PARAM = "atlas.jaas.";
- private static final String JAAS_CONFIG_LOGIN_MODULE_NAME_PARAM = "loginModuleName";
- private static final String JAAS_CONFIG_LOGIN_MODULE_CONTROL_FLAG_PARAM = "loginModuleControlFlag";
- private static final String JAAS_CONFIG_LOGIN_OPTIONS_PREFIX = "option";
- private static final String JAAS_PRINCIPAL_PROP = "principal";
- private static final Map<String, String> CONFIG_SECTION_REDIRECTS = new HashMap<>();
-
- private Configuration parent = null;
- private Map<String, List<AppConfigurationEntry>> applicationConfigEntryMap = new HashMap<>();
-
- public static void init(String propFile) throws AtlasException {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> InMemoryJAASConfiguration.init({})", propFile);
- }
-
- InputStream in = null;
-
- try {
- Properties properties = new Properties();
- in = ClassLoader.getSystemResourceAsStream(propFile);
- if (in == null) {
- if (!propFile.startsWith("/")) {
- in = ClassLoader.getSystemResourceAsStream("/" + propFile);
- }
- if (in == null) {
- in = new FileInputStream(new File(propFile));
- }
- }
- properties.load(in);
- init(properties);
- } catch (IOException e) {
- throw new AtlasException("Failed to load JAAS application properties", e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (Exception exception) {
- // Ignore
- }
- }
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== InMemoryJAASConfiguration.init({})", propFile);
- }
- }
-
- public static void init(org.apache.commons.configuration.Configuration atlasConfiguration) throws AtlasException {
- LOG.debug("==> InMemoryJAASConfiguration.init()");
-
- if (atlasConfiguration != null && !atlasConfiguration.isEmpty()) {
- Properties properties = ConfigurationConverter.getProperties(atlasConfiguration);
- init(properties);
- } else {
- throw new AtlasException("Failed to load JAAS application properties: configuration NULL or empty!");
- }
-
- LOG.debug("<== InMemoryJAASConfiguration.init()");
- }
-
- public static void init(Properties properties) throws AtlasException {
- LOG.debug("==> InMemoryJAASConfiguration.init()");
-
- if (properties != null && MapUtils.isNotEmpty(properties)) {
- InMemoryJAASConfiguration conf = new InMemoryJAASConfiguration(properties);
- Configuration.setConfiguration(conf);
- } else {
- throw new AtlasException("Failed to load JAAS application properties: properties NULL or empty!");
- }
-
- LOG.debug("<== InMemoryJAASConfiguration.init()");
- }
-
- @Override
- public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("==> InMemoryJAASConfiguration.getAppConfigurationEntry({})", name);
- }
-
- AppConfigurationEntry[] ret = null;
- List<AppConfigurationEntry> retList = null;
- String redirectedName = getConfigSectionRedirect(name);
-
- if (redirectedName != null) {
- retList = applicationConfigEntryMap.get(redirectedName);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("Redirected jaasConfigSection ({} -> {}): ", name, redirectedName, retList);
- }
- }
-
- if (retList == null || retList.size() == 0) {
- retList = applicationConfigEntryMap.get(name);
- }
-
- if (retList == null || retList.size() == 0) {
- if (parent != null) {
- ret = parent.getAppConfigurationEntry(name);
- }
- } else {
- int sz = retList.size();
- ret = new AppConfigurationEntry[sz];
- ret = retList.toArray(ret);
- }
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("<== InMemoryJAASConfiguration.getAppConfigurationEntry({}): {}", name, ArrayUtils.toString(ret));
- }
-
- return ret;
- }
-
- private InMemoryJAASConfiguration(Properties prop) {
- parent = Configuration.getConfiguration();
- initialize(prop);
- }
-
- private void initialize(Properties properties) {
- LOG.debug("==> InMemoryJAASConfiguration.initialize()");
-
- int prefixLen = JAAS_CONFIG_PREFIX_PARAM.length();
-
- Map<String, SortedSet<Integer>> jaasClients = new HashMap<>();
- for (String key : properties.stringPropertyNames()) {
- if (key.startsWith(JAAS_CONFIG_PREFIX_PARAM)) {
- String jaasKey = key.substring(prefixLen);
- StringTokenizer tokenizer = new StringTokenizer(jaasKey, ".");
- int tokenCount = tokenizer.countTokens();
- if (tokenCount > 0) {
- String clientId = tokenizer.nextToken();
- SortedSet<Integer> indexList = jaasClients.get(clientId);
- if (indexList == null) {
- indexList = new TreeSet<>();
- jaasClients.put(clientId, indexList);
- }
- String indexStr = tokenizer.nextToken();
-
- int indexId = isNumeric(indexStr) ? Integer.parseInt(indexStr) : -1;
-
- Integer clientIdIndex = Integer.valueOf(indexId);
-
- if (!indexList.contains(clientIdIndex)) {
- indexList.add(clientIdIndex);
- }
-
- }
- }
- }
- for (String jaasClient : jaasClients.keySet()) {
-
- for (Integer index : jaasClients.get(jaasClient)) {
-
- String keyPrefix = JAAS_CONFIG_PREFIX_PARAM + jaasClient + ".";
-
- if (index > -1) {
- keyPrefix = keyPrefix + String.valueOf(index) + ".";
- }
-
- String keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_NAME_PARAM;
- String loginModuleName = properties.getProperty(keyParam);
-
- if (loginModuleName == null) {
- LOG.error("Unable to add JAAS configuration for client [{}] as it is missing param [{}]. Skipping JAAS config for [{}]", jaasClient, keyParam, jaasClient);
- continue;
- } else {
- loginModuleName = loginModuleName.trim();
- }
-
- keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_CONTROL_FLAG_PARAM;
- String controlFlag = properties.getProperty(keyParam);
-
- AppConfigurationEntry.LoginModuleControlFlag loginControlFlag = null;
- if (controlFlag != null) {
- controlFlag = controlFlag.trim().toLowerCase();
- switch (controlFlag) {
- case "optional":
- loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
- break;
- case "requisite":
- loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
- break;
- case "sufficient":
- loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
- break;
- case "required":
- loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
- break;
- default:
- String validValues = "optional|requisite|sufficient|required";
- LOG.warn("Unknown JAAS configuration value for ({}) = [{}], valid value are [{}] using the default value, REQUIRED", keyParam, controlFlag, validValues);
- loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
- break;
- }
- } else {
- LOG.warn("Unable to find JAAS configuration ({}); using the default value, REQUIRED", keyParam);
- loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
- }
-
-
- Map<String, String> options = new HashMap<>();
- String optionPrefix = keyPrefix + JAAS_CONFIG_LOGIN_OPTIONS_PREFIX + ".";
- int optionPrefixLen = optionPrefix.length();
- for (String key : properties.stringPropertyNames()) {
- if (key.startsWith(optionPrefix)) {
- String optionKey = key.substring(optionPrefixLen);
- String optionVal = properties.getProperty(key);
- if (optionVal != null) {
- optionVal = optionVal.trim();
-
- try {
- if (optionKey.equalsIgnoreCase(JAAS_PRINCIPAL_PROP)) {
- optionVal = SecurityUtil.getServerPrincipal(optionVal, (String) null);
- }
- } catch (IOException e) {
- LOG.warn("Failed to build serverPrincipal. Using provided value:[{}]", optionVal);
- }
- }
- options.put(optionKey, optionVal);
- }
- }
-
- AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName, loginControlFlag, options);
-
- if (LOG.isDebugEnabled()) {
- StringBuilder sb = new StringBuilder();
- sb.append("Adding client: [").append(jaasClient).append("{").append(index).append("}]\n");
- sb.append("\tloginModule: [").append(loginModuleName).append("]\n");
- sb.append("\tcontrolFlag: [").append(loginControlFlag).append("]\n");
- for (String key : options.keySet()) {
- String val = options.get(key);
- sb.append("\tOptions: [").append(key).append("] => [").append(val).append("]\n");
- }
- LOG.debug(sb.toString());
- }
-
- List<AppConfigurationEntry> retList = applicationConfigEntryMap.get(jaasClient);
- if (retList == null) {
- retList = new ArrayList<>();
- applicationConfigEntryMap.put(jaasClient, retList);
- }
-
- retList.add(entry);
- }
- }
-
- LOG.debug("<== InMemoryJAASConfiguration.initialize({})", applicationConfigEntryMap);
- }
-
- private static boolean isNumeric(String str) {
- return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal.
- }
-
- public static void setConfigSectionRedirect(String name, String redirectTo) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("setConfigSectionRedirect({}, {})", name, redirectTo);
- }
-
- if (name != null) {
- if (redirectTo != null) {
- CONFIG_SECTION_REDIRECTS.put(name, redirectTo);
- } else {
- CONFIG_SECTION_REDIRECTS.remove(name);
- }
- }
- }
-
- private static String getConfigSectionRedirect(String name) {
- return name != null ? CONFIG_SECTION_REDIRECTS.get(name) : null;
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/main/java/org/apache/atlas/security/SecurityProperties.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/security/SecurityProperties.java b/common/src/main/java/org/apache/atlas/security/SecurityProperties.java
deleted file mode 100644
index 2e953eb..0000000
--- a/common/src/main/java/org/apache/atlas/security/SecurityProperties.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.security;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- *
- */
-public final class SecurityProperties {
-
- private SecurityProperties() {
- }
-
- public static final String TLS_ENABLED = "atlas.enableTLS";
- public static final String KEYSTORE_FILE_KEY = "keystore.file";
- public static final String DEFAULT_KEYSTORE_FILE_LOCATION = "target/atlas.keystore";
- public static final String KEYSTORE_PASSWORD_KEY = "keystore.password";
- public static final String TRUSTSTORE_FILE_KEY = "truststore.file";
- public static final String DEFATULT_TRUSTORE_FILE_LOCATION = "target/atlas.keystore";
- public static final String TRUSTSTORE_PASSWORD_KEY = "truststore.password";
- public static final String SERVER_CERT_PASSWORD_KEY = "password";
- public static final String CLIENT_AUTH_KEY = "client.auth.enabled";
- public static final String CERT_STORES_CREDENTIAL_PROVIDER_PATH = "cert.stores.credential.provider.path";
- public static final String SSL_CLIENT_PROPERTIES = "ssl-client.xml";
- public static final String BIND_ADDRESS = "atlas.server.bind.address";
- public static final String ATLAS_SSL_EXCLUDE_CIPHER_SUITES = "atlas.ssl.exclude.cipher.suites";
- public static final List<String> DEFAULT_CIPHER_SUITES = Arrays.asList(
- ".*NULL.*", ".*RC4.*", ".*MD5.*", ".*DES.*", ".*DSS.*");
- public static final String ATLAS_SSL_EXCLUDE_PROTOCOLS = "atlas.ssl.exclude.protocols";
- public static final String[] DEFAULT_EXCLUDE_PROTOCOLS = new String[] { "TLSv1", "TLSv1.1" };
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java b/common/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java
deleted file mode 100644
index 09d8085..0000000
--- a/common/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * 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.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasException;
-import org.apache.commons.configuration.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.Console;
-
-/**
- * Util class for Authentication.
- */
-public final class AuthenticationUtil {
- private static final Logger LOG = LoggerFactory.getLogger(AuthenticationUtil.class);
-
- private AuthenticationUtil() {
- }
-
- public static boolean isKerberosAuthenticationEnabled() {
- boolean isKerberosAuthenticationEnabled = false;
- try {
- isKerberosAuthenticationEnabled = isKerberosAuthenticationEnabled(ApplicationProperties.get());
- } catch (AtlasException e) {
- LOG.error("Error while isKerberosAuthenticationEnabled ", e);
- }
- return isKerberosAuthenticationEnabled;
- }
-
- public static boolean isKerberosAuthenticationEnabled(Configuration atlasConf) {
- return atlasConf.getBoolean("atlas.authentication.method.kerberos", false);
- }
-
- public static String[] getBasicAuthenticationInput() {
- String username = null;
- String password = null;
-
- try {
- Console console = System.console();
- username = console.readLine("Enter username for atlas :- ");
-
- char[] pwdChar = console.readPassword("Enter password for atlas :- ");
- if(pwdChar != null) {
- password = new String(pwdChar);
- }
-
- } catch (Exception e) {
- System.out.print("Error while reading ");
- System.exit(1);
- }
- return new String[]{username, password};
- }
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java b/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
deleted file mode 100644
index 89e5e9b..0000000
--- a/common/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * 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;
-
-import java.io.InputStream;
-
-import org.apache.commons.configuration.Configuration;
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
-
-/**
- * Unit test for {@link ApplicationProperties}
- *
- */
-public class ApplicationPropertiesTest {
-
- @Test
- public void testGetFileAsInputStream() throws Exception {
- Configuration props = ApplicationProperties.get("test.properties");
- InputStream inStr = null;
-
- // configured file as class loader resource
- try {
- inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
- assertNotNull(inStr);
- }
- finally {
- if (inStr != null) {
- inStr.close();
- }
- }
-
- // configured file from file system path
- props.setProperty("jaas.properties.file", "src/test/resources/atlas-jaas.properties");
- try {
- inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
- assertNotNull(inStr);
- }
- finally {
- if (inStr != null) {
- inStr.close();
- }
- }
-
- // default file as class loader resource
- try {
- inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties");
- assertNotNull(inStr);
- }
- finally {
- if (inStr != null) {
- inStr.close();
- }
- }
-
- // default file relative to working directory
- try {
- inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "src/test/resources/atlas-jaas.properties");
- assertNotNull(inStr);
- }
- finally {
- if (inStr != null) {
- inStr.close();
- }
- }
-
- // default file relative to atlas configuration directory
- String originalConfDirSetting = System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, "src/test/resources");
- try {
- inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties");
- assertNotNull(inStr);
- }
- finally {
- if (inStr != null) {
- inStr.close();
- }
- if (originalConfDirSetting != null) {
- System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, originalConfDirSetting);
- }
- else {
- System.clearProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
- }
- }
-
- // non-existent property and no default file
- try {
- inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", null);
- fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
- }
- catch (AtlasException e) {
- // good
- }
- finally {
- if (inStr != null) {
- inStr.close();
- }
- }
-
- // configured file not found in file system or classpath
- props.setProperty("jaas.properties.file", "does_not_exist.txt");
- try {
- inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
- fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
- }
- catch (AtlasException e) {
- // good
- }
- finally {
- if (inStr != null) {
- inStr.close();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java b/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java
deleted file mode 100644
index b26ac7f..0000000
--- a/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * 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.security;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.apache.hadoop.util.StringUtils;
-import org.testng.annotations.Test;
-
-
-//Unstable test. Disabling
-@Test(enabled=false)
-public class InMemoryJAASConfigurationTest extends TestCase {
-
- private static final String ATLAS_JAAS_PROP_FILE = "atlas-jaas.properties";
-
- protected void setUp() throws Exception {
- super.setUp();
- try {
- InMemoryJAASConfiguration.init(ATLAS_JAAS_PROP_FILE);
- } catch(Throwable t) {
- fail("InMemoryJAASConfiguration.init() is not expected to throw Exception:" + t);
- }
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @Test(enabled=false)
- public void testGetAppConfigurationEntryStringForKafkaClient() {
- AppConfigurationEntry[] entries =
- Configuration.getConfiguration().getAppConfigurationEntry("KafkaClient");
- Assert.assertNotNull(entries);
- Assert.assertEquals(1, entries.length);
- String principal = (String) entries[0].getOptions().get("principal");
- Assert.assertNotNull(principal);
- String[] components = principal.split("[/@]");
- Assert.assertEquals(3, components.length);
- Assert.assertEquals(false, StringUtils.equalsIgnoreCase(components[1], "_HOST"));
-
- }
-
- @Test(enabled=false)
- public void testGetAppConfigurationEntryStringForMyClient() {
- AppConfigurationEntry[] entries =
- Configuration.getConfiguration().getAppConfigurationEntry("myClient");
- Assert.assertNotNull(entries);
- Assert.assertEquals(2, entries.length);
- String principal = (String) entries[0].getOptions().get("principal");
- Assert.assertNotNull(principal);
- String[] components = principal.split("[/@]");
- Assert.assertEquals(3, components.length);
- Assert.assertEquals(true, StringUtils.equalsIgnoreCase(components[1], "abcd"));
-
- principal = (String) entries[1].getOptions().get("principal");
- Assert.assertNotNull(principal);
- components = principal.split("[/@]");
- Assert.assertEquals(2, components.length);
- }
-
- @Test(enabled=false)
- public void testGetAppConfigurationEntryStringForUnknownClient() {
- AppConfigurationEntry[] entries =
- Configuration.getConfiguration().getAppConfigurationEntry("UnknownClient");
- Assert.assertNull(entries);
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java b/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java
deleted file mode 100644
index 3d8175f..0000000
--- a/common/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * 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.security;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.testng.annotations.Test;
-
-
-@Test
-public class InMemoryJAASConfigurationTicketBasedKafkaClientTest extends TestCase {
-
- private static final String ATLAS_JAAS_PROP_FILE = "atlas-jaas.properties";
-
- protected void setUp() throws Exception {
- super.setUp();
- try {
- InMemoryJAASConfiguration.init(ATLAS_JAAS_PROP_FILE);
- InMemoryJAASConfiguration.setConfigSectionRedirect("KafkaClient", "ticketBased-KafkaClient");
- } catch (Throwable t) {
- fail("InMemoryJAASConfiguration.init() is not expected to throw Exception:" + t);
- }
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-
- @Test
- public void testGetAppConfigurationEntryStringForticketBasedKafkaClient() {
-
- AppConfigurationEntry[] entries =
- Configuration.getConfiguration().getAppConfigurationEntry("KafkaClient");
- Assert.assertNotNull(entries);
- Assert.assertEquals((String) entries[0].getOptions().get("useTicketCache"), "true");
- }
-
-
-}
-
[5/7] atlas git commit: ATLAS-2179: Split Atlas client library to
avoid unnecessary dependencies
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/common/src/main/java/org/apache/atlas/security/SecureClientUtils.java
----------------------------------------------------------------------
diff --git a/client/common/src/main/java/org/apache/atlas/security/SecureClientUtils.java b/client/common/src/main/java/org/apache/atlas/security/SecureClientUtils.java
new file mode 100644
index 0000000..d5392b2
--- /dev/null
+++ b/client/common/src/main/java/org/apache/atlas/security/SecureClientUtils.java
@@ -0,0 +1,248 @@
+/*
+ * 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.security;
+
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.client.urlconnection.HttpURLConnectionFactory;
+import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
+import org.apache.atlas.AtlasException;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.alias.CredentialProviderFactory;
+import org.apache.hadoop.security.authentication.client.Authenticator;
+import org.apache.hadoop.security.authentication.client.ConnectionConfigurator;
+import org.apache.hadoop.security.ssl.SSLFactory;
+import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL;
+import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticator;
+import org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.GeneralSecurityException;
+import java.security.PrivilegedExceptionAction;
+
+import static org.apache.atlas.security.SecurityProperties.CERT_STORES_CREDENTIAL_PROVIDER_PATH;
+import static org.apache.atlas.security.SecurityProperties.CLIENT_AUTH_KEY;
+import static org.apache.atlas.security.SecurityProperties.KEYSTORE_FILE_KEY;
+import static org.apache.atlas.security.SecurityProperties.TRUSTSTORE_FILE_KEY;
+
+/**
+ *
+ */
+public class SecureClientUtils {
+
+ public final static int DEFAULT_SOCKET_TIMEOUT_IN_MSECS = 1 * 60 * 1000; // 1 minute
+ private static final Logger LOG = LoggerFactory.getLogger(SecureClientUtils.class);
+
+
+ public static URLConnectionClientHandler getClientConnectionHandler(DefaultClientConfig config,
+ org.apache.commons.configuration.Configuration clientConfig, String doAsUser,
+ final UserGroupInformation ugi) {
+ config.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
+ Configuration conf = new Configuration();
+ conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, SecurityProperties.SSL_CLIENT_PROPERTIES));
+ UserGroupInformation.setConfiguration(conf);
+ final ConnectionConfigurator connConfigurator = newConnConfigurator(conf);
+
+ Authenticator authenticator = new KerberosDelegationTokenAuthenticator();
+
+ authenticator.setConnectionConfigurator(connConfigurator);
+ final DelegationTokenAuthenticator finalAuthenticator = (DelegationTokenAuthenticator) authenticator;
+ final DelegationTokenAuthenticatedURL.Token token = new DelegationTokenAuthenticatedURL.Token();
+ HttpURLConnectionFactory httpURLConnectionFactory = null;
+ try {
+ UserGroupInformation ugiToUse = ugi != null ? ugi : UserGroupInformation.getCurrentUser();
+ final UserGroupInformation actualUgi =
+ (ugiToUse.getAuthenticationMethod() == UserGroupInformation.AuthenticationMethod.PROXY)
+ ? ugiToUse.getRealUser() : ugiToUse;
+ LOG.info("Real User: {}, is from ticket cache? {}", actualUgi, actualUgi.isLoginTicketBased());
+ if (StringUtils.isEmpty(doAsUser)) {
+ doAsUser = actualUgi.getShortUserName();
+ }
+ LOG.info("doAsUser: {}", doAsUser);
+ final String finalDoAsUser = doAsUser;
+ httpURLConnectionFactory = new HttpURLConnectionFactory() {
+ @Override
+ public HttpURLConnection getHttpURLConnection(final URL url) throws IOException {
+ try {
+ return actualUgi.doAs(new PrivilegedExceptionAction<HttpURLConnection>() {
+ @Override
+ public HttpURLConnection run() throws Exception {
+ try {
+ return new DelegationTokenAuthenticatedURL(finalAuthenticator, connConfigurator)
+ .openConnection(url, token, finalDoAsUser);
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+ });
+ } catch (Exception e) {
+ if (e instanceof IOException) {
+ throw (IOException) e;
+ } else {
+ throw new IOException(e);
+ }
+ }
+ }
+ };
+ } catch (IOException e) {
+ LOG.warn("Error obtaining user", e);
+ }
+
+ return new URLConnectionClientHandler(httpURLConnectionFactory);
+ }
+
+ private final static ConnectionConfigurator DEFAULT_TIMEOUT_CONN_CONFIGURATOR = new ConnectionConfigurator() {
+ @Override
+ public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
+ setTimeouts(conn, DEFAULT_SOCKET_TIMEOUT_IN_MSECS);
+ return conn;
+ }
+ };
+
+ private static ConnectionConfigurator newConnConfigurator(Configuration conf) {
+ try {
+ return newSslConnConfigurator(DEFAULT_SOCKET_TIMEOUT_IN_MSECS, conf);
+ } catch (Exception e) {
+ LOG.debug("Cannot load customized ssl related configuration. " + "Fallback to system-generic settings.", e);
+ return DEFAULT_TIMEOUT_CONN_CONFIGURATOR;
+ }
+ }
+
+ private static ConnectionConfigurator newSslConnConfigurator(final int timeout, Configuration conf)
+ throws IOException, GeneralSecurityException {
+ final SSLFactory factory;
+ final SSLSocketFactory sf;
+ final HostnameVerifier hv;
+
+ factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
+ factory.init();
+ sf = factory.createSSLSocketFactory();
+ hv = factory.getHostnameVerifier();
+
+ return new ConnectionConfigurator() {
+ @Override
+ public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
+ if (conn instanceof HttpsURLConnection) {
+ HttpsURLConnection c = (HttpsURLConnection) conn;
+ c.setSSLSocketFactory(sf);
+ c.setHostnameVerifier(hv);
+ }
+ setTimeouts(conn, timeout);
+ return conn;
+ }
+ };
+ }
+
+ private static void setTimeouts(URLConnection connection, int socketTimeout) {
+ connection.setConnectTimeout(socketTimeout);
+ connection.setReadTimeout(socketTimeout);
+ }
+
+ private static File getSSLClientFile() throws AtlasException {
+ String confLocation = System.getProperty("atlas.conf");
+ File sslDir;
+ try {
+ if (confLocation == null) {
+ String persistDir = null;
+ URL resource = SecureClientUtils.class.getResource("/");
+ if (resource != null) {
+ persistDir = resource.toURI().getPath();
+ }
+ assert persistDir != null;
+ sslDir = new File(persistDir);
+ } else {
+ sslDir = new File(confLocation);
+ }
+ LOG.info("ssl-client.xml will be created in {}", sslDir);
+ } catch (Exception e) {
+ throw new AtlasException("Failed to find client configuration directory", e);
+ }
+ return new File(sslDir, SecurityProperties.SSL_CLIENT_PROPERTIES);
+ }
+
+ public static void persistSSLClientConfiguration(org.apache.commons.configuration.Configuration clientConfig)
+ throws AtlasException, IOException {
+ //trust settings
+ Configuration configuration = new Configuration(false);
+ File sslClientFile = getSSLClientFile();
+ if (!sslClientFile.exists()) {
+ configuration.set("ssl.client.truststore.type", "jks");
+ configuration.set("ssl.client.truststore.location", clientConfig.getString(TRUSTSTORE_FILE_KEY));
+ if (clientConfig.getBoolean(CLIENT_AUTH_KEY, false)) {
+ // need to get client key properties
+ configuration.set("ssl.client.keystore.location", clientConfig.getString(KEYSTORE_FILE_KEY));
+ configuration.set("ssl.client.keystore.type", "jks");
+ }
+ // add the configured credential provider
+ configuration.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
+ clientConfig.getString(CERT_STORES_CREDENTIAL_PROVIDER_PATH));
+ String hostnameVerifier = clientConfig.getString(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY);
+ if (hostnameVerifier != null) {
+ configuration.set(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, hostnameVerifier);
+ }
+
+ configuration.writeXml(new FileWriter(sslClientFile));
+ }
+ }
+
+ public static URLConnectionClientHandler getUrlConnectionClientHandler() {
+ return new URLConnectionClientHandler(new HttpURLConnectionFactory() {
+ @Override
+ public HttpURLConnection getHttpURLConnection(URL url)
+ throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ if (connection instanceof HttpsURLConnection) {
+ LOG.debug("Attempting to configure HTTPS connection using client "
+ + "configuration");
+ final SSLFactory factory;
+ final SSLSocketFactory sf;
+ final HostnameVerifier hv;
+
+ try {
+ Configuration conf = new Configuration();
+ conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, SecurityProperties.SSL_CLIENT_PROPERTIES));
+ UserGroupInformation.setConfiguration(conf);
+
+ HttpsURLConnection c = (HttpsURLConnection) connection;
+ factory = new SSLFactory(SSLFactory.Mode.CLIENT, conf);
+ factory.init();
+ sf = factory.createSSLSocketFactory();
+ hv = factory.getHostnameVerifier();
+ c.setSSLSocketFactory(sf);
+ c.setHostnameVerifier(hv);
+ } catch (Exception e) {
+ LOG.info("Unable to configure HTTPS connection from "
+ + "configuration. Leveraging JDK properties.");
+ }
+ }
+ return connection;
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 9d41176..b065833 100755
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -24,58 +24,28 @@
<groupId>org.apache.atlas</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
+
+ <!-- Sub modules -->
+ <modules>
+ <module>common</module>
+ <module>client-v1</module>
+ <module>client-v2</module>
+ </modules>
+
<artifactId>atlas-client</artifactId>
<description>Apache Atlas Client</description>
<name>Apache Atlas Client</name>
- <packaging>jar</packaging>
+ <packaging>pom</packaging>
<dependencies>
<dependency>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-typesystem</artifactId>
- </dependency>
-
- <!-- supports simple auth handler -->
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-common</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-annotations</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.hadoop</groupId>
- <artifactId>hadoop-minikdc</artifactId>
- </dependency>
-
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-client</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-typesystem</artifactId>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/assembly/all-jar.xml
----------------------------------------------------------------------
diff --git a/client/src/main/assembly/all-jar.xml b/client/src/main/assembly/all-jar.xml
new file mode 100644
index 0000000..8bc9eee
--- /dev/null
+++ b/client/src/main/assembly/all-jar.xml
@@ -0,0 +1,35 @@
+<!--
+ ~ 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.
+ -->
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>all-jar</id>
+ <formats>
+ <format>jar</format> <!-- the result is a jar file -->
+ </formats>
+
+ <includeBaseDirectory>false</includeBaseDirectory> <!-- strip the module prefixes -->
+
+ <dependencySets>
+ <dependencySet>
+ <unpack>true</unpack> <!-- unpack , then repack the jars -->
+ <useTransitiveDependencies>false</useTransitiveDependencies> <!-- do not pull in any transitive dependencies -->
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasAdminClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/AtlasAdminClient.java b/client/src/main/java/org/apache/atlas/AtlasAdminClient.java
deleted file mode 100644
index f334f6c..0000000
--- a/client/src/main/java/org/apache/atlas/AtlasAdminClient.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * 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;
-
-import org.apache.atlas.model.metrics.AtlasMetrics;
-import org.apache.atlas.type.AtlasType;
-import org.apache.atlas.utils.AuthenticationUtil;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.configuration.Configuration;
-
-import java.util.Arrays;
-
-
-/**
- * An application that allows users to run admin commands against an Atlas server.
- *
- * The application uses {@link AtlasClient} to send REST requests to the Atlas server. The details of connections
- * and other configuration is specified in the Atlas properties file.
- * Exit status of the application will be as follows:
- * <li>0: successful execution</li>
- * <li>1: error in options used for the application</li>
- * <li>-1/255: application error</li>
- */
-public class AtlasAdminClient {
-
- private static final Option STATUS = new Option("status", false, "Get the status of an atlas instance");
- private static final Option STATS = new Option("stats", false, "Get the metrics of an atlas instance");
- private static final Options OPTIONS = new Options();
-
- private static final int INVALID_OPTIONS_STATUS = 1;
- private static final int PROGRAM_ERROR_STATUS = -1;
-
- static {
- OPTIONS.addOption(STATUS);
- OPTIONS.addOption(STATS);
- }
-
- public static void main(String[] args) throws AtlasException, ParseException {
- AtlasAdminClient atlasAdminClient = new AtlasAdminClient();
- int result = atlasAdminClient.run(args);
- System.exit(result);
- }
-
- private int run(String[] args) throws AtlasException {
- CommandLine commandLine = parseCommandLineOptions(args);
- Configuration configuration = ApplicationProperties.get();
- String[] atlasServerUri = configuration.getStringArray(AtlasConstants.ATLAS_REST_ADDRESS_KEY);
-
- if (atlasServerUri == null || atlasServerUri.length == 0) {
- atlasServerUri = new String[] { AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS };
- }
-
- AtlasClient atlasClient = null;
- if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
- String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput();
- atlasClient = new AtlasClient(atlasServerUri, basicAuthUsernamePassword);
- } else {
- atlasClient = new AtlasClient(atlasServerUri);
- }
- return handleCommand(commandLine, atlasServerUri, atlasClient);
- }
-
- private int handleCommand(CommandLine commandLine, String[] atlasServerUri, AtlasClient atlasClient) {
- int cmdStatus = PROGRAM_ERROR_STATUS;
- if (commandLine.hasOption(STATUS.getOpt())) {
- try {
- System.out.println(atlasClient.getAdminStatus());
- cmdStatus = 0;
- } catch (AtlasServiceException e) {
- System.err.println("Could not retrieve status of the server at " + Arrays.toString(atlasServerUri));
- printStandardHttpErrorDetails(e);
- }
- } else if (commandLine.hasOption(STATS.getOpt())) {
- try {
- AtlasMetrics atlasMetrics = atlasClient.getAtlasMetrics();
- String json = AtlasType.toJson(atlasMetrics);
- System.out.println(json);
- cmdStatus = 0;
- } catch (AtlasServiceException e) {
- System.err.println("Could not retrieve metrics of the server at " + Arrays.toString(atlasServerUri));
- printStandardHttpErrorDetails(e);
- }
- } else {
- System.err.println("Unsupported option. Refer to usage for valid options.");
- printUsage(INVALID_OPTIONS_STATUS);
- }
- return cmdStatus;
- }
-
- private void printStandardHttpErrorDetails(AtlasServiceException e) {
- System.err.println("Error details: ");
- System.err.println("HTTP Status: " + e.getStatus().getStatusCode() + ","
- + e.getStatus().getReasonPhrase());
- System.err.println("Exception message: " + e.getMessage());
- }
-
- private CommandLine parseCommandLineOptions(String[] args) {
- if (args.length == 0) {
- printUsage(INVALID_OPTIONS_STATUS);
- }
- CommandLineParser parser = new GnuParser();
- CommandLine commandLine = null;
- try {
- commandLine = parser.parse(OPTIONS, args);
- } catch (ParseException e) {
- System.err.println("Could not parse command line options.");
- printUsage(INVALID_OPTIONS_STATUS);
- }
- return commandLine;
- }
-
- private void printUsage(int statusCode) {
- HelpFormatter helpFormatter = new HelpFormatter();
- helpFormatter.printHelp("atlas_admin.py", OPTIONS);
- System.exit(statusCode);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasBaseClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/AtlasBaseClient.java b/client/src/main/java/org/apache/atlas/AtlasBaseClient.java
deleted file mode 100644
index 602831a..0000000
--- a/client/src/main/java/org/apache/atlas/AtlasBaseClient.java
+++ /dev/null
@@ -1,620 +0,0 @@
-/**
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.GenericType;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
-import com.sun.jersey.api.json.JSONConfiguration;
-import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
-import org.apache.atlas.model.metrics.AtlasMetrics;
-import org.apache.atlas.security.SecureClientUtils;
-import org.apache.atlas.utils.AuthenticationUtil;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED;
-
-public abstract class AtlasBaseClient {
- public static final String BASE_URI = "api/atlas/";
- public static final String TYPES = "types";
- public static final String ADMIN_VERSION = "admin/version";
- public static final String ADMIN_STATUS = "admin/status";
- public static final String ADMIN_METRICS = "admin/metrics";
- public static final String HTTP_AUTHENTICATION_ENABLED = "atlas.http.authentication.enabled";
- //Admin operations
- public static final APIInfo VERSION = new APIInfo(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK);
- public static final APIInfo STATUS = new APIInfo(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK);
- public static final APIInfo METRICS = new APIInfo(BASE_URI + ADMIN_METRICS, HttpMethod.GET, Response.Status.OK);
- static final String JSON_MEDIA_TYPE = MediaType.APPLICATION_JSON + "; charset=UTF-8";
- static final String UNKNOWN_STATUS = "Unknown status";
- static final String ATLAS_CLIENT_HA_RETRIES_KEY = "atlas.client.ha.retries";
- // Setting the default value based on testing failovers while client code like quickstart is running.
- static final int DEFAULT_NUM_RETRIES = 4;
- static final String ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY = "atlas.client.ha.sleep.interval.ms";
- // Setting the default value based on testing failovers while client code like quickstart is running.
- // With number of retries, this gives a total time of about 20s for the server to start.
- static final int DEFAULT_SLEEP_BETWEEN_RETRIES_MS = 5000;
- private static final Logger LOG = LoggerFactory.getLogger(AtlasBaseClient.class);
- protected WebResource service;
- protected Configuration configuration;
- private String basicAuthUser;
- private String basicAuthPassword;
- private AtlasClientContext atlasClientContext;
- private boolean retryEnabled = false;
- private Cookie cookie = null;
-
- protected AtlasBaseClient() {
- }
-
- protected AtlasBaseClient(String[] baseUrl, String[] basicAuthUserNamePassword) {
- if (basicAuthUserNamePassword != null) {
- if (basicAuthUserNamePassword.length > 0) {
- this.basicAuthUser = basicAuthUserNamePassword[0];
- }
- if (basicAuthUserNamePassword.length > 1) {
- this.basicAuthPassword = basicAuthUserNamePassword[1];
- }
- }
-
- initializeState(baseUrl, null, null);
- }
-
- protected AtlasBaseClient(String... baseUrls) throws AtlasException {
- this(getCurrentUGI(), baseUrls);
- }
-
- protected AtlasBaseClient(UserGroupInformation ugi, String[] baseUrls) {
- this(ugi, ugi.getShortUserName(), baseUrls);
- }
-
- protected AtlasBaseClient(UserGroupInformation ugi, String doAsUser, String[] baseUrls) {
- initializeState(baseUrls, ugi, doAsUser);
- }
-
- protected AtlasBaseClient(String[] baseUrls, Cookie cookie) {
- this.cookie = cookie;
- initializeState(baseUrls, null, null);
- }
-
- @VisibleForTesting
- protected AtlasBaseClient(WebResource service, Configuration configuration) {
- this.service = service;
- this.configuration = configuration;
- }
-
- @VisibleForTesting
- protected AtlasBaseClient(Configuration configuration, String[] baseUrl, String[] basicAuthUserNamePassword) {
- if (basicAuthUserNamePassword != null) {
- if (basicAuthUserNamePassword.length > 0) {
- this.basicAuthUser = basicAuthUserNamePassword[0];
- }
- if (basicAuthUserNamePassword.length > 1) {
- this.basicAuthPassword = basicAuthUserNamePassword[1];
- }
- }
-
- initializeState(configuration, baseUrl, null, null);
- }
-
- public void setCookie(Cookie cookie) {
- this.cookie = cookie;
- }
-
- protected static UserGroupInformation getCurrentUGI() throws AtlasException {
- try {
- return UserGroupInformation.getCurrentUser();
- } catch (IOException e) {
- throw new AtlasException(e);
- }
- }
-
- void initializeState(String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
- initializeState(getClientProperties(), baseUrls, ugi, doAsUser);
- }
-
- void initializeState(Configuration configuration, String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
- this.configuration = configuration;
- Client client = getClient(configuration, ugi, doAsUser);
-
- if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
- final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(basicAuthUser, basicAuthPassword);
- client.addFilter(authFilter);
- }
-
- String activeServiceUrl = determineActiveServiceURL(baseUrls, client);
- atlasClientContext = new AtlasClientContext(baseUrls, client, ugi, doAsUser);
- service = client.resource(UriBuilder.fromUri(activeServiceUrl).build());
- }
-
- @VisibleForTesting
- protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
- DefaultClientConfig config = new DefaultClientConfig();
- // Enable POJO mapping feature
- config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000);
- int connectTimeout = configuration.getInt("atlas.client.connectTimeoutMSecs", 60000);
- if (configuration.getBoolean(TLS_ENABLED, false)) {
- // create an SSL properties configuration if one doesn't exist. SSLFactory expects a file, so forced
- // to create a
- // configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory
- try {
- SecureClientUtils.persistSSLClientConfiguration(configuration);
- } catch (Exception e) {
- LOG.info("Error processing client configuration.", e);
- }
- }
-
- final URLConnectionClientHandler handler;
-
- if ((AuthenticationUtil.isKerberosAuthenticationEnabled())) {
- handler = SecureClientUtils.getClientConnectionHandler(config, configuration, doAsUser, ugi);
- } else {
- if (configuration.getBoolean(TLS_ENABLED, false)) {
- handler = SecureClientUtils.getUrlConnectionClientHandler();
- } else {
- handler = new URLConnectionClientHandler();
- }
- }
- Client client = new Client(handler, config);
- client.setReadTimeout(readTimeout);
- client.setConnectTimeout(connectTimeout);
- return client;
- }
-
- @VisibleForTesting
- protected String determineActiveServiceURL(String[] baseUrls, Client client) {
- if (baseUrls.length == 0) {
- throw new IllegalArgumentException("Base URLs cannot be null or empty");
- }
- final String baseUrl;
- AtlasServerEnsemble atlasServerEnsemble = new AtlasServerEnsemble(baseUrls);
- if (atlasServerEnsemble.hasSingleInstance()) {
- baseUrl = atlasServerEnsemble.firstURL();
- LOG.info("Client has only one service URL, will use that for all actions: {}", baseUrl);
- } else {
- try {
- baseUrl = selectActiveServerAddress(client, atlasServerEnsemble);
- } catch (AtlasServiceException e) {
- LOG.error("None of the passed URLs are active: {}", atlasServerEnsemble, e);
- throw new IllegalArgumentException("None of the passed URLs are active " + atlasServerEnsemble, e);
- }
- }
- return baseUrl;
- }
-
- private String selectActiveServerAddress(Client client, AtlasServerEnsemble serverEnsemble)
- throws AtlasServiceException {
- List<String> serverInstances = serverEnsemble.getMembers();
- String activeServerAddress = null;
- for (String serverInstance : serverInstances) {
- LOG.info("Trying with address {}", serverInstance);
- activeServerAddress = getAddressIfActive(client, serverInstance);
- if (activeServerAddress != null) {
- LOG.info("Found service {} as active service.", serverInstance);
- break;
- }
- }
- if (activeServerAddress != null)
- return activeServerAddress;
- else
- throw new AtlasServiceException(STATUS, new RuntimeException("Could not find any active instance"));
- }
-
- private String getAddressIfActive(Client client, String serverInstance) {
- String activeServerAddress = null;
- for (int i = 0; i < getNumberOfRetries(); i++) {
- try {
- service = client.resource(UriBuilder.fromUri(serverInstance).build());
- String adminStatus = getAdminStatus();
- if (StringUtils.equals(adminStatus, "ACTIVE")) {
- activeServerAddress = serverInstance;
- break;
- } else {
- LOG.info("attempt #{}: Service {} - is not active. status={}", (i + 1), serverInstance, adminStatus);
- }
- } catch (Exception e) {
- LOG.error("attempt #{}: Service {} - could not get status", (i + 1), serverInstance, e);
- }
- sleepBetweenRetries();
- }
- return activeServerAddress;
- }
-
- protected Configuration getClientProperties() {
- try {
- if (configuration == null) {
- configuration = ApplicationProperties.get();
- }
- } catch (AtlasException e) {
- LOG.error("Exception while loading configuration.", e);
- }
- return configuration;
- }
-
- public boolean isServerReady() throws AtlasServiceException {
- WebResource resource = getResource(VERSION.getPath());
- try {
- callAPIWithResource(VERSION, resource, null, JSONObject.class);
- return true;
- } catch (ClientHandlerException che) {
- return false;
- } catch (AtlasServiceException ase) {
- if (ase.getStatus() != null && ase.getStatus().equals(ClientResponse.Status.SERVICE_UNAVAILABLE)) {
- LOG.warn("Received SERVICE_UNAVAILABLE, server is not yet ready");
- return false;
- }
- throw ase;
- }
- }
-
- protected WebResource getResource(String path, String... pathParams) {
- return getResource(service, path, pathParams);
- }
-
- protected <T> T callAPIWithResource(APIInfo api, WebResource resource, Object requestObject, Class<T> responseType) throws AtlasServiceException {
- GenericType<T> genericType = null;
- if (responseType != null) {
- genericType = new GenericType<>(responseType);
- }
- return callAPIWithResource(api, resource, requestObject, genericType);
- }
-
- protected <T> T callAPIWithResource(APIInfo api, WebResource resource, Object requestObject, GenericType<T> responseType) throws AtlasServiceException {
- ClientResponse clientResponse = null;
- int i = 0;
- do {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Calling API [ {} : {} ] {}", api.getMethod(), api.getPath(), requestObject != null ? "<== " + requestObject : "");
- }
-
- WebResource.Builder requestBuilder = resource.getRequestBuilder();
-
- // Set content headers
- requestBuilder
- .accept(JSON_MEDIA_TYPE)
- .type(JSON_MEDIA_TYPE);
-
- // Set cookie if present
- if (cookie != null) {
- requestBuilder.cookie(cookie);
- }
-
- clientResponse = requestBuilder.method(api.getMethod(), ClientResponse.class, requestObject);
-
- if (LOG.isDebugEnabled()) {
- LOG.debug("API {} returned status {}", resource.getURI(), clientResponse.getStatus());
- }
-
- if (clientResponse.getStatus() == api.getExpectedStatus().getStatusCode()) {
- if (null == responseType) {
- return null;
- }
- try {
- if (responseType.getRawClass() == JSONObject.class) {
- String stringEntity = clientResponse.getEntity(String.class);
- try {
- JSONObject jsonObject = new JSONObject(stringEntity);
- LOG.info("Response = {}", jsonObject);
- return (T) jsonObject;
- } catch (JSONException e) {
- throw new AtlasServiceException(api, e);
- }
- } else {
- T entity = clientResponse.getEntity(responseType);
- return entity;
- }
- } catch (ClientHandlerException e) {
- throw new AtlasServiceException(api, e);
- }
- } else if (clientResponse.getStatus() != ClientResponse.Status.SERVICE_UNAVAILABLE.getStatusCode()) {
- break;
- } else {
- LOG.error("Got a service unavailable when calling: {}, will retry..", resource);
- sleepBetweenRetries();
- }
-
- i++;
- } while (i < getNumberOfRetries());
-
- throw new AtlasServiceException(api, clientResponse);
- }
-
- private WebResource getResource(WebResource service, String path, String... pathParams) {
- WebResource resource = service.path(path);
- resource = appendPathParams(resource, pathParams);
- return resource;
- }
-
- void sleepBetweenRetries() {
- try {
- Thread.sleep(getSleepBetweenRetriesMs());
- } catch (InterruptedException e) {
- LOG.error("Interrupted from sleeping between retries.", e);
- }
- }
-
- int getNumberOfRetries() {
- return configuration.getInt(AtlasBaseClient.ATLAS_CLIENT_HA_RETRIES_KEY, AtlasBaseClient.DEFAULT_NUM_RETRIES);
- }
-
- private int getSleepBetweenRetriesMs() {
- return configuration.getInt(AtlasBaseClient.ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY, AtlasBaseClient.DEFAULT_SLEEP_BETWEEN_RETRIES_MS);
- }
-
- /**
- * Return status of the service instance the client is pointing to.
- *
- * @return One of the values in ServiceState.ServiceStateValue or {@link #UNKNOWN_STATUS} if
- * there is a JSON parse exception
- * @throws AtlasServiceException if there is a HTTP error.
- */
- public String getAdminStatus() throws AtlasServiceException {
- String result = AtlasBaseClient.UNKNOWN_STATUS;
- WebResource resource = getResource(service, STATUS.getPath());
- JSONObject response = callAPIWithResource(STATUS, resource, null, JSONObject.class);
- try {
- result = response.getString("Status");
- } catch (JSONException e) {
- LOG.error("Exception while parsing admin status response. Returned response {}", response.toString(), e);
- }
- return result;
- }
-
- /**
- * @return Return metrics of the service instance the client is pointing to
- * @throws AtlasServiceException
- */
- public AtlasMetrics getAtlasMetrics() throws AtlasServiceException {
- return callAPI(METRICS, AtlasMetrics.class, null);
- }
-
- boolean isRetryableException(ClientHandlerException che) {
- return che.getCause().getClass().equals(IOException.class)
- || che.getCause().getClass().equals(ConnectException.class);
- }
-
- void handleClientHandlerException(ClientHandlerException che) {
- if (isRetryableException(che)) {
- atlasClientContext.getClient().destroy();
- LOG.warn("Destroyed current context while handling ClientHandlerEception.");
- LOG.warn("Will retry and create new context.");
- sleepBetweenRetries();
- initializeState(atlasClientContext.getBaseUrls(), atlasClientContext.getUgi(),
- atlasClientContext.getDoAsUser());
- return;
- }
- throw che;
- }
-
- @VisibleForTesting
- JSONObject callAPIWithRetries(APIInfo api, Object requestObject, ResourceCreator resourceCreator)
- throws AtlasServiceException {
- for (int i = 0; i < getNumberOfRetries(); i++) {
- WebResource resource = resourceCreator.createResource();
- try {
- LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1);
- return callAPIWithResource(api, resource, requestObject, JSONObject.class);
- } catch (ClientHandlerException che) {
- if (i == (getNumberOfRetries() - 1)) {
- throw che;
- }
- LOG.warn("Handled exception in calling api {}", api.getPath(), che);
- LOG.warn("Exception's cause: {}", che.getCause().getClass());
- handleClientHandlerException(che);
- }
- }
- throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries."));
- }
-
- public <T> T callAPI(APIInfo api, Class<T> responseType, Object requestObject, String... params)
- throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
- }
-
- public <T> T callAPI(APIInfo api, GenericType<T> responseType, Object requestObject, String... params)
- throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
- }
-
-
- public <T> T callAPI(APIInfo api, Class<T> responseType, Object requestBody,
- MultivaluedMap<String, String> queryParams, String... params) throws AtlasServiceException {
- WebResource resource = getResource(api, queryParams, params);
- return callAPIWithResource(api, resource, requestBody, responseType);
- }
-
- public <T> T callAPI(APIInfo api, Class<T> responseType, MultivaluedMap<String, String> queryParams, String... params)
- throws AtlasServiceException {
- WebResource resource = getResource(api, queryParams, params);
- return callAPIWithResource(api, resource, null, responseType);
- }
-
- public <T> T callAPI(APIInfo api, GenericType<T> responseType, MultivaluedMap<String, String> queryParams, String... params)
- throws AtlasServiceException {
- WebResource resource = getResource(api, queryParams, params);
- return callAPIWithResource(api, resource, null, responseType);
- }
-
- protected WebResource getResource(APIInfo api, String... pathParams) {
- return getResource(service, api, pathParams);
- }
-
- // Modify URL to include the path params
- private WebResource getResource(WebResource service, APIInfo api, String... pathParams) {
- WebResource resource = service.path(api.getPath());
- resource = appendPathParams(resource, pathParams);
- return resource;
- }
-
- public <T> T callAPI(APIInfo api, Class<T> responseType, MultivaluedMap<String, String> queryParams)
- throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, queryParams), null, responseType);
- }
-
- public <T> T callAPI(APIInfo api, Class<T> responseType, String queryParamKey, List<String> queryParamValues)
- throws AtlasServiceException {
- return callAPIWithResource(api, getResource(api, queryParamKey, queryParamValues), null, responseType);
- }
-
- private WebResource getResource(APIInfo api, String queryParamKey, List<String> queryParamValues) {
- WebResource resource = service.path(api.getPath());
- for (String queryParamValue : queryParamValues) {
- if (StringUtils.isNotBlank(queryParamKey) && StringUtils.isNotBlank(queryParamValue)) {
- resource = resource.queryParam(queryParamKey, queryParamValue);
- }
- }
- return resource;
- }
-
- protected WebResource getResource(APIInfo api, MultivaluedMap<String, String> queryParams, String... pathParams) {
- WebResource resource = service.path(api.getPath());
- resource = appendPathParams(resource, pathParams);
- resource = appendQueryParams(queryParams, resource);
- return resource;
- }
-
- private WebResource appendPathParams(WebResource resource, String[] pathParams) {
- if (pathParams != null) {
- for (String pathParam : pathParams) {
- resource = resource.path(pathParam);
- }
- }
- return resource;
- }
-
- protected WebResource getResource(APIInfo api, MultivaluedMap<String, String> queryParams) {
- return getResource(service, api, queryParams);
- }
-
- // Modify URL to include the query params
- private WebResource getResource(WebResource service, APIInfo api, MultivaluedMap<String, String> queryParams) {
- WebResource resource = service.path(api.getPath());
- resource = appendQueryParams(queryParams, resource);
- return resource;
- }
-
- private WebResource appendQueryParams(MultivaluedMap<String, String> queryParams, WebResource resource) {
- if (null != queryParams && !queryParams.isEmpty()) {
- for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
- for (String value : entry.getValue()) {
- if (StringUtils.isNotBlank(value)) {
- resource = resource.queryParam(entry.getKey(), value);
- }
- }
- }
- }
- return resource;
- }
-
- protected APIInfo updatePathParameters(APIInfo apiInfo, String... params) {
- return new APIInfo(String.format(apiInfo.getPath(), params), apiInfo.getMethod(), apiInfo.getExpectedStatus());
- }
-
- @VisibleForTesting
- void setConfiguration(Configuration configuration) {
- this.configuration = configuration;
- }
-
- @VisibleForTesting
- void setService(WebResource resource) {
- this.service = resource;
- }
-
-
- public static class APIInfo {
- private final String method;
- private final String path;
- private final Response.Status status;
-
- public APIInfo(String path, String method, Response.Status status) {
- this.path = path;
- this.method = method;
- this.status = status;
- }
-
- public String getMethod() {
- return method;
- }
-
- public String getPath() {
- return path;
- }
-
- public Response.Status getExpectedStatus() {
- return status;
- }
- }
-
- /**
- * A class to capture input state while creating the client.
- *
- * The information here will be reused when the client is re-initialized on switch-over
- * in case of High Availability.
- */
- private class AtlasClientContext {
- private String[] baseUrls;
- private Client client;
- private String doAsUser;
- private UserGroupInformation ugi;
-
- public AtlasClientContext(String[] baseUrls, Client client, UserGroupInformation ugi, String doAsUser) {
- this.baseUrls = baseUrls;
- this.client = client;
- this.ugi = ugi;
- this.doAsUser = doAsUser;
- }
-
- public Client getClient() {
- return client;
- }
-
- public String[] getBaseUrls() {
- return baseUrls;
- }
-
- public String getDoAsUser() {
- return doAsUser;
- }
-
- public UserGroupInformation getUgi() {
- return ugi;
- }
- }
-}
[4/7] atlas git commit: ATLAS-2179: Split Atlas client library to
avoid unnecessary dependencies
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasClient.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/AtlasClient.java b/client/src/main/java/org/apache/atlas/AtlasClient.java
deleted file mode 100755
index 5fa5df7..0000000
--- a/client/src/main/java/org/apache/atlas/AtlasClient.java
+++ /dev/null
@@ -1,962 +0,0 @@
-/**
- * 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;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableSet;
-import com.sun.jersey.api.client.WebResource;
-import org.apache.atlas.model.legacy.EntityResult;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.Struct;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.json.InstanceSerialization;
-import org.apache.atlas.typesystem.json.TypesSerialization;
-import org.apache.atlas.typesystem.types.AttributeDefinition;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Client for metadata.
- */
-@Deprecated
-public class AtlasClient extends AtlasBaseClient {
- private static final Logger LOG = LoggerFactory.getLogger(AtlasClient.class);
-
- public static final String TYPE = "type";
- public static final String TYPENAME = "typeName";
- public static final String GUID = "GUID";
- public static final String ENTITIES = "entities";
- public static final String GUID_ASSIGNMENTS = "guidAssignments";
-
- public static final String DEFINITION = "definition";
- public static final String ERROR = "error";
- public static final String STACKTRACE = "stackTrace";
- public static final String REQUEST_ID = "requestId";
- public static final String RESULTS = "results";
- public static final String COUNT = "count";
- public static final String ROWS = "rows";
- public static final String DATATYPE = "dataType";
- public static final String STATUS = "Status";
-
- public static final String EVENTS = "events";
- public static final String START_KEY = "startKey";
- public static final String NUM_RESULTS = "count";
-
- public static final String URI_ENTITY = "entities";
- public static final String URI_ENTITY_AUDIT = "audit";
- public static final String URI_SEARCH = "discovery/search";
- public static final String URI_NAME_LINEAGE = "lineage/hive/table";
- public static final String URI_LINEAGE = "lineage/";
- public static final String URI_TRAITS = "traits";
- public static final String TRAITS = "traits";
- public static final String TRAIT_DEFINITIONS = "traitDefinitions";
-
-
- public static final String QUERY = "query";
- public static final String LIMIT = "limit";
- public static final String OFFSET = "offset";
- public static final String QUERY_TYPE = "queryType";
- public static final String ATTRIBUTE_NAME = "property";
- public static final String ATTRIBUTE_VALUE = "value";
-
- public static final String SUPERTYPE = "supertype";
- public static final String NOT_SUPERTYPE = "notsupertype";
-
- public static final String ASSET_TYPE = "Asset";
- public static final String NAME = "name";
- public static final String DESCRIPTION = "description";
- public static final String OWNER = "owner";
- public static final String CREATE_TIME = "createTime";
-
- public static final String INFRASTRUCTURE_SUPER_TYPE = "Infrastructure";
- public static final String DATA_SET_SUPER_TYPE = "DataSet";
- public static final String PROCESS_SUPER_TYPE = "Process";
- public static final String PROCESS_ATTRIBUTE_INPUTS = "inputs";
- public static final String PROCESS_ATTRIBUTE_OUTPUTS = "outputs";
-
- public static final String REFERENCEABLE_SUPER_TYPE = "Referenceable";
- public static final String QUALIFIED_NAME = "qualifiedName";
- public static final String REFERENCEABLE_ATTRIBUTE_NAME = QUALIFIED_NAME;
-
- public static final String UNKNOWN_STATUS = "Unknown status";
-
- /**
- * Constructor for AtlasClient with cookie params as header
- * @param baseUrl
- * @param cookieName
- * @param value
- * @param path
- * @param domain
- */
-
- public AtlasClient(String[] baseUrl, String cookieName, String value, String path, String domain) {
- super(baseUrl, new Cookie( cookieName, value, path, domain));
- }
-
- /**
- * Constructor for AtlasClient with cookie as header
- * @param baseUrl
- * @param cookie
- */
-
- public AtlasClient(String[] baseUrl, Cookie cookie) {
- super(baseUrl, cookie);
- }
-
-
- // New constructor for Basic auth
- public AtlasClient(String[] baseUrl, String[] basicAuthUserNamePassword) {
- super(baseUrl, basicAuthUserNamePassword);
- }
-
- /**
- * Create a new Atlas client.
- * @param baseUrls A list of URLs that point to an ensemble of Atlas servers working in
- * High Availability mode. The client will automatically determine the
- * active instance on startup and also when there is a scenario of
- * failover.
- */
- public AtlasClient(String... baseUrls) throws AtlasException {
- this(getCurrentUGI(), baseUrls);
- }
-
- /**
- * Create a new Atlas client.
- * @param ugi UserGroupInformation
- * @param doAsUser
- * @param baseUrls A list of URLs that point to an ensemble of Atlas servers working in
- * High Availability mode. The client will automatically determine the
- * active instance on startup and also when there is a scenario of
- * failover.
- */
- public AtlasClient(UserGroupInformation ugi, String doAsUser, String... baseUrls) {
- initializeState(baseUrls, ugi, doAsUser);
- }
-
- private AtlasClient(UserGroupInformation ugi, String[] baseUrls) {
- this(ugi, ugi.getShortUserName(), baseUrls);
- }
-
- //Used by LocalAtlasClient
- protected AtlasClient() {
- //Do nothing
- }
-
- @VisibleForTesting
- public AtlasClient(Configuration configuration, String[] baseUrl, String[] basicAuthUserNamePassword) {
- super(configuration, baseUrl, basicAuthUserNamePassword);
- }
-
- @VisibleForTesting
- public AtlasClient(Configuration configuration, String... baseUrls) throws AtlasException {
- initializeState(configuration, baseUrls, getCurrentUGI(), getCurrentUGI().getShortUserName());
- }
-
- @VisibleForTesting
- AtlasClient(WebResource service, Configuration configuration) {
- super(service, configuration);
- }
-
- public WebResource getResource() {
- return service;
- }
-
- public enum API {
-
- //Admin operations
- VERSION(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK),
- STATUS(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK),
-
- //Type operations
- CREATE_TYPE(BASE_URI + TYPES, HttpMethod.POST, Response.Status.CREATED),
- UPDATE_TYPE(BASE_URI + TYPES, HttpMethod.PUT, Response.Status.OK),
- GET_TYPE(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK),
- LIST_TYPES(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK),
- LIST_TRAIT_TYPES(BASE_URI + TYPES + "?type=trait", HttpMethod.GET, Response.Status.OK),
-
- //Entity operations
- CREATE_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED),
- GET_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- UPDATE_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.PUT, Response.Status.OK),
- UPDATE_ENTITY_PARTIAL(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.OK),
- LIST_ENTITIES(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- DELETE_ENTITIES(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK),
- DELETE_ENTITY(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK),
-
- //audit operation
- LIST_ENTITY_AUDIT(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
-
- //Trait operations
- ADD_TRAITS(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED),
- DELETE_TRAITS(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK),
- LIST_TRAITS(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- GET_ALL_TRAIT_DEFINITIONS(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
- GET_TRAIT_DEFINITION(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK),
-
- //Search operations
- SEARCH(BASE_URI + URI_SEARCH, HttpMethod.GET, Response.Status.OK),
- SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET, Response.Status.OK),
- SEARCH_FULL_TEXT(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET, Response.Status.OK),
-
- GREMLIN_SEARCH(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET, Response.Status.OK),
-
- //Lineage operations based on dataset name
- NAME_LINEAGE_INPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
- NAME_LINEAGE_OUTPUTS_GRAPH(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
- NAME_LINEAGE_SCHEMA(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK),
-
- //Lineage operations based on entity id of the dataset
- LINEAGE_INPUTS_GRAPH(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK),
- LINEAGE_OUTPUTS_GRAPH(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK),
- LINEAGE_SCHEMA(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
-
- private final String method;
- private final String path;
- private final Response.Status status;
-
- API(String path, String method, Response.Status status) {
- this.path = path;
- this.method = method;
- this.status = status;
- }
-
- public String getMethod() {
- return method;
- }
-
- public String getPath() {
- return path;
- }
-
- public Response.Status getExpectedStatus() {
- return status;
- }
- }
-
- /**
- * Register the given type(meta model)
- * @param typeAsJson type definition a jaon
- * @return result json object
- * @throws AtlasServiceException
- */
- public List<String> createType(String typeAsJson) throws AtlasServiceException {
- LOG.debug("Creating type definition: {}", typeAsJson);
- JSONObject response = callAPIWithBody(API.CREATE_TYPE, typeAsJson);
- List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {
- @Override
- String extractElement(JSONObject element) throws JSONException {
- return element.getString(AtlasClient.NAME);
- }
- });
- LOG.debug("Create type definition returned results: {}", results);
- return results;
- }
-
- /**
- * Register the given type(meta model)
- * @param typeDef type definition
- * @return result json object
- * @throws AtlasServiceException
- */
- public List<String> createType(TypesDef typeDef) throws AtlasServiceException {
- return createType(TypesSerialization.toJson(typeDef));
- }
-
- /**
- * Creates trait type with specifiedName, superTraits and attributes
- * @param traitName the name of the trait type
- * @param superTraits the list of super traits from which this trait type inherits attributes
- * @param attributeDefinitions the list of attributes of the trait type
- * @return the list of types created
- * @throws AtlasServiceException
- */
- public List<String> createTraitType(String traitName, ImmutableSet<String> superTraits, AttributeDefinition... attributeDefinitions) throws AtlasServiceException {
- HierarchicalTypeDefinition<TraitType> piiTrait =
- TypesUtil.createTraitTypeDef(traitName, superTraits, attributeDefinitions);
-
- String traitDefinitionAsJSON = TypesSerialization.toJson(piiTrait, true);
- LOG.debug("Creating trait type {} {}" , traitName, traitDefinitionAsJSON);
- return createType(traitDefinitionAsJSON);
- }
-
- /**
- * Creates simple trait type with specifiedName with no superTraits or attributes
- * @param traitName the name of the trait type
- * @return the list of types created
- * @throws AtlasServiceException
- */
- public List<String> createTraitType(String traitName) throws AtlasServiceException {
- return createTraitType(traitName, null);
- }
-
- /**
- * Register the given type(meta model)
- * @param typeAsJson type definition a jaon
- * @return result json object
- * @throws AtlasServiceException
- */
- public List<String> updateType(String typeAsJson) throws AtlasServiceException {
- LOG.debug("Updating type definition: {}", typeAsJson);
- JSONObject response = callAPIWithBody(API.UPDATE_TYPE, typeAsJson);
- List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {
- @Override
- String extractElement(JSONObject element) throws JSONException {
- return element.getString(AtlasClient.NAME);
- }
- });
- LOG.debug("Update type definition returned results: {}", results);
- return results;
- }
-
- /**
- * Register the given type(meta model)
- * @param typeDef type definition
- * @return result json object
- * @throws AtlasServiceException
- */
- public List<String> updateType(TypesDef typeDef) throws AtlasServiceException {
- return updateType(TypesSerialization.toJson(typeDef));
- }
-
- /**
- * Returns all type names in the system
- * @return list of type names
- * @throws AtlasServiceException
- */
- public List<String> listTypes() throws AtlasServiceException {
- final JSONObject jsonObject = callAPIWithQueryParams(API.LIST_TYPES, null);
- return extractResults(jsonObject, AtlasClient.RESULTS, new ExtractOperation<String, String>());
- }
-
- /**
- * Returns all type names with the given category
- * @param category
- * @return list of type names
- * @throws AtlasServiceException
- */
- public List<String> listTypes(final DataTypes.TypeCategory category) throws AtlasServiceException {
- JSONObject response = callAPIWithRetries(API.LIST_TYPES, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(API.LIST_TYPES.getPath());
- resource = resource.queryParam(TYPE, category.name());
- return resource;
- }
- });
- return extractResults(response, AtlasClient.RESULTS, new ExtractOperation<String, String>());
- }
-
- /**
- * Return the list of type names in the type system which match the specified filter.
- *
- * @param category returns types whose category is the given typeCategory
- * @param superType returns types which contain the given supertype
- * @param notSupertype returns types which do not contain the given supertype
- *
- * Its possible to specify combination of these filters in one request and the conditions are combined with AND
- * For example, typeCategory = TRAIT && supertype contains 'X' && supertype !contains 'Y'
- * If there is no filter, all the types are returned
- * @return list of type names
- */
- public List<String> listTypes(final DataTypes.TypeCategory category, final String superType,
- final String notSupertype) throws AtlasServiceException {
- JSONObject response = callAPIWithRetries(API.LIST_TYPES, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(API.LIST_TYPES);
- resource = resource.queryParam(TYPE, category.name());
- resource = resource.queryParam(SUPERTYPE, superType);
- resource = resource.queryParam(NOT_SUPERTYPE, notSupertype);
- return resource;
- }
- });
- return extractResults(response, AtlasClient.RESULTS, new ExtractOperation<String, String>());
- }
-
- public TypesDef getType(String typeName) throws AtlasServiceException {
- try {
- JSONObject response = callAPIWithBodyAndParams(API.GET_TYPE, null, typeName);
- String typeJson = response.getString(DEFINITION);
- return TypesSerialization.fromJson(typeJson);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- /**
- * Create the given entity
- * @param entities entity(type instance) as json
- * @return json array of guids
- * @throws AtlasServiceException
- */
- protected List<String> createEntity(JSONArray entities) throws AtlasServiceException {
- LOG.debug("Creating entities: {}", entities);
- JSONObject response = callAPIWithBody(API.CREATE_ENTITY, entities.toString());
- List<String> results = extractEntityResult(response).getCreatedEntities();
- LOG.debug("Create entities returned results: {}", results);
- return results;
- }
-
- protected EntityResult extractEntityResult(JSONObject response) throws AtlasServiceException {
- return EntityResult.fromString(response.toString());
- }
-
- /**
- * Create the given entity
- * @param entitiesAsJson entity(type instance) as json
- * @return json array of guids
- * @throws AtlasServiceException
- */
- public List<String> createEntity(String... entitiesAsJson) throws AtlasServiceException {
- return createEntity(new JSONArray(Arrays.asList(entitiesAsJson)));
- }
-
- public List<String> createEntity(Referenceable... entities) throws AtlasServiceException {
- return createEntity(Arrays.asList(entities));
- }
-
- public List<String> createEntity(Collection<Referenceable> entities) throws AtlasServiceException {
- JSONArray entityArray = getEntitiesArray(entities);
- return createEntity(entityArray);
- }
-
- private JSONArray getEntitiesArray(Collection<Referenceable> entities) {
- JSONArray entityArray = new JSONArray(entities.size());
- for (Referenceable entity : entities) {
- entityArray.put(InstanceSerialization.toJson(entity, true));
- }
- return entityArray;
- }
-
- /**
- * Replaces entity definitions identified by their guid or unique attribute
- * Updates properties set in the definition for the entity corresponding to guid
- * @param entities entities to be updated
- * @return json array of guids which were updated/created
- * @throws AtlasServiceException
- */
- public EntityResult updateEntities(Referenceable... entities) throws AtlasServiceException {
- return updateEntities(Arrays.asList(entities));
- }
-
- protected EntityResult updateEntities(JSONArray entities) throws AtlasServiceException {
- LOG.debug("Updating entities: {}", entities);
- JSONObject response = callAPIWithBody(API.UPDATE_ENTITY, entities.toString());
- EntityResult results = extractEntityResult(response);
- LOG.debug("Update entities returned results: {}", results);
- return results;
- }
-
- public EntityResult updateEntities(Collection<Referenceable> entities) throws AtlasServiceException {
- JSONArray entitiesArray = getEntitiesArray(entities);
- return updateEntities(entitiesArray);
- }
-
- /**
- * Supports Partial updates
- * Updates property for the entity corresponding to guid
- * @param guid guid
- * @param attribute property key
- * @param value property value
- */
- public EntityResult updateEntityAttribute(final String guid, final String attribute, String value)
- throws AtlasServiceException {
- LOG.debug("Updating entity id: {}, attribute name: {}, attribute value: {}", guid, attribute, value);
- JSONObject response = callAPIWithRetries(API.UPDATE_ENTITY_PARTIAL, value, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- API api = API.UPDATE_ENTITY_PARTIAL;
- WebResource resource = getResource(api, guid);
- resource = resource.queryParam(ATTRIBUTE_NAME, attribute);
- return resource;
- }
- });
- return extractEntityResult(response);
- }
-
- /**
- * Supports Partial updates
- * Updates properties set in the definition for the entity corresponding to guid
- * @param guid guid
- * @param entity entity definition
- */
- public EntityResult updateEntity(String guid, Referenceable entity) throws AtlasServiceException {
- String entityJson = InstanceSerialization.toJson(entity, true);
- LOG.debug("Updating entity id {} with {}", guid, entityJson);
- JSONObject response = callAPIWithBodyAndParams(API.UPDATE_ENTITY_PARTIAL, entityJson, guid);
- return extractEntityResult(response);
- }
-
- /**
- * Associate trait to an entity
- *
- * @param guid guid
- * @param traitDefinition trait definition
- */
- public void addTrait(String guid, Struct traitDefinition) throws AtlasServiceException {
- String traitJson = InstanceSerialization.toJson(traitDefinition, true);
- LOG.debug("Adding trait to entity with id {} {}", guid, traitJson);
- callAPIWithBodyAndParams(API.ADD_TRAITS, traitJson, guid, URI_TRAITS);
- }
-
- /**
- * Delete a trait from the given entity
- * @param guid guid of the entity
- * @param traitName trait to be deleted
- * @throws AtlasServiceException
- */
- public void deleteTrait(String guid, String traitName) throws AtlasServiceException {
- callAPIWithBodyAndParams(API.DELETE_TRAITS, null, guid, TRAITS, traitName);
- }
-
- /**
- * Supports Partial updates
- * Updates properties set in the definition for the entity corresponding to guid
- * @param entityType Type of the entity being updated
- * @param uniqueAttributeName Attribute Name that uniquely identifies the entity
- * @param uniqueAttributeValue Attribute Value that uniquely identifies the entity
- * @param entity entity definition
- */
- public EntityResult updateEntity(final String entityType, final String uniqueAttributeName,
- final String uniqueAttributeValue,
- Referenceable entity) throws AtlasServiceException {
- final API api = API.UPDATE_ENTITY_PARTIAL;
- String entityJson = InstanceSerialization.toJson(entity, true);
- LOG.debug("Updating entity type: {}, attributeName: {}, attributeValue: {}, entity: {}", entityType,
- uniqueAttributeName, uniqueAttributeValue, entityJson);
- JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(api, QUALIFIED_NAME);
- resource = resource.queryParam(TYPE, entityType);
- resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
- resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
- return resource;
- }
- });
- EntityResult result = extractEntityResult(response);
- LOG.debug("Update entity returned result: {}", result);
- return result;
- }
-
- protected String getString(JSONObject jsonObject, String parameter) throws AtlasServiceException {
- try {
- return jsonObject.getString(parameter);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- /**
- * Delete the specified entities from the repository
- *
- * @param guids guids of entities to delete
- * @return List of entity ids updated/deleted
- * @throws AtlasServiceException
- */
- public EntityResult deleteEntities(final String ... guids) throws AtlasServiceException {
- LOG.debug("Deleting entities: {}", guids);
- JSONObject jsonResponse = callAPIWithRetries(API.DELETE_ENTITIES, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- API api = API.DELETE_ENTITIES;
- WebResource resource = getResource(api);
- for (String guid : guids) {
- resource = resource.queryParam(GUID.toLowerCase(), guid);
- }
- return resource;
- }
- });
- EntityResult results = extractEntityResult(jsonResponse);
- LOG.debug("Delete entities returned results: {}", results);
- return results;
- }
-
- /**
- * Supports Deletion of an entity identified by its unique attribute value
- * @param entityType Type of the entity being deleted
- * @param uniqueAttributeName Attribute Name that uniquely identifies the entity
- * @param uniqueAttributeValue Attribute Value that uniquely identifies the entity
- * @return List of entity ids updated/deleted(including composite references from that entity)
- */
- public EntityResult deleteEntity(String entityType, String uniqueAttributeName, String uniqueAttributeValue)
- throws AtlasServiceException {
- LOG.debug("Deleting entity type: {}, attributeName: {}, attributeValue: {}", entityType, uniqueAttributeName,
- uniqueAttributeValue);
- API api = API.DELETE_ENTITY;
- WebResource resource = getResource(api);
- resource = resource.queryParam(TYPE, entityType);
- resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
- resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
- JSONObject jsonResponse = callAPIWithResource(API.DELETE_ENTITIES, resource);
- EntityResult results = extractEntityResult(jsonResponse);
- LOG.debug("Delete entities returned results: {}", results);
- return results;
- }
-
- /**
- * Get an entity given the entity id
- * @param guid entity id
- * @return result object
- * @throws AtlasServiceException
- */
- public Referenceable getEntity(String guid) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_ENTITY, null, guid);
- try {
- String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
- return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true);
- } catch (JSONException e) {
- throw new AtlasServiceException(API.GET_ENTITY, e);
- }
- }
-
- public static String toString(JSONArray jsonArray) throws JSONException {
- ArrayList<String> resultsList = new ArrayList<>();
- for (int index = 0; index < jsonArray.length(); index++) {
- resultsList.add(jsonArray.getString(index));
- }
- return StringUtils.join(resultsList, ",");
- }
-
- /**
- * Get an entity given the entity id
- * @param entityType entity type name
- * @param attribute qualified name of the entity
- * @param value
- * @return result object
- * @throws AtlasServiceException
- */
- public Referenceable getEntity(final String entityType, final String attribute, final String value)
- throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithRetries(API.GET_ENTITY, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(API.GET_ENTITY);
- resource = resource.queryParam(TYPE, entityType);
- resource = resource.queryParam(ATTRIBUTE_NAME, attribute);
- resource = resource.queryParam(ATTRIBUTE_VALUE, value);
- return resource;
- }
- });
- try {
- String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
- return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true);
- } catch (JSONException e) {
- throw new AtlasServiceException(API.GET_ENTITY, e);
- }
- }
-
- /**
- * List entities for a given entity type
- * @param entityType
- * @return
- * @throws AtlasServiceException
- */
- public List<String> listEntities(final String entityType) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithRetries(API.LIST_ENTITIES, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(API.LIST_ENTITIES);
- resource = resource.queryParam(TYPE, entityType);
- return resource;
- }
- });
- return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>());
- }
-
- /**
- * List traits for a given entity identified by its GUID
- * @param guid GUID of the entity
- * @return List<String> - traitnames associated with entity
- * @throws AtlasServiceException
- */
- public List<String> listTraits(final String guid) throws AtlasServiceException {
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.LIST_TRAITS, null, guid, URI_TRAITS);
- return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>());
- }
-
- /**
- * Get all trait definitions for an entity
- * @param guid GUID of the entity
- * @return List<String> trait definitions of the traits associated to the entity
- * @throws AtlasServiceException
- */
- public List<Struct> listTraitDefinitions(final String guid) throws AtlasServiceException{
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
- List<JSONObject> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<JSONObject, JSONObject>());
- ArrayList<Struct> traitStructList = new ArrayList<>();
- for(JSONObject traitDef:traitDefList){
- Struct traitStruct = InstanceSerialization.fromJsonStruct(traitDef.toString(), true);
- traitStructList.add(traitStruct);
- }
- return traitStructList;
- }
-
- /**
- * Get trait definition for a given entity and traitname
- * @param guid GUID of the entity
- * @param traitName
- * @return trait definition
- * @throws AtlasServiceException
- */
- public Struct getTraitDefinition(final String guid, final String traitName) throws AtlasServiceException{
- JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName);
-
- try {
- return InstanceSerialization.fromJsonStruct(jsonResponse.getString(AtlasClient.RESULTS), false);
- }catch (JSONException e){
- throw new AtlasServiceException(API.GET_TRAIT_DEFINITION, e);
- }
- }
-
- protected class ExtractOperation<T, U> {
- T extractElement(U element) throws JSONException {
- return (T) element;
- }
- }
-
- protected <T, U> List<T> extractResults(JSONObject jsonResponse, String key, ExtractOperation<T, U> extractInterafce)
- throws AtlasServiceException {
- try {
- JSONArray results = jsonResponse.getJSONArray(key);
- ArrayList<T> resultsList = new ArrayList<>();
- for (int index = 0; index < results.length(); index++) {
- Object element = results.get(index);
- resultsList.add(extractInterafce.extractElement((U) element));
- }
- return resultsList;
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- /**
- * Get the latest numResults entity audit events in decreasing order of timestamp for the given entity id
- * @param entityId entity id
- * @param numResults number of results to be returned
- * @return list of audit events for the entity id
- * @throws AtlasServiceException
- */
- public List<EntityAuditEvent> getEntityAuditEvents(String entityId, short numResults)
- throws AtlasServiceException {
- return getEntityAuditEvents(entityId, null, numResults);
- }
-
- /**
- * Get the entity audit events in decreasing order of timestamp for the given entity id
- * @param entityId entity id
- * @param startKey key for the first event to be returned, used for pagination
- * @param numResults number of results to be returned
- * @return list of audit events for the entity id
- * @throws AtlasServiceException
- */
- public List<EntityAuditEvent> getEntityAuditEvents(String entityId, String startKey, short numResults)
- throws AtlasServiceException {
- WebResource resource = getResource(API.LIST_ENTITY_AUDIT, entityId, URI_ENTITY_AUDIT);
- if (StringUtils.isNotEmpty(startKey)) {
- resource = resource.queryParam(START_KEY, startKey);
- }
- resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults));
-
- JSONObject jsonResponse = callAPIWithResource(API.LIST_ENTITY_AUDIT, resource);
- return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, JSONObject>() {
- @Override
- EntityAuditEvent extractElement(JSONObject element) throws JSONException {
- return SerDe.GSON.fromJson(element.toString(), EntityAuditEvent.class);
- }
- });
-
- }
-
- /**
- * Search using dsl/full text
- * @param searchQuery
- * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
- * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
- * @return Query results
- * @throws AtlasServiceException
- */
- public JSONArray search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException {
- JSONObject result = callAPIWithRetries(API.SEARCH, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(API.SEARCH);
- resource = resource.queryParam(QUERY, searchQuery);
- resource = resource.queryParam(LIMIT, String.valueOf(limit));
- resource = resource.queryParam(OFFSET, String.valueOf(offset));
- return resource;
- }
- });
- try {
- return result.getJSONArray(RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
-
- }
-
- /**
- * Search given query DSL
- * @param query DSL query
- * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
- * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
- * @return result json object
- * @throws AtlasServiceException
- */
- public JSONArray searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
- LOG.debug("DSL query: {}", query);
- JSONObject result = callAPIWithRetries(API.SEARCH_DSL, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(API.SEARCH_DSL);
- resource = resource.queryParam(QUERY, query);
- resource = resource.queryParam(LIMIT, String.valueOf(limit));
- resource = resource.queryParam(OFFSET, String.valueOf(offset));
- return resource;
- }
- });
- try {
- return result.getJSONArray(RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- /**
- * Search given full text search
- * @param query Query
- * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
- * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
- * @return result json object
- * @throws AtlasServiceException
- */
- public JSONObject searchByFullText(final String query, final int limit, final int offset) throws AtlasServiceException {
- return callAPIWithRetries(API.SEARCH_FULL_TEXT, null, new ResourceCreator() {
- @Override
- public WebResource createResource() {
- WebResource resource = getResource(API.SEARCH_FULL_TEXT);
- resource = resource.queryParam(QUERY, query);
- resource = resource.queryParam(LIMIT, String.valueOf(limit));
- resource = resource.queryParam(OFFSET, String.valueOf(offset));
- return resource;
- }
- });
- }
-
- public JSONObject getInputGraph(String datasetName) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- public JSONObject getOutputGraph(String datasetName) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- public JSONObject getInputGraphForEntity(String entityId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- public JSONObject getOutputGraphForEntity(String datasetId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- public JSONObject getSchemaForEntity(String datasetId) throws AtlasServiceException {
- JSONObject response = callAPIWithBodyAndParams(API.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema");
- try {
- return response.getJSONObject(AtlasClient.RESULTS);
- } catch (JSONException e) {
- throw new AtlasServiceException(e);
- }
- }
-
- // Wrapper methods for compatibility
- @VisibleForTesting
- public JSONObject callAPIWithResource(API api, WebResource resource) throws AtlasServiceException {
- return callAPIWithResource(toAPIInfo(api), resource, null, JSONObject.class);
- }
-
- @VisibleForTesting
- public WebResource getResource(API api, String ... params) {
- return getResource(toAPIInfo(api), params);
- }
-
- @VisibleForTesting
- public JSONObject callAPIWithBody(API api, Object requestObject) throws AtlasServiceException {
- return callAPI(toAPIInfo(api), JSONObject.class, requestObject, (String[]) null);
- }
-
- @VisibleForTesting
- public JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String ... params) throws AtlasServiceException {
- return callAPI(toAPIInfo(api), JSONObject.class, requestObject, params);
- }
-
- @VisibleForTesting
- public JSONObject callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
- return callAPI(toAPIInfo(api), JSONObject.class, queryParams);
- }
-
- @VisibleForTesting
- JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
- return super.callAPIWithRetries(toAPIInfo(api), requestObject, resourceCreator);
- }
-
- private APIInfo toAPIInfo(API api){
- return new APIInfo(api.getPath(), api.getMethod(), api.getExpectedStatus());
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasClientV2.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/AtlasClientV2.java b/client/src/main/java/org/apache/atlas/AtlasClientV2.java
deleted file mode 100644
index 2cb9e84..0000000
--- a/client/src/main/java/org/apache/atlas/AtlasClientV2.java
+++ /dev/null
@@ -1,466 +0,0 @@
-/**
- * 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;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import org.apache.atlas.model.SearchFilter;
-import org.apache.atlas.model.discovery.AtlasSearchResult;
-import org.apache.atlas.model.discovery.SearchParameters;
-import org.apache.atlas.model.instance.AtlasClassification;
-import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
-import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
-import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
-import org.apache.atlas.model.instance.EntityMutationResponse;
-import org.apache.atlas.model.lineage.AtlasLineageInfo;
-import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
-import org.apache.atlas.model.typedef.AtlasClassificationDef;
-import org.apache.atlas.model.typedef.AtlasEntityDef;
-import org.apache.atlas.model.typedef.AtlasEnumDef;
-import org.apache.atlas.model.typedef.AtlasStructDef;
-import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.type.AtlasType;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.configuration.Configuration;
-import org.apache.hadoop.security.UserGroupInformation;
-
-import javax.ws.rs.HttpMethod;
-import javax.ws.rs.core.Cookie;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.atlas.AtlasClient.LIMIT;
-import static org.apache.atlas.AtlasClient.OFFSET;
-import static org.apache.atlas.AtlasClient.QUERY;
-
-public class AtlasClientV2 extends AtlasBaseClient {
-
- // Type APIs
- public static final String TYPES_API = BASE_URI + "v2/types/";
- private static final String TYPEDEFS_API = TYPES_API + "typedefs/";
- private static final String TYPEDEF_BY_NAME = TYPES_API + "typedef/name/";
- private static final String TYPEDEF_BY_GUID = TYPES_API + "typedef/guid/";
-
- private static final String GET_BY_NAME_TEMPLATE = TYPES_API + "%s/name/%s";
- private static final String GET_BY_GUID_TEMPLATE = TYPES_API + "%s/guid/%s";
-
- private static final APIInfo GET_TYPEDEF_BY_NAME = new APIInfo(TYPEDEF_BY_NAME, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo GET_TYPEDEF_BY_GUID = new APIInfo(TYPEDEF_BY_GUID, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo GET_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo CREATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.POST, Response.Status.OK);
- private static final APIInfo UPDATE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.PUT, Response.Status.OK);
- private static final APIInfo DELETE_ALL_TYPE_DEFS = new APIInfo(TYPEDEFS_API, HttpMethod.DELETE, Response.Status.NO_CONTENT);
-
- // Entity APIs
- public static final String ENTITY_API = BASE_URI + "v2/entity/";
- private static final String ENTITY_BULK_API = ENTITY_API + "bulk/";
-
- private static final APIInfo GET_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.GET, Response.Status.OK);
- private static final APIInfo GET_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/", HttpMethod.GET, Response.Status.OK);
- public static final APIInfo CREATE_ENTITY = new APIInfo(ENTITY_API, HttpMethod.POST, Response.Status.OK);
- public static final APIInfo UPDATE_ENTITY = CREATE_ENTITY;
- public static final APIInfo UPDATE_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/", HttpMethod.PUT, Response.Status.OK);
- private static final APIInfo DELETE_ENTITY_BY_GUID = new APIInfo(ENTITY_API + "guid/", HttpMethod.DELETE, Response.Status.OK);
- public static final APIInfo DELETE_ENTITY_BY_ATTRIBUTE = new APIInfo(ENTITY_API + "uniqueAttribute/type/", HttpMethod.DELETE, Response.Status.OK);
-
- private static final APIInfo GET_ENTITIES_BY_GUIDS = new APIInfo(ENTITY_BULK_API, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo CREATE_ENTITIES = new APIInfo(ENTITY_BULK_API, HttpMethod.POST, Response.Status.OK);
- private static final APIInfo UPDATE_ENTITIES = CREATE_ENTITIES;
- private static final APIInfo DELETE_ENTITIES_BY_GUIDS = new APIInfo(ENTITY_BULK_API, HttpMethod.DELETE, Response.Status.OK);
-
- private static final APIInfo GET_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.GET, Response.Status.OK);
- private static final APIInfo ADD_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.POST, Response.Status.NO_CONTENT);
- private static final APIInfo UPDATE_CLASSIFICATIONS = new APIInfo(ENTITY_API + "guid/%s/classifications", HttpMethod.PUT, Response.Status.OK);
- private static final APIInfo DELETE_CLASSIFICATION = new APIInfo(ENTITY_API + "guid/%s/classification/%s", HttpMethod.DELETE, Response.Status.NO_CONTENT);
-
- public static final String PREFIX_ATTR = "attr:";
-
- // Lineage APIs
- private static final String LINEAGE_URI = BASE_URI + "v2/lineage/";
- private static final APIInfo LINEAGE_INFO = new APIInfo(LINEAGE_URI, HttpMethod.GET, Response.Status.OK);
-
-
- // Discovery APIs
- private static final String DISCOVERY_URI = BASE_URI + "v2/search";
- private static final String DSL_URI = DISCOVERY_URI + "/dsl";
- private static final String FULL_TEXT_URI = DISCOVERY_URI + "/fulltext";
- private static final String BASIC_SEARCH_URI = DISCOVERY_URI + "/basic";
- private static final String FACETED_SEARCH_URI = BASIC_SEARCH_URI;
-
- private static final APIInfo DSL_SEARCH = new APIInfo(DSL_URI, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo FULL_TEXT_SEARCH = new APIInfo(FULL_TEXT_URI, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo BASIC_SEARCH = new APIInfo(BASIC_SEARCH_URI, HttpMethod.GET, Response.Status.OK);
- private static final APIInfo FACETED_SEARCH = new APIInfo(FACETED_SEARCH_URI, HttpMethod.POST, Response.Status.OK);
-
-
- public AtlasClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) {
- super(baseUrl, basicAuthUserNamePassword);
- }
-
- public AtlasClientV2(String... baseUrls) throws AtlasException {
- super(baseUrls);
- }
-
- public AtlasClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) {
- super(ugi, doAsUser, baseUrls);
- }
-
- /**
- * Constructor for AtlasClient with cookie params as header
- * @param baseUrl
- * @param cookieName
- * @param value
- * @param path
- * @param domain
- */
- public AtlasClientV2(String[] baseUrl, String cookieName, String value, String path, String domain) {
- super(baseUrl, new Cookie(cookieName, value, path, domain));
- }
-
- /**
- * Constructor for AtlasClient with cookie as header
- * @param baseUrl
- * @param cookie
- */
- public AtlasClientV2(String[] baseUrl, Cookie cookie) {
- super(baseUrl, cookie);
- }
-
- @VisibleForTesting
- AtlasClientV2(WebResource service, Configuration configuration) {
- super(service, configuration);
- }
-
- /**
- * Bulk retrieval API for retrieving all type definitions in Atlas
- *
- * @return A composite wrapper object with lists of all type definitions
- */
- public AtlasTypesDef getAllTypeDefs(SearchFilter searchFilter) throws AtlasServiceException {
- return callAPI(GET_ALL_TYPE_DEFS, AtlasTypesDef.class, searchFilter.getParams());
- }
-
- public boolean typeWithGuidExists(String guid) {
- try {
- callAPI(GET_TYPEDEF_BY_GUID, String.class, null, guid);
- } catch (AtlasServiceException e) {
- return false;
- }
- return true;
- }
-
- public boolean typeWithNameExists(String name) {
- try {
- callAPI(GET_TYPEDEF_BY_NAME, String.class, null, name);
- } catch (AtlasServiceException e) {
- return false;
- }
- return true;
- }
-
- public AtlasEnumDef getEnumDefByName(final String name) throws AtlasServiceException {
- return getTypeDefByName(name, AtlasEnumDef.class);
- }
-
- public AtlasEnumDef getEnumDefByGuid(final String guid) throws AtlasServiceException {
- return getTypeDefByGuid(guid, AtlasEnumDef.class);
- }
-
- public AtlasStructDef getStructDefByName(final String name) throws AtlasServiceException {
- return getTypeDefByName(name, AtlasStructDef.class);
- }
-
- public AtlasStructDef getStructDefByGuid(final String guid) throws AtlasServiceException {
- return getTypeDefByGuid(guid, AtlasStructDef.class);
- }
-
- public AtlasClassificationDef getClassificationDefByName(final String name) throws AtlasServiceException {
- return getTypeDefByName(name, AtlasClassificationDef.class);
- }
-
- public AtlasClassificationDef getClassificationDefByGuid(final String guid) throws AtlasServiceException {
- return getTypeDefByGuid(guid, AtlasClassificationDef.class);
- }
-
- public AtlasEntityDef getEntityDefByName(final String name) throws AtlasServiceException {
- return getTypeDefByName(name, AtlasEntityDef.class);
- }
-
- public AtlasEntityDef getEntityDefByGuid(final String guid) throws AtlasServiceException {
- return getTypeDefByGuid(guid, AtlasEntityDef.class);
- }
-
- @Deprecated
- public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasServiceException {
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
- atlasTypesDef.getEnumDefs().add(enumDef);
- AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
- assert created != null;
- assert created.getEnumDefs() != null;
- return created.getEnumDefs().get(0);
- }
-
- @Deprecated
- public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasServiceException {
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
- atlasTypesDef.getStructDefs().add(structDef);
- AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
- assert created != null;
- assert created.getStructDefs() != null;
- return created.getStructDefs().get(0);
- }
-
- @Deprecated
- public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException {
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
- atlasTypesDef.getEntityDefs().add(entityDef);
- AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
- assert created != null;
- assert created.getEntityDefs() != null;
- return created.getEntityDefs().get(0);
- }
-
- @Deprecated
- public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef)
- throws AtlasServiceException {
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
- atlasTypesDef.getClassificationDefs().add(classificationDef);
- AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
- assert created != null;
- assert created.getClassificationDefs() != null;
- return created.getClassificationDefs().get(0);
- }
-
-
- /**
- * Bulk create APIs for all atlas type definitions, only new definitions will be created.
- * Any changes to the existing definitions will be discarded
- *
- * @param typesDef A composite wrapper object with corresponding lists of the type definition
- * @return A composite wrapper object with lists of type definitions that were successfully
- * created
- */
- public AtlasTypesDef createAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
- return callAPI(CREATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
- }
-
- /**
- * Bulk update API for all types, changes detected in the type definitions would be persisted
- *
- * @param typesDef A composite object that captures all type definition changes
- * @return A composite object with lists of type definitions that were updated
- */
- public AtlasTypesDef updateAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
- return callAPI(UPDATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
- }
-
- /**
- * Bulk delete API for all types
- *
- * @param typesDef A composite object that captures all types to be deleted
- */
- public void deleteAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
- callAPI(DELETE_ALL_TYPE_DEFS, (Class<?>)null, AtlasType.toJson(typesDef));
- }
-
- /* Lineage Calls */
-
- public AtlasLineageInfo getLineageInfo(final String guid, final LineageDirection direction, final int depth) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("direction", direction.toString());
- queryParams.add("depth", String.valueOf(depth));
-
- return callAPI(LINEAGE_INFO, AtlasLineageInfo.class, queryParams, guid);
- }
-
- /* Entity Calls */
-
- public AtlasEntityWithExtInfo getEntityByGuid(String guid) throws AtlasServiceException {
- return callAPI(GET_ENTITY_BY_GUID, AtlasEntityWithExtInfo.class, (MultivaluedMap<String, String>) null, guid);
- }
-
- public AtlasEntityWithExtInfo getEntityByAttribute(String type, Map<String, String> attributes) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes);
-
- return callAPI(GET_ENTITY_BY_ATTRIBUTE, AtlasEntityWithExtInfo.class, queryParams, type);
- }
-
- public EntityMutationResponse updateEntityByAttribute(String type, Map<String, String> attributes, AtlasEntityWithExtInfo entityInfo)
- throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes);
-
- return callAPI(UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entityInfo, queryParams, type);
- }
-
- public EntityMutationResponse deleteEntityByAttribute(String type, Map<String, String> attributes) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes);
-
- return callAPI(DELETE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, queryParams, type);
- }
-
- public EntityMutationResponse createEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException {
- return callAPI(CREATE_ENTITY, EntityMutationResponse.class, entity);
- }
-
- public EntityMutationResponse updateEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException {
- return callAPI(UPDATE_ENTITY, EntityMutationResponse.class, entity);
- }
-
- public EntityMutationResponse deleteEntityByGuid(String guid) throws AtlasServiceException {
- return callAPI(DELETE_ENTITY_BY_GUID, EntityMutationResponse.class, null, guid);
- }
-
- public AtlasEntitiesWithExtInfo getEntitiesByGuids(List<String> guids) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
-
- queryParams.put("guid", guids);
-
- return callAPI(GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams);
- }
-
- public EntityMutationResponse createEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException {
- return callAPI(CREATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
- }
-
- public EntityMutationResponse updateEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException {
- return callAPI(UPDATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
- }
-
- public EntityMutationResponse deleteEntitiesByGuids(List<String> guids) throws AtlasServiceException {
- return callAPI(DELETE_ENTITIES_BY_GUIDS, EntityMutationResponse.class, "guid", guids);
- }
-
- public AtlasClassifications getClassifications(String guid) throws AtlasServiceException {
- return callAPI(updatePathParameters(GET_CLASSIFICATIONS, guid), AtlasClassifications.class, null);
- }
-
- public void addClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
- callAPI(updatePathParameters(ADD_CLASSIFICATIONS, guid), (Class<?>)null, classifications, (String[]) null);
- }
-
- public void updateClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
- callAPI(updatePathParameters(UPDATE_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
- }
-
- public void deleteClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
- callAPI(updatePathParameters(GET_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
- }
-
- public void deleteClassification(String guid, String classificationName) throws AtlasServiceException {
- callAPI(updatePathParameters(DELETE_CLASSIFICATION, guid, classificationName), null, null);
- }
-
-
- private MultivaluedMap<String, String> attributesToQueryParams(Map<String, String> attributes) {
- return attributesToQueryParams(attributes, null);
- }
-
- private MultivaluedMap<String, String> attributesToQueryParams(Map<String, String> attributes,
- MultivaluedMap<String, String> queryParams) {
- if (queryParams == null) {
- queryParams = new MultivaluedMapImpl();
- }
-
- if (MapUtils.isNotEmpty(attributes)) {
- for (Map.Entry<String, String> e : attributes.entrySet()) {
- queryParams.putSingle(PREFIX_ATTR + e.getKey(), e.getValue());
- }
- }
-
- return queryParams;
- }
-
- /* Discovery calls */
- public AtlasSearchResult dslSearch(final String query) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
-
- return callAPI(DSL_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult dslSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
- queryParams.add(LIMIT, String.valueOf(limit));
- queryParams.add(OFFSET, String.valueOf(offset));
-
- return callAPI(DSL_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult fullTextSearch(final String query) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
-
- return callAPI(FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult fullTextSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(QUERY, query);
- queryParams.add(LIMIT, String.valueOf(limit));
- queryParams.add(OFFSET, String.valueOf(offset));
-
- return callAPI(FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult basicSearch(final String typeName, final String classification, final String query,
- final boolean excludeDeletedEntities, final int limit, final int offset) throws AtlasServiceException {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("typeName", typeName);
- queryParams.add("classification", classification);
- queryParams.add(QUERY, query);
- queryParams.add("excludeDeletedEntities", String.valueOf(excludeDeletedEntities));
- queryParams.add(LIMIT, String.valueOf(limit));
- queryParams.add(OFFSET, String.valueOf(offset));
-
- return callAPI(BASIC_SEARCH, AtlasSearchResult.class, queryParams);
- }
-
- public AtlasSearchResult facetedSearch(SearchParameters searchParameters) throws AtlasServiceException {
- return callAPI(FACETED_SEARCH, AtlasSearchResult.class, searchParameters);
- }
-
- private <T> T getTypeDefByName(final String name, Class<T> typeDefClass) throws AtlasServiceException {
- String atlasPath = getAtlasPath(typeDefClass);
- APIInfo apiInfo = new APIInfo(String.format(GET_BY_NAME_TEMPLATE, atlasPath, name), HttpMethod.GET, Response.Status.OK);
- return callAPI(apiInfo, typeDefClass, null);
- }
-
- private <T> T getTypeDefByGuid(final String guid, Class<T> typeDefClass) throws AtlasServiceException {
- String atlasPath = getAtlasPath(typeDefClass);
- APIInfo apiInfo = new APIInfo(String.format(GET_BY_GUID_TEMPLATE, atlasPath, guid), HttpMethod.GET, Response.Status.OK);
- return callAPI(apiInfo, typeDefClass, null);
- }
-
- private <T> String getAtlasPath(Class<T> typeDefClass) {
- if (AtlasEnumDef.class.isAssignableFrom(typeDefClass)) {
- return "enumdef";
- } else if (AtlasEntityDef.class.isAssignableFrom(typeDefClass)) {
- return "entitydef";
- } else if (AtlasClassificationDef.class.isAssignableFrom(typeDefClass)) {
- return "classificationdef";
- } else if (AtlasStructDef.class.isAssignableFrom(typeDefClass)) {
- return "structdef";
- }
- // Code should never reach this point
- return "";
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java b/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
deleted file mode 100644
index 01e4e32..0000000
--- a/client/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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;
-
-import com.google.common.base.Preconditions;
-import org.apache.commons.lang.StringUtils;
-import java.util.Arrays;
-
-import java.util.List;
-
-public class AtlasServerEnsemble {
-
- private final String[] urls;
-
- public AtlasServerEnsemble(String[] baseUrls) {
- Preconditions.checkArgument((baseUrls!=null && baseUrls.length>0),
- "List of baseURLs cannot be null or empty.");
- for (String baseUrl : baseUrls) {
- Preconditions.checkArgument(StringUtils.isNotEmpty(baseUrl),
- "Base URL cannot be null or empty.");
- }
- urls = baseUrls;
- }
-
- public boolean hasSingleInstance() {
- return urls.length==1;
- }
-
- public String firstURL() {
- return urls[0];
- }
-
- public List<String> getMembers() {
- return Arrays.asList(urls);
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/AtlasServiceException.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/AtlasServiceException.java b/client/src/main/java/org/apache/atlas/AtlasServiceException.java
deleted file mode 100755
index b128f98..0000000
--- a/client/src/main/java/org/apache/atlas/AtlasServiceException.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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;
-
-import com.sun.jersey.api.client.ClientResponse;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-
-import javax.ws.rs.WebApplicationException;
-
-public class AtlasServiceException extends Exception {
- private ClientResponse.Status status;
-
- public AtlasServiceException(AtlasClient.API api, Exception e) {
- super("Metadata service API " + api + " failed", e);
- }
-
- public AtlasServiceException(AtlasBaseClient.APIInfo api, Exception e) {
- super("Metadata service API " + api.getMethod() + " : " + api.getPath() + " failed", e);
- }
-
- public AtlasServiceException(AtlasClient.API api, WebApplicationException e) throws JSONException {
- this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()),
- ((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
- }
-
- public AtlasServiceException(AtlasBaseClient.APIInfo api, WebApplicationException e) throws JSONException {
- this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()),
- ((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
- }
-
- private AtlasServiceException(AtlasClient.API api, ClientResponse.Status status, String response) {
- super("Metadata service API " + api + " failed with status " + (status != null ? status.getStatusCode() : -1)
- + " (" + status + ") Response Body (" + response + ")");
- this.status = status;
- }
-
- private AtlasServiceException(AtlasBaseClient.APIInfo api, ClientResponse.Status status, String response) {
- super("Metadata service API " + api + " failed with status " + (status != null ? status.getStatusCode() : -1)
- + " (" + status + ") Response Body (" + response + ")");
- this.status = status;
- }
-
- public AtlasServiceException(AtlasClient.API api, ClientResponse response) {
- this(api, ClientResponse.Status.fromStatusCode(response.getStatus()), response.getEntity(String.class));
- }
-
- public AtlasServiceException(AtlasBaseClient.APIInfo api, ClientResponse response) {
- this(api, ClientResponse.Status.fromStatusCode(response.getStatus()), response.getEntity(String.class));
- }
-
- public AtlasServiceException(Exception e) {
- super(e);
- }
-
- public ClientResponse.Status getStatus() {
- return status;
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java b/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
deleted file mode 100644
index 5e6d6db..0000000
--- a/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * 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;
-
-import org.apache.atlas.model.instance.GuidMapping;
-import org.apache.atlas.model.legacy.EntityResult;
-import org.apache.atlas.type.AtlasType;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Result from creating or updating entities.
- */
-@Deprecated
-public class CreateUpdateEntitiesResult {
-
- /**
- * Guid mapping for the entities that were created/updated
- */
- private GuidMapping guidMapping;
-
- /**
- * Entity result
- */
- private EntityResult entityResult;
-
- /**
- * Gets the guid mapping
- */
- public GuidMapping getGuidMapping() {
- return guidMapping;
- }
-
- /**
- * Sets the guid mapping
- */
- public void setGuidMapping(GuidMapping guidMapping) {
- this.guidMapping = guidMapping;
- }
-
- /**
- * Gets the entity result
- */
- public EntityResult getEntityResult() {
- return entityResult;
- }
-
- /**
- * Sets the entity result
- */
- public void setEntityResult(EntityResult entityResult) {
- this.entityResult = entityResult;
- }
-
- /**
- * Deserializes the given json into an instance of
- * CreateUpdateEntitiesResult.
- *
- * @param json
- * the (unmodified) json that comes back from Atlas.
- * @return
- * @throws AtlasServiceException
- */
- public static CreateUpdateEntitiesResult fromJson(String json) throws AtlasServiceException {
-
- GuidMapping guidMapping = AtlasType.fromJson(json, GuidMapping.class);
- EntityResult entityResult = EntityResult.fromString(json);
- CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
- result.setEntityResult(entityResult);
- result.setGuidMapping(guidMapping);
- return result;
- }
-
- /**
- * Convenience method to get the guids of the created entities from
- * the EntityResult.
- */
- public List<String> getCreatedEntities() {
- if(entityResult == null) {
- return Collections.emptyList();
- }
- return getEntityResult().getCreatedEntities();
- }
-
- /**
- * Convenience method to get the guids of the updated entities from
- * the EntityResult.
- */
- public List<String> getUpdatedEntities() {
- if(entityResult == null) {
- return Collections.emptyList();
- }
- return getEntityResult().getUpdateEntities();
- }
-
-
- /**
- * Convenience method to get the guids of the deleted entities
- * from the EntityResult.
- */
- public List<String> getDeletedEntities() {
- if (entityResult == null) {
- return Collections.emptyList();
- }
- return getEntityResult().getDeletedEntities();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/EntityAuditEvent.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/EntityAuditEvent.java b/client/src/main/java/org/apache/atlas/EntityAuditEvent.java
deleted file mode 100644
index 904674d..0000000
--- a/client/src/main/java/org/apache/atlas/EntityAuditEvent.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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;
-
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.json.InstanceSerialization;
-
-import java.util.Objects;
-
-/**
- * Structure of entity audit event
- */
-public class EntityAuditEvent {
- public enum EntityAuditAction {
- ENTITY_CREATE, ENTITY_UPDATE, ENTITY_DELETE, TAG_ADD, TAG_DELETE, TAG_UPDATE,
- ENTITY_IMPORT_CREATE, ENTITY_IMPORT_UPDATE, ENTITY_IMPORT_DELETE,
- }
-
- private String entityId;
- private long timestamp;
- private String user;
- private EntityAuditAction action;
- private String details;
- private String eventKey;
- private IReferenceableInstance entityDefinition;
-
- public EntityAuditEvent() {
- }
-
- public EntityAuditEvent(String entityId, Long ts, String user, EntityAuditAction action, String details,
- IReferenceableInstance entityDefinition) throws AtlasException {
- this.entityId = entityId;
- this.timestamp = ts;
- this.user = user;
- this.action = action;
- this.details = details;
- this.entityDefinition = entityDefinition;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- EntityAuditEvent that = (EntityAuditEvent) o;
- return timestamp == that.timestamp &&
- Objects.equals(entityId, that.entityId) &&
- Objects.equals(user, that.user) &&
- action == that.action &&
- Objects.equals(details, that.details) &&
- Objects.equals(eventKey, that.eventKey) &&
- Objects.equals(entityDefinition, that.entityDefinition);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(entityId, timestamp, user, action, details, eventKey, entityDefinition);
- }
-
- @Override
- public String toString() {
- return SerDe.GSON.toJson(this);
- }
-
- public static EntityAuditEvent fromString(String eventString) {
- return SerDe.GSON.fromJson(eventString, EntityAuditEvent.class);
- }
-
- public String getEntityId() {
- return entityId;
- }
-
- public long getTimestamp() {
- return timestamp;
- }
-
- public String getUser() {
- return user;
- }
-
- public EntityAuditAction getAction() {
- return action;
- }
-
- public String getDetails() {
- return details;
- }
-
- public void setEntityId(String entityId) {
- this.entityId = entityId;
- }
-
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
-
- public void setUser(String user) {
- this.user = user;
- }
-
- public void setAction(EntityAuditAction action) {
- this.action = action;
- }
-
- public void setDetails(String details) {
- this.details = details;
- }
-
- public String getEventKey() {
- return eventKey;
- }
-
- public void setEventKey(String eventKey) {
- this.eventKey = eventKey;
- }
-
- public IReferenceableInstance getEntityDefinition() {
- return entityDefinition;
- }
-
- public String getEntityDefinitionString() {
- if (entityDefinition != null) {
- return InstanceSerialization.toJson(entityDefinition, true);
- }
- return null;
- }
-
- public void setEntityDefinition(String entityDefinition) {
- this.entityDefinition = InstanceSerialization.fromJsonReferenceable(entityDefinition, true);
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/ResourceCreator.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/ResourceCreator.java b/client/src/main/java/org/apache/atlas/ResourceCreator.java
deleted file mode 100644
index 2017065..0000000
--- a/client/src/main/java/org/apache/atlas/ResourceCreator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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;
-
-import com.sun.jersey.api.client.WebResource;
-
-/**
- * An interface to capture the closure of how a WebResource is created.
- */
-@Deprecated
-public interface ResourceCreator {
- WebResource createResource();
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/src/main/java/org/apache/atlas/SerDe.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/atlas/SerDe.java b/client/src/main/java/org/apache/atlas/SerDe.java
deleted file mode 100644
index cdc3509..0000000
--- a/client/src/main/java/org/apache/atlas/SerDe.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
-import org.apache.atlas.typesystem.IReferenceableInstance;
-import org.apache.atlas.typesystem.IStruct;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.Struct;
-import org.apache.atlas.typesystem.json.InstanceSerialization;
-
-import java.lang.reflect.Type;
-
-@Deprecated
-public class SerDe {
- public static final Gson GSON = new GsonBuilder().
- registerTypeAdapter(IStruct.class, new StructDeserializer()).
- registerTypeAdapter(IReferenceableInstance.class, new ReferenceableSerializerDeserializer()).
- registerTypeAdapter(Referenceable.class, new ReferenceableSerializerDeserializer()).
- create();
-
- /**
- * Serde for Struct used by AbstractNotificationConsumer.GSON.
- */
- public static final class StructDeserializer implements JsonDeserializer<IStruct>, JsonSerializer<IStruct> {
- @Override
- public IStruct deserialize(final JsonElement json, final Type type,
- final JsonDeserializationContext context) {
- return context.deserialize(json, Struct.class);
- }
-
- @Override
- public JsonElement serialize(IStruct src, Type typeOfSrc, JsonSerializationContext context) {
- String instanceJson = InstanceSerialization.toJson(src, true);
- return new JsonParser().parse(instanceJson).getAsJsonObject();
- }
- }
-
- /**
- * Serde for Referenceable used by AbstractNotificationConsumer.GSON.
- */
- public static final class ReferenceableSerializerDeserializer implements JsonDeserializer<IStruct>,
- JsonSerializer<IReferenceableInstance> {
- @Override
- public IReferenceableInstance deserialize(final JsonElement json, final Type type,
- final JsonDeserializationContext context) {
-
- return InstanceSerialization.fromJsonReferenceable(json.toString(), true);
- }
-
- @Override
- public JsonElement serialize(IReferenceableInstance src, Type typeOfSrc, JsonSerializationContext context) {
- String instanceJson = InstanceSerialization.toJson(src, true);
- return new JsonParser().parse(instanceJson).getAsJsonObject();
- }
- }
-}
[7/7] atlas git commit: ATLAS-2179: Split Atlas client library to
avoid unnecessary dependencies
Posted by ma...@apache.org.
ATLAS-2179: Split Atlas client library to avoid unnecessary dependencies
Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/187730dd
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/187730dd
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/187730dd
Branch: refs/heads/master
Commit: 187730dd745f5f558e00393e28b919963c24bf08
Parents: 049c512
Author: apoorvnaik <ap...@apache.org>
Authored: Tue Sep 26 12:13:02 2017 -0700
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Tue Sep 26 18:25:59 2017 -0700
----------------------------------------------------------------------
addons/falcon-bridge/pom.xml | 4 +-
addons/hdfs-model/pom.xml | 2 +-
addons/hive-bridge/pom.xml | 4 +-
addons/sqoop-bridge/pom.xml | 4 +-
addons/storm-bridge/pom.xml | 4 +-
authorization/pom.xml | 5 -
.../simple/AtlasAuthorizationUtils.java | 10 +-
.../atlas/authorize/simple/PolicyParser.java | 3 +-
client/client-v1/pom.xml | 48 +
.../java/org/apache/atlas/AtlasAdminClient.java | 140 +++
.../main/java/org/apache/atlas/AtlasClient.java | 974 +++++++++++++++++++
.../atlas/CreateUpdateEntitiesResult.java | 124 +++
.../java/org/apache/atlas/EntityAuditEvent.java | 146 +++
.../src/main/java/org/apache/atlas/SerDe.java | 80 ++
.../java/org/apache/atlas/AtlasClientTest.java | 474 +++++++++
client/client-v2/pom.xml | 42 +
.../java/org/apache/atlas/AtlasClientV2.java | 460 +++++++++
client/common/pom.xml | 48 +
.../java/org/apache/atlas/AtlasBaseClient.java | 621 ++++++++++++
.../org/apache/atlas/AtlasServerEnsemble.java | 52 +
.../org/apache/atlas/AtlasServiceException.java | 56 ++
.../java/org/apache/atlas/ResourceCreator.java | 29 +
.../atlas/security/SecureClientUtils.java | 248 +++++
client/pom.xml | 54 +-
client/src/main/assembly/all-jar.xml | 35 +
.../java/org/apache/atlas/AtlasAdminClient.java | 140 ---
.../java/org/apache/atlas/AtlasBaseClient.java | 620 ------------
.../main/java/org/apache/atlas/AtlasClient.java | 962 ------------------
.../java/org/apache/atlas/AtlasClientV2.java | 466 ---------
.../org/apache/atlas/AtlasServerEnsemble.java | 52 -
.../org/apache/atlas/AtlasServiceException.java | 75 --
.../atlas/CreateUpdateEntitiesResult.java | 124 ---
.../java/org/apache/atlas/EntityAuditEvent.java | 146 ---
.../java/org/apache/atlas/ResourceCreator.java | 29 -
.../src/main/java/org/apache/atlas/SerDe.java | 80 --
.../atlas/security/SecureClientUtils.java | 248 -----
.../java/org/apache/atlas/AtlasClientTest.java | 474 ---------
common/pom.xml | 5 +
.../org/apache/atlas/ApplicationProperties.java | 203 ----
.../java/org/apache/atlas/AtlasException.java | 43 -
.../atlas/groovy/ArithmeticExpression.java | 4 +-
.../security/InMemoryJAASConfiguration.java | 401 --------
.../atlas/security/SecurityProperties.java | 49 -
.../apache/atlas/utils/AuthenticationUtil.java | 70 --
.../apache/atlas/ApplicationPropertiesTest.java | 129 ---
.../security/InMemoryJAASConfigurationTest.java | 89 --
...ConfigurationTicketBasedKafkaClientTest.java | 60 --
.../org/apache/atlas/ApplicationProperties.java | 203 ++++
.../java/org/apache/atlas/AtlasException.java | 43 +
.../security/InMemoryJAASConfiguration.java | 401 ++++++++
.../atlas/security/SecurityProperties.java | 49 +
.../apache/atlas/utils/AuthenticationUtil.java | 70 ++
.../apache/atlas/ApplicationPropertiesTest.java | 129 +++
.../security/InMemoryJAASConfigurationTest.java | 89 ++
...ConfigurationTicketBasedKafkaClientTest.java | 60 ++
intg/src/test/resources/atlas-jaas.properties | 62 ++
intg/src/test/resources/test.properties | 19 +
notification/pom.xml | 2 +-
pom.xml | 12 +
repository/pom.xml | 2 +-
.../converters/AtlasInstanceConverter.java | 4 +-
.../graph/GraphBackedMetadataRepository.java | 13 +-
.../store/graph/v1/EntityGraphRetriever.java | 53 +-
.../test/java/org/apache/atlas/TestUtils.java | 6 +-
...hBackedMetadataRepositoryDeleteTestBase.java | 6 +-
.../GraphBackedMetadataRepositoryTest.java | 2 +-
.../graph/ReverseReferenceUpdateTestBase.java | 8 +-
.../service/DefaultMetadataServiceTest.java | 4 +-
server-api/pom.xml | 2 +-
.../apache/atlas/services/MetadataService.java | 2 +-
.../test/resources/atlas-application.properties | 6 +-
webapp/pom.xml | 7 +-
.../notification/NotificationHookConsumer.java | 22 +-
.../atlas/web/resources/EntityResource.java | 4 +-
.../web/integration/AdminJerseyResourceIT.java | 2 +-
.../DataSetLineageJerseyResourceIT.java | 10 +-
.../web/integration/EntityJerseyResourceIT.java | 20 +-
.../EntityLineageJerseyResourceIT.java | 17 +-
.../MetadataDiscoveryJerseyResourceIT.java | 14 +-
.../web/integration/TypesJerseyResourceIT.java | 10 +-
80 files changed, 4857 insertions(+), 4632 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/addons/falcon-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/falcon-bridge/pom.xml b/addons/falcon-bridge/pom.xml
index f0e668f..442be48 100644
--- a/addons/falcon-bridge/pom.xml
+++ b/addons/falcon-bridge/pom.xml
@@ -53,7 +53,7 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
<dependency>
@@ -157,7 +157,7 @@
</artifactItem>
<artifactItem>
<groupId>${project.groupId}</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/addons/hdfs-model/pom.xml
----------------------------------------------------------------------
diff --git a/addons/hdfs-model/pom.xml b/addons/hdfs-model/pom.xml
index fe78442..6ed444a 100644
--- a/addons/hdfs-model/pom.xml
+++ b/addons/hdfs-model/pom.xml
@@ -50,7 +50,7 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/addons/hive-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/hive-bridge/pom.xml b/addons/hive-bridge/pom.xml
index d16fde7..0909dc2 100755
--- a/addons/hive-bridge/pom.xml
+++ b/addons/hive-bridge/pom.xml
@@ -100,7 +100,7 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
<dependency>
@@ -205,7 +205,7 @@
</artifactItem>
<artifactItem>
<groupId>${project.groupId}</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/addons/sqoop-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/sqoop-bridge/pom.xml b/addons/sqoop-bridge/pom.xml
index c866f16..7afc806 100644
--- a/addons/sqoop-bridge/pom.xml
+++ b/addons/sqoop-bridge/pom.xml
@@ -101,7 +101,7 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
<dependency>
@@ -222,7 +222,7 @@
</artifactItem>
<artifactItem>
<groupId>${project.groupId}</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/addons/storm-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/storm-bridge/pom.xml b/addons/storm-bridge/pom.xml
index 8726681..279dd6e 100644
--- a/addons/storm-bridge/pom.xml
+++ b/addons/storm-bridge/pom.xml
@@ -43,7 +43,7 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
<dependency>
@@ -171,7 +171,7 @@
</artifactItem>
<artifactItem>
<groupId>${project.groupId}</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/authorization/pom.xml
----------------------------------------------------------------------
diff --git a/authorization/pom.xml b/authorization/pom.xml
index bc0882b..143c4e4 100644
--- a/authorization/pom.xml
+++ b/authorization/pom.xml
@@ -36,11 +36,6 @@
</dependency>
<dependency>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
- </dependency>
-
- <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.version}</version>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
----------------------------------------------------------------------
diff --git a/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java b/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
index d67376f..cc42a73 100644
--- a/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
+++ b/authorization/src/main/java/org/apache/atlas/authorize/simple/AtlasAuthorizationUtils.java
@@ -19,16 +19,16 @@
package org.apache.atlas.authorize.simple;
-import javax.servlet.http.HttpServletRequest;
-import org.apache.atlas.AtlasClient;
+import org.apache.atlas.authorize.AtlasAccessRequest;
import org.apache.atlas.authorize.AtlasActionTypes;
-import org.apache.atlas.authorize.AtlasResourceTypes;
import org.apache.atlas.authorize.AtlasAuthorizationException;
import org.apache.atlas.authorize.AtlasAuthorizer;
-import org.apache.atlas.authorize.AtlasAccessRequest;
import org.apache.atlas.authorize.AtlasAuthorizerFactory;
+import org.apache.atlas.authorize.AtlasResourceTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashSet;
@@ -38,7 +38,7 @@ import java.util.regex.Pattern;
public class AtlasAuthorizationUtils {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorizationUtils.class);
private static boolean isDebugEnabled = LOG.isDebugEnabled();
- private static final String BASE_URL = "/" + AtlasClient.BASE_URI;
+ private static final String BASE_URL = "/api/atlas/";
public static String getApi(String contextPath) {
if (isDebugEnabled) {
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java
----------------------------------------------------------------------
diff --git a/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java b/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java
index fc611c8..aabac90 100644
--- a/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java
+++ b/authorization/src/main/java/org/apache/atlas/authorize/simple/PolicyParser.java
@@ -21,7 +21,6 @@ import org.apache.atlas.authorize.AtlasActionTypes;
import org.apache.atlas.authorize.AtlasResourceTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import scala.tools.jline_embedded.internal.Log;
import java.util.ArrayList;
import java.util.HashMap;
@@ -234,7 +233,7 @@ public class PolicyParser {
} else if (type.equalsIgnoreCase("RELATIONSHIP")) {
resourceType = AtlasResourceTypes.RELATIONSHIP;
} else {
- Log.warn(type + " is invalid resource please check PolicyStore file");
+ LOG.warn(type + " is invalid resource please check PolicyStore file");
continue;
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v1/pom.xml
----------------------------------------------------------------------
diff --git a/client/client-v1/pom.xml b/client/client-v1/pom.xml
new file mode 100644
index 0000000..2b492bb
--- /dev/null
+++ b/client/client-v1/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>atlas-client</artifactId>
+ <groupId>org.apache.atlas</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>atlas-client-v1</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-typesystem</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-client-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-typesystem</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v1/src/main/java/org/apache/atlas/AtlasAdminClient.java
----------------------------------------------------------------------
diff --git a/client/client-v1/src/main/java/org/apache/atlas/AtlasAdminClient.java b/client/client-v1/src/main/java/org/apache/atlas/AtlasAdminClient.java
new file mode 100644
index 0000000..f334f6c
--- /dev/null
+++ b/client/client-v1/src/main/java/org/apache/atlas/AtlasAdminClient.java
@@ -0,0 +1,140 @@
+/**
+ * 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;
+
+import org.apache.atlas.model.metrics.AtlasMetrics;
+import org.apache.atlas.type.AtlasType;
+import org.apache.atlas.utils.AuthenticationUtil;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.configuration.Configuration;
+
+import java.util.Arrays;
+
+
+/**
+ * An application that allows users to run admin commands against an Atlas server.
+ *
+ * The application uses {@link AtlasClient} to send REST requests to the Atlas server. The details of connections
+ * and other configuration is specified in the Atlas properties file.
+ * Exit status of the application will be as follows:
+ * <li>0: successful execution</li>
+ * <li>1: error in options used for the application</li>
+ * <li>-1/255: application error</li>
+ */
+public class AtlasAdminClient {
+
+ private static final Option STATUS = new Option("status", false, "Get the status of an atlas instance");
+ private static final Option STATS = new Option("stats", false, "Get the metrics of an atlas instance");
+ private static final Options OPTIONS = new Options();
+
+ private static final int INVALID_OPTIONS_STATUS = 1;
+ private static final int PROGRAM_ERROR_STATUS = -1;
+
+ static {
+ OPTIONS.addOption(STATUS);
+ OPTIONS.addOption(STATS);
+ }
+
+ public static void main(String[] args) throws AtlasException, ParseException {
+ AtlasAdminClient atlasAdminClient = new AtlasAdminClient();
+ int result = atlasAdminClient.run(args);
+ System.exit(result);
+ }
+
+ private int run(String[] args) throws AtlasException {
+ CommandLine commandLine = parseCommandLineOptions(args);
+ Configuration configuration = ApplicationProperties.get();
+ String[] atlasServerUri = configuration.getStringArray(AtlasConstants.ATLAS_REST_ADDRESS_KEY);
+
+ if (atlasServerUri == null || atlasServerUri.length == 0) {
+ atlasServerUri = new String[] { AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS };
+ }
+
+ AtlasClient atlasClient = null;
+ if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
+ String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput();
+ atlasClient = new AtlasClient(atlasServerUri, basicAuthUsernamePassword);
+ } else {
+ atlasClient = new AtlasClient(atlasServerUri);
+ }
+ return handleCommand(commandLine, atlasServerUri, atlasClient);
+ }
+
+ private int handleCommand(CommandLine commandLine, String[] atlasServerUri, AtlasClient atlasClient) {
+ int cmdStatus = PROGRAM_ERROR_STATUS;
+ if (commandLine.hasOption(STATUS.getOpt())) {
+ try {
+ System.out.println(atlasClient.getAdminStatus());
+ cmdStatus = 0;
+ } catch (AtlasServiceException e) {
+ System.err.println("Could not retrieve status of the server at " + Arrays.toString(atlasServerUri));
+ printStandardHttpErrorDetails(e);
+ }
+ } else if (commandLine.hasOption(STATS.getOpt())) {
+ try {
+ AtlasMetrics atlasMetrics = atlasClient.getAtlasMetrics();
+ String json = AtlasType.toJson(atlasMetrics);
+ System.out.println(json);
+ cmdStatus = 0;
+ } catch (AtlasServiceException e) {
+ System.err.println("Could not retrieve metrics of the server at " + Arrays.toString(atlasServerUri));
+ printStandardHttpErrorDetails(e);
+ }
+ } else {
+ System.err.println("Unsupported option. Refer to usage for valid options.");
+ printUsage(INVALID_OPTIONS_STATUS);
+ }
+ return cmdStatus;
+ }
+
+ private void printStandardHttpErrorDetails(AtlasServiceException e) {
+ System.err.println("Error details: ");
+ System.err.println("HTTP Status: " + e.getStatus().getStatusCode() + ","
+ + e.getStatus().getReasonPhrase());
+ System.err.println("Exception message: " + e.getMessage());
+ }
+
+ private CommandLine parseCommandLineOptions(String[] args) {
+ if (args.length == 0) {
+ printUsage(INVALID_OPTIONS_STATUS);
+ }
+ CommandLineParser parser = new GnuParser();
+ CommandLine commandLine = null;
+ try {
+ commandLine = parser.parse(OPTIONS, args);
+ } catch (ParseException e) {
+ System.err.println("Could not parse command line options.");
+ printUsage(INVALID_OPTIONS_STATUS);
+ }
+ return commandLine;
+ }
+
+ private void printUsage(int statusCode) {
+ HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.printHelp("atlas_admin.py", OPTIONS);
+ System.exit(statusCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
----------------------------------------------------------------------
diff --git a/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
new file mode 100644
index 0000000..6d0b83d
--- /dev/null
+++ b/client/client-v1/src/main/java/org/apache/atlas/AtlasClient.java
@@ -0,0 +1,974 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableSet;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.atlas.model.legacy.EntityResult;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.Struct;
+import org.apache.atlas.typesystem.TypesDef;
+import org.apache.atlas.typesystem.json.InstanceSerialization;
+import org.apache.atlas.typesystem.json.TypesSerialization;
+import org.apache.atlas.typesystem.types.AttributeDefinition;
+import org.apache.atlas.typesystem.types.DataTypes;
+import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
+import org.apache.atlas.typesystem.types.TraitType;
+import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Client for metadata.
+ */
+@Deprecated
+public class AtlasClient extends AtlasBaseClient {
+ private static final Logger LOG = LoggerFactory.getLogger(AtlasClient.class);
+
+ public static final String TYPE = "type";
+ public static final String TYPENAME = "typeName";
+ public static final String GUID = "GUID";
+ public static final String ENTITIES = "entities";
+ public static final String GUID_ASSIGNMENTS = "guidAssignments";
+
+ public static final String DEFINITION = "definition";
+ public static final String ERROR = "error";
+ public static final String STACKTRACE = "stackTrace";
+ public static final String REQUEST_ID = "requestId";
+ public static final String RESULTS = "results";
+ public static final String COUNT = "count";
+ public static final String ROWS = "rows";
+ public static final String DATATYPE = "dataType";
+ public static final String STATUS = "Status";
+
+ public static final String EVENTS = "events";
+ public static final String START_KEY = "startKey";
+ public static final String NUM_RESULTS = "count";
+
+ public static final String URI_ENTITY = "entities";
+ public static final String URI_ENTITY_AUDIT = "audit";
+ public static final String URI_SEARCH = "discovery/search";
+ public static final String URI_NAME_LINEAGE = "lineage/hive/table";
+ public static final String URI_LINEAGE = "lineage/";
+ public static final String URI_TRAITS = "traits";
+ public static final String TRAITS = "traits";
+ public static final String TRAIT_DEFINITIONS = "traitDefinitions";
+
+
+ public static final String QUERY_TYPE = "queryType";
+ public static final String ATTRIBUTE_NAME = "property";
+ public static final String ATTRIBUTE_VALUE = "value";
+
+ public static final String SUPERTYPE = "supertype";
+ public static final String NOT_SUPERTYPE = "notsupertype";
+
+ public static final String ASSET_TYPE = "Asset";
+ public static final String NAME = "name";
+ public static final String DESCRIPTION = "description";
+ public static final String OWNER = "owner";
+ public static final String CREATE_TIME = "createTime";
+
+ public static final String INFRASTRUCTURE_SUPER_TYPE = "Infrastructure";
+ public static final String DATA_SET_SUPER_TYPE = "DataSet";
+ public static final String PROCESS_SUPER_TYPE = "Process";
+ public static final String PROCESS_ATTRIBUTE_INPUTS = "inputs";
+ public static final String PROCESS_ATTRIBUTE_OUTPUTS = "outputs";
+
+ public static final String REFERENCEABLE_SUPER_TYPE = "Referenceable";
+ public static final String QUALIFIED_NAME = "qualifiedName";
+ public static final String REFERENCEABLE_ATTRIBUTE_NAME = QUALIFIED_NAME;
+
+ public static final String UNKNOWN_STATUS = "Unknown status";
+
+ /**
+ * Constructor for AtlasClient with cookie params as header
+ * @param baseUrl
+ * @param cookieName
+ * @param value
+ * @param path
+ * @param domain
+ */
+
+ public AtlasClient(String[] baseUrl, String cookieName, String value, String path, String domain) {
+ super(baseUrl, new Cookie(cookieName, value, path, domain));
+ }
+
+ /**
+ * Constructor for AtlasClient with cookie as header
+ * @param baseUrl
+ * @param cookie
+ */
+
+ public AtlasClient(String[] baseUrl, Cookie cookie) {
+ super(baseUrl, cookie);
+ }
+
+
+ // New constructor for Basic auth
+ public AtlasClient(String[] baseUrl, String[] basicAuthUserNamePassword) {
+ super(baseUrl, basicAuthUserNamePassword);
+ }
+
+ /**
+ * Create a new Atlas client.
+ * @param baseUrls A list of URLs that point to an ensemble of Atlas servers working in
+ * High Availability mode. The client will automatically determine the
+ * active instance on startup and also when there is a scenario of
+ * failover.
+ */
+ public AtlasClient(String... baseUrls) throws AtlasException {
+ this(getCurrentUGI(), baseUrls);
+ }
+
+ /**
+ * Create a new Atlas client.
+ * @param ugi UserGroupInformation
+ * @param doAsUser
+ * @param baseUrls A list of URLs that point to an ensemble of Atlas servers working in
+ * High Availability mode. The client will automatically determine the
+ * active instance on startup and also when there is a scenario of
+ * failover.
+ */
+ public AtlasClient(UserGroupInformation ugi, String doAsUser, String... baseUrls) {
+ initializeState(baseUrls, ugi, doAsUser);
+ }
+
+ private AtlasClient(UserGroupInformation ugi, String[] baseUrls) {
+ this(ugi, ugi.getShortUserName(), baseUrls);
+ }
+
+ //Used by LocalAtlasClient
+ protected AtlasClient() {
+ //Do nothing
+ }
+
+ @VisibleForTesting
+ public AtlasClient(Configuration configuration, String[] baseUrl, String[] basicAuthUserNamePassword) {
+ super(configuration, baseUrl, basicAuthUserNamePassword);
+ }
+
+ @Override
+ protected API formatPathParameters(final API api, final String... params) {
+ return new API(String.format(api.getPath(), params), api.getMethod(), api.getExpectedStatus());
+ }
+
+ @VisibleForTesting
+ public AtlasClient(Configuration configuration, String... baseUrls) throws AtlasException {
+ initializeState(configuration, baseUrls, getCurrentUGI(), getCurrentUGI().getShortUserName());
+ }
+
+ @VisibleForTesting
+ AtlasClient(WebResource service, Configuration configuration) {
+ super(service, configuration);
+ }
+
+ public WebResource getResource() {
+ return service;
+ }
+
+ public static class API_V1 extends API {
+ //Admin operations
+ public static final API_V1 VERSION = new API_V1(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 STATUS = new API_V1(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK);
+
+ //Type operations
+ public static final API_V1 CREATE_TYPE = new API_V1(BASE_URI + TYPES, HttpMethod.POST, Response.Status.CREATED);
+ public static final API_V1 UPDATE_TYPE = new API_V1(BASE_URI + TYPES, HttpMethod.PUT, Response.Status.OK);
+ public static final API_V1 GET_TYPE = new API_V1(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LIST_TYPES = new API_V1(BASE_URI + TYPES, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LIST_TRAIT_TYPES = new API_V1(BASE_URI + TYPES + "?type=trait", HttpMethod.GET, Response.Status.OK);
+
+ //Entity operations
+ public static final API_V1 CREATE_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED);
+ public static final API_V1 GET_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 UPDATE_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.PUT, Response.Status.OK);
+ public static final API_V1 UPDATE_ENTITY_PARTIAL = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.OK);
+ public static final API_V1 LIST_ENTITIES = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 DELETE_ENTITIES = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V1 DELETE_ENTITY = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK);
+
+ //audit operation
+ public static final API_V1 LIST_ENTITY_AUDIT = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+
+ //Trait operations
+ public static final API_V1 ADD_TRAITS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.POST, Response.Status.CREATED);
+ public static final API_V1 DELETE_TRAITS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V1 LIST_TRAITS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 GET_ALL_TRAIT_DEFINITIONS = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 GET_TRAIT_DEFINITION = new API_V1(BASE_URI + URI_ENTITY, HttpMethod.GET, Response.Status.OK);
+
+ //Search operations
+ public static final API_V1 SEARCH = new API_V1(BASE_URI + URI_SEARCH, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 SEARCH_DSL = new API_V1(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 SEARCH_FULL_TEXT = new API_V1(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 GREMLIN_SEARCH = new API_V1(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET, Response.Status.OK);
+
+ //Lineage operations based on dataset name
+ public static final API_V1 NAME_LINEAGE_INPUTS_GRAPH = new API_V1(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 NAME_LINEAGE_OUTPUTS_GRAPH = new API_V1(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 NAME_LINEAGE_SCHEMA = new API_V1(BASE_URI + URI_NAME_LINEAGE, HttpMethod.GET, Response.Status.OK);
+
+ //Lineage operations based on entity id of the dataset
+ public static final API_V1 LINEAGE_INPUTS_GRAPH = new API_V1(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LINEAGE_OUTPUTS_GRAPH = new API_V1(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
+ public static final API_V1 LINEAGE_SCHEMA = new API_V1(BASE_URI + URI_LINEAGE, HttpMethod.GET, Response.Status.OK);
+
+ private API_V1(String path, String method, Response.Status status) {
+ super(path, method, status);
+ }
+ }
+
+ /**
+ * Register the given type(meta model)
+ * @param typeAsJson type definition a jaon
+ * @return result json object
+ * @throws AtlasServiceException
+ */
+ public List<String> createType(String typeAsJson) throws AtlasServiceException {
+ LOG.debug("Creating type definition: {}", typeAsJson);
+ JSONObject response = callAPIWithBody(API_V1.CREATE_TYPE, typeAsJson);
+ List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {
+ @Override
+ String extractElement(JSONObject element) throws JSONException {
+ return element.getString(AtlasClient.NAME);
+ }
+ });
+ LOG.debug("Create type definition returned results: {}", results);
+ return results;
+ }
+
+ /**
+ * Register the given type(meta model)
+ * @param typeDef type definition
+ * @return result json object
+ * @throws AtlasServiceException
+ */
+ public List<String> createType(TypesDef typeDef) throws AtlasServiceException {
+ return createType(TypesSerialization.toJson(typeDef));
+ }
+
+ /**
+ * Creates trait type with specifiedName, superTraits and attributes
+ * @param traitName the name of the trait type
+ * @param superTraits the list of super traits from which this trait type inherits attributes
+ * @param attributeDefinitions the list of attributes of the trait type
+ * @return the list of types created
+ * @throws AtlasServiceException
+ */
+ public List<String> createTraitType(String traitName, ImmutableSet<String> superTraits, AttributeDefinition... attributeDefinitions) throws AtlasServiceException {
+ HierarchicalTypeDefinition<TraitType> piiTrait =
+ TypesUtil.createTraitTypeDef(traitName, superTraits, attributeDefinitions);
+
+ String traitDefinitionAsJSON = TypesSerialization.toJson(piiTrait, true);
+ LOG.debug("Creating trait type {} {}", traitName, traitDefinitionAsJSON);
+ return createType(traitDefinitionAsJSON);
+ }
+
+ /**
+ * Creates simple trait type with specifiedName with no superTraits or attributes
+ * @param traitName the name of the trait type
+ * @return the list of types created
+ * @throws AtlasServiceException
+ */
+ public List<String> createTraitType(String traitName) throws AtlasServiceException {
+ return createTraitType(traitName, null);
+ }
+
+ /**
+ * Register the given type(meta model)
+ * @param typeAsJson type definition a jaon
+ * @return result json object
+ * @throws AtlasServiceException
+ */
+ public List<String> updateType(String typeAsJson) throws AtlasServiceException {
+ LOG.debug("Updating type definition: {}", typeAsJson);
+ JSONObject response = callAPIWithBody(API_V1.UPDATE_TYPE, typeAsJson);
+ List<String> results = extractResults(response, AtlasClient.TYPES, new ExtractOperation<String, JSONObject>() {
+ @Override
+ String extractElement(JSONObject element) throws JSONException {
+ return element.getString(AtlasClient.NAME);
+ }
+ });
+ LOG.debug("Update type definition returned results: {}", results);
+ return results;
+ }
+
+ /**
+ * Register the given type(meta model)
+ * @param typeDef type definition
+ * @return result json object
+ * @throws AtlasServiceException
+ */
+ public List<String> updateType(TypesDef typeDef) throws AtlasServiceException {
+ return updateType(TypesSerialization.toJson(typeDef));
+ }
+
+ /**
+ * Returns all type names in the system
+ * @return list of type names
+ * @throws AtlasServiceException
+ */
+ public List<String> listTypes() throws AtlasServiceException {
+ final JSONObject jsonObject = callAPIWithQueryParams(API_V1.LIST_TYPES, null);
+ return extractResults(jsonObject, AtlasClient.RESULTS, new ExtractOperation<String, String>());
+ }
+
+ /**
+ * Returns all type names with the given category
+ * @param category
+ * @return list of type names
+ * @throws AtlasServiceException
+ */
+ public List<String> listTypes(final DataTypes.TypeCategory category) throws AtlasServiceException {
+ final API api = API_V1.LIST_TYPES;
+ JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api.getPath());
+ resource = resource.queryParam(TYPE, category.name());
+ return resource;
+ }
+ });
+ return extractResults(response, AtlasClient.RESULTS, new ExtractOperation<String, String>());
+ }
+
+ /**
+ * Return the list of type names in the type system which match the specified filter.
+ *
+ * @param category returns types whose category is the given typeCategory
+ * @param superType returns types which contain the given supertype
+ * @param notSupertype returns types which do not contain the given supertype
+ *
+ * Its possible to specify combination of these filters in one request and the conditions are combined with AND
+ * For example, typeCategory = TRAIT && supertype contains 'X' && supertype !contains 'Y'
+ * If there is no filter, all the types are returned
+ * @return list of type names
+ */
+ public List<String> listTypes(final DataTypes.TypeCategory category, final String superType,
+ final String notSupertype) throws AtlasServiceException {
+ final API api = API_V1.LIST_TYPES;
+ JSONObject response = callAPIWithRetries(api, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api);
+ resource = resource.queryParam(TYPE, category.name());
+ resource = resource.queryParam(SUPERTYPE, superType);
+ resource = resource.queryParam(NOT_SUPERTYPE, notSupertype);
+ return resource;
+ }
+ });
+ return extractResults(response, AtlasClient.RESULTS, new ExtractOperation<String, String>());
+ }
+
+ public TypesDef getType(String typeName) throws AtlasServiceException {
+ try {
+ JSONObject response = callAPIWithBodyAndParams(API_V1.GET_TYPE, null, typeName);
+ String typeJson = response.getString(DEFINITION);
+ return TypesSerialization.fromJson(typeJson);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ /**
+ * Create the given entity
+ * @param entities entity(type instance) as json
+ * @return json array of guids
+ * @throws AtlasServiceException
+ */
+ protected List<String> createEntity(JSONArray entities) throws AtlasServiceException {
+ LOG.debug("Creating entities: {}", entities);
+ JSONObject response = callAPIWithBody(API_V1.CREATE_ENTITY, entities.toString());
+ List<String> results = extractEntityResult(response).getCreatedEntities();
+ LOG.debug("Create entities returned results: {}", results);
+ return results;
+ }
+
+ protected EntityResult extractEntityResult(JSONObject response) throws AtlasServiceException {
+ return EntityResult.fromString(response.toString());
+ }
+
+ /**
+ * Create the given entity
+ * @param entitiesAsJson entity(type instance) as json
+ * @return json array of guids
+ * @throws AtlasServiceException
+ */
+ public List<String> createEntity(String... entitiesAsJson) throws AtlasServiceException {
+ return createEntity(new JSONArray(Arrays.asList(entitiesAsJson)));
+ }
+
+ public List<String> createEntity(Referenceable... entities) throws AtlasServiceException {
+ return createEntity(Arrays.asList(entities));
+ }
+
+ public List<String> createEntity(Collection<Referenceable> entities) throws AtlasServiceException {
+ JSONArray entityArray = getEntitiesArray(entities);
+ return createEntity(entityArray);
+ }
+
+ private JSONArray getEntitiesArray(Collection<Referenceable> entities) {
+ JSONArray entityArray = new JSONArray(entities.size());
+ for (Referenceable entity : entities) {
+ entityArray.put(InstanceSerialization.toJson(entity, true));
+ }
+ return entityArray;
+ }
+
+ /**
+ * Replaces entity definitions identified by their guid or unique attribute
+ * Updates properties set in the definition for the entity corresponding to guid
+ * @param entities entities to be updated
+ * @return json array of guids which were updated/created
+ * @throws AtlasServiceException
+ */
+ public EntityResult updateEntities(Referenceable... entities) throws AtlasServiceException {
+ return updateEntities(Arrays.asList(entities));
+ }
+
+ protected EntityResult updateEntities(JSONArray entities) throws AtlasServiceException {
+ LOG.debug("Updating entities: {}", entities);
+ JSONObject response = callAPIWithBody(API_V1.UPDATE_ENTITY, entities.toString());
+ EntityResult results = extractEntityResult(response);
+ LOG.debug("Update entities returned results: {}", results);
+ return results;
+ }
+
+ public EntityResult updateEntities(Collection<Referenceable> entities) throws AtlasServiceException {
+ JSONArray entitiesArray = getEntitiesArray(entities);
+ return updateEntities(entitiesArray);
+ }
+
+ /**
+ * Supports Partial updates
+ * Updates property for the entity corresponding to guid
+ * @param guid guid
+ * @param attribute property key
+ * @param value property value
+ */
+ public EntityResult updateEntityAttribute(final String guid, final String attribute, String value)
+ throws AtlasServiceException {
+ LOG.debug("Updating entity id: {}, attribute name: {}, attribute value: {}", guid, attribute, value);
+ final API api = API_V1.UPDATE_ENTITY_PARTIAL;
+ JSONObject response = callAPIWithRetries(api, value, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api, guid);
+ resource = resource.queryParam(ATTRIBUTE_NAME, attribute);
+ return resource;
+ }
+ });
+ return extractEntityResult(response);
+ }
+
+ /**
+ * Supports Partial updates
+ * Updates properties set in the definition for the entity corresponding to guid
+ * @param guid guid
+ * @param entity entity definition
+ */
+ public EntityResult updateEntity(String guid, Referenceable entity) throws AtlasServiceException {
+ String entityJson = InstanceSerialization.toJson(entity, true);
+ LOG.debug("Updating entity id {} with {}", guid, entityJson);
+ JSONObject response = callAPIWithBodyAndParams(API_V1.UPDATE_ENTITY_PARTIAL, entityJson, guid);
+ return extractEntityResult(response);
+ }
+
+ /**
+ * Associate trait to an entity
+ *
+ * @param guid guid
+ * @param traitDefinition trait definition
+ */
+ public void addTrait(String guid, Struct traitDefinition) throws AtlasServiceException {
+ String traitJson = InstanceSerialization.toJson(traitDefinition, true);
+ LOG.debug("Adding trait to entity with id {} {}", guid, traitJson);
+ callAPIWithBodyAndParams(API_V1.ADD_TRAITS, traitJson, guid, URI_TRAITS);
+ }
+
+ /**
+ * Delete a trait from the given entity
+ * @param guid guid of the entity
+ * @param traitName trait to be deleted
+ * @throws AtlasServiceException
+ */
+ public void deleteTrait(String guid, String traitName) throws AtlasServiceException {
+ callAPIWithBodyAndParams(API_V1.DELETE_TRAITS, null, guid, TRAITS, traitName);
+ }
+
+ /**
+ * Supports Partial updates
+ * Updates properties set in the definition for the entity corresponding to guid
+ * @param entityType Type of the entity being updated
+ * @param uniqueAttributeName Attribute Name that uniquely identifies the entity
+ * @param uniqueAttributeValue Attribute Value that uniquely identifies the entity
+ * @param entity entity definition
+ */
+ public EntityResult updateEntity(final String entityType, final String uniqueAttributeName,
+ final String uniqueAttributeValue,
+ Referenceable entity) throws AtlasServiceException {
+ final API api = API_V1.UPDATE_ENTITY_PARTIAL;
+ String entityJson = InstanceSerialization.toJson(entity, true);
+ LOG.debug("Updating entity type: {}, attributeName: {}, attributeValue: {}, entity: {}", entityType,
+ uniqueAttributeName, uniqueAttributeValue, entityJson);
+ JSONObject response = callAPIWithRetries(api, entityJson, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api, QUALIFIED_NAME);
+ resource = resource.queryParam(TYPE, entityType);
+ resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
+ resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
+ return resource;
+ }
+ });
+ EntityResult result = extractEntityResult(response);
+ LOG.debug("Update entity returned result: {}", result);
+ return result;
+ }
+
+ protected String getString(JSONObject jsonObject, String parameter) throws AtlasServiceException {
+ try {
+ return jsonObject.getString(parameter);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ /**
+ * Delete the specified entities from the repository
+ *
+ * @param guids guids of entities to delete
+ * @return List of entity ids updated/deleted
+ * @throws AtlasServiceException
+ */
+ public EntityResult deleteEntities(final String... guids) throws AtlasServiceException {
+ LOG.debug("Deleting entities: {}", guids);
+ final API api = API_V1.DELETE_ENTITIES;
+ JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api);
+ for (String guid : guids) {
+ resource = resource.queryParam(GUID.toLowerCase(), guid);
+ }
+ return resource;
+ }
+ });
+ EntityResult results = extractEntityResult(jsonResponse);
+ LOG.debug("Delete entities returned results: {}", results);
+ return results;
+ }
+
+ /**
+ * Supports Deletion of an entity identified by its unique attribute value
+ * @param entityType Type of the entity being deleted
+ * @param uniqueAttributeName Attribute Name that uniquely identifies the entity
+ * @param uniqueAttributeValue Attribute Value that uniquely identifies the entity
+ * @return List of entity ids updated/deleted(including composite references from that entity)
+ */
+ public EntityResult deleteEntity(String entityType, String uniqueAttributeName, String uniqueAttributeValue)
+ throws AtlasServiceException {
+ LOG.debug("Deleting entity type: {}, attributeName: {}, attributeValue: {}", entityType, uniqueAttributeName,
+ uniqueAttributeValue);
+ API api = API_V1.DELETE_ENTITIES;
+ WebResource resource = getResource(api);
+ resource = resource.queryParam(TYPE, entityType);
+ resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
+ resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
+ JSONObject jsonResponse = callAPIWithResource(api, resource);
+ EntityResult results = extractEntityResult(jsonResponse);
+ LOG.debug("Delete entities returned results: {}", results);
+ return results;
+ }
+
+ /**
+ * Get an entity given the entity id
+ * @param guid entity id
+ * @return result object
+ * @throws AtlasServiceException
+ */
+ public Referenceable getEntity(String guid) throws AtlasServiceException {
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ENTITY, null, guid);
+ try {
+ String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
+ return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(API_V1.GET_ENTITY, e);
+ }
+ }
+
+ public static String toString(JSONArray jsonArray) throws JSONException {
+ ArrayList<String> resultsList = new ArrayList<>();
+ for (int index = 0; index < jsonArray.length(); index++) {
+ resultsList.add(jsonArray.getString(index));
+ }
+ return StringUtils.join(resultsList, ",");
+ }
+
+ /**
+ * Get an entity given the entity id
+ * @param entityType entity type name
+ * @param attribute qualified name of the entity
+ * @param value
+ * @return result object
+ * @throws AtlasServiceException
+ */
+ public Referenceable getEntity(final String entityType, final String attribute, final String value)
+ throws AtlasServiceException {
+ final API api = API_V1.GET_ENTITY;
+ JSONObject jsonResponse = callAPIWithRetries(api, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api);
+ resource = resource.queryParam(TYPE, entityType);
+ resource = resource.queryParam(ATTRIBUTE_NAME, attribute);
+ resource = resource.queryParam(ATTRIBUTE_VALUE, value);
+ return resource;
+ }
+ });
+ try {
+ String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION);
+ return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(api, e);
+ }
+ }
+
+ /**
+ * List entities for a given entity type
+ * @param entityType
+ * @return
+ * @throws AtlasServiceException
+ */
+ public List<String> listEntities(final String entityType) throws AtlasServiceException {
+ JSONObject jsonResponse = callAPIWithRetries(API_V1.LIST_ENTITIES, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(API_V1.LIST_ENTITIES);
+ resource = resource.queryParam(TYPE, entityType);
+ return resource;
+ }
+ });
+ return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>());
+ }
+
+ /**
+ * List traits for a given entity identified by its GUID
+ * @param guid GUID of the entity
+ * @return List<String> - traitnames associated with entity
+ * @throws AtlasServiceException
+ */
+ public List<String> listTraits(final String guid) throws AtlasServiceException {
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.LIST_TRAITS, null, guid, URI_TRAITS);
+ return extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<String, String>());
+ }
+
+ /**
+ * Get all trait definitions for an entity
+ * @param guid GUID of the entity
+ * @return List<String> trait definitions of the traits associated to the entity
+ * @throws AtlasServiceException
+ */
+ public List<Struct> listTraitDefinitions(final String guid) throws AtlasServiceException {
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_ALL_TRAIT_DEFINITIONS, null, guid, TRAIT_DEFINITIONS);
+ List<JSONObject> traitDefList = extractResults(jsonResponse, AtlasClient.RESULTS, new ExtractOperation<JSONObject, JSONObject>());
+ ArrayList<Struct> traitStructList = new ArrayList<>();
+ for (JSONObject traitDef : traitDefList) {
+ Struct traitStruct = InstanceSerialization.fromJsonStruct(traitDef.toString(), true);
+ traitStructList.add(traitStruct);
+ }
+ return traitStructList;
+ }
+
+ /**
+ * Get trait definition for a given entity and traitname
+ * @param guid GUID of the entity
+ * @param traitName
+ * @return trait definition
+ * @throws AtlasServiceException
+ */
+ public Struct getTraitDefinition(final String guid, final String traitName) throws AtlasServiceException {
+ JSONObject jsonResponse = callAPIWithBodyAndParams(API_V1.GET_TRAIT_DEFINITION, null, guid, TRAIT_DEFINITIONS, traitName);
+
+ try {
+ return InstanceSerialization.fromJsonStruct(jsonResponse.getString(AtlasClient.RESULTS), false);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(API_V1.GET_TRAIT_DEFINITION, e);
+ }
+ }
+
+ protected class ExtractOperation<T, U> {
+ T extractElement(U element) throws JSONException {
+ return (T) element;
+ }
+ }
+
+ protected <T, U> List<T> extractResults(JSONObject jsonResponse, String key, ExtractOperation<T, U> extractInterafce)
+ throws AtlasServiceException {
+ try {
+ JSONArray results = jsonResponse.getJSONArray(key);
+ ArrayList<T> resultsList = new ArrayList<>();
+ for (int index = 0; index < results.length(); index++) {
+ Object element = results.get(index);
+ resultsList.add(extractInterafce.extractElement((U) element));
+ }
+ return resultsList;
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ /**
+ * Get the latest numResults entity audit events in decreasing order of timestamp for the given entity id
+ * @param entityId entity id
+ * @param numResults number of results to be returned
+ * @return list of audit events for the entity id
+ * @throws AtlasServiceException
+ */
+ public List<EntityAuditEvent> getEntityAuditEvents(String entityId, short numResults)
+ throws AtlasServiceException {
+ return getEntityAuditEvents(entityId, null, numResults);
+ }
+
+ /**
+ * Get the entity audit events in decreasing order of timestamp for the given entity id
+ * @param entityId entity id
+ * @param startKey key for the first event to be returned, used for pagination
+ * @param numResults number of results to be returned
+ * @return list of audit events for the entity id
+ * @throws AtlasServiceException
+ */
+ public List<EntityAuditEvent> getEntityAuditEvents(String entityId, String startKey, short numResults)
+ throws AtlasServiceException {
+ WebResource resource = getResource(API_V1.LIST_ENTITY_AUDIT, entityId, URI_ENTITY_AUDIT);
+ if (StringUtils.isNotEmpty(startKey)) {
+ resource = resource.queryParam(START_KEY, startKey);
+ }
+ resource = resource.queryParam(NUM_RESULTS, String.valueOf(numResults));
+
+ JSONObject jsonResponse = callAPIWithResource(API_V1.LIST_ENTITY_AUDIT, resource);
+ return extractResults(jsonResponse, AtlasClient.EVENTS, new ExtractOperation<EntityAuditEvent, JSONObject>() {
+ @Override
+ EntityAuditEvent extractElement(JSONObject element) throws JSONException {
+ return SerDe.GSON.fromJson(element.toString(), EntityAuditEvent.class);
+ }
+ });
+
+ }
+
+ /**
+ * Search using dsl/full text
+ * @param searchQuery
+ * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
+ * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
+ * @return Query results
+ * @throws AtlasServiceException
+ */
+ public JSONArray search(final String searchQuery, final int limit, final int offset) throws AtlasServiceException {
+ final API api = API_V1.SEARCH;
+ JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api);
+ resource = resource.queryParam(QUERY, searchQuery);
+ resource = resource.queryParam(LIMIT, String.valueOf(limit));
+ resource = resource.queryParam(OFFSET, String.valueOf(offset));
+ return resource;
+ }
+ });
+ try {
+ return result.getJSONArray(RESULTS);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+
+ }
+
+ /**
+ * Search given query DSL
+ * @param query DSL query
+ * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
+ * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
+ * @return result json object
+ * @throws AtlasServiceException
+ */
+ public JSONArray searchByDSL(final String query, final int limit, final int offset) throws AtlasServiceException {
+ LOG.debug("DSL query: {}", query);
+ final API api = API_V1.SEARCH_DSL;
+ JSONObject result = callAPIWithRetries(api, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api);
+ resource = resource.queryParam(QUERY, query);
+ resource = resource.queryParam(LIMIT, String.valueOf(limit));
+ resource = resource.queryParam(OFFSET, String.valueOf(offset));
+ return resource;
+ }
+ });
+ try {
+ return result.getJSONArray(RESULTS);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ /**
+ * Search given full text search
+ * @param query Query
+ * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
+ * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
+ * @return result json object
+ * @throws AtlasServiceException
+ */
+ public JSONObject searchByFullText(final String query, final int limit, final int offset) throws AtlasServiceException {
+ final API api = API_V1.SEARCH_FULL_TEXT;
+ return callAPIWithRetries(api, null, new ResourceCreator() {
+ @Override
+ public WebResource createResource() {
+ WebResource resource = getResource(api);
+ resource = resource.queryParam(QUERY, query);
+ resource = resource.queryParam(LIMIT, String.valueOf(limit));
+ resource = resource.queryParam(OFFSET, String.valueOf(offset));
+ return resource;
+ }
+ });
+ }
+
+ public JSONObject getInputGraph(String datasetName) throws AtlasServiceException {
+ JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, datasetName, "/inputs/graph");
+ try {
+ return response.getJSONObject(AtlasClient.RESULTS);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ public JSONObject getOutputGraph(String datasetName) throws AtlasServiceException {
+ JSONObject response = callAPIWithBodyAndParams(API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, datasetName, "/outputs/graph");
+ try {
+ return response.getJSONObject(AtlasClient.RESULTS);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ public JSONObject getInputGraphForEntity(String entityId) throws AtlasServiceException {
+ JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_INPUTS_GRAPH, null, entityId, "/inputs/graph");
+ try {
+ return response.getJSONObject(AtlasClient.RESULTS);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ public JSONObject getOutputGraphForEntity(String datasetId) throws AtlasServiceException {
+ JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/outputs/graph");
+ try {
+ return response.getJSONObject(AtlasClient.RESULTS);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ public JSONObject getSchemaForEntity(String datasetId) throws AtlasServiceException {
+ JSONObject response = callAPIWithBodyAndParams(API_V1.LINEAGE_OUTPUTS_GRAPH, null, datasetId, "/schema");
+ try {
+ return response.getJSONObject(AtlasClient.RESULTS);
+ } catch (JSONException e) {
+ throw new AtlasServiceException(e);
+ }
+ }
+
+ // Wrapper methods for compatibility
+ @VisibleForTesting
+ public JSONObject callAPIWithResource(API api, WebResource resource) throws AtlasServiceException {
+ return callAPIWithResource(api, resource, null, JSONObject.class);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithResource(API_V1 apiV1, WebResource resource) throws AtlasServiceException {
+ return callAPIWithResource(apiV1, resource, null, JSONObject.class);
+ }
+
+ @VisibleForTesting
+ public WebResource getResource(API api, String... params) {
+ return getResource(api.getPath(), params);
+ }
+
+ @VisibleForTesting
+ public WebResource getResource(API_V1 apiV1, String... params) {
+ return getResource(apiV1.getPath(), params);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithBody(API api, Object requestObject) throws AtlasServiceException {
+ return callAPI(api, JSONObject.class, requestObject, (String[]) null);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithBody(API_V1 apiV1, Object requestObject) throws AtlasServiceException {
+ return callAPI(apiV1, JSONObject.class, requestObject, (String[]) null);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String... params) throws AtlasServiceException {
+ return callAPI(api, JSONObject.class, requestObject, params);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithBodyAndParams(API_V1 apiV1, Object requestObject, String... params) throws AtlasServiceException {
+ return callAPI(apiV1, JSONObject.class, requestObject, params);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
+ return callAPI(api, JSONObject.class, queryParams);
+ }
+
+ @VisibleForTesting
+ public JSONObject callAPIWithQueryParams(API_V1 apiV1, MultivaluedMap<String, String> queryParams) throws AtlasServiceException {
+ return callAPI(apiV1, JSONObject.class, queryParams);
+ }
+
+ @VisibleForTesting
+ JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
+ return super.callAPIWithRetries(api, requestObject, resourceCreator);
+ }
+
+ @VisibleForTesting
+ JSONObject callAPIWithRetries(API_V1 apiV1, Object requestObject, ResourceCreator resourceCreator) throws AtlasServiceException {
+ return super.callAPIWithRetries(apiV1, requestObject, resourceCreator);
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v1/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
----------------------------------------------------------------------
diff --git a/client/client-v1/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java b/client/client-v1/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
new file mode 100644
index 0000000..5e6d6db
--- /dev/null
+++ b/client/client-v1/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
@@ -0,0 +1,124 @@
+/**
+ * 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;
+
+import org.apache.atlas.model.instance.GuidMapping;
+import org.apache.atlas.model.legacy.EntityResult;
+import org.apache.atlas.type.AtlasType;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Result from creating or updating entities.
+ */
+@Deprecated
+public class CreateUpdateEntitiesResult {
+
+ /**
+ * Guid mapping for the entities that were created/updated
+ */
+ private GuidMapping guidMapping;
+
+ /**
+ * Entity result
+ */
+ private EntityResult entityResult;
+
+ /**
+ * Gets the guid mapping
+ */
+ public GuidMapping getGuidMapping() {
+ return guidMapping;
+ }
+
+ /**
+ * Sets the guid mapping
+ */
+ public void setGuidMapping(GuidMapping guidMapping) {
+ this.guidMapping = guidMapping;
+ }
+
+ /**
+ * Gets the entity result
+ */
+ public EntityResult getEntityResult() {
+ return entityResult;
+ }
+
+ /**
+ * Sets the entity result
+ */
+ public void setEntityResult(EntityResult entityResult) {
+ this.entityResult = entityResult;
+ }
+
+ /**
+ * Deserializes the given json into an instance of
+ * CreateUpdateEntitiesResult.
+ *
+ * @param json
+ * the (unmodified) json that comes back from Atlas.
+ * @return
+ * @throws AtlasServiceException
+ */
+ public static CreateUpdateEntitiesResult fromJson(String json) throws AtlasServiceException {
+
+ GuidMapping guidMapping = AtlasType.fromJson(json, GuidMapping.class);
+ EntityResult entityResult = EntityResult.fromString(json);
+ CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
+ result.setEntityResult(entityResult);
+ result.setGuidMapping(guidMapping);
+ return result;
+ }
+
+ /**
+ * Convenience method to get the guids of the created entities from
+ * the EntityResult.
+ */
+ public List<String> getCreatedEntities() {
+ if(entityResult == null) {
+ return Collections.emptyList();
+ }
+ return getEntityResult().getCreatedEntities();
+ }
+
+ /**
+ * Convenience method to get the guids of the updated entities from
+ * the EntityResult.
+ */
+ public List<String> getUpdatedEntities() {
+ if(entityResult == null) {
+ return Collections.emptyList();
+ }
+ return getEntityResult().getUpdateEntities();
+ }
+
+
+ /**
+ * Convenience method to get the guids of the deleted entities
+ * from the EntityResult.
+ */
+ public List<String> getDeletedEntities() {
+ if (entityResult == null) {
+ return Collections.emptyList();
+ }
+ return getEntityResult().getDeletedEntities();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v1/src/main/java/org/apache/atlas/EntityAuditEvent.java
----------------------------------------------------------------------
diff --git a/client/client-v1/src/main/java/org/apache/atlas/EntityAuditEvent.java b/client/client-v1/src/main/java/org/apache/atlas/EntityAuditEvent.java
new file mode 100644
index 0000000..904674d
--- /dev/null
+++ b/client/client-v1/src/main/java/org/apache/atlas/EntityAuditEvent.java
@@ -0,0 +1,146 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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;
+
+import org.apache.atlas.typesystem.IReferenceableInstance;
+import org.apache.atlas.typesystem.json.InstanceSerialization;
+
+import java.util.Objects;
+
+/**
+ * Structure of entity audit event
+ */
+public class EntityAuditEvent {
+ public enum EntityAuditAction {
+ ENTITY_CREATE, ENTITY_UPDATE, ENTITY_DELETE, TAG_ADD, TAG_DELETE, TAG_UPDATE,
+ ENTITY_IMPORT_CREATE, ENTITY_IMPORT_UPDATE, ENTITY_IMPORT_DELETE,
+ }
+
+ private String entityId;
+ private long timestamp;
+ private String user;
+ private EntityAuditAction action;
+ private String details;
+ private String eventKey;
+ private IReferenceableInstance entityDefinition;
+
+ public EntityAuditEvent() {
+ }
+
+ public EntityAuditEvent(String entityId, Long ts, String user, EntityAuditAction action, String details,
+ IReferenceableInstance entityDefinition) throws AtlasException {
+ this.entityId = entityId;
+ this.timestamp = ts;
+ this.user = user;
+ this.action = action;
+ this.details = details;
+ this.entityDefinition = entityDefinition;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ EntityAuditEvent that = (EntityAuditEvent) o;
+ return timestamp == that.timestamp &&
+ Objects.equals(entityId, that.entityId) &&
+ Objects.equals(user, that.user) &&
+ action == that.action &&
+ Objects.equals(details, that.details) &&
+ Objects.equals(eventKey, that.eventKey) &&
+ Objects.equals(entityDefinition, that.entityDefinition);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(entityId, timestamp, user, action, details, eventKey, entityDefinition);
+ }
+
+ @Override
+ public String toString() {
+ return SerDe.GSON.toJson(this);
+ }
+
+ public static EntityAuditEvent fromString(String eventString) {
+ return SerDe.GSON.fromJson(eventString, EntityAuditEvent.class);
+ }
+
+ public String getEntityId() {
+ return entityId;
+ }
+
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public EntityAuditAction getAction() {
+ return action;
+ }
+
+ public String getDetails() {
+ return details;
+ }
+
+ public void setEntityId(String entityId) {
+ this.entityId = entityId;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public void setAction(EntityAuditAction action) {
+ this.action = action;
+ }
+
+ public void setDetails(String details) {
+ this.details = details;
+ }
+
+ public String getEventKey() {
+ return eventKey;
+ }
+
+ public void setEventKey(String eventKey) {
+ this.eventKey = eventKey;
+ }
+
+ public IReferenceableInstance getEntityDefinition() {
+ return entityDefinition;
+ }
+
+ public String getEntityDefinitionString() {
+ if (entityDefinition != null) {
+ return InstanceSerialization.toJson(entityDefinition, true);
+ }
+ return null;
+ }
+
+ public void setEntityDefinition(String entityDefinition) {
+ this.entityDefinition = InstanceSerialization.fromJsonReferenceable(entityDefinition, true);
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v1/src/main/java/org/apache/atlas/SerDe.java
----------------------------------------------------------------------
diff --git a/client/client-v1/src/main/java/org/apache/atlas/SerDe.java b/client/client-v1/src/main/java/org/apache/atlas/SerDe.java
new file mode 100644
index 0000000..cdc3509
--- /dev/null
+++ b/client/client-v1/src/main/java/org/apache/atlas/SerDe.java
@@ -0,0 +1,80 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import org.apache.atlas.typesystem.IReferenceableInstance;
+import org.apache.atlas.typesystem.IStruct;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.Struct;
+import org.apache.atlas.typesystem.json.InstanceSerialization;
+
+import java.lang.reflect.Type;
+
+@Deprecated
+public class SerDe {
+ public static final Gson GSON = new GsonBuilder().
+ registerTypeAdapter(IStruct.class, new StructDeserializer()).
+ registerTypeAdapter(IReferenceableInstance.class, new ReferenceableSerializerDeserializer()).
+ registerTypeAdapter(Referenceable.class, new ReferenceableSerializerDeserializer()).
+ create();
+
+ /**
+ * Serde for Struct used by AbstractNotificationConsumer.GSON.
+ */
+ public static final class StructDeserializer implements JsonDeserializer<IStruct>, JsonSerializer<IStruct> {
+ @Override
+ public IStruct deserialize(final JsonElement json, final Type type,
+ final JsonDeserializationContext context) {
+ return context.deserialize(json, Struct.class);
+ }
+
+ @Override
+ public JsonElement serialize(IStruct src, Type typeOfSrc, JsonSerializationContext context) {
+ String instanceJson = InstanceSerialization.toJson(src, true);
+ return new JsonParser().parse(instanceJson).getAsJsonObject();
+ }
+ }
+
+ /**
+ * Serde for Referenceable used by AbstractNotificationConsumer.GSON.
+ */
+ public static final class ReferenceableSerializerDeserializer implements JsonDeserializer<IStruct>,
+ JsonSerializer<IReferenceableInstance> {
+ @Override
+ public IReferenceableInstance deserialize(final JsonElement json, final Type type,
+ final JsonDeserializationContext context) {
+
+ return InstanceSerialization.fromJsonReferenceable(json.toString(), true);
+ }
+
+ @Override
+ public JsonElement serialize(IReferenceableInstance src, Type typeOfSrc, JsonSerializationContext context) {
+ String instanceJson = InstanceSerialization.toJson(src, true);
+ return new JsonParser().parse(instanceJson).getAsJsonObject();
+ }
+ }
+}
[6/7] atlas git commit: ATLAS-2179: Split Atlas client library to
avoid unnecessary dependencies
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
----------------------------------------------------------------------
diff --git a/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java b/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
new file mode 100644
index 0000000..1da6b45
--- /dev/null
+++ b/client/client-v1/src/test/java/org/apache/atlas/AtlasClientTest.java
@@ -0,0 +1,474 @@
+/*
+ * 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;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.atlas.model.legacy.EntityResult;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.json.InstanceSerialization;
+import org.apache.commons.configuration.Configuration;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.codehaus.jettison.json.JSONObject;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import java.net.ConnectException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+public class AtlasClientTest {
+
+ @Mock
+ private WebResource service;
+ @Mock
+ private WebResource.Builder resourceBuilderMock;
+
+ @Mock
+ private Configuration configuration;
+
+ @Mock
+ private Client client;
+
+ @BeforeMethod
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void shouldVerifyServerIsReady() throws AtlasServiceException {
+ setupRetryParams();
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ when(response.getEntity(String.class)).thenReturn("{\"Version\":\"version-rrelease\",\"Name\":\"apache-atlas\"," +
+ "\"Description\":\"Metadata Management and Data Governance Platform over Hadoop\"}");
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
+
+ assertTrue(atlasClient.isServerReady());
+ }
+
+ @Test
+ public void testCreateEntity() throws Exception {
+ setupRetryParams();
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.CREATE_ENTITY, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
+
+ JSONObject jsonResponse = new JSONObject(new EntityResult(Arrays.asList("id"), null, null).toString());
+ when(response.getEntity(String.class)).thenReturn(jsonResponse.toString());
+ when(response.getLength()).thenReturn(jsonResponse.length());
+ String entityJson = InstanceSerialization.toJson(new Referenceable("type"), true);
+ when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response);
+
+ List<String> ids = atlasClient.createEntity(entityJson);
+ assertEquals(ids.size(), 1);
+ assertEquals(ids.get(0), "id");
+ }
+
+ private WebResource.Builder setupBuilder(AtlasClient.API_V1 api, WebResource webResource) {
+ when(webResource.path(api.getPath())).thenReturn(service);
+ return getBuilder(service);
+ }
+
+ @Test
+ public void shouldReturnFalseIfServerIsNotReady() throws AtlasServiceException {
+ setupRetryParams();
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenThrow(
+ new ClientHandlerException());
+ assertFalse(atlasClient.isServerReady());
+ }
+
+ @Test
+ public void shouldReturnFalseIfServiceIsUnavailable() throws AtlasServiceException {
+ setupRetryParams();
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
+ when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.SERVICE_UNAVAILABLE);
+
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
+
+ assertFalse(atlasClient.isServerReady());
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void shouldThrowErrorIfAnyResponseOtherThanServiceUnavailable() throws AtlasServiceException {
+ setupRetryParams();
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.VERSION, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.INTERNAL_SERVER_ERROR);
+
+ when(builder.method(AtlasClient.API_V1.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response);
+
+ atlasClient.isServerReady();
+ fail("Should throw exception");
+ }
+
+ @Test
+ public void shouldGetAdminStatus() throws AtlasServiceException {
+ setupRetryParams();
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String activeStatus = "{\"Status\":\"Active\"}";
+ when(response.getEntity(String.class)).thenReturn(activeStatus);
+ when(response.getLength()).thenReturn(activeStatus.length());
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
+
+// Fix after AtlasBaseClient
+// atlasClient.setService();
+
+
+ String status = atlasClient.getAdminStatus();
+ assertEquals(status, "Active");
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void shouldReturnStatusAsUnknownOnException() throws AtlasServiceException {
+ setupRetryParams();
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ when(response.getClientResponseStatus()).thenReturn(ClientResponse.Status.INTERNAL_SERVER_ERROR);
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
+
+ String status = atlasClient.getAdminStatus();
+ fail("Should fail with AtlasServiceException");
+ }
+
+ @Test
+ public void shouldReturnStatusAsUnknownIfJSONIsInvalid() throws AtlasServiceException {
+ setupRetryParams();
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ when(response.getEntity(String.class)).thenReturn("{\"status\":\"Active\"}");
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response);
+
+ String status = atlasClient.getAdminStatus();
+ assertEquals(status, AtlasClient.UNKNOWN_STATUS);
+ }
+
+ @Test
+ public void shouldReturnBaseURLAsPassedInURL() {
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ String serviceURL = atlasClient.determineActiveServiceURL(new String[]{"http://localhost:21000"}, client);
+ assertEquals(serviceURL, "http://localhost:21000");
+ }
+
+ @Test
+ public void shouldSelectActiveAmongMultipleServersIfHAIsEnabled() {
+ setupRetryParams();
+
+ when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
+ when(client.resource(UriBuilder.fromUri("http://localhost:41000").build())).thenReturn(service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
+ ClientResponse firstResponse = mock(ClientResponse.class);
+ when(firstResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String passiveStatus = "{\"Status\":\"PASSIVE\"}";
+ when(firstResponse.getEntity(String.class)).thenReturn(passiveStatus);
+ when(firstResponse.getLength()).thenReturn(passiveStatus.length());
+ ClientResponse secondResponse = mock(ClientResponse.class);
+ when(secondResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String activeStatus = "{\"Status\":\"ACTIVE\"}";
+ when(secondResponse.getEntity(String.class)).thenReturn(activeStatus);
+ when(secondResponse.getLength()).thenReturn(activeStatus.length());
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
+ thenReturn(firstResponse).thenReturn(firstResponse).thenReturn(firstResponse).
+ thenReturn(secondResponse);
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ String serviceURL = atlasClient.determineActiveServiceURL(
+ new String[]{"http://localhost:31000", "http://localhost:41000"},
+ client);
+ assertEquals(serviceURL, "http://localhost:41000");
+ }
+
+ @Test
+ public void shouldRetryUntilServiceBecomesActive() {
+ setupRetryParams();
+
+ when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
+ ClientResponse nextResponse = mock(ClientResponse.class);
+ when(nextResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String activeStatus = "{\"Status\":\"ACTIVE\"}";
+ when(response.getEntity(String.class)).thenReturn(activeStatus);
+ when(response.getLength()).thenReturn(activeStatus.length());
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
+ thenReturn(response).thenReturn(response).thenReturn(nextResponse);
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ String serviceURL = atlasClient.determineActiveServiceURL(
+ new String[] {"http://localhost:31000","http://localhost:41000"},
+ client);
+ assertEquals(serviceURL, "http://localhost:31000");
+ }
+
+ @Test
+ public void shouldRetryIfCannotConnectToServiceInitially() {
+ setupRetryParams();
+
+ when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
+ ClientResponse nextResponse = mock(ClientResponse.class);
+ when(nextResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String activeStatus = "{\"Status\":\"ACTIVE\"}";
+ when(response.getEntity(String.class)).thenReturn(activeStatus);
+ when(response.getLength()).thenReturn(activeStatus.length());
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
+ thenThrow(new ClientHandlerException("Simulating connection exception")).
+ thenReturn(response).
+ thenReturn(nextResponse);
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+ atlasClient.setService(service);
+ atlasClient.setConfiguration(configuration);
+
+ String serviceURL = atlasClient.determineActiveServiceURL(
+ new String[] {"http://localhost:31000","http://localhost:41000"},
+ client);
+ assertEquals(serviceURL, "http://localhost:31000");
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void shouldThrowExceptionIfActiveServerIsNotFound() {
+ setupRetryParams();
+
+ when(client.resource(UriBuilder.fromUri("http://localhost:31000").build())).thenReturn(service);
+ WebResource.Builder builder = setupBuilder(AtlasClient.API_V1.STATUS, service);
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}");
+ when(builder.method(AtlasClient.API_V1.STATUS.getMethod(), ClientResponse.class, null)).
+ thenThrow(new ClientHandlerException("Simulating connection exception")).
+ thenReturn(response).
+ thenReturn(response);
+
+ AtlasClient atlasClient = new AtlasClient(service, configuration);
+
+ String serviceURL = atlasClient.determineActiveServiceURL(
+ new String[] {"http://localhost:31000","http://localhost:41000"},
+ client);
+ assertNull(serviceURL);
+ }
+
+ @Test
+ public void shouldRetryAPICallsOnClientHandlerException() throws AtlasServiceException, URISyntaxException {
+ setupRetryParams();
+
+ ResourceCreator resourceCreator = mock(ResourceCreator.class);
+ WebResource resourceObject = mock(WebResource.class);
+ when(resourceObject.getURI()).
+ thenReturn(new URI("http://localhost:31000/api/atlas/types")).
+ thenReturn(new URI("http://localhost:41000/api/atlas/types")).
+ thenReturn(new URI("http://localhost:41000/api/atlas/types"));
+
+ WebResource.Builder builder = getBuilder(resourceObject);
+
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String activeStatus = "{\"Status\":\"ACTIVE\"}";
+ when(response.getEntity(String.class)).thenReturn(activeStatus);
+ when(response.getLength()).thenReturn(activeStatus.length());
+
+ when(builder.method(AtlasClient.API_V1.LIST_TYPES.getMethod(), ClientResponse.class, null)).
+ thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
+ thenReturn(response);
+
+ when(resourceCreator.createResource()).thenReturn(resourceObject);
+
+ AtlasClient atlasClient = getClientForTest("http://localhost:31000","http://localhost:41000");
+
+ atlasClient.setService(service);
+ atlasClient.setConfiguration(configuration);
+
+ atlasClient.callAPIWithRetries(AtlasClient.API_V1.LIST_TYPES, null, resourceCreator);
+
+ verify(client).destroy();
+ verify(client).resource(UriBuilder.fromUri("http://localhost:31000").build());
+ verify(client).resource(UriBuilder.fromUri("http://localhost:41000").build());
+ }
+
+ @Test
+ public void shouldRetryWithSameClientIfSingleAddressIsUsed() throws URISyntaxException, AtlasServiceException {
+ setupRetryParams();
+
+ ResourceCreator resourceCreator = mock(ResourceCreator.class);
+ WebResource resourceObject = mock(WebResource.class);
+ when(resourceObject.getURI()).
+ thenReturn(new URI("http://localhost:31000/api/atlas/types"));
+
+ WebResource.Builder builder = getBuilder(resourceObject);
+
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String activeStatus = "{\"Status\":\"ACTIVE\"}";
+ when(response.getEntity(String.class)).thenReturn(activeStatus);
+ when(response.getLength()).thenReturn(activeStatus.length());
+
+ when(builder.method(AtlasClient.API_V1.LIST_TYPES.getMethod(), ClientResponse.class, null)).
+ thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
+ thenReturn(response);
+
+ when(resourceCreator.createResource()).thenReturn(resourceObject);
+ when(configuration.getString("atlas.http.authentication.type", "simple")).thenReturn("simple");
+
+ AtlasClient atlasClient = getClientForTest("http://localhost:31000");
+
+ atlasClient.setService(resourceObject);
+ atlasClient.setConfiguration(configuration);
+
+ atlasClient.callAPIWithRetries(AtlasClient.API_V1.LIST_TYPES, null, resourceCreator);
+
+ verify(client).destroy();
+ verify(client, times(2)).resource(UriBuilder.fromUri("http://localhost:31000").build());
+ }
+
+ @Test
+ public void shouldRetryAPICallsOnServiceUnavailable() throws AtlasServiceException, URISyntaxException {
+ setupRetryParams();
+
+ ResourceCreator resourceCreator = mock(ResourceCreator.class);
+ WebResource resourceObject = mock(WebResource.class);
+ when(resourceObject.getURI()).
+ thenReturn(new URI("http://localhost:31000/api/atlas/types")).
+ thenReturn(new URI("http://localhost:41000/api/atlas/types")).
+ thenReturn(new URI("http://localhost:41000/api/atlas/types"));
+
+ WebResource.Builder builder = getBuilder(resourceObject);
+
+ ClientResponse firstResponse = mock(ClientResponse.class);
+ when(firstResponse.getStatus()).thenReturn(Response.Status.SERVICE_UNAVAILABLE.getStatusCode());
+ when(firstResponse.getClientResponseStatus()).thenReturn(ClientResponse.Status.SERVICE_UNAVAILABLE);
+
+ ClientResponse response = mock(ClientResponse.class);
+ when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
+ String activeStatus = "{\"Status\":\"ACTIVE\"}";
+ when(response.getEntity(String.class)).thenReturn(activeStatus);
+ when(response.getLength()).thenReturn(activeStatus.length());
+
+ when(builder.method(AtlasClient.API_V1.LIST_TYPES.getMethod(), ClientResponse.class, null)).
+ thenThrow(new ClientHandlerException("simulating exception in calling API", new ConnectException())).
+ thenReturn(firstResponse).
+ thenReturn(response);
+
+ when(resourceCreator.createResource()).thenReturn(resourceObject);
+
+ AtlasClient atlasClient = getClientForTest("http://localhost:31000","http://localhost:41000");
+ atlasClient.setService(resourceObject);
+ atlasClient.setConfiguration(configuration);
+
+ atlasClient.callAPIWithRetries(AtlasClient.API_V1.LIST_TYPES, null, resourceCreator);
+
+
+ verify(client).destroy();
+ verify(client).resource(UriBuilder.fromUri("http://localhost:31000").build());
+ verify(client).resource(UriBuilder.fromUri("http://localhost:41000").build());
+ }
+
+ private WebResource.Builder getBuilder(WebResource resourceObject) {
+ when(resourceObject.getRequestBuilder()).thenReturn(resourceBuilderMock);
+ when(resourceObject.path(anyString())).thenReturn(resourceObject);
+ when(resourceBuilderMock.accept(AtlasBaseClient.JSON_MEDIA_TYPE)).thenReturn(resourceBuilderMock);
+ when(resourceBuilderMock.type(AtlasBaseClient.JSON_MEDIA_TYPE)).thenReturn(resourceBuilderMock);
+ return resourceBuilderMock;
+ }
+
+ private void setupRetryParams() {
+ when(configuration.getInt(AtlasClient.ATLAS_CLIENT_HA_RETRIES_KEY, AtlasClient.DEFAULT_NUM_RETRIES)).
+ thenReturn(3);
+ when(configuration.getInt(AtlasClient.ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY,
+ AtlasClient.DEFAULT_SLEEP_BETWEEN_RETRIES_MS)).
+ thenReturn(1);
+ }
+
+ private AtlasClient getClientForTest(final String... baseUrls) {
+ return new AtlasClient((UserGroupInformation)null, (String)null, baseUrls) {
+ boolean firstCall = true;
+ @Override
+ protected String determineActiveServiceURL(String[] baseUrls, Client client) {
+ String returnUrl = baseUrls[0];
+ if (baseUrls.length > 1 && !firstCall) {
+ returnUrl = baseUrls[1];
+ }
+ firstCall = false;
+ return returnUrl;
+ }
+
+ @Override
+ protected Configuration getClientProperties() {
+ return configuration;
+ }
+
+ @Override
+ protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
+ return client;
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v2/pom.xml
----------------------------------------------------------------------
diff --git a/client/client-v2/pom.xml b/client/client-v2/pom.xml
new file mode 100644
index 0000000..66013f5
--- /dev/null
+++ b/client/client-v2/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>atlas-client</artifactId>
+ <groupId>org.apache.atlas</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>atlas-client-v2</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-intg</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-client-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
----------------------------------------------------------------------
diff --git a/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java b/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
new file mode 100644
index 0000000..24a3ef6
--- /dev/null
+++ b/client/client-v2/src/main/java/org/apache/atlas/AtlasClientV2.java
@@ -0,0 +1,460 @@
+/**
+ * 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;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.model.SearchFilter;
+import org.apache.atlas.model.discovery.AtlasSearchResult;
+import org.apache.atlas.model.discovery.SearchParameters;
+import org.apache.atlas.model.instance.AtlasClassification;
+import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
+import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
+import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
+import org.apache.atlas.model.instance.EntityMutationResponse;
+import org.apache.atlas.model.lineage.AtlasLineageInfo;
+import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
+import org.apache.atlas.model.typedef.AtlasClassificationDef;
+import org.apache.atlas.model.typedef.AtlasEntityDef;
+import org.apache.atlas.model.typedef.AtlasEnumDef;
+import org.apache.atlas.model.typedef.AtlasStructDef;
+import org.apache.atlas.model.typedef.AtlasTypesDef;
+import org.apache.atlas.type.AtlasType;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.configuration.Configuration;
+import org.apache.hadoop.security.UserGroupInformation;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.util.List;
+import java.util.Map;
+
+public class AtlasClientV2 extends AtlasBaseClient {
+ // Type APIs
+ public static final String TYPES_API = BASE_URI + "v2/types/";
+ // Entity APIs
+ public static final String ENTITY_API = BASE_URI + "v2/entity/";
+ private static final String PREFIX_ATTR = "attr:";
+ private static final String TYPEDEFS_API = TYPES_API + "typedefs/";
+ private static final String TYPEDEF_BY_NAME = TYPES_API + "typedef/name/";
+ private static final String TYPEDEF_BY_GUID = TYPES_API + "typedef/guid/";
+ private static final String GET_BY_NAME_TEMPLATE = TYPES_API + "%s/name/%s";
+ private static final String GET_BY_GUID_TEMPLATE = TYPES_API + "%s/guid/%s";
+ private static final String ENTITY_BULK_API = ENTITY_API + "bulk/";
+ // Lineage APIs
+ private static final String LINEAGE_URI = BASE_URI + "v2/lineage/";
+
+ // Discovery APIs
+ private static final String DISCOVERY_URI = BASE_URI + "v2/search";
+ private static final String DSL_URI = DISCOVERY_URI + "/dsl";
+ private static final String FULL_TEXT_URI = DISCOVERY_URI + "/fulltext";
+ private static final String BASIC_SEARCH_URI = DISCOVERY_URI + "/basic";
+ private static final String FACETED_SEARCH_URI = BASIC_SEARCH_URI;
+
+ public AtlasClientV2(String[] baseUrl, String[] basicAuthUserNamePassword) {
+ super(baseUrl, basicAuthUserNamePassword);
+ }
+
+ public AtlasClientV2(String... baseUrls) throws AtlasException {
+ super(baseUrls);
+ }
+
+ public AtlasClientV2(UserGroupInformation ugi, String doAsUser, String... baseUrls) {
+ super(ugi, doAsUser, baseUrls);
+ }
+
+ /**
+ * Constructor for AtlasClient with cookie params as header
+ * @param baseUrl
+ * @param cookieName
+ * @param value
+ * @param path
+ * @param domain
+ */
+ public AtlasClientV2(String[] baseUrl, String cookieName, String value, String path, String domain) {
+ super(baseUrl, new Cookie(cookieName, value, path, domain));
+ }
+
+ /**
+ * Constructor for AtlasClient with cookie as header
+ * @param baseUrl
+ * @param cookie
+ */
+ public AtlasClientV2(String[] baseUrl, Cookie cookie) {
+ super(baseUrl, cookie);
+ }
+
+ @VisibleForTesting
+ AtlasClientV2(WebResource service, Configuration configuration) {
+ super(service, configuration);
+ }
+
+ /**
+ * Bulk retrieval API for retrieving all type definitions in Atlas
+ *
+ * @return A composite wrapper object with lists of all type definitions
+ */
+ public AtlasTypesDef getAllTypeDefs(SearchFilter searchFilter) throws AtlasServiceException {
+ return callAPI(API_V2.GET_ALL_TYPE_DEFS, AtlasTypesDef.class, searchFilter.getParams());
+ }
+
+ public boolean typeWithGuidExists(String guid) {
+ try {
+ callAPI(API_V2.GET_TYPEDEF_BY_GUID, String.class, null, guid);
+ } catch (AtlasServiceException e) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean typeWithNameExists(String name) {
+ try {
+ callAPI(API_V2.GET_TYPEDEF_BY_NAME, String.class, null, name);
+ } catch (AtlasServiceException e) {
+ return false;
+ }
+ return true;
+ }
+
+ public AtlasEnumDef getEnumDefByName(final String name) throws AtlasServiceException {
+ return getTypeDefByName(name, AtlasEnumDef.class);
+ }
+
+ public AtlasEnumDef getEnumDefByGuid(final String guid) throws AtlasServiceException {
+ return getTypeDefByGuid(guid, AtlasEnumDef.class);
+ }
+
+ public AtlasStructDef getStructDefByName(final String name) throws AtlasServiceException {
+ return getTypeDefByName(name, AtlasStructDef.class);
+ }
+
+ public AtlasStructDef getStructDefByGuid(final String guid) throws AtlasServiceException {
+ return getTypeDefByGuid(guid, AtlasStructDef.class);
+ }
+
+ public AtlasClassificationDef getClassificationDefByName(final String name) throws AtlasServiceException {
+ return getTypeDefByName(name, AtlasClassificationDef.class);
+ }
+
+ public AtlasClassificationDef getClassificationDefByGuid(final String guid) throws AtlasServiceException {
+ return getTypeDefByGuid(guid, AtlasClassificationDef.class);
+ }
+
+ public AtlasEntityDef getEntityDefByName(final String name) throws AtlasServiceException {
+ return getTypeDefByName(name, AtlasEntityDef.class);
+ }
+
+ public AtlasEntityDef getEntityDefByGuid(final String guid) throws AtlasServiceException {
+ return getTypeDefByGuid(guid, AtlasEntityDef.class);
+ }
+
+ @Deprecated
+ public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasServiceException {
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+ atlasTypesDef.getEnumDefs().add(enumDef);
+ AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
+ assert created != null;
+ assert created.getEnumDefs() != null;
+ return created.getEnumDefs().get(0);
+ }
+
+ @Deprecated
+ public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasServiceException {
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+ atlasTypesDef.getStructDefs().add(structDef);
+ AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
+ assert created != null;
+ assert created.getStructDefs() != null;
+ return created.getStructDefs().get(0);
+ }
+
+ @Deprecated
+ public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasServiceException {
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+ atlasTypesDef.getEntityDefs().add(entityDef);
+ AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
+ assert created != null;
+ assert created.getEntityDefs() != null;
+ return created.getEntityDefs().get(0);
+ }
+
+ @Deprecated
+ public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef)
+ throws AtlasServiceException {
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+ atlasTypesDef.getClassificationDefs().add(classificationDef);
+ AtlasTypesDef created = createAtlasTypeDefs(atlasTypesDef);
+ assert created != null;
+ assert created.getClassificationDefs() != null;
+ return created.getClassificationDefs().get(0);
+ }
+
+ /**
+ * Bulk create APIs for all atlas type definitions, only new definitions will be created.
+ * Any changes to the existing definitions will be discarded
+ *
+ * @param typesDef A composite wrapper object with corresponding lists of the type definition
+ * @return A composite wrapper object with lists of type definitions that were successfully
+ * created
+ */
+ public AtlasTypesDef createAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
+ return callAPI(API_V2.CREATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
+ }
+
+ /**
+ * Bulk update API for all types, changes detected in the type definitions would be persisted
+ *
+ * @param typesDef A composite object that captures all type definition changes
+ * @return A composite object with lists of type definitions that were updated
+ */
+ public AtlasTypesDef updateAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
+ return callAPI(API_V2.UPDATE_ALL_TYPE_DEFS, AtlasTypesDef.class, AtlasType.toJson(typesDef));
+ }
+
+ /**
+ * Bulk delete API for all types
+ *
+ * @param typesDef A composite object that captures all types to be deleted
+ */
+ public void deleteAtlasTypeDefs(final AtlasTypesDef typesDef) throws AtlasServiceException {
+ callAPI(API_V2.DELETE_ALL_TYPE_DEFS, (Class<?>)null, AtlasType.toJson(typesDef));
+ }
+
+ public AtlasLineageInfo getLineageInfo(final String guid, final LineageDirection direction, final int depth) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("direction", direction.toString());
+ queryParams.add("depth", String.valueOf(depth));
+
+ return callAPI(API_V2.LINEAGE_INFO, AtlasLineageInfo.class, queryParams, guid);
+ }
+
+ public AtlasEntityWithExtInfo getEntityByGuid(String guid) throws AtlasServiceException {
+ return callAPI(API_V2.GET_ENTITY_BY_GUID, AtlasEntityWithExtInfo.class, (MultivaluedMap<String, String>) null, guid);
+ }
+
+ public AtlasEntityWithExtInfo getEntityByAttribute(String type, Map<String, String> attributes) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes);
+
+ return callAPI(API_V2.GET_ENTITY_BY_ATTRIBUTE, AtlasEntityWithExtInfo.class, queryParams, type);
+ }
+
+ public EntityMutationResponse updateEntityByAttribute(String type, Map<String, String> attributes, AtlasEntityWithExtInfo entityInfo)
+ throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes);
+
+ return callAPI(API_V2.UPDATE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, entityInfo, queryParams, type);
+ }
+
+ /* Lineage Calls */
+
+ public EntityMutationResponse deleteEntityByAttribute(String type, Map<String, String> attributes) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = attributesToQueryParams(attributes);
+
+ return callAPI(API_V2.DELETE_ENTITY_BY_ATTRIBUTE, EntityMutationResponse.class, queryParams, type);
+ }
+
+ /* Entity Calls */
+
+ public EntityMutationResponse createEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException {
+ return callAPI(API_V2.CREATE_ENTITY, EntityMutationResponse.class, entity);
+ }
+
+ public EntityMutationResponse updateEntity(AtlasEntityWithExtInfo entity) throws AtlasServiceException {
+ return callAPI(API_V2.UPDATE_ENTITY, EntityMutationResponse.class, entity);
+ }
+
+ public EntityMutationResponse deleteEntityByGuid(String guid) throws AtlasServiceException {
+ return callAPI(API_V2.DELETE_ENTITY_BY_GUID, EntityMutationResponse.class, null, guid);
+ }
+
+ public AtlasEntitiesWithExtInfo getEntitiesByGuids(List<String> guids) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+
+ queryParams.put("guid", guids);
+
+ return callAPI(API_V2.GET_ENTITIES_BY_GUIDS, AtlasEntitiesWithExtInfo.class, queryParams);
+ }
+
+ public EntityMutationResponse createEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException {
+ return callAPI(API_V2.CREATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
+ }
+
+ public EntityMutationResponse updateEntities(AtlasEntitiesWithExtInfo atlasEntities) throws AtlasServiceException {
+ return callAPI(API_V2.UPDATE_ENTITIES, EntityMutationResponse.class, atlasEntities);
+ }
+
+ public EntityMutationResponse deleteEntitiesByGuids(List<String> guids) throws AtlasServiceException {
+ return callAPI(API_V2.DELETE_ENTITIES_BY_GUIDS, EntityMutationResponse.class, "guid", guids);
+ }
+
+ public AtlasClassifications getClassifications(String guid) throws AtlasServiceException {
+ return callAPI(formatPathParameters(API_V2.GET_CLASSIFICATIONS, guid), AtlasClassifications.class, null);
+ }
+
+ public void addClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
+ callAPI(formatPathParameters(API_V2.ADD_CLASSIFICATIONS, guid), (Class<?>)null, classifications, (String[]) null);
+ }
+
+ public void updateClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
+ callAPI(formatPathParameters(API_V2.UPDATE_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
+ }
+
+ public void deleteClassifications(String guid, List<AtlasClassification> classifications) throws AtlasServiceException {
+ callAPI(formatPathParameters(API_V2.GET_CLASSIFICATIONS, guid), AtlasClassifications.class, classifications);
+ }
+
+ public void deleteClassification(String guid, String classificationName) throws AtlasServiceException {
+ callAPI(formatPathParameters(API_V2.DELETE_CLASSIFICATION, guid, classificationName), null, null);
+ }
+
+ /* Discovery calls */
+ public AtlasSearchResult dslSearch(final String query) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+
+ return callAPI(API_V2.DSL_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult dslSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+ queryParams.add(LIMIT, String.valueOf(limit));
+ queryParams.add(OFFSET, String.valueOf(offset));
+
+ return callAPI(API_V2.DSL_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult fullTextSearch(final String query) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+
+ return callAPI(API_V2.FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult fullTextSearchWithParams(final String query, final int limit, final int offset) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(QUERY, query);
+ queryParams.add(LIMIT, String.valueOf(limit));
+ queryParams.add(OFFSET, String.valueOf(offset));
+
+ return callAPI(API_V2.FULL_TEXT_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult basicSearch(final String typeName, final String classification, final String query,
+ final boolean excludeDeletedEntities, final int limit, final int offset) throws AtlasServiceException {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("typeName", typeName);
+ queryParams.add("classification", classification);
+ queryParams.add(QUERY, query);
+ queryParams.add("excludeDeletedEntities", String.valueOf(excludeDeletedEntities));
+ queryParams.add(LIMIT, String.valueOf(limit));
+ queryParams.add(OFFSET, String.valueOf(offset));
+
+ return callAPI(API_V2.BASIC_SEARCH, AtlasSearchResult.class, queryParams);
+ }
+
+ public AtlasSearchResult facetedSearch(SearchParameters searchParameters) throws AtlasServiceException {
+ return callAPI(API_V2.FACETED_SEARCH, AtlasSearchResult.class, searchParameters);
+ }
+
+ @Override
+ protected API formatPathParameters(final API api, final String... params) {
+ return new API(String.format(api.getPath(), params), api.getMethod(), api.getExpectedStatus());
+ }
+
+ private MultivaluedMap<String, String> attributesToQueryParams(Map<String, String> attributes) {
+ return attributesToQueryParams(attributes, null);
+ }
+
+ private MultivaluedMap<String, String> attributesToQueryParams(Map<String, String> attributes,
+ MultivaluedMap<String, String> queryParams) {
+ if (queryParams == null) {
+ queryParams = new MultivaluedMapImpl();
+ }
+
+ if (MapUtils.isNotEmpty(attributes)) {
+ for (Map.Entry<String, String> e : attributes.entrySet()) {
+ queryParams.putSingle(PREFIX_ATTR + e.getKey(), e.getValue());
+ }
+ }
+
+ return queryParams;
+ }
+
+ private <T> T getTypeDefByName(final String name, Class<T> typeDefClass) throws AtlasServiceException {
+ String atlasPath = getAtlasPath(typeDefClass);
+ API api = new API(String.format(GET_BY_NAME_TEMPLATE, atlasPath, name), HttpMethod.GET, Response.Status.OK);
+ return callAPI(api, typeDefClass, null);
+ }
+
+ private <T> T getTypeDefByGuid(final String guid, Class<T> typeDefClass) throws AtlasServiceException {
+ String atlasPath = getAtlasPath(typeDefClass);
+ API api = new API(String.format(GET_BY_GUID_TEMPLATE, atlasPath, guid), HttpMethod.GET, Response.Status.OK);
+ return callAPI(api, typeDefClass, null);
+ }
+
+ private <T> String getAtlasPath(Class<T> typeDefClass) {
+ if (AtlasEnumDef.class.isAssignableFrom(typeDefClass)) {
+ return "enumdef";
+ } else if (AtlasEntityDef.class.isAssignableFrom(typeDefClass)) {
+ return "entitydef";
+ } else if (AtlasClassificationDef.class.isAssignableFrom(typeDefClass)) {
+ return "classificationdef";
+ } else if (AtlasStructDef.class.isAssignableFrom(typeDefClass)) {
+ return "structdef";
+ }
+ // Code should never reach this point
+ return "";
+ }
+
+ public static class API_V2 extends API {
+ public static final API_V2 GET_TYPEDEF_BY_NAME = new API_V2(TYPEDEF_BY_NAME, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 GET_TYPEDEF_BY_GUID = new API_V2(TYPEDEF_BY_GUID, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 GET_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 CREATE_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.PUT, Response.Status.OK);
+ public static final API_V2 DELETE_ALL_TYPE_DEFS = new API_V2(TYPEDEFS_API, HttpMethod.DELETE, Response.Status.NO_CONTENT);
+ public static final API_V2 GET_ENTITY_BY_GUID = new API_V2(ENTITY_API + "guid/", HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 GET_ENTITY_BY_ATTRIBUTE = new API_V2(ENTITY_API + "uniqueAttribute/type/", HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 CREATE_ENTITY = new API_V2(ENTITY_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ENTITY = new API_V2(ENTITY_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ENTITY_BY_ATTRIBUTE = new API_V2(ENTITY_API + "uniqueAttribute/type/", HttpMethod.PUT, Response.Status.OK);
+ public static final API_V2 DELETE_ENTITY_BY_GUID = new API_V2(ENTITY_API + "guid/", HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V2 DELETE_ENTITY_BY_ATTRIBUTE = new API_V2(ENTITY_API + "uniqueAttribute/type/", HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V2 GET_ENTITIES_BY_GUIDS = new API_V2(ENTITY_BULK_API, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 CREATE_ENTITIES = new API_V2(ENTITY_BULK_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 UPDATE_ENTITIES = new API_V2(ENTITY_BULK_API, HttpMethod.POST, Response.Status.OK);
+ public static final API_V2 DELETE_ENTITIES_BY_GUIDS = new API_V2(ENTITY_BULK_API, HttpMethod.DELETE, Response.Status.OK);
+ public static final API_V2 GET_CLASSIFICATIONS = new API_V2(ENTITY_API + "guid/%s/classifications", HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 ADD_CLASSIFICATIONS = new API_V2(ENTITY_API + "guid/%s/classifications", HttpMethod.POST, Response.Status.NO_CONTENT);
+ public static final API_V2 UPDATE_CLASSIFICATIONS = new API_V2(ENTITY_API + "guid/%s/classifications", HttpMethod.PUT, Response.Status.OK);
+ public static final API_V2 DELETE_CLASSIFICATION = new API_V2(ENTITY_API + "guid/%s/classification/%s", HttpMethod.DELETE, Response.Status.NO_CONTENT);
+ public static final API_V2 LINEAGE_INFO = new API_V2(LINEAGE_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 DSL_SEARCH = new API_V2(DSL_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 FULL_TEXT_SEARCH = new API_V2(FULL_TEXT_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 BASIC_SEARCH = new API_V2(BASIC_SEARCH_URI, HttpMethod.GET, Response.Status.OK);
+ public static final API_V2 FACETED_SEARCH = new API_V2(FACETED_SEARCH_URI, HttpMethod.POST, Response.Status.OK);
+
+ private API_V2(String path, String method, Response.Status status) {
+ super(path, method, status);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/common/pom.xml
----------------------------------------------------------------------
diff --git a/client/common/pom.xml b/client/common/pom.xml
new file mode 100644
index 0000000..c6ef0b8
--- /dev/null
+++ b/client/common/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>atlas-client</artifactId>
+ <groupId>org.apache.atlas</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>atlas-client-common</artifactId>
+
+ <dependencies>
+ <!-- supports simple auth handler -->
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-intg</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
----------------------------------------------------------------------
diff --git a/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
new file mode 100644
index 0000000..5e1d101
--- /dev/null
+++ b/client/common/src/main/java/org/apache/atlas/AtlasBaseClient.java
@@ -0,0 +1,621 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientHandlerException;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.GenericType;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.client.urlconnection.URLConnectionClientHandler;
+import org.apache.atlas.model.metrics.AtlasMetrics;
+import org.apache.atlas.security.SecureClientUtils;
+import org.apache.atlas.utils.AuthenticationUtil;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.core.Cookie;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED;
+
+public abstract class AtlasBaseClient {
+ public static final String BASE_URI = "api/atlas/";
+ public static final String TYPES = "types";
+ public static final String ADMIN_VERSION = "admin/version";
+ public static final String ADMIN_STATUS = "admin/status";
+ public static final String ADMIN_METRICS = "admin/metrics";
+ public static final String HTTP_AUTHENTICATION_ENABLED = "atlas.http.authentication.enabled";
+
+ public static final String QUERY = "query";
+ public static final String LIMIT = "limit";
+ public static final String OFFSET = "offset";
+
+ public static final API API_STATUS = new API(BASE_URI + ADMIN_STATUS, HttpMethod.GET, Response.Status.OK);;
+ public static final API API_VERSION = new API(BASE_URI + ADMIN_VERSION, HttpMethod.GET, Response.Status.OK);;
+ public static final API API_METRICS = new API(BASE_URI + ADMIN_METRICS, HttpMethod.GET, Response.Status.OK);;
+
+ static final String JSON_MEDIA_TYPE = MediaType.APPLICATION_JSON + "; charset=UTF-8";
+ static final String UNKNOWN_STATUS = "Unknown status";
+ static final String ATLAS_CLIENT_HA_RETRIES_KEY = "atlas.client.ha.retries";
+ // Setting the default value based on testing failovers while client code like quickstart is running.
+ static final int DEFAULT_NUM_RETRIES = 4;
+ static final String ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY = "atlas.client.ha.sleep.interval.ms";
+ // Setting the default value based on testing failovers while client code like quickstart is running.
+ // With number of retries, this gives a total time of about 20s for the server to start.
+ static final int DEFAULT_SLEEP_BETWEEN_RETRIES_MS = 5000;
+ private static final Logger LOG = LoggerFactory.getLogger(AtlasBaseClient.class);
+ protected WebResource service;
+ protected Configuration configuration;
+ private String basicAuthUser;
+ private String basicAuthPassword;
+ private AtlasClientContext atlasClientContext;
+ private boolean retryEnabled = false;
+ private Cookie cookie = null;
+
+ protected AtlasBaseClient() {
+ }
+
+ protected AtlasBaseClient(String[] baseUrl, String[] basicAuthUserNamePassword) {
+ if (basicAuthUserNamePassword != null) {
+ if (basicAuthUserNamePassword.length > 0) {
+ this.basicAuthUser = basicAuthUserNamePassword[0];
+ }
+ if (basicAuthUserNamePassword.length > 1) {
+ this.basicAuthPassword = basicAuthUserNamePassword[1];
+ }
+ }
+
+ initializeState(baseUrl, null, null);
+ }
+
+ protected AtlasBaseClient(String... baseUrls) throws AtlasException {
+ this(getCurrentUGI(), baseUrls);
+ }
+
+ protected AtlasBaseClient(UserGroupInformation ugi, String[] baseUrls) {
+ this(ugi, ugi.getShortUserName(), baseUrls);
+ }
+
+ protected AtlasBaseClient(UserGroupInformation ugi, String doAsUser, String[] baseUrls) {
+ initializeState(baseUrls, ugi, doAsUser);
+ }
+
+ protected AtlasBaseClient(String[] baseUrls, Cookie cookie) {
+ this.cookie = cookie;
+ initializeState(baseUrls, null, null);
+ }
+
+ @VisibleForTesting
+ protected AtlasBaseClient(WebResource service, Configuration configuration) {
+ this.service = service;
+ this.configuration = configuration;
+ }
+
+ @VisibleForTesting
+ protected AtlasBaseClient(Configuration configuration, String[] baseUrl, String[] basicAuthUserNamePassword) {
+ if (basicAuthUserNamePassword != null) {
+ if (basicAuthUserNamePassword.length > 0) {
+ this.basicAuthUser = basicAuthUserNamePassword[0];
+ }
+ if (basicAuthUserNamePassword.length > 1) {
+ this.basicAuthPassword = basicAuthUserNamePassword[1];
+ }
+ }
+
+ initializeState(configuration, baseUrl, null, null);
+ }
+
+ protected static UserGroupInformation getCurrentUGI() throws AtlasException {
+ try {
+ return UserGroupInformation.getCurrentUser();
+ } catch (IOException e) {
+ throw new AtlasException(e);
+ }
+ }
+
+ public void setCookie(Cookie cookie) {
+ this.cookie = cookie;
+ }
+
+ public boolean isServerReady() throws AtlasServiceException {
+ WebResource resource = getResource(API_VERSION.getPath());
+ try {
+ callAPIWithResource(API_VERSION, resource, null, JSONObject.class);
+ return true;
+ } catch (ClientHandlerException che) {
+ return false;
+ } catch (AtlasServiceException ase) {
+ if (ase.getStatus() != null && ase.getStatus().equals(ClientResponse.Status.SERVICE_UNAVAILABLE)) {
+ LOG.warn("Received SERVICE_UNAVAILABLE, server is not yet ready");
+ return false;
+ }
+ throw ase;
+ }
+ }
+
+ /**
+ * Return status of the service instance the client is pointing to.
+ *
+ * @return One of the values in ServiceState.ServiceStateValue or {@link #UNKNOWN_STATUS} if
+ * there is a JSON parse exception
+ * @throws AtlasServiceException if there is a HTTP error.
+ */
+ public String getAdminStatus() throws AtlasServiceException {
+ String result = AtlasBaseClient.UNKNOWN_STATUS;
+ WebResource resource = getResource(service, API_STATUS.getPath());
+ JSONObject response = callAPIWithResource(API_STATUS, resource, null, JSONObject.class);
+ try {
+ result = response.getString("Status");
+ } catch (JSONException e) {
+ LOG.error("Exception while parsing admin status response. Returned response {}", response.toString(), e);
+ }
+ return result;
+ }
+
+ /**
+ * @return Return metrics of the service instance the client is pointing to
+ * @throws AtlasServiceException
+ */
+ public AtlasMetrics getAtlasMetrics() throws AtlasServiceException {
+ return callAPI(API_METRICS, AtlasMetrics.class, null);
+ }
+
+ public <T> T callAPI(API api, Class<T> responseType, Object requestObject, String... params)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
+ }
+
+ public <T> T callAPI(API api, GenericType<T> responseType, Object requestObject, String... params)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, params), requestObject, responseType);
+ }
+
+ public <T> T callAPI(API api, Class<T> responseType, Object requestBody,
+ MultivaluedMap<String, String> queryParams, String... params) throws AtlasServiceException {
+ WebResource resource = getResource(api, queryParams, params);
+ return callAPIWithResource(api, resource, requestBody, responseType);
+ }
+
+ public <T> T callAPI(API api, Class<T> responseType, MultivaluedMap<String, String> queryParams, String... params)
+ throws AtlasServiceException {
+ WebResource resource = getResource(api, queryParams, params);
+ return callAPIWithResource(api, resource, null, responseType);
+ }
+
+ public <T> T callAPI(API api, GenericType<T> responseType, MultivaluedMap<String, String> queryParams, String... params)
+ throws AtlasServiceException {
+ WebResource resource = getResource(api, queryParams, params);
+ return callAPIWithResource(api, resource, null, responseType);
+ }
+
+ public <T> T callAPI(API api, Class<T> responseType, MultivaluedMap<String, String> queryParams)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, queryParams), null, responseType);
+ }
+
+ public <T> T callAPI(API api, Class<T> responseType, String queryParamKey, List<String> queryParamValues)
+ throws AtlasServiceException {
+ return callAPIWithResource(api, getResource(api, queryParamKey, queryParamValues), null, responseType);
+ }
+
+ @VisibleForTesting
+ protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
+ DefaultClientConfig config = new DefaultClientConfig();
+ // Enable POJO mapping feature
+ config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
+ int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000);
+ int connectTimeout = configuration.getInt("atlas.client.connectTimeoutMSecs", 60000);
+ if (configuration.getBoolean(TLS_ENABLED, false)) {
+ // create an SSL properties configuration if one doesn't exist. SSLFactory expects a file, so forced
+ // to create a
+ // configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory
+ try {
+ SecureClientUtils.persistSSLClientConfiguration(configuration);
+ } catch (Exception e) {
+ LOG.info("Error processing client configuration.", e);
+ }
+ }
+
+ final URLConnectionClientHandler handler;
+
+ if ((AuthenticationUtil.isKerberosAuthenticationEnabled())) {
+ handler = SecureClientUtils.getClientConnectionHandler(config, configuration, doAsUser, ugi);
+ } else {
+ if (configuration.getBoolean(TLS_ENABLED, false)) {
+ handler = SecureClientUtils.getUrlConnectionClientHandler();
+ } else {
+ handler = new URLConnectionClientHandler();
+ }
+ }
+ Client client = new Client(handler, config);
+ client.setReadTimeout(readTimeout);
+ client.setConnectTimeout(connectTimeout);
+ return client;
+ }
+
+ @VisibleForTesting
+ protected String determineActiveServiceURL(String[] baseUrls, Client client) {
+ if (baseUrls.length == 0) {
+ throw new IllegalArgumentException("Base URLs cannot be null or empty");
+ }
+ final String baseUrl;
+ AtlasServerEnsemble atlasServerEnsemble = new AtlasServerEnsemble(baseUrls);
+ if (atlasServerEnsemble.hasSingleInstance()) {
+ baseUrl = atlasServerEnsemble.firstURL();
+ LOG.info("Client has only one service URL, will use that for all actions: {}", baseUrl);
+ } else {
+ try {
+ baseUrl = selectActiveServerAddress(client, atlasServerEnsemble);
+ } catch (AtlasServiceException e) {
+ LOG.error("None of the passed URLs are active: {}", atlasServerEnsemble, e);
+ throw new IllegalArgumentException("None of the passed URLs are active " + atlasServerEnsemble, e);
+ }
+ }
+ return baseUrl;
+ }
+
+ protected Configuration getClientProperties() {
+ try {
+ if (configuration == null) {
+ configuration = ApplicationProperties.get();
+ }
+ } catch (AtlasException e) {
+ LOG.error("Exception while loading configuration.", e);
+ }
+ return configuration;
+ }
+
+ protected WebResource getResource(String path, String... pathParams) {
+ return getResource(service, path, pathParams);
+ }
+
+ protected <T> T callAPIWithResource(API api, WebResource resource, Object requestObject, Class<T> responseType) throws AtlasServiceException {
+ GenericType<T> genericType = null;
+ if (responseType != null) {
+ genericType = new GenericType<>(responseType);
+ }
+ return callAPIWithResource(api, resource, requestObject, genericType);
+ }
+
+ protected <T> T callAPIWithResource(API api, WebResource resource, Object requestObject, GenericType<T> responseType) throws AtlasServiceException {
+ ClientResponse clientResponse = null;
+ int i = 0;
+ do {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Calling API [ {} : {} ] {}", api.getMethod(), api.getPath(), requestObject != null ? "<== " + requestObject : "");
+ }
+
+ WebResource.Builder requestBuilder = resource.getRequestBuilder();
+
+ // Set content headers
+ requestBuilder
+ .accept(JSON_MEDIA_TYPE)
+ .type(JSON_MEDIA_TYPE);
+
+ // Set cookie if present
+ if (cookie != null) {
+ requestBuilder.cookie(cookie);
+ }
+
+ clientResponse = requestBuilder.method(api.getMethod(), ClientResponse.class, requestObject);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("API {} returned status {}", resource.getURI(), clientResponse.getStatus());
+ }
+
+ if (clientResponse.getStatus() == api.getExpectedStatus().getStatusCode()) {
+ if (null == responseType) {
+ return null;
+ }
+ try {
+ if (responseType.getRawClass() == JSONObject.class) {
+ String stringEntity = clientResponse.getEntity(String.class);
+ try {
+ JSONObject jsonObject = new JSONObject(stringEntity);
+ LOG.info("Response = {}", jsonObject);
+ return (T) jsonObject;
+ } catch (JSONException e) {
+ throw new AtlasServiceException(api, e);
+ }
+ } else {
+ T entity = clientResponse.getEntity(responseType);
+ return entity;
+ }
+ } catch (ClientHandlerException e) {
+ throw new AtlasServiceException(api, e);
+ }
+ } else if (clientResponse.getStatus() != ClientResponse.Status.SERVICE_UNAVAILABLE.getStatusCode()) {
+ break;
+ } else {
+ LOG.error("Got a service unavailable when calling: {}, will retry..", resource);
+ sleepBetweenRetries();
+ }
+
+ i++;
+ } while (i < getNumberOfRetries());
+
+ throw new AtlasServiceException(api, clientResponse);
+ }
+
+ protected WebResource getResource(API api, String... pathParams) {
+ return getResource(service, api, pathParams);
+ }
+
+ protected WebResource getResource(API api, MultivaluedMap<String, String> queryParams, String... pathParams) {
+ WebResource resource = service.path(api.getPath());
+ resource = appendPathParams(resource, pathParams);
+ resource = appendQueryParams(queryParams, resource);
+ return resource;
+ }
+
+ protected WebResource getResource(API api, MultivaluedMap<String, String> queryParams) {
+ return getResource(service, api, queryParams);
+ }
+
+ protected abstract API formatPathParameters(API api, String ... params);
+
+ void initializeState(String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
+ initializeState(getClientProperties(), baseUrls, ugi, doAsUser);
+ }
+
+ void initializeState(Configuration configuration, String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
+ this.configuration = configuration;
+ Client client = getClient(configuration, ugi, doAsUser);
+
+ if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
+ final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(basicAuthUser, basicAuthPassword);
+ client.addFilter(authFilter);
+ }
+
+ String activeServiceUrl = determineActiveServiceURL(baseUrls, client);
+ atlasClientContext = new AtlasClientContext(baseUrls, client, ugi, doAsUser);
+ service = client.resource(UriBuilder.fromUri(activeServiceUrl).build());
+ }
+
+ void sleepBetweenRetries() {
+ try {
+ Thread.sleep(getSleepBetweenRetriesMs());
+ } catch (InterruptedException e) {
+ LOG.error("Interrupted from sleeping between retries.", e);
+ }
+ }
+
+ int getNumberOfRetries() {
+ return configuration.getInt(AtlasBaseClient.ATLAS_CLIENT_HA_RETRIES_KEY, AtlasBaseClient.DEFAULT_NUM_RETRIES);
+ }
+
+ boolean isRetryableException(ClientHandlerException che) {
+ return che.getCause().getClass().equals(IOException.class)
+ || che.getCause().getClass().equals(ConnectException.class);
+ }
+
+ void handleClientHandlerException(ClientHandlerException che) {
+ if (isRetryableException(che)) {
+ atlasClientContext.getClient().destroy();
+ LOG.warn("Destroyed current context while handling ClientHandlerEception.");
+ LOG.warn("Will retry and create new context.");
+ sleepBetweenRetries();
+ initializeState(atlasClientContext.getBaseUrls(), atlasClientContext.getUgi(),
+ atlasClientContext.getDoAsUser());
+ return;
+ }
+ throw che;
+ }
+
+ @VisibleForTesting
+ JSONObject callAPIWithRetries(API api, Object requestObject, ResourceCreator resourceCreator)
+ throws AtlasServiceException {
+ for (int i = 0; i < getNumberOfRetries(); i++) {
+ WebResource resource = resourceCreator.createResource();
+ try {
+ LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1);
+ return callAPIWithResource(api, resource, requestObject, JSONObject.class);
+ } catch (ClientHandlerException che) {
+ if (i == (getNumberOfRetries() - 1)) {
+ throw che;
+ }
+ LOG.warn("Handled exception in calling api {}", api.getPath(), che);
+ LOG.warn("Exception's cause: {}", che.getCause().getClass());
+ handleClientHandlerException(che);
+ }
+ }
+ throw new AtlasServiceException(api, new RuntimeException("Could not get response after retries."));
+ }
+
+ @VisibleForTesting
+ void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ @VisibleForTesting
+ void setService(WebResource resource) {
+ this.service = resource;
+ }
+
+ private String selectActiveServerAddress(Client client, AtlasServerEnsemble serverEnsemble)
+ throws AtlasServiceException {
+ List<String> serverInstances = serverEnsemble.getMembers();
+ String activeServerAddress = null;
+ for (String serverInstance : serverInstances) {
+ LOG.info("Trying with address {}", serverInstance);
+ activeServerAddress = getAddressIfActive(client, serverInstance);
+ if (activeServerAddress != null) {
+ LOG.info("Found service {} as active service.", serverInstance);
+ break;
+ }
+ }
+ if (activeServerAddress != null)
+ return activeServerAddress;
+ else
+ throw new AtlasServiceException(API_STATUS, new RuntimeException("Could not find any active instance"));
+ }
+
+ private String getAddressIfActive(Client client, String serverInstance) {
+ String activeServerAddress = null;
+ for (int i = 0; i < getNumberOfRetries(); i++) {
+ try {
+ service = client.resource(UriBuilder.fromUri(serverInstance).build());
+ String adminStatus = getAdminStatus();
+ if (StringUtils.equals(adminStatus, "ACTIVE")) {
+ activeServerAddress = serverInstance;
+ break;
+ } else {
+ LOG.info("attempt #{}: Service {} - is not active. status={}", (i + 1), serverInstance, adminStatus);
+ }
+ } catch (Exception e) {
+ LOG.error("attempt #{}: Service {} - could not get status", (i + 1), serverInstance, e);
+ }
+ sleepBetweenRetries();
+ }
+ return activeServerAddress;
+ }
+
+ private WebResource getResource(WebResource service, String path, String... pathParams) {
+ WebResource resource = service.path(path);
+ resource = appendPathParams(resource, pathParams);
+ return resource;
+ }
+
+ private int getSleepBetweenRetriesMs() {
+ return configuration.getInt(AtlasBaseClient.ATLAS_CLIENT_HA_SLEEP_INTERVAL_MS_KEY, AtlasBaseClient.DEFAULT_SLEEP_BETWEEN_RETRIES_MS);
+ }
+
+ // Modify URL to include the path params
+ private WebResource getResource(WebResource service, API api, String... pathParams) {
+ WebResource resource = service.path(api.getPath());
+ resource = appendPathParams(resource, pathParams);
+ return resource;
+ }
+
+ private WebResource getResource(API api, String queryParamKey, List<String> queryParamValues) {
+ WebResource resource = service.path(api.getPath());
+ for (String queryParamValue : queryParamValues) {
+ if (StringUtils.isNotBlank(queryParamKey) && StringUtils.isNotBlank(queryParamValue)) {
+ resource = resource.queryParam(queryParamKey, queryParamValue);
+ }
+ }
+ return resource;
+ }
+
+ private WebResource appendPathParams(WebResource resource, String[] pathParams) {
+ if (pathParams != null) {
+ for (String pathParam : pathParams) {
+ resource = resource.path(pathParam);
+ }
+ }
+ return resource;
+ }
+
+ // Modify URL to include the query params
+ private WebResource getResource(WebResource service, API api, MultivaluedMap<String, String> queryParams) {
+ WebResource resource = service.path(api.getPath());
+ resource = appendQueryParams(queryParams, resource);
+ return resource;
+ }
+
+ private WebResource appendQueryParams(MultivaluedMap<String, String> queryParams, WebResource resource) {
+ if (null != queryParams && !queryParams.isEmpty()) {
+ for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
+ for (String value : entry.getValue()) {
+ if (StringUtils.isNotBlank(value)) {
+ resource = resource.queryParam(entry.getKey(), value);
+ }
+ }
+ }
+ }
+ return resource;
+ }
+
+ public static class API {
+ private final String method;
+ private final String path;
+ private final Response.Status status;
+
+ public API(String path, String method, Response.Status status) {
+ this.path = path;
+ this.method = method;
+ this.status = status;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public Response.Status getExpectedStatus() {
+ return status;
+ }
+ }
+
+ /**
+ * A class to capture input state while creating the client.
+ *
+ * The information here will be reused when the client is re-initialized on switch-over
+ * in case of High Availability.
+ */
+ private class AtlasClientContext {
+ private String[] baseUrls;
+ private Client client;
+ private String doAsUser;
+ private UserGroupInformation ugi;
+
+ public AtlasClientContext(String[] baseUrls, Client client, UserGroupInformation ugi, String doAsUser) {
+ this.baseUrls = baseUrls;
+ this.client = client;
+ this.ugi = ugi;
+ this.doAsUser = doAsUser;
+ }
+
+ public Client getClient() {
+ return client;
+ }
+
+ public String[] getBaseUrls() {
+ return baseUrls;
+ }
+
+ public String getDoAsUser() {
+ return doAsUser;
+ }
+
+ public UserGroupInformation getUgi() {
+ return ugi;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/common/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
----------------------------------------------------------------------
diff --git a/client/common/src/main/java/org/apache/atlas/AtlasServerEnsemble.java b/client/common/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
new file mode 100644
index 0000000..01e4e32
--- /dev/null
+++ b/client/common/src/main/java/org/apache/atlas/AtlasServerEnsemble.java
@@ -0,0 +1,52 @@
+/**
+ * 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;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang.StringUtils;
+import java.util.Arrays;
+
+import java.util.List;
+
+public class AtlasServerEnsemble {
+
+ private final String[] urls;
+
+ public AtlasServerEnsemble(String[] baseUrls) {
+ Preconditions.checkArgument((baseUrls!=null && baseUrls.length>0),
+ "List of baseURLs cannot be null or empty.");
+ for (String baseUrl : baseUrls) {
+ Preconditions.checkArgument(StringUtils.isNotEmpty(baseUrl),
+ "Base URL cannot be null or empty.");
+ }
+ urls = baseUrls;
+ }
+
+ public boolean hasSingleInstance() {
+ return urls.length==1;
+ }
+
+ public String firstURL() {
+ return urls[0];
+ }
+
+ public List<String> getMembers() {
+ return Arrays.asList(urls);
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
----------------------------------------------------------------------
diff --git a/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
new file mode 100755
index 0000000..83f4f8d
--- /dev/null
+++ b/client/common/src/main/java/org/apache/atlas/AtlasServiceException.java
@@ -0,0 +1,56 @@
+/**
+ * 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;
+
+import com.sun.jersey.api.client.ClientResponse;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+
+import javax.ws.rs.WebApplicationException;
+
+public class AtlasServiceException extends Exception {
+ private ClientResponse.Status status;
+
+ public AtlasServiceException(AtlasBaseClient.API api, Exception e) {
+ super("Metadata service API " + api.getMethod() + " : " + api.getPath() + " failed", e);
+ }
+
+ public AtlasServiceException(AtlasBaseClient.API api, WebApplicationException e) throws JSONException {
+ this(api, ClientResponse.Status.fromStatusCode(e.getResponse().getStatus()),
+ ((JSONObject) e.getResponse().getEntity()).getString("stackTrace"));
+ }
+
+ private AtlasServiceException(AtlasBaseClient.API api, ClientResponse.Status status, String response) {
+ super("Metadata service API " + api + " failed with status " + (status != null ? status.getStatusCode() : -1)
+ + " (" + status + ") Response Body (" + response + ")");
+ this.status = status;
+ }
+
+ public AtlasServiceException(AtlasBaseClient.API api, ClientResponse response) {
+ this(api, ClientResponse.Status.fromStatusCode(response.getStatus()), response.getEntity(String.class));
+ }
+
+ public AtlasServiceException(Exception e) {
+ super(e);
+ }
+
+ public ClientResponse.Status getStatus() {
+ return status;
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/client/common/src/main/java/org/apache/atlas/ResourceCreator.java
----------------------------------------------------------------------
diff --git a/client/common/src/main/java/org/apache/atlas/ResourceCreator.java b/client/common/src/main/java/org/apache/atlas/ResourceCreator.java
new file mode 100644
index 0000000..2017065
--- /dev/null
+++ b/client/common/src/main/java/org/apache/atlas/ResourceCreator.java
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+import com.sun.jersey.api.client.WebResource;
+
+/**
+ * An interface to capture the closure of how a WebResource is created.
+ */
+@Deprecated
+public interface ResourceCreator {
+ WebResource createResource();
+}
[2/7] atlas git commit: ATLAS-2179: Split Atlas client library to
avoid unnecessary dependencies
Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/main/java/org/apache/atlas/ApplicationProperties.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/ApplicationProperties.java b/intg/src/main/java/org/apache/atlas/ApplicationProperties.java
new file mode 100644
index 0000000..a35bdfe
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/ApplicationProperties.java
@@ -0,0 +1,203 @@
+/**
+ * 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;
+
+import org.apache.atlas.security.InMemoryJAASConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Iterator;
+
+/**
+ * Application properties used by Atlas.
+ */
+public final class ApplicationProperties extends PropertiesConfiguration {
+ public static final String ATLAS_CONFIGURATION_DIRECTORY_PROPERTY = "atlas.conf";
+
+ private static final Logger LOG = LoggerFactory.getLogger(ApplicationProperties.class);
+
+ public static final String APPLICATION_PROPERTIES = "atlas-application.properties";
+
+ private static volatile Configuration instance = null;
+
+ private ApplicationProperties(URL url) throws ConfigurationException {
+ super(url);
+ }
+
+ public static void forceReload() {
+ if (instance != null) {
+ synchronized (ApplicationProperties.class) {
+ if (instance != null) {
+ instance = null;
+ }
+ }
+ }
+ }
+
+ public static Configuration get() throws AtlasException {
+ if (instance == null) {
+ synchronized (ApplicationProperties.class) {
+ if (instance == null) {
+ instance = get(APPLICATION_PROPERTIES);
+ InMemoryJAASConfiguration.init(instance);
+ }
+ }
+ }
+ return instance;
+ }
+
+ public static Configuration get(String fileName) throws AtlasException {
+ String confLocation = System.getProperty(ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
+ try {
+ URL url = null;
+
+ if (confLocation == null) {
+ LOG.info("Looking for {} in classpath", fileName);
+
+ url = ApplicationProperties.class.getClassLoader().getResource(fileName);
+
+ if (url == null) {
+ LOG.info("Looking for /{} in classpath", fileName);
+
+ url = ApplicationProperties.class.getClassLoader().getResource("/" + fileName);
+ }
+ } else {
+ url = new File(confLocation, fileName).toURI().toURL();
+ }
+
+ LOG.info("Loading {} from {}", fileName, url);
+
+ Configuration configuration = new ApplicationProperties(url).interpolatedConfiguration();
+ logConfiguration(configuration);
+ return configuration;
+ } catch (Exception e) {
+ throw new AtlasException("Failed to load application properties", e);
+ }
+ }
+
+ private static void logConfiguration(Configuration configuration) {
+ if (LOG.isDebugEnabled()) {
+ Iterator<String> keys = configuration.getKeys();
+ LOG.debug("Configuration loaded:");
+ while (keys.hasNext()) {
+ String key = keys.next();
+ LOG.debug("{} = {}", key, configuration.getProperty(key));
+ }
+ }
+ }
+
+ public static Configuration getSubsetConfiguration(Configuration inConf, String prefix) {
+ return inConf.subset(prefix);
+ }
+
+ public static Class getClass(Configuration configuration, String propertyName, String defaultValue,
+ Class assignableClass) throws AtlasException {
+ try {
+ String propertyValue = configuration.getString(propertyName, defaultValue);
+ Class<?> clazz = Class.forName(propertyValue);
+ if (assignableClass == null || assignableClass.isAssignableFrom(clazz)) {
+ return clazz;
+ } else {
+ String message = "Class " + clazz.getName() + " specified in property " + propertyName
+ + " is not assignable to class " + assignableClass.getName();
+ LOG.error(message);
+ throw new AtlasException(message);
+ }
+ } catch (Exception e) {
+ throw new AtlasException(e);
+ }
+ }
+
+ /**
+ * Get the specified property as an {@link InputStream}.
+ * If the property is not set, then the specified default filename
+ * is searched for in the following locations, in order of precedence:
+ * 1. Atlas configuration directory specified by the {@link #ATLAS_CONFIGURATION_DIRECTORY_PROPERTY} system property
+ * 2. relative to the working directory if {@link #ATLAS_CONFIGURATION_DIRECTORY_PROPERTY} is not set
+ * 3. as a classloader resource
+ *
+ * @param configuration
+ * @param propertyName
+ * @param defaultFileName name of file to use by default if specified property is not set in the configuration- if null,
+ * an {@link AtlasException} is thrown if the property is not set
+ * @return an {@link InputStream}
+ * @throws AtlasException if no file was found or if there was an error loading the file
+ */
+ public static InputStream getFileAsInputStream(Configuration configuration, String propertyName, String defaultFileName) throws AtlasException {
+ File fileToLoad = null;
+ String fileName = configuration.getString(propertyName);
+ if (fileName == null) {
+ if (defaultFileName == null) {
+ throw new AtlasException(propertyName + " property not set and no default value specified");
+ }
+ fileName = defaultFileName;
+ String atlasConfDir = System.getProperty(ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
+ if (atlasConfDir != null) {
+ // Look for default filename in Atlas config directory
+ fileToLoad = new File(atlasConfDir, fileName);
+ }
+ else {
+ // Look for default filename under the working directory
+ fileToLoad = new File(fileName);
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("{} property not set - defaulting to {}", propertyName, fileToLoad.getPath());
+ }
+ }
+ else {
+ // Look for configured filename
+ fileToLoad = new File(fileName);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using {} property setting: {}", propertyName, fileToLoad.getPath());
+ }
+ }
+
+ InputStream inStr = null;
+ if (fileToLoad.exists()) {
+ try {
+ inStr = new FileInputStream(fileToLoad);
+ } catch (FileNotFoundException e) {
+ throw new AtlasException("Error loading file " + fileName, e);
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Loaded file from : {}", fileToLoad.getPath());
+ }
+ }
+ else {
+ // Look for file as class loader resource
+ inStr = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
+ if (inStr == null) {
+ String msg = fileName + " not found in file system or as class loader resource";
+ LOG.error(msg);
+ throw new AtlasException(msg);
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Loaded {} as resource from : {}", fileName, Thread.currentThread().getContextClassLoader().getResource(fileName).toString());
+ }
+ }
+ return inStr;
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/main/java/org/apache/atlas/AtlasException.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/AtlasException.java b/intg/src/main/java/org/apache/atlas/AtlasException.java
new file mode 100644
index 0000000..45d91d4
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/AtlasException.java
@@ -0,0 +1,43 @@
+/**
+ * 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;
+
+/**
+ * Base Exception class for Atlas API.
+ */
+public class AtlasException extends Exception {
+
+ public AtlasException() {
+ }
+
+ public AtlasException(String message) {
+ super(message);
+ }
+
+ public AtlasException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public AtlasException(Throwable cause) {
+ super(cause);
+ }
+
+ public AtlasException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java b/intg/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java
new file mode 100644
index 0000000..936311b
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/security/InMemoryJAASConfiguration.java
@@ -0,0 +1,401 @@
+/**
+ * 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.security;
+
+import org.apache.atlas.AtlasException;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.configuration.ConfigurationConverter;
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.hadoop.security.SecurityUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+
+
+/**
+ * InMemoryJAASConfiguration
+ * <p>
+ * An utility class - which has a static method init to load all JAAS configuration from Application
+ * properties file (eg: atlas.properties) and set it as part of the default lookup configuration for
+ * all JAAS configuration lookup.
+ * <p>
+ * Example settings in jaas-application.properties:
+ *
+ * <pre class=code>
+ * atlas.jaas.KafkaClient.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
+ * atlas.jaas.KafkaClient.loginModuleControlFlag = required
+ * atlas.jaas.KafkaClient.option.useKeyTab = true
+ * atlas.jaas.KafkaClient.option.storeKey = true
+ * atlas.jaas.KafkaClient.option.serviceName = kafka
+ * atlas.jaas.KafkaClient.option.keyTab = /etc/security/keytabs/kafka_client.keytab
+ * atlas.jaas.KafkaClient.option.principal = kafka-client-1@EXAMPLE.COM
+
+ * atlas.jaas.MyClient.0.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
+ * atlas.jaas.MyClient.0.loginModuleControlFlag = required
+ * atlas.jaas.MyClient.0.option.useKeyTab = true
+ * atlas.jaas.MyClient.0.option.storeKey = true
+ * atlas.jaas.MyClient.0.option.serviceName = kafka
+ * atlas.jaas.MyClient.0.option.keyTab = /etc/security/keytabs/kafka_client.keytab
+ * atlas.jaas.MyClient.0.option.principal = kafka-client-1@EXAMPLE.COM
+ * atlas.jaas.MyClient.1.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
+ * atlas.jaas.MyClient.1.loginModuleControlFlag = optional
+ * atlas.jaas.MyClient.1.option.useKeyTab = true
+ * atlas.jaas.MyClient.1.option.storeKey = true
+ * atlas.jaas.MyClient.1.option.serviceName = kafka
+ * atlas.jaas.MyClient.1.option.keyTab = /etc/security/keytabs/kafka_client.keytab
+ * atlas.jaas.MyClient.1.option.principal = kafka-client-1@EXAMPLE.COM </pre>
+ *
+ * <p>
+ * This will set the JAAS configuration - equivalent to the jaas.conf file entries:
+ *
+ * <pre class=code>
+ * KafkaClient {
+ * com.sun.security.auth.module.Krb5LoginModule required
+ * useKeyTab=true
+ * storeKey=true
+ * serviceName=kafka
+ * keyTab="/etc/security/keytabs/kafka_client.keytab"
+ * principal="kafka-client-1@EXAMPLE.COM";
+ * };
+ * MyClient {
+ * com.sun.security.auth.module.Krb5LoginModule required
+ * useKeyTab=true
+ * storeKey=true
+ * serviceName=kafka keyTab="/etc/security/keytabs/kafka_client.keytab"
+ * principal="kafka-client-1@EXAMPLE.COM";
+ * };
+ * MyClient {
+ * com.sun.security.auth.module.Krb5LoginModule optional
+ * useKeyTab=true
+ * storeKey=true
+ * serviceName=kafka
+ * keyTab="/etc/security/keytabs/kafka_client.keytab"
+ * principal="kafka-client-1@EXAMPLE.COM";
+ * }; </pre>
+ * <p>
+ * Here is the syntax for atlas.properties to add JAAS configuration:
+ * <p>
+ * The property name has to begin with 'atlas.jaas.' + clientId (in case of Kafka client,
+ * it expects the clientId to be KafkaClient).
+ * <p>
+ * The following property must be there to specify the JAAS loginModule name
+ * <pre> 'atlas.jaas.' + clientId + '.loginModuleName' </pre>
+ * <p>
+ * The following optional property should be set to specify the loginModuleControlFlag
+ * <pre> 'atlas.jaas.' + clientId + '.loginModuleControlFlag'
+ * Default value : required , Possible values: required, optional, sufficient, requisite </pre>
+ * <p>
+ * Then you can add additional optional parameters as options for the configuration using the following
+ * syntax:
+ * <pre> 'atlas.jaas.' + clientId + '.option.' + <optionName> = <optionValue> </pre>
+ * <p>
+ * The current setup will lookup JAAS configration from the atlas-application.properties first,
+ * if not available, it will delegate to the original configuration
+ *
+ */
+
+
+public final class InMemoryJAASConfiguration extends Configuration {
+
+ private static final Logger LOG = LoggerFactory.getLogger(InMemoryJAASConfiguration.class);
+
+ private static final String JAAS_CONFIG_PREFIX_PARAM = "atlas.jaas.";
+ private static final String JAAS_CONFIG_LOGIN_MODULE_NAME_PARAM = "loginModuleName";
+ private static final String JAAS_CONFIG_LOGIN_MODULE_CONTROL_FLAG_PARAM = "loginModuleControlFlag";
+ private static final String JAAS_CONFIG_LOGIN_OPTIONS_PREFIX = "option";
+ private static final String JAAS_PRINCIPAL_PROP = "principal";
+ private static final Map<String, String> CONFIG_SECTION_REDIRECTS = new HashMap<>();
+
+ private Configuration parent = null;
+ private Map<String, List<AppConfigurationEntry>> applicationConfigEntryMap = new HashMap<>();
+
+ public static void init(String propFile) throws AtlasException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> InMemoryJAASConfiguration.init({})", propFile);
+ }
+
+ InputStream in = null;
+
+ try {
+ Properties properties = new Properties();
+ in = ClassLoader.getSystemResourceAsStream(propFile);
+ if (in == null) {
+ if (!propFile.startsWith("/")) {
+ in = ClassLoader.getSystemResourceAsStream("/" + propFile);
+ }
+ if (in == null) {
+ in = new FileInputStream(new File(propFile));
+ }
+ }
+ properties.load(in);
+ init(properties);
+ } catch (IOException e) {
+ throw new AtlasException("Failed to load JAAS application properties", e);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (Exception exception) {
+ // Ignore
+ }
+ }
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<== InMemoryJAASConfiguration.init({})", propFile);
+ }
+ }
+
+ public static void init(org.apache.commons.configuration.Configuration atlasConfiguration) throws AtlasException {
+ LOG.debug("==> InMemoryJAASConfiguration.init()");
+
+ if (atlasConfiguration != null && !atlasConfiguration.isEmpty()) {
+ Properties properties = ConfigurationConverter.getProperties(atlasConfiguration);
+ init(properties);
+ } else {
+ throw new AtlasException("Failed to load JAAS application properties: configuration NULL or empty!");
+ }
+
+ LOG.debug("<== InMemoryJAASConfiguration.init()");
+ }
+
+ public static void init(Properties properties) throws AtlasException {
+ LOG.debug("==> InMemoryJAASConfiguration.init()");
+
+ if (properties != null && MapUtils.isNotEmpty(properties)) {
+ InMemoryJAASConfiguration conf = new InMemoryJAASConfiguration(properties);
+ Configuration.setConfiguration(conf);
+ } else {
+ throw new AtlasException("Failed to load JAAS application properties: properties NULL or empty!");
+ }
+
+ LOG.debug("<== InMemoryJAASConfiguration.init()");
+ }
+
+ @Override
+ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> InMemoryJAASConfiguration.getAppConfigurationEntry({})", name);
+ }
+
+ AppConfigurationEntry[] ret = null;
+ List<AppConfigurationEntry> retList = null;
+ String redirectedName = getConfigSectionRedirect(name);
+
+ if (redirectedName != null) {
+ retList = applicationConfigEntryMap.get(redirectedName);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Redirected jaasConfigSection ({} -> {}): ", name, redirectedName, retList);
+ }
+ }
+
+ if (retList == null || retList.size() == 0) {
+ retList = applicationConfigEntryMap.get(name);
+ }
+
+ if (retList == null || retList.size() == 0) {
+ if (parent != null) {
+ ret = parent.getAppConfigurationEntry(name);
+ }
+ } else {
+ int sz = retList.size();
+ ret = new AppConfigurationEntry[sz];
+ ret = retList.toArray(ret);
+ }
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<== InMemoryJAASConfiguration.getAppConfigurationEntry({}): {}", name, ArrayUtils.toString(ret));
+ }
+
+ return ret;
+ }
+
+ private InMemoryJAASConfiguration(Properties prop) {
+ parent = Configuration.getConfiguration();
+ initialize(prop);
+ }
+
+ private void initialize(Properties properties) {
+ LOG.debug("==> InMemoryJAASConfiguration.initialize()");
+
+ int prefixLen = JAAS_CONFIG_PREFIX_PARAM.length();
+
+ Map<String, SortedSet<Integer>> jaasClients = new HashMap<>();
+ for (String key : properties.stringPropertyNames()) {
+ if (key.startsWith(JAAS_CONFIG_PREFIX_PARAM)) {
+ String jaasKey = key.substring(prefixLen);
+ StringTokenizer tokenizer = new StringTokenizer(jaasKey, ".");
+ int tokenCount = tokenizer.countTokens();
+ if (tokenCount > 0) {
+ String clientId = tokenizer.nextToken();
+ SortedSet<Integer> indexList = jaasClients.get(clientId);
+ if (indexList == null) {
+ indexList = new TreeSet<>();
+ jaasClients.put(clientId, indexList);
+ }
+ String indexStr = tokenizer.nextToken();
+
+ int indexId = isNumeric(indexStr) ? Integer.parseInt(indexStr) : -1;
+
+ Integer clientIdIndex = Integer.valueOf(indexId);
+
+ if (!indexList.contains(clientIdIndex)) {
+ indexList.add(clientIdIndex);
+ }
+
+ }
+ }
+ }
+ for (String jaasClient : jaasClients.keySet()) {
+
+ for (Integer index : jaasClients.get(jaasClient)) {
+
+ String keyPrefix = JAAS_CONFIG_PREFIX_PARAM + jaasClient + ".";
+
+ if (index > -1) {
+ keyPrefix = keyPrefix + String.valueOf(index) + ".";
+ }
+
+ String keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_NAME_PARAM;
+ String loginModuleName = properties.getProperty(keyParam);
+
+ if (loginModuleName == null) {
+ LOG.error("Unable to add JAAS configuration for client [{}] as it is missing param [{}]. Skipping JAAS config for [{}]", jaasClient, keyParam, jaasClient);
+ continue;
+ } else {
+ loginModuleName = loginModuleName.trim();
+ }
+
+ keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_CONTROL_FLAG_PARAM;
+ String controlFlag = properties.getProperty(keyParam);
+
+ AppConfigurationEntry.LoginModuleControlFlag loginControlFlag = null;
+ if (controlFlag != null) {
+ controlFlag = controlFlag.trim().toLowerCase();
+ switch (controlFlag) {
+ case "optional":
+ loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
+ break;
+ case "requisite":
+ loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
+ break;
+ case "sufficient":
+ loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
+ break;
+ case "required":
+ loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
+ break;
+ default:
+ String validValues = "optional|requisite|sufficient|required";
+ LOG.warn("Unknown JAAS configuration value for ({}) = [{}], valid value are [{}] using the default value, REQUIRED", keyParam, controlFlag, validValues);
+ loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
+ break;
+ }
+ } else {
+ LOG.warn("Unable to find JAAS configuration ({}); using the default value, REQUIRED", keyParam);
+ loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
+ }
+
+
+ Map<String, String> options = new HashMap<>();
+ String optionPrefix = keyPrefix + JAAS_CONFIG_LOGIN_OPTIONS_PREFIX + ".";
+ int optionPrefixLen = optionPrefix.length();
+ for (String key : properties.stringPropertyNames()) {
+ if (key.startsWith(optionPrefix)) {
+ String optionKey = key.substring(optionPrefixLen);
+ String optionVal = properties.getProperty(key);
+ if (optionVal != null) {
+ optionVal = optionVal.trim();
+
+ try {
+ if (optionKey.equalsIgnoreCase(JAAS_PRINCIPAL_PROP)) {
+ optionVal = SecurityUtil.getServerPrincipal(optionVal, (String) null);
+ }
+ } catch (IOException e) {
+ LOG.warn("Failed to build serverPrincipal. Using provided value:[{}]", optionVal);
+ }
+ }
+ options.put(optionKey, optionVal);
+ }
+ }
+
+ AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName, loginControlFlag, options);
+
+ if (LOG.isDebugEnabled()) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Adding client: [").append(jaasClient).append("{").append(index).append("}]\n");
+ sb.append("\tloginModule: [").append(loginModuleName).append("]\n");
+ sb.append("\tcontrolFlag: [").append(loginControlFlag).append("]\n");
+ for (String key : options.keySet()) {
+ String val = options.get(key);
+ sb.append("\tOptions: [").append(key).append("] => [").append(val).append("]\n");
+ }
+ LOG.debug(sb.toString());
+ }
+
+ List<AppConfigurationEntry> retList = applicationConfigEntryMap.get(jaasClient);
+ if (retList == null) {
+ retList = new ArrayList<>();
+ applicationConfigEntryMap.put(jaasClient, retList);
+ }
+
+ retList.add(entry);
+ }
+ }
+
+ LOG.debug("<== InMemoryJAASConfiguration.initialize({})", applicationConfigEntryMap);
+ }
+
+ private static boolean isNumeric(String str) {
+ return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal.
+ }
+
+ public static void setConfigSectionRedirect(String name, String redirectTo) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("setConfigSectionRedirect({}, {})", name, redirectTo);
+ }
+
+ if (name != null) {
+ if (redirectTo != null) {
+ CONFIG_SECTION_REDIRECTS.put(name, redirectTo);
+ } else {
+ CONFIG_SECTION_REDIRECTS.remove(name);
+ }
+ }
+ }
+
+ private static String getConfigSectionRedirect(String name) {
+ return name != null ? CONFIG_SECTION_REDIRECTS.get(name) : null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/main/java/org/apache/atlas/security/SecurityProperties.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/security/SecurityProperties.java b/intg/src/main/java/org/apache/atlas/security/SecurityProperties.java
new file mode 100644
index 0000000..2e953eb
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/security/SecurityProperties.java
@@ -0,0 +1,49 @@
+/**
+ * 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.security;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ *
+ */
+public final class SecurityProperties {
+
+ private SecurityProperties() {
+ }
+
+ public static final String TLS_ENABLED = "atlas.enableTLS";
+ public static final String KEYSTORE_FILE_KEY = "keystore.file";
+ public static final String DEFAULT_KEYSTORE_FILE_LOCATION = "target/atlas.keystore";
+ public static final String KEYSTORE_PASSWORD_KEY = "keystore.password";
+ public static final String TRUSTSTORE_FILE_KEY = "truststore.file";
+ public static final String DEFATULT_TRUSTORE_FILE_LOCATION = "target/atlas.keystore";
+ public static final String TRUSTSTORE_PASSWORD_KEY = "truststore.password";
+ public static final String SERVER_CERT_PASSWORD_KEY = "password";
+ public static final String CLIENT_AUTH_KEY = "client.auth.enabled";
+ public static final String CERT_STORES_CREDENTIAL_PROVIDER_PATH = "cert.stores.credential.provider.path";
+ public static final String SSL_CLIENT_PROPERTIES = "ssl-client.xml";
+ public static final String BIND_ADDRESS = "atlas.server.bind.address";
+ public static final String ATLAS_SSL_EXCLUDE_CIPHER_SUITES = "atlas.ssl.exclude.cipher.suites";
+ public static final List<String> DEFAULT_CIPHER_SUITES = Arrays.asList(
+ ".*NULL.*", ".*RC4.*", ".*MD5.*", ".*DES.*", ".*DSS.*");
+ public static final String ATLAS_SSL_EXCLUDE_PROTOCOLS = "atlas.ssl.exclude.protocols";
+ public static final String[] DEFAULT_EXCLUDE_PROTOCOLS = new String[] { "TLSv1", "TLSv1.1" };
+
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java b/intg/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java
new file mode 100644
index 0000000..09d8085
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/utils/AuthenticationUtil.java
@@ -0,0 +1,70 @@
+/**
+ * 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.atlas.ApplicationProperties;
+import org.apache.atlas.AtlasException;
+import org.apache.commons.configuration.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.Console;
+
+/**
+ * Util class for Authentication.
+ */
+public final class AuthenticationUtil {
+ private static final Logger LOG = LoggerFactory.getLogger(AuthenticationUtil.class);
+
+ private AuthenticationUtil() {
+ }
+
+ public static boolean isKerberosAuthenticationEnabled() {
+ boolean isKerberosAuthenticationEnabled = false;
+ try {
+ isKerberosAuthenticationEnabled = isKerberosAuthenticationEnabled(ApplicationProperties.get());
+ } catch (AtlasException e) {
+ LOG.error("Error while isKerberosAuthenticationEnabled ", e);
+ }
+ return isKerberosAuthenticationEnabled;
+ }
+
+ public static boolean isKerberosAuthenticationEnabled(Configuration atlasConf) {
+ return atlasConf.getBoolean("atlas.authentication.method.kerberos", false);
+ }
+
+ public static String[] getBasicAuthenticationInput() {
+ String username = null;
+ String password = null;
+
+ try {
+ Console console = System.console();
+ username = console.readLine("Enter username for atlas :- ");
+
+ char[] pwdChar = console.readPassword("Enter password for atlas :- ");
+ if(pwdChar != null) {
+ password = new String(pwdChar);
+ }
+
+ } catch (Exception e) {
+ System.out.print("Error while reading ");
+ System.exit(1);
+ }
+ return new String[]{username, password};
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java b/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
new file mode 100644
index 0000000..89e5e9b
--- /dev/null
+++ b/intg/src/test/java/org/apache/atlas/ApplicationPropertiesTest.java
@@ -0,0 +1,129 @@
+/**
+ * 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;
+
+import java.io.InputStream;
+
+import org.apache.commons.configuration.Configuration;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/**
+ * Unit test for {@link ApplicationProperties}
+ *
+ */
+public class ApplicationPropertiesTest {
+
+ @Test
+ public void testGetFileAsInputStream() throws Exception {
+ Configuration props = ApplicationProperties.get("test.properties");
+ InputStream inStr = null;
+
+ // configured file as class loader resource
+ try {
+ inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
+ assertNotNull(inStr);
+ }
+ finally {
+ if (inStr != null) {
+ inStr.close();
+ }
+ }
+
+ // configured file from file system path
+ props.setProperty("jaas.properties.file", "src/test/resources/atlas-jaas.properties");
+ try {
+ inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
+ assertNotNull(inStr);
+ }
+ finally {
+ if (inStr != null) {
+ inStr.close();
+ }
+ }
+
+ // default file as class loader resource
+ try {
+ inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties");
+ assertNotNull(inStr);
+ }
+ finally {
+ if (inStr != null) {
+ inStr.close();
+ }
+ }
+
+ // default file relative to working directory
+ try {
+ inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "src/test/resources/atlas-jaas.properties");
+ assertNotNull(inStr);
+ }
+ finally {
+ if (inStr != null) {
+ inStr.close();
+ }
+ }
+
+ // default file relative to atlas configuration directory
+ String originalConfDirSetting = System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, "src/test/resources");
+ try {
+ inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties");
+ assertNotNull(inStr);
+ }
+ finally {
+ if (inStr != null) {
+ inStr.close();
+ }
+ if (originalConfDirSetting != null) {
+ System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, originalConfDirSetting);
+ }
+ else {
+ System.clearProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
+ }
+ }
+
+ // non-existent property and no default file
+ try {
+ inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", null);
+ fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
+ }
+ catch (AtlasException e) {
+ // good
+ }
+ finally {
+ if (inStr != null) {
+ inStr.close();
+ }
+ }
+
+ // configured file not found in file system or classpath
+ props.setProperty("jaas.properties.file", "does_not_exist.txt");
+ try {
+ inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
+ fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
+ }
+ catch (AtlasException e) {
+ // good
+ }
+ finally {
+ if (inStr != null) {
+ inStr.close();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java b/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java
new file mode 100644
index 0000000..b26ac7f
--- /dev/null
+++ b/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.security;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.hadoop.util.StringUtils;
+import org.testng.annotations.Test;
+
+
+//Unstable test. Disabling
+@Test(enabled=false)
+public class InMemoryJAASConfigurationTest extends TestCase {
+
+ private static final String ATLAS_JAAS_PROP_FILE = "atlas-jaas.properties";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ try {
+ InMemoryJAASConfiguration.init(ATLAS_JAAS_PROP_FILE);
+ } catch(Throwable t) {
+ fail("InMemoryJAASConfiguration.init() is not expected to throw Exception:" + t);
+ }
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ @Test(enabled=false)
+ public void testGetAppConfigurationEntryStringForKafkaClient() {
+ AppConfigurationEntry[] entries =
+ Configuration.getConfiguration().getAppConfigurationEntry("KafkaClient");
+ Assert.assertNotNull(entries);
+ Assert.assertEquals(1, entries.length);
+ String principal = (String) entries[0].getOptions().get("principal");
+ Assert.assertNotNull(principal);
+ String[] components = principal.split("[/@]");
+ Assert.assertEquals(3, components.length);
+ Assert.assertEquals(false, StringUtils.equalsIgnoreCase(components[1], "_HOST"));
+
+ }
+
+ @Test(enabled=false)
+ public void testGetAppConfigurationEntryStringForMyClient() {
+ AppConfigurationEntry[] entries =
+ Configuration.getConfiguration().getAppConfigurationEntry("myClient");
+ Assert.assertNotNull(entries);
+ Assert.assertEquals(2, entries.length);
+ String principal = (String) entries[0].getOptions().get("principal");
+ Assert.assertNotNull(principal);
+ String[] components = principal.split("[/@]");
+ Assert.assertEquals(3, components.length);
+ Assert.assertEquals(true, StringUtils.equalsIgnoreCase(components[1], "abcd"));
+
+ principal = (String) entries[1].getOptions().get("principal");
+ Assert.assertNotNull(principal);
+ components = principal.split("[/@]");
+ Assert.assertEquals(2, components.length);
+ }
+
+ @Test(enabled=false)
+ public void testGetAppConfigurationEntryStringForUnknownClient() {
+ AppConfigurationEntry[] entries =
+ Configuration.getConfiguration().getAppConfigurationEntry("UnknownClient");
+ Assert.assertNull(entries);
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java b/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java
new file mode 100644
index 0000000..3d8175f
--- /dev/null
+++ b/intg/src/test/java/org/apache/atlas/security/InMemoryJAASConfigurationTicketBasedKafkaClientTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.security;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.testng.annotations.Test;
+
+
+@Test
+public class InMemoryJAASConfigurationTicketBasedKafkaClientTest extends TestCase {
+
+ private static final String ATLAS_JAAS_PROP_FILE = "atlas-jaas.properties";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ try {
+ InMemoryJAASConfiguration.init(ATLAS_JAAS_PROP_FILE);
+ InMemoryJAASConfiguration.setConfigSectionRedirect("KafkaClient", "ticketBased-KafkaClient");
+ } catch (Throwable t) {
+ fail("InMemoryJAASConfiguration.init() is not expected to throw Exception:" + t);
+ }
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+ @Test
+ public void testGetAppConfigurationEntryStringForticketBasedKafkaClient() {
+
+ AppConfigurationEntry[] entries =
+ Configuration.getConfiguration().getAppConfigurationEntry("KafkaClient");
+ Assert.assertNotNull(entries);
+ Assert.assertEquals((String) entries[0].getOptions().get("useTicketCache"), "true");
+ }
+
+
+}
+
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/test/resources/atlas-jaas.properties
----------------------------------------------------------------------
diff --git a/intg/src/test/resources/atlas-jaas.properties b/intg/src/test/resources/atlas-jaas.properties
new file mode 100644
index 0000000..9412fae
--- /dev/null
+++ b/intg/src/test/resources/atlas-jaas.properties
@@ -0,0 +1,62 @@
+#
+# 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.
+#
+
+######### Notification Configs #########
+atlas.notification.embedded=true
+
+atlas.kafka.zookeeper.connect=localhost:19026
+atlas.kafka.bootstrap.servers=localhost:19027
+atlas.kafka.data=${sys:atlas.data}/kafka
+atlas.kafka.zookeeper.session.timeout.ms=4000
+atlas.kafka.zookeeper.sync.time.ms=20
+atlas.kafka.consumer.timeout.ms=100
+atlas.kafka.auto.commit.interval.ms=100
+atlas.kafka.hook.group.id=atlas
+atlas.kafka.entities.group.id=atlas_entities
+atlas.kafka.auto.commit.enable=false
+
+######## JAAS configs ##################
+
+atlas.jaas.KafkaClient.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
+atlas.jaas.KafkaClient.loginModuleControlFlag = required
+atlas.jaas.KafkaClient.option.useKeyTab = true
+atlas.jaas.KafkaClient.option.storeKey = true
+atlas.jaas.KafkaClient.option.serviceName = kafka
+atlas.jaas.KafkaClient.option.keyTab = /etc/security/keytabs/kafka_client.keytab
+atlas.jaas.KafkaClient.option.principal = kafka-client-1/_HOST@EXAMPLE.COM
+
+atlas.jaas.myClient.0.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
+atlas.jaas.myClient.0.loginModuleControlFlag = required
+atlas.jaas.myClient.0.option.useKeyTab = true
+atlas.jaas.myClient.0.option.storeKey = true
+atlas.jaas.myClient.0.option.serviceName = kafka
+atlas.jaas.myClient.0.option.keyTab = /etc/security/keytabs/kafka_client.keytab
+atlas.jaas.myClient.0.option.principal = kafka-client-1/abcd@EXAMPLE.COM
+
+atlas.jaas.myClient.1.loginModuleName = com.sun.security.auth.module.Krb5LoginModule
+atlas.jaas.myClient.1.loginModuleControlFlag = optional
+atlas.jaas.myClient.1.option.useKeyTab = true
+atlas.jaas.myClient.1.option.storeKey = true
+atlas.jaas.myClient.1.option.serviceName = kafka
+atlas.jaas.myClient.1.option.keyTab = /etc/security/keytabs/kafka_client.keytab
+atlas.jaas.myClient.1.option.principal = kafka-client-1@EXAMPLE.COM
+
+
+atlas.jaas.ticketBased-KafkaClient.loginModuleControlFlag=required
+atlas.jaas.ticketBased-KafkaClient.loginModuleName=com.sun.security.auth.module.Krb5LoginModule
+atlas.jaas.ticketBased-KafkaClient.option.useTicketCache=true
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/intg/src/test/resources/test.properties
----------------------------------------------------------------------
diff --git a/intg/src/test/resources/test.properties b/intg/src/test/resources/test.properties
new file mode 100644
index 0000000..395537f
--- /dev/null
+++ b/intg/src/test/resources/test.properties
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+jaas.properties.file=atlas-jaas.properties
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/notification/pom.xml
----------------------------------------------------------------------
diff --git a/notification/pom.xml b/notification/pom.xml
index 192a3fc..9b36940 100644
--- a/notification/pom.xml
+++ b/notification/pom.xml
@@ -32,7 +32,7 @@
<dependencies>
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 684535a..f793321 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1385,6 +1385,18 @@
<dependency>
<groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-client-v1</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-client-v2</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
<artifactId>atlas-common</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/pom.xml
----------------------------------------------------------------------
diff --git a/repository/pom.xml b/repository/pom.xml
index 4252751..b7eedde 100755
--- a/repository/pom.xml
+++ b/repository/pom.xml
@@ -49,7 +49,7 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java
index 3426ae5..9bde5db 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasInstanceConverter.java
@@ -17,7 +17,6 @@
*/
package org.apache.atlas.repository.converters;
-import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
@@ -31,6 +30,8 @@ import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.instance.EntityMutations.EntityOperation;
import org.apache.atlas.model.instance.GuidMapping;
+import org.apache.atlas.model.legacy.EntityResult;
+import org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
@@ -46,7 +47,6 @@ import org.apache.atlas.typesystem.exception.EntityExistsException;
import org.apache.atlas.typesystem.exception.EntityNotFoundException;
import org.apache.atlas.typesystem.exception.TraitNotFoundException;
import org.apache.atlas.typesystem.exception.TypeNotFoundException;
-import org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext;
import org.apache.atlas.typesystem.types.ValueConversionException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
index 50b7116..568f6b0 100755
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java
@@ -50,16 +50,7 @@ import org.springframework.stereotype.Component;
import javax.inject.Inject;
import javax.inject.Singleton;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* An implementation backed by a Graph database provided
@@ -145,7 +136,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@GraphTransaction
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException,
- EntityExistsException {
+ EntityExistsException {
if (LOG.isDebugEnabled()) {
LOG.debug("adding entities={}", entities);
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
index ad88c1b..36cd980 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
@@ -17,8 +17,6 @@
*/
package org.apache.atlas.repository.store.graph.v1;
-import com.sun.istack.Nullable;
-import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasClassification;
@@ -40,8 +38,15 @@ import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.atlas.repository.graphdb.AtlasElement;
import org.apache.atlas.repository.graphdb.AtlasVertex;
-import org.apache.atlas.type.*;
+import org.apache.atlas.type.AtlasArrayType;
+import org.apache.atlas.type.AtlasEntityType;
+import org.apache.atlas.type.AtlasMapType;
+import org.apache.atlas.type.AtlasRelationshipType;
+import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
+import org.apache.atlas.type.AtlasType;
+import org.apache.atlas.type.AtlasTypeRegistry;
+import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -58,17 +63,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_BYTE;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_DATE;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_FLOAT;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_INT;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_LONG;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_SHORT;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_STRING;
+import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*;
import static org.apache.atlas.repository.graph.GraphHelper.EDGE_LABEL_PREFIX;
import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getIdFromVertex;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection;
@@ -80,6 +75,12 @@ import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelation
public final class EntityGraphRetriever {
private static final Logger LOG = LoggerFactory.getLogger(EntityGraphRetriever.class);
+ private final String NAME = "name";
+ private final String DESCRIPTION = "description";
+ private final String OWNER = "owner";
+ private final String CREATE_TIME = "createTime";
+ private final String QUALIFIED_NAME = "qualifiedName";
+
private static final GraphHelper graphHelper = GraphHelper.getInstance();
private final AtlasTypeRegistry typeRegistry;
@@ -232,16 +233,16 @@ public final class EntityGraphRetriever {
}
}
- Object name = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.NAME));
- Object description = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.DESCRIPTION));
- Object owner = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.OWNER));
- Object createTime = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.CREATE_TIME));
- Object displayText = name != null ? name : ret.getAttribute(AtlasClient.QUALIFIED_NAME);
+ Object name = getVertexAttribute(entityVertex, entityType.getAttribute(NAME));
+ Object description = getVertexAttribute(entityVertex, entityType.getAttribute(DESCRIPTION));
+ Object owner = getVertexAttribute(entityVertex, entityType.getAttribute(OWNER));
+ Object createTime = getVertexAttribute(entityVertex, entityType.getAttribute(CREATE_TIME));
+ Object displayText = name != null ? name : ret.getAttribute(QUALIFIED_NAME);
- ret.setAttribute(AtlasClient.NAME, name);
- ret.setAttribute(AtlasClient.DESCRIPTION, description);
- ret.setAttribute(AtlasClient.OWNER, owner);
- ret.setAttribute(AtlasClient.CREATE_TIME, createTime);
+ ret.setAttribute(NAME, name);
+ ret.setAttribute(DESCRIPTION, description);
+ ret.setAttribute(OWNER, owner);
+ ret.setAttribute(CREATE_TIME, createTime);
if (displayText != null) {
ret.setDisplayText(displayText.toString());
@@ -339,7 +340,7 @@ public final class EntityGraphRetriever {
}
- private List<AtlasClassification> getClassifications(AtlasVertex instanceVertex, @Nullable String classificationNameFilter) throws AtlasBaseException {
+ private List<AtlasClassification> getClassifications(AtlasVertex instanceVertex, String classificationNameFilter) throws AtlasBaseException {
List<AtlasClassification> classifications = new ArrayList<>();
List<String> classificationNames = GraphHelper.getTraitNames(instanceVertex);
@@ -741,10 +742,10 @@ public final class EntityGraphRetriever {
Object ret = null;
if (entityType != null) {
- ret = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.NAME));
+ ret = getVertexAttribute(entityVertex, entityType.getAttribute(NAME));
if (ret == null) {
- ret = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.QUALIFIED_NAME));
+ ret = getVertexAttribute(entityVertex, entityType.getAttribute(QUALIFIED_NAME));
}
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/test/java/org/apache/atlas/TestUtils.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/TestUtils.java b/repository/src/test/java/org/apache/atlas/TestUtils.java
index 4891279..56bfb82 100755
--- a/repository/src/test/java/org/apache/atlas/TestUtils.java
+++ b/repository/src/test/java/org/apache/atlas/TestUtils.java
@@ -528,9 +528,9 @@ public final class TestUtils {
String entityjson = InstanceSerialization.toJson(entity, true);
JSONArray entitiesJson = new JSONArray();
entitiesJson.put(entityjson);
- CreateUpdateEntitiesResult creationResult = metadataService.createEntities(entitiesJson.toString());
- Map<String,String> guidMap = creationResult.getGuidMapping().getGuidAssignments();
- Map<Id, Referenceable> referencedObjects = findReferencedObjects(entity);
+ CreateUpdateEntitiesResult creationResult = metadataService.createEntities(entitiesJson.toString());
+ Map<String,String> guidMap = creationResult.getGuidMapping().getGuidAssignments();
+ Map<Id, Referenceable> referencedObjects = findReferencedObjects(entity);
for(Map.Entry<Id,Referenceable> entry : referencedObjects.entrySet()) {
Id foundId = entry.getKey();
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java
index 0e22080..0834601 100644
--- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteTestBase.java
@@ -237,10 +237,10 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
}
private String createInstance(Referenceable entity) throws Exception {
- ClassType dataType = typeSystem.getDataType(ClassType.class, entity.getTypeName());
+ ClassType dataType = typeSystem.getDataType(ClassType.class, entity.getTypeName());
ITypedReferenceableInstance instance = dataType.convert(entity, Multiplicity.REQUIRED);
- CreateUpdateEntitiesResult result = repositoryService.createEntities(instance);
- List<String> results = result.getCreatedEntities();
+ CreateUpdateEntitiesResult result = repositoryService.createEntities(instance);
+ List<String> results = result.getCreatedEntities();
return results.get(results.size() - 1);
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
index d4c250c..6444328 100755
--- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryTest.java
@@ -22,8 +22,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
-import org.apache.atlas.TestModules;
import org.apache.atlas.RequestContext;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java
index 26dc6a8..8518f93 100644
--- a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateTestBase.java
@@ -255,10 +255,10 @@ public abstract class ReverseReferenceUpdateTestBase {
a.set("oneB", b1);
b1.set("manyA", Collections.singletonList(a));
- CreateUpdateEntitiesResult result = repositoryService.createEntities(a);
- Map<String, String> guidAssignments = result.getGuidMapping().getGuidAssignments();
- String aGuid = a.getId()._getId();
- String b1Guid = guidAssignments.get(b1.getId()._getId());
+ CreateUpdateEntitiesResult result = repositoryService.createEntities(a);
+ Map<String, String> guidAssignments = result.getGuidMapping().getGuidAssignments();
+ String aGuid = a.getId()._getId();
+ String b1Guid = guidAssignments.get(b1.getId()._getId());
a = repositoryService.getEntityDefinition(aGuid);
Object object = a.get("oneB");
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java b/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java
index e93f08d..e885b8c 100644
--- a/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java
@@ -1304,8 +1304,8 @@ public class DefaultMetadataServiceTest {
}
private String createBasicEntity(final HierarchicalTypeDefinition<ClassType> refType) throws AtlasException {
- String json = InstanceSerialization.toJson(new Referenceable(refType.typeName), false);
- CreateUpdateEntitiesResult entities = metadataService.createEntities("[" + json + "]");
+ String json = InstanceSerialization.toJson(new Referenceable(refType.typeName), false);
+ CreateUpdateEntitiesResult entities = metadataService.createEntities("[" + json + "]");
return entities.getCreatedEntities().get(0);
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/server-api/pom.xml
----------------------------------------------------------------------
diff --git a/server-api/pom.xml b/server-api/pom.xml
index 05e5eec..6e99ca3 100644
--- a/server-api/pom.xml
+++ b/server-api/pom.xml
@@ -53,7 +53,7 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
</dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/server-api/src/main/java/org/apache/atlas/services/MetadataService.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java b/server-api/src/main/java/org/apache/atlas/services/MetadataService.java
index 7fb3d3f..d2aa457 100644
--- a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java
+++ b/server-api/src/main/java/org/apache/atlas/services/MetadataService.java
@@ -24,11 +24,11 @@ import org.apache.atlas.EntityAuditEvent;
import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.typesystem.IReferenceableInstance;
+import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.ITypedStruct;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.Struct;
-import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.types.cache.TypeCache;
import org.codehaus.jettison.json.JSONObject;
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/typesystem/src/test/resources/atlas-application.properties
----------------------------------------------------------------------
diff --git a/typesystem/src/test/resources/atlas-application.properties b/typesystem/src/test/resources/atlas-application.properties
index 65dd9a3..d7537a5 100644
--- a/typesystem/src/test/resources/atlas-application.properties
+++ b/typesystem/src/test/resources/atlas-application.properties
@@ -35,7 +35,7 @@ atlas.TypeSystem.impl=org.apache.atlas.typesystem.types.TypeSystem
######### Atlas Server Configs #########
-atlas.rest.address=http://localhost:31000
+atlas.rest.address=http://localhost:21000
######### Graph Database Configs #########
@@ -82,8 +82,8 @@ atlas.lineage.schema.query.hive_table_v1=hive_table_v1 where __guid='%s'\, colum
######### Notification Configs #########
atlas.notification.embedded=true
-atlas.kafka.zookeeper.connect=localhost:19026
-atlas.kafka.bootstrap.servers=localhost:19027
+atlas.kafka.zookeeper.connect=localhost:9026
+atlas.kafka.bootstrap.servers=localhost:9027
atlas.kafka.data=${sys:atlas.data}/kafka
atlas.kafka.zookeeper.session.timeout.ms=4000
atlas.kafka.zookeeper.sync.time.ms=20
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/pom.xml
----------------------------------------------------------------------
diff --git a/webapp/pom.xml b/webapp/pom.xml
index 8d03af7..bfa79e8 100755
--- a/webapp/pom.xml
+++ b/webapp/pom.xml
@@ -134,7 +134,12 @@
<dependency>
<groupId>org.apache.atlas</groupId>
- <artifactId>atlas-client</artifactId>
+ <artifactId>atlas-client-v1</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-client-v2</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
index 858b320..5fd5087 100644
--- a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
+++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
@@ -21,6 +21,8 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import kafka.utils.ShutdownableThread;
import org.apache.atlas.ApplicationProperties;
+import org.apache.atlas.AtlasBaseClient;
+import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.RequestContext;
@@ -64,7 +66,9 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import static org.apache.atlas.AtlasClientV2.*;
+import static org.apache.atlas.AtlasClientV2.API_V2.DELETE_ENTITY_BY_ATTRIBUTE;
+import static org.apache.atlas.AtlasClientV2.API_V2.UPDATE_ENTITY;
+import static org.apache.atlas.AtlasClientV2.API_V2.UPDATE_ENTITY_BY_ATTRIBUTE;
/**
* Consumer of notifications from hooks e.g., hive hook etc.
@@ -350,7 +354,8 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
EntityCreateRequest createRequest = (EntityCreateRequest) message;
if (numRetries == 0) { // audit only on the first attempt
- audit(messageUser, CREATE_ENTITY.getMethod(), CREATE_ENTITY.getPath());
+ AtlasBaseClient.API api = AtlasClient.API_V1.CREATE_ENTITY;
+ audit(messageUser, api.getMethod(), api.getPath());
}
entities = instanceConverter.toAtlasEntities(createRequest.getEntities());
@@ -362,8 +367,9 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
final EntityPartialUpdateRequest partialUpdateRequest = (EntityPartialUpdateRequest) message;
if (numRetries == 0) { // audit only on the first attempt
- audit(messageUser, UPDATE_ENTITY_BY_ATTRIBUTE.getMethod(),
- String.format(UPDATE_ENTITY_BY_ATTRIBUTE.getPath(), partialUpdateRequest.getTypeName()));
+ AtlasBaseClient.API api = UPDATE_ENTITY_BY_ATTRIBUTE;
+ audit(messageUser, api.getMethod(),
+ String.format(api.getPath(), partialUpdateRequest.getTypeName()));
}
Referenceable referenceable = partialUpdateRequest.getEntity();
@@ -386,8 +392,9 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
final EntityDeleteRequest deleteRequest = (EntityDeleteRequest) message;
if (numRetries == 0) { // audit only on the first attempt
- audit(messageUser, DELETE_ENTITY_BY_ATTRIBUTE.getMethod(),
- String.format(DELETE_ENTITY_BY_ATTRIBUTE.getPath(), deleteRequest.getTypeName()));
+ AtlasBaseClient.API api = DELETE_ENTITY_BY_ATTRIBUTE;
+ audit(messageUser, api.getMethod(),
+ String.format(api.getPath(), deleteRequest.getTypeName()));
}
try {
@@ -405,7 +412,8 @@ public class NotificationHookConsumer implements Service, ActiveStateChangeHandl
EntityUpdateRequest updateRequest = (EntityUpdateRequest) message;
if (numRetries == 0) { // audit only on the first attempt
- audit(messageUser, UPDATE_ENTITY.getMethod(), UPDATE_ENTITY.getPath());
+ AtlasBaseClient.API api = UPDATE_ENTITY;
+ audit(messageUser, api.getMethod(), api.getPath());
}
entities = instanceConverter.toAtlasEntities(updateRequest.getEntities());
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
index 711cc04..67c9b27 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityResource.java
@@ -22,7 +22,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.sun.jersey.api.core.ResourceContext;
import org.apache.atlas.AtlasClient;
-import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.AtlasConstants;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
@@ -35,6 +34,7 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.GuidMapping;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.repository.converters.AtlasInstanceConverter;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream;
@@ -215,7 +215,7 @@ public class EntityResource {
UriBuilder ub = uriInfo.getAbsolutePathBuilder();
locationURI = CollectionUtils.isEmpty(guids) ? null : ub.path(guids.get(0)).build();
} else {
- String uriPath = AtlasClient.API.GET_ENTITY.getPath();
+ String uriPath = AtlasClient.API_V1.GET_ENTITY.getPath();
locationURI = guids.isEmpty() ? null : UriBuilder
.fromPath(AtlasConstants.DEFAULT_ATLAS_REST_ADDRESS)
.path(uriPath).path(guids.get(0)).build();
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
index cfe09d6..7d045f3 100755
--- a/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.java
@@ -37,7 +37,7 @@ public class AdminJerseyResourceIT extends BaseResourceIT {
@Test
public void testGetVersion() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.VERSION, null, (String[]) null);
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.VERSION, null, (String[]) null);
Assert.assertNotNull(response);
PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
http://git-wip-us.apache.org/repos/asf/atlas/blob/187730dd/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
index 8c6ba77..1a65dab 100644
--- a/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
@@ -59,7 +59,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testInputsGraph() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph");
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph");
Assert.assertNotNull(response);
System.out.println("inputs graph = " + response);
@@ -95,7 +95,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testOutputsGraph() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph");
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph");
Assert.assertNotNull(response);
System.out.println("outputs graph= " + response);
@@ -131,7 +131,7 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test
public void testSchema() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema");
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema");
Assert.assertNotNull(response);
System.out.println("schema = " + response);
@@ -173,12 +173,12 @@ public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
@Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForInvalidTable() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, "blah", "schema");
}
@Test(expectedExceptions = AtlasServiceException.class)
public void testSchemaForDB() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.NAME_LINEAGE_SCHEMA, null, salesDBName, "schema");
}
private void setupInstances() throws Exception {