You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ap...@apache.org on 2017/05/23 22:06:59 UTC
[01/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Repository: incubator-atlas
Updated Branches:
refs/heads/master 35c776448 -> 35e5828fb
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java b/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java
index d1b0318..dd2df70 100644
--- a/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/service/ActiveInstanceElectorServiceTest.java
@@ -18,9 +18,9 @@
package org.apache.atlas.web.service;
-import com.google.inject.Provider;
import org.apache.atlas.AtlasConstants;
import org.apache.atlas.AtlasException;
+import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.ha.HAConfiguration;
import org.apache.atlas.listener.ActiveStateChangeHandler;
import org.apache.commons.configuration.Configuration;
@@ -32,15 +32,10 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import org.apache.atlas.exception.AtlasBaseException;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.mockito.Mockito.*;
public class ActiveInstanceElectorServiceTest {
@@ -75,7 +70,7 @@ public class ActiveInstanceElectorServiceTest {
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.start();
@@ -96,7 +91,7 @@ public class ActiveInstanceElectorServiceTest {
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.start();
@@ -108,7 +103,7 @@ public class ActiveInstanceElectorServiceTest {
when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY, false)).thenReturn(false);
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.start();
@@ -129,7 +124,7 @@ public class ActiveInstanceElectorServiceTest {
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.start();
activeInstanceElectorService.stop();
@@ -151,7 +146,7 @@ public class ActiveInstanceElectorServiceTest {
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.start();
activeInstanceElectorService.stop();
@@ -165,7 +160,7 @@ public class ActiveInstanceElectorServiceTest {
when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY, false)).thenReturn(false);
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.stop();
@@ -185,23 +180,12 @@ public class ActiveInstanceElectorServiceTest {
LeaderLatch leaderLatch = mock(LeaderLatch.class);
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
- Collection<Provider<ActiveStateChangeHandler>> changeHandlers = new ArrayList();
+ Set<ActiveStateChangeHandler> changeHandlers = new HashSet<>();
final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class);
final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class);
- changeHandlers.add(new Provider<ActiveStateChangeHandler>() {
- @Override
- public ActiveStateChangeHandler get() {
- return handler1;
- }
- });
-
- changeHandlers.add(new Provider<ActiveStateChangeHandler>() {
- @Override
- public ActiveStateChangeHandler get() {
- return handler2;
- }
- });
+ changeHandlers.add(handler1);
+ changeHandlers.add(handler2);
ActiveInstanceElectorService activeInstanceElectorService =
new ActiveInstanceElectorService(configuration, changeHandlers, curatorFactory,
@@ -227,7 +211,7 @@ public class ActiveInstanceElectorServiceTest {
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.start();
@@ -250,23 +234,12 @@ public class ActiveInstanceElectorServiceTest {
LeaderLatch leaderLatch = mock(LeaderLatch.class);
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
- Collection<Provider<ActiveStateChangeHandler>> changeHandlers = new ArrayList();
+ Set<ActiveStateChangeHandler> changeHandlers = new HashSet<>();
final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class);
final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class);
- changeHandlers.add(new Provider<ActiveStateChangeHandler>() {
- @Override
- public ActiveStateChangeHandler get() {
- return handler1;
- }
- });
-
- changeHandlers.add(new Provider<ActiveStateChangeHandler>() {
- @Override
- public ActiveStateChangeHandler get() {
- return handler2;
- }
- });
+ changeHandlers.add(handler1);
+ changeHandlers.add(handler2);
doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1");
@@ -297,7 +270,7 @@ public class ActiveInstanceElectorServiceTest {
doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1");
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(), curatorFactory,
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory,
activeInstanceState, serviceState);
activeInstanceElectorService.start();
@@ -324,23 +297,12 @@ public class ActiveInstanceElectorServiceTest {
LeaderLatch leaderLatch = mock(LeaderLatch.class);
when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
- Collection<Provider<ActiveStateChangeHandler>> changeHandlers = new ArrayList();
+ Set<ActiveStateChangeHandler> changeHandlers = new HashSet<>();
final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class);
final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class);
- changeHandlers.add(new Provider<ActiveStateChangeHandler>() {
- @Override
- public ActiveStateChangeHandler get() {
- return handler1;
- }
- });
-
- changeHandlers.add(new Provider<ActiveStateChangeHandler>() {
- @Override
- public ActiveStateChangeHandler get() {
- return handler2;
- }
- });
+ changeHandlers.add(handler1);
+ changeHandlers.add(handler2);
ActiveInstanceElectorService activeInstanceElectorService =
new ActiveInstanceElectorService(configuration, changeHandlers, curatorFactory,
@@ -355,7 +317,7 @@ public class ActiveInstanceElectorServiceTest {
@Test
public void testActiveStateSetOnBecomingLeader() {
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(),
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(),
curatorFactory, activeInstanceState, serviceState);
activeInstanceElectorService.isLeader();
@@ -368,7 +330,7 @@ public class ActiveInstanceElectorServiceTest {
@Test
public void testPassiveStateSetOnLoosingLeadership() {
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(),
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(),
curatorFactory, activeInstanceState, serviceState);
activeInstanceElectorService.notLeader();
@@ -395,7 +357,7 @@ public class ActiveInstanceElectorServiceTest {
doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1");
ActiveInstanceElectorService activeInstanceElectorService =
- new ActiveInstanceElectorService(configuration, new ArrayList(),
+ new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(),
curatorFactory, activeInstanceState, serviceState);
activeInstanceElectorService.start();
activeInstanceElectorService.isLeader();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java
index 5d4ca97..41c3cb1 100755
--- a/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java
+++ b/webapp/src/test/java/org/apache/atlas/web/service/SecureEmbeddedServerTestBase.java
@@ -23,10 +23,10 @@ import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.Atlas;
import org.apache.atlas.AtlasException;
import org.apache.atlas.web.TestUtils;
-import org.apache.atlas.web.resources.AdminJerseyResourceIT;
-import org.apache.atlas.web.resources.EntityJerseyResourceIT;
-import org.apache.atlas.web.resources.MetadataDiscoveryJerseyResourceIT;
-import org.apache.atlas.web.resources.TypesJerseyResourceIT;
+import org.apache.atlas.web.integration.AdminJerseyResourceIT;
+import org.apache.atlas.web.integration.EntityJerseyResourceIT;
+import org.apache.atlas.web.integration.MetadataDiscoveryJerseyResourceIT;
+import org.apache.atlas.web.integration.TypesJerseyResourceIT;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java b/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java
index 82abc1b..7365fae 100644
--- a/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/setup/SetupStepsTest.java
@@ -47,12 +47,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
import static org.testng.AssertJUnit.assertTrue;
public class SetupStepsTest {
@@ -94,8 +89,8 @@ public class SetupStepsTest {
InterProcessMutex lock = mock(InterProcessMutex.class);
when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
thenReturn(lock);
- SetupSteps setupSteps = new SetupSteps(steps, curatorFactory);
- setupSteps.runSetup(configuration);
+ SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
+ setupSteps.runSetup();
verify(setupStep1).run();
verify(setupStep2).run();
@@ -147,8 +142,8 @@ public class SetupStepsTest {
thenReturn(lock);
InOrder inOrder = inOrder(lock, setupStep1, setupStep2);
- SetupSteps setupSteps = new SetupSteps(steps, curatorFactory);
- setupSteps.runSetup(configuration);
+ SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
+ setupSteps.runSetup();
inOrder.verify(lock).acquire();
inOrder.verify(setupStep1).run();
@@ -175,9 +170,9 @@ public class SetupStepsTest {
thenReturn(lock);
InOrder inOrder = inOrder(lock, setupStep1);
- SetupSteps setupSteps = new SetupSteps(steps, curatorFactory);
+ SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
try {
- setupSteps.runSetup(configuration);
+ setupSteps.runSetup();
} catch (Exception e) {
assertTrue(e instanceof SetupException);
}
@@ -205,8 +200,8 @@ public class SetupStepsTest {
InterProcessMutex lock = mock(InterProcessMutex.class);
when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
thenReturn(lock);
- SetupSteps setupSteps = new SetupSteps(steps, curatorFactory);
- setupSteps.runSetup(configuration);
+ SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
+ setupSteps.runSetup();
verify(createBuilder).withACL(aclList);
verify(createBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT+SetupSteps.SETUP_IN_PROGRESS_NODE,
@@ -231,8 +226,8 @@ public class SetupStepsTest {
InterProcessMutex lock = mock(InterProcessMutex.class);
when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
thenReturn(lock);
- SetupSteps setupSteps = new SetupSteps(steps, curatorFactory);
- setupSteps.runSetup(configuration);
+ SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
+ setupSteps.runSetup();
verify(deleteBuilder).forPath(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT+SetupSteps.SETUP_IN_PROGRESS_NODE);
}
@@ -252,10 +247,10 @@ public class SetupStepsTest {
InterProcessMutex lock = mock(InterProcessMutex.class);
when(curatorFactory.lockInstance(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).
thenReturn(lock);
- SetupSteps setupSteps = new SetupSteps(steps, curatorFactory);
+ SetupSteps setupSteps = new SetupSteps(steps, curatorFactory, configuration);
try {
- setupSteps.runSetup(configuration);
+ setupSteps.runSetup();
} catch (Exception e) {
assertTrue(e instanceof SetupException);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/resources/test-spring-security.xml
----------------------------------------------------------------------
diff --git a/webapp/src/test/resources/test-spring-security.xml b/webapp/src/test/resources/test-spring-security.xml
new file mode 100644
index 0000000..0ef15d7
--- /dev/null
+++ b/webapp/src/test/resources/test-spring-security.xml
@@ -0,0 +1,116 @@
+<?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. -->
+
+<beans:beans xmlns="http://www.springframework.org/schema/security"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns:security="http://www.springframework.org/schema/security"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <security:http pattern="/login.jsp" security="none" />
+ <security:http pattern="/css/**" security="none" />
+ <security:http pattern="/img/**" security="none" />
+ <security:http pattern="/libs/**" security="none" />
+ <security:http pattern="/js/**" security="none" />
+ <security:http pattern="/ieerror.html" security="none" />
+ <security:http pattern="/api/atlas/admin/status" security="none" />
+ <security:http pattern="/api/atlas/admin/metrics" security="none" />
+
+ <security:http create-session="always"
+ entry-point-ref="entryPoint">
+ <security:session-management
+ session-fixation-protection="newSession" />
+ <intercept-url pattern="/**" access="isAuthenticated()" />
+ <custom-filter ref="ssoAuthenticationFilter" after="BASIC_AUTH_FILTER" />
+
+ <security:custom-filter ref="krbAuthenticationFilter" after="SERVLET_API_SUPPORT_FILTER" />
+ <security:custom-filter ref="csrfPreventionFilter" after="REMEMBER_ME_FILTER" />
+
+ <form-login
+ login-page="/login.jsp"
+ login-processing-url="/j_spring_security_check"
+ authentication-success-handler-ref="atlasAuthenticationSuccessHandler"
+ authentication-failure-handler-ref="atlasAuthenticationFailureHandler"
+ username-parameter="j_username"
+ password-parameter="j_password" />
+
+ <security:logout logout-success-url="/login.jsp" delete-cookies="ATLASSESSIONID"
+ logout-url="/logout.html" />
+ <http-basic />
+ <headers disabled="true"/>
+ <csrf disabled="true"/>
+ <security:custom-filter position="LAST" ref="atlasAuthorizationFilter"/>
+ </security:http>
+
+ <beans:bean id="userDAO" class="org.apache.atlas.web.dao.UserDao" init-method="init"/>
+ <beans:bean id="userDetailsService" class="org.apache.atlas.web.service.UserService">
+ <beans:constructor-arg ref="userDAO"/>
+ </beans:bean>
+ <beans:bean id="atlasLDAPProvider" class="org.apache.atlas.web.security.AtlasLdapAuthenticationProvider"/>
+ <beans:bean id="atlasFileProvider" class="org.apache.atlas.web.security.AtlasFileAuthenticationProvider">
+ <beans:constructor-arg ref="userDetailsService"/>
+ </beans:bean>
+ <beans:bean id="atlasADProvider" class="org.apache.atlas.web.security.AtlasADAuthenticationProvider"/>
+ <beans:bean id="atlasAuthenticationProvider" class="org.apache.atlas.web.security.AtlasAuthenticationProvider">
+ <beans:constructor-arg index="0" ref="atlasLDAPProvider"/>
+ <beans:constructor-arg index="1" ref="atlasFileProvider"/>
+ <beans:constructor-arg index="2" ref="atlasADProvider"/>
+ </beans:bean>
+
+ <beans:bean id="krbAuthenticationFilter" class="org.apache.atlas.web.filters.AtlasAuthenticationFilter">
+ </beans:bean>
+
+ <beans:bean id="ssoAuthenticationFilter" class="org.apache.atlas.web.filters.AtlasKnoxSSOAuthenticationFilter">
+ <beans:constructor-arg name="authenticationProvider" ref="atlasAuthenticationProvider"/>
+ </beans:bean>
+
+ <beans:bean id="csrfPreventionFilter" class="org.apache.atlas.web.filters.AtlasCSRFPreventionFilter">
+ </beans:bean>
+
+ <beans:bean id="atlasAuthenticationSuccessHandler"
+ class="org.apache.atlas.web.security.AtlasAuthenticationSuccessHandler" />
+
+ <beans:bean id="atlasAuthenticationFailureHandler"
+ class="org.apache.atlas.web.security.AtlasAuthenticationFailureHandler" />
+
+ <beans:bean id="formAuthenticationEntryPoint"
+ class="org.apache.atlas.web.filters.AtlasAuthenticationEntryPoint">
+ <beans:constructor-arg value="/login.jsp"/>
+ </beans:bean>
+
+ <beans:bean id="authenticationEntryPoint"
+ class="org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint">
+ <beans:property name="realmName" value="atlas.com" />
+ </beans:bean>
+
+ <beans:bean id="entryPoint" class="org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint">
+ <beans:constructor-arg>
+ <beans:map>
+ <beans:entry key="hasHeader('User-Agent','Mozilla')" value-ref="formAuthenticationEntryPoint" />
+ </beans:map>
+ </beans:constructor-arg>
+ <beans:property name="defaultEntryPoint" ref="authenticationEntryPoint"/>
+ </beans:bean>
+
+
+ <security:authentication-manager
+ alias="authenticationManager">
+ <security:authentication-provider
+ ref="atlasAuthenticationProvider" />
+ </security:authentication-manager>
+
+ <security:global-method-security pre-post-annotations="enabled" />
+
+ <beans:bean id = "atlasAuthorizationFilter" class="org.apache.atlas.web.filters.AtlasAuthorizationFilter"/>
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/webapp/src/test/webapp/WEB-INF/web.xml b/webapp/src/test/webapp/WEB-INF/web.xml
index 011bf37..2388fbf 100755
--- a/webapp/src/test/webapp/WEB-INF/web.xml
+++ b/webapp/src/test/webapp/WEB-INF/web.xml
@@ -24,51 +24,52 @@
<display-name>Apache Atlas</display-name>
<description>Metadata Management and Data Governance Platform over Hadoop</description>
- <context-param>
- <param-name>guice.packages</param-name>
- <param-value>
- org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest,org.apache.atlas.web.errors
- </param-value>
- </context-param>
-
- <context-param>
- <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
- <param-value>true</param-value>
- </context-param>
-
<!--
More information can be found here:
https://jersey.java.net/nonav/apidocs/1.11/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
-->
+ <servlet>
+ <servlet-name>jersey-servlet</servlet-name>
+ <servlet-class>
+ com.sun.jersey.spi.spring.container.servlet.SpringServlet
+ </servlet-class>
+ <init-param>
+ <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>jersey-servlet</servlet-name>
+ <url-pattern>/api/atlas/*</url-pattern>
+ </servlet-mapping>
+
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
-
- <filter>
- <filter-name>guiceFilter</filter-name>
- <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
- </filter>
-
+
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
+ <filter>
+ <filter-name>AuditFilter</filter-name>
+ <filter-class>org.apache.atlas.web.filters.AuditFilter</filter-class>
+ </filter>
+
<filter-mapping>
- <filter-name>guiceFilter</filter-name>
+ <filter-name>AuditFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
-
- <listener>
- <listener-class>org.apache.atlas.web.listeners.TestGuiceServletConfig</listener-class>
- </listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
@@ -88,5 +89,5 @@
</cookie-config>
</session-config>
-
+
</web-app>
[08/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationEntryPoint.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationEntryPoint.java b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationEntryPoint.java
index 382b494..7767602 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationEntryPoint.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationEntryPoint.java
@@ -16,23 +16,32 @@
*/
package org.apache.atlas.web.filters;
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
@SuppressWarnings("deprecation")
-class AtlasAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
+@Component
+public class AtlasAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthenticationEntryPoint.class);
private String loginPath = "/login.jsp";
+ @Inject
+ public AtlasAuthenticationEntryPoint(@Value("/login.jsp") String loginFormUrl) {
+ super(loginFormUrl);
+ }
+
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java
index 473c78d..25aede3 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthenticationFilter.java
@@ -51,6 +51,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
+import org.springframework.stereotype.Component;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -78,6 +79,7 @@ import java.util.regex.Pattern;
* todo: Subclass of {@link org.apache.hadoop.security.authentication.server.AuthenticationFilter}.
*/
+@Component
public class AtlasAuthenticationFilter extends AuthenticationFilter {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthenticationFilter.class);
static final String PREFIX = "atlas.authentication.method";
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthorizationFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthorizationFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthorizationFilter.java
index a1a168a..862e34f 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthorizationFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasAuthorizationFilter.java
@@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;
import javax.servlet.FilterChain;
@@ -44,6 +45,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+@Component
public class AtlasAuthorizationFilter extends GenericFilterBean {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorizationFilter.class);
@@ -95,7 +97,7 @@ public class AtlasAuthorizationFilter extends GenericFilterBean {
responseWrapper.setHeader("X-Frame-Options", "DENY");
String pathInfo = request.getServletPath();
- if (!Strings.isNullOrEmpty(pathInfo) && pathInfo.startsWith(BASE_URL)) {
+ if (!Strings.isNullOrEmpty(pathInfo) && (pathInfo.startsWith(BASE_URL) || BASE_URL.startsWith(pathInfo))) {
if (isDebugEnabled) {
LOG.debug("{} is a valid REST API request!!!", pathInfo);
}
@@ -113,10 +115,11 @@ public class AtlasAuthorizationFilter extends GenericFilterBean {
}
} else {
if (LOG.isErrorEnabled()) {
- LOG.error("Cannot obtain Security Context : {}", auth);
+ LOG.error("Cannot obtain Security Context");
}
- throw new ServletException("Cannot obtain Security Context : " + auth);
+ throw new ServletException("Cannot obtain Security Context");
}
+
AtlasAccessRequest atlasRequest = new AtlasAccessRequest(request, userName, groups);
if (isDebugEnabled) {
LOG.debug("============================\nUserName :: {}\nGroups :: {}\nURL :: {}\nAction :: {}\nrequest.getServletPath() :: {}\n============================\n", atlasRequest.getUser(), atlasRequest.getUserGroups(), request.getRequestURL(), atlasRequest.getAction(), pathInfo);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/AtlasCSRFPreventionFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasCSRFPreventionFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasCSRFPreventionFilter.java
index 5294c9b..277ac22 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasCSRFPreventionFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasCSRFPreventionFilter.java
@@ -18,12 +18,13 @@
package org.apache.atlas.web.filters;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import org.apache.atlas.ApplicationProperties;
+import org.apache.atlas.AtlasException;
+import org.apache.commons.configuration.Configuration;
+import org.json.simple.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -33,15 +34,14 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasException;
-import org.apache.commons.configuration.Configuration;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.json.simple.JSONObject;
-
+@Component
public class AtlasCSRFPreventionFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(AtlasCSRFPreventionFilter.class);
private static Configuration configuration;
@@ -238,13 +238,11 @@ public class AtlasCSRFPreventionFilter implements Filter {
@Override
public void sendError(int code, String message) throws IOException {
JSONObject json = new JSONObject();
- ObjectMapper mapper = new ObjectMapper();
json.put("msgDesc", message);
- String jsonAsStr = mapper.writeValueAsString(json);
httpResponse.setContentType("application/json");
httpResponse.setStatus(code);
httpResponse.setCharacterEncoding("UTF-8");
- httpResponse.getWriter().write(jsonAsStr);
+ httpResponse.getWriter().write(json.toJSONString());
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java
index d5fa003..665fa34 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/AtlasKnoxSSOAuthenticationFilter.java
@@ -20,7 +20,6 @@
package org.apache.atlas.web.filters;
-import com.google.inject.Inject;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jose.JWSVerifier;
@@ -42,6 +41,9 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
import javax.servlet.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@@ -61,6 +63,7 @@ import java.util.List;
import org.apache.commons.lang.StringUtils;
+@Component("ssoAuthenticationFilter")
public class AtlasKnoxSSOAuthenticationFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(AtlasKnoxSSOAuthenticationFilter.class);
@@ -73,6 +76,8 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
public static final String JWT_ORIGINAL_URL_QUERY_PARAM_DEFAULT = "originalUrl";
public static final String DEFAULT_BROWSER_USERAGENT = "Mozilla,Opera,Chrome";
+ private final AtlasAuthenticationProvider authenticationProvider;
+
private SSOAuthenticationProperties jwtProperties;
private String originalUrlQueryParam = "originalUrl";
@@ -84,7 +89,8 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
private JWSVerifier verifier = null;
@Inject
- public AtlasKnoxSSOAuthenticationFilter() {
+ public AtlasKnoxSSOAuthenticationFilter(AtlasAuthenticationProvider authenticationProvider) {
+ this.authenticationProvider = authenticationProvider;
try {
configuration = ApplicationProperties.get();
} catch (Exception e) {
@@ -97,8 +103,9 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
setJwtProperties();
}
- public AtlasKnoxSSOAuthenticationFilter(
- SSOAuthenticationProperties jwtProperties) {
+ public AtlasKnoxSSOAuthenticationFilter(AtlasAuthenticationProvider authenticationProvider,
+ SSOAuthenticationProperties jwtProperties) {
+ this.authenticationProvider = authenticationProvider;
this.jwtProperties = jwtProperties;
setJwtProperties();
}
@@ -166,7 +173,6 @@ public class AtlasKnoxSSOAuthenticationFilter implements Filter {
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, "", grantedAuths);
WebAuthenticationDetails webDetails = new WebAuthenticationDetails(httpRequest);
((AbstractAuthenticationToken) finalAuthentication).setDetails(webDetails);
- AtlasAuthenticationProvider authenticationProvider = new AtlasAuthenticationProvider();
authenticationProvider.setSsoEnabled(ssoEnabled);
Authentication authentication = authenticationProvider.authenticate(finalAuthentication);
SecurityContextHolder.getContext().setAuthentication(authentication);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java
index 525bbc0..191388a 100755
--- a/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/AuditFilter.java
@@ -18,19 +18,18 @@
package org.apache.atlas.web.filters;
-import com.google.inject.Singleton;
-
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.RequestContext;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.metrics.Metrics;
-import org.apache.commons.configuration.Configuration;
import org.apache.atlas.util.AtlasRepositoryConfiguration;
import org.apache.atlas.web.util.DateTimeHelper;
import org.apache.atlas.web.util.Servlets;
+import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -40,7 +39,6 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import java.io.IOException;
import java.util.Date;
import java.util.UUID;
@@ -49,7 +47,7 @@ import java.util.UUID;
* This records audit information as part of the filter after processing the request
* and also introduces a UUID into request and response for tracing requests in logs.
*/
-@Singleton
+@Component
public class AuditFilter implements Filter {
private static final Logger AUDIT_LOG = LoggerFactory.getLogger("AUDIT");
private static final Logger LOG = LoggerFactory.getLogger(AuditFilter.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/StaleTransactionCleanupFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/StaleTransactionCleanupFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/StaleTransactionCleanupFilter.java
index 5f62bc4..cdb9064 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/StaleTransactionCleanupFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/StaleTransactionCleanupFilter.java
@@ -18,7 +18,10 @@
package org.apache.atlas.web.filters;
-import java.io.IOException;
+import org.apache.atlas.repository.graph.AtlasGraphProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -26,12 +29,7 @@ import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.Singleton;
+import java.io.IOException;
/**
* Filter that rolls back the stale transaction associated with
@@ -39,7 +37,7 @@ import com.google.inject.Singleton;
* see all of the committed changes.
*
*/
-@Singleton
+@Component
public class StaleTransactionCleanupFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(StaleTransactionCleanupFilter.class);
@@ -52,6 +50,7 @@ public class StaleTransactionCleanupFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException, ServletException {
+ LOG.info("Cleaning stale transactions");
AtlasGraphProvider.getGraphInstance().rollback();
filterChain.doFilter(request, response);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/listeners/GuiceServletConfig.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/listeners/GuiceServletConfig.java b/webapp/src/main/java/org/apache/atlas/web/listeners/GuiceServletConfig.java
deleted file mode 100755
index 95647e0..0000000
--- a/webapp/src/main/java/org/apache/atlas/web/listeners/GuiceServletConfig.java
+++ /dev/null
@@ -1,190 +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.web.listeners;
-
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.ServletContextEvent;
-
-import org.apache.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.RepositoryMetadataModule;
-import org.apache.atlas.ha.HAConfiguration;
-import org.apache.atlas.notification.NotificationModule;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
-import org.apache.atlas.repository.graphdb.AtlasGraph;
-import org.apache.atlas.service.Services;
-import org.apache.atlas.web.filters.ActiveServerFilter;
-import org.apache.atlas.web.filters.AuditFilter;
-import org.apache.atlas.web.filters.StaleTransactionCleanupFilter;
-import org.apache.atlas.web.service.ActiveInstanceElectorModule;
-import org.apache.atlas.web.service.ServiceModule;
-import org.apache.commons.configuration.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.bridge.SLF4JBridgeHandler;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Module;
-import com.google.inject.Stage;
-import com.google.inject.servlet.GuiceServletContextListener;
-import com.sun.jersey.api.core.PackagesResourceConfig;
-import com.sun.jersey.guice.JerseyServletModule;
-import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
-
-public class GuiceServletConfig extends GuiceServletContextListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(GuiceServletConfig.class);
-
- private static final String GUICE_CTX_PARAM = "guice.packages";
- protected volatile Injector injector;
-
- @Override
- protected Injector getInjector() {
- LOG.info("Loading Guice modules");
- /*
- * More information on this can be found here:
- * https://jersey.java.net/nonav/apidocs/1
- * .11/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary
- * .html
- */
- if (injector == null) {
-
- // perform login operations
- LoginProcessor loginProcessor = new LoginProcessor();
- loginProcessor.login();
-
- injector = Guice.createInjector(Stage.PRODUCTION, getRepositoryModule(), new ActiveInstanceElectorModule(),
- new NotificationModule(), new ServiceModule(), new JerseyServletModule() {
-
- private Configuration appConfiguration = null;
-
- private Configuration getConfiguration() {
- if (appConfiguration == null) {
- try {
- appConfiguration = ApplicationProperties.get();
- } catch (AtlasException e) {
- LOG.warn("Could not load application configuration", e);
- }
- }
- return appConfiguration;
- }
-
- @Override
- protected void configureServlets() {
- filter("/*").through(StaleTransactionCleanupFilter.class);
- filter("/*").through(AuditFilter.class);
- configureActiveServerFilterIfNecessary();
-
- Map<String, String> initParams = new HashMap<>();
- Enumeration<String> initParamNames = getServletContext().getInitParameterNames();
-
- while (initParamNames.hasMoreElements()) {
- String initParamName = initParamNames.nextElement();
- String initParamValue = getServletContext().getInitParameter(initParamName);
-
- if (GUICE_CTX_PARAM.equals(initParamName)) {
- LOG.info("Jersey loading from packages: {}", initParamValue);
-
- initParams.put(PackagesResourceConfig.PROPERTY_PACKAGES, initParamValue);
- } else {
- initParams.put(initParamName, initParamValue);
- }
- }
-
- serve("/" + AtlasClient.BASE_URI + "*").with(GuiceContainer.class, initParams);
- }
-
- private void configureActiveServerFilterIfNecessary() {
- Configuration configuration = getConfiguration();
- if ((configuration == null) ||
- !HAConfiguration.isHAEnabled(configuration)) {
- LOG.info("HA configuration is disabled, not activating ActiveServerFilter");
- } else {
- filter("/*").through(ActiveServerFilter.class);
- }
- }
-
- });
-
- LOG.info("Guice modules loaded");
- }
-
- return injector;
- }
-
- protected Module getRepositoryModule() {
- return new RepositoryMetadataModule();
- }
-
- @Override
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- super.contextInitialized(servletContextEvent);
-
- installLogBridge();
-
- startServices();
- }
-
- protected void startServices() {
- LOG.info("Starting services");
- Services services = injector.getInstance(Services.class);
- services.start();
- }
-
- /**
- * Maps jersey's java.util.logging to slf4j
- */
- private void installLogBridge() {
- // Optionally remove existing handlers attached to j.u.l root logger
- SLF4JBridgeHandler.removeHandlersForRootLogger(); // (since SLF4J 1.6.5)
-
- // add SLF4JBridgeHandler to j.u.l's root logger, should be done once during
- // the initialization phase of your application
- SLF4JBridgeHandler.install();
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- LOG.info("Starting servlet context destroy");
- if(injector != null) {
- //stop services
- stopServices();
-
- final AtlasGraph graph = AtlasGraphProvider.getGraphInstance();
-
- try {
- graph.shutdown();
- } catch(Throwable t) {
- LOG.warn("Error while shutting down graph", t);
- }
- }
- super.contextDestroyed(servletContextEvent);
- }
-
- protected void stopServices() {
- LOG.info("Stopping services");
- Services services = injector.getInstance(Services.class);
- services.stop();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/listeners/LoginProcessor.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/listeners/LoginProcessor.java b/webapp/src/main/java/org/apache/atlas/web/listeners/LoginProcessor.java
index cc2ef8a..e21656e 100644
--- a/webapp/src/main/java/org/apache/atlas/web/listeners/LoginProcessor.java
+++ b/webapp/src/main/java/org/apache/atlas/web/listeners/LoginProcessor.java
@@ -26,7 +26,9 @@ import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.Shell;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.annotation.PostConstruct;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -34,6 +36,7 @@ import java.net.UnknownHostException;
/**
* A class capable of performing a simple or kerberos login.
*/
+@Component
public class LoginProcessor {
private static final Logger LOG = LoggerFactory.getLogger(LoginProcessor.class);
@@ -46,6 +49,7 @@ public class LoginProcessor {
* Perform a SIMPLE login based on established OS identity or a kerberos based login using the configured
* principal and keytab (via atlas-application.properties).
*/
+ @PostConstruct
public void login() {
// first, let's see if we're running in a hadoop cluster and have the env configured
boolean isHadoopCluster = isHadoopCluster();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
index 9fe1624..01f9a86 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/AdminResource.java
@@ -18,7 +18,6 @@
package org.apache.atlas.web.resources;
-import com.google.inject.Inject;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
@@ -50,10 +49,13 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Service;
+import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -80,6 +82,7 @@ import java.util.concurrent.locks.ReentrantLock;
*/
@Path("admin")
@Singleton
+@Service
public class AdminResource {
private static final Logger LOG = LoggerFactory.getLogger(AdminResource.class);
@@ -108,6 +111,10 @@ public class AdminResource {
private final AtlasTypeDefStore typesDefStore;
private final AtlasEntityStore entityStore;
private static Configuration atlasProperties;
+ private final ExportService exportService;
+
+ @Inject
+ ApplicationContext applicationContext;
static {
try {
@@ -120,12 +127,13 @@ public class AdminResource {
@Inject
public AdminResource(ServiceState serviceState, MetricsService metricsService,
AtlasTypeRegistry typeRegistry, AtlasTypeDefStore typeDefStore,
- AtlasEntityStore entityStore) {
+ AtlasEntityStore entityStore, ExportService exportService) {
this.serviceState = serviceState;
this.metricsService = metricsService;
this.typeRegistry = typeRegistry;
this.typesDefStore = typeDefStore;
this.entityStore = entityStore;
+ this.exportService = exportService;
this.importExportOperationLock = new ReentrantLock();
}
@@ -320,8 +328,6 @@ public class AdminResource {
ZipSink exportSink = null;
try {
exportSink = new ZipSink(httpServletResponse.getOutputStream());
- ExportService exportService = new ExportService(this.typeRegistry);
-
AtlasExportResult result = exportService.run(exportSink, request, Servlets.getUserName(httpServletRequest),
Servlets.getHostName(httpServletRequest),
AtlasAuthorizationUtils.getRequestIpAddress(httpServletRequest));
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java
index 2fe6898..435659e 100644
--- a/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/DataSetLineageResource.java
@@ -27,16 +27,12 @@ import org.apache.atlas.web.util.Servlets;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
@@ -45,6 +41,7 @@ import javax.ws.rs.core.Response;
*/
@Path("lineage/hive")
@Singleton
+@Service
@Deprecated
public class DataSetLineageResource {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 19c5594..711cc04 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,17 +22,17 @@ 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;
import org.apache.atlas.CreateUpdateEntitiesResult;
import org.apache.atlas.EntityAuditEvent;
-import org.apache.atlas.AtlasClient.EntityResult;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
-import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
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.repository.converters.AtlasInstanceConverter;
@@ -40,8 +40,8 @@ import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream;
import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1;
import org.apache.atlas.services.MetadataService;
-import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasEntityType;
+import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
@@ -62,6 +62,7 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -86,8 +87,9 @@ import java.util.Map;
* An entity is an "instance" of a Type. Entities conform to the definition
* of the Type they correspond with.
*/
-@Path("entities")
@Singleton
+@Path("entities")
+@Service
@Deprecated
public class EntityResource {
@@ -100,6 +102,7 @@ public class EntityResource {
private final AtlasInstanceConverter restAdapters;
private final AtlasEntityStore entitiesStore;
private final AtlasTypeRegistry typeRegistry;
+ private final EntityREST entityREST;
@Context
UriInfo uriInfo;
@@ -114,11 +117,13 @@ public class EntityResource {
* @param metadataService metadata service handle
*/
@Inject
- public EntityResource(MetadataService metadataService, AtlasInstanceConverter restAdapters, AtlasEntityStore entitiesStore, AtlasTypeRegistry typeRegistry) {
+ public EntityResource(MetadataService metadataService, AtlasInstanceConverter restAdapters,
+ AtlasEntityStore entitiesStore, AtlasTypeRegistry typeRegistry, EntityREST entityREST) {
this.metadataService = metadataService;
this.restAdapters = restAdapters;
this.entitiesStore = entitiesStore;
this.typeRegistry = typeRegistry;
+ this.entityREST = entityREST;
}
/**
@@ -159,7 +164,6 @@ public class EntityResource {
LOG.debug("submitting entities {} ", entityJson);
}
- EntityREST entityREST = resourceContext.getResource(EntityREST.class);
AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(entities);
EntityMutationResponse mutationResponse = entityREST.createOrUpdate(entitiesInfo);
@@ -220,7 +224,7 @@ public class EntityResource {
return locationURI;
}
- private JSONObject getResponse(AtlasClient.EntityResult entityResult) throws AtlasException, JSONException {
+ private JSONObject getResponse(EntityResult entityResult) throws AtlasException, JSONException {
CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
result.setEntityResult(entityResult);
return getResponse(result);
@@ -273,7 +277,6 @@ public class EntityResource {
LOG.info("updating entities {} ", entityJson);
}
- EntityREST entityREST = resourceContext.getResource(EntityREST.class);
AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(entities);
EntityMutationResponse mutationResponse = entityREST.createOrUpdate(entitiesInfo);
CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
@@ -311,7 +314,7 @@ public class EntityResource {
}
}
- private String getSample(AtlasClient.EntityResult entityResult) {
+ private String getSample(EntityResult entityResult) {
String sample = getSample(entityResult.getCreatedEntities());
if (sample == null) {
sample = getSample(entityResult.getUpdateEntities());
@@ -585,7 +588,6 @@ public class EntityResource {
}
EntityResult entityResult;
- EntityREST entityREST = resourceContext.getResource(EntityREST.class);
if (guids != null && !guids.isEmpty()) {
if (LOG.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java b/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
index 32c2cb8..77115d7 100644
--- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java
@@ -18,7 +18,6 @@
package org.apache.atlas.web.resources;
-import org.apache.atlas.AtlasException;
import org.apache.atlas.catalog.BaseRequest;
import org.apache.atlas.catalog.CollectionRequest;
import org.apache.atlas.catalog.DefaultTypeSystem;
@@ -33,6 +32,7 @@ import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets;
import org.slf4j.Logger;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -58,6 +58,7 @@ import java.util.Map;
*/
@Path("v1/entities")
@Singleton
+@Service
public class EntityService extends BaseService {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.EntityService");
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java
index 9f4a0bd..cba8ccf 100644
--- a/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/LineageResource.java
@@ -35,6 +35,7 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -48,6 +49,7 @@ import javax.ws.rs.core.Response;
@Path("lineage")
@Singleton
+@Service
@Deprecated
public class LineageResource {
private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageResource.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
index 32b4cae..d29c8da 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/MetadataDiscoveryResource.java
@@ -33,6 +33,7 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -52,6 +53,7 @@ import java.util.Map;
*/
@Path("discovery")
@Singleton
+@Service
@Deprecated
public class MetadataDiscoveryResource {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java b/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
index b13810f..05b197f 100644
--- a/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java
@@ -18,7 +18,6 @@
package org.apache.atlas.web.resources;
-import org.apache.atlas.AtlasException;
import org.apache.atlas.catalog.*;
import org.apache.atlas.catalog.exception.CatalogException;
import org.apache.atlas.catalog.exception.InvalidPayloadException;
@@ -28,9 +27,9 @@ import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets;
import org.slf4j.Logger;
+import org.springframework.stereotype.Component;
import javax.inject.Inject;
-import javax.inject.Singleton;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -52,7 +51,7 @@ import java.util.Map;
* Service which handles API requests for taxonomy and term resources.
*/
@Path("v1/taxonomies")
-@Singleton
+@Component
public class TaxonomyService extends BaseService {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.TaxonomyService");
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
index 424ca58..08121d8 100755
--- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
+++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java
@@ -35,6 +35,7 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -63,15 +64,18 @@ import java.util.List;
*/
@Path("types")
@Singleton
+@Service
@Deprecated
public class TypesResource {
private static final Logger LOG = LoggerFactory.getLogger(TypesResource.class);
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.TypesResource");
private static AtlasTypeRegistry typeRegistry;
+ private final TypesREST typesREST;
@Inject
- public TypesResource(AtlasTypeRegistry typeRegistry) {
+ public TypesResource(AtlasTypeRegistry typeRegistry, TypesREST typesREST) {
this.typeRegistry = typeRegistry;
+ this.typesREST = typesREST;
}
@Context
@@ -95,7 +99,6 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.submit()");
}
- TypesREST typesRest = resourceContext.getResource(TypesREST.class);
JSONArray typesResponse = new JSONArray();
try {
@@ -106,7 +109,7 @@ public class TypesResource {
}
AtlasTypesDef createTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
- AtlasTypesDef createdTypesDef = typesRest.createAtlasTypeDefs(createTypesDef);
+ AtlasTypesDef createdTypesDef = typesREST.createAtlasTypeDefs(createTypesDef);
List<String> typeNames = TypeConverterUtil.getTypeNames(createdTypesDef);
for (int i = 0; i < typeNames.size(); i++) {
@@ -164,7 +167,6 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.update()");
}
- TypesREST typesRest = resourceContext.getResource(TypesREST.class);
JSONArray typesResponse = new JSONArray();
try {
final String typeDefinition = Servlets.getRequestPayload(request);
@@ -174,7 +176,7 @@ public class TypesResource {
}
AtlasTypesDef updateTypesDef = TypeConverterUtil.toAtlasTypesDef(typeDefinition, typeRegistry);
- AtlasTypesDef updatedTypesDef = typesRest.updateAtlasTypeDefs(updateTypesDef);
+ AtlasTypesDef updatedTypesDef = typesREST.updateAtlasTypeDefs(updateTypesDef);
List<String> typeNames = TypeConverterUtil.getTypeNames(updatedTypesDef);
for (int i = 0; i < typeNames.size(); i++) {
@@ -287,10 +289,9 @@ public class TypesResource {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TypesResource.getTypesByFilter(" + typeCategory + ", " + supertype + ", " + notsupertype + ")");
}
- TypesREST typesRest = resourceContext.getResource(TypesREST.class);
JSONObject response = new JSONObject();
try {
- List<String> result = TypeConverterUtil.getTypeNames(typesRest.getTypeDefHeaders(request));
+ List<String> result = TypeConverterUtil.getTypeNames(typesREST.getTypeDefHeaders(request));
response.put(AtlasClient.RESULTS, new JSONArray(result));
response.put(AtlasClient.COUNT, result.size());
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
index edaf3ef..ea55021 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
@@ -23,6 +23,7 @@ import org.apache.atlas.discovery.AtlasDiscoveryService;
import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets;
+import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -39,6 +40,7 @@ import javax.ws.rs.QueryParam;
*/
@Path("v2/search")
@Singleton
+@Service
public class DiscoveryREST {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.DiscoveryREST");
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
index 88222db..0f6eeb1 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
@@ -26,11 +26,9 @@ import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.ClassificationAssociateRequest;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
-import org.apache.atlas.repository.converters.AtlasInstanceConverter;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream;
import org.apache.atlas.repository.store.graph.v1.EntityStream;
-import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasTypeRegistry;
@@ -40,6 +38,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -66,22 +65,18 @@ import java.util.Map;
*/
@Path("v2/entity")
@Singleton
+@Service
public class EntityREST {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.EntityREST");
public static final String PREFIX_ATTR = "attr:";
private final AtlasTypeRegistry typeRegistry;
- private final AtlasInstanceConverter instanceConverter;
- private final MetadataService metadataService;
private final AtlasEntityStore entitiesStore;
@Inject
- public EntityREST(AtlasTypeRegistry typeRegistry, AtlasInstanceConverter instanceConverter,
- MetadataService metadataService, AtlasEntityStore entitiesStore) {
+ public EntityREST(AtlasTypeRegistry typeRegistry, AtlasEntityStore entitiesStore) {
this.typeRegistry = typeRegistry;
- this.instanceConverter = instanceConverter;
- this.metadataService = metadataService;
this.entitiesStore = entitiesStore;
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/rest/LineageREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/LineageREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/LineageREST.java
index 2b19e73..8638ea6 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/LineageREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/LineageREST.java
@@ -26,6 +26,7 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets;
import org.slf4j.Logger;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -44,6 +45,7 @@ import javax.ws.rs.core.Context;
*/
@Path("v2/lineage")
@Singleton
+@Service
public class LineageREST {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.LineageREST");
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
index 5d846cf..c32f36e 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java
@@ -17,7 +17,6 @@
*/
package org.apache.atlas.web.rest;
-import com.google.inject.Inject;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
@@ -33,7 +32,9 @@ import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets;
import org.apache.http.annotation.Experimental;
import org.slf4j.Logger;
+import org.springframework.stereotype.Service;
+import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
@@ -53,6 +54,7 @@ import java.util.Set;
*/
@Path("v2/types")
@Singleton
+@Service
public class TypesREST {
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.TypesREST");
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/security/AtlasADAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasADAuthenticationProvider.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasADAuthenticationProvider.java
index d78990b..b123c52 100644
--- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasADAuthenticationProvider.java
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasADAuthenticationProvider.java
@@ -18,11 +18,6 @@
package org.apache.atlas.web.security;
-import java.util.List;
-import java.util.Properties;
-
-import javax.annotation.PostConstruct;
-
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.web.model.User;
import org.apache.commons.configuration.Configuration;
@@ -32,7 +27,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
@@ -42,9 +36,12 @@ import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAu
import org.springframework.security.ldap.search.FilterBasedLdapUserSearch;
import org.springframework.stereotype.Component;
+import javax.annotation.PostConstruct;
+import java.util.List;
+import java.util.Properties;
+
@Component
-public class AtlasADAuthenticationProvider extends
- AtlasAbstractAuthenticationProvider {
+public class AtlasADAuthenticationProvider extends AtlasAbstractAuthenticationProvider {
private static Logger LOG = LoggerFactory.getLogger(AtlasADAuthenticationProvider.class);
private String adURL;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/security/AtlasAbstractAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAbstractAuthenticationProvider.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAbstractAuthenticationProvider.java
index e55d2cf..f77cb01 100644
--- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAbstractAuthenticationProvider.java
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAbstractAuthenticationProvider.java
@@ -19,12 +19,9 @@
package org.apache.atlas.web.security;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.Groups;
import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hadoop.security.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.AuthenticationProvider;
@@ -35,14 +32,15 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
-public abstract class AtlasAbstractAuthenticationProvider implements
- AuthenticationProvider {
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AtlasAbstractAuthenticationProvider implements AuthenticationProvider {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAbstractAuthenticationProvider.class);
@Override
public boolean supports(Class<?> authentication) {
- return UsernamePasswordAuthenticationToken.class
- .isAssignableFrom(authentication);
+ return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationFailureHandler.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationFailureHandler.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationFailureHandler.java
index 49a7e86..a117df6 100644
--- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationFailureHandler.java
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationFailureHandler.java
@@ -18,12 +18,12 @@
package org.apache.atlas.web.security;
+import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.json.simple.JSONObject;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
+import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+@Component
public class AtlasAuthenticationFailureHandler implements AuthenticationFailureHandler {
private static Logger LOG = LoggerFactory.getLogger(AtlasAuthenticationFailureHandler.class);
@@ -43,14 +44,12 @@ public class AtlasAuthenticationFailureHandler implements AuthenticationFailureH
LOG.debug("Login Failure ", e);
JSONObject json = new JSONObject();
- ObjectMapper mapper = new ObjectMapper();
json.put("msgDesc", e.getMessage());
- String jsonAsStr = mapper.writeValueAsString(json);
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setCharacterEncoding("UTF-8");
- response.getWriter().write(jsonAsStr);
+ response.getWriter().write(json.toJSONString());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationProvider.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationProvider.java
index 953d737..80d6604 100644
--- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationProvider.java
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationProvider.java
@@ -17,20 +17,19 @@
*/
package org.apache.atlas.web.security;
-import javax.annotation.PostConstruct;
-
+import org.apache.atlas.ApplicationProperties;
+import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
-import org.apache.atlas.ApplicationProperties;
-import org.apache.commons.configuration.Configuration;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
@Component
-public class AtlasAuthenticationProvider extends
- AtlasAbstractAuthenticationProvider {
+public class AtlasAuthenticationProvider extends AtlasAbstractAuthenticationProvider {
private static final Logger LOG = LoggerFactory
.getLogger(AtlasAuthenticationProvider.class);
@@ -44,22 +43,27 @@ public class AtlasAuthenticationProvider extends
private boolean ssoEnabled = false;
- @Autowired
- AtlasLdapAuthenticationProvider ldapAuthenticationProvider;
+ final AtlasLdapAuthenticationProvider ldapAuthenticationProvider;
- @Autowired
- AtlasFileAuthenticationProvider fileAuthenticationProvider;
+ final AtlasFileAuthenticationProvider fileAuthenticationProvider;
- @Autowired
- AtlasADAuthenticationProvider adAuthenticationProvider;
+ final AtlasADAuthenticationProvider adAuthenticationProvider;
+
+ @Inject
+ public AtlasAuthenticationProvider(AtlasLdapAuthenticationProvider ldapAuthenticationProvider,
+ AtlasFileAuthenticationProvider fileAuthenticationProvider,
+ AtlasADAuthenticationProvider adAuthenticationProvider) {
+ this.ldapAuthenticationProvider = ldapAuthenticationProvider;
+ this.fileAuthenticationProvider = fileAuthenticationProvider;
+ this.adAuthenticationProvider = adAuthenticationProvider;
+ }
@PostConstruct
void setAuthenticationMethod() {
try {
Configuration configuration = ApplicationProperties.get();
- this.fileAuthenticationMethodEnabled = configuration.getBoolean(
- FILE_AUTH_METHOD, true);
+ this.fileAuthenticationMethodEnabled = configuration.getBoolean(FILE_AUTH_METHOD, true);
boolean ldapAuthenticationEnabled = configuration.getBoolean(LDAP_AUTH_METHOD, false);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationSuccessHandler.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationSuccessHandler.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationSuccessHandler.java
index 2942e8e..e7a5d66 100644
--- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationSuccessHandler.java
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasAuthenticationSuccessHandler.java
@@ -18,12 +18,12 @@
package org.apache.atlas.web.security;
+import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.json.simple.JSONObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+@Component
public class AtlasAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
private static Logger LOG = LoggerFactory.getLogger(AuthenticationSuccessHandler.class);
@@ -41,7 +42,6 @@ public class AtlasAuthenticationSuccessHandler implements AuthenticationSuccessH
LOG.debug("Login Success " + authentication.getPrincipal());
JSONObject json = new JSONObject();
- ObjectMapper mapper = new ObjectMapper();
json.put("msgDesc", "Success");
if (request.getSession() != null) { // incase of form based login mark it as local login in session
@@ -49,10 +49,9 @@ public class AtlasAuthenticationSuccessHandler implements AuthenticationSuccessH
request.getServletContext().setAttribute(request.getSession().getId(), "locallogin");
}
- String jsonAsStr = mapper.writeValueAsString(json);
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
response.setCharacterEncoding("UTF-8");
- response.getWriter().write(jsonAsStr);
+ response.getWriter().write(json.toJSONString());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/security/AtlasFileAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasFileAuthenticationProvider.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasFileAuthenticationProvider.java
index 1032b1c..f177fd4 100644
--- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasFileAuthenticationProvider.java
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasFileAuthenticationProvider.java
@@ -16,12 +16,9 @@
*/
package org.apache.atlas.web.security;
-import java.util.Collection;
-
import org.apache.atlas.web.dao.UserDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
@@ -30,6 +27,9 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import java.util.Collection;
@Component
@@ -37,8 +37,12 @@ public class AtlasFileAuthenticationProvider extends AtlasAbstractAuthentication
private static Logger logger = LoggerFactory.getLogger(AtlasFileAuthenticationProvider.class);
- @Autowired
- private UserDetailsService userDetailsService;
+ private final UserDetailsService userDetailsService;
+
+ @Inject
+ public AtlasFileAuthenticationProvider(UserDetailsService userDetailsService) {
+ this.userDetailsService = userDetailsService;
+ }
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java
new file mode 100644
index 0000000..6b512af
--- /dev/null
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java
@@ -0,0 +1,169 @@
+/**
+ * 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.web.security;
+
+import org.apache.atlas.web.filters.ActiveServerFilter;
+import org.apache.atlas.web.filters.AtlasAuthenticationEntryPoint;
+import org.apache.atlas.web.filters.AtlasAuthenticationFilter;
+import org.apache.atlas.web.filters.AtlasAuthorizationFilter;
+import org.apache.atlas.web.filters.AtlasCSRFPreventionFilter;
+import org.apache.atlas.web.filters.AtlasKnoxSSOAuthenticationFilter;
+import org.apache.atlas.web.filters.StaleTransactionCleanupFilter;
+import org.apache.commons.configuration.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.web.AuthenticationEntryPoint;
+import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
+import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint;
+import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
+import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
+import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter;
+import org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher;
+import org.springframework.security.web.util.matcher.RequestMatcher;
+
+import javax.inject.Inject;
+import java.util.LinkedHashMap;
+
+@EnableWebSecurity
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+public class AtlasSecurityConfig extends WebSecurityConfigurerAdapter {
+ private static final Logger LOG = LoggerFactory.getLogger(AtlasSecurityConfig.class);
+
+ private final AtlasAuthenticationProvider authenticationProvider;
+ private final AtlasAuthenticationSuccessHandler successHandler;
+ private final AtlasAuthenticationFailureHandler failureHandler;
+ private final AtlasAuthorizationFilter atlasAuthorizationFilter;
+ private final AtlasKnoxSSOAuthenticationFilter ssoAuthenticationFilter;
+ private final AtlasAuthenticationFilter atlasAuthenticationFilter;
+ private final AtlasCSRFPreventionFilter csrfPreventionFilter;
+ private final AtlasAuthenticationEntryPoint atlasAuthenticationEntryPoint;
+
+ // Our own Atlas filters need to be registered as well
+ private final Configuration configuration;
+ private final StaleTransactionCleanupFilter staleTransactionCleanupFilter;
+ private final ActiveServerFilter activeServerFilter;
+
+ @Inject
+ public AtlasSecurityConfig(AtlasKnoxSSOAuthenticationFilter ssoAuthenticationFilter,
+ AtlasCSRFPreventionFilter atlasCSRFPreventionFilter,
+ AtlasAuthenticationFilter atlasAuthenticationFilter,
+ AtlasAuthenticationProvider authenticationProvider,
+ AtlasAuthenticationSuccessHandler successHandler,
+ AtlasAuthenticationFailureHandler failureHandler,
+ AtlasAuthorizationFilter atlasAuthorizationFilter,
+ AtlasAuthenticationEntryPoint atlasAuthenticationEntryPoint,
+ Configuration configuration,
+ StaleTransactionCleanupFilter staleTransactionCleanupFilter,
+ ActiveServerFilter activeServerFilter) {
+ this.ssoAuthenticationFilter = ssoAuthenticationFilter;
+ this.csrfPreventionFilter = atlasCSRFPreventionFilter;
+ this.atlasAuthenticationFilter = atlasAuthenticationFilter;
+ this.authenticationProvider = authenticationProvider;
+ this.successHandler = successHandler;
+ this.failureHandler = failureHandler;
+ this.atlasAuthorizationFilter = atlasAuthorizationFilter;
+ this.atlasAuthenticationEntryPoint = atlasAuthenticationEntryPoint;
+ this.configuration = configuration;
+ this.staleTransactionCleanupFilter = staleTransactionCleanupFilter;
+ this.activeServerFilter = activeServerFilter;
+ }
+
+ public BasicAuthenticationEntryPoint getAuthenticationEntryPoint() {
+ BasicAuthenticationEntryPoint basicAuthenticationEntryPoint = new BasicAuthenticationEntryPoint();
+ basicAuthenticationEntryPoint.setRealmName("atlas.com");
+ return basicAuthenticationEntryPoint;
+ }
+
+ public DelegatingAuthenticationEntryPoint getDelegatingAuthenticationEntryPoint() {
+ LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPointMap = new LinkedHashMap<>();
+ entryPointMap.put(new RequestHeaderRequestMatcher("User-Agent", "Mozilla"), atlasAuthenticationEntryPoint);
+ DelegatingAuthenticationEntryPoint entryPoint = new DelegatingAuthenticationEntryPoint(entryPointMap);
+ entryPoint.setDefaultEntryPoint(getAuthenticationEntryPoint());
+ return entryPoint;
+ }
+
+ @Inject
+ protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) {
+ authenticationManagerBuilder.authenticationProvider(authenticationProvider);
+ }
+
+ @Override
+ public void configure(WebSecurity web) throws Exception {
+ web.ignoring()
+ .antMatchers("/login.jsp",
+ "/css/**",
+ "/img/**",
+ "/libs/**",
+ "/js/**",
+ "/ieerror.html",
+ "/api/atlas/admin/status",
+ "/api/atlas/admin/metrics");
+ }
+
+ protected void configure(HttpSecurity httpSecurity) throws Exception {
+
+ //@formatter:off
+ httpSecurity
+ .authorizeRequests().anyRequest().authenticated()
+ .and()
+ .headers().disable()
+ .servletApi()
+ .and()
+ .csrf().disable()
+ .sessionManagement()
+ .enableSessionUrlRewriting(false)
+ .sessionCreationPolicy(SessionCreationPolicy.ALWAYS)
+ .sessionFixation()
+ .newSession()
+ .and()
+ .formLogin()
+ .loginPage("/login.jsp")
+ .loginProcessingUrl("/j_spring_security_check")
+ .successHandler(successHandler)
+ .failureHandler(failureHandler)
+ .usernameParameter("j_username")
+ .passwordParameter("j_password")
+ .and()
+ .logout()
+ .logoutSuccessUrl("/login.jsp")
+ .deleteCookies("ATLASSESSIONID")
+ .logoutUrl("/logout.html")
+ .and()
+ .httpBasic()
+ .authenticationEntryPoint(getDelegatingAuthenticationEntryPoint());
+ //@formatter:on
+
+ if (configuration.getBoolean("atlas.server.ha.enabled", false)) {
+ LOG.info("Atlas is in HA Mode, enabling ActiveServerFilter");
+ httpSecurity.addFilterAfter(activeServerFilter, BasicAuthenticationFilter.class);
+ }
+ httpSecurity
+ .addFilterAfter(staleTransactionCleanupFilter, BasicAuthenticationFilter.class)
+ .addFilterAfter(ssoAuthenticationFilter, BasicAuthenticationFilter.class)
+ .addFilterAfter(atlasAuthenticationFilter, SecurityContextHolderAwareRequestFilter.class)
+ .addFilterAfter(csrfPreventionFilter, AtlasAuthenticationFilter.class)
+ .addFilterAfter(atlasAuthorizationFilter, FilterSecurityInterceptor.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorModule.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorModule.java b/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorModule.java
deleted file mode 100644
index 1f67f9f..0000000
--- a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorModule.java
+++ /dev/null
@@ -1,50 +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.web.service;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
-import org.apache.atlas.listener.ActiveStateChangeHandler;
-import org.apache.atlas.notification.NotificationHookConsumer;
-import org.apache.atlas.repository.audit.HBaseBasedAuditRepository;
-import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
-import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
-import org.apache.atlas.service.Service;
-import org.apache.atlas.services.DefaultMetadataService;
-
-/**
- * A Guice module that registers the handlers of High Availability state change handlers and other services.
- *
- * Any new handler that should react to HA state change should be registered here.
- */
-public class ActiveInstanceElectorModule extends AbstractModule {
- @Override
- protected void configure() {
- Multibinder<ActiveStateChangeHandler> activeStateChangeHandlerBinder =
- Multibinder.newSetBinder(binder(), ActiveStateChangeHandler.class);
- activeStateChangeHandlerBinder.addBinding().to(GraphBackedSearchIndexer.class);
- activeStateChangeHandlerBinder.addBinding().to(DefaultMetadataService.class);
- activeStateChangeHandlerBinder.addBinding().to(NotificationHookConsumer.class);
- activeStateChangeHandlerBinder.addBinding().to(HBaseBasedAuditRepository.class);
- activeStateChangeHandlerBinder.addBinding().to(AtlasTypeDefGraphStoreV1.class);
-
- Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder(), Service.class);
- serviceBinder.addBinding().to(ActiveInstanceElectorService.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java b/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
index 8e649f7..5071204 100644
--- a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceElectorService.java
@@ -18,10 +18,6 @@
package org.apache.atlas.web.service;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.Singleton;
-import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.atlas.ha.AtlasServerIdSelector;
import org.apache.atlas.ha.HAConfiguration;
@@ -32,10 +28,14 @@ import org.apache.curator.framework.recipes.leader.LeaderLatch;
import org.apache.curator.framework.recipes.leader.LeaderLatchListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Set;
/**
* A service that implements leader election to determine whether this Atlas server is Active.
@@ -47,7 +47,9 @@ import java.util.Collection;
* on being removed from leadership, this instance is treated as a passive instance and calls
* {@link ActiveStateChangeHandler}s to deactivate them.
*/
-@Singleton
+
+@Component
+@Order(1)
public class ActiveInstanceElectorService implements Service, LeaderLatchListener {
private static final Logger LOG = LoggerFactory.getLogger(ActiveInstanceElectorService.class);
@@ -55,7 +57,7 @@ public class ActiveInstanceElectorService implements Service, LeaderLatchListene
private final Configuration configuration;
private final ServiceState serviceState;
private final ActiveInstanceState activeInstanceState;
- private Collection<Provider<ActiveStateChangeHandler>> activeStateChangeHandlerProviders;
+ private Set<ActiveStateChangeHandler> activeStateChangeHandlerProviders;
private Collection<ActiveStateChangeHandler> activeStateChangeHandlers;
private CuratorFactory curatorFactory;
private LeaderLatch leaderLatch;
@@ -68,17 +70,8 @@ public class ActiveInstanceElectorService implements Service, LeaderLatchListene
* @throws AtlasException
*/
@Inject
- public ActiveInstanceElectorService(
- Collection<Provider<ActiveStateChangeHandler>> activeStateChangeHandlerProviders,
- CuratorFactory curatorFactory, ActiveInstanceState activeInstanceState,
- ServiceState serviceState)
- throws AtlasException {
- this(ApplicationProperties.get(), activeStateChangeHandlerProviders,
- curatorFactory, activeInstanceState, serviceState);
- }
-
ActiveInstanceElectorService(Configuration configuration,
- Collection<Provider<ActiveStateChangeHandler>> activeStateChangeHandlerProviders,
+ Set<ActiveStateChangeHandler> activeStateChangeHandlerProviders,
CuratorFactory curatorFactory, ActiveInstanceState activeInstanceState,
ServiceState serviceState) {
this.configuration = configuration;
@@ -164,10 +157,7 @@ public class ActiveInstanceElectorService implements Service, LeaderLatchListene
private void cacheActiveStateChangeHandlers() {
if (activeStateChangeHandlers.size()==0) {
- for (Provider<ActiveStateChangeHandler> provider : activeStateChangeHandlerProviders) {
- ActiveStateChangeHandler handler = provider.get();
- activeStateChangeHandlers.add(handler);
- }
+ activeStateChangeHandlers.addAll(activeStateChangeHandlerProviders);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceState.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceState.java b/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceState.java
index ee3b829..c6b4a6f 100644
--- a/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceState.java
+++ b/webapp/src/main/java/org/apache/atlas/web/service/ActiveInstanceState.java
@@ -18,7 +18,6 @@
package org.apache.atlas.web.service;
-import com.google.inject.Inject;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
@@ -33,8 +32,10 @@ import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import scala.actors.threadpool.Arrays;
+import javax.inject.Inject;
import java.nio.charset.Charset;
import java.util.List;
@@ -45,6 +46,7 @@ import java.util.List;
* under a read-write lock implemented using Curator's {@link InterProcessReadWriteLock} to
* provide for safety across multiple processes.
*/
+@Component
public class ActiveInstanceState {
private final Configuration configuration;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java b/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
index 50351f0..7c89055 100644
--- a/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
+++ b/webapp/src/main/java/org/apache/atlas/web/service/CuratorFactory.java
@@ -20,7 +20,6 @@ package org.apache.atlas.web.service;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
-import com.google.inject.Singleton;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.atlas.ha.HAConfiguration;
@@ -36,7 +35,9 @@ import org.apache.hadoop.security.UserGroupInformation;
import org.apache.zookeeper.data.ACL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Singleton;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@@ -47,6 +48,7 @@ import java.util.List;
* Allows for stubbing in tests.
*/
@Singleton
+@Component
public class CuratorFactory {
private static final Logger LOG = LoggerFactory.getLogger(CuratorFactory.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/service/ServiceModule.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/ServiceModule.java b/webapp/src/main/java/org/apache/atlas/web/service/ServiceModule.java
deleted file mode 100644
index 2128b7c..0000000
--- a/webapp/src/main/java/org/apache/atlas/web/service/ServiceModule.java
+++ /dev/null
@@ -1,41 +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.web.service;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
-import org.apache.atlas.kafka.KafkaNotification;
-import org.apache.atlas.listener.EntityChangeListener;
-import org.apache.atlas.notification.NotificationHookConsumer;
-import org.apache.atlas.notification.NotificationEntityChangeListener;
-import org.apache.atlas.service.Service;
-
-public class ServiceModule extends AbstractModule {
- @Override
- protected void configure() {
- Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder(), Service.class);
- serviceBinder.addBinding().to(KafkaNotification.class);
- serviceBinder.addBinding().to(NotificationHookConsumer.class);
-
- //Add NotificationEntityChangeListener as EntityChangeListener
- Multibinder<EntityChangeListener> entityChangeListenerBinder =
- Multibinder.newSetBinder(binder(), EntityChangeListener.class);
- entityChangeListenerBinder.addBinding().to(NotificationEntityChangeListener.class);
- }
-}
[02/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java
deleted file mode 100755
index 9d5ff5a..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityV2JerseyResourceIT.java
+++ /dev/null
@@ -1,779 +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.web.resources;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.EntityAuditEvent;
-import org.apache.atlas.model.instance.AtlasClassification;
-import org.apache.atlas.model.instance.AtlasEntity;
-import org.apache.atlas.model.instance.AtlasEntityHeader;
-import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
-import org.apache.atlas.model.instance.AtlasObjectId;
-import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
-import org.apache.atlas.model.instance.EntityMutationResponse;
-import org.apache.atlas.model.instance.EntityMutations;
-import org.apache.atlas.model.typedef.AtlasClassificationDef;
-import org.apache.atlas.model.typedef.AtlasEntityDef;
-import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.notification.NotificationConsumer;
-import org.apache.atlas.notification.NotificationInterface;
-import org.apache.atlas.notification.NotificationModule;
-import org.apache.atlas.notification.entity.EntityNotification;
-import org.apache.atlas.type.AtlasTypeUtil;
-import org.apache.atlas.typesystem.types.TypeUtils;
-import org.apache.commons.lang.RandomStringUtils;
-import org.codehaus.jettison.json.JSONArray;
-import org.joda.time.DateTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Guice;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.inject.Inject;
-import com.sun.jersey.api.client.ClientResponse;
-
-
-/**
- * Integration tests for Entity Jersey Resource.
- */
-@Guice(modules = {NotificationModule.class})
-public class EntityV2JerseyResourceIT extends BaseResourceIT {
-
- private static final Logger LOG = LoggerFactory.getLogger(EntityV2JerseyResourceIT.class);
-
- private final String DATABASE_NAME = "db" + randomString();
- private final String TABLE_NAME = "table" + randomString();
- private String traitName;
-
- private AtlasEntity dbEntity;
- private AtlasEntity tableEntity;
- @Inject
- private NotificationInterface notificationInterface;
- private NotificationConsumer<EntityNotification> notificationConsumer;
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
-
- createTypeDefinitionsV2();
-
- List<NotificationConsumer<EntityNotification>> consumers =
- notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);
-
- notificationConsumer = consumers.iterator().next();
- }
-
- @Test
- public void testSubmitEntity() throws Exception {
- TypeUtils.Pair dbAndTable = createDBAndTable();
- assertNotNull(dbAndTable);
- assertNotNull(dbAndTable.left);
- assertNotNull(dbAndTable.right);
- }
-
- @Test
- public void testCreateNestedEntities() throws Exception {
- AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo();
-
- AtlasEntity databaseInstance = new AtlasEntity(DATABASE_TYPE_V2, "name", "db1");
- databaseInstance.setAttribute("name", "db1");
- databaseInstance.setAttribute("description", "foo database");
- databaseInstance.setAttribute("owner", "user1");
- databaseInstance.setAttribute("locationUri", "/tmp");
- databaseInstance.setAttribute("createTime",1000);
- entities.addEntity(databaseInstance);
-
- int nTables = 5;
- int colsPerTable=3;
-
- for(int i = 0; i < nTables; i++) {
- String tableName = "db1-table-" + i;
-
- AtlasEntity tableInstance = new AtlasEntity(HIVE_TABLE_TYPE_V2, "name", tableName);
- tableInstance.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
- tableInstance.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(databaseInstance));
- tableInstance.setAttribute("description", tableName + " table");
- entities.addEntity(tableInstance);
-
- List<AtlasObjectId> columns = new ArrayList<>();
- for(int j = 0; j < colsPerTable; j++) {
- AtlasEntity columnInstance = new AtlasEntity(COLUMN_TYPE_V2);
- columnInstance.setAttribute("name", tableName + "-col-" + j);
- columnInstance.setAttribute("dataType", "String");
- columnInstance.setAttribute("comment", "column " + j + " for table " + i);
-
- columns.add(AtlasTypeUtil.getAtlasObjectId(columnInstance));
-
- entities.addReferredEntity(columnInstance);
- }
- tableInstance.setAttribute("columns", columns);
- }
-
- //Create the tables. The database and columns should be created automatically, since
- //the tables reference them.
-
- EntityMutationResponse response = atlasClientV2.createEntities(entities);
- Assert.assertNotNull(response);
-
- Map<String,String> guidsCreated = response.getGuidAssignments();
- assertEquals(guidsCreated.size(), nTables * colsPerTable + nTables + 1);
- assertNotNull(guidsCreated.get(databaseInstance.getGuid()));
-
- for(AtlasEntity r : entities.getEntities()) {
- assertNotNull(guidsCreated.get(r.getGuid()));
- }
-
- for(AtlasEntity r : entities.getReferredEntities().values()) {
- assertNotNull(guidsCreated.get(r.getGuid()));
- }
- }
-
- @Test
- public void testRequestUser() throws Exception {
- AtlasEntity hiveDBInstanceV2 = createHiveDB(randomString());
- List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(hiveDBInstanceV2.getGuid(), (short) 10);
- assertEquals(events.size(), 1);
- assertEquals(events.get(0).getUser(), "admin");
- }
-
- @Test
- public void testEntityDeduping() throws Exception {
- JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
- assertEquals(results.length(), 1);
-
- final AtlasEntity hiveDBInstanceV2 = createHiveDB();
- // Do the notification thing here
- waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
- @Override
- public boolean evaluate(EntityNotification notification) throws Exception {
- return notification != null && notification.getEntity().getId()._getId().equals(hiveDBInstanceV2.getGuid());
- }
- });
-
-
- results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
- assertEquals(results.length(), 1);
-
- //Test the same across references
- final String tableName = randomString();
- AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(hiveDBInstanceV2, tableName);
- hiveTableInstanceV2.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
-
- EntityMutationResponse entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(hiveTableInstanceV2));
- assertNotNull(entity);
- assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
- results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
- assertEquals(results.length(), 1);
- }
-
- private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
- throws Exception {
- List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
- for (EntityAuditEvent event : events) {
- if (event.getAction() == auditAction) {
- return;
- }
- }
- fail("Expected audit event with action = " + auditAction);
- }
-
- @Test
- public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
- //create type
- AtlasEntityDef entityDef = AtlasTypeUtil
- .createClassTypeDef(randomString(),
- ImmutableSet.<String>of(),
- AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string")
- );
- AtlasTypesDef typesDef = new AtlasTypesDef();
- typesDef.getEntityDefs().add(entityDef);
-
- AtlasTypesDef created = atlasClientV2.createAtlasTypeDefs(typesDef);
- assertNotNull(created);
- assertNotNull(created.getEntityDefs());
- assertEquals(created.getEntityDefs().size(), 1);
-
- //create entity for the type
- AtlasEntity instance = new AtlasEntity(entityDef.getName());
- instance.setAttribute("name", randomString());
- EntityMutationResponse mutationResponse = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(instance));
- assertNotNull(mutationResponse);
- assertNotNull(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
- assertEquals(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(),1 );
- String guid = mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
-
- //update type - add attribute
- entityDef = AtlasTypeUtil.createClassTypeDef(entityDef.getName(), ImmutableSet.<String>of(),
- AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
- AtlasTypeUtil.createOptionalAttrDef("description", "string"));
-
- typesDef = new AtlasTypesDef();
- typesDef.getEntityDefs().add(entityDef);
-
- AtlasTypesDef updated = atlasClientV2.updateAtlasTypeDefs(typesDef);
- assertNotNull(updated);
- assertNotNull(updated.getEntityDefs());
- assertEquals(updated.getEntityDefs().size(), 1);
-
- //Get definition after type update - new attributes should be null
- AtlasEntity entityByGuid = getEntityByGuid(guid);
- assertNull(entityByGuid.getAttribute("description"));
- assertEquals(entityByGuid.getAttribute("name"), instance.getAttribute("name"));
- }
-
- @Test
- public void testEntityInvalidValue() throws Exception {
- AtlasEntity databaseInstance = new AtlasEntity(DATABASE_TYPE_V2);
- String dbName = randomString();
- String nullString = null;
- String emptyString = "";
- databaseInstance.setAttribute("name", dbName);
- databaseInstance.setAttribute("description", nullString);
- AtlasEntityHeader created = createEntity(databaseInstance);
-
- // null valid value for required attr - description
- assertNull(created);
-
- databaseInstance.setAttribute("description", emptyString);
- created = createEntity(databaseInstance);
-
- // empty string valid value for required attr
- assertNotNull(created);
-
- databaseInstance.setGuid(created.getGuid());
- databaseInstance.setAttribute("owner", nullString);
- databaseInstance.setAttribute("locationUri", emptyString);
-
- created = updateEntity(databaseInstance);
-
- // null/empty string valid value for optional attr
- assertNotNull(created);
- }
-
- @Test
- public void testGetEntityByAttribute() throws Exception {
- AtlasEntity hiveDB = createHiveDB();
- String qualifiedName = (String) hiveDB.getAttribute(NAME);
- //get entity by attribute
-
- AtlasEntity byAttribute = atlasClientV2.getEntityByAttribute(DATABASE_TYPE_V2, toMap(NAME, qualifiedName)).getEntity();
- assertEquals(byAttribute.getTypeName(), DATABASE_TYPE_V2);
- assertEquals(byAttribute.getAttribute(NAME), qualifiedName);
- }
-
- @Test
- public void testSubmitEntityWithBadDateFormat() throws Exception {
- AtlasEntity hiveDBEntity = createHiveDBInstanceV2("db" + randomString());
- AtlasEntityHeader hiveDBHeader = createEntity(hiveDBEntity);
- hiveDBEntity.setGuid(hiveDBHeader.getGuid());
-
- AtlasEntity tableInstance = createHiveTableInstanceV2(hiveDBEntity, "table" + randomString());
- //Dates with an invalid format are simply nulled out. This does not produce
- //an error. See AtlasBuiltInTypes.AtlasDateType.getNormalizedValue().
- tableInstance.setAttribute("lastAccessTime", 1107201407);
- AtlasEntityHeader tableEntityHeader = createEntity(tableInstance);
- assertNotNull(tableEntityHeader);
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testAddProperty() throws Exception {
- //add property
- String description = "bar table - new desc";
- addProperty(createHiveTable().getGuid(), "description", description);
-
- AtlasEntity entityByGuid = getEntityByGuid(createHiveTable().getGuid());
- Assert.assertNotNull(entityByGuid);
-
- entityByGuid.setAttribute("description", description);
-
- // TODO: This behavior should've been consistent across APIs
-// //invalid property for the type
-// try {
-// addProperty(table.getGuid(), "invalid_property", "bar table");
-// Assert.fail("Expected AtlasServiceException");
-// } catch (AtlasServiceException e) {
-// assertNotNull(e.getStatus());
-// assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
-// }
-
- //non-string property, update
- Object currentTime = new DateTime();
- addProperty(createHiveTable().getGuid(), "createTime", currentTime);
-
- entityByGuid = getEntityByGuid(createHiveTable().getGuid());
- Assert.assertNotNull(entityByGuid);
- }
-
- @Test
- public void testAddNullPropertyValue() throws Exception {
- // FIXME: Behavior has changed between v1 and v2
- //add property
-// try {
- addProperty(createHiveTable().getGuid(), "description", null);
-// Assert.fail("Expected AtlasServiceException");
-// } catch(AtlasServiceException e) {
-// Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
-// }
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testGetInvalidEntityDefinition() throws Exception {
- getEntityByGuid("blah");
- }
-
- @Test(dependsOnMethods = "testSubmitEntity", enabled = false)
- public void testGetEntityList() throws Exception {
- // TODO: Can only be done when there's a search API exposed from entity REST
- }
-
- @Test(enabled = false)
- public void testGetEntityListForBadEntityType() throws Exception {
- // FIXME: Complete test when search interface is in place
- }
-
- @Test(enabled = false)
- public void testGetEntityListForNoInstances() throws Exception {
- // FIXME: Complete test when search interface is in place
- /*
- String typeName = "";
-
- ClientResponse clientResponse =
- service.path(ENTITIES).queryParam("type", typeName).accept(Servlets.JSON_MEDIA_TYPE)
- .type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class);
- Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
-
- String responseAsString = clientResponse.getEntity(String.class);
- Assert.assertNotNull(responseAsString);
-
- JSONObject response = new JSONObject(responseAsString);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
- Assert.assertEquals(list.length(), 0);
- */
- }
-
- private String addNewType() throws Exception {
- String typeName = "test" + randomString();
- AtlasEntityDef classTypeDef = AtlasTypeUtil
- .createClassTypeDef(typeName, ImmutableSet.<String>of(),
- AtlasTypeUtil.createRequiredAttrDef("name", "string"),
- AtlasTypeUtil.createRequiredAttrDef("description", "string"));
- AtlasTypesDef typesDef = new AtlasTypesDef();
- typesDef.getEntityDefs().add(classTypeDef);
- createType(typesDef);
- return typeName;
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testGetTraitNames() throws Exception {
- AtlasClassifications classifications = atlasClientV2.getClassifications(createHiveTable().getGuid());
- assertNotNull(classifications);
- assertTrue(classifications.getList().size() > 0);
- assertEquals(classifications.getList().size(), 8);
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testCommonAttributes() throws Exception{
- AtlasEntity entity = getEntityByGuid(createHiveTable().getGuid());
- Assert.assertNotNull(entity.getStatus());
- Assert.assertNotNull(entity.getVersion());
- Assert.assertNotNull(entity.getCreatedBy());
- Assert.assertNotNull(entity.getCreateTime());
- Assert.assertNotNull(entity.getUpdatedBy());
- Assert.assertNotNull(entity.getUpdateTime());
- }
-
- private void addProperty(String guid, String property, Object value) throws AtlasServiceException {
-
- AtlasEntity entityByGuid = getEntityByGuid(guid);
- entityByGuid.setAttribute(property, value);
- EntityMutationResponse response = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(entityByGuid));
- assertNotNull(response);
- assertNotNull(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
- }
-
- private AtlasEntity createHiveDB() {
- if (dbEntity == null) {
- dbEntity = createHiveDB(DATABASE_NAME);
- }
- return dbEntity;
- }
-
- private AtlasEntity createHiveDB(String dbName) {
- AtlasEntity hiveDBInstanceV2 = createHiveDBInstanceV2(dbName);
- AtlasEntityHeader entityHeader = createEntity(hiveDBInstanceV2);
- assertNotNull(entityHeader);
- assertNotNull(entityHeader.getGuid());
- hiveDBInstanceV2.setGuid(entityHeader.getGuid());
- return hiveDBInstanceV2;
- }
-
- private TypeUtils.Pair<AtlasEntity, AtlasEntity> createDBAndTable() throws Exception {
- AtlasEntity dbInstanceV2 = createHiveDB();
- AtlasEntity hiveTableInstanceV2 = createHiveTable();
- return TypeUtils.Pair.of(dbInstanceV2, hiveTableInstanceV2);
- }
-
- private AtlasEntity createHiveTable() throws Exception {
- if (tableEntity == null) {
- tableEntity = createHiveTable(createHiveDB(), TABLE_NAME);
- }
- return tableEntity;
-
- }
-
- private AtlasEntity createHiveTable(AtlasEntity dbInstanceV2, String tableName) throws Exception {
- AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(dbInstanceV2, tableName);
- AtlasEntityHeader createdHeader = createEntity(hiveTableInstanceV2);
- assertNotNull(createdHeader);
- assertNotNull(createdHeader.getGuid());
- hiveTableInstanceV2.setGuid(createdHeader.getGuid());
- tableEntity = hiveTableInstanceV2;
- return hiveTableInstanceV2;
- }
-
- @Test(dependsOnMethods = "testGetTraitNames")
- public void testAddTrait() throws Exception {
- traitName = "PII_Trait" + randomString();
- AtlasClassificationDef piiTrait =
- AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
- AtlasTypesDef typesDef = new AtlasTypesDef();
- typesDef.getClassificationDefs().add(piiTrait);
- createType(typesDef);
-
- atlasClientV2.addClassifications(createHiveTable().getGuid(), ImmutableList.of(new AtlasClassification(piiTrait.getName())));
-
- assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_ADD);
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testGetTraitDefinitionForEntity() throws Exception{
- traitName = "PII_Trait" + randomString();
- AtlasClassificationDef piiTrait =
- AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
- AtlasTypesDef typesDef = new AtlasTypesDef();
- typesDef.getClassificationDefs().add(piiTrait);
- createType(typesDef);
-
- AtlasClassificationDef classificationByName = atlasClientV2.getClassificationDefByName(traitName);
- assertNotNull(classificationByName);
-
- AtlasEntity hiveTable = createHiveTable();
- assertEquals(hiveTable.getClassifications().size(), 7);
-
- AtlasClassification piiClassification = new AtlasClassification(piiTrait.getName());
-
- atlasClientV2.addClassifications(hiveTable.getGuid(), Lists.newArrayList(piiClassification));
-
- AtlasClassifications classifications = atlasClientV2.getClassifications(hiveTable.getGuid());
- assertNotNull(classifications);
- assertTrue(classifications.getList().size() > 0);
- assertEquals(classifications.getList().size(), 8);
- }
-
-
- @Test(dependsOnMethods = "testGetTraitNames")
- public void testAddTraitWithAttribute() throws Exception {
- final String traitName = "PII_Trait" + randomString();
- AtlasClassificationDef piiTrait = AtlasTypeUtil
- .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
- AtlasTypeUtil.createRequiredAttrDef("type", "string"));
- AtlasTypesDef typesDef = new AtlasTypesDef();
- typesDef.getClassificationDefs().add(piiTrait);
- createType(typesDef);
-
- AtlasClassification traitInstance = new AtlasClassification(traitName);
- traitInstance.setAttribute("type", "SSN");
-
- final String guid = createHiveTable().getGuid();
- atlasClientV2.addClassifications(guid, ImmutableList.of(traitInstance));
-
- // verify the response
- AtlasEntity withAssociationByGuid = atlasClientV2.getEntityByGuid(guid).getEntity();
- assertNotNull(withAssociationByGuid);
- assertFalse(withAssociationByGuid.getClassifications().isEmpty());
-
- boolean found = false;
- for (AtlasClassification atlasClassification : withAssociationByGuid.getClassifications()) {
- String attribute = (String)atlasClassification.getAttribute("type");
- if (attribute != null && attribute.equals("SSN")) {
- found = true;
- break;
- }
- }
- assertTrue(found);
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testAddTraitWithNoRegistration() throws Exception {
- final String traitName = "PII_Trait" + randomString();
- AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
-
- AtlasClassification traitInstance = new AtlasClassification(traitName);
-
- atlasClientV2.addClassifications("random", ImmutableList.of(traitInstance));
- }
-
- @Test(dependsOnMethods = "testAddTrait")
- public void testDeleteTrait() throws Exception {
- final String guid = createHiveTable().getGuid();
-
- try {
- atlasClientV2.deleteClassification(guid, traitName);
- } catch (AtlasServiceException ex) {
- fail("Deletion should've succeeded");
- }
- assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
- }
-
- @Test
- public void testDeleteTraitNonExistent() throws Exception {
- final String traitName = "blah_trait";
-
- try {
- atlasClientV2.deleteClassification("random", traitName);
- fail("Deletion for bogus names shouldn't have succeeded");
- } catch (AtlasServiceException ex) {
- assertNotNull(ex.getStatus());
-// assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
- assertEquals(ex.getStatus(), ClientResponse.Status.BAD_REQUEST);
- // Should it be a 400 or 404
- }
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
-
- final String guid = createHiveTable().getGuid();
- final String traitName = "PII_Trait" + randomString();
- AtlasClassificationDef piiTrait = AtlasTypeUtil
- .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
- AtlasTypeUtil.createRequiredAttrDef("type", "string"));
- AtlasTypesDef typesDef = new AtlasTypesDef();
- typesDef.getClassificationDefs().add(piiTrait);
- createType(typesDef);
-
- try {
- atlasClientV2.deleteClassification(guid, traitName);
- fail("Deletion should've failed for non-existent trait association");
- } catch (AtlasServiceException ex) {
- Assert.assertNotNull(ex.getStatus());
- assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
- }
- }
-
- private String random() {
- return RandomStringUtils.random(10);
- }
-
- @Test
- public void testUTF8() throws Exception {
- String classType = randomString();
- String attrName = random();
- String attrValue = random();
-
- AtlasEntityDef classTypeDef = AtlasTypeUtil
- .createClassTypeDef(classType, ImmutableSet.<String>of(),
- AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string"));
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
- atlasTypesDef.getEntityDefs().add(classTypeDef);
- createType(atlasTypesDef);
-
- AtlasEntity instance = new AtlasEntity(classType);
- instance.setAttribute(attrName, attrValue);
- AtlasEntityHeader entity = createEntity(instance);
- assertNotNull(entity);
- assertNotNull(entity.getGuid());
-
- AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid());
- assertEquals(entityByGuid.getAttribute(attrName), attrValue);
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testPartialUpdate() throws Exception {
- final List<AtlasEntity> columns = new ArrayList<>();
- Map<String, Object> values = new HashMap<>();
- values.put("name", "col1");
- values.put(NAME, "qualifiedName.col1");
- values.put("type", "string");
- values.put("comment", "col1 comment");
-
- AtlasEntity colEntity = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values);
- columns.add(colEntity);
- AtlasEntity hiveTable = createHiveTable();
- AtlasEntity tableUpdated = hiveTable;
-
- hiveTable.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
-
- AtlasEntityWithExtInfo entityInfo = new AtlasEntityWithExtInfo(tableUpdated);
- entityInfo.addReferredEntity(colEntity);
-
- LOG.debug("Full Update entity= " + tableUpdated);
- EntityMutationResponse updateResult = atlasClientV2.updateEntity(entityInfo);
- assertNotNull(updateResult);
- assertNotNull(updateResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
- assertTrue(updateResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
-
- String guid = hiveTable.getGuid();
- AtlasEntity entityByGuid1 = getEntityByGuid(guid);
- assertNotNull(entityByGuid1);
- entityByGuid1.getAttribute("columns");
-
- values.put("type", "int");
- colEntity = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values);
- columns.clear();
- columns.add(colEntity);
-
- tableUpdated = new AtlasEntity(HIVE_TABLE_TYPE_V2, "name", entityByGuid1.getAttribute("name"));
- tableUpdated.setGuid(entityByGuid1.getGuid());
- tableUpdated.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
-
- // tableUpdated = hiveTable;
- // tableUpdated.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
-
- LOG.debug("Partial Update entity by unique attributes= " + tableUpdated);
- Map<String, String> uniqAttributes = new HashMap<>();
- uniqAttributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, (String) hiveTable.getAttribute("name"));
-
- entityInfo = new AtlasEntityWithExtInfo(tableUpdated);
- entityInfo.addReferredEntity(colEntity);
-
- EntityMutationResponse updateResponse = atlasClientV2.updateEntityByAttribute(BaseResourceIT.HIVE_TABLE_TYPE_V2, uniqAttributes, entityInfo);
-
- assertNotNull(updateResponse);
- assertNotNull(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE));
- assertTrue(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).size() > 0);
-
- AtlasEntity entityByGuid2 = getEntityByGuid(guid);
- assertNotNull(entityByGuid2);
- }
-
- private AtlasEntity getEntityByGuid(String guid) throws AtlasServiceException {
- return atlasClientV2.getEntityByGuid(guid).getEntity();
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testCompleteUpdate() throws Exception {
- final List<AtlasEntity> columns = new ArrayList<>();
- Map<String, Object> values1 = new HashMap<>();
- values1.put("name", "col3");
- values1.put(NAME, "qualifiedName.col3");
- values1.put("type", "string");
- values1.put("comment", "col3 comment");
-
- Map<String, Object> values2 = new HashMap<>();
- values2.put("name", "col4");
- values2.put(NAME, "qualifiedName.col4");
- values2.put("type", "string");
- values2.put("comment", "col4 comment");
-
- AtlasEntity colEntity1 = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values1);
- AtlasEntity colEntity2 = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values2);
- columns.add(colEntity1);
- columns.add(colEntity2);
- AtlasEntity hiveTable = createHiveTable();
- hiveTable.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
-
- AtlasEntityWithExtInfo entityInfo = new AtlasEntityWithExtInfo(hiveTable);
- entityInfo.addReferredEntity(colEntity1);
- entityInfo.addReferredEntity(colEntity2);
-
- EntityMutationResponse updateEntityResult = atlasClientV2.updateEntity(entityInfo);
- assertNotNull(updateEntityResult);
- assertNotNull(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
- assertNotNull(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
- //2 columns are being created, and 1 hiveTable is being updated
- assertEquals(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size(), 1);
- assertEquals(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(), 2);
-
- AtlasEntity entityByGuid = getEntityByGuid(hiveTable.getGuid());
- List<AtlasObjectId> refs = (List<AtlasObjectId>) entityByGuid.getAttribute("columns");
- assertEquals(refs.size(), 2);
- }
-
- @Test
- public void testDeleteEntities() throws Exception {
- // Create 2 database entities
- AtlasEntity db1 = new AtlasEntity(DATABASE_TYPE_V2);
- String dbName1 = randomString();
- db1.setAttribute("name", dbName1);
- db1.setAttribute(NAME, dbName1);
- db1.setAttribute("clusterName", randomString());
- db1.setAttribute("description", randomString());
- AtlasEntityHeader entity1Header = createEntity(db1);
- AtlasEntity db2 = new AtlasEntity(DATABASE_TYPE_V2);
- String dbName2 = randomString();
- db2.setAttribute("name", dbName2);
- db2.setAttribute(NAME, dbName2);
- db2.setAttribute("clusterName", randomString());
- db2.setAttribute("description", randomString());
- AtlasEntityHeader entity2Header = createEntity(db2);
-
- // Delete the database entities
- EntityMutationResponse deleteResponse = atlasClientV2.deleteEntitiesByGuids(ImmutableList.of(entity1Header.getGuid(), entity2Header.getGuid()));
-
- // Verify that deleteEntities() response has database entity guids
- assertNotNull(deleteResponse);
- assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
- assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2);
-
- // Verify entities were deleted from the repository.
- }
-
- @Test
- public void testDeleteEntityByUniqAttribute() throws Exception {
- // Create database entity
- AtlasEntity hiveDB = createHiveDB(DATABASE_NAME + random());
-
- // Delete the database entity
- EntityMutationResponse deleteResponse = atlasClientV2.deleteEntityByAttribute(DATABASE_TYPE_V2, toMap(NAME, (String) hiveDB.getAttribute(NAME)));
-
- // Verify that deleteEntities() response has database entity guids
- assertNotNull(deleteResponse);
- assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
- assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 1);
-
- // Verify entities were deleted from the repository.
- }
-
- private Map<String, String> toMap(final String name, final String value) {
- return new HashMap<String, String>() {{
- put(name, value);
- }};
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java
deleted file mode 100755
index 87d8719..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/MetadataDiscoveryJerseyResourceIT.java
+++ /dev/null
@@ -1,267 +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.web.resources;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.Struct;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.EnumTypeDefinition;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.StructTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import javax.ws.rs.core.MultivaluedMap;
-import java.util.List;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.fail;
-
-/**
- * Search Integration Tests.
- */
-public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
-
- private String tagName;
- private String dbName;
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
- dbName = "db"+randomString();
- createTypes();
- createInstance( createHiveDBInstanceV1(dbName) );
- }
-
- @Test
- public void testSearchByDSL() throws Exception {
- 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);
-
- Assert.assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- assertEquals(response.getString("query"), dslQuery);
- assertEquals(response.getString("queryType"), "dsl");
-
- JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
- assertNotNull(results);
- assertEquals(results.length(), 1);
-
- int numRows = response.getInt(AtlasClient.COUNT);
- assertEquals(numRows, 1);
- }
-
- @Test
- public void testSearchDSLLimits() throws Exception {
-
- //search without new parameters of limit and offset should work
- 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);
- assertNotNull(response);
-
- //higher limit, all results returned
- JSONArray results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
- assertEquals(results.length(), 1);
-
- //default limit and offset -1, all results returned
- results = atlasClientV1.searchByDSL(dslQuery, -1, -1);
- assertEquals(results.length(), 1);
-
- //uses the limit parameter passed
- results = atlasClientV1.searchByDSL(dslQuery, 1, 0);
- assertEquals(results.length(), 1);
-
- //uses the offset parameter passed
- results = atlasClientV1.searchByDSL(dslQuery, 10, 1);
- assertEquals(results.length(), 0);
-
- //limit > 0
- try {
- atlasClientV1.searchByDSL(dslQuery, 0, 10);
- fail("Expected BAD_REQUEST");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
- }
-
- //limit > maxlimit
- try {
- atlasClientV1.searchByDSL(dslQuery, Integer.MAX_VALUE, 10);
- fail("Expected BAD_REQUEST");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
- }
-
- //offset >= 0
- try {
- atlasClientV1.searchByDSL(dslQuery, 10, -2);
- fail("Expected BAD_REQUEST");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
- }
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testSearchByDSLForUnknownType() throws Exception {
- String dslQuery = "from blah";
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("query", dslQuery);
- atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams);
- }
-
- @Test
- public void testSearchUsingGremlin() throws Exception {
- String query = "g.V.has('type', '" + BaseResourceIT.HIVE_TABLE_TYPE + "').toList()";
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("query", query);
-
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GREMLIN_SEARCH, queryParams);
-
- assertNotNull(response);
- assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- assertEquals(response.getString("query"), query);
- assertEquals(response.getString("queryType"), "gremlin");
- }
-
- @Test
- public void testSearchUsingDSL() throws Exception {
- //String query = "from dsl_test_type";
- 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);
-
- Assert.assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- assertEquals(response.getString("query"), query);
- assertEquals(response.getString("queryType"), "dsl");
- }
-
- @Test
- public void testSearchFullTextOnDSLFailure() throws Exception {
- String query = "*";
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("query", query);
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH, queryParams);
-
- Assert.assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- assertEquals(response.getString("query"), query);
- assertEquals(response.getString("queryType"), "full-text");
- }
-
- @Test(dependsOnMethods = "testSearchDSLLimits")
- public void testSearchUsingFullText() throws Exception {
- JSONObject response = atlasClientV1.searchByFullText(dbName, 10, 0);
- assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- assertEquals(response.getString("query"), dbName);
- assertEquals(response.getString("queryType"), "full-text");
-
- JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1, "Results: " + results);
-
- JSONObject row = results.getJSONObject(0);
- assertNotNull(row.get("guid"));
- assertEquals(row.getString("typeName"), DATABASE_TYPE);
- assertNotNull(row.get("score"));
-
- int numRows = response.getInt(AtlasClient.COUNT);
- assertEquals(numRows, 1);
-
- //API works without limit and offset
- String query = dbName;
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("query", query);
- response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_FULL_TEXT, queryParams);
- results = response.getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1);
-
- //verify passed in limits and offsets are used
- //higher limit and 0 offset returns all results
- results = atlasClientV1.searchByFullText(query, 10, 0).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1);
-
- //offset is used
- results = atlasClientV1.searchByFullText(query, 10, 1).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 0);
-
- //limit is used
- results = atlasClientV1.searchByFullText(query, 1, 0).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 1);
-
- //higher offset returns 0 results
- results = atlasClientV1.searchByFullText(query, 1, 2).getJSONArray(AtlasClient.RESULTS);
- assertEquals(results.length(), 0);
- }
-
- private void createTypes() throws Exception {
- createTypeDefinitionsV1();
-
- HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil
- .createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
-
- HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil
- .createTraitTypeDef("Classification", ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
- TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
- ImmutableList.of(classificationTraitDefinition), ImmutableList.of(dslTestTypeDefinition));
- createType(typesDef);
- }
-
- private Id createInstance() throws Exception {
- Referenceable entityInstance = new Referenceable("dsl_test_type", "Classification");
- entityInstance.set("name", randomString());
- entityInstance.set("description", randomString());
-
-
- Struct traitInstance = (Struct) entityInstance.getTrait("Classification");
- tagName = randomString();
- traitInstance.set("tag", tagName);
-
- List<String> traits = entityInstance.getTraits();
- assertEquals(traits.size(), 1);
-
- return createInstance(entityInstance);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
deleted file mode 100644
index a6a0568..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
+++ /dev/null
@@ -1,352 +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.web.resources;
-
-import com.google.common.collect.ImmutableSet;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import org.apache.atlas.AtlasClientV2;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.model.SearchFilter;
-import org.apache.atlas.model.TypeCategory;
-import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
-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.AtlasStructDef.AtlasAttributeDef;
-import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
-import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.type.AtlasTypeUtil;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.utils.AuthenticationUtil;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import java.util.Collections;
-
-import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
-import static org.apache.atlas.type.AtlasTypeUtil.createClassTypeDef;
-import static org.testng.Assert.*;
-
-/**
- * Integration test for types jersey resource.
- */
-public class TypedefsJerseyResourceIT extends BaseResourceIT {
-
- private AtlasTypesDef typeDefinitions;
-
- private AtlasClientV2 clientV2;
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
-
- typeDefinitions = createHiveTypes();
-
- if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
- clientV2 = new AtlasClientV2(atlasUrls, new String[]{"admin", "admin"});
- } else {
- clientV2 = new AtlasClientV2(atlasUrls);
- }
- }
-
- @AfterClass
- public void tearDown() throws Exception {
- emptyTypeDefs(typeDefinitions);
- }
-
- @Test
- public void testCreate() throws Exception {
- AtlasTypesDef atlasTypeDefs = clientV2.createAtlasTypeDefs(typeDefinitions);
- Assert.assertNotNull(atlasTypeDefs);
- assertFalse(atlasTypeDefs.isEmpty());
- }
-
- @Test
- public void testDuplicateCreate() throws Exception {
- AtlasEntityDef type = createClassTypeDef(randomString(),
- ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
- AtlasTypesDef typesDef = new AtlasTypesDef();
- typesDef.getEntityDefs().add(type);
-
- AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
- assertNotNull(created);
-
- try {
- created = clientV2.createAtlasTypeDefs(typesDef);
- fail("Expected 409");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
- }
- }
-
- @Test
- public void testUpdate() throws Exception {
- String entityType = randomString();
- AtlasEntityDef typeDefinition =
- createClassTypeDef(entityType, ImmutableSet.<String>of(),
- AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
-
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
- atlasTypesDef.getEntityDefs().add(typeDefinition);
-
- AtlasTypesDef createdTypeDefs = clientV2.createAtlasTypeDefs(atlasTypesDef);
- assertNotNull(createdTypeDefs);
- assertEquals(createdTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
-
- //Add attribute description
- typeDefinition = createClassTypeDef(typeDefinition.getName(),
- ImmutableSet.<String>of(),
- AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
- AtlasTypeUtil.createOptionalAttrDef("description", "string"));
-
- emptyTypeDefs(atlasTypesDef);
-
- atlasTypesDef.getEntityDefs().add(typeDefinition);
-
- AtlasTypesDef updatedTypeDefs = clientV2.updateAtlasTypeDefs(atlasTypesDef);
- assertNotNull(updatedTypeDefs);
- assertEquals(updatedTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
- assertEquals(updatedTypeDefs.getEntityDefs().get(0).getName(), atlasTypesDef.getEntityDefs().get(0).getName());
-
- MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl();
- filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY");
- AtlasTypesDef allTypeDefs = clientV2.getAllTypeDefs(new SearchFilter(filterParams));
- assertNotNull(allTypeDefs);
- Boolean entityDefFound = false;
- for (AtlasEntityDef atlasEntityDef : allTypeDefs.getEntityDefs()){
- if (atlasEntityDef.getName().equals(typeDefinition.getName())) {
- assertEquals(atlasEntityDef.getAttributeDefs().size(), 2);
- entityDefFound = true;
- break;
- }
- }
- assertTrue(entityDefFound, "Required entityDef not found.");
- }
-
- @Test(dependsOnMethods = "testCreate")
- public void testGetDefinition() throws Exception {
- if (CollectionUtils.isNotEmpty(typeDefinitions.getEnumDefs())) {
- for (AtlasEnumDef atlasEnumDef : typeDefinitions.getEnumDefs()) {
- verifyByNameAndGUID(atlasEnumDef);
- }
- }
-
- if (CollectionUtils.isNotEmpty(typeDefinitions.getStructDefs())) {
- for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
- verifyByNameAndGUID(structDef);
- }
- }
-
- if (CollectionUtils.isNotEmpty(typeDefinitions.getClassificationDefs())) {
- for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
- verifyByNameAndGUID(classificationDef);
- }
- }
-
- if (CollectionUtils.isNotEmpty(typeDefinitions.getEntityDefs())) {
- for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
- verifyByNameAndGUID(entityDef);
- }
- }
- }
-
- @Test
- public void testInvalidGets() throws Exception {
- try {
- AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
- try {
- AtlasEnumDef byGuid = clientV2.getEnumDefByGuid("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
- try {
- AtlasStructDef byName = clientV2.getStructDefByName("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
- try {
- AtlasStructDef byGuid = clientV2.getStructDefByGuid("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
- try {
- AtlasClassificationDef byName = clientV2.getClassificationDefByName("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
- try {
- AtlasClassificationDef byGuid = clientV2.getClassificationDefByGuid("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
- try {
- AtlasEntityDef byName = clientV2.getEntityDefByName("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
- try {
- AtlasEntityDef byGuid = clientV2.getEntityDefByGuid("blah");
- fail("Get for invalid name should have reported a failure");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
- "Should've returned a 404");
- }
-
-
- }
-
- @Test
- public void testListTypesByFilter() throws Exception {
- AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
- AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr);
- AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(classDefA.getName()), attr);
- AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr);
- AtlasEntityDef classDefC = AtlasTypeUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(classDefB.getName(), classDefA.getName()), attr);
-
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
- atlasTypesDef.getEntityDefs().add(classDefA);
- atlasTypesDef.getEntityDefs().add(classDefA1);
- atlasTypesDef.getEntityDefs().add(classDefB);
- atlasTypesDef.getEntityDefs().add(classDefC);
-
- AtlasTypesDef created = clientV2.createAtlasTypeDefs(atlasTypesDef);
- assertNotNull(created);
- assertEquals(created.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
-
- MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
- searchParams.add(SearchFilter.PARAM_TYPE, "CLASS");
- searchParams.add(SearchFilter.PARAM_SUPERTYPE, classDefA.getName());
- SearchFilter searchFilter = new SearchFilter(searchParams);
- AtlasTypesDef searchDefs = clientV2.getAllTypeDefs(searchFilter);
- assertNotNull(searchDefs);
- assertEquals(searchDefs.getEntityDefs().size(), 2);
-
- searchParams.add(SearchFilter.PARAM_NOT_SUPERTYPE, classDefB.getName());
- searchFilter = new SearchFilter(searchParams);
- searchDefs = clientV2.getAllTypeDefs(searchFilter);
- assertNotNull(searchDefs);
- assertEquals(searchDefs.getEntityDefs().size(), 1);
- }
-
- private AtlasTypesDef createHiveTypes() throws Exception {
- AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
-
- AtlasEntityDef databaseTypeDefinition =
- createClassTypeDef("database", ImmutableSet.<String>of(),
- AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
- AtlasTypeUtil.createRequiredAttrDef("description", "string"));
- atlasTypesDef.getEntityDefs().add(databaseTypeDefinition);
-
- AtlasEntityDef tableTypeDefinition =
- createClassTypeDef("table", ImmutableSet.<String>of(),
- AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
- AtlasTypeUtil.createRequiredAttrDef("description", "string"),
- AtlasTypeUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName("string")),
- AtlasTypeUtil.createOptionalAttrDef("created", "date"),
- AtlasTypeUtil.createOptionalAttrDef("parameters",
- DataTypes.mapTypeName("string", "string")),
- AtlasTypeUtil.createRequiredAttrDef("type", "string"),
- new AtlasAttributeDef("database", "database",
- false,
- Cardinality.SINGLE, 1, 1,
- true, true,
- Collections.<AtlasConstraintDef>emptyList()));
- atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
-
- AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil
- .createTraitTypeDef("fetl", ImmutableSet.<String>of(),
- AtlasTypeUtil.createRequiredAttrDef("level", "int"));
- atlasTypesDef.getClassificationDefs().add(fetlTypeDefinition);
-
- return atlasTypesDef;
- }
-
- private void verifyByNameAndGUID(AtlasBaseTypeDef typeDef) {
- try {
- AtlasBaseTypeDef byName = null;
- if (typeDef.getCategory() == TypeCategory.ENUM) {
- byName = clientV2.getEnumDefByName(typeDef.getName());
- } else if (typeDef.getCategory() == TypeCategory.ENTITY) {
- byName = clientV2.getEntityDefByName(typeDef.getName());
- } else if (typeDef.getCategory() == TypeCategory.CLASSIFICATION) {
- byName = clientV2.getClassificationDefByName(typeDef.getName());
- } else if (typeDef.getCategory() == TypeCategory.STRUCT) {
- byName = clientV2.getStructDefByName(typeDef.getName());
- }
- assertNotNull(byName);
- } catch (AtlasServiceException e) {
- fail("Get byName should've succeeded", e);
- }
- if (StringUtils.isNotBlank(typeDef.getGuid())) {
- try {
- AtlasBaseTypeDef byGuid = null;
- if (typeDef.getCategory() == TypeCategory.ENUM) {
- byGuid = clientV2.getEnumDefByGuid(typeDef.getGuid());
- } else if (typeDef.getCategory() == TypeCategory.ENTITY) {
- byGuid = clientV2.getEntityDefByGuid(typeDef.getGuid());
- } else if (typeDef.getCategory() == TypeCategory.CLASSIFICATION) {
- byGuid = clientV2.getClassificationDefByGuid(typeDef.getGuid());
- } else if (typeDef.getCategory() == TypeCategory.STRUCT) {
- byGuid = clientV2.getStructDefByGuid(typeDef.getGuid());
- }
- assertNotNull(byGuid);
- } catch (AtlasServiceException e) {
- fail("Get byGuid should've succeeded", e);
- }
- }
- }
-
- private void emptyTypeDefs(AtlasTypesDef def) {
- def.getEnumDefs().clear();
- def.getStructDefs().clear();
- def.getClassificationDefs().clear();
- def.getEntityDefs().clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/TypesJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/TypesJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/TypesJerseyResourceIT.java
deleted file mode 100755
index 2ef33c3..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/TypesJerseyResourceIT.java
+++ /dev/null
@@ -1,262 +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.web.resources;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.json.TypesSerialization;
-import org.apache.atlas.typesystem.json.TypesSerialization$;
-import org.apache.atlas.typesystem.types.AttributeDefinition;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.EnumTypeDefinition;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.Multiplicity;
-import org.apache.atlas.typesystem.types.StructTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.fail;
-
-/**
- * Integration test for types jersey resource.
- */
-public class TypesJerseyResourceIT extends BaseResourceIT {
-
- private List<HierarchicalTypeDefinition> typeDefinitions;
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
-
- typeDefinitions = createHiveTypes();
- }
-
- @AfterClass
- public void tearDown() throws Exception {
- typeDefinitions.clear();
- }
-
- @Test
- public void testSubmit() throws Exception {
- for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
- try{
- atlasClientV1.getType(typeDefinition.typeName);
- } catch (AtlasServiceException ase){
- String typesAsJSON = TypesSerialization.toJson(typeDefinition, false);
- System.out.println("typesAsJSON = " + typesAsJSON);
-
- JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.CREATE_TYPE, typesAsJSON);
- Assert.assertNotNull(response);
-
-
- JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES);
- assertEquals(typesAdded.length(), 1);
- assertEquals(typesAdded.getJSONObject(0).getString(NAME), typeDefinition.typeName);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));}
- }
- }
-
- @Test
- public void testDuplicateSubmit() throws Exception {
- HierarchicalTypeDefinition<ClassType> type = TypesUtil.createClassTypeDef(randomString(),
- ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
- TypesDef typesDef =
- TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
- ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(type));
- atlasClientV1.createType(typesDef);
-
- try {
- atlasClientV1.createType(typesDef);
- fail("Expected 409");
- } catch (AtlasServiceException e) {
- assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
- }
- }
-
- @Test
- public void testUpdate() throws Exception {
- HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil
- .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
- List<String> typesCreated = atlasClientV1.createType(TypesSerialization.toJson(typeDefinition, false));
- assertEquals(typesCreated.size(), 1);
- assertEquals(typesCreated.get(0), typeDefinition.typeName);
-
- //Add attribute description
- typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName,
- ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
- createOptionalAttrDef(DESCRIPTION, DataTypes.STRING_TYPE));
- TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
- ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
- ImmutableList.of(typeDefinition));
- List<String> typesUpdated = atlasClientV1.updateType(typeDef);
- assertEquals(typesUpdated.size(), 1);
- Assert.assertTrue(typesUpdated.contains(typeDefinition.typeName));
-
- TypesDef updatedTypeDef = atlasClientV1.getType(typeDefinition.typeName);
- assertNotNull(updatedTypeDef);
-
- HierarchicalTypeDefinition<ClassType> updatedType = updatedTypeDef.classTypesAsJavaList().get(0);
- assertEquals(updatedType.attributeDefinitions.length, 2);
- }
-
- @Test(dependsOnMethods = "testSubmit")
- public void testGetDefinition() throws Exception {
- for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
- System.out.println("typeName = " + typeDefinition.typeName);
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName);
-
- Assert.assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- String typesJson = response.getString(AtlasClient.DEFINITION);
- final TypesDef typesDef = TypesSerialization.fromJson(typesJson);
- List<HierarchicalTypeDefinition<ClassType>> hierarchicalTypeDefinitions = typesDef.classTypesAsJavaList();
- for (HierarchicalTypeDefinition<ClassType> classType : hierarchicalTypeDefinitions) {
- for (AttributeDefinition attrDef : classType.attributeDefinitions) {
- if (NAME.equals(attrDef.name)) {
- assertEquals(attrDef.isIndexable, true);
- assertEquals(attrDef.isUnique, true);
- }
- }
- }
- }
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testGetDefinitionForNonexistentType() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, "blah");
- }
-
- @Test(dependsOnMethods = "testSubmit")
- public void testGetTypeNames() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, (String[]) null);
- Assert.assertNotNull(response);
-
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
- Assert.assertNotNull(list);
-
- //Verify that primitive and core types are not returned
- String typesString = list.join(" ");
- Assert.assertFalse(typesString.contains(" \"__IdType\" "));
- Assert.assertFalse(typesString.contains(" \"string\" "));
- }
-
- @Test
- public void testGetTraitNames() throws Exception {
- String[] traitsAdded = addTraits();
-
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("type", DataTypes.TypeCategory.TRAIT.name());
-
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.LIST_TYPES, queryParams);
- Assert.assertNotNull(response);
-
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
- Assert.assertNotNull(list);
- Assert.assertTrue(list.length() >= traitsAdded.length);
- }
-
- @Test
- public void testListTypesByFilter() throws Exception {
- AttributeDefinition attr = TypesUtil.createOptionalAttrDef("attr", DataTypes.STRING_TYPE);
- String a = createType(TypesSerialization.toJson(
- TypesUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr), false)).get(0);
- String a1 = createType(TypesSerialization.toJson(
- TypesUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(a), attr), false)).get(0);
- String b = createType(TypesSerialization.toJson(
- TypesUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr), false)).get(0);
- String c = createType(TypesSerialization.toJson(
- TypesUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(a, b), attr), false)).get(0);
-
- List<String> results = atlasClientV1.listTypes(DataTypes.TypeCategory.CLASS, a, b);
- assertEquals(results, Arrays.asList(a1), "Results: " + results);
- }
-
- private String[] addTraits() throws Exception {
- String[] traitNames = {"class_trait", "secure_trait", "pii_trait", "ssn_trait", "salary_trait", "sox_trait",};
-
- for (String traitName : traitNames) {
- HierarchicalTypeDefinition<TraitType> traitTypeDef =
- TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
- String json = TypesSerialization$.MODULE$.toJson(traitTypeDef, true);
- createType(json);
- }
-
- return traitNames;
- }
-
- private List<HierarchicalTypeDefinition> createHiveTypes() throws Exception {
- ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>();
-
- HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil
- .createClassTypeDef("database", ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE));
- typeDefinitions.add(databaseTypeDefinition);
-
- HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil
- .createClassTypeDef("table", ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE),
- createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)),
- createOptionalAttrDef("created", DataTypes.DATE_TYPE),
- createOptionalAttrDef("parameters",
- DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE)),
- TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE),
- new AttributeDefinition("database", "database", Multiplicity.REQUIRED, false, "database"));
- typeDefinitions.add(tableTypeDefinition);
-
- HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil
- .createTraitTypeDef("fetl", ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
- typeDefinitions.add(fetlTypeDefinition);
-
- return typeDefinitions;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/security/FileAuthenticationTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/security/FileAuthenticationTest.java b/webapp/src/test/java/org/apache/atlas/web/security/FileAuthenticationTest.java
index c5cd3f6..84346ce 100644
--- a/webapp/src/test/java/org/apache/atlas/web/security/FileAuthenticationTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/security/FileAuthenticationTest.java
@@ -18,14 +18,13 @@
package org.apache.atlas.web.security;
-import java.io.File;
-import java.util.Collection;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.web.TestUtils;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
@@ -33,12 +32,15 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
-import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.util.Collection;
+
import static org.mockito.Mockito.when;
public class FileAuthenticationTest {
@@ -69,7 +71,7 @@ public class FileAuthenticationTest {
System.setProperty("atlas.conf", persistDir);
applicationContext = new ClassPathXmlApplicationContext(
- "spring-security.xml");
+ "test-spring-security.xml");
authProvider = applicationContext
.getBean(org.apache.atlas.web.security.AtlasAuthenticationProvider.class);
[12/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
ATLAS-1198: Spring Framework (v4 with Spring security) over Guice
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/35e5828f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/35e5828f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/35e5828f
Branch: refs/heads/master
Commit: 35e5828fb8649d14cfe4b1079237562f31186ad4
Parents: 35c7764
Author: apoorvnaik <an...@hortonworks.com>
Authored: Tue May 23 08:23:23 2017 -0700
Committer: apoorvnaik <an...@hortonworks.com>
Committed: Tue May 23 10:20:20 2017 -0700
----------------------------------------------------------------------
addons/falcon-bridge/pom.xml | 4 -
.../apache/atlas/falcon/hook/FalconHook.java | 8 +-
addons/hive-bridge/pom.xml | 4 -
addons/sqoop-bridge/pom.xml | 4 -
addons/storm-bridge/pom.xml | 27 -
.../atlas/authorize/AtlasAccessRequest.java | 12 +-
catalog/pom.xml | 15 -
.../java/org/apache/atlas/AtlasBaseClient.java | 46 +-
.../main/java/org/apache/atlas/AtlasClient.java | 90 +-
.../java/org/apache/atlas/AtlasClientV2.java | 32 +-
.../atlas/CreateUpdateEntitiesResult.java | 8 +-
.../java/org/apache/atlas/AtlasClientTest.java | 9 +-
common/pom.xml | 10 +-
.../org/apache/atlas/CommonConfiguration.java | 38 +
.../apache/atlas/annotation/AtlasService.java | 33 +
.../annotation/ConditionalOnAtlasProperty.java | 36 +
.../atlas/annotation/GraphTransaction.java | 28 +
.../java/org/apache/atlas/service/Services.java | 35 +-
.../atlas/utils/OnAtlasPropertyCondition.java | 53 +
distro/pom.xml | 3 +
distro/src/conf/atlas-log4j.xml | 15 +
graphdb/titan0/pom.xml | 9 +-
graphdb/titan1/pom.xml | 8 +-
intg/pom.xml | 5 +
.../java/org/apache/atlas/AtlasErrorCode.java | 2 +-
.../apache/atlas/model/legacy/EntityResult.java | 100 ++
.../apache/atlas/type/AtlasTypeRegistry.java | 11 +-
notification/pom.xml | 15 -
.../java/org/apache/atlas/hook/AtlasHook.java | 11 +-
.../apache/atlas/kafka/KafkaNotification.java | 8 +-
.../atlas/kafka/KafkaNotificationProvider.java | 43 -
.../atlas/kafka/NotificationProvider.java | 41 +
.../atlas/notification/NotificationModule.java | 37 -
pom.xml | 160 +--
repository/pom.xml | 70 +-
.../java/org/apache/atlas/GraphTransaction.java | 28 -
.../apache/atlas/GraphTransactionAdvisor.java | 63 +
.../atlas/GraphTransactionInterceptor.java | 16 +-
.../apache/atlas/RepositoryMetadataModule.java | 155 ---
.../atlas/discovery/DataSetLineageService.java | 22 +-
.../atlas/discovery/EntityDiscoveryService.java | 11 +-
.../atlas/discovery/EntityLineageService.java | 10 +-
.../graph/GraphBackedDiscoveryService.java | 29 +-
.../atlas/repository/MetadataRepository.java | 4 +-
.../repository/RepositoryConfiguration.java | 37 +
.../repository/audit/EntityAuditListener.java | 2 +
.../audit/HBaseBasedAuditRepository.java | 6 +-
.../audit/InMemoryEntityAuditRepository.java | 13 +-
.../audit/NoopEntityAuditRepository.java | 11 +-
.../AtlasAbstractFormatConverter.java | 2 +-
.../converters/AtlasEnumFormatConverter.java | 2 +-
.../converters/AtlasFormatConverters.java | 6 +-
.../converters/AtlasInstanceConverter.java | 21 +-
.../converters/AtlasObjectIdConverter.java | 3 +-
.../AtlasPrimitiveFormatConverter.java | 2 +-
.../repository/graph/AtlasGraphProvider.java | 7 +-
.../repository/graph/FullTextMapperV2.java | 20 +-
.../graph/GraphBackedMetadataRepository.java | 53 +-
.../graph/GraphBackedSearchIndexer.java | 2 +
.../graph/GraphSchemaInitializer.java | 2 +
.../graph/GraphToTypedInstanceMapper.java | 35 +-
.../repository/graph/HardDeleteHandler.java | 9 +-
.../repository/graph/SoftDeleteHandler.java | 12 +-
.../graph/TypedInstanceToGraphMapper.java | 50 +-
.../atlas/repository/impexp/ExportService.java | 9 +-
.../bootstrap/AtlasTypeDefStoreInitializer.java | 40 +-
.../store/graph/AtlasEntityStore.java | 6 -
.../store/graph/AtlasTypeDefGraphStore.java | 15 +-
.../graph/v1/AtlasEntityChangeNotifier.java | 21 +-
.../store/graph/v1/AtlasEntityDefStoreV1.java | 2 +-
.../store/graph/v1/AtlasEntityStoreV1.java | 32 +-
.../store/graph/v1/AtlasEntityStream.java | 2 +-
.../graph/v1/AtlasTypeDefGraphStoreV1.java | 16 +-
.../store/graph/v1/EntityGraphMapper.java | 32 +-
.../store/graph/v1/EntityGraphRetriever.java | 10 +-
.../store/graph/v1/HardDeleteHandlerV1.java | 7 +-
.../store/graph/v1/SoftDeleteHandlerV1.java | 9 +-
.../graph/v1/UniqAttrBasedEntityResolver.java | 9 -
.../typestore/GraphBackedTypeStore.java | 16 +-
.../typestore/StoreBackedTypeCache.java | 23 +-
.../atlas/services/DefaultMetadataService.java | 69 +-
.../apache/atlas/services/MetricsService.java | 9 +-
.../util/AtlasRepositoryConfiguration.java | 8 +-
.../org/apache/atlas/BaseRepositoryTest.java | 4 +-
.../atlas/RepositoryServiceLoadingTest.java | 2 +-
.../test/java/org/apache/atlas/TestModules.java | 231 ++++
.../java/org/apache/atlas/TestOnlyModule.java | 30 -
.../test/java/org/apache/atlas/TestUtils.java | 22 +-
.../discovery/DataSetLineageServiceTest.java | 8 +-
.../GraphBackedDiscoveryServiceTest.java | 4 +-
.../atlas/lineage/EntityLineageServiceTest.java | 8 +-
.../AbstractGremlinQueryOptimizerTest.java | 4 +-
...hBackedMetadataRepositoryDeleteTestBase.java | 32 +-
.../GraphBackedMetadataRepositoryTest.java | 8 +-
.../graph/GraphBackedSearchIndexerTest.java | 8 +-
.../atlas/repository/graph/GraphHelperTest.java | 6 +-
.../graph/GraphRepoMapperScaleTest.java | 8 +-
.../ReverseReferenceUpdateHardDeleteTest.java | 12 +-
.../ReverseReferenceUpdateSoftDeleteTest.java | 11 +-
.../graph/ReverseReferenceUpdateTestBase.java | 10 -
.../repository/impexp/ExportServiceTest.java | 34 +-
.../impexp/ImportServiceReportingTest.java | 4 +-
.../repository/impexp/ImportServiceTest.java | 4 +-
.../store/graph/AtlasEntityDefStoreV1Test.java | 8 +-
.../store/graph/AtlasTypeDefGraphStoreTest.java | 11 +-
.../graph/v1/AtlasDeleteHandlerV1Test.java | 13 +-
.../store/graph/v1/AtlasEntityStoreV1Test.java | 8 +-
.../store/graph/v1/HardDeleteHandlerV1Test.java | 9 +-
.../InverseReferenceUpdateHardDeleteV1Test.java | 10 +-
.../InverseReferenceUpdateSoftDeleteV1Test.java | 10 +-
.../graph/v1/InverseReferenceUpdateV1Test.java | 17 +-
.../store/graph/v1/SoftDeleteHandlerV1Test.java | 9 +-
.../typestore/GraphBackedTypeStoreTest.java | 7 +-
.../StoreBackedTypeCacheConfigurationTest.java | 42 -
.../typestore/StoreBackedTypeCacheTest.java | 7 +-
.../StoreBackedTypeCacheTestOnlyModule.java | 44 -
.../service/DefaultMetadataServiceTest.java | 15 +-
...StoreBackedTypeCacheMetadataServiceTest.java | 10 +-
.../services/EntityDiscoveryServiceTest.java | 3 +-
.../org/apache/atlas/query/GremlinTest.scala | 2 +-
.../org/apache/atlas/query/GremlinTest2.scala | 2 +-
.../apache/atlas/query/LineageQueryTest.scala | 2 +-
server-api/pom.xml | 58 -
.../org/apache/atlas/aspect/AtlasAspect.java | 68 --
.../apache/atlas/services/MetadataService.java | 8 +-
.../atlas/typesystem/types/TypeSystem.java | 4 +-
.../typesystem/types/TypeSystemProvider.java | 28 -
.../types/cache/DefaultTypeCache.java | 8 +-
typesystem/src/main/resources/atlas-log4j.xml | 15 +
webapp/pom.xml | 172 +--
.../src/main/java/org/apache/atlas/Atlas.java | 35 +-
.../NotificationEntityChangeListener.java | 4 +-
.../notification/NotificationHookConsumer.java | 6 +-
.../atlas/web/errors/AllExceptionMapper.java | 7 +-
.../web/errors/AtlasBaseExceptionMapper.java | 4 +-
.../web/errors/NotFoundExceptionMapper.java | 4 +-
.../atlas/web/filters/ActiveServerFilter.java | 4 +-
.../filters/AtlasAuthenticationEntryPoint.java | 21 +-
.../web/filters/AtlasAuthenticationFilter.java | 2 +
.../web/filters/AtlasAuthorizationFilter.java | 9 +-
.../web/filters/AtlasCSRFPreventionFilter.java | 32 +-
.../AtlasKnoxSSOAuthenticationFilter.java | 16 +-
.../apache/atlas/web/filters/AuditFilter.java | 8 +-
.../filters/StaleTransactionCleanupFilter.java | 15 +-
.../atlas/web/listeners/GuiceServletConfig.java | 190 ---
.../atlas/web/listeners/LoginProcessor.java | 4 +
.../atlas/web/resources/AdminResource.java | 14 +-
.../web/resources/DataSetLineageResource.java | 9 +-
.../atlas/web/resources/EntityResource.java | 22 +-
.../atlas/web/resources/EntityService.java | 3 +-
.../atlas/web/resources/LineageResource.java | 2 +
.../resources/MetadataDiscoveryResource.java | 2 +
.../atlas/web/resources/TaxonomyService.java | 5 +-
.../atlas/web/resources/TypesResource.java | 15 +-
.../apache/atlas/web/rest/DiscoveryREST.java | 2 +
.../org/apache/atlas/web/rest/EntityREST.java | 11 +-
.../org/apache/atlas/web/rest/LineageREST.java | 2 +
.../org/apache/atlas/web/rest/TypesREST.java | 4 +-
.../security/AtlasADAuthenticationProvider.java | 13 +-
.../AtlasAbstractAuthenticationProvider.java | 14 +-
.../AtlasAuthenticationFailureHandler.java | 9 +-
.../security/AtlasAuthenticationProvider.java | 34 +-
.../AtlasAuthenticationSuccessHandler.java | 9 +-
.../AtlasFileAuthenticationProvider.java | 14 +-
.../atlas/web/security/AtlasSecurityConfig.java | 169 +++
.../service/ActiveInstanceElectorModule.java | 50 -
.../service/ActiveInstanceElectorService.java | 30 +-
.../atlas/web/service/ActiveInstanceState.java | 4 +-
.../atlas/web/service/CuratorFactory.java | 4 +-
.../apache/atlas/web/service/ServiceModule.java | 41 -
.../apache/atlas/web/service/ServiceState.java | 5 +-
.../apache/atlas/web/service/UserService.java | 15 +-
.../org/apache/atlas/web/setup/AtlasSetup.java | 65 --
.../atlas/web/setup/AtlasSetupModule.java | 32 -
.../org/apache/atlas/web/setup/SetupSteps.java | 42 +-
webapp/src/main/resources/spring-security.xml | 45 +-
.../main/webapp/WEB-INF/applicationContext.xml | 9 +-
webapp/src/main/webapp/WEB-INF/web.xml | 53 +-
.../org/apache/atlas/examples/QuickStartIT.java | 2 +-
.../apache/atlas/examples/QuickStartV2IT.java | 3 +-
.../notification/EntityNotificationIT.java | 9 +-
.../NotificationHookConsumerIT.java | 13 +-
.../NotificationHookConsumerKafkaTest.java | 7 +-
.../atlas/web/adapters/TestEntitiesREST.java | 11 +-
.../atlas/web/adapters/TestEntityREST.java | 7 +-
.../web/integration/AdminJerseyResourceIT.java | 49 +
.../atlas/web/integration/BaseResourceIT.java | 669 +++++++++++
.../DataSetLineageJerseyResourceIT.java | 298 +++++
.../EntityDiscoveryJerseyResourceIT.java | 211 ++++
.../web/integration/EntityJerseyResourceIT.java | 1101 ++++++++++++++++++
.../EntityLineageJerseyResourceIT.java | 190 +++
.../integration/EntityV2JerseyResourceIT.java | 769 ++++++++++++
.../MetadataDiscoveryJerseyResourceIT.java | 267 +++++
.../integration/TypedefsJerseyResourceIT.java | 370 ++++++
.../web/integration/TypesJerseyResourceIT.java | 262 +++++
.../web/listeners/TestGuiceServletConfig.java | 82 --
.../apache/atlas/web/listeners/TestModule.java | 34 -
.../web/resources/AdminJerseyResourceIT.java | 49 -
.../atlas/web/resources/AdminResourceTest.java | 4 +-
.../atlas/web/resources/BaseResourceIT.java | 690 -----------
.../DataSetLineageJerseyResourceIT.java | 298 -----
.../EntityDiscoveryJerseyResourceIT.java | 227 ----
.../web/resources/EntityJerseyResourceIT.java | 953 ---------------
.../EntityLineageJerseyResourceIT.java | 190 ---
.../atlas/web/resources/EntityResourceTest.java | 22 +-
.../web/resources/EntityV2JerseyResourceIT.java | 779 -------------
.../MetadataDiscoveryJerseyResourceIT.java | 267 -----
.../web/resources/TypedefsJerseyResourceIT.java | 352 ------
.../web/resources/TypesJerseyResourceIT.java | 262 -----
.../web/security/FileAuthenticationTest.java | 14 +-
.../ActiveInstanceElectorServiceTest.java | 88 +-
.../service/SecureEmbeddedServerTestBase.java | 8 +-
.../apache/atlas/web/setup/SetupStepsTest.java | 31 +-
.../src/test/resources/test-spring-security.xml | 116 ++
webapp/src/test/webapp/WEB-INF/web.xml | 51 +-
215 files changed, 6363 insertions(+), 6539 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/addons/falcon-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/falcon-bridge/pom.xml b/addons/falcon-bridge/pom.xml
index aa55bd6..287b8e9 100644
--- a/addons/falcon-bridge/pom.xml
+++ b/addons/falcon-bridge/pom.xml
@@ -201,10 +201,6 @@
<version>${scala.version}</version>
</artifactItem>
<artifactItem>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- </artifactItem>
- <artifactItem>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_${scala.binary.version}</artifactId>
<version>${kafka.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
----------------------------------------------------------------------
diff --git a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
index 842b2ce..3b384f8 100644
--- a/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
+++ b/addons/falcon-bridge/src/main/java/org/apache/atlas/falcon/hook/FalconHook.java
@@ -19,15 +19,12 @@
package org.apache.atlas.falcon.hook;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
import org.apache.atlas.AtlasConstants;
import org.apache.atlas.falcon.bridge.FalconBridge;
import org.apache.atlas.falcon.event.FalconEvent;
import org.apache.atlas.falcon.publisher.FalconEventPublisher;
import org.apache.atlas.hook.AtlasHook;
-import org.apache.atlas.notification.NotificationInterface;
-import org.apache.atlas.notification.NotificationModule;
+import org.apache.atlas.kafka.NotificationProvider;
import org.apache.atlas.notification.hook.HookNotification;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.falcon.entity.store.ConfigurationStore;
@@ -112,8 +109,7 @@ public class FalconHook extends AtlasHook implements FalconEventPublisher {
STORE = ConfigurationStore.get();
- Injector injector = Guice.createInjector(new NotificationModule());
- notifInterface = injector.getInstance(NotificationInterface.class);
+ notificationInterface = NotificationProvider.get();
} catch (Exception e) {
LOG.error("Caught exception initializing the falcon hook.", e);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/addons/hive-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/hive-bridge/pom.xml b/addons/hive-bridge/pom.xml
index c8dee7c..983a04f 100755
--- a/addons/hive-bridge/pom.xml
+++ b/addons/hive-bridge/pom.xml
@@ -249,10 +249,6 @@
<version>${scala.version}</version>
</artifactItem>
<artifactItem>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- </artifactItem>
- <artifactItem>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_${scala.binary.version}</artifactId>
<version>${kafka.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/addons/sqoop-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/sqoop-bridge/pom.xml b/addons/sqoop-bridge/pom.xml
index 805d40d..d52167b 100644
--- a/addons/sqoop-bridge/pom.xml
+++ b/addons/sqoop-bridge/pom.xml
@@ -261,10 +261,6 @@
<version>${scala.version}</version>
</artifactItem>
<artifactItem>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- </artifactItem>
- <artifactItem>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_${scala.binary.version}</artifactId>
<version>${kafka.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/addons/storm-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/addons/storm-bridge/pom.xml b/addons/storm-bridge/pom.xml
index 527fe32..5fb1be0 100644
--- a/addons/storm-bridge/pom.xml
+++ b/addons/storm-bridge/pom.xml
@@ -35,17 +35,6 @@
</properties>
<dependencies>
- <!-- Logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
-
<!-- apache atlas core dependencies -->
<dependency>
<groupId>org.apache.atlas</groupId>
@@ -231,22 +220,6 @@
<version>${scala.version}</version>
</artifactItem>
<artifactItem>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
- </artifactItem>
- <artifactItem>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- </artifactItem>
- <artifactItem>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-servlet</artifactId>
- </artifactItem>
- <artifactItem>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-throwingproviders</artifactId>
- </artifactItem>
- <artifactItem>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_${scala.binary.version}</artifactId>
<version>${kafka.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/authorization/src/main/java/org/apache/atlas/authorize/AtlasAccessRequest.java
----------------------------------------------------------------------
diff --git a/authorization/src/main/java/org/apache/atlas/authorize/AtlasAccessRequest.java b/authorization/src/main/java/org/apache/atlas/authorize/AtlasAccessRequest.java
index 9b405cc..7022081 100644
--- a/authorization/src/main/java/org/apache/atlas/authorize/AtlasAccessRequest.java
+++ b/authorization/src/main/java/org/apache/atlas/authorize/AtlasAccessRequest.java
@@ -17,15 +17,14 @@
*/
package org.apache.atlas.authorize;
-import java.util.Date;
-import java.util.Set;
-
-import javax.servlet.http.HttpServletRequest;
-
import org.apache.atlas.authorize.simple.AtlasAuthorizationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
+import java.util.Set;
+
public class AtlasAccessRequest {
private static Logger LOG = LoggerFactory.getLogger(AtlasAccessRequest.class);
@@ -39,7 +38,8 @@ public class AtlasAccessRequest {
private String clientIPAddress = null;
public AtlasAccessRequest(HttpServletRequest request, String user, Set<String> userGroups) {
- this(AtlasAuthorizationUtils.getAtlasResourceType(request.getServletPath()), "*", AtlasAuthorizationUtils
+ // Spring Security 4 Change => request.getServletPath() -> request.getPathInfo()
+ this(AtlasAuthorizationUtils.getAtlasResourceType(request.getPathInfo()), "*", AtlasAuthorizationUtils
.getAtlasAction(request.getMethod()), user, userGroups,AtlasAuthorizationUtils.getRequestIpAddress(request));
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/catalog/pom.xml
----------------------------------------------------------------------
diff --git a/catalog/pom.xml b/catalog/pom.xml
index 5f7bb8e..2828bed 100755
--- a/catalog/pom.xml
+++ b/catalog/pom.xml
@@ -114,21 +114,6 @@
</dependency>
<dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
- </dependency>
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-throwingproviders</artifactId>
- </dependency>
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- </dependency>
-
- <dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
index 3bdddd9..98da51e 100644
--- a/client/src/main/java/org/apache/atlas/AtlasBaseClient.java
+++ b/client/src/main/java/org/apache/atlas/AtlasBaseClient.java
@@ -17,19 +17,16 @@
*/
package org.apache.atlas;
-import static org.apache.atlas.security.SecurityProperties.TLS_ENABLED;
-
-import java.io.IOException;
-import java.net.ConnectException;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.HttpMethod;
-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 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;
@@ -41,16 +38,17 @@ import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-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 javax.ws.rs.HttpMethod;
+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/";
@@ -410,7 +408,7 @@ public abstract class AtlasBaseClient {
for (int i = 0; i < getNumberOfRetries(); i++) {
WebResource resource = resourceCreator.createResource();
try {
- LOG.debug("Using resource {} for {} times", resource.getURI(), i);
+ LOG.debug("Using resource {} for {} times", resource.getURI(), i + 1);
return callAPIWithResource(api, resource, requestObject, JSONObject.class);
} catch (ClientHandlerException che) {
if (i == (getNumberOfRetries() - 1)) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
index f503ade..ec482da 100755
--- a/client/src/main/java/org/apache/atlas/AtlasClient.java
+++ b/client/src/main/java/org/apache/atlas/AtlasClient.java
@@ -20,9 +20,8 @@ package org.apache.atlas;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
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;
@@ -36,10 +35,6 @@ 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.jackson.annotate.JsonAutoDetect;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -49,18 +44,10 @@ import org.slf4j.LoggerFactory;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-
-import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
-import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
/**
* Client for metadata.
@@ -255,76 +242,6 @@ public class AtlasClient extends AtlasBaseClient {
}
}
- @JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
- @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
- @JsonIgnoreProperties(ignoreUnknown=true)
- @XmlRootElement
- @XmlAccessorType(XmlAccessType.PROPERTY)
- public static class EntityResult {
- private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
-
- public static final String OP_CREATED = "created";
- public static final String OP_UPDATED = "updated";
- public static final String OP_DELETED = "deleted";
-
- Map<String, List<String>> entities = new HashMap<>();
-
- public EntityResult() {
- //For gson
- }
-
- public EntityResult(List<String> created, List<String> updated, List<String> deleted) {
- set(OP_CREATED, created);
- set(OP_UPDATED, updated);
- set(OP_DELETED, deleted);
- }
-
- public void set(String type, List<String> list) {
- if (list != null && list.size() > 0) {
- entities.put(type, list);
- }
- }
-
- private List<String> get(String type) {
- List<String> list = entities.get(type);
- if (list == null) {
- list = new ArrayList<>();
- }
- return list;
- }
-
- public Map<String, List<String>> getEntities(){
- return entities;
- }
-
- public void setEntities(Map<String, List<String>> entities){
- this.entities = entities;
- }
-
- @JsonIgnore
- public List<String> getCreatedEntities() {
- return get(OP_CREATED);
- }
-
- @JsonIgnore
- public List<String> getUpdateEntities() {
- return get(OP_UPDATED);
- }
-
-
- @JsonIgnore
- public List<String> getDeletedEntities() {
- return get(OP_DELETED);
- }
-
- @Override
- public String toString() { return gson.toJson(this); }
-
- public static EntityResult fromString(String json) throws AtlasServiceException {
- return gson.fromJson(json, EntityResult.class);
- }
- }
-
/**
* Register the given type(meta model)
* @param typeAsJson type definition a jaon
@@ -470,11 +387,6 @@ public class AtlasClient extends AtlasBaseClient {
JSONObject response = callAPIWithBodyAndParams(API.GET_TYPE, null, typeName);
String typeJson = response.getString(DEFINITION);
return TypesSerialization.fromJson(typeJson);
- } catch (AtlasServiceException e) {
- if (Response.Status.NOT_FOUND.equals(e.getStatus())) {
- return null;
- }
- throw e;
} catch (JSONException e) {
throw new AtlasServiceException(e);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
index 10638ad..6141342 100644
--- a/client/src/main/java/org/apache/atlas/AtlasClientV2.java
+++ b/client/src/main/java/org/apache/atlas/AtlasClientV2.java
@@ -24,7 +24,6 @@ import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.discovery.AtlasSearchResult;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
-import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.EntityMutationResponse;
@@ -55,9 +54,14 @@ 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);
@@ -131,6 +135,24 @@ public class AtlasClientV2 extends AtlasBaseClient {
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);
}
@@ -389,13 +411,13 @@ public class AtlasClientV2 extends AtlasBaseClient {
}
private <T> String getAtlasPath(Class<T> typeDefClass) {
- if (typeDefClass.isAssignableFrom(AtlasEnumDef.class)) {
+ if (AtlasEnumDef.class.isAssignableFrom(typeDefClass)) {
return "enumdef";
- } else if (typeDefClass.isAssignableFrom(AtlasEntityDef.class)) {
+ } else if (AtlasEntityDef.class.isAssignableFrom(typeDefClass)) {
return "entitydef";
- } else if (typeDefClass.isAssignableFrom(AtlasClassificationDef.class)) {
+ } else if (AtlasClassificationDef.class.isAssignableFrom(typeDefClass)) {
return "classificationdef";
- } else if (typeDefClass.isAssignableFrom(AtlasStructDef.class)) {
+ } else if (AtlasStructDef.class.isAssignableFrom(typeDefClass)) {
return "structdef";
}
// Code should never reach this point
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
index 3f8760f..5e6d6db 100644
--- a/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
+++ b/client/src/main/java/org/apache/atlas/CreateUpdateEntitiesResult.java
@@ -17,13 +17,13 @@
*/
package org.apache.atlas;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.atlas.AtlasClient.EntityResult;
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.
*/
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
index 56c4ae6..0c78916 100644
--- a/client/src/test/java/org/apache/atlas/AtlasClientTest.java
+++ b/client/src/test/java/org/apache/atlas/AtlasClientTest.java
@@ -21,7 +21,7 @@ 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;
@@ -33,15 +33,14 @@ 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 javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriBuilder;
-
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
@@ -94,7 +93,7 @@ public class AtlasClientTest {
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
- JSONObject jsonResponse = new JSONObject(new AtlasClient.EntityResult(Arrays.asList("id"), null, null).toString());
+ 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);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/common/pom.xml
----------------------------------------------------------------------
diff --git a/common/pom.xml b/common/pom.xml
index 48df41f..bcbb5c5 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -36,8 +36,8 @@
</dependency>
<dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
</dependency>
<dependency>
@@ -65,6 +65,12 @@
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>com.google.guava</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/common/src/main/java/org/apache/atlas/CommonConfiguration.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/CommonConfiguration.java b/common/src/main/java/org/apache/atlas/CommonConfiguration.java
new file mode 100644
index 0000000..8ef9f8b
--- /dev/null
+++ b/common/src/main/java/org/apache/atlas/CommonConfiguration.java
@@ -0,0 +1,38 @@
+/**
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class CommonConfiguration {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CommonConfiguration.class);
+
+ @Bean
+ public org.apache.commons.configuration.Configuration getAtlasConfig() throws AtlasException {
+ try {
+ return ApplicationProperties.get();
+ } catch (AtlasException e) {
+ LOGGER.warn("AtlasConfig init failed", e);
+ throw e;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/common/src/main/java/org/apache/atlas/annotation/AtlasService.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/annotation/AtlasService.java b/common/src/main/java/org/apache/atlas/annotation/AtlasService.java
new file mode 100644
index 0000000..fe34027
--- /dev/null
+++ b/common/src/main/java/org/apache/atlas/annotation/AtlasService.java
@@ -0,0 +1,33 @@
+/**
+ * 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.annotation;
+
+import org.springframework.stereotype.Service;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Service
+@Inherited
+public @interface AtlasService {
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/common/src/main/java/org/apache/atlas/annotation/ConditionalOnAtlasProperty.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/annotation/ConditionalOnAtlasProperty.java b/common/src/main/java/org/apache/atlas/annotation/ConditionalOnAtlasProperty.java
new file mode 100644
index 0000000..427e3a8
--- /dev/null
+++ b/common/src/main/java/org/apache/atlas/annotation/ConditionalOnAtlasProperty.java
@@ -0,0 +1,36 @@
+/**
+ * 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.annotation;
+
+import org.apache.atlas.utils.OnAtlasPropertyCondition;
+import org.springframework.context.annotation.Conditional;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ ElementType.TYPE, ElementType.METHOD })
+@Retention(RetentionPolicy.RUNTIME)
+@Conditional(OnAtlasPropertyCondition.class)
+public @interface ConditionalOnAtlasProperty {
+ // Configured atlas property
+ String property();
+ // The default interface implementation should declare this as true
+ boolean isDefault() default false;
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/common/src/main/java/org/apache/atlas/annotation/GraphTransaction.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/annotation/GraphTransaction.java b/common/src/main/java/org/apache/atlas/annotation/GraphTransaction.java
new file mode 100644
index 0000000..7120166
--- /dev/null
+++ b/common/src/main/java/org/apache/atlas/annotation/GraphTransaction.java
@@ -0,0 +1,28 @@
+/*
+ * 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.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface GraphTransaction {
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/common/src/main/java/org/apache/atlas/service/Services.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/service/Services.java b/common/src/main/java/org/apache/atlas/service/Services.java
index 588dd8e..6f880e4 100644
--- a/common/src/main/java/org/apache/atlas/service/Services.java
+++ b/common/src/main/java/org/apache/atlas/service/Services.java
@@ -17,38 +17,49 @@
*/
package org.apache.atlas.service;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import org.apache.atlas.annotation.AtlasService;
+import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Profile;
-import java.util.Set;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import java.util.List;
/**
* Utility for starting and stopping all services.
*/
-@Singleton
+@AtlasService
+@Profile("!test")
public class Services {
public static final Logger LOG = LoggerFactory.getLogger(Services.class);
- private final Set<Service> services;
+ private final List<Service> services;
+ private final Configuration configuration;
@Inject
- public Services(Set<Service> services) {
+ public Services(List<Service> services, Configuration configuration) {
this.services = services;
+ this.configuration = configuration;
}
+ @PostConstruct
public void start() {
- try {
- for (Service service : services) {
- LOG.info("Starting service {}", service.getClass().getName());
- service.start();
+ if (configuration.getBoolean("atlas.services.enabled", true)) {
+ try {
+ for (Service service : services) {
+ LOG.info("Starting service {}", service.getClass().getName());
+ service.start();
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
- } catch (Exception e) {
- throw new RuntimeException(e);
}
}
+ @PreDestroy
public void stop() {
for (Service service : services) {
LOG.info("Stopping service {}", service.getClass().getName());
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/common/src/main/java/org/apache/atlas/utils/OnAtlasPropertyCondition.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/atlas/utils/OnAtlasPropertyCondition.java b/common/src/main/java/org/apache/atlas/utils/OnAtlasPropertyCondition.java
new file mode 100644
index 0000000..ece6e37
--- /dev/null
+++ b/common/src/main/java/org/apache/atlas/utils/OnAtlasPropertyCondition.java
@@ -0,0 +1,53 @@
+/**
+ * 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.utils;
+
+import org.apache.atlas.ApplicationProperties;
+import org.apache.atlas.AtlasException;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+import org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor;
+
+public class OnAtlasPropertyCondition implements Condition {
+ private final Logger LOG = LoggerFactory.getLogger(OnAtlasPropertyCondition.class);
+
+ @Override
+ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ boolean matches = false;
+ String propertyName = (String) metadata.getAnnotationAttributes(ConditionalOnAtlasProperty.class.getName()).get("property");
+ boolean isDefault = (Boolean) metadata.getAnnotationAttributes(ConditionalOnAtlasProperty.class.getName()).get("isDefault");
+ String className = ((AnnotationMetadataReadingVisitor) metadata).getClassName();
+
+ try {
+ Configuration configuration = ApplicationProperties.get();
+ String configuredProperty = configuration.getString(propertyName);
+ if (StringUtils.isNotEmpty(configuredProperty)) {
+ matches = configuredProperty.equals(className);
+ } else if (isDefault) matches = true;
+ } catch (AtlasException e) {
+ LOG.error("Unable to load atlas properties. Dependent bean configuration may fail");
+ }
+ return matches;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/distro/pom.xml
----------------------------------------------------------------------
diff --git a/distro/pom.xml b/distro/pom.xml
index f0962b6..3ffaee9 100644
--- a/distro/pom.xml
+++ b/distro/pom.xml
@@ -126,6 +126,9 @@ atlas.graph.index.search.solr.zookeeper-session-timeout=60000
<titan.storage.backend>berkeleyje</titan.storage.backend>
<titan.storage.properties>#Berkeley
atlas.graph.storage.directory=${sys:atlas.home}/data/berkley
+atlas.graph.storage.lock.clean-expired=true
+atlas.graph.storage.lock.expiry-time=500
+atlas.graph.storage.lock.wait-time=300
</titan.storage.properties>
<titan.index.backend>elasticsearch</titan.index.backend>
<titan.index.properties>#ElasticSearch
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/distro/src/conf/atlas-log4j.xml
----------------------------------------------------------------------
diff --git a/distro/src/conf/atlas-log4j.xml b/distro/src/conf/atlas-log4j.xml
index a79b722..e6c0d9f 100755
--- a/distro/src/conf/atlas-log4j.xml
+++ b/distro/src/conf/atlas-log4j.xml
@@ -69,6 +69,21 @@
<appender-ref ref="FILE"/>
</logger>
+ <logger name="org.springframework" additivity="false">
+ <level value="warn"/>
+ <appender-ref ref="console"/>
+ </logger>
+
+ <logger name="org.eclipse" additivity="false">
+ <level value="warn"/>
+ <appender-ref ref="console"/>
+ </logger>
+
+ <logger name="com.sun.jersey" additivity="false">
+ <level value="warn"/>
+ <appender-ref ref="console"/>
+ </logger>
+
<!-- to avoid logs - The configuration log.flush.interval.messages = 1 was supplied but isn't a known config -->
<logger name="org.apache.kafka.common.config.AbstractConfig" additivity="false">
<level value="error"/>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/graphdb/titan0/pom.xml
----------------------------------------------------------------------
diff --git a/graphdb/titan0/pom.xml b/graphdb/titan0/pom.xml
index 71f2832..ceda1bb 100644
--- a/graphdb/titan0/pom.xml
+++ b/graphdb/titan0/pom.xml
@@ -51,7 +51,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
- <skip>false</skip>
+ <skip>${skipUTs}</skip>
</configuration>
</plugin>
</plugins>
@@ -81,13 +81,6 @@
<version>${guava.version}</version>
</dependency>
-
- <dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
- <scope>provided</scope>
- </dependency>
-
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/graphdb/titan1/pom.xml
----------------------------------------------------------------------
diff --git a/graphdb/titan1/pom.xml b/graphdb/titan1/pom.xml
index 5611193..fc0b2f6 100644
--- a/graphdb/titan1/pom.xml
+++ b/graphdb/titan1/pom.xml
@@ -71,7 +71,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
- <skip>false</skip>
+ <skip>${skipUTs}</skip>
</configuration>
</plugin>
<plugin>
@@ -106,12 +106,6 @@
</dependency>
<dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<scope>provided</scope>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/intg/pom.xml
----------------------------------------------------------------------
diff --git a/intg/pom.xml b/intg/pom.xml
index 7f3ab12..2a06ea9 100644
--- a/intg/pom.xml
+++ b/intg/pom.xml
@@ -67,6 +67,11 @@
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
index 298df6b..d723b2a 100644
--- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
+++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
@@ -96,7 +96,7 @@ public enum AtlasErrorCode {
DISCOVERY_QUERY_FAILED(500, "ATLAS-500-00-004", "Discovery query failed {0}"),
FAILED_TO_OBTAIN_TYPE_UPDATE_LOCK(500, "ATLAS-500-00-005", "Failed to get the lock; another type update might be in progress. Please try again"),
FAILED_TO_OBTAIN_IMPORT_EXPORT_LOCK(500, "ATLAS-500-00-006", "Another import or export is in progress. Please try again"),
- NOTIFICATION_FAILED(500, "ATLAS-500-00-007", "Failed to notify for change {0}"),
+ NOTIFICATION_FAILED(500, "ATLAS-500-00-007", "Failed to notify {0} for change {1}"),
FAILED_TO_OBTAIN_GREMLIN_SCRIPT_ENGINE(500, "ATLAS-500-00-008", "Failed to obtain gremlin script engine: {0}"),
JSON_ERROR_OBJECT_MAPPER_NULL_RETURNED(500, "ATLAS-500-00-009", "ObjectMapper.readValue returned NULL for class: {0}"),
GREMLIN_SCRIPT_EXECUTION_FAILED(500, "ATLAS-500-00-00A", "Gremlin script execution failed: {0}"),
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/intg/src/main/java/org/apache/atlas/model/legacy/EntityResult.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/legacy/EntityResult.java b/intg/src/main/java/org/apache/atlas/model/legacy/EntityResult.java
new file mode 100644
index 0000000..e6cef97
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/model/legacy/EntityResult.java
@@ -0,0 +1,100 @@
+/**
+ * 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.model.legacy;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.NONE;
+import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONLY;
+
+@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
+@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@JsonIgnoreProperties(ignoreUnknown=true)
+public class EntityResult {
+ private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ public static final String OP_CREATED = "created";
+ public static final String OP_UPDATED = "updated";
+ public static final String OP_DELETED = "deleted";
+
+ Map<String, List<String>> entities = new HashMap<>();
+
+ public EntityResult() {
+ //For gson
+ }
+
+ public EntityResult(List<String> created, List<String> updated, List<String> deleted) {
+ set(OP_CREATED, created);
+ set(OP_UPDATED, updated);
+ set(OP_DELETED, deleted);
+ }
+
+ public void set(String type, List<String> list) {
+ if (list != null && list.size() > 0) {
+ entities.put(type, list);
+ }
+ }
+
+ private List<String> get(String type) {
+ List<String> list = entities.get(type);
+ if (list == null) {
+ list = new ArrayList<>();
+ }
+ return list;
+ }
+
+ public Map<String, List<String>> getEntities(){
+ return entities;
+ }
+
+ public void setEntities(Map<String, List<String>> entities){
+ this.entities = entities;
+ }
+
+ @JsonIgnore
+ public List<String> getCreatedEntities() {
+ return get(OP_CREATED);
+ }
+
+ @JsonIgnore
+ public List<String> getUpdateEntities() {
+ return get(OP_UPDATED);
+ }
+
+ @JsonIgnore
+ public List<String> getDeletedEntities() {
+ return get(OP_DELETED);
+ }
+
+ @Override
+ public String toString() { return gson.toJson(this); }
+
+ public static EntityResult fromString(String json) {
+ return gson.fromJson(json, EntityResult.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java b/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
index 29ea603..1b3526b 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasTypeRegistry.java
@@ -17,8 +17,6 @@
*/
package org.apache.atlas.type;
-import com.sun.jersey.spi.resource.Singleton;
-
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
@@ -31,7 +29,9 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -41,16 +41,13 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_KEY_VAL_SEP;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_PREFIX;
-import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_SUFFIX;
+import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*;
/**
* registry for all types defined in Atlas.
*/
@Singleton
+@Component
public class AtlasTypeRegistry {
private static final Logger LOG = LoggerFactory.getLogger(AtlasStructType.class);
private static final int DEFAULT_LOCK_MAX_WAIT_TIME_IN_SECONDS = 15;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/notification/pom.xml
----------------------------------------------------------------------
diff --git a/notification/pom.xml b/notification/pom.xml
index c4a1115..daa5d11 100644
--- a/notification/pom.xml
+++ b/notification/pom.xml
@@ -61,21 +61,6 @@
</dependency>
<dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/notification/src/main/java/org/apache/atlas/hook/AtlasHook.java
----------------------------------------------------------------------
diff --git a/notification/src/main/java/org/apache/atlas/hook/AtlasHook.java b/notification/src/main/java/org/apache/atlas/hook/AtlasHook.java
index 65b88e9..a8609e6 100644
--- a/notification/src/main/java/org/apache/atlas/hook/AtlasHook.java
+++ b/notification/src/main/java/org/apache/atlas/hook/AtlasHook.java
@@ -19,12 +19,10 @@
package org.apache.atlas.hook;
import com.google.common.annotations.VisibleForTesting;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
import org.apache.atlas.ApplicationProperties;
+import org.apache.atlas.kafka.NotificationProvider;
import org.apache.atlas.notification.NotificationException;
import org.apache.atlas.notification.NotificationInterface;
-import org.apache.atlas.notification.NotificationModule;
import org.apache.atlas.notification.hook.HookNotification;
import org.apache.atlas.security.InMemoryJAASConfiguration;
import org.apache.atlas.typesystem.Referenceable;
@@ -51,7 +49,7 @@ public abstract class AtlasHook {
protected static Configuration atlasProperties;
- protected static NotificationInterface notifInterface;
+ protected static NotificationInterface notificationInterface;
private static boolean logFailedMessages;
private static FailedMessagesLogger failedMessagesLogger;
@@ -86,8 +84,7 @@ public abstract class AtlasHook {
}
notificationRetryInterval = atlasProperties.getInt(ATLAS_NOTIFICATION_RETRY_INTERVAL, 1000);
- Injector injector = Guice.createInjector(new NotificationModule());
- notifInterface = injector.getInstance(NotificationInterface.class);
+ notificationInterface = NotificationProvider.get();
LOG.info("Created Atlas Hook");
}
@@ -118,7 +115,7 @@ public abstract class AtlasHook {
* @param maxRetries maximum number of retries while sending message to messaging system
*/
public static void notifyEntities(List<HookNotification.HookNotificationMessage> messages, int maxRetries) {
- notifyEntitiesInternal(messages, maxRetries, notifInterface, logFailedMessages, failedMessagesLogger);
+ notifyEntitiesInternal(messages, maxRetries, notificationInterface, logFailedMessages, failedMessagesLogger);
}
@VisibleForTesting
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/notification/src/main/java/org/apache/atlas/kafka/KafkaNotification.java
----------------------------------------------------------------------
diff --git a/notification/src/main/java/org/apache/atlas/kafka/KafkaNotification.java b/notification/src/main/java/org/apache/atlas/kafka/KafkaNotification.java
index 77c1711..8bd31fd 100644
--- a/notification/src/main/java/org/apache/atlas/kafka/KafkaNotification.java
+++ b/notification/src/main/java/org/apache/atlas/kafka/KafkaNotification.java
@@ -18,7 +18,6 @@
package org.apache.atlas.kafka;
import com.google.common.annotations.VisibleForTesting;
-import com.google.inject.Singleton;
import kafka.consumer.Consumer;
import kafka.consumer.KafkaStream;
import kafka.javaapi.consumer.ConsumerConnector;
@@ -46,8 +45,11 @@ import org.apache.zookeeper.server.ServerCnxnFactory;
import org.apache.zookeeper.server.ZooKeeperServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
import scala.Option;
+import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -64,7 +66,8 @@ import java.util.concurrent.Future;
/**
* Kafka specific access point to the Atlas notification framework.
*/
-@Singleton
+@Component
+@Order(3)
public class KafkaNotification extends AbstractNotification implements Service {
public static final Logger LOG = LoggerFactory.getLogger(KafkaNotification.class);
@@ -105,6 +108,7 @@ public class KafkaNotification extends AbstractNotification implements Service {
*
* @throws AtlasException if the notification interface can not be created
*/
+ @Inject
public KafkaNotification(Configuration applicationProperties) throws AtlasException {
super(applicationProperties);
Configuration subsetConfiguration =
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/notification/src/main/java/org/apache/atlas/kafka/KafkaNotificationProvider.java
----------------------------------------------------------------------
diff --git a/notification/src/main/java/org/apache/atlas/kafka/KafkaNotificationProvider.java b/notification/src/main/java/org/apache/atlas/kafka/KafkaNotificationProvider.java
deleted file mode 100644
index fd0e518..0000000
--- a/notification/src/main/java/org/apache/atlas/kafka/KafkaNotificationProvider.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.kafka;
-
-import com.google.inject.Provider;
-import com.google.inject.Provides;
-import com.google.inject.Singleton;
-import org.apache.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasException;
-import org.apache.commons.configuration.Configuration;
-
-/**
- * Provider class that provides KafkaNotification for Guice.
- */
-public class KafkaNotificationProvider implements Provider<KafkaNotification> {
-
- @Override
- @Provides
- @Singleton
- public KafkaNotification get() {
- try {
- Configuration applicationProperties = ApplicationProperties.get();
- return new KafkaNotification(applicationProperties);
- } catch(AtlasException e) {
- throw new RuntimeException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/notification/src/main/java/org/apache/atlas/kafka/NotificationProvider.java
----------------------------------------------------------------------
diff --git a/notification/src/main/java/org/apache/atlas/kafka/NotificationProvider.java b/notification/src/main/java/org/apache/atlas/kafka/NotificationProvider.java
new file mode 100644
index 0000000..2dd970e
--- /dev/null
+++ b/notification/src/main/java/org/apache/atlas/kafka/NotificationProvider.java
@@ -0,0 +1,41 @@
+/**
+ * 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.kafka;
+
+import org.apache.atlas.ApplicationProperties;
+import org.apache.atlas.AtlasException;
+import org.apache.commons.configuration.Configuration;
+
+/**
+ * Provider class for Notification interfaces
+ */
+public class NotificationProvider {
+ private static KafkaNotification kafka;
+
+ public static KafkaNotification get() {
+ if (kafka == null) {
+ try {
+ Configuration applicationProperties = ApplicationProperties.get();
+ kafka = new KafkaNotification(applicationProperties);
+ } catch (AtlasException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return kafka;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/notification/src/main/java/org/apache/atlas/notification/NotificationModule.java
----------------------------------------------------------------------
diff --git a/notification/src/main/java/org/apache/atlas/notification/NotificationModule.java b/notification/src/main/java/org/apache/atlas/notification/NotificationModule.java
deleted file mode 100644
index 44d08d3..0000000
--- a/notification/src/main/java/org/apache/atlas/notification/NotificationModule.java
+++ /dev/null
@@ -1,37 +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.notification;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Singleton;
-import org.apache.atlas.kafka.KafkaNotification;
-import org.apache.atlas.kafka.KafkaNotificationProvider;
-
-/**
- * Notification module for Guice.
- *
- * NOTE: This module is loaded by hook clients like hive hook etc. Don't add any server specific bindings here.
- */
-public class NotificationModule extends AbstractModule {
-
- @Override
- protected void configure() {
- bind(NotificationInterface.class).to(KafkaNotification.class).in(Singleton.class);
- bind(KafkaNotification.class).toProvider(KafkaNotificationProvider.class).in(Singleton.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index cc8c94f..a93b8ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -496,9 +496,9 @@
<gson.version>2.5</gson.version>
<fastutil.version>6.5.16</fastutil.version>
<guice.version>4.1.0</guice.version>
- <spring.version>3.1.3.RELEASE</spring.version>
- <spring.security.version>3.1.3.RELEASE</spring.security.version>
- <spring-ldap-core.version>1.3.1.RELEASE</spring-ldap-core.version>
+ <spring.version>4.3.8.RELEASE</spring.version>
+ <spring.security.version>4.2.2.RELEASE</spring.security.version>
+ <spring-ldap-core.version>2.3.1.RELEASE</spring-ldap-core.version>
<javax.servlet.version>3.1.0</javax.servlet.version>
<guava.version>19.0</guava.version>
@@ -535,21 +535,9 @@
<atlas.surefire.options></atlas.surefire.options>
<aspectj.runtime.version>1.8.7</aspectj.runtime.version>
- <aspectj.skip>true</aspectj.skip>
</properties>
<profiles>
- <!-- Turn on this profile to instrument atlas server to collect performance metrics -->
- <profile>
- <id>perf</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <properties>
- <aspectj.skip>false</aspectj.skip>
- </properties>
- </profile>
-
<!-- Turning on this profile affects only tests and does not affect packaging -->
<profile>
<id>distributed</id>
@@ -687,18 +675,6 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
- <!-- AOP dependencies. -->
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>${aspectj.runtime.version}</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjtools</artifactId>
- <version>${aspectj.runtime.version}</version>
- </dependency>
-
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
@@ -916,43 +892,13 @@
<version>${commons-collections.version}</version>
</dependency>
- <!-- utilities -->
- <dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
- <version>${guice.version}</version>
- <exclusions>
- <exclusion>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-throwingproviders</artifactId>
- <version>${guice.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- <version>${guice.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-servlet</artifactId>
- <version>${guice.version}</version>
- </dependency>
-
+ <!--Javax inject-->
<dependency>
- <groupId>com.sun.jersey.contribs</groupId>
- <artifactId>jersey-guice</artifactId>
- <version>1.18.3</version>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>${javax-inject.version}</version>
</dependency>
-
+ <!-- utilities -->
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
@@ -998,6 +944,12 @@
</dependency>
<dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ <version>${jersey.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
@@ -1104,6 +1056,12 @@
<dependency>
<groupId>com.thinkaurelius.titan</groupId>
+ <artifactId>titan-lucene</artifactId>
+ <version>${titan.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-hbase</artifactId>
<version>${titan.version}</version>
</dependency>
@@ -1203,6 +1161,73 @@
<version>${solr.version}</version>
</dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>${javax.servlet.version}</version>
+ </dependency>
+
+ <!-- Spring -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
+ <version>${spring.security.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-web</artifactId>
+ <version>${spring.security.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-config</artifactId>
+ <version>${spring.security.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-ldap</artifactId>
+ <version>${spring.security.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.ldap</groupId>
+ <artifactId>spring-ldap-core</artifactId>
+ <version>${spring-ldap-core.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
<!-- atlas modules -->
<dependency>
<groupId>org.apache.atlas</groupId>
@@ -1603,6 +1628,11 @@
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2.2</version>
+ </dependency>
</dependencies>
<build>
@@ -1747,12 +1777,6 @@
</plugin>
<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>aspectj-maven-plugin</artifactId>
- <version>1.8</version>
- </plugin>
-
- <plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>2.8.0</version>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/pom.xml
----------------------------------------------------------------------
diff --git a/repository/pom.xml b/repository/pom.xml
index 54c779f..2573198 100755
--- a/repository/pom.xml
+++ b/repository/pom.xml
@@ -76,21 +76,6 @@
</dependency>
<dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
- </dependency>
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-throwingproviders</artifactId>
- </dependency>
-
- <dependency>
- <groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-multibindings</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
</dependency>
@@ -168,6 +153,20 @@
<artifactId>atlas-hbase-server-shaded</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-multibindings</artifactId>
+ <version>4.1.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -235,47 +234,6 @@
</properties>
</configuration>
</plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>aspectj-maven-plugin</artifactId>
- <configuration>
- <complianceLevel>1.7</complianceLevel>
- <includes>
- <include>**/*.java</include>
- <include>**/*.aj</include>
- </includes>
- <XaddSerialVersionUID>true</XaddSerialVersionUID>
- <showWeaveInfo>true</showWeaveInfo>
- <aspectLibraries>
- <aspectLibrary>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-server-api</artifactId>
- </aspectLibrary>
- </aspectLibraries>
- </configuration>
- <executions>
- <execution>
- <id>compile_with_aspectj</id>
- <goals>
- <goal>compile</goal>
- </goals>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjtools</artifactId>
- <version>${aspectj.runtime.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-server-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
</plugins>
</build>
</project>
[04/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java
deleted file mode 100755
index 457dc39..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/BaseResourceIT.java
+++ /dev/null
@@ -1,690 +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.web.resources;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import kafka.consumer.ConsumerTimeoutException;
-import org.apache.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasClientV2;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.model.instance.AtlasClassification;
-import org.apache.atlas.model.instance.AtlasEntity;
-import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
-import org.apache.atlas.model.instance.AtlasEntityHeader;
-import org.apache.atlas.model.instance.AtlasStruct;
-import org.apache.atlas.model.instance.EntityMutationResponse;
-import org.apache.atlas.model.instance.EntityMutations;
-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.AtlasStructDef.AtlasAttributeDef;
-import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
-import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
-import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.notification.NotificationConsumer;
-import org.apache.atlas.notification.entity.EntityNotification;
-import org.apache.atlas.type.AtlasTypeUtil;
-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.persistence.Id;
-import org.apache.atlas.typesystem.types.*;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.apache.atlas.utils.AuthenticationUtil;
-import org.apache.atlas.utils.ParamChecker;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang.RandomStringUtils;
-import org.codehaus.jettison.json.JSONArray;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE;
-import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF;
-import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-/**
- * Base class for integration tests.
- * Sets up the web resource and has helper methods to create type and entity.
- */
-public abstract class BaseResourceIT {
-
- public static final String ATLAS_REST_ADDRESS = "atlas.rest.address";
- public static final String NAME = "name";
- public static final String QUALIFIED_NAME = "qualifiedName";
- public static final String CLUSTER_NAME = "clusterName";
- public static final String DESCRIPTION = "description";
-
- // All service clients
- protected AtlasClient atlasClientV1;
- protected AtlasClientV2 atlasClientV2;
-
- public static final Logger LOG = LoggerFactory.getLogger(BaseResourceIT.class);
- protected static final int MAX_WAIT_TIME = 60000;
- protected String[] atlasUrls;
-
- @BeforeClass
- public void setUp() throws Exception {
-
- //set high timeouts so that tests do not fail due to read timeouts while you
- //are stepping through the code in a debugger
- ApplicationProperties.get().setProperty("atlas.client.readTimeoutMSecs", "100000000");
- ApplicationProperties.get().setProperty("atlas.client.connectTimeoutMSecs", "100000000");
-
-
- Configuration configuration = ApplicationProperties.get();
- atlasUrls = configuration.getStringArray(ATLAS_REST_ADDRESS);
-
- if (atlasUrls == null || atlasUrls.length == 0) {
- atlasUrls = new String[] { "http://localhost:21000/" };
- }
-
- if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
- atlasClientV1 = new AtlasClient(atlasUrls, new String[]{"admin", "admin"});
- atlasClientV2 = new AtlasClientV2(atlasUrls, new String[]{"admin", "admin"});
- } else {
- atlasClientV1 = new AtlasClient(atlasUrls);
- atlasClientV2 = new AtlasClientV2(atlasUrls);
- }
- }
-
- protected void batchCreateTypes(AtlasTypesDef typesDef) throws AtlasServiceException {
- for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
- try {
- atlasClientV2.createEnumDef(enumDef);
- } catch (AtlasServiceException ex) {
- LOG.warn("EnumDef creation failed for {}", enumDef.getName());
- }
- }
- for (AtlasStructDef structDef : typesDef.getStructDefs()) {
- try {
- atlasClientV2.createStructDef(structDef);
- } catch (AtlasServiceException ex) {
- LOG.warn("StructDef creation failed for {}", structDef.getName());
- }
- }
-
- AtlasTypesDef entityDefs = new AtlasTypesDef(
- Collections.<AtlasEnumDef>emptyList(),
- Collections.<AtlasStructDef>emptyList(),
- Collections.<AtlasClassificationDef>emptyList(),
- typesDef.getEntityDefs());
- try {
- atlasClientV2.createAtlasTypeDefs(entityDefs);
- }
- catch(AtlasServiceException e) {
- LOG.warn("Type creation failed for {}", typesDef.toString());
- LOG.warn(e.toString());
- }
-
- for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
- try {
- atlasClientV2.createClassificationDef(classificationDef);
- } catch (AtlasServiceException ex) {
- LOG.warn("ClassificationDef creation failed for {}", classificationDef.getName());
- }
- }
-
- }
-
- protected void createType(AtlasTypesDef typesDef) {
- // Since the bulk create bails out on a single failure, this has to be done as a workaround
- for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
- try {
- atlasClientV2.createEnumDef(enumDef);
- } catch (AtlasServiceException ex) {
- LOG.warn("EnumDef creation failed for {}", enumDef.getName());
- }
- }
- for (AtlasStructDef structDef : typesDef.getStructDefs()) {
- try {
- atlasClientV2.createStructDef(structDef);
- } catch (AtlasServiceException ex) {
- LOG.warn("StructDef creation failed for {}", structDef.getName());
- }
- }
- for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
- try {
- atlasClientV2.createEntityDef(entityDef);
- } catch (AtlasServiceException ex) {
- LOG.warn("EntityDef creation failed for {}", entityDef.getName());
- }
- }
- for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
- try {
- atlasClientV2.createClassificationDef(classificationDef);
- } catch (AtlasServiceException ex) {
- LOG.warn("ClassificationDef creation failed for {}", classificationDef.getName());
- }
- }
-
- }
-
- protected void createType(TypesDef typesDef) throws Exception {
- try{
- if ( !typesDef.enumTypes().isEmpty() ){
- String sampleType = typesDef.enumTypesAsJavaList().get(0).name;
- atlasClientV1.getType(sampleType);
- LOG.info("Checking enum type existence");
- }
- else if( !typesDef.structTypes().isEmpty()){
- StructTypeDefinition sampleType = typesDef.structTypesAsJavaList().get(0);
- atlasClientV1.getType(sampleType.typeName);
- LOG.info("Checking struct type existence");
- }
- else if( !typesDef.traitTypes().isEmpty()){
- HierarchicalTypeDefinition<TraitType> sampleType = typesDef.traitTypesAsJavaList().get(0);
- atlasClientV1.getType(sampleType.typeName);
- LOG.info("Checking trait type existence");
- }
- else{
- HierarchicalTypeDefinition<ClassType> sampleType = typesDef.classTypesAsJavaList().get(0);
- atlasClientV1.getType(sampleType.typeName);
- LOG.info("Checking class type existence");
- }
- LOG.info("Types already exist. Skipping type creation");
- } catch(AtlasServiceException ase) {
- //Expected if type doesn't exist
- String typesAsJSON = TypesSerialization.toJson(typesDef);
- createType(typesAsJSON);
- }
- }
-
- protected List<String> createType(String typesAsJSON) throws Exception {
- return atlasClientV1.createType(TypesSerialization.fromJson(typesAsJSON));
- }
-
- protected Id createInstance(Referenceable referenceable) throws Exception {
- String typeName = referenceable.getTypeName();
- System.out.println("creating instance of type " + typeName);
-
- String entityJSON = InstanceSerialization.toJson(referenceable, true);
- System.out.println("Submitting new entity= " + entityJSON);
- List<String> guids = atlasClientV1.createEntity(entityJSON);
- System.out.println("created instance for type " + typeName + ", guid: " + guids);
-
- // return the reference to created instance with guid
- if (guids.size() > 0) {
- return new Id(guids.get(guids.size() - 1), 0, referenceable.getTypeName());
- }
- return null;
- }
-
- protected TypesDef getTypesDef(ImmutableList<EnumTypeDefinition> enums,
- ImmutableList<StructTypeDefinition> structs,
- ImmutableList<HierarchicalTypeDefinition<TraitType>> traits,
- ImmutableList<HierarchicalTypeDefinition<ClassType>> classes){
- enums = (enums != null) ? enums : ImmutableList
- .<EnumTypeDefinition>of();
- structs =
- (structs != null) ? structs : ImmutableList.<StructTypeDefinition>of();
-
- traits = (traits != null) ? traits : ImmutableList
- .<HierarchicalTypeDefinition<TraitType>>of();
-
- classes = (classes != null) ? classes : ImmutableList
- .<HierarchicalTypeDefinition<ClassType>>of();
- return TypesUtil.getTypesDef(enums, structs, traits, classes);
-
- }
-
- protected AtlasEntityHeader modifyEntity(AtlasEntity atlasEntity, boolean update) {
- EntityMutationResponse entity = null;
- try {
- if (!update) {
- entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(atlasEntity));
- assertNotNull(entity);
- assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
- assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size() > 0);
- return entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0);
- } else {
- entity = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(atlasEntity));
- assertNotNull(entity);
- assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
- assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
- return entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0);
- }
-
- } catch (AtlasServiceException e) {
- LOG.error("Entity {} failed", update ? "update" : "creation", entity);
- }
- return null;
- }
-
- protected AtlasEntityHeader createEntity(AtlasEntity atlasEntity) {
- return modifyEntity(atlasEntity, false);
- }
-
- protected AtlasEntityHeader updateEntity(AtlasEntity atlasEntity) {
- return modifyEntity(atlasEntity, true);
- }
-
- protected static final String DATABASE_TYPE_V2 = "hive_db_v2";
- protected static final String HIVE_TABLE_TYPE_V2 = "hive_table_v2";
- protected static final String COLUMN_TYPE_V2 = "hive_column_v2";
- protected static final String HIVE_PROCESS_TYPE_V2 = "hive_process_v2";
-
- protected static final String DATABASE_TYPE = "hive_db_v1";
- protected static final String HIVE_TABLE_TYPE = "hive_table_v1";
- protected static final String COLUMN_TYPE = "hive_column_v1";
- protected static final String HIVE_PROCESS_TYPE = "hive_process_v1";
-
- protected static final String DATABASE_TYPE_BUILTIN = "hive_db";
- protected static final String HIVE_TABLE_TYPE_BUILTIN = "hive_table";
- protected static final String COLUMN_TYPE_BUILTIN = "hive_column";
- protected static final String HIVE_PROCESS_TYPE_BUILTIN = "hive_process";
-
- protected void createTypeDefinitionsV1() throws Exception {
- HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil
- .createClassTypeDef(DATABASE_TYPE, null,
- TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
- attrDef("locationUri", DataTypes.STRING_TYPE),
- attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.INT_TYPE),
- new AttributeDefinition("tables", DataTypes.arrayTypeName(HIVE_TABLE_TYPE),
- Multiplicity.OPTIONAL, false, "db")
- );
-
- HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil
- .createClassTypeDef(COLUMN_TYPE, null, attrDef(NAME, DataTypes.STRING_TYPE),
- attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE));
-
- StructTypeDefinition structTypeDefinition = new StructTypeDefinition("serdeType",
- new AttributeDefinition[]{TypesUtil.createRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef("serde", DataTypes.STRING_TYPE)});
-
- EnumValue values[] = {new EnumValue("MANAGED", 1), new EnumValue("EXTERNAL", 2),};
-
- EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", values);
-
- HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil
- .createClassTypeDef(HIVE_TABLE_TYPE, ImmutableSet.of("DataSet"),
- attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE),
- attrDef("lastAccessTime", DataTypes.DATE_TYPE),
- attrDef("temporary", DataTypes.BOOLEAN_TYPE),
- new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.OPTIONAL, true, "tables"),
- new AttributeDefinition("columns", DataTypes.arrayTypeName(COLUMN_TYPE),
- Multiplicity.OPTIONAL, true, null),
- new AttributeDefinition("tableType", "tableType", Multiplicity.OPTIONAL, false, null),
- new AttributeDefinition("serde1", "serdeType", Multiplicity.OPTIONAL, false, null),
- new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null));
-
- HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil
- .createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableSet.of("Process"),
- attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.INT_TYPE),
- attrDef("endTime", DataTypes.LONG_TYPE),
- attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
- attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
- attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
- attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED));
-
- HierarchicalTypeDefinition<TraitType> classificationTrait = TypesUtil
- .createTraitTypeDef("classification", ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
- HierarchicalTypeDefinition<TraitType> piiTrait =
- TypesUtil.createTraitTypeDef("pii", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> phiTrait =
- TypesUtil.createTraitTypeDef("phi", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> pciTrait =
- TypesUtil.createTraitTypeDef("pci", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> soxTrait =
- TypesUtil.createTraitTypeDef("sox", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> secTrait =
- TypesUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> financeTrait =
- TypesUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
- /*HierarchicalTypeDefinition<TraitType> factTrait =
- TypesUtil.createTraitTypeDef("Fact", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> etlTrait =
- TypesUtil.createTraitTypeDef("ETL", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> dimensionTrait =
- TypesUtil.createTraitTypeDef("Dimension", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> metricTrait =
- TypesUtil.createTraitTypeDef("Metric", ImmutableSet.<String>of());*/
-
- createType(getTypesDef(ImmutableList.of(enumTypeDefinition), null, null, null));
- createType(getTypesDef(null, ImmutableList.of(structTypeDefinition), null, null));
- createType(getTypesDef(null, null,
- ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait,
- soxTrait, secTrait, financeTrait), null));
- createType(getTypesDef(null, null, null,
- ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)));
- }
-
- protected void createTypeDefinitionsV2() throws Exception {
-
- AtlasConstraintDef isCompositeSourceConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF);
-
- AtlasConstraintDef isCompositeTargetConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF,
- Collections.<String, Object>singletonMap(CONSTRAINT_PARAM_ATTRIBUTE, "randomTable"));
-
- AtlasEntityDef dbClsTypeDef = AtlasTypeUtil.createClassTypeDef(
- DATABASE_TYPE_V2,
- null,
- AtlasTypeUtil.createUniqueRequiredAttrDef(NAME, "string"),
- AtlasTypeUtil.createRequiredAttrDef(DESCRIPTION, "string"),
- AtlasTypeUtil.createOptionalAttrDef("locationUri", "string"),
- AtlasTypeUtil.createOptionalAttrDef("owner", "string"),
- AtlasTypeUtil.createOptionalAttrDef("createTime", "int"),
- AtlasTypeUtil.createOptionalAttrDef("createTime", "int"),
- //there is a serializ
- new AtlasAttributeDef("randomTable",
- DataTypes.arrayTypeName(HIVE_TABLE_TYPE_V2),
- true,
- Cardinality.SET,
- 0, -1, false, true, Collections.singletonList(isCompositeSourceConstraint))
- );
-
- AtlasEntityDef columnClsDef = AtlasTypeUtil
- .createClassTypeDef(COLUMN_TYPE_V2, null,
- AtlasTypeUtil.createOptionalAttrDef(NAME, "string"),
- AtlasTypeUtil.createOptionalAttrDef("dataType", "string"),
- AtlasTypeUtil.createOptionalAttrDef("comment", "string"));
-
- AtlasStructDef structTypeDef = AtlasTypeUtil.createStructTypeDef("serdeType",
- AtlasTypeUtil.createRequiredAttrDef(NAME, "string"),
- AtlasTypeUtil.createRequiredAttrDef("serde", "string")
- );
-
- AtlasEnumDef enumDef = new AtlasEnumDef("tableType", DESCRIPTION, Arrays.asList(
- new AtlasEnumDef.AtlasEnumElementDef("MANAGED", null, 1),
- new AtlasEnumDef.AtlasEnumElementDef("EXTERNAL", null, 2)
- ));
-
- AtlasEntityDef tblClsDef = AtlasTypeUtil
- .createClassTypeDef(HIVE_TABLE_TYPE_V2,
- ImmutableSet.of("DataSet"),
- AtlasTypeUtil.createOptionalAttrDef("owner", "string"),
- AtlasTypeUtil.createOptionalAttrDef("createTime", "long"),
- AtlasTypeUtil.createOptionalAttrDef("lastAccessTime", "date"),
- AtlasTypeUtil.createOptionalAttrDef("temporary", "boolean"),
- new AtlasAttributeDef("db",
- DATABASE_TYPE_V2,
- true,
- Cardinality.SINGLE,
- 0, 1, false, true, Collections.singletonList(isCompositeTargetConstraint)),
-
- //some tests don't set the columns field or set it to null...
- AtlasTypeUtil.createOptionalAttrDef("columns", DataTypes.arrayTypeName(COLUMN_TYPE_V2)),
- AtlasTypeUtil.createOptionalAttrDef("tableType", "tableType"),
- AtlasTypeUtil.createOptionalAttrDef("serde1", "serdeType"),
- AtlasTypeUtil.createOptionalAttrDef("serde2", "serdeType"));
-
- AtlasEntityDef loadProcessClsDef = AtlasTypeUtil
- .createClassTypeDef(HIVE_PROCESS_TYPE_V2,
- ImmutableSet.of("Process"),
- AtlasTypeUtil.createOptionalAttrDef("userName", "string"),
- AtlasTypeUtil.createOptionalAttrDef("startTime", "int"),
- AtlasTypeUtil.createOptionalAttrDef("endTime", "long"),
- AtlasTypeUtil.createRequiredAttrDef("queryText", "string"),
- AtlasTypeUtil.createRequiredAttrDef("queryPlan", "string"),
- AtlasTypeUtil.createRequiredAttrDef("queryId", "string"),
- AtlasTypeUtil.createRequiredAttrDef("queryGraph", "string"));
-
- AtlasClassificationDef classificationTrait = AtlasTypeUtil
- .createTraitTypeDef("classification",ImmutableSet.<String>of(),
- AtlasTypeUtil.createRequiredAttrDef("tag", "string"));
- AtlasClassificationDef piiTrait =
- AtlasTypeUtil.createTraitTypeDef("pii", ImmutableSet.<String>of());
- AtlasClassificationDef phiTrait =
- AtlasTypeUtil.createTraitTypeDef("phi", ImmutableSet.<String>of());
- AtlasClassificationDef pciTrait =
- AtlasTypeUtil.createTraitTypeDef("pci", ImmutableSet.<String>of());
- AtlasClassificationDef soxTrait =
- AtlasTypeUtil.createTraitTypeDef("sox", ImmutableSet.<String>of());
- AtlasClassificationDef secTrait =
- AtlasTypeUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
- AtlasClassificationDef financeTrait =
- AtlasTypeUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
-
- AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.of(enumDef),
- ImmutableList.of(structTypeDef),
- ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait),
- ImmutableList.of(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef));
-
- batchCreateTypes(typesDef);
- }
-
- AttributeDefinition attrDef(String name, IDataType dT) {
- return attrDef(name, dT, Multiplicity.OPTIONAL, false, null);
- }
-
- AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m) {
- return attrDef(name, dT, m, false, null);
- }
-
- AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m, boolean isComposite,
- String reverseAttributeName) {
- Preconditions.checkNotNull(name);
- Preconditions.checkNotNull(dT);
- return new AttributeDefinition(name, dT.getName(), m, isComposite, reverseAttributeName);
- }
-
- protected String randomString() {
- //names cannot start with a digit
- return RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomAlphanumeric(9);
- }
-
- protected Referenceable createHiveTableInstanceBuiltIn(String dbName, String tableName, Id dbId) throws Exception {
- Map<String, Object> values = new HashMap<>();
- values.put(NAME, dbName);
- values.put(DESCRIPTION, "foo database");
- values.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- values.put("owner", "user1");
- values.put(CLUSTER_NAME, "cl1");
- values.put("parameters", Collections.EMPTY_MAP);
- values.put("location", "/tmp");
- Referenceable databaseInstance = new Referenceable(dbId._getId(), dbId.getTypeName(), values);
- Referenceable tableInstance =
- new Referenceable(HIVE_TABLE_TYPE_BUILTIN, "classification", "pii", "phi", "pci", "sox", "sec", "finance");
- tableInstance.set(NAME, tableName);
- tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
- tableInstance.set("db", databaseInstance);
- tableInstance.set(DESCRIPTION, "bar table");
- tableInstance.set("lastAccessTime", "2014-07-11T08:00:00.000Z");
- tableInstance.set("type", "managed");
- tableInstance.set("level", 2);
- tableInstance.set("tableType", 1); // enum
- tableInstance.set("compressed", false);
-
- Struct traitInstance = (Struct) tableInstance.getTrait("classification");
- traitInstance.set("tag", "foundation_etl");
-
- Struct serde1Instance = new Struct("serdeType");
- serde1Instance.set(NAME, "serde1");
- serde1Instance.set("serde", "serde1");
- tableInstance.set("serde1", serde1Instance);
-
- Struct serde2Instance = new Struct("serdeType");
- serde2Instance.set(NAME, "serde2");
- serde2Instance.set("serde", "serde2");
- tableInstance.set("serde2", serde2Instance);
-
- List<String> traits = tableInstance.getTraits();
- Assert.assertEquals(traits.size(), 7);
-
- return tableInstance;
- }
-
- protected AtlasEntity createHiveTableInstanceV2(AtlasEntity databaseInstance, String tableName) throws Exception {
- AtlasEntity tableInstance = new AtlasEntity(HIVE_TABLE_TYPE_V2);
- tableInstance.setClassifications(
- Arrays.asList(new AtlasClassification("classification"),
- new AtlasClassification("pii"),
- new AtlasClassification("phi"),
- new AtlasClassification("pci"),
- new AtlasClassification("sox"),
- new AtlasClassification("sec"),
- new AtlasClassification("finance"))
- );
-
- tableInstance.setAttribute(NAME, tableName);
- tableInstance.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
- tableInstance.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(databaseInstance));
- tableInstance.setAttribute(DESCRIPTION, "bar table");
- tableInstance.setAttribute("lastAccessTime", "2014-07-11T08:00:00.000Z");
- tableInstance.setAttribute("type", "managed");
- tableInstance.setAttribute("level", 2);
- tableInstance.setAttribute("tableType", "MANAGED"); // enum
- tableInstance.setAttribute("compressed", false);
-
- AtlasClassification classification = tableInstance.getClassifications().get(0);
- classification.setAttribute("tag", "foundation_etl");
-
- AtlasStruct serde1Instance = new AtlasStruct("serdeType");
- serde1Instance.setAttribute(NAME, "serde1");
- serde1Instance.setAttribute("serde", "serde1");
- tableInstance.setAttribute("serde1", serde1Instance);
-
- AtlasStruct serde2Instance = new AtlasStruct("serdeType");
- serde2Instance.setAttribute(NAME, "serde2");
- serde2Instance.setAttribute("serde", "serde2");
- tableInstance.setAttribute("serde2", serde2Instance);
-
- List<AtlasClassification> traits = tableInstance.getClassifications();
- Assert.assertEquals(traits.size(), 7);
-
- return tableInstance;
- }
- protected Referenceable createHiveDBInstanceBuiltIn(String dbName) {
- Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
- databaseInstance.set(NAME, dbName);
- databaseInstance.set(QUALIFIED_NAME, dbName);
- databaseInstance.set(CLUSTER_NAME, randomString());
- databaseInstance.set(DESCRIPTION, "foo database");
- return databaseInstance;
- }
-
-
- protected Referenceable createHiveDBInstanceV1(String dbName) {
- Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
- databaseInstance.set(NAME, dbName);
- databaseInstance.set(DESCRIPTION, "foo database");
- return databaseInstance;
- }
-
- protected AtlasEntity createHiveDBInstanceV2(String dbName) {
- AtlasEntity atlasEntity = new AtlasEntity(DATABASE_TYPE_V2);
- atlasEntity.setAttribute(NAME, dbName);
- atlasEntity.setAttribute(DESCRIPTION, "foo database");
- atlasEntity.setAttribute("owner", "user1");
- atlasEntity.setAttribute("locationUri", "/tmp");
- atlasEntity.setAttribute("createTime",1000);
- return atlasEntity;
- }
-
-
- public interface Predicate {
-
- /**
- * Perform a predicate evaluation.
- *
- * @return the boolean result of the evaluation.
- * @throws Exception thrown if the predicate evaluation could not evaluate.
- */
- boolean evaluate() throws Exception;
- }
-
- public interface NotificationPredicate {
-
- /**
- * Perform a predicate evaluation.
- *
- * @return the boolean result of the evaluation.
- * @throws Exception thrown if the predicate evaluation could not evaluate.
- */
- boolean evaluate(EntityNotification notification) throws Exception;
- }
-
- /**
- * Wait for a condition, expressed via a {@link Predicate} to become true.
- *
- * @param timeout maximum time in milliseconds to wait for the predicate to become true.
- * @param predicate predicate waiting on.
- */
- protected void waitFor(int timeout, Predicate predicate) throws Exception {
- ParamChecker.notNull(predicate, "predicate");
- long mustEnd = System.currentTimeMillis() + timeout;
-
- boolean eval;
- while (!(eval = predicate.evaluate()) && System.currentTimeMillis() < mustEnd) {
- LOG.info("Waiting up to {} msec", mustEnd - System.currentTimeMillis());
- Thread.sleep(100);
- }
- if (!eval) {
- throw new Exception("Waiting timed out after " + timeout + " msec");
- }
- }
-
- protected EntityNotification waitForNotification(final NotificationConsumer<EntityNotification> consumer, int maxWait,
- final NotificationPredicate predicate) throws Exception {
- final TypeUtils.Pair<EntityNotification, String> pair = TypeUtils.Pair.of(null, null);
- final long maxCurrentTime = System.currentTimeMillis() + maxWait;
- waitFor(maxWait, new Predicate() {
- @Override
- public boolean evaluate() throws Exception {
- try {
- while (consumer.hasNext() && System.currentTimeMillis() < maxCurrentTime) {
- EntityNotification notification = consumer.next();
- if (predicate.evaluate(notification)) {
- pair.left = notification;
- return true;
- }
- }
- } catch(ConsumerTimeoutException e) {
- //ignore
- }
- return false;
- }
- });
- return pair.left;
- }
-
- protected NotificationPredicate newNotificationPredicate(final EntityNotification.OperationType operationType,
- final String typeName, final String guid) {
- return new NotificationPredicate() {
- @Override
- public boolean evaluate(EntityNotification notification) throws Exception {
- return notification != null &&
- notification.getOperationType() == operationType &&
- notification.getEntity().getTypeName().equals(typeName) &&
- notification.getEntity().getId()._getId().equals(guid);
- }
- };
- }
-
- protected JSONArray searchByDSL(String dslQuery) throws AtlasServiceException {
- return atlasClientV1.searchByDSL(dslQuery, 10, 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/DataSetLineageJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/DataSetLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/DataSetLineageJerseyResourceIT.java
deleted file mode 100644
index ee4057d..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/DataSetLineageJerseyResourceIT.java
+++ /dev/null
@@ -1,298 +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.web.resources;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.Struct;
-import org.apache.atlas.typesystem.json.InstanceSerialization;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import com.google.common.collect.ImmutableSet;
-
-import java.util.List;
-import java.util.Map;
-
-import static org.testng.Assert.assertEquals;
-
-/**
- * Hive Lineage Integration Tests.
- */
-public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
-
- private String salesFactTable;
- private String salesMonthlyTable;
- private String salesDBName;
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
-
- createTypeDefinitionsV1();
- setupInstances();
- }
-
- @Test
- public void testInputsGraph() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph");
- Assert.assertNotNull(response);
- System.out.println("inputs graph = " + response);
-
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
- Assert.assertNotNull(results);
-
- Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
- Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
- Assert.assertEquals(vertices.size(), 4);
-
- Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
- Assert.assertEquals(edges.size(), 4);
- }
-
- @Test
- public void testInputsGraphForEntity() throws Exception {
- String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
- salesMonthlyTable).getId()._getId();
- JSONObject results = atlasClientV1.getInputGraphForEntity(tableId);
- Assert.assertNotNull(results);
-
- Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
- Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
- Assert.assertEquals(vertices.size(), 4);
- Struct vertex = vertices.get(tableId);
- assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
-
- Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
- Assert.assertEquals(edges.size(), 4);
- }
-
- @Test
- public void testOutputsGraph() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph");
- Assert.assertNotNull(response);
- System.out.println("outputs graph= " + response);
-
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
- Assert.assertNotNull(results);
-
- Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
- Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
- Assert.assertEquals(vertices.size(), 3);
-
- Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
- Assert.assertEquals(edges.size(), 4);
- }
-
- @Test
- public void testOutputsGraphForEntity() throws Exception {
- String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
- salesFactTable).getId()._getId();
- JSONObject results = atlasClientV1.getOutputGraphForEntity(tableId);
- Assert.assertNotNull(results);
-
- Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
- Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
- Assert.assertEquals(vertices.size(), 3);
- Struct vertex = vertices.get(tableId);
- assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
-
- Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
- Assert.assertEquals(edges.size(), 4);
- }
-
- @Test
- public void testSchema() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema");
-
- Assert.assertNotNull(response);
- System.out.println("schema = " + response);
-
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
- Assert.assertNotNull(results);
-
- JSONArray rows = results.getJSONArray("rows");
- Assert.assertEquals(rows.length(), 4);
-
- for (int index = 0; index < rows.length(); index++) {
- final JSONObject row = rows.getJSONObject(index);
- LOG.info("JsonRow - {}", row);
- Assert.assertNotNull(row.getString("name"));
- Assert.assertNotNull(row.getString("comment"));
- Assert.assertEquals(row.getString("$typeName$"), "hive_column_v1");
- }
- }
-
- @Test
- public void testSchemaForEntity() throws Exception {
- String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
- JSONObject results = atlasClientV1.getSchemaForEntity(tableId);
- Assert.assertNotNull(results);
-
- JSONArray rows = results.getJSONArray("rows");
- Assert.assertEquals(rows.length(), 4);
-
- for (int index = 0; index < rows.length(); index++) {
- final JSONObject row = rows.getJSONObject(index);
- LOG.info("JsonRow - {}", row);
- Assert.assertNotNull(row.getString("name"));
- Assert.assertNotNull(row.getString("comment"));
- Assert.assertEquals(row.getString("$typeName$"), "hive_column_v1");
- }
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testSchemaForInvalidTable() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.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");
- }
-
- private void setupInstances() throws Exception {
- HierarchicalTypeDefinition<TraitType> factTrait =
- TypesUtil.createTraitTypeDef("Fact", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> etlTrait =
- TypesUtil.createTraitTypeDef("ETL", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> dimensionTrait =
- TypesUtil.createTraitTypeDef("Dimension", ImmutableSet.<String>of());
- HierarchicalTypeDefinition<TraitType> metricTrait =
- TypesUtil.createTraitTypeDef("Metric", ImmutableSet.<String>of());
- createType(getTypesDef(null, null,
- ImmutableList.of(factTrait, etlTrait, dimensionTrait, metricTrait), null));
-
- salesDBName = "Sales" + randomString();
- Id salesDB = database(salesDBName, "Sales Database", "John ETL",
- "hdfs://host:8000/apps/warehouse/sales");
-
- List<Referenceable> salesFactColumns = ImmutableList
- .of(column("time_id", "int", "time id"), column("product_id", "int", "product id"),
- column("customer_id", "int", "customer id", "pii"),
- column("sales", "double", "product id", "Metric"));
-
- salesFactTable = "sales_fact" + randomString();
- Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns, "Fact");
-
- List<Referenceable> timeDimColumns = ImmutableList
- .of(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"),
- column("weekDay", "int", "week Day"));
-
- Id timeDim =
- table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL",
- timeDimColumns, "Dimension");
-
- Id reportingDB =
- database("Reporting" + randomString(), "reporting database", "Jane BI",
- "hdfs://host:8000/apps/warehouse/reporting");
-
- Id salesFactDaily =
- table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB,
- "Joe BI", "MANAGED", salesFactColumns, "Metric");
-
- loadProcess("loadSalesDaily" + randomString(), "John ETL", ImmutableList.of(salesFact, timeDim),
- ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph", "ETL");
-
- salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
- Id salesFactMonthly =
- table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI",
- "MANAGED", salesFactColumns, "Metric");
-
- loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily),
- ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph", "ETL");
- }
-
- Id database(String name, String description, String owner, String locationUri, String... traitNames)
- throws Exception {
- Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
- referenceable.set(NAME, name);
- referenceable.set(QUALIFIED_NAME, name);
- referenceable.set(CLUSTER_NAME, locationUri + name);
- referenceable.set("description", description);
- referenceable.set("owner", owner);
- referenceable.set("locationUri", locationUri);
- referenceable.set("createTime", System.currentTimeMillis());
-
- return createInstance(referenceable);
- }
-
- Referenceable column(String name, String type, String comment, String... traitNames) throws Exception {
- Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
- referenceable.set(NAME, name);
- referenceable.set(QUALIFIED_NAME, name);
- referenceable.set("type", type);
- referenceable.set("comment", comment);
-
- return referenceable;
- }
-
- Id table(String name, String description, Id dbId, String owner, String tableType, List<Referenceable> columns,
- String... traitNames) throws Exception {
- Referenceable referenceable = new Referenceable(HIVE_TABLE_TYPE, traitNames);
- referenceable.set("name", name);
- referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
- referenceable.set("description", description);
- referenceable.set("owner", owner);
- referenceable.set("tableType", tableType);
- referenceable.set("createTime", System.currentTimeMillis());
- referenceable.set("lastAccessTime", System.currentTimeMillis());
- referenceable.set("retention", System.currentTimeMillis());
-
- referenceable.set("db", dbId);
- referenceable.set("columns", columns);
-
- return createInstance(referenceable);
- }
-
- Id loadProcess(String name, String user, List<Id> inputTables, List<Id> outputTables, String queryText,
- String queryPlan, String queryId, String queryGraph, String... traitNames) throws Exception {
- Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames);
- referenceable.set("name", name);
- referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
- referenceable.set("userName", user);
- referenceable.set("startTime", System.currentTimeMillis());
- referenceable.set("endTime", System.currentTimeMillis() + 10000);
-
- referenceable.set("inputs", inputTables);
- referenceable.set("outputs", outputTables);
-
- referenceable.set("operationType", "testOperation");
- referenceable.set("queryText", queryText);
- referenceable.set("queryPlan", queryPlan);
- referenceable.set("queryId", queryId);
- referenceable.set("queryGraph", queryGraph);
-
- return createInstance(referenceable);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java
index a51f371..e69de29 100755
--- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/EntityDiscoveryJerseyResourceIT.java
@@ -1,227 +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.web.resources;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.model.discovery.AtlasSearchResult;
-import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult;
-import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType;
-import org.apache.atlas.model.instance.AtlasEntity.Status;
-import org.apache.atlas.model.instance.AtlasEntityHeader;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.EnumTypeDefinition;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.StructTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import javax.ws.rs.core.MultivaluedMap;
-import java.util.List;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-
-/**
- * Search V2 Integration Tests.
- */
-public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT {
- private String dbName;
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
- dbName = "database" + randomString();
- createTypes();
- createInstance(createHiveDBInstanceBuiltIn(dbName));
- }
-
- @Test
- public void testSearchByDSL() throws Exception {
- String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
-
- AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
- assertNotNull(searchResult);
- assertEquals(searchResult.getQueryText(), dslQuery);
- assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
-
- List<AtlasEntityHeader> entities = searchResult.getEntities();
- assertNotNull(entities);
- assertEquals(entities.size(), 1);
-
- AtlasEntityHeader dbEntity = entities.get(0);
- assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
- assertEquals(dbEntity.getDisplayText(), dbName);
- assertEquals(dbEntity.getStatus(), Status.ACTIVE);
- assertNotNull(dbEntity.getGuid());
- assertNull(searchResult.getAttributes());
- assertNull(searchResult.getFullTextResult());
- }
-
- @Test
- public void testSearchDSLLimits() throws Exception {
- String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
- AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
- assertNotNull(searchResult);
-
- //higher limit, all results returned
- searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);
- assertEquals(searchResult.getEntities().size(), 1);
-
- //default limit and offset -1, all results returned
- searchResult = atlasClientV2.dslSearchWithParams(dslQuery, -1, -1);
- assertEquals(searchResult.getEntities().size(), 1);
-
- //uses the limit parameter passed
- searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 1, 0);
- assertEquals(searchResult.getEntities().size(), 1);
-
- //uses the offset parameter passed
- searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 1);
- assertNull(searchResult.getEntities());
-
- //limit > 0
- searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 0, 10);
- assertNull(searchResult.getEntities());
-
- //limit > maxlimit
- searchResult = atlasClientV2.dslSearchWithParams(dslQuery, Integer.MAX_VALUE, 10);
- assertNull(searchResult.getEntities());
-
- //offset >= 0
- searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, -2);
- assertEquals(searchResult.getEntities().size(), 1);
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testSearchByDSLForUnknownType() throws Exception {
- String dslQuery = "from blah";
- atlasClientV2.dslSearch(dslQuery);
- }
-
- @Test
- public void testSearchUsingDSL() throws Exception {
- String query = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
- AtlasSearchResult searchResult = atlasClientV2.dslSearch(query);
- assertNotNull(searchResult);
-
- assertEquals(searchResult.getQueryText(), query);
- assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
- List<AtlasEntityHeader> entities = searchResult.getEntities();
- assertNotNull(entities);
- assertEquals(entities.size(), 1);
-
- AtlasEntityHeader dbEntity = entities.get(0);
- assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
- assertEquals(dbEntity.getDisplayText(), dbName);
- assertEquals(dbEntity.getStatus(), Status.ACTIVE);
-
- assertNotNull(dbEntity.getGuid());
- assertNull(searchResult.getAttributes());
- assertNull(searchResult.getFullTextResult());
- }
-
- @Test
- public void testLikeSearchUsingDSL() throws Exception {
- String dslQuery = DATABASE_TYPE_BUILTIN + " where " + QUALIFIED_NAME + " like \"da?a*\"";
-
- AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
- assertNotNull(searchResult);
-
- List<AtlasEntityHeader> entities = searchResult.getEntities();
- assertNotNull(entities);
- assertEquals(entities.size(), 1);
-
- AtlasEntityHeader dbEntity = entities.get(0);
- assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
- assertEquals(dbEntity.getDisplayText(), dbName);
- }
-
- @Test
- public void testSearchFullTextOnDSLFailure() throws Exception {
- String query = "*";
- AtlasSearchResult searchResult = atlasClientV2.fullTextSearch(query);
- assertNotNull(searchResult);
- assertEquals(searchResult.getQueryText(), query);
- assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT);
- }
-
- @Test(dependsOnMethods = "testSearchDSLLimits")
- public void testSearchUsingFullText() throws Exception {
- AtlasSearchResult searchResult = atlasClientV2.fullTextSearchWithParams(dbName, 10, 0);
- assertNotNull(searchResult);
-
- assertEquals(searchResult.getQueryText(), dbName);
- assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT);
-
- List<AtlasFullTextResult> fullTextResults = searchResult.getFullTextResult();
- assertEquals(fullTextResults.size(), 1);
-
- AtlasFullTextResult result = fullTextResults.get(0);
- assertNotNull(result.getEntity());
- assertEquals(result.getEntity().getTypeName(), DATABASE_TYPE_BUILTIN);
- assertNotNull(result.getScore());
-
- //API works without limit and offset
- String query = dbName;
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("query", query);
- searchResult = atlasClientV2.fullTextSearch(query);
- assertNotNull(searchResult);
- assertEquals(searchResult.getFullTextResult().size(), 1);
-
- //verify passed in limits and offsets are used
- //higher limit and 0 offset returns all results
- searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 0);
- assertEquals(searchResult.getFullTextResult().size(), 1);
-
- //offset is used
- searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 1);
- assertEquals(searchResult.getFullTextResult().size(), 1);
-
- //limit is used
- searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 0);
- assertEquals(searchResult.getFullTextResult().size(), 1);
-
- //higher offset returns 0 results
- searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 2);
- assertEquals(searchResult.getFullTextResult().size(), 1);
- }
-
- private void createTypes() throws Exception {
- HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil
- .createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
-
- HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil
- .createTraitTypeDef("Classification", ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
- TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
- ImmutableList.of(classificationTraitDefinition), ImmutableList.of(dslTestTypeDefinition));
- createType(typesDef);
- }
-}
[07/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/service/ServiceState.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/ServiceState.java b/webapp/src/main/java/org/apache/atlas/web/service/ServiceState.java
index 2d9e00a..3fe8d18 100644
--- a/webapp/src/main/java/org/apache/atlas/web/service/ServiceState.java
+++ b/webapp/src/main/java/org/apache/atlas/web/service/ServiceState.java
@@ -19,13 +19,15 @@
package org.apache.atlas.web.service;
import com.google.common.base.Preconditions;
-import com.google.inject.Singleton;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.atlas.ha.HAConfiguration;
import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Singleton;
/**
* A class that maintains the state of this instance.
@@ -34,6 +36,7 @@ import org.slf4j.LoggerFactory;
* directed by {@link ActiveInstanceElectorService}.
*/
@Singleton
+@Component
public class ServiceState {
private static final Logger LOG = LoggerFactory.getLogger(ServiceState.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/service/UserService.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/service/UserService.java b/webapp/src/main/java/org/apache/atlas/web/service/UserService.java
index 6e5c210..24fd7cf 100644
--- a/webapp/src/main/java/org/apache/atlas/web/service/UserService.java
+++ b/webapp/src/main/java/org/apache/atlas/web/service/UserService.java
@@ -17,18 +17,23 @@
package org.apache.atlas.web.service;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.atlas.web.dao.UserDao;
+import org.apache.atlas.web.model.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
-import org.apache.atlas.web.dao.UserDao;
-import org.apache.atlas.web.model.User;
+
+import javax.inject.Inject;
@Service
public class UserService implements UserDetailsService {
- @Autowired
- private UserDao userDao;
+ private final UserDao userDao;
+
+ @Inject
+ public UserService(UserDao userDao) {
+ this.userDao = userDao;
+ }
@Override
public User loadUserByUsername(final String username)
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetup.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetup.java b/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetup.java
deleted file mode 100644
index 41eccd1..0000000
--- a/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetup.java
+++ /dev/null
@@ -1,65 +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.web.setup;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import org.apache.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.setup.SetupException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An application that is used to setup dependencies for the Atlas web service.
- *
- * This should be executed immediately after installation with the same configuration
- * as the Atlas web service itself. The application runs all steps registered with {@link SetupSteps}.
- */
-public class AtlasSetup {
-
- private static final Logger LOG = LoggerFactory.getLogger(AtlasSetup.class);
-
- private final Injector injector;
-
- public AtlasSetup() {
- injector = Guice.createInjector(new AtlasSetupModule());
- LOG.info("Got injector: {}", injector);
- }
-
- public static void main(String[] args) {
- try {
- AtlasSetup atlasSetup = new AtlasSetup();
- atlasSetup.run();
- LOG.info("Finished running all setup steps.");
- } catch (SetupException e) {
- LOG.error("Could not run setup step.", e);
- }
- }
-
- public void run() throws SetupException {
- SetupSteps setupSteps = injector.getInstance(SetupSteps.class);
- LOG.info("Got setup steps.");
- try {
- setupSteps.runSetup(ApplicationProperties.get());
- } catch (AtlasException e) {
- throw new SetupException("Cannot get application properties.", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetupModule.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetupModule.java b/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetupModule.java
deleted file mode 100644
index 6edfb12..0000000
--- a/webapp/src/main/java/org/apache/atlas/web/setup/AtlasSetupModule.java
+++ /dev/null
@@ -1,32 +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.web.setup;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
-import org.apache.atlas.repository.graph.GraphSchemaInitializer;
-import org.apache.atlas.setup.SetupStep;
-
-public class AtlasSetupModule extends AbstractModule {
- @Override
- protected void configure() {
- Multibinder<SetupStep> setupStepMultibinder = Multibinder.newSetBinder(binder(), SetupStep.class);
- setupStepMultibinder.addBinding().to(GraphSchemaInitializer.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/setup/SetupSteps.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/setup/SetupSteps.java b/webapp/src/main/java/org/apache/atlas/web/setup/SetupSteps.java
index eadd5ce..cfb49b6 100644
--- a/webapp/src/main/java/org/apache/atlas/web/setup/SetupSteps.java
+++ b/webapp/src/main/java/org/apache/atlas/web/setup/SetupSteps.java
@@ -19,8 +19,7 @@
package org.apache.atlas.web.setup;
import com.google.common.base.Charsets;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasConstants;
import org.apache.atlas.AtlasException;
import org.apache.atlas.ha.AtlasServerIdSelector;
@@ -37,32 +36,44 @@ import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+import org.springframework.stereotype.Component;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
@Singleton
+@Component
+@Conditional(SetupSteps.SetupRequired.class)
public class SetupSteps {
private static final Logger LOG = LoggerFactory.getLogger(SetupSteps.class);
public static final String SETUP_IN_PROGRESS_NODE = "/setup_in_progress";
private final Set<SetupStep> setupSteps;
+ private final Configuration configuration;
private CuratorFactory curatorFactory;
@Inject
- public SetupSteps(Set<SetupStep> steps, CuratorFactory curatorFactory) {
+ public SetupSteps(Set<SetupStep> steps, CuratorFactory curatorFactory, Configuration configuration) {
setupSteps = steps;
this.curatorFactory = curatorFactory;
+ this.configuration = configuration;
}
/**
* Call each registered {@link SetupStep} one after the other.
* @throws SetupException Thrown with any error during running setup, including Zookeeper interactions, and
* individual failures in the {@link SetupStep}.
- * @param configuration Configuration for Atlas server.
*/
- public void runSetup(Configuration configuration) throws SetupException {
+ @PostConstruct
+ public void runSetup() throws SetupException {
HAConfiguration.ZookeeperProperties zookeeperProperties = HAConfiguration.getZookeeperProperties(configuration);
InterProcessMutex lock = curatorFactory.lockInstance(zookeeperProperties.getZkRoot());
try {
@@ -162,4 +173,25 @@ public class SetupSteps {
throw new SetupException("Could not create lock node before running setup.", e);
}
}
+
+ static class SetupRequired implements Condition {
+ private static final String ATLAS_SERVER_RUN_SETUP_KEY = "atlas.server.run.setup.on.start";
+
+ @Override
+ public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ try {
+ Configuration configuration = ApplicationProperties.get();
+ boolean shouldRunSetup = configuration.getBoolean(ATLAS_SERVER_RUN_SETUP_KEY, false);
+ if (shouldRunSetup) {
+ LOG.warn("Running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
+ return true;
+ } else {
+ LOG.info("Not running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
+ }
+ } catch (AtlasException e) {
+ LOG.error("Unable to read config to determine if setup is needed. Not running setup.");
+ }
+ return false;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/resources/spring-security.xml
----------------------------------------------------------------------
diff --git a/webapp/src/main/resources/spring-security.xml b/webapp/src/main/resources/spring-security.xml
index 208c325..1743218 100644
--- a/webapp/src/main/resources/spring-security.xml
+++ b/webapp/src/main/resources/spring-security.xml
@@ -1,30 +1,23 @@
<?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
+<!-- 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. -->
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/security
- http://www.springframework.org/schema/security/spring-security-3.1.xsd
-
-
-
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.1.xsd">
+ <!-- This XML is no longer being used, @see AtlasSecurityConfig for the equivalent java config -->
<security:http pattern="/login.jsp" security="none" />
<security:http pattern="/css/**" security="none" />
@@ -35,8 +28,7 @@
<security:http pattern="/api/atlas/admin/status" security="none" />
<security:http pattern="/api/atlas/admin/metrics" security="none" />
- <security:http disable-url-rewriting="true"
- use-expressions="true" create-session="always"
+ <security:http create-session="always"
entry-point-ref="entryPoint">
<security:session-management
session-fixation-protection="newSession" />
@@ -48,6 +40,7 @@
<form-login
login-page="/login.jsp"
+ login-processing-url="/j_spring_security_check"
authentication-success-handler-ref="atlasAuthenticationSuccessHandler"
authentication-failure-handler-ref="atlasAuthenticationFailureHandler"
username-parameter="j_username"
@@ -56,6 +49,8 @@
<security:logout logout-success-url="/login.jsp" delete-cookies="ATLASSESSIONID"
logout-url="/logout.html" />
<http-basic />
+ <headers disabled="true"/>
+ <csrf disabled="true"/>
<security:custom-filter position="LAST" ref="atlasAuthorizationFilter"/>
</security:http>
@@ -76,7 +71,7 @@
<beans:bean id="formAuthenticationEntryPoint"
class="org.apache.atlas.web.filters.AtlasAuthenticationEntryPoint">
- <beans:property name="loginFormUrl" value="/login.jsp" />
+ <beans:constructor-arg value="/login.jsp"/>
</beans:bean>
<beans:bean id="authenticationEntryPoint"
@@ -108,7 +103,5 @@
<security:global-method-security
pre-post-annotations="enabled" />
- <context:component-scan base-package="org.apache.atlas.web" />
-
<beans:bean id = "atlasAuthorizationFilter" class="org.apache.atlas.web.filters.AtlasAuthorizationFilter"/>
-</beans:beans>
+</beans:beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/webapp/WEB-INF/applicationContext.xml
----------------------------------------------------------------------
diff --git a/webapp/src/main/webapp/WEB-INF/applicationContext.xml b/webapp/src/main/webapp/WEB-INF/applicationContext.xml
index d4ad14e..aae2aa0 100644
--- a/webapp/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/webapp/src/main/webapp/WEB-INF/applicationContext.xml
@@ -12,9 +12,12 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
-
- <import resource="classpath:/spring-security.xml" />
+ http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
+ <context:annotation-config/>
+ <aop:config proxy-target-class="true"/>
+ <context:component-scan base-package="org.apache.atlas" />
</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/webapp/src/main/webapp/WEB-INF/web.xml b/webapp/src/main/webapp/WEB-INF/web.xml
index f7e2028..d2d08f5 100755
--- a/webapp/src/main/webapp/WEB-INF/web.xml
+++ b/webapp/src/main/webapp/WEB-INF/web.xml
@@ -24,51 +24,46 @@
<display-name>Apache Atlas</display-name>
<description>Metadata Management and Data Governance Platform over Hadoop</description>
- <context-param>
- <param-name>guice.packages</param-name>
- <param-value>
- org.apache.atlas.web.resources,org.apache.atlas.web.params,org.apache.atlas.web.rest,org.apache.atlas.web.errors
- </param-value>
- </context-param>
-
- <context-param>
- <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
- <param-value>true</param-value>
- </context-param>
+ <servlet>
+ <servlet-name>jersey-servlet</servlet-name>
+ <servlet-class>
+ com.sun.jersey.spi.spring.container.servlet.SpringServlet
+ </servlet-class>
+ <init-param>
+ <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
- <!--
- More information can be found here:
-
- https://jersey.java.net/nonav/apidocs/1.11/contribs/jersey-guice/com/sun/jersey/guice/spi/container/servlet/package-summary.html
- -->
+ <servlet-mapping>
+ <servlet-name>jersey-servlet</servlet-name>
+ <url-pattern>/api/atlas/*</url-pattern>
+ </servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
-
- <filter>
- <filter-name>guiceFilter</filter-name>
- <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
- </filter>
-
+
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-
+
+ <filter>
+ <filter-name>AuditFilter</filter-name>
+ <filter-class>org.apache.atlas.web.filters.AuditFilter</filter-class>
+ </filter>
+
<filter-mapping>
- <filter-name>guiceFilter</filter-name>
+ <filter-name>AuditFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
-
- <listener>
- <listener-class>org.apache.atlas.web.listeners.GuiceServletConfig</listener-class>
- </listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
@@ -88,5 +83,5 @@
</cookie-config>
</session-config>
-
+
</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java b/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
index 06c78be..592c2a6 100644
--- a/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
+++ b/webapp/src/test/java/org/apache/atlas/examples/QuickStartIT.java
@@ -22,7 +22,7 @@ import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.web.resources.BaseResourceIT;
+import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java b/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
index 7f3192a..773a514 100644
--- a/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
+++ b/webapp/src/test/java/org/apache/atlas/examples/QuickStartV2IT.java
@@ -26,9 +26,8 @@ import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
-import org.apache.atlas.web.resources.BaseResourceIT;
+import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONException;
-import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java b/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java
index 29be942..ac3b538 100644
--- a/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java
+++ b/webapp/src/test/java/org/apache/atlas/notification/EntityNotificationIT.java
@@ -19,8 +19,8 @@
package org.apache.atlas.notification;
import com.google.common.collect.ImmutableSet;
-import com.google.inject.Inject;
import org.apache.atlas.AtlasClient;
+import org.apache.atlas.kafka.NotificationProvider;
import org.apache.atlas.notification.entity.EntityNotification;
import org.apache.atlas.typesystem.IReferenceableInstance;
import org.apache.atlas.typesystem.IStruct;
@@ -32,9 +32,8 @@ import org.apache.atlas.typesystem.persistence.Id;
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.atlas.web.resources.BaseResourceIT;
+import org.apache.atlas.web.integration.BaseResourceIT;
import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.Collections;
@@ -48,13 +47,11 @@ import static org.testng.Assert.assertTrue;
/**
* Entity Notification Integration Tests.
*/
-@Guice(modules = NotificationModule.class)
public class EntityNotificationIT extends BaseResourceIT {
private final String DATABASE_NAME = "db" + randomString();
private final String TABLE_NAME = "table" + randomString();
- @Inject
- private NotificationInterface notificationInterface;
+ private NotificationInterface notificationInterface = NotificationProvider.get();
private Id tableId;
private Id dbId;
private String traitName;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
index 1c2cdc6..9c5597e 100644
--- a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
+++ b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerIT.java
@@ -18,23 +18,21 @@
package org.apache.atlas.notification;
-import com.google.inject.Inject;
import org.apache.atlas.EntityAuditEvent;
+import org.apache.atlas.kafka.NotificationProvider;
import org.apache.atlas.notification.hook.HookNotification;
import org.apache.atlas.typesystem.Referenceable;
import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.web.resources.BaseResourceIT;
+import org.apache.atlas.web.integration.BaseResourceIT;
import org.codehaus.jettison.json.JSONArray;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.List;
import static org.testng.Assert.assertEquals;
-@Guice(modules = NotificationModule.class)
public class NotificationHookConsumerIT extends BaseResourceIT {
private static final String TEST_USER = "testuser";
@@ -43,8 +41,7 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
public static final String QUALIFIED_NAME = "qualifiedName";
public static final String CLUSTER_NAME = "clusterName";
- @Inject
- private NotificationInterface kafka;
+ private NotificationInterface notificationInterface = NotificationProvider.get();
@BeforeClass
public void setUp() throws Exception {
@@ -54,11 +51,11 @@ public class NotificationHookConsumerIT extends BaseResourceIT {
@AfterClass
public void teardown() throws Exception {
- kafka.close();
+ notificationInterface.close();
}
private void sendHookMessage(HookNotification.HookNotificationMessage message) throws NotificationException {
- kafka.send(NotificationInterface.NotificationType.HOOK, message);
+ notificationInterface.send(NotificationInterface.NotificationType.HOOK, message);
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerKafkaTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerKafkaTest.java b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerKafkaTest.java
index e744e2e..18fd2ee 100644
--- a/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerKafkaTest.java
+++ b/webapp/src/test/java/org/apache/atlas/notification/NotificationHookConsumerKafkaTest.java
@@ -18,12 +18,12 @@
package org.apache.atlas.notification;
-import com.google.inject.Inject;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.kafka.KafkaNotification;
+import org.apache.atlas.kafka.NotificationProvider;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.notification.hook.HookNotification;
import org.apache.atlas.repository.converters.AtlasInstanceConverter;
@@ -39,7 +39,6 @@ import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
@@ -47,14 +46,12 @@ import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
-@Guice(modules = NotificationModule.class)
public class NotificationHookConsumerKafkaTest {
public static final String NAME = "name";
public static final String DESCRIPTION = "description";
public static final String QUALIFIED_NAME = "qualifiedName";
- @Inject
- private NotificationInterface notificationInterface;
+ private NotificationInterface notificationInterface = NotificationProvider.get();
@Mock
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
index 9272203..e753881 100644
--- a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
+++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
@@ -20,7 +20,7 @@ package org.apache.atlas.web.adapters;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.RequestContext;
import org.apache.atlas.RequestContextV1;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
@@ -32,7 +32,6 @@ import org.apache.atlas.model.instance.ClassificationAssociateRequest;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasType;
@@ -42,7 +41,6 @@ import org.apache.atlas.web.rest.EntityREST;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
@@ -57,7 +55,7 @@ import java.util.List;
import java.util.Map;
-@Guice(modules = {TestOnlyModule.class})
+@Guice(modules = {TestModules.TestOnlyModule.class})
public class TestEntitiesREST {
private static final Logger LOG = LoggerFactory.getLogger(TestEntitiesREST.class);
@@ -105,11 +103,6 @@ public class TestEntitiesREST {
RequestContextV1.clear();
}
- @AfterClass
- public void tearDown() throws Exception {
- AtlasGraphProvider.cleanup();
- }
-
@Test
public void testCreateOrUpdateEntities() throws Exception {
AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
index cadf0ff..b90ea64 100644
--- a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
+++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java
@@ -17,9 +17,9 @@
*/
package org.apache.atlas.web.adapters;
+import org.apache.atlas.TestModules;
import org.apache.atlas.RequestContext;
import org.apache.atlas.RequestContextV1;
-import org.apache.atlas.TestOnlyModule;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
@@ -30,7 +30,6 @@ import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.web.rest.EntityREST;
@@ -50,7 +49,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-@Guice(modules = {TestOnlyModule.class})
+@Guice(modules = {TestModules.TestOnlyModule.class})
public class TestEntityREST {
@Inject
@@ -73,7 +72,7 @@ public class TestEntityREST {
@AfterClass
public void tearDown() throws Exception {
- AtlasGraphProvider.cleanup();
+// AtlasGraphProvider.cleanup();
}
@AfterMethod
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
new file mode 100755
index 0000000..cfe09d6
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/AdminJerseyResourceIT.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.web.integration;
+
+import org.apache.atlas.AtlasClient;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.codehaus.jettison.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Integration test for Admin jersey resource.
+ */
+public class AdminJerseyResourceIT extends BaseResourceIT {
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Test
+ public void testGetVersion() throws Exception {
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.VERSION, null, (String[]) null);
+ Assert.assertNotNull(response);
+
+ PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
+
+ Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version"));
+ Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name"));
+ Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
new file mode 100755
index 0000000..b59d3ee
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/BaseResourceIT.java
@@ -0,0 +1,669 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import kafka.consumer.ConsumerTimeoutException;
+import org.apache.atlas.ApplicationProperties;
+import org.apache.atlas.AtlasClient;
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.instance.AtlasClassification;
+import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
+import org.apache.atlas.model.instance.AtlasStruct;
+import org.apache.atlas.model.instance.EntityMutationResponse;
+import org.apache.atlas.model.instance.EntityMutations;
+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.AtlasStructDef.AtlasAttributeDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
+import org.apache.atlas.model.typedef.AtlasTypesDef;
+import org.apache.atlas.notification.NotificationConsumer;
+import org.apache.atlas.notification.entity.EntityNotification;
+import org.apache.atlas.type.AtlasTypeUtil;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.Struct;
+import org.apache.atlas.typesystem.TypesDef;
+import org.apache.atlas.typesystem.json.TypesSerialization;
+import org.apache.atlas.typesystem.persistence.Id;
+import org.apache.atlas.typesystem.types.*;
+import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.apache.atlas.utils.AuthenticationUtil;
+import org.apache.atlas.utils.ParamChecker;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.RandomStringUtils;
+import org.codehaus.jettison.json.JSONArray;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE;
+import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF;
+import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * Base class for integration tests.
+ * Sets up the web resource and has helper methods to created type and entity.
+ */
+public abstract class BaseResourceIT {
+
+ public static final String ATLAS_REST_ADDRESS = "atlas.rest.address";
+ public static final String NAME = "name";
+ public static final String QUALIFIED_NAME = "qualifiedName";
+ public static final String CLUSTER_NAME = "clusterName";
+ public static final String DESCRIPTION = "description";
+
+ // All service clients
+ protected AtlasClient atlasClientV1;
+ protected AtlasClientV2 atlasClientV2;
+
+ public static final Logger LOG = LoggerFactory.getLogger(BaseResourceIT.class);
+ protected static final int MAX_WAIT_TIME = 60000;
+ protected String[] atlasUrls;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+
+ //set high timeouts so that tests do not fail due to read timeouts while you
+ //are stepping through the code in a debugger
+ ApplicationProperties.get().setProperty("atlas.client.readTimeoutMSecs", "100000000");
+ ApplicationProperties.get().setProperty("atlas.client.connectTimeoutMSecs", "100000000");
+
+
+ Configuration configuration = ApplicationProperties.get();
+ atlasUrls = configuration.getStringArray(ATLAS_REST_ADDRESS);
+
+ if (atlasUrls == null || atlasUrls.length == 0) {
+ atlasUrls = new String[] { "http://localhost:21000/" };
+ }
+
+ if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
+ atlasClientV1 = new AtlasClient(atlasUrls, new String[]{"admin", "admin"});
+ atlasClientV2 = new AtlasClientV2(atlasUrls, new String[]{"admin", "admin"});
+ } else {
+ atlasClientV1 = new AtlasClient(atlasUrls);
+ atlasClientV2 = new AtlasClientV2(atlasUrls);
+ }
+ }
+
+ protected void batchCreateTypes(AtlasTypesDef typesDef) throws AtlasServiceException {
+ AtlasTypesDef toCreate = new AtlasTypesDef();
+ for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
+ if (atlasClientV2.typeWithNameExists(enumDef.getName())) {
+ LOG.warn("Type with name {} already exists. Skipping", enumDef.getName());
+ } else {
+ toCreate.getEnumDefs().add(enumDef);
+ }
+ }
+
+ for (AtlasStructDef structDef : typesDef.getStructDefs()) {
+ if (atlasClientV2.typeWithNameExists(structDef.getName())) {
+ LOG.warn("Type with name {} already exists. Skipping", structDef.getName());
+ } else {
+ toCreate.getStructDefs().add(structDef);
+ }
+ }
+
+ for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
+ if (atlasClientV2.typeWithNameExists(entityDef.getName())) {
+ LOG.warn("Type with name {} already exists. Skipping", entityDef.getName());
+ } else {
+ toCreate.getEntityDefs().add(entityDef);
+ }
+ }
+
+ for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
+ if (atlasClientV2.typeWithNameExists(classificationDef.getName())) {
+ LOG.warn("Type with name {} already exists. Skipping", classificationDef.getName());
+ } else {
+ toCreate.getClassificationDefs().add(classificationDef);
+ }
+ }
+
+ atlasClientV2.createAtlasTypeDefs(toCreate);
+ }
+
+ protected void createType(AtlasTypesDef typesDef) throws AtlasServiceException {
+ // Since the bulk create bails out on a single failure, this has to be done as a workaround
+ batchCreateTypes(typesDef);
+ }
+
+ protected List<String> createType(TypesDef typesDef) throws Exception {
+ List<EnumTypeDefinition> enumTypes = new ArrayList<>();
+ List<StructTypeDefinition> structTypes = new ArrayList<>();
+ List<HierarchicalTypeDefinition<TraitType>> traitTypes = new ArrayList<>();
+ List<HierarchicalTypeDefinition<ClassType>> classTypes = new ArrayList<>();
+
+ for (EnumTypeDefinition enumTypeDefinition : typesDef.enumTypesAsJavaList()) {
+ if (atlasClientV2.typeWithNameExists(enumTypeDefinition.name)) {
+ LOG.warn("Type with name {} already exists. Skipping", enumTypeDefinition.name);
+ } else {
+ enumTypes.add(enumTypeDefinition);
+ }
+ }
+ for (StructTypeDefinition structTypeDefinition : typesDef.structTypesAsJavaList()) {
+ if (atlasClientV2.typeWithNameExists(structTypeDefinition.typeName)) {
+ LOG.warn("Type with name {} already exists. Skipping", structTypeDefinition.typeName);
+ } else {
+ structTypes.add(structTypeDefinition);
+ }
+ }
+ for (HierarchicalTypeDefinition<TraitType> hierarchicalTypeDefinition : typesDef.traitTypesAsJavaList()) {
+ if (atlasClientV2.typeWithNameExists(hierarchicalTypeDefinition.typeName)) {
+ LOG.warn("Type with name {} already exists. Skipping", hierarchicalTypeDefinition.typeName);
+ } else {
+ traitTypes.add(hierarchicalTypeDefinition);
+ }
+ }
+ for (HierarchicalTypeDefinition<ClassType> hierarchicalTypeDefinition : typesDef.classTypesAsJavaList()) {
+ if (atlasClientV2.typeWithNameExists(hierarchicalTypeDefinition.typeName)) {
+ LOG.warn("Type with name {} already exists. Skipping", hierarchicalTypeDefinition.typeName);
+ } else {
+ classTypes.add(hierarchicalTypeDefinition);
+ }
+ }
+
+ TypesDef toCreate = TypesUtil.getTypesDef(ImmutableList.copyOf(enumTypes),
+ ImmutableList.copyOf(structTypes),
+ ImmutableList.copyOf(traitTypes),
+ ImmutableList.copyOf(classTypes));
+ return atlasClientV1.createType(toCreate);
+ }
+
+ protected List<String> createType(String typesAsJSON) throws Exception {
+ return createType(TypesSerialization.fromJson(typesAsJSON));
+ }
+
+ protected Id createInstance(Referenceable referenceable) throws Exception {
+ String typeName = referenceable.getTypeName();
+ System.out.println("creating instance of type " + typeName);
+
+ List<String> guids = atlasClientV1.createEntity(referenceable);
+ System.out.println("created instance for type " + typeName + ", guid: " + guids);
+
+ // return the reference to created instance with guid
+ if (guids.size() > 0) {
+ return new Id(guids.get(guids.size() - 1), 0, referenceable.getTypeName());
+ }
+ return null;
+ }
+
+ protected TypesDef getTypesDef(ImmutableList<EnumTypeDefinition> enums,
+ ImmutableList<StructTypeDefinition> structs,
+ ImmutableList<HierarchicalTypeDefinition<TraitType>> traits,
+ ImmutableList<HierarchicalTypeDefinition<ClassType>> classes){
+ enums = (enums != null) ? enums : ImmutableList
+ .<EnumTypeDefinition>of();
+ structs =
+ (structs != null) ? structs : ImmutableList.<StructTypeDefinition>of();
+
+ traits = (traits != null) ? traits : ImmutableList
+ .<HierarchicalTypeDefinition<TraitType>>of();
+
+ classes = (classes != null) ? classes : ImmutableList
+ .<HierarchicalTypeDefinition<ClassType>>of();
+ return TypesUtil.getTypesDef(enums, structs, traits, classes);
+
+ }
+
+ protected AtlasEntityHeader modifyEntity(AtlasEntity atlasEntity, boolean update) {
+ EntityMutationResponse entity = null;
+ try {
+ if (!update) {
+ entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(atlasEntity));
+ assertNotNull(entity);
+ assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
+ assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size() > 0);
+ return entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0);
+ } else {
+ entity = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(atlasEntity));
+ assertNotNull(entity);
+ assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
+ assertTrue(entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
+ return entity.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0);
+ }
+
+ } catch (AtlasServiceException e) {
+ LOG.error("Entity {} failed", update ? "update" : "creation", entity);
+ }
+ return null;
+ }
+
+ protected AtlasEntityHeader createEntity(AtlasEntity atlasEntity) {
+ return modifyEntity(atlasEntity, false);
+ }
+
+ protected AtlasEntityHeader updateEntity(AtlasEntity atlasEntity) {
+ return modifyEntity(atlasEntity, true);
+ }
+
+ protected static final String DATABASE_TYPE_V2 = "hive_db_v2";
+ protected static final String HIVE_TABLE_TYPE_V2 = "hive_table_v2";
+ protected static final String COLUMN_TYPE_V2 = "hive_column_v2";
+ protected static final String HIVE_PROCESS_TYPE_V2 = "hive_process_v2";
+
+ protected static final String DATABASE_TYPE = "hive_db_v1";
+ protected static final String HIVE_TABLE_TYPE = "hive_table_v1";
+ protected static final String COLUMN_TYPE = "hive_column_v1";
+ protected static final String HIVE_PROCESS_TYPE = "hive_process_v1";
+
+ protected static final String DATABASE_TYPE_BUILTIN = "hive_db";
+ protected static final String HIVE_TABLE_TYPE_BUILTIN = "hive_table";
+ protected static final String COLUMN_TYPE_BUILTIN = "hive_column";
+ protected static final String HIVE_PROCESS_TYPE_BUILTIN = "hive_process";
+
+ protected void createTypeDefinitionsV1() throws Exception {
+ HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil
+ .createClassTypeDef(DATABASE_TYPE, null,
+ TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
+ attrDef("locationUri", DataTypes.STRING_TYPE),
+ attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.INT_TYPE),
+ new AttributeDefinition("tables", DataTypes.arrayTypeName(HIVE_TABLE_TYPE),
+ Multiplicity.OPTIONAL, false, "db")
+ );
+
+ HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil
+ .createClassTypeDef(COLUMN_TYPE, null, attrDef(NAME, DataTypes.STRING_TYPE),
+ attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE));
+
+ StructTypeDefinition structTypeDefinition = new StructTypeDefinition("serdeType",
+ new AttributeDefinition[]{TypesUtil.createRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef("serde", DataTypes.STRING_TYPE)});
+
+ EnumValue values[] = {new EnumValue("MANAGED", 1), new EnumValue("EXTERNAL", 2),};
+
+ EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", values);
+
+ HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil
+ .createClassTypeDef(HIVE_TABLE_TYPE, ImmutableSet.of("DataSet"),
+ attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE),
+ attrDef("lastAccessTime", DataTypes.DATE_TYPE),
+ attrDef("temporary", DataTypes.BOOLEAN_TYPE),
+ new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.OPTIONAL, true, "tables"),
+ new AttributeDefinition("columns", DataTypes.arrayTypeName(COLUMN_TYPE),
+ Multiplicity.OPTIONAL, true, null),
+ new AttributeDefinition("tableType", "tableType", Multiplicity.OPTIONAL, false, null),
+ new AttributeDefinition("serde1", "serdeType", Multiplicity.OPTIONAL, false, null),
+ new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null));
+
+ HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil
+ .createClassTypeDef(HIVE_PROCESS_TYPE, ImmutableSet.of("Process"),
+ attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.INT_TYPE),
+ attrDef("endTime", DataTypes.LONG_TYPE),
+ attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
+ attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
+ attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED),
+ attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED));
+
+ HierarchicalTypeDefinition<TraitType> classificationTrait = TypesUtil
+ .createTraitTypeDef("classification", ImmutableSet.<String>of(),
+ TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
+ HierarchicalTypeDefinition<TraitType> piiTrait =
+ TypesUtil.createTraitTypeDef("pii", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> phiTrait =
+ TypesUtil.createTraitTypeDef("phi", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> pciTrait =
+ TypesUtil.createTraitTypeDef("pci", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> soxTrait =
+ TypesUtil.createTraitTypeDef("sox", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> secTrait =
+ TypesUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> financeTrait =
+ TypesUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> factTrait =
+ TypesUtil.createTraitTypeDef("Fact", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> etlTrait =
+ TypesUtil.createTraitTypeDef("ETL", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> dimensionTrait =
+ TypesUtil.createTraitTypeDef("Dimension", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> metricTrait =
+ TypesUtil.createTraitTypeDef("Metric", ImmutableSet.<String>of());
+
+ createType(getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition),
+ ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait,
+ soxTrait, secTrait, financeTrait, factTrait, etlTrait, dimensionTrait, metricTrait),
+ ImmutableList.of(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)));
+ }
+
+ protected void createTypeDefinitionsV2() throws Exception {
+
+ AtlasConstraintDef isCompositeSourceConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF);
+
+ AtlasConstraintDef isCompositeTargetConstraint = new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF,
+ Collections.<String, Object>singletonMap(CONSTRAINT_PARAM_ATTRIBUTE, "randomTable"));
+
+ AtlasEntityDef dbClsTypeDef = AtlasTypeUtil.createClassTypeDef(
+ DATABASE_TYPE_V2,
+ null,
+ AtlasTypeUtil.createUniqueRequiredAttrDef(NAME, "string"),
+ AtlasTypeUtil.createRequiredAttrDef(DESCRIPTION, "string"),
+ AtlasTypeUtil.createOptionalAttrDef("locationUri", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("owner", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("createTime", "int"),
+ AtlasTypeUtil.createOptionalAttrDef("createTime", "int"),
+ //there is a serializ
+ new AtlasAttributeDef("randomTable",
+ DataTypes.arrayTypeName(HIVE_TABLE_TYPE_V2),
+ true,
+ Cardinality.SET,
+ 0, -1, false, true, Collections.singletonList(isCompositeSourceConstraint))
+ );
+
+ AtlasEntityDef columnClsDef = AtlasTypeUtil
+ .createClassTypeDef(COLUMN_TYPE_V2, null,
+ AtlasTypeUtil.createOptionalAttrDef(NAME, "string"),
+ AtlasTypeUtil.createOptionalAttrDef("dataType", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("comment", "string"));
+
+ AtlasStructDef structTypeDef = AtlasTypeUtil.createStructTypeDef("serdeType",
+ AtlasTypeUtil.createRequiredAttrDef(NAME, "string"),
+ AtlasTypeUtil.createRequiredAttrDef("serde", "string")
+ );
+
+ AtlasEnumDef enumDef = new AtlasEnumDef("tableType", DESCRIPTION, Arrays.asList(
+ new AtlasEnumDef.AtlasEnumElementDef("MANAGED", null, 1),
+ new AtlasEnumDef.AtlasEnumElementDef("EXTERNAL", null, 2)
+ ));
+
+ AtlasEntityDef tblClsDef = AtlasTypeUtil
+ .createClassTypeDef(HIVE_TABLE_TYPE_V2,
+ ImmutableSet.of("DataSet"),
+ AtlasTypeUtil.createOptionalAttrDef("owner", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("createTime", "long"),
+ AtlasTypeUtil.createOptionalAttrDef("lastAccessTime", "date"),
+ AtlasTypeUtil.createOptionalAttrDef("temporary", "boolean"),
+ new AtlasAttributeDef("db",
+ DATABASE_TYPE_V2,
+ true,
+ Cardinality.SINGLE,
+ 0, 1, false, true, Collections.singletonList(isCompositeTargetConstraint)),
+
+ //some tests don't set the columns field or set it to null...
+ AtlasTypeUtil.createOptionalAttrDef("columns", DataTypes.arrayTypeName(COLUMN_TYPE_V2)),
+ AtlasTypeUtil.createOptionalAttrDef("tableType", "tableType"),
+ AtlasTypeUtil.createOptionalAttrDef("serde1", "serdeType"),
+ AtlasTypeUtil.createOptionalAttrDef("serde2", "serdeType"));
+
+ AtlasEntityDef loadProcessClsDef = AtlasTypeUtil
+ .createClassTypeDef(HIVE_PROCESS_TYPE_V2,
+ ImmutableSet.of("Process"),
+ AtlasTypeUtil.createOptionalAttrDef("userName", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("startTime", "int"),
+ AtlasTypeUtil.createOptionalAttrDef("endTime", "long"),
+ AtlasTypeUtil.createRequiredAttrDef("queryText", "string"),
+ AtlasTypeUtil.createRequiredAttrDef("queryPlan", "string"),
+ AtlasTypeUtil.createRequiredAttrDef("queryId", "string"),
+ AtlasTypeUtil.createRequiredAttrDef("queryGraph", "string"));
+
+ AtlasClassificationDef classificationTrait = AtlasTypeUtil
+ .createTraitTypeDef("classification",ImmutableSet.<String>of(),
+ AtlasTypeUtil.createRequiredAttrDef("tag", "string"));
+ AtlasClassificationDef piiTrait =
+ AtlasTypeUtil.createTraitTypeDef("pii", ImmutableSet.<String>of());
+ AtlasClassificationDef phiTrait =
+ AtlasTypeUtil.createTraitTypeDef("phi", ImmutableSet.<String>of());
+ AtlasClassificationDef pciTrait =
+ AtlasTypeUtil.createTraitTypeDef("pci", ImmutableSet.<String>of());
+ AtlasClassificationDef soxTrait =
+ AtlasTypeUtil.createTraitTypeDef("sox", ImmutableSet.<String>of());
+ AtlasClassificationDef secTrait =
+ AtlasTypeUtil.createTraitTypeDef("sec", ImmutableSet.<String>of());
+ AtlasClassificationDef financeTrait =
+ AtlasTypeUtil.createTraitTypeDef("finance", ImmutableSet.<String>of());
+
+ AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.of(enumDef),
+ ImmutableList.of(structTypeDef),
+ ImmutableList.of(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait),
+ ImmutableList.of(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef));
+
+ batchCreateTypes(typesDef);
+ }
+
+ AttributeDefinition attrDef(String name, IDataType dT) {
+ return attrDef(name, dT, Multiplicity.OPTIONAL, false, null);
+ }
+
+ AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m) {
+ return attrDef(name, dT, m, false, null);
+ }
+
+ AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m, boolean isComposite,
+ String reverseAttributeName) {
+ Preconditions.checkNotNull(name);
+ Preconditions.checkNotNull(dT);
+ return new AttributeDefinition(name, dT.getName(), m, isComposite, reverseAttributeName);
+ }
+
+ protected String randomString() {
+ //names cannot start with a digit
+ return RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomAlphanumeric(9);
+ }
+
+ protected Referenceable createHiveTableInstanceBuiltIn(String dbName, String tableName, Id dbId) throws Exception {
+ Map<String, Object> values = new HashMap<>();
+ values.put(NAME, dbName);
+ values.put(DESCRIPTION, "foo database");
+ values.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ values.put("owner", "user1");
+ values.put(CLUSTER_NAME, "cl1");
+ values.put("parameters", Collections.EMPTY_MAP);
+ values.put("location", "/tmp");
+ Referenceable databaseInstance = new Referenceable(dbId._getId(), dbId.getTypeName(), values);
+ Referenceable tableInstance =
+ new Referenceable(HIVE_TABLE_TYPE_BUILTIN, "classification", "pii", "phi", "pci", "sox", "sec", "finance");
+ tableInstance.set(NAME, tableName);
+ tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
+ tableInstance.set("db", databaseInstance);
+ tableInstance.set(DESCRIPTION, "bar table");
+ tableInstance.set("lastAccessTime", "2014-07-11T08:00:00.000Z");
+ tableInstance.set("type", "managed");
+ tableInstance.set("level", 2);
+ tableInstance.set("tableType", 1); // enum
+ tableInstance.set("compressed", false);
+
+ Struct traitInstance = (Struct) tableInstance.getTrait("classification");
+ traitInstance.set("tag", "foundation_etl");
+
+ Struct serde1Instance = new Struct("serdeType");
+ serde1Instance.set(NAME, "serde1");
+ serde1Instance.set("serde", "serde1");
+ tableInstance.set("serde1", serde1Instance);
+
+ Struct serde2Instance = new Struct("serdeType");
+ serde2Instance.set(NAME, "serde2");
+ serde2Instance.set("serde", "serde2");
+ tableInstance.set("serde2", serde2Instance);
+
+ List<String> traits = tableInstance.getTraits();
+ Assert.assertEquals(traits.size(), 7);
+
+ return tableInstance;
+ }
+
+ protected AtlasEntity createHiveTableInstanceV2(AtlasEntity databaseInstance, String tableName) throws Exception {
+ AtlasEntity tableInstance = new AtlasEntity(HIVE_TABLE_TYPE_V2);
+ tableInstance.setClassifications(
+ Arrays.asList(new AtlasClassification("classification"),
+ new AtlasClassification("pii"),
+ new AtlasClassification("phi"),
+ new AtlasClassification("pci"),
+ new AtlasClassification("sox"),
+ new AtlasClassification("sec"),
+ new AtlasClassification("finance"))
+ );
+
+ tableInstance.setAttribute(NAME, tableName);
+ tableInstance.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
+ tableInstance.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(databaseInstance));
+ tableInstance.setAttribute(DESCRIPTION, "bar table");
+ tableInstance.setAttribute("lastAccessTime", "2014-07-11T08:00:00.000Z");
+ tableInstance.setAttribute("type", "managed");
+ tableInstance.setAttribute("level", 2);
+ tableInstance.setAttribute("tableType", "MANAGED"); // enum
+ tableInstance.setAttribute("compressed", false);
+
+ AtlasClassification classification = tableInstance.getClassifications().get(0);
+ classification.setAttribute("tag", "foundation_etl");
+
+ AtlasStruct serde1Instance = new AtlasStruct("serdeType");
+ serde1Instance.setAttribute(NAME, "serde1");
+ serde1Instance.setAttribute("serde", "serde1");
+ tableInstance.setAttribute("serde1", serde1Instance);
+
+ AtlasStruct serde2Instance = new AtlasStruct("serdeType");
+ serde2Instance.setAttribute(NAME, "serde2");
+ serde2Instance.setAttribute("serde", "serde2");
+ tableInstance.setAttribute("serde2", serde2Instance);
+
+ List<AtlasClassification> traits = tableInstance.getClassifications();
+ Assert.assertEquals(traits.size(), 7);
+
+ return tableInstance;
+ }
+ protected Referenceable createHiveDBInstanceBuiltIn(String dbName) {
+ Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
+ databaseInstance.set(NAME, dbName);
+ databaseInstance.set(QUALIFIED_NAME, dbName);
+ databaseInstance.set(CLUSTER_NAME, randomString());
+ databaseInstance.set(DESCRIPTION, "foo database");
+ return databaseInstance;
+ }
+
+
+ protected Referenceable createHiveDBInstanceV1(String dbName) {
+ Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
+ databaseInstance.set(NAME, dbName);
+ databaseInstance.set(DESCRIPTION, "foo database");
+ databaseInstance.set(CLUSTER_NAME, "fooCluster");
+ return databaseInstance;
+ }
+
+ protected AtlasEntity createHiveDBInstanceV2(String dbName) {
+ AtlasEntity atlasEntity = new AtlasEntity(DATABASE_TYPE_V2);
+ atlasEntity.setAttribute(NAME, dbName);
+ atlasEntity.setAttribute(DESCRIPTION, "foo database");
+ atlasEntity.setAttribute(CLUSTER_NAME, "fooCluster");
+ atlasEntity.setAttribute("owner", "user1");
+ atlasEntity.setAttribute("locationUri", "/tmp");
+ atlasEntity.setAttribute("createTime",1000);
+ return atlasEntity;
+ }
+
+
+ public interface Predicate {
+
+ /**
+ * Perform a predicate evaluation.
+ *
+ * @return the boolean result of the evaluation.
+ * @throws Exception thrown if the predicate evaluation could not evaluate.
+ */
+ boolean evaluate() throws Exception;
+ }
+
+ public interface NotificationPredicate {
+
+ /**
+ * Perform a predicate evaluation.
+ *
+ * @return the boolean result of the evaluation.
+ * @throws Exception thrown if the predicate evaluation could not evaluate.
+ */
+ boolean evaluate(EntityNotification notification) throws Exception;
+ }
+
+ /**
+ * Wait for a condition, expressed via a {@link Predicate} to become true.
+ *
+ * @param timeout maximum time in milliseconds to wait for the predicate to become true.
+ * @param predicate predicate waiting on.
+ */
+ protected void waitFor(int timeout, Predicate predicate) throws Exception {
+ ParamChecker.notNull(predicate, "predicate");
+ long mustEnd = System.currentTimeMillis() + timeout;
+
+ boolean eval;
+ while (!(eval = predicate.evaluate()) && System.currentTimeMillis() < mustEnd) {
+ LOG.info("Waiting up to {} msec", mustEnd - System.currentTimeMillis());
+ Thread.sleep(100);
+ }
+ if (!eval) {
+ throw new Exception("Waiting timed out after " + timeout + " msec");
+ }
+ }
+
+ protected EntityNotification waitForNotification(final NotificationConsumer<EntityNotification> consumer, int maxWait,
+ final NotificationPredicate predicate) throws Exception {
+ final TypeUtils.Pair<EntityNotification, String> pair = TypeUtils.Pair.of(null, null);
+ final long maxCurrentTime = System.currentTimeMillis() + maxWait;
+ waitFor(maxWait, new Predicate() {
+ @Override
+ public boolean evaluate() throws Exception {
+ try {
+ while (consumer.hasNext() && System.currentTimeMillis() < maxCurrentTime) {
+ EntityNotification notification = consumer.next();
+ if (predicate.evaluate(notification)) {
+ pair.left = notification;
+ return true;
+ }
+ }
+ } catch(ConsumerTimeoutException e) {
+ //ignore
+ }
+ return false;
+ }
+ });
+ return pair.left;
+ }
+
+ protected NotificationPredicate newNotificationPredicate(final EntityNotification.OperationType operationType,
+ final String typeName, final String guid) {
+ return new NotificationPredicate() {
+ @Override
+ public boolean evaluate(EntityNotification notification) throws Exception {
+ return notification != null &&
+ notification.getOperationType() == operationType &&
+ notification.getEntity().getTypeName().equals(typeName) &&
+ notification.getEntity().getId()._getId().equals(guid);
+ }
+ };
+ }
+
+ protected JSONArray searchByDSL(String dslQuery) throws AtlasServiceException {
+ return atlasClientV1.searchByDSL(dslQuery, 10, 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
new file mode 100644
index 0000000..8c6ba77
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/DataSetLineageJerseyResourceIT.java
@@ -0,0 +1,298 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.apache.atlas.AtlasClient;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.Struct;
+import org.apache.atlas.typesystem.json.InstanceSerialization;
+import org.apache.atlas.typesystem.persistence.Id;
+import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
+import org.apache.atlas.typesystem.types.TraitType;
+import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.testng.Assert.assertEquals;
+
+/**
+ * Hive Lineage Integration Tests.
+ */
+public class DataSetLineageJerseyResourceIT extends BaseResourceIT {
+
+ private String salesFactTable;
+ private String salesMonthlyTable;
+ private String salesDBName;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+
+ createTypeDefinitionsV1();
+ setupInstances();
+ }
+
+ @Test
+ public void testInputsGraph() throws Exception {
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_INPUTS_GRAPH, null, salesMonthlyTable, "inputs", "graph");
+ Assert.assertNotNull(response);
+ System.out.println("inputs graph = " + response);
+
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
+ Assert.assertNotNull(results);
+
+ Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
+ Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
+ Assert.assertEquals(vertices.size(), 4);
+
+ Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
+ Assert.assertEquals(edges.size(), 4);
+ }
+
+ @Test
+ public void testInputsGraphForEntity() throws Exception {
+ String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
+ salesMonthlyTable).getId()._getId();
+ JSONObject results = atlasClientV1.getInputGraphForEntity(tableId);
+ Assert.assertNotNull(results);
+
+ Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
+ Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
+ Assert.assertEquals(vertices.size(), 4);
+ Struct vertex = vertices.get(tableId);
+ assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
+
+ Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
+ Assert.assertEquals(edges.size(), 4);
+ }
+
+ @Test
+ public void testOutputsGraph() throws Exception {
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_OUTPUTS_GRAPH, null, salesFactTable, "outputs", "graph");
+ Assert.assertNotNull(response);
+ System.out.println("outputs graph= " + response);
+
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
+ Assert.assertNotNull(results);
+
+ Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
+ Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
+ Assert.assertEquals(vertices.size(), 3);
+
+ Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
+ Assert.assertEquals(edges.size(), 4);
+ }
+
+ @Test
+ public void testOutputsGraphForEntity() throws Exception {
+ String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
+ salesFactTable).getId()._getId();
+ JSONObject results = atlasClientV1.getOutputGraphForEntity(tableId);
+ Assert.assertNotNull(results);
+
+ Struct resultsInstance = InstanceSerialization.fromJsonStruct(results.toString(), true);
+ Map<String, Struct> vertices = (Map<String, Struct>) resultsInstance.get("vertices");
+ Assert.assertEquals(vertices.size(), 3);
+ Struct vertex = vertices.get(tableId);
+ assertEquals(((Struct) vertex.get("vertexId")).get("state"), Id.EntityState.ACTIVE.name());
+
+ Map<String, Struct> edges = (Map<String, Struct>) resultsInstance.get("edges");
+ Assert.assertEquals(edges.size(), 4);
+ }
+
+ @Test
+ public void testSchema() throws Exception {
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.NAME_LINEAGE_SCHEMA, null, salesFactTable, "schema");
+
+ Assert.assertNotNull(response);
+ System.out.println("schema = " + response);
+
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ JSONObject results = response.getJSONObject(AtlasClient.RESULTS);
+ Assert.assertNotNull(results);
+
+ JSONArray rows = results.getJSONArray("rows");
+ Assert.assertEquals(rows.length(), 4);
+
+ for (int index = 0; index < rows.length(); index++) {
+ final JSONObject row = rows.getJSONObject(index);
+ LOG.info("JsonRow - {}", row);
+ Assert.assertNotNull(row.getString("name"));
+ Assert.assertNotNull(row.getString("comment"));
+ Assert.assertEquals(row.getString("$typeName$"), "hive_column_v1");
+ }
+ }
+
+ @Test
+ public void testSchemaForEntity() throws Exception {
+ String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
+ JSONObject results = atlasClientV1.getSchemaForEntity(tableId);
+ Assert.assertNotNull(results);
+
+ JSONArray rows = results.getJSONArray("rows");
+ Assert.assertEquals(rows.length(), 4);
+
+ for (int index = 0; index < rows.length(); index++) {
+ final JSONObject row = rows.getJSONObject(index);
+ LOG.info("JsonRow - {}", row);
+ Assert.assertNotNull(row.getString("name"));
+ Assert.assertNotNull(row.getString("comment"));
+ Assert.assertEquals(row.getString("$typeName$"), "hive_column_v1");
+ }
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testSchemaForInvalidTable() throws Exception {
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.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");
+ }
+
+ private void setupInstances() throws Exception {
+ HierarchicalTypeDefinition<TraitType> factTrait =
+ TypesUtil.createTraitTypeDef("Fact", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> etlTrait =
+ TypesUtil.createTraitTypeDef("ETL", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> dimensionTrait =
+ TypesUtil.createTraitTypeDef("Dimension", ImmutableSet.<String>of());
+ HierarchicalTypeDefinition<TraitType> metricTrait =
+ TypesUtil.createTraitTypeDef("Metric", ImmutableSet.<String>of());
+ createType(getTypesDef(null, null,
+ ImmutableList.of(factTrait, etlTrait, dimensionTrait, metricTrait), null));
+
+ salesDBName = "Sales" + randomString();
+ Id salesDB = database(salesDBName, "Sales Database", "John ETL",
+ "hdfs://host:8000/apps/warehouse/sales");
+
+ List<Referenceable> salesFactColumns = ImmutableList
+ .of(column("time_id", "int", "time id"), column("product_id", "int", "product id"),
+ column("customer_id", "int", "customer id", "pii"),
+ column("sales", "double", "product id", "Metric"));
+
+ salesFactTable = "sales_fact" + randomString();
+ Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns, "Fact");
+
+ List<Referenceable> timeDimColumns = ImmutableList
+ .of(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"),
+ column("weekDay", "int", "week Day"));
+
+ Id timeDim =
+ table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL",
+ timeDimColumns, "Dimension");
+
+ Id reportingDB =
+ database("Reporting" + randomString(), "reporting database", "Jane BI",
+ "hdfs://host:8000/apps/warehouse/reporting");
+
+ Id salesFactDaily =
+ table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB,
+ "Joe BI", "MANAGED", salesFactColumns, "Metric");
+
+ loadProcess("loadSalesDaily" + randomString(), "John ETL", ImmutableList.of(salesFact, timeDim),
+ ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph", "ETL");
+
+ salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
+ Id salesFactMonthly =
+ table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI",
+ "MANAGED", salesFactColumns, "Metric");
+
+ loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily),
+ ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph", "ETL");
+ }
+
+ Id database(String name, String description, String owner, String locationUri, String... traitNames)
+ throws Exception {
+ Referenceable referenceable = new Referenceable(DATABASE_TYPE, traitNames);
+ referenceable.set(NAME, name);
+ referenceable.set(QUALIFIED_NAME, name);
+ referenceable.set(CLUSTER_NAME, locationUri + name);
+ referenceable.set("description", description);
+ referenceable.set("owner", owner);
+ referenceable.set("locationUri", locationUri);
+ referenceable.set("createTime", System.currentTimeMillis());
+
+ return createInstance(referenceable);
+ }
+
+ Referenceable column(String name, String type, String comment, String... traitNames) throws Exception {
+ Referenceable referenceable = new Referenceable(COLUMN_TYPE, traitNames);
+ referenceable.set(NAME, name);
+ referenceable.set(QUALIFIED_NAME, name);
+ referenceable.set("type", type);
+ referenceable.set("comment", comment);
+
+ return referenceable;
+ }
+
+ Id table(String name, String description, Id dbId, String owner, String tableType, List<Referenceable> columns,
+ String... traitNames) throws Exception {
+ Referenceable referenceable = new Referenceable(HIVE_TABLE_TYPE, traitNames);
+ referenceable.set("name", name);
+ referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
+ referenceable.set("description", description);
+ referenceable.set("owner", owner);
+ referenceable.set("tableType", tableType);
+ referenceable.set("createTime", System.currentTimeMillis());
+ referenceable.set("lastAccessTime", System.currentTimeMillis());
+ referenceable.set("retention", System.currentTimeMillis());
+
+ referenceable.set("db", dbId);
+ referenceable.set("columns", columns);
+
+ return createInstance(referenceable);
+ }
+
+ Id loadProcess(String name, String user, List<Id> inputTables, List<Id> outputTables, String queryText,
+ String queryPlan, String queryId, String queryGraph, String... traitNames) throws Exception {
+ Referenceable referenceable = new Referenceable(HIVE_PROCESS_TYPE, traitNames);
+ referenceable.set("name", name);
+ referenceable.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name);
+ referenceable.set("userName", user);
+ referenceable.set("startTime", System.currentTimeMillis());
+ referenceable.set("endTime", System.currentTimeMillis() + 10000);
+
+ referenceable.set("inputs", inputTables);
+ referenceable.set("outputs", outputTables);
+
+ referenceable.set("operationType", "testOperation");
+ referenceable.set("queryText", queryText);
+ referenceable.set("queryPlan", queryPlan);
+ referenceable.set("queryId", queryId);
+ referenceable.set("queryGraph", queryGraph);
+
+ return createInstance(referenceable);
+ }
+}
[10/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
index 70a904b..27c0b5d 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
@@ -18,11 +18,9 @@
package org.apache.atlas.repository.store.graph.v1;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
import org.apache.atlas.AtlasErrorCode;
-import org.apache.atlas.GraphTransaction;
import org.apache.atlas.RequestContextV1;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.impexp.AtlasImportResult;
import org.apache.atlas.model.instance.AtlasClassification;
@@ -47,7 +45,9 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -61,19 +61,22 @@ import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.DE
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.UPDATE;
-@Singleton
+@Component
public class AtlasEntityStoreV1 implements AtlasEntityStore {
private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityStoreV1.class);
private final DeleteHandlerV1 deleteHandler;
private final AtlasTypeRegistry typeRegistry;
private final AtlasEntityChangeNotifier entityChangeNotifier;
+ private final EntityGraphMapper entityGraphMapper;
@Inject
- public AtlasEntityStoreV1(DeleteHandlerV1 deleteHandler, AtlasTypeRegistry typeRegistry, AtlasEntityChangeNotifier entityChangeNotifier) {
+ public AtlasEntityStoreV1(DeleteHandlerV1 deleteHandler, AtlasTypeRegistry typeRegistry,
+ AtlasEntityChangeNotifier entityChangeNotifier, EntityGraphMapper entityGraphMapper) {
this.deleteHandler = deleteHandler;
this.typeRegistry = typeRegistry;
this.entityChangeNotifier = entityChangeNotifier;
+ this.entityGraphMapper = entityGraphMapper;
}
@Override
@@ -143,6 +146,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
}
@Override
+ @GraphTransaction
public EntityMutationResponse bulkImport(EntityImportStream entityStream, AtlasImportResult importResult) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> bulkImport()");
@@ -208,7 +212,6 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
}
}
- @GraphTransaction
private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate, boolean replaceClassifications) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> createOrUpdate()");
@@ -219,8 +222,6 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
}
// Create/Update entities
- EntityGraphMapper entityGraphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
-
EntityMutationContext context = preCreateOrUpdate(entityStream, entityGraphMapper, isPartialUpdate);
EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate, replaceClassifications);
@@ -238,6 +239,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
}
@Override
+ @GraphTransaction
public EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate) throws AtlasBaseException {
return createOrUpdate(entityStream, isPartialUpdate, false);
}
@@ -315,6 +317,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
return createOrUpdate(new AtlasEntityStream(updateEntity), true);
}
+ @Override
@GraphTransaction
public EntityMutationResponse deleteById(final String guid) throws AtlasBaseException {
@@ -432,8 +435,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
// validate if entity, not already associated with classifications
validateEntityAssociations(guid, classifications);
- EntityGraphMapper graphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
- graphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
+ entityGraphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
// notify listeners on classification addition
entityChangeNotifier.onClassificationAddedToEntity(guid, classifications);
@@ -454,7 +456,6 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "classifications(s) not specified");
}
- EntityGraphMapper graphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
List<AtlasClassification> updatedClassifications = new ArrayList<>();
for (AtlasClassification newClassification : newClassifications) {
@@ -475,7 +476,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
}
}
- graphMapper.updateClassification(new EntityMutationContext(), guid, oldClassification);
+ entityGraphMapper.updateClassification(new EntityMutationContext(), guid, oldClassification);
updatedClassifications.add(oldClassification);
}
@@ -498,8 +499,6 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
LOG.debug("Adding classification={} to entities={}", classification, guids);
}
- EntityGraphMapper graphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
-
validateAndNormalize(classification);
List<AtlasClassification> classifications = Collections.singletonList(classification);
@@ -508,7 +507,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
// validate if entity, not already associated with classifications
validateEntityAssociations(guid, classifications);
- graphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
+ entityGraphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
// notify listeners on classification addition
entityChangeNotifier.onClassificationAddedToEntity(guid, classifications);
@@ -530,7 +529,6 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
LOG.debug("Deleting classifications={} from entity={}", classificationNames, guid);
}
- EntityGraphMapper entityGraphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
entityGraphMapper.deleteClassifications(guid, classificationNames);
// notify listeners on classification deletion
@@ -569,7 +567,7 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
AtlasEntity entity = entityStream.getByGuid(guid);
if (entity != null) {
-
+
if (vertex != null) {
// entity would be null if guid is not in the stream but referenced by an entity in the stream
if (!isPartialUpdate) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStream.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStream.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStream.java
index eb860ff..d6d6272 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStream.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStream.java
@@ -18,8 +18,8 @@
package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.model.instance.AtlasEntity;
-import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
+import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import java.util.Iterator;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
index 3bf318f..f0c8380 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java
@@ -19,14 +19,11 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
-import com.google.inject.Inject;
-
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.repository.Constants;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.atlas.repository.graphdb.AtlasGraph;
@@ -43,7 +40,11 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
@@ -59,15 +60,19 @@ import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.VERTE
/**
* Graph persistence store for TypeDef - v1
*/
+@Singleton
+@Component
public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStoreV1.class);
- protected final AtlasGraph atlasGraph = AtlasGraphProvider.getGraphInstance();
+ protected final AtlasGraph atlasGraph;
@Inject
public AtlasTypeDefGraphStoreV1(AtlasTypeRegistry typeRegistry,
- Set<TypeDefChangeListener> typeDefChangeListeners) {
+ Set<TypeDefChangeListener> typeDefChangeListeners,
+ AtlasGraph atlasGraph) {
super(typeRegistry, typeDefChangeListeners);
+ this.atlasGraph = atlasGraph;
LOG.debug("==> AtlasTypeDefGraphStoreV1()");
@@ -105,6 +110,7 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
}
@Override
+ @PostConstruct
public void init() throws AtlasBaseException {
LOG.debug("==> AtlasTypeDefGraphStoreV1.init()");
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
index 0fe748e..80cd1ee 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
@@ -18,7 +18,6 @@
package org.apache.atlas.repository.store.graph.v1;
-import com.google.inject.Inject;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.RequestContextV1;
@@ -29,9 +28,8 @@ import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasStruct;
-import org.apache.atlas.model.instance.EntityMutations;
-import org.apache.atlas.model.instance.EntityMutations.EntityOperation;
import org.apache.atlas.model.instance.EntityMutationResponse;
+import org.apache.atlas.model.instance.EntityMutations.EntityOperation;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.RepositoryException;
@@ -45,48 +43,42 @@ import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasMapType;
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.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import javax.inject.Inject;
+import java.util.*;
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.CREATE;
+import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.DELETE;
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.PARTIAL_UPDATE;
import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.UPDATE;
-import static org.apache.atlas.model.instance.EntityMutations.EntityOperation.DELETE;
import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY;
import static org.apache.atlas.repository.graph.GraphHelper.string;
-
+@Component
public class EntityGraphMapper {
private static final Logger LOG = LoggerFactory.getLogger(EntityGraphMapper.class);
- private final AtlasGraph graph = AtlasGraphProvider.getGraphInstance();
private final GraphHelper graphHelper = GraphHelper.getInstance();
+ private final AtlasGraph graph;
private final DeleteHandlerV1 deleteHandler;
private final AtlasTypeRegistry typeRegistry;
@Inject
- public EntityGraphMapper(DeleteHandlerV1 deleteHandler, AtlasTypeRegistry typeRegistry) {
+ public EntityGraphMapper(DeleteHandlerV1 deleteHandler, AtlasTypeRegistry typeRegistry, AtlasGraph atlasGraph) {
this.deleteHandler = deleteHandler;
this.typeRegistry = typeRegistry;
+ this.graph = atlasGraph;
}
public AtlasVertex createVertex(AtlasEntity entity) {
@@ -284,7 +276,7 @@ public class EntityGraphMapper {
}
private Object mapToVertexByTypeCategory(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
- if (ctx.getOp() == EntityMutations.EntityOperation.CREATE && ctx.getValue() == null) {
+ if (ctx.getOp() == CREATE && ctx.getValue() == null) {
return null;
}
@@ -509,7 +501,7 @@ public class EntityGraphMapper {
try {
AtlasAttribute attribute = ctx.getAttribute();
- List<String> currentKeys = GraphHelper.getListProperty(ctx.getReferringVertex(), ctx.getVertexProperty());
+ List<String> currentKeys = GraphHelper.getListProperty(ctx.getReferringVertex(), ctx.getVertexProperty());
Map<String, Object> currentMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(currentKeys)) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 da6d636..66f20da 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
@@ -289,16 +289,16 @@ public final class EntityGraphRetriever {
List<String> classificationNames = GraphHelper.getTraitNames(instanceVertex);
if (CollectionUtils.isNotEmpty(classificationNames)) {
- for (String classficationName : classificationNames) {
- AtlasClassification classification = null;
+ for (String classificationName : classificationNames) {
+ AtlasClassification classification;
if (StringUtils.isNotEmpty(classificationNameFilter)) {
- if (classficationName.equals(classificationNameFilter)) {
- classification = getClassification(instanceVertex, classficationName);
+ if (classificationName.equals(classificationNameFilter)) {
+ classification = getClassification(instanceVertex, classificationName);
classifications.add(classification);
return classifications;
}
} else {
- classification = getClassification(instanceVertex, classficationName);
+ classification = getClassification(instanceVertex, classificationName);
classifications.add(classification);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
index f51238a..29518c4 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1.java
@@ -18,12 +18,17 @@
package org.apache.atlas.repository.store.graph.v1;
-import com.google.inject.Inject;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasTypeRegistry;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
+
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.DeleteHandlerV1.impl")
public class HardDeleteHandlerV1 extends DeleteHandlerV1 {
@Inject
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
index 31bb24a..49c9e0c 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1.java
@@ -18,21 +18,24 @@
package org.apache.atlas.repository.store.graph.v1;
-import com.google.inject.Inject;
import org.apache.atlas.RequestContextV1;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
-import org.apache.atlas.RequestContext;
import org.apache.atlas.type.AtlasTypeRegistry;
-import org.apache.atlas.typesystem.persistence.Id;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
import static org.apache.atlas.repository.Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.MODIFIED_BY_KEY;
import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY;
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.DeleteHandlerV1.impl", isDefault = true)
public class SoftDeleteHandlerV1 extends DeleteHandlerV1 {
@Inject
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
index c80639a..50eee72 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
@@ -20,31 +20,22 @@ package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
-import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
-import org.apache.atlas.repository.Constants;
-import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext;
import org.apache.atlas.repository.store.graph.EntityResolver;
import org.apache.atlas.type.AtlasEntityType;
-import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasTypeRegistry;
-import org.apache.atlas.typesystem.exception.EntityNotFoundException;
-import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
public class UniqAttrBasedEntityResolver implements EntityResolver {
private static final Logger LOG = LoggerFactory.getLogger(UniqAttrBasedEntityResolver.class);
- private final static GraphHelper graphHelper = GraphHelper.getInstance();
-
private final AtlasTypeRegistry typeRegistry;
public UniqAttrBasedEntityResolver(AtlasTypeRegistry typeRegistry) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java b/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java
index ac13586..7a064b6 100644
--- a/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java
@@ -22,13 +22,10 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.GraphTransaction;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.RepositoryException;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
@@ -41,7 +38,10 @@ import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.codehaus.jettison.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -53,6 +53,7 @@ import java.util.Set;
import static org.apache.atlas.repository.graph.GraphHelper.setProperty;
@Singleton
+@Component
@Deprecated
public class GraphBackedTypeStore implements ITypeStore {
public static final String VERTEX_TYPE = "typeSystem";
@@ -66,8 +67,8 @@ public class GraphBackedTypeStore implements ITypeStore {
private GraphHelper graphHelper = GraphHelper.getInstance();
@Inject
- public GraphBackedTypeStore() {
- graph = AtlasGraphProvider.getGraphInstance();
+ public GraphBackedTypeStore(AtlasGraph atlasGraph) {
+ this.graph = atlasGraph;
}
@Override
@@ -123,7 +124,7 @@ public class GraphBackedTypeStore implements ITypeStore {
List<AtlasVertex> vertices = createVertices(typeVerticesNeeded);
//Create a type name->AtlasVertex map with the result
- Map<String, AtlasVertex> result = new HashMap<String,AtlasVertex>(typeVerticesNeeded.size());
+ Map<String, AtlasVertex> result = new HashMap<>(typeVerticesNeeded.size());
for(int i = 0 ; i < typeVerticesNeeded.size(); i++) {
TypeVertexInfo createdVertexInfo = typeVerticesNeeded.get(i);
AtlasVertex createdVertex = vertices.get(i);
@@ -357,7 +358,6 @@ public class GraphBackedTypeStore implements ITypeStore {
List<AtlasVertex> result = new ArrayList<>(infoList.size());
List<String> typeNames = Lists.transform(infoList, new Function<TypeVertexInfo,String>() {
-
@Override
public String apply(TypeVertexInfo input) {
return input.getTypeName();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java b/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java
index 8573719..f472fa6 100644
--- a/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java
+++ b/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java
@@ -17,14 +17,9 @@
*/
package org.apache.atlas.repository.typestore;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.collect.ImmutableList;
import org.apache.atlas.AtlasException;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.types.AttributeDefinition;
import org.apache.atlas.typesystem.types.ClassType;
@@ -38,10 +33,16 @@ import org.apache.atlas.typesystem.types.TypeSystem.TransientTypeSystem;
import org.apache.atlas.typesystem.types.TypeUtils;
import org.apache.atlas.typesystem.types.cache.DefaultTypeCache;
import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.springframework.stereotype.Component;
-import com.google.common.collect.ImmutableList;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
@@ -52,7 +53,9 @@ import com.google.inject.Singleton;
* are also loaded from the store if they are not already in the cache.
*/
@Singleton
+@Component
@Deprecated
+@ConditionalOnAtlasProperty(property = "atlas.TypeCache.impl")
public class StoreBackedTypeCache extends DefaultTypeCache {
private ITypeStore typeStore;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
index fd85ef0..99d2107 100755
--- a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
+++ b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java
@@ -20,8 +20,6 @@ package org.apache.atlas.services;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
-import com.google.inject.Provider;
-import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
@@ -35,6 +33,7 @@ import org.apache.atlas.listener.ChangedTypeDefs;
import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.listener.TypesChangeListener;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.audit.EntityAuditRepository;
@@ -54,16 +53,7 @@ import org.apache.atlas.typesystem.json.InstanceSerialization;
import org.apache.atlas.typesystem.json.TypesSerialization;
import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.typesystem.persistence.ReferenceableInstance;
-import org.apache.atlas.typesystem.types.AttributeInfo;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.EnumTypeDefinition;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.IDataType;
-import org.apache.atlas.typesystem.types.Multiplicity;
-import org.apache.atlas.typesystem.types.StructTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.TypeSystem;
+import org.apache.atlas.typesystem.types.*;
import org.apache.atlas.typesystem.types.cache.TypeCache;
import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.configuration.Configuration;
@@ -71,6 +61,7 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -80,6 +71,7 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
@@ -88,6 +80,7 @@ import java.util.Map;
* for listening to changes to the repository.
*/
@Singleton
+@Component
@Deprecated
public class DefaultMetadataService implements MetadataService, ActiveStateChangeHandler, TypeDefChangeListener {
private enum OperationType {
@@ -106,24 +99,16 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
private final Collection<TypesChangeListener> typeChangeListeners = new LinkedHashSet<>();
private final Collection<EntityChangeListener> entityChangeListeners = new LinkedHashSet<>();
- @Inject
private EntityAuditRepository auditRepository;
@Inject
- DefaultMetadataService(final MetadataRepository repository, final ITypeStore typeStore,
- final Collection<Provider<TypesChangeListener>> typeListenerProviders,
- final Collection<Provider<EntityChangeListener>> entityListenerProviders, TypeCache typeCache)
- throws AtlasException {
- this(repository, typeStore, typeListenerProviders, entityListenerProviders,
- TypeSystem.getInstance(), ApplicationProperties.get(), typeCache);
- }
-
- //for testing only
public DefaultMetadataService(final MetadataRepository repository, final ITypeStore typeStore,
- final Collection<Provider<TypesChangeListener>> typeListenerProviders,
- final Collection<Provider<EntityChangeListener>> entityListenerProviders,
- final TypeSystem typeSystem,
- final Configuration configuration, TypeCache typeCache) throws AtlasException {
+ final Set<TypesChangeListener> typesChangeListeners,
+ final Set<EntityChangeListener> entityChangeListeners,
+ final TypeSystem typeSystem,
+ final Configuration configuration,
+ TypeCache typeCache,
+ EntityAuditRepository auditRepository) throws AtlasException {
this.typeStore = typeStore;
this.typeSystem = typeSystem;
/**
@@ -139,19 +124,17 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
this.repository = repository;
- for (Provider<TypesChangeListener> provider : typeListenerProviders) {
- typeChangeListeners.add(provider.get());
- }
+ this.typeChangeListeners.addAll(typesChangeListeners);
- for (Provider<EntityChangeListener> provider : entityListenerProviders) {
- entityChangeListeners.add(provider.get());
- }
+ this.entityChangeListeners.addAll(entityChangeListeners);
if (!HAConfiguration.isHAEnabled(configuration)) {
restoreTypeSystem();
}
maxAuditResults = configuration.getShort(CONFIG_MAX_AUDIT_RESULTS, DEFAULT_MAX_AUDIT_RESULTS);
+
+ this.auditRepository = auditRepository;
}
private void restoreTypeSystem() throws AtlasException {
@@ -313,7 +296,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
public ITypedReferenceableInstance[] deserializeClassInstances(String entityInstanceDefinition) throws AtlasException {
return GraphHelper.deserializeClassInstances(typeSystem, entityInstanceDefinition);
}
-
+
@Override
public ITypedReferenceableInstance getTypedReferenceableInstance(Referenceable entityInstance) throws AtlasException {
return GraphHelper.getTypedReferenceableInstance(typeSystem, entityInstance);
@@ -356,7 +339,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
return repository.getEntityDefinition(entityType, attribute, value);
}
- @Override
+ @Override
public String getEntityDefinition(String entityType, String attribute, String value) throws AtlasException {
final ITypedReferenceableInstance instance = getEntityDefinitionReference(entityType, attribute, value);
return InstanceSerialization.toJson(instance, true);
@@ -422,7 +405,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
return result;
}
- private void onEntitiesAddedUpdated(AtlasClient.EntityResult entityResult) throws AtlasException {
+ private void onEntitiesAddedUpdated(EntityResult entityResult) throws AtlasException {
onEntitiesAdded(entityResult.getCreatedEntities());
onEntitiesUpdated(entityResult.getUpdateEntities());
//Note: doesn't access deletedEntities from entityResult
@@ -635,8 +618,8 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
// ensure trait is not already defined
Preconditions
- .checkArgument(!getTraitNames(guid).contains(traitName), "trait=%s is already defined for entity=%s",
- traitName, guid);
+ .checkArgument(!getTraitNames(guid).contains(traitName), "trait=%s is already defined for entity=%s",
+ traitName, guid);
repository.addTrait(guid, traitInstance);
@@ -644,7 +627,7 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
}
private ITypedStruct deserializeTraitInstance(String traitInstanceDefinition)
- throws AtlasException {
+ throws AtlasException {
return createTraitInstance(InstanceSerialization.fromJsonStruct(traitInstanceDefinition, true));
}
@@ -762,14 +745,14 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
* @see org.apache.atlas.services.MetadataService#deleteEntities(java.lang.String)
*/
@Override
- public AtlasClient.EntityResult deleteEntities(List<String> deleteCandidateGuids) throws AtlasException {
+ public EntityResult deleteEntities(List<String> deleteCandidateGuids) throws AtlasException {
ParamChecker.notEmpty(deleteCandidateGuids, "delete candidate guids");
return deleteGuids(deleteCandidateGuids);
}
@Override
- public AtlasClient.EntityResult deleteEntityByUniqueAttribute(String typeName, String uniqueAttributeName,
- String attrValue) throws AtlasException {
+ public EntityResult deleteEntityByUniqueAttribute(String typeName, String uniqueAttributeName,
+ String attrValue) throws AtlasException {
typeName = ParamChecker.notEmpty(typeName, "delete candidate typeName");
uniqueAttributeName = ParamChecker.notEmpty(uniqueAttributeName, "delete candidate unique attribute name");
attrValue = ParamChecker.notEmpty(attrValue, "delete candidate unique attribute value");
@@ -782,8 +765,8 @@ public class DefaultMetadataService implements MetadataService, ActiveStateChang
return deleteGuids(deleteCandidateGuids);
}
- private AtlasClient.EntityResult deleteGuids(List<String> deleteCandidateGuids) throws AtlasException {
- AtlasClient.EntityResult entityResult = repository.deleteEntities(deleteCandidateGuids);
+ private EntityResult deleteGuids(List<String> deleteCandidateGuids) throws AtlasException {
+ EntityResult entityResult = repository.deleteEntities(deleteCandidateGuids);
onEntitiesAddedUpdated(entityResult);
return entityResult;
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/services/MetricsService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/services/MetricsService.java b/repository/src/main/java/org/apache/atlas/services/MetricsService.java
index e3bedb8..0fa68b2 100644
--- a/repository/src/main/java/org/apache/atlas/services/MetricsService.java
+++ b/repository/src/main/java/org/apache/atlas/services/MetricsService.java
@@ -18,12 +18,11 @@
package org.apache.atlas.services;
import com.google.common.annotations.VisibleForTesting;
-import com.google.inject.Singleton;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
+import org.apache.atlas.annotation.AtlasService;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.metrics.AtlasMetrics;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.util.AtlasGremlinQueryProvider;
import org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery;
@@ -35,7 +34,7 @@ import javax.inject.Inject;
import java.util.List;
import java.util.Map;
-@Singleton
+@AtlasService
public class MetricsService {
private static final Logger LOG = LoggerFactory.getLogger(MetricsService.class);
@@ -75,8 +74,8 @@ public class MetricsService {
@Inject
- public MetricsService() throws AtlasException {
- this(ApplicationProperties.get(), AtlasGraphProvider.getGraphInstance());
+ public MetricsService(AtlasGraph atlasGraph) throws AtlasException {
+ this(ApplicationProperties.get(), atlasGraph);
}
@VisibleForTesting
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java b/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java
index a4a596a..09f366e 100644
--- a/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java
+++ b/repository/src/main/java/org/apache/atlas/util/AtlasRepositoryConfiguration.java
@@ -17,18 +17,13 @@
*/
package org.apache.atlas.util;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.atlas.repository.audit.EntityAuditRepository;
import org.apache.atlas.repository.audit.HBaseBasedAuditRepository;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.DeleteHandler;
import org.apache.atlas.repository.graph.SoftDeleteHandler;
import org.apache.atlas.repository.graphdb.GraphDatabase;
-import org.apache.atlas.repository.graphdb.GremlinVersion;
import org.apache.atlas.repository.store.graph.v1.DeleteHandlerV1;
import org.apache.atlas.repository.store.graph.v1.SoftDeleteHandlerV1;
import org.apache.atlas.typesystem.types.cache.DefaultTypeCache;
@@ -37,6 +32,9 @@ import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Atlas configuration for repository project
*
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java b/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
index a7cb2e5..7c6b60b 100644
--- a/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
+++ b/repository/src/test/java/org/apache/atlas/BaseRepositoryTest.java
@@ -21,7 +21,6 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.repository.MetadataRepository;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasTypeRegistry;
@@ -45,7 +44,7 @@ import static org.apache.atlas.AtlasClient.PROCESS_ATTRIBUTE_OUTPUTS;
/**
* Base Class to set up hive types and instances for tests
*/
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class BaseRepositoryTest {
@Inject
@@ -70,7 +69,6 @@ public class BaseRepositoryTest {
protected void tearDown() throws Exception {
TypeSystem.getInstance().reset();
- AtlasGraphProvider.cleanup();
}
private void setUpTypes() throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/RepositoryServiceLoadingTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/RepositoryServiceLoadingTest.java b/repository/src/test/java/org/apache/atlas/RepositoryServiceLoadingTest.java
index 01081da..506d11c 100755
--- a/repository/src/test/java/org/apache/atlas/RepositoryServiceLoadingTest.java
+++ b/repository/src/test/java/org/apache/atlas/RepositoryServiceLoadingTest.java
@@ -29,7 +29,7 @@ import org.testng.annotations.Test;
* Uses TestNG's Guice annotation to load the necessary modules and inject the
* objects from Guice
*/
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class RepositoryServiceLoadingTest {
@Test
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/TestModules.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/TestModules.java b/repository/src/test/java/org/apache/atlas/TestModules.java
new file mode 100644
index 0000000..095af41
--- /dev/null
+++ b/repository/src/test/java/org/apache/atlas/TestModules.java
@@ -0,0 +1,231 @@
+/**
+ * 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.inject.Binder;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.matcher.Matchers;
+import com.google.inject.multibindings.Multibinder;
+import org.apache.atlas.annotation.GraphTransaction;
+import org.apache.atlas.discovery.AtlasDiscoveryService;
+import org.apache.atlas.discovery.AtlasLineageService;
+import org.apache.atlas.discovery.DataSetLineageService;
+import org.apache.atlas.discovery.DiscoveryService;
+import org.apache.atlas.discovery.EntityDiscoveryService;
+import org.apache.atlas.discovery.EntityLineageService;
+import org.apache.atlas.discovery.LineageService;
+import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
+import org.apache.atlas.graph.GraphSandboxUtil;
+import org.apache.atlas.listener.EntityChangeListener;
+import org.apache.atlas.listener.TypeDefChangeListener;
+import org.apache.atlas.listener.TypesChangeListener;
+import org.apache.atlas.repository.MetadataRepository;
+import org.apache.atlas.repository.audit.EntityAuditListener;
+import org.apache.atlas.repository.audit.EntityAuditRepository;
+import org.apache.atlas.repository.graph.DeleteHandler;
+import org.apache.atlas.repository.graph.GraphBackedMetadataRepository;
+import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
+import org.apache.atlas.repository.graph.HardDeleteHandler;
+import org.apache.atlas.repository.graph.SoftDeleteHandler;
+import org.apache.atlas.repository.graphdb.AtlasGraph;
+import org.apache.atlas.repository.impexp.ExportService;
+import org.apache.atlas.repository.store.graph.AtlasEntityDefStore;
+import org.apache.atlas.repository.store.graph.AtlasEntityStore;
+import org.apache.atlas.repository.store.graph.v1.AtlasEntityChangeNotifier;
+import org.apache.atlas.repository.store.graph.v1.AtlasEntityDefStoreV1;
+import org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1;
+import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
+import org.apache.atlas.repository.store.graph.v1.DeleteHandlerV1;
+import org.apache.atlas.repository.store.graph.v1.EntityGraphMapper;
+import org.apache.atlas.repository.store.graph.v1.HardDeleteHandlerV1;
+import org.apache.atlas.repository.store.graph.v1.SoftDeleteHandlerV1;
+import org.apache.atlas.repository.typestore.GraphBackedTypeStore;
+import org.apache.atlas.repository.typestore.ITypeStore;
+import org.apache.atlas.repository.typestore.StoreBackedTypeCache;
+import org.apache.atlas.service.Service;
+import org.apache.atlas.services.DefaultMetadataService;
+import org.apache.atlas.services.MetadataService;
+import org.apache.atlas.store.AtlasTypeDefStore;
+import org.apache.atlas.type.AtlasTypeRegistry;
+import org.apache.atlas.typesystem.types.TypeSystem;
+import org.apache.atlas.typesystem.types.cache.TypeCache;
+import org.apache.atlas.util.AtlasRepositoryConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.mockito.Mockito;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestModules {
+
+ static class MockNotifier implements Provider<AtlasEntityChangeNotifier> {
+ @Override
+ public AtlasEntityChangeNotifier get() {
+ return Mockito.mock(AtlasEntityChangeNotifier.class);
+ }
+ }
+
+ // Test only DI modules
+ public static class TestOnlyModule extends com.google.inject.AbstractModule {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestOnlyModule.class);
+
+ static class TypeSystemProvider implements Provider<TypeSystem> {
+ @Override
+ public TypeSystem get() {
+ return TypeSystem.getInstance();
+ }
+ }
+
+ static class AtlasConfigurationProvider implements Provider<Configuration> {
+
+ @Override
+ public Configuration get() {
+ try {
+ return ApplicationProperties.get();
+ } catch (AtlasException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static class AtlasGraphProvider implements Provider<AtlasGraph> {
+ @Override
+ public AtlasGraph get() {
+ return org.apache.atlas.repository.graph.AtlasGraphProvider.getGraphInstance();
+ }
+ }
+
+ @Override
+ protected void configure() {
+ GraphSandboxUtil.create();
+
+ bindAuditRepository(binder());
+
+ bindDeleteHandler(binder());
+
+ bind(AtlasGraph.class).toProvider(AtlasGraphProvider.class);
+
+ // allow for dynamic binding of the metadata repo & graph service
+ // bind the MetadataRepositoryService interface to an implementation
+ bind(MetadataRepository.class).to(GraphBackedMetadataRepository.class).asEagerSingleton();
+
+ bind(TypeSystem.class).toProvider(TypeSystemProvider.class).in(Singleton.class);
+ bind(Configuration.class).toProvider(AtlasConfigurationProvider.class).in(Singleton.class);
+
+ // bind the ITypeStore interface to an implementation
+ bind(ITypeStore.class).to(GraphBackedTypeStore.class).asEagerSingleton();
+ bind(AtlasTypeDefStore.class).to(AtlasTypeDefGraphStoreV1.class).asEagerSingleton();
+
+ //For testing
+ bind(AtlasEntityDefStore.class).to(AtlasEntityDefStoreV1.class).asEagerSingleton();
+ bind(AtlasTypeRegistry.class).asEagerSingleton();
+ bind(EntityGraphMapper.class).asEagerSingleton();
+ bind(ExportService.class).asEagerSingleton();
+
+ //GraphBackedSearchIndexer must be an eager singleton to force the search index creation to happen before
+ //we try to restore the type system (otherwise we'll end up running queries
+ //before we have any indices during the initial graph setup)
+ Multibinder<TypesChangeListener> typesChangeListenerBinder =
+ Multibinder.newSetBinder(binder(), TypesChangeListener.class);
+ typesChangeListenerBinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton();
+
+ // New typesdef/instance change listener should also be bound to the corresponding implementation
+ Multibinder<TypeDefChangeListener> typeDefChangeListenerMultibinder =
+ Multibinder.newSetBinder(binder(), TypeDefChangeListener.class);
+ typeDefChangeListenerMultibinder.addBinding().to(DefaultMetadataService.class);
+ typeDefChangeListenerMultibinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton();
+
+ bind(AtlasEntityStore.class).to(AtlasEntityStoreV1.class);
+
+ // bind the MetadataService interface to an implementation
+ bind(MetadataService.class).to(DefaultMetadataService.class).asEagerSingleton();
+
+ // bind the DiscoveryService interface to an implementation
+ bind(DiscoveryService.class).to(GraphBackedDiscoveryService.class).asEagerSingleton();
+ bind(AtlasDiscoveryService.class).to(EntityDiscoveryService.class).asEagerSingleton();
+
+ bind(LineageService.class).to(DataSetLineageService.class).asEagerSingleton();
+ bind(AtlasLineageService.class).to(EntityLineageService.class).asEagerSingleton();
+
+ bindTypeCache();
+
+ //Add EntityAuditListener as EntityChangeListener
+ Multibinder<EntityChangeListener> entityChangeListenerBinder =
+ Multibinder.newSetBinder(binder(), EntityChangeListener.class);
+ entityChangeListenerBinder.addBinding().to(EntityAuditListener.class);
+
+ final GraphTransactionInterceptor graphTransactionInterceptor = new GraphTransactionInterceptor(new AtlasGraphProvider().get());
+ requestInjection(graphTransactionInterceptor);
+ bindInterceptor(Matchers.any(), Matchers.annotatedWith(GraphTransaction.class), graphTransactionInterceptor);
+ }
+
+ protected void bindTypeCache() {
+ bind(TypeCache.class).to(AtlasRepositoryConfiguration.getTypeCache()).asEagerSingleton();
+ }
+
+ protected void bindDeleteHandler(Binder binder) {
+ binder.bind(DeleteHandler.class).to(AtlasRepositoryConfiguration.getDeleteHandlerImpl()).asEagerSingleton();
+ binder.bind(DeleteHandlerV1.class).to(AtlasRepositoryConfiguration.getDeleteHandlerV1Impl()).asEagerSingleton();
+ }
+
+ protected void bindAuditRepository(Binder binder) {
+
+ Class<? extends EntityAuditRepository> auditRepoImpl = AtlasRepositoryConfiguration.getAuditRepositoryImpl();
+
+ //Map EntityAuditRepository interface to configured implementation
+ binder.bind(EntityAuditRepository.class).to(auditRepoImpl).asEagerSingleton();
+
+ if(Service.class.isAssignableFrom(auditRepoImpl)) {
+ Class<? extends Service> auditRepoService = (Class<? extends Service>)auditRepoImpl;
+ //if it's a service, make sure that it gets properly closed at shutdown
+ Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder, Service.class);
+ serviceBinder.addBinding().to(auditRepoService);
+ }
+ }
+ }
+
+ public static class SoftDeleteModule extends TestOnlyModule {
+ @Override
+ protected void bindDeleteHandler(Binder binder) {
+ bind(DeleteHandler.class).to(SoftDeleteHandler.class).asEagerSingleton();
+ bind(DeleteHandlerV1.class).to(SoftDeleteHandlerV1.class).asEagerSingleton();
+ bind(AtlasEntityChangeNotifier.class).toProvider(MockNotifier.class);
+ }
+ }
+
+ public static class HardDeleteModule extends TestOnlyModule {
+ @Override
+ protected void bindDeleteHandler(Binder binder) {
+ bind(DeleteHandler.class).to(HardDeleteHandler.class).asEagerSingleton();
+ bind(DeleteHandlerV1.class).to(HardDeleteHandlerV1.class).asEagerSingleton();
+ bind(AtlasEntityChangeNotifier.class).toProvider(MockNotifier.class);
+ }
+ }
+
+ /**
+ * Guice module which sets TypeCache implementation class configuration property to {@link StoreBackedTypeCache}.
+ *
+ */
+ public static class StoreBackedTypeCacheTestModule extends TestOnlyModule {
+ @Override
+ protected void bindTypeCache() {
+ bind(TypeCache.class).to(StoreBackedTypeCache.class).asEagerSingleton();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/TestOnlyModule.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/TestOnlyModule.java b/repository/src/test/java/org/apache/atlas/TestOnlyModule.java
deleted file mode 100644
index c930953..0000000
--- a/repository/src/test/java/org/apache/atlas/TestOnlyModule.java
+++ /dev/null
@@ -1,30 +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.graph.GraphSandboxUtil;
-
-public class TestOnlyModule extends RepositoryMetadataModule {
- @Override
- protected void configure() {
- GraphSandboxUtil.create();
-
- // Configure extra stuff for test DI here
- super.configure();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 cf39d8d..1e439f7 100755
--- a/repository/src/test/java/org/apache/atlas/TestUtils.java
+++ b/repository/src/test/java/org/apache/atlas/TestUtils.java
@@ -20,10 +20,11 @@ package org.apache.atlas;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import com.google.inject.Provider;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.listener.TypesChangeListener;
import org.apache.atlas.repository.MetadataRepository;
+import org.apache.atlas.repository.audit.InMemoryEntityAuditRepository;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphBackedMetadataRepository;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
@@ -64,7 +65,6 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -600,20 +600,18 @@ public final class TestUtils {
typeCache = new DefaultTypeCache();
}
final GraphBackedSearchIndexer indexer = new GraphBackedSearchIndexer(new AtlasTypeRegistry());
- Provider<TypesChangeListener> indexerProvider = new Provider<TypesChangeListener>() {
-
- @Override
- public TypesChangeListener get() {
- return indexer;
- }
- };
Configuration config = ApplicationProperties.get();
- ITypeStore typeStore = new GraphBackedTypeStore();
+ ITypeStore typeStore = new GraphBackedTypeStore(AtlasGraphProvider.getGraphInstance());
DefaultMetadataService defaultMetadataService = new DefaultMetadataService(repo,
typeStore,
- Collections.singletonList(indexerProvider),
- new ArrayList<Provider<EntityChangeListener>>(), TypeSystem.getInstance(), config, typeCache);
+ new HashSet<TypesChangeListener>() {{ add(indexer); }},
+ new HashSet<EntityChangeListener>(),
+ TypeSystem.getInstance(),
+ config,
+ typeCache,
+ // Fixme: Can we work with Noop
+ new InMemoryEntityAuditRepository());
//commit the created types
getGraph().commit();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/discovery/DataSetLineageServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/discovery/DataSetLineageServiceTest.java b/repository/src/test/java/org/apache/atlas/discovery/DataSetLineageServiceTest.java
index fc38edf..c700a61 100644
--- a/repository/src/test/java/org/apache/atlas/discovery/DataSetLineageServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/discovery/DataSetLineageServiceTest.java
@@ -19,10 +19,10 @@
package org.apache.atlas.discovery;
import com.google.common.collect.ImmutableList;
-import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.BaseRepositoryTest;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.query.QueryParams;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.Referenceable;
@@ -55,7 +55,7 @@ import static org.testng.Assert.fail;
/**
* Unit tests for Hive LineageService.
*/
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class DataSetLineageServiceTest extends BaseRepositoryTest {
@Inject
@@ -400,7 +400,7 @@ public class DataSetLineageServiceTest extends BaseRepositoryTest {
//Delete the entity. Lineage for entity returns the same results as before.
//Lineage for table name throws EntityNotFoundException
- AtlasClient.EntityResult deleteResult = repository.deleteEntities(Arrays.asList(tableId));
+ EntityResult deleteResult = repository.deleteEntities(Arrays.asList(tableId));
assertTrue(deleteResult.getDeletedEntities().contains(tableId));
results = new JSONObject(lineageService.getSchemaForEntity(tableId));
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java b/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
index 3ea8f34..834abe1 100755
--- a/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java
@@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException;
import org.apache.atlas.BaseRepositoryTest;
import org.apache.atlas.RequestContext;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
import org.apache.atlas.query.QueryParams;
@@ -62,7 +62,7 @@ import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAt
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class GraphBackedDiscoveryServiceTest extends BaseRepositoryTest {
@Inject
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/lineage/EntityLineageServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/lineage/EntityLineageServiceTest.java b/repository/src/test/java/org/apache/atlas/lineage/EntityLineageServiceTest.java
index 0a4a445..8a88f32 100644
--- a/repository/src/test/java/org/apache/atlas/lineage/EntityLineageServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/lineage/EntityLineageServiceTest.java
@@ -19,15 +19,15 @@
package org.apache.atlas.lineage;
import com.google.common.collect.ImmutableList;
-import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.BaseRepositoryTest;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.discovery.EntityLineageService;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity.Status;
import org.apache.atlas.model.instance.AtlasEntityHeader;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.model.lineage.AtlasLineageInfo;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
@@ -56,7 +56,7 @@ import static org.testng.Assert.fail;
/**
* Unit tests for the new v2 Instance LineageService.
*/
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class EntityLineageServiceTest extends BaseRepositoryTest {
@Inject
@@ -301,7 +301,7 @@ public class EntityLineageServiceTest extends BaseRepositoryTest {
//Delete the table entity. Lineage for entity returns the same results as before.
//Lineage for table name throws EntityNotFoundException
- AtlasClient.EntityResult deleteResult = repository.deleteEntities(Arrays.asList(entityGuid));
+ EntityResult deleteResult = repository.deleteEntities(Arrays.asList(entityGuid));
assertTrue(deleteResult.getDeletedEntities().contains(entityGuid));
inputLineage = getInputLineageInfo(entityGuid, 5);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/graph/AbstractGremlinQueryOptimizerTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/AbstractGremlinQueryOptimizerTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/AbstractGremlinQueryOptimizerTest.java
index 59d2a3f..88de2c4 100644
--- a/repository/src/test/java/org/apache/atlas/repository/graph/AbstractGremlinQueryOptimizerTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/AbstractGremlinQueryOptimizerTest.java
@@ -63,12 +63,12 @@ public abstract class AbstractGremlinQueryOptimizerTest implements IAtlasGraphPr
private final GraphPersistenceStrategies STRATEGY = mock(GraphPersistenceStrategies.class);
@BeforeClass
- public void setUp() {
+ public void setUp() throws RepositoryException {
GremlinQueryOptimizer.reset();
GremlinQueryOptimizer.setExpressionFactory(getFactory());
when(STRATEGY.typeAttributeName()).thenReturn(Constants.ENTITY_TYPE_PROPERTY_KEY);
when(STRATEGY.superTypeAttributeName()).thenReturn(Constants.SUPER_TYPES_PROPERTY_KEY);
- repo = new GraphBackedMetadataRepository(this, new HardDeleteHandler(TypeSystem.getInstance()));
+ repo = new GraphBackedMetadataRepository(new HardDeleteHandler(TypeSystem.getInstance()), this.get());
}
private FieldInfo getTestFieldInfo() throws AtlasException {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 4fd416c..0e22080 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
@@ -21,12 +21,12 @@ package org.apache.atlas.repository.graph;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasClient.EntityResult;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
import org.apache.atlas.RequestContext;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.RepositoryException;
@@ -53,6 +53,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -72,7 +73,7 @@ import static org.testng.Assert.fail;
* Guice loads the dependencies and injects the necessary objects
*
*/
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
protected MetadataRepository repositoryService;
@@ -83,6 +84,9 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
private ClassType compositeMapValueType;
+ @Inject
+ AtlasGraph atlasGraph;
+
@BeforeClass
public void setUp() throws Exception {
@@ -90,7 +94,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
typeSystem.reset();
new GraphBackedSearchIndexer(new AtlasTypeRegistry());
- final GraphBackedMetadataRepository delegate = new GraphBackedMetadataRepository(getDeleteHandler(typeSystem));
+ final GraphBackedMetadataRepository delegate = new GraphBackedMetadataRepository(getDeleteHandler(typeSystem), atlasGraph);
repositoryService = TestUtils.addTransactionWrapper(delegate);
@@ -126,7 +130,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
@AfterClass
public void tearDown() throws Exception {
TypeSystem.getInstance().reset();
- AtlasGraphProvider.cleanup();
+// AtlasGraphProvider.cleanup();
}
@Test
@@ -194,7 +198,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
table.set(COLUMNS_ATTR_NAME, Arrays.asList(new Id(colId, 0, COLUMN_TYPE)));
String tableId = createInstance(table);
- AtlasClient.EntityResult entityResult = deleteEntities(colId);
+ EntityResult entityResult = deleteEntities(colId);
assertEquals(entityResult.getDeletedEntities().size(), 1);
assertEquals(entityResult.getDeletedEntities().get(0), colId);
assertEquals(entityResult.getUpdateEntities().size(), 1);
@@ -227,7 +231,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
protected abstract void assertEntityDeleted(String id) throws Exception;
- private AtlasClient.EntityResult deleteEntities(String... id) throws Exception {
+ private EntityResult deleteEntities(String... id) throws Exception {
RequestContext.createContext();
return repositoryService.deleteEntities(Arrays.asList(id));
}
@@ -261,7 +265,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
String colId = columns.get(0).getId()._getId();
String tableId = tableInstance.getId()._getId();
- AtlasClient.EntityResult entityResult = deleteEntities(colId);
+ EntityResult entityResult = deleteEntities(colId);
assertEquals(entityResult.getDeletedEntities().size(), 1);
assertEquals(entityResult.getDeletedEntities().get(0), colId);
assertEquals(entityResult.getUpdateEntities().size(), 1);
@@ -389,7 +393,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
return entityDefinition;
}
- private AtlasClient.EntityResult updatePartial(ITypedReferenceableInstance entity) throws RepositoryException {
+ private EntityResult updatePartial(ITypedReferenceableInstance entity) throws RepositoryException {
RequestContext.createContext();
return repositoryService.updatePartial(entity).getEntityResult();
}
@@ -419,7 +423,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
ClassType personType = typeSystem.getDataType(ClassType.class, "Person");
ITypedReferenceableInstance maxEntity = personType.createInstance(max.getId());
maxEntity.set("mentor", johnGuid);
- AtlasClient.EntityResult entityResult = updatePartial(maxEntity);
+ EntityResult entityResult = updatePartial(maxEntity);
assertEquals(entityResult.getUpdateEntities().size(), 1);
assertTrue(entityResult.getUpdateEntities().contains(maxGuid));
@@ -512,7 +516,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
Assert.assertTrue(subordinateIds.contains(maxGuid));
- AtlasClient.EntityResult entityResult = deleteEntities(maxGuid);
+ EntityResult entityResult = deleteEntities(maxGuid);
ITypedReferenceableInstance john = repositoryService.getEntityDefinition("Person", "name", "John");
assertEquals(entityResult.getDeletedEntities().size(), 1);
@@ -560,7 +564,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
String columnGuid = columns.get(0).getId()._getId();
// Delete the column.
- AtlasClient.EntityResult entityResult = deleteEntities(columnGuid);
+ EntityResult entityResult = deleteEntities(columnGuid);
assertEquals(entityResult.getDeletedEntities().size(), 1);
Assert.assertTrue(entityResult.getDeletedEntities().contains(columnGuid));
assertEquals(entityResult.getUpdateEntities().size(), 1);
@@ -672,7 +676,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
Assert.assertEquals(refList.get(0).getId()._getId(), traitTargetGuid);
// Delete the entities that are targets of the struct and trait instances.
- AtlasClient.EntityResult entityResult = deleteEntities(structTargetGuid, traitTargetGuid);
+ EntityResult entityResult = deleteEntities(structTargetGuid, traitTargetGuid);
Assert.assertEquals(entityResult.getDeletedEntities().size(), 2);
Assert.assertTrue(entityResult.getDeletedEntities().containsAll(Arrays.asList(structTargetGuid, traitTargetGuid)));
assertEntityDeleted(structTargetGuid);
@@ -1037,7 +1041,7 @@ public abstract class GraphBackedMetadataRepositoryDeleteTestBase {
String table2Id = createInstance(table2);
// Delete the tables and column
- AtlasClient.EntityResult entityResult = deleteEntities(table1Id, colId, table2Id);
+ EntityResult entityResult = deleteEntities(table1Id, colId, table2Id);
Assert.assertEquals(entityResult.getDeletedEntities().size(), 3);
Assert.assertTrue(entityResult.getDeletedEntities().containsAll(Arrays.asList(colId, table1Id, table2Id)));
assertEntityDeleted(table1Id);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 9f44c31..8120aaa 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,10 +22,10 @@ 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.GraphTransaction;
+import org.apache.atlas.TestModules;
import org.apache.atlas.RequestContext;
-import org.apache.atlas.TestOnlyModule;
import org.apache.atlas.TestUtils;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
import org.apache.atlas.query.QueryParams;
import org.apache.atlas.repository.Constants;
@@ -92,7 +92,7 @@ import static org.testng.Assert.assertTrue;
* Guice loads the dependencies and injects the necessary objects
*
*/
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class GraphBackedMetadataRepositoryTest {
@Inject
@@ -126,7 +126,7 @@ public class GraphBackedMetadataRepositoryTest {
@AfterClass
public void tearDown() throws Exception {
TypeSystem.getInstance().reset();
- AtlasGraphProvider.cleanup();
+// AtlasGraphProvider.cleanup();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexerTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexerTest.java
index a254d0a..ef5d469 100644
--- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexerTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexerTest.java
@@ -20,7 +20,7 @@ package org.apache.atlas.repository.graph;
import com.google.inject.Inject;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasGraph;
@@ -41,12 +41,10 @@ import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Set;
-import static junit.framework.Assert.assertTrue;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.*;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class GraphBackedSearchIndexerTest {
@Inject
private GraphBackedSearchIndexer graphBackedSearchIndexer;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/graph/GraphHelperTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphHelperTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphHelperTest.java
index 4061543..e64c2c8 100644
--- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphHelperTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphHelperTest.java
@@ -19,7 +19,7 @@
package org.apache.atlas.repository.graph;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.repository.graph.GraphHelper.VertexInfo;
import org.apache.atlas.repository.graphdb.AtlasEdge;
@@ -56,7 +56,7 @@ import java.util.Set;
import static org.testng.Assert.*;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class GraphHelperTest {
@@ -104,7 +104,7 @@ public class GraphHelperTest {
@AfterClass
public void tearDown() {
- AtlasGraphProvider.cleanup();
+// AtlasGraphProvider.cleanup();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/graph/GraphRepoMapperScaleTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/GraphRepoMapperScaleTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/GraphRepoMapperScaleTest.java
index 21926dc..1f077ba 100755
--- a/repository/src/test/java/org/apache/atlas/repository/graph/GraphRepoMapperScaleTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/GraphRepoMapperScaleTest.java
@@ -20,9 +20,9 @@ package org.apache.atlas.repository.graph;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.CreateUpdateEntitiesResult;
-import org.apache.atlas.GraphTransaction;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graphdb.AtlasGraph;
@@ -54,7 +54,7 @@ import java.util.Date;
import java.util.Iterator;
@Test
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class GraphRepoMapperScaleTest {
private static final String DATABASE_NAME = "foo";
@@ -89,7 +89,7 @@ public class GraphRepoMapperScaleTest {
@AfterClass
public void tearDown() throws Exception {
TypeSystem.getInstance().reset();
- AtlasGraphProvider.cleanup();
+// AtlasGraphProvider.cleanup();
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateHardDeleteTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateHardDeleteTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateHardDeleteTest.java
index 9778c63..a3207fb 100644
--- a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateHardDeleteTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateHardDeleteTest.java
@@ -17,9 +17,10 @@
*/
package org.apache.atlas.repository.graph;
+import org.apache.atlas.TestModules;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
-import org.apache.atlas.typesystem.types.TypeSystem;
import org.testng.Assert;
+import org.testng.annotations.Guice;
import java.util.List;
@@ -28,14 +29,8 @@ import java.util.List;
* Run tests in {@link ReverseReferenceUpdateTestBase} with hard delete enabled.
*
*/
+@Guice(modules = TestModules.HardDeleteModule.class)
public class ReverseReferenceUpdateHardDeleteTest extends ReverseReferenceUpdateTestBase {
-
- @Override
- DeleteHandler getDeleteHandler(TypeSystem typeSystem) {
-
- return new HardDeleteHandler(typeSystem);
- }
-
@Override
void assertTestOneToOneReference(Object refValue, ITypedReferenceableInstance expectedValue, ITypedReferenceableInstance referencingInstance) throws Exception {
// Verify reference was disconnected
@@ -48,5 +43,4 @@ public class ReverseReferenceUpdateHardDeleteTest extends ReverseReferenceUpdate
List<ITypedReferenceableInstance> refValues = (List<ITypedReferenceableInstance>) object;
Assert.assertEquals(refValues.size(), 1);
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateSoftDeleteTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateSoftDeleteTest.java b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateSoftDeleteTest.java
index 100ccfb..c5eda37 100644
--- a/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateSoftDeleteTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/graph/ReverseReferenceUpdateSoftDeleteTest.java
@@ -17,13 +17,14 @@
*/
package org.apache.atlas.repository.graph;
+import org.apache.atlas.TestModules;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.types.TypeSystem;
import org.testng.Assert;
+import org.testng.annotations.Guice;
import java.util.Iterator;
import java.util.List;
@@ -33,14 +34,8 @@ import java.util.List;
* Run tests in {@link ReverseReferenceUpdateTestBase} with soft delete enabled.
*
*/
+@Guice(modules = TestModules.SoftDeleteModule.class)
public class ReverseReferenceUpdateSoftDeleteTest extends ReverseReferenceUpdateTestBase {
-
- @Override
- DeleteHandler getDeleteHandler(TypeSystem typeSystem) {
-
- return new SoftDeleteHandler(typeSystem);
- }
-
@Override
void assertTestOneToOneReference(Object actual, ITypedReferenceableInstance expectedValue, ITypedReferenceableInstance referencingInstance) throws Exception {
// Verify reference was not disconnected if soft deletes are enabled.
[11/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/GraphTransaction.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/GraphTransaction.java b/repository/src/main/java/org/apache/atlas/GraphTransaction.java
deleted file mode 100644
index b73f4ed..0000000
--- a/repository/src/main/java/org/apache/atlas/GraphTransaction.java
+++ /dev/null
@@ -1,28 +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.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface GraphTransaction {
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/GraphTransactionAdvisor.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/GraphTransactionAdvisor.java b/repository/src/main/java/org/apache/atlas/GraphTransactionAdvisor.java
new file mode 100644
index 0000000..9751a87
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/GraphTransactionAdvisor.java
@@ -0,0 +1,63 @@
+/**
+ * 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.aopalliance.aop.Advice;
+import org.apache.atlas.annotation.GraphTransaction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.aop.Pointcut;
+import org.springframework.aop.support.AbstractPointcutAdvisor;
+import org.springframework.aop.support.StaticMethodMatcherPointcut;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import java.lang.reflect.Method;
+
+@Component
+public class GraphTransactionAdvisor extends AbstractPointcutAdvisor {
+ private static final Logger LOG = LoggerFactory.getLogger(GraphTransactionAdvisor.class);
+
+ private final StaticMethodMatcherPointcut pointcut = new StaticMethodMatcherPointcut() {
+ @Override
+ public boolean matches(Method method, Class<?> targetClass) {
+ boolean annotationPresent = method.isAnnotationPresent(GraphTransaction.class);
+ if (annotationPresent) {
+ LOG.info("GraphTransaction intercept for {}.{}", targetClass.getName(), method.getName());
+ }
+ return annotationPresent;
+ }
+ };
+
+ private final GraphTransactionInterceptor interceptor;
+
+ @Inject
+ public GraphTransactionAdvisor(GraphTransactionInterceptor interceptor) {
+ this.interceptor = interceptor;
+ }
+
+ @Override
+ public Pointcut getPointcut() {
+ return pointcut;
+ }
+
+ @Override
+ public Advice getAdvice() {
+ return interceptor;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java b/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java
index 0f85b61..7d3bdf7 100644
--- a/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java
+++ b/repository/src/main/java/org/apache/atlas/GraphTransactionInterceptor.java
@@ -20,30 +20,32 @@ package org.apache.atlas;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.atlas.exception.AtlasBaseException;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.typesystem.exception.NotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
+@Component
public class GraphTransactionInterceptor implements MethodInterceptor {
private static final Logger LOG = LoggerFactory.getLogger(GraphTransactionInterceptor.class);
private static final ThreadLocal<List<PostTransactionHook>> postTransactionHooks = new ThreadLocal<>();
- private AtlasGraph graph;
+ private final AtlasGraph graph;
+
+ @Inject
+ public GraphTransactionInterceptor(AtlasGraph graph) {
+ this.graph = graph;
+ }
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
-
- if (graph == null) {
- graph = AtlasGraphProvider.getGraphInstance();
- }
-
boolean isSuccess = false;
try {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java b/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java
deleted file mode 100755
index 6c175ae..0000000
--- a/repository/src/main/java/org/apache/atlas/RepositoryMetadataModule.java
+++ /dev/null
@@ -1,155 +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.inject.Binder;
-import com.google.inject.Singleton;
-import com.google.inject.matcher.Matchers;
-import com.google.inject.multibindings.Multibinder;
-
-import org.aopalliance.intercept.MethodInterceptor;
-import org.apache.atlas.discovery.AtlasDiscoveryService;
-import org.apache.atlas.discovery.AtlasLineageService;
-import org.apache.atlas.discovery.DataSetLineageService;
-import org.apache.atlas.discovery.DiscoveryService;
-import org.apache.atlas.discovery.EntityDiscoveryService;
-import org.apache.atlas.discovery.EntityLineageService;
-import org.apache.atlas.discovery.LineageService;
-import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
-import org.apache.atlas.listener.EntityChangeListener;
-import org.apache.atlas.listener.TypeDefChangeListener;
-import org.apache.atlas.listener.TypesChangeListener;
-import org.apache.atlas.repository.MetadataRepository;
-import org.apache.atlas.repository.audit.EntityAuditListener;
-import org.apache.atlas.repository.audit.EntityAuditRepository;
-import org.apache.atlas.repository.graph.DeleteHandler;
-import org.apache.atlas.repository.graph.GraphBackedMetadataRepository;
-import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
-import org.apache.atlas.repository.store.graph.AtlasEntityDefStore;
-import org.apache.atlas.repository.store.graph.AtlasEntityStore;
-import org.apache.atlas.repository.store.graph.v1.AtlasEntityDefStoreV1;
-import org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1;
-import org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1;
-import org.apache.atlas.repository.store.graph.v1.DeleteHandlerV1;
-import org.apache.atlas.repository.store.graph.v1.EntityGraphMapper;
-import org.apache.atlas.repository.typestore.GraphBackedTypeStore;
-import org.apache.atlas.repository.typestore.ITypeStore;
-import org.apache.atlas.service.Service;
-import org.apache.atlas.services.DefaultMetadataService;
-import org.apache.atlas.services.MetadataService;
-import org.apache.atlas.store.AtlasTypeDefStore;
-import org.apache.atlas.type.AtlasTypeRegistry;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.typesystem.types.TypeSystemProvider;
-import org.apache.atlas.typesystem.types.cache.TypeCache;
-import org.apache.atlas.util.AtlasRepositoryConfiguration;
-import org.apache.commons.configuration.Configuration;
-
-/**
- * Guice module for Repository module.
- */
-public class RepositoryMetadataModule extends com.google.inject.AbstractModule {
-
- @Override
- protected void configure() {
-
- // allow for dynamic binding of the metadata repo & graph service
- // bind the MetadataRepositoryService interface to an implementation
- bind(MetadataRepository.class).to(GraphBackedMetadataRepository.class).asEagerSingleton();
-
- bind(TypeSystem.class).toProvider(TypeSystemProvider.class).in(Singleton.class);
-
- // bind the ITypeStore interface to an implementation
- bind(ITypeStore.class).to(GraphBackedTypeStore.class).asEagerSingleton();
- bind(AtlasTypeDefStore.class).to(AtlasTypeDefGraphStoreV1.class).asEagerSingleton();
-
- //For testing
- bind(AtlasEntityDefStore.class).to(AtlasEntityDefStoreV1.class).asEagerSingleton();
- bind(AtlasTypeRegistry.class).asEagerSingleton();
-
- //GraphBackedSearchIndexer must be an eager singleton to force the search index creation to happen before
- //we try to restore the type system (otherwise we'll end up running queries
- //before we have any indices during the initial graph setup)
- Multibinder<TypesChangeListener> typesChangeListenerBinder =
- Multibinder.newSetBinder(binder(), TypesChangeListener.class);
- typesChangeListenerBinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton();
-
- // New typesdef/instance change listener should also be bound to the corresponding implementation
- Multibinder<TypeDefChangeListener> typeDefChangeListenerMultibinder =
- Multibinder.newSetBinder(binder(), TypeDefChangeListener.class);
- typeDefChangeListenerMultibinder.addBinding().to(DefaultMetadataService.class);
- typeDefChangeListenerMultibinder.addBinding().to(GraphBackedSearchIndexer.class).asEagerSingleton();
-
- bind(AtlasEntityStore.class).to(AtlasEntityStoreV1.class);
-
- // bind the MetadataService interface to an implementation
- bind(MetadataService.class).to(DefaultMetadataService.class).asEagerSingleton();
-
- // bind the DiscoveryService interface to an implementation
- bind(DiscoveryService.class).to(GraphBackedDiscoveryService.class).asEagerSingleton();
- bind(AtlasDiscoveryService.class).to(EntityDiscoveryService.class).asEagerSingleton();
-
- bind(LineageService.class).to(DataSetLineageService.class).asEagerSingleton();
- bind(AtlasLineageService.class).to(EntityLineageService.class).asEagerSingleton();
-
- Configuration configuration = getConfiguration();
- bindAuditRepository(binder(), configuration);
-
- bind(DeleteHandler.class).to(AtlasRepositoryConfiguration.getDeleteHandlerImpl()).asEagerSingleton();
-
- bind(DeleteHandlerV1.class).to(AtlasRepositoryConfiguration.getDeleteHandlerV1Impl()).asEagerSingleton();
-
- bind(TypeCache.class).to(AtlasRepositoryConfiguration.getTypeCache()).asEagerSingleton();
-
- bind(EntityGraphMapper.class);
-
- //Add EntityAuditListener as EntityChangeListener
- Multibinder<EntityChangeListener> entityChangeListenerBinder =
- Multibinder.newSetBinder(binder(), EntityChangeListener.class);
- entityChangeListenerBinder.addBinding().to(EntityAuditListener.class);
-
- MethodInterceptor interceptor = new GraphTransactionInterceptor();
- requestInjection(interceptor);
- bindInterceptor(Matchers.any(), Matchers.annotatedWith(GraphTransaction.class), interceptor);
- }
-
- protected Configuration getConfiguration() {
- try {
- return ApplicationProperties.get();
- } catch (AtlasException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void bindAuditRepository(Binder binder, Configuration configuration) {
-
- Class<? extends EntityAuditRepository> auditRepoImpl = AtlasRepositoryConfiguration.getAuditRepositoryImpl();
-
- //Map EntityAuditRepository interface to configured implementation
- binder.bind(EntityAuditRepository.class).to(auditRepoImpl).asEagerSingleton();
-
- if(Service.class.isAssignableFrom(auditRepoImpl)) {
- Class<? extends Service> auditRepoService = (Class<? extends Service>)auditRepoImpl;
- //if it's a service, make sure that it gets properly closed at shutdown
- Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder, Service.class);
- serviceBinder.addBinding().to(auditRepoService);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/discovery/DataSetLineageService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/DataSetLineageService.java b/repository/src/main/java/org/apache/atlas/discovery/DataSetLineageService.java
index b65b67d..af7f1b4 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/DataSetLineageService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/DataSetLineageService.java
@@ -18,17 +18,11 @@
package org.apache.atlas.discovery;
-import java.util.Arrays;
-import java.util.Iterator;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.GraphTransaction;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.discovery.graph.DefaultGraphPersistenceStrategy;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
import org.apache.atlas.query.GremlinQueryResult;
@@ -37,7 +31,6 @@ import org.apache.atlas.query.OutputLineageClosureQuery;
import org.apache.atlas.query.QueryParams;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.MetadataRepository;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasVertex;
@@ -49,16 +42,22 @@ import org.apache.atlas.utils.ParamChecker;
import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.springframework.stereotype.Component;
import scala.Option;
import scala.Some;
import scala.collection.JavaConversions;
import scala.collection.immutable.List;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.util.Arrays;
+import java.util.Iterator;
+
/**
* Hive implementation of Lineage service interface.
*/
@Singleton
+@Component
public class DataSetLineageService implements LineageService {
private static final Logger LOG = LoggerFactory.getLogger(DataSetLineageService.class);
@@ -91,8 +90,9 @@ public class DataSetLineageService implements LineageService {
@Inject
DataSetLineageService(MetadataRepository metadataRepository,
- GraphBackedDiscoveryService discoveryService) throws DiscoveryException {
- this.graph = AtlasGraphProvider.getGraphInstance();
+ GraphBackedDiscoveryService discoveryService,
+ AtlasGraph atlasGraph) throws DiscoveryException {
+ this.graph = atlasGraph;
this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository);
this.discoveryService = discoveryService;
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
index 1b4583a..128cdbf 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
@@ -20,7 +20,6 @@ package org.apache.atlas.discovery;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasConfiguration;
import org.apache.atlas.AtlasErrorCode;
-import org.apache.atlas.AtlasException;
import org.apache.atlas.discovery.graph.DefaultGraphPersistenceStrategy;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.discovery.AtlasSearchResult;
@@ -28,6 +27,7 @@ import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult;
import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType;
import org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult;
import org.apache.atlas.model.instance.AtlasEntity.Status;
+import org.apache.atlas.AtlasException;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.query.Expressions.AliasExpression;
import org.apache.atlas.query.Expressions.Expression;
@@ -40,7 +40,6 @@ import org.apache.atlas.query.QueryProcessor;
import org.apache.atlas.query.SelectExpressionHelper;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.MetadataRepository;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasIndexQuery;
@@ -58,6 +57,7 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import scala.Option;
import scala.util.Either;
import scala.util.parsing.combinator.Parsers.NoSuccess;
@@ -73,10 +73,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import static org.apache.atlas.AtlasErrorCode.CLASSIFICATION_NOT_FOUND;
import static org.apache.atlas.AtlasErrorCode.DISCOVERY_QUERY_FAILED;
import static org.apache.atlas.AtlasErrorCode.UNKNOWN_TYPENAME;
-import static org.apache.atlas.AtlasErrorCode.CLASSIFICATION_NOT_FOUND;
+@Component
public class EntityDiscoveryService implements AtlasDiscoveryService {
private static final Logger LOG = LoggerFactory.getLogger(EntityDiscoveryService.class);
@@ -90,8 +91,8 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
private final int maxTagsCountInIdxQuery;
@Inject
- EntityDiscoveryService(MetadataRepository metadataRepository, AtlasTypeRegistry typeRegistry) throws AtlasException {
- this.graph = AtlasGraphProvider.getGraphInstance();
+ EntityDiscoveryService(MetadataRepository metadataRepository, AtlasTypeRegistry typeRegistry, AtlasGraph graph) throws AtlasException {
+ this.graph = graph;
this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository);
this.entityRetriever = new EntityGraphRetriever(typeRegistry);
this.gremlinQueryProvider = AtlasGremlinQueryProvider.INSTANCE;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java
index d6aca89..b07091a 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/EntityLineageService.java
@@ -24,10 +24,9 @@ import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.lineage.AtlasLineageInfo;
-import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
+import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
import org.apache.atlas.repository.Constants;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasVertex;
@@ -36,9 +35,9 @@ import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.util.AtlasGremlinQueryProvider;
import org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery;
import org.apache.commons.collections.CollectionUtils;
+import org.springframework.stereotype.Service;
import javax.inject.Inject;
-import javax.script.ScriptException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -46,6 +45,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+@Service
public class EntityLineageService implements AtlasLineageService {
private static final String INPUT_PROCESS_EDGE = "__Process.inputs";
private static final String OUTPUT_PROCESS_EDGE = "__Process.outputs";
@@ -55,8 +55,8 @@ public class EntityLineageService implements AtlasLineageService {
private final EntityGraphRetriever entityRetriever;
@Inject
- EntityLineageService(AtlasTypeRegistry typeRegistry) throws DiscoveryException {
- this.graph = AtlasGraphProvider.getGraphInstance();
+ EntityLineageService(AtlasTypeRegistry typeRegistry, AtlasGraph atlasGraph) throws DiscoveryException {
+ this.graph = atlasGraph;
this.gremlinQueryProvider = AtlasGremlinQueryProvider.INSTANCE;
this.entityRetriever = new EntityGraphRetriever(typeRegistry);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
index 23e4531..083c34d 100755
--- a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java
@@ -18,18 +18,8 @@
package org.apache.atlas.discovery.graph;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
import org.apache.atlas.AtlasClient;
-import org.apache.atlas.GraphTransaction;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.discovery.DiscoveryException;
import org.apache.atlas.discovery.DiscoveryService;
import org.apache.atlas.exception.AtlasBaseException;
@@ -43,7 +33,6 @@ import org.apache.atlas.query.QueryParser;
import org.apache.atlas.query.QueryProcessor;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.MetadataRepository;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasGraph;
@@ -56,14 +45,24 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+import org.springframework.stereotype.Component;
import scala.util.Either;
import scala.util.parsing.combinator.Parsers;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
/**
* Graph backed implementation of Search.
*/
@Singleton
+@Component
public class GraphBackedDiscoveryService implements DiscoveryService {
private static final Logger LOG = LoggerFactory.getLogger(GraphBackedDiscoveryService.class);
@@ -74,9 +73,9 @@ public class GraphBackedDiscoveryService implements DiscoveryService {
public final static String SCORE = "score";
@Inject
- GraphBackedDiscoveryService(MetadataRepository metadataRepository)
+ GraphBackedDiscoveryService(MetadataRepository metadataRepository, AtlasGraph atlasGraph)
throws DiscoveryException {
- this.graph = AtlasGraphProvider.getGraphInstance();
+ this.graph = atlasGraph;
this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java
index 9a873b3..b72ee7d 100644
--- a/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/MetadataRepository.java
@@ -18,9 +18,9 @@
package org.apache.atlas.repository;
-import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.ITypedStruct;
import org.apache.atlas.typesystem.exception.EntityExistsException;
@@ -135,7 +135,7 @@ public interface MetadataRepository {
* @return guids of deleted entities
* @throws RepositoryException
*/
- AtlasClient.EntityResult deleteEntities(List<String> guids) throws RepositoryException;
+ EntityResult deleteEntities(List<String> guids) throws RepositoryException;
// Trait management functions
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java b/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java
new file mode 100644
index 0000000..261a6d0
--- /dev/null
+++ b/repository/src/main/java/org/apache/atlas/repository/RepositoryConfiguration.java
@@ -0,0 +1,37 @@
+/**
+ * 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.repository;
+
+import org.apache.atlas.repository.graphdb.GraphDatabase;
+import org.apache.atlas.typesystem.types.TypeSystem;
+import org.apache.atlas.util.AtlasRepositoryConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RepositoryConfiguration {
+ @Bean
+ public GraphDatabase getGraphDatabase() throws IllegalAccessException, InstantiationException {
+ return AtlasRepositoryConfiguration.getGraphDatabaseImpl().newInstance();
+ }
+
+ @Bean
+ public TypeSystem getTypeSystem() {
+ return TypeSystem.getInstance();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
index eab86c4..2a1881b 100644
--- a/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
+++ b/repository/src/main/java/org/apache/atlas/repository/audit/EntityAuditListener.java
@@ -32,6 +32,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.nio.charset.StandardCharsets;
@@ -44,6 +45,7 @@ import java.util.Map;
/**
* Listener on entity create/update/delete, tag add/delete. Adds the corresponding audit event to the audit repository.
*/
+@Component
public class EntityAuditListener implements EntityChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(EntityAuditListener.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/audit/HBaseBasedAuditRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/audit/HBaseBasedAuditRepository.java b/repository/src/main/java/org/apache/atlas/repository/audit/HBaseBasedAuditRepository.java
index 9de2110..89ca748 100644
--- a/repository/src/main/java/org/apache/atlas/repository/audit/HBaseBasedAuditRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/audit/HBaseBasedAuditRepository.java
@@ -19,10 +19,10 @@
package org.apache.atlas.repository.audit;
import com.google.common.annotations.VisibleForTesting;
-import com.google.inject.Singleton;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.atlas.EntityAuditEvent;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
import org.apache.atlas.ha.HAConfiguration;
import org.apache.atlas.listener.ActiveStateChangeHandler;
import org.apache.atlas.service.Service;
@@ -47,7 +47,9 @@ import org.apache.hadoop.hbase.regionserver.BloomType;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Singleton;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
@@ -70,6 +72,8 @@ import java.util.Map;
* But if there are more than one atlas servers, we should use server id in the key
*/
@Singleton
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.EntityAuditRepository.impl")
public class HBaseBasedAuditRepository implements Service, EntityAuditRepository, ActiveStateChangeHandler {
private static final Logger LOG = LoggerFactory.getLogger(HBaseBasedAuditRepository.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/audit/InMemoryEntityAuditRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/audit/InMemoryEntityAuditRepository.java b/repository/src/main/java/org/apache/atlas/repository/audit/InMemoryEntityAuditRepository.java
index 86f1af7..22d2a81 100644
--- a/repository/src/main/java/org/apache/atlas/repository/audit/InMemoryEntityAuditRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/audit/InMemoryEntityAuditRepository.java
@@ -18,21 +18,24 @@
package org.apache.atlas.repository.audit;
+import org.apache.atlas.AtlasException;
+import org.apache.atlas.EntityAuditEvent;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.EntityAuditEvent;
-
-import com.google.inject.Singleton;
-
/**
* Entity audit repository where audit events are stored in-memory. Used only for integration tests
*/
@Singleton
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.EntityAuditRepository.impl")
public class InMemoryEntityAuditRepository implements EntityAuditRepository {
private TreeMap<String, EntityAuditEvent> auditEvents = new TreeMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/audit/NoopEntityAuditRepository.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/audit/NoopEntityAuditRepository.java b/repository/src/main/java/org/apache/atlas/repository/audit/NoopEntityAuditRepository.java
index d4d3c20..7c39ce9 100644
--- a/repository/src/main/java/org/apache/atlas/repository/audit/NoopEntityAuditRepository.java
+++ b/repository/src/main/java/org/apache/atlas/repository/audit/NoopEntityAuditRepository.java
@@ -18,18 +18,21 @@
package org.apache.atlas.repository.audit;
-import java.util.Collections;
-import java.util.List;
-
import org.apache.atlas.AtlasException;
import org.apache.atlas.EntityAuditEvent;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
+import org.springframework.stereotype.Component;
-import com.google.inject.Singleton;
+import javax.inject.Singleton;
+import java.util.Collections;
+import java.util.List;
/**
* Implementation that completely disables the audit repository.
*/
@Singleton
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.EntityAuditRepository.impl", isDefault = true)
public class NoopEntityAuditRepository implements EntityAuditRepository {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/converters/AtlasAbstractFormatConverter.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasAbstractFormatConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasAbstractFormatConverter.java
index a36618c..ab0d1fc 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasAbstractFormatConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasAbstractFormatConverter.java
@@ -21,8 +21,8 @@ package org.apache.atlas.repository.converters;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasTypeRegistry;
-
public abstract class AtlasAbstractFormatConverter implements AtlasFormatConverter {
+
protected final AtlasFormatConverters converterRegistry;
protected final AtlasTypeRegistry typeRegistry;
protected final TypeCategory typeCategory;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEnumFormatConverter.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEnumFormatConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEnumFormatConverter.java
index d71d543..734bd0c 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEnumFormatConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasEnumFormatConverter.java
@@ -28,8 +28,8 @@ import org.apache.atlas.typesystem.types.EnumValue;
import java.util.Map;
-
public class AtlasEnumFormatConverter extends AtlasAbstractFormatConverter {
+
public AtlasEnumFormatConverter(AtlasFormatConverters registry, AtlasTypeRegistry typeRegistry) {
super(registry, typeRegistry, TypeCategory.ENUM);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/converters/AtlasFormatConverters.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasFormatConverters.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasFormatConverters.java
index 3a164c8..d519806 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasFormatConverters.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasFormatConverters.java
@@ -17,17 +17,19 @@
*/
package org.apache.atlas.repository.converters;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasTypeRegistry;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.HashMap;
import java.util.Map;
@Singleton
+@Component
public class AtlasFormatConverters {
private final Map<TypeCategory, AtlasFormatConverter> registry = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 6e0766d..3426ae5 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,10 +17,7 @@
*/
package org.apache.atlas.repository.converters;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasClient.EntityResult;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
@@ -55,7 +52,10 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -64,19 +64,24 @@ import java.util.List;
import java.util.Map;
@Singleton
+@Component
public class AtlasInstanceConverter {
private static final Logger LOG = LoggerFactory.getLogger(AtlasInstanceConverter.class);
- @Inject
private AtlasTypeRegistry typeRegistry;
- @Inject
private AtlasFormatConverters instanceFormatters;
- @Inject
private MetadataService metadataService;
+ @Inject
+ public AtlasInstanceConverter(AtlasTypeRegistry typeRegistry, AtlasFormatConverters instanceFormatters, MetadataService metadataService) {
+ this.typeRegistry = typeRegistry;
+ this.instanceFormatters = instanceFormatters;
+ this.metadataService = metadataService;
+ }
+
public ITypedReferenceableInstance[] getITypedReferenceables(Collection<AtlasEntity> entities) throws AtlasBaseException {
ITypedReferenceableInstance[] entitiesInOldFormat = new ITypedReferenceableInstance[entities.size()];
@@ -166,7 +171,7 @@ public class AtlasInstanceConverter {
return ctx.getEntities();
}
- public static EntityMutationResponse toEntityMutationResponse(AtlasClient.EntityResult entityResult) {
+ public static EntityMutationResponse toEntityMutationResponse(EntityResult entityResult) {
CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
result.setEntityResult(entityResult);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
index f8fa4d5..f946b9c 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasObjectIdConverter.java
@@ -36,8 +36,7 @@ import org.apache.commons.lang3.StringUtils;
import java.util.Map;
-public class
-AtlasObjectIdConverter extends AtlasAbstractFormatConverter {
+public class AtlasObjectIdConverter extends AtlasAbstractFormatConverter {
public AtlasObjectIdConverter(AtlasFormatConverters registry, AtlasTypeRegistry typeRegistry) {
this(registry, typeRegistry, TypeCategory.OBJECT_ID_TYPE);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/converters/AtlasPrimitiveFormatConverter.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasPrimitiveFormatConverter.java b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasPrimitiveFormatConverter.java
index d0e63eb..dc29689 100644
--- a/repository/src/main/java/org/apache/atlas/repository/converters/AtlasPrimitiveFormatConverter.java
+++ b/repository/src/main/java/org/apache/atlas/repository/converters/AtlasPrimitiveFormatConverter.java
@@ -23,8 +23,8 @@ import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
-
public class AtlasPrimitiveFormatConverter extends AtlasAbstractFormatConverter {
+
public AtlasPrimitiveFormatConverter(AtlasFormatConverters registry, AtlasTypeRegistry typeRegistry) {
super(registry, typeRegistry, TypeCategory.PRIMITIVE);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/AtlasGraphProvider.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/AtlasGraphProvider.java b/repository/src/main/java/org/apache/atlas/repository/graph/AtlasGraphProvider.java
index 0c5cac6..323af40 100755
--- a/repository/src/main/java/org/apache/atlas/repository/graph/AtlasGraphProvider.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/AtlasGraphProvider.java
@@ -18,17 +18,19 @@
package org.apache.atlas.repository.graph;
+import com.google.common.annotations.VisibleForTesting;
import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.GraphDatabase;
import org.apache.atlas.util.AtlasRepositoryConfiguration;
-
-import com.google.common.annotations.VisibleForTesting;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
/**
* Provides access to the AtlasGraph
*
*/
+@Configuration
public class AtlasGraphProvider implements IAtlasGraphProvider {
private static volatile GraphDatabase<?,?> graphDb_;
@@ -64,6 +66,7 @@ public class AtlasGraphProvider implements IAtlasGraphProvider {
}
@Override
+ @Bean
public AtlasGraph get() throws RepositoryException {
return getGraphInstance();
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
index a60ef9e..1ed12bc 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/FullTextMapperV2.java
@@ -17,8 +17,6 @@
*/
package org.apache.atlas.repository.graph;
-import com.google.inject.Singleton;
-import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.RequestContext;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasClassification;
@@ -34,6 +32,7 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.HashSet;
@@ -42,7 +41,7 @@ import java.util.Map;
import java.util.Set;
-@Singleton
+@Component
public class FullTextMapperV2 {
private static final Logger LOG = LoggerFactory.getLogger(FullTextMapperV2.class);
@@ -53,20 +52,9 @@ public class FullTextMapperV2 {
private final boolean followReferences;
@Inject
- public FullTextMapperV2(AtlasTypeRegistry typeRegistry) {
+ public FullTextMapperV2(AtlasTypeRegistry typeRegistry, Configuration configuration) {
entityGraphRetriever = new EntityGraphRetriever(typeRegistry);
-
- Configuration configuration = null;
-
- try {
- configuration = ApplicationProperties.get();
- } catch (Throwable e) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("AtlasApplication properties couldn't be loaded", e);
- }
- } finally {
- followReferences = configuration != null && configuration.getBoolean(FULL_TEXT_FOLLOW_REFERENCES, false);
- }
+ followReferences = configuration != null && configuration.getBoolean(FULL_TEXT_FOLLOW_REFERENCES, false);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 d1e8cb7..5bec8fa 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
@@ -18,23 +18,13 @@
package org.apache.atlas.repository.graph;
-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 org.apache.atlas.AtlasClient;
+import com.google.common.base.Preconditions;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
-import org.apache.atlas.GraphTransaction;
import org.apache.atlas.RequestContext;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.model.instance.GuidMapping;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.MetadataRepository;
import org.apache.atlas.repository.RepositoryException;
@@ -55,16 +45,18 @@ import org.apache.atlas.typesystem.types.IDataType;
import org.apache.atlas.typesystem.types.TypeSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
-import com.google.common.base.Preconditions;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.util.*;
/**
* An implementation backed by a Graph database provided
* as a Graph Service.
*/
@Singleton
+@Component
@Deprecated
public class GraphBackedMetadataRepository implements MetadataRepository {
@@ -76,24 +68,16 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
private DeleteHandler deleteHandler;
- private final IAtlasGraphProvider graphProvider;
+ private final AtlasGraph atlasGraph;
private final GraphToTypedInstanceMapper graphToInstanceMapper;
@Inject
- public GraphBackedMetadataRepository(DeleteHandler deleteHandler) {
- this.graphProvider = new AtlasGraphProvider();
- this.graphToInstanceMapper = new GraphToTypedInstanceMapper(graphProvider);
+ public GraphBackedMetadataRepository(DeleteHandler deleteHandler, AtlasGraph atlasGraph) {
+ this.atlasGraph = atlasGraph;
+ this.graphToInstanceMapper = new GraphToTypedInstanceMapper(atlasGraph);
this.deleteHandler = deleteHandler;
}
- //for testing only
- public GraphBackedMetadataRepository(IAtlasGraphProvider graphProvider, DeleteHandler deleteHandler) {
- this.graphProvider = graphProvider;
- this.graphToInstanceMapper = new GraphToTypedInstanceMapper(graphProvider);
- this.deleteHandler = deleteHandler;
- }
-
-
public GraphToTypedInstanceMapper getGraphToInstanceMapper() {
return graphToInstanceMapper;
}
@@ -161,7 +145,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities);
List<String> createdGuids = RequestContext.get().getCreatedEntityIds();
CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
- AtlasClient.EntityResult entityResult = new AtlasClient.EntityResult(createdGuids, null, null);
+ EntityResult entityResult = new EntityResult(createdGuids, null, null);
GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
result.setEntityResult(entityResult);
result.setGuidMapping(mapping);
@@ -174,6 +158,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
}
@Override
+ @GraphTransaction
public ITypedReferenceableInstance getEntityDefinition(String guid) throws RepositoryException, EntityNotFoundException {
return getEntityDefinitions(guid).get(0);
}
@@ -469,7 +454,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
@Override
@GraphTransaction
- public AtlasClient.EntityResult deleteEntities(List<String> guids) throws RepositoryException {
+ public EntityResult deleteEntities(List<String> guids) throws RepositoryException {
if (guids == null || guids.size() == 0) {
throw new IllegalArgumentException("guids must be non-null and non-empty");
@@ -491,7 +476,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
if (deletionCandidates.isEmpty()) {
LOG.info("No deletion candidate entities were found for guids %s", guids);
- return new AtlasClient.EntityResult(Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
+ return new EntityResult(Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
}
try {
@@ -505,14 +490,14 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
return createEntityResultFromContext(requestContext);
}
- private AtlasClient.EntityResult createEntityResultFromContext(RequestContext requestContext) {
- return new AtlasClient.EntityResult(
+ private EntityResult createEntityResultFromContext(RequestContext requestContext) {
+ return new EntityResult(
requestContext.getCreatedEntityIds(),
requestContext.getUpdatedEntityIds(),
requestContext.getDeletedEntityIds());
}
public AtlasGraph getGraph() throws RepositoryException {
- return graphProvider.get();
+ return atlasGraph;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
index 9b921f9..35dbf6c 100755
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
@@ -60,6 +60,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.math.BigDecimal;
@@ -76,6 +77,7 @@ import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*;
/**
* Adds index for properties of a given type when its added before any instances are added.
*/
+@Component
public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChangeHandler,
TypeDefChangeListener {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/GraphSchemaInitializer.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphSchemaInitializer.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphSchemaInitializer.java
index 8b03b6a..e877680 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphSchemaInitializer.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphSchemaInitializer.java
@@ -22,6 +22,7 @@ import org.apache.atlas.setup.SetupException;
import org.apache.atlas.setup.SetupStep;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
/**
* A {@link SetupStep} that initializes the Graph backend for Atlas.
@@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory;
* This class will initialize the specific backend implementation specified in
* the Atlas configuration for the key atlas.graph.storage.backend.
*/
+@Component
public class GraphSchemaInitializer implements SetupStep {
private static final Logger LOG = LoggerFactory.getLogger(GraphSchemaInitializer.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
index 3a54e3e..bbacb14 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java
@@ -17,20 +17,10 @@
*/
package org.apache.atlas.repository.graph;
-import static org.apache.atlas.repository.graph.GraphHelper.string;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.apache.atlas.AtlasException;
import org.apache.atlas.RequestContext;
-import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.Constants;
+import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.atlas.repository.graphdb.AtlasGraph;
@@ -50,10 +40,20 @@ import org.apache.atlas.typesystem.types.TraitType;
import org.apache.atlas.typesystem.types.TypeSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-import com.google.inject.Singleton;
+import static org.apache.atlas.repository.graph.GraphHelper.string;
-@Singleton
+@Component
@Deprecated
public final class GraphToTypedInstanceMapper {
@@ -61,10 +61,11 @@ public final class GraphToTypedInstanceMapper {
private static TypeSystem typeSystem = TypeSystem.getInstance();
private static final GraphHelper graphHelper = GraphHelper.getInstance();
- private final IAtlasGraphProvider graphProvider;
+ private final AtlasGraph atlasGraph;
- public GraphToTypedInstanceMapper(IAtlasGraphProvider graphProvider) {
- this.graphProvider = graphProvider;
+ @Inject
+ public GraphToTypedInstanceMapper(AtlasGraph atlasGraph) {
+ this.atlasGraph = atlasGraph;
}
public ITypedReferenceableInstance mapGraphToTypedInstance(String guid, AtlasVertex instanceVertex)
@@ -448,7 +449,7 @@ public final class GraphToTypedInstanceMapper {
}
private AtlasGraph getGraph() throws RepositoryException {
- return graphProvider.get();
+ return atlasGraph;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/HardDeleteHandler.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/HardDeleteHandler.java b/repository/src/main/java/org/apache/atlas/repository/graph/HardDeleteHandler.java
index 78cf946..e00ef96 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/HardDeleteHandler.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/HardDeleteHandler.java
@@ -18,12 +18,17 @@
package org.apache.atlas.repository.graph;
-import com.google.inject.Inject;
+import org.apache.atlas.AtlasException;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
-import org.apache.atlas.AtlasException;
import org.apache.atlas.typesystem.types.TypeSystem;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.DeleteHandler.impl")
public class HardDeleteHandler extends DeleteHandler {
@Inject
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java b/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java
index dc21291..b37fe75 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java
@@ -18,19 +18,25 @@
package org.apache.atlas.repository.graph;
-import com.google.inject.Inject;
-import org.apache.atlas.repository.graphdb.AtlasEdge;
-import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.AtlasException;
import org.apache.atlas.RequestContext;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
+import org.apache.atlas.repository.graphdb.AtlasEdge;
+import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.typesystem.types.TypeSystem;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
import static org.apache.atlas.repository.Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.MODIFIED_BY_KEY;
import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY;
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.DeleteHandler.impl", isDefault = true)
public class SoftDeleteHandler extends DeleteHandler {
+
@Inject
public SoftDeleteHandler(TypeSystem typeSystem) {
super(typeSystem, false, true);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
index c3e25bd..4dac293 100644
--- a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java
@@ -17,19 +17,8 @@
*/
package org.apache.atlas.repository.graph;
-import static org.apache.atlas.repository.graph.GraphHelper.string;
-
-import java.security.MessageDigest;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
import org.apache.atlas.AtlasException;
import org.apache.atlas.RequestContext;
import org.apache.atlas.model.instance.GuidMapping;
@@ -46,27 +35,30 @@ import org.apache.atlas.typesystem.exception.EntityExistsException;
import org.apache.atlas.typesystem.exception.EntityNotFoundException;
import org.apache.atlas.typesystem.persistence.Id;
import org.apache.atlas.typesystem.persistence.ReferenceableInstance;
-import org.apache.atlas.typesystem.types.AttributeInfo;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
+import org.apache.atlas.typesystem.types.*;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
-import org.apache.atlas.typesystem.types.EnumValue;
-import org.apache.atlas.typesystem.types.IDataType;
-import org.apache.atlas.typesystem.types.Multiplicity;
-import org.apache.atlas.typesystem.types.ObjectGraphWalker;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.typesystem.types.TypeUtils;
import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.apache.atlas.util.AtlasRepositoryConfiguration;
import org.apache.atlas.utils.MD5Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import com.google.inject.Inject;
+import javax.inject.Inject;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.atlas.repository.graph.GraphHelper.string;
+@Component
@Deprecated
public final class TypedInstanceToGraphMapper {
@@ -473,8 +465,8 @@ public final class TypedInstanceToGraphMapper {
IDataType entryType, AttributeInfo attributeInfo) throws AtlasException {
if (currentEntries != null && !currentEntries.isEmpty()) {
LOG.debug("Removing unused entries from the old collection");
- if (entryType.getTypeCategory() == DataTypes.TypeCategory.STRUCT
- || entryType.getTypeCategory() == DataTypes.TypeCategory.CLASS) {
+ if (entryType.getTypeCategory() == TypeCategory.STRUCT
+ || entryType.getTypeCategory() == TypeCategory.CLASS) {
//Remove the edges for (current edges - new edges)
List<AtlasEdge> cloneElements = new ArrayList<>(currentEntries);
@@ -840,7 +832,7 @@ public final class TypedInstanceToGraphMapper {
if (dateVal != null) {
propertyValue = dateVal.getTime();
}
- } else if (attributeInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.ENUM) {
+ } else if (attributeInfo.dataType().getTypeCategory() == TypeCategory.ENUM) {
if (attrValue != null) {
propertyValue = ((EnumValue) attrValue).value;
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
index 2f298ba..7744c78 100644
--- a/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
+++ b/repository/src/main/java/org/apache/atlas/repository/impexp/ExportService.java
@@ -35,7 +35,6 @@ import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever;
import org.apache.atlas.type.AtlasArrayType;
@@ -55,7 +54,9 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.util.ArrayList;
@@ -68,6 +69,7 @@ import java.util.Set;
import static org.apache.atlas.model.impexp.AtlasExportRequest.*;
+@Component
public class ExportService {
private static final Logger LOG = LoggerFactory.getLogger(ExportService.class);
@@ -76,10 +78,11 @@ public class ExportService {
private final EntityGraphRetriever entityGraphRetriever;
private final AtlasGremlinQueryProvider gremlinQueryProvider;
- public ExportService(final AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
+ @Inject
+ public ExportService(final AtlasTypeRegistry typeRegistry, AtlasGraph atlasGraph) throws AtlasBaseException {
this.typeRegistry = typeRegistry;
this.entityGraphRetriever = new EntityGraphRetriever(this.typeRegistry);
- this.atlasGraph = AtlasGraphProvider.getGraphInstance();
+ this.atlasGraph = atlasGraph;
this.gremlinQueryProvider = AtlasGremlinQueryProvider.INSTANCE;
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java b/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
index 245c1d8..4530f51 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/bootstrap/AtlasTypeDefStoreInitializer.java
@@ -33,12 +33,16 @@ import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@@ -57,10 +61,28 @@ import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.PUBLIC_ONL
/**
* Class that handles initial loading of models and patches into typedef store
*/
+@Service
public class AtlasTypeDefStoreInitializer {
private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefStoreInitializer.class);
- public void initializeStore(AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry, String typesDirName) {
+ private final AtlasTypeDefStore atlasTypeDefStore;
+ private final AtlasTypeRegistry atlasTypeRegistry;
+
+ @Inject
+ public AtlasTypeDefStoreInitializer(AtlasTypeDefStore atlasTypeDefStore, AtlasTypeRegistry atlasTypeRegistry) {
+ this.atlasTypeDefStore = atlasTypeDefStore;
+ this.atlasTypeRegistry = atlasTypeRegistry;
+ }
+
+ @PostConstruct
+ public void init() {
+ String atlasHomeDir = System.getProperty("atlas.home");
+ String typesDirName = (StringUtils.isEmpty(atlasHomeDir) ? "." : atlasHomeDir) + File.separator + "models";
+
+ initializeStore(typesDirName);
+ }
+
+ private void initializeStore(String typesDirName) {
File typesDir = new File(typesDirName);
File[] typeDefFiles = typesDir.exists() ? typesDir.listFiles() : null;
@@ -88,11 +110,11 @@ public class AtlasTypeDefStoreInitializer {
continue;
}
- AtlasTypesDef typesToCreate = getTypesToCreate(typesDef, typeRegistry);
- AtlasTypesDef typesToUpdate = getTypesToUpdate(typesDef, typeRegistry);
+ AtlasTypesDef typesToCreate = getTypesToCreate(typesDef, atlasTypeRegistry);
+ AtlasTypesDef typesToUpdate = getTypesToUpdate(typesDef, atlasTypeRegistry);
if (!typesToCreate.isEmpty() || !typesToUpdate.isEmpty()) {
- typeDefStore.createUpdateTypesDef(typesToCreate, typesToUpdate);
+ atlasTypeDefStore.createUpdateTypesDef(typesToCreate, typesToUpdate);
LOG.info("Created/Updated types defined in file {}", typeDefFile.getAbsolutePath());
} else {
@@ -104,7 +126,7 @@ public class AtlasTypeDefStoreInitializer {
}
}
- applyTypePatches(typeDefStore, typeRegistry, typesDirName);
+ applyTypePatches(typesDirName);
}
public static AtlasTypesDef getTypesToCreate(AtlasTypesDef typesDef, AtlasTypeRegistry typeRegistry) {
@@ -239,7 +261,7 @@ public class AtlasTypeDefStoreInitializer {
return ObjectUtils.compare(newTypeVersion, oldTypeVersion) > 0;
}
- private void applyTypePatches(AtlasTypeDefStore typeDefStore, AtlasTypeRegistry typeRegistry, String typesDirName) {
+ private void applyTypePatches(String typesDirName) {
String typePatchesDirName = typesDirName + File.separator + "patches";
File typePatchesDir = new File(typePatchesDirName);
File[] typePatchFiles = typePatchesDir.exists() ? typePatchesDir.listFiles() : null;
@@ -254,9 +276,9 @@ public class AtlasTypeDefStoreInitializer {
Arrays.sort(typePatchFiles);
PatchHandler[] patchHandlers = new PatchHandler[] {
- new AddAttributePatchHandler(typeDefStore, typeRegistry),
- new UpdateTypeDefOptionsPatchHandler(typeDefStore, typeRegistry),
- new UpdateAttributePatchHandler(typeDefStore, typeRegistry)
+ new AddAttributePatchHandler(atlasTypeDefStore, atlasTypeRegistry),
+ new UpdateTypeDefOptionsPatchHandler(atlasTypeDefStore, atlasTypeRegistry),
+ new UpdateAttributePatchHandler(atlasTypeDefStore, atlasTypeRegistry)
};
Map<String, PatchHandler> patchHandlerRegistry = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
index e873e91..a4163f2 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java
@@ -17,12 +17,9 @@
*/
package org.apache.atlas.repository.store.graph;
-
-import org.apache.atlas.GraphTransaction;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.impexp.AtlasImportResult;
import org.apache.atlas.model.instance.AtlasClassification;
-import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
import org.apache.atlas.model.instance.EntityMutationResponse;
@@ -132,7 +129,6 @@ public interface AtlasEntityStore {
*/
void updateClassifications(String guid, List<AtlasClassification> classifications) throws AtlasBaseException;
- @GraphTransaction
void addClassification(List<String> guids, AtlasClassification classification) throws AtlasBaseException;
/**
@@ -140,9 +136,7 @@ public interface AtlasEntityStore {
*/
void deleteClassifications(String guid, List<String> classificationNames) throws AtlasBaseException;
- @GraphTransaction
List<AtlasClassification> getClassifications(String guid) throws AtlasBaseException;
- @GraphTransaction
AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException;
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
index 4a8e1de..17b7e17 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
@@ -19,8 +19,8 @@ package org.apache.atlas.repository.store.graph;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.GraphTransaction;
import org.apache.atlas.GraphTransactionInterceptor;
+import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.ActiveStateChangeHandler;
import org.apache.atlas.listener.ChangedTypeDefs;
@@ -34,7 +34,6 @@ import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer;
import org.apache.atlas.repository.util.FilterUtil;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasClassificationType;
@@ -52,7 +51,6 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -108,8 +106,6 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commitUpdates);
}
-
- bootstrapTypes();
}
@Override
@@ -571,15 +567,6 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ
LOG.info("Not reacting to a Passive state change");
}
- private void bootstrapTypes() {
- AtlasTypeDefStoreInitializer storeInitializer = new AtlasTypeDefStoreInitializer();
-
- String atlasHomeDir = System.getProperty("atlas.home");
- String typesDirName = (StringUtils.isEmpty(atlasHomeDir) ? "." : atlasHomeDir) + File.separator + "models";
-
- storeInitializer.initializeStore(this, typeRegistry, typesDirName);
- }
-
private AtlasBaseTypeDef getTypeDefFromType(AtlasType type) throws AtlasBaseException {
AtlasBaseTypeDef ret;
switch (type.getTypeCategory()) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
index d9bc924..6423aea 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java
@@ -18,8 +18,6 @@
package org.apache.atlas.repository.store.graph.v1;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
@@ -30,7 +28,8 @@ import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations.EntityOperation;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.converters.AtlasInstanceConverter;
-import org.apache.atlas.repository.graph.*;
+import org.apache.atlas.repository.graph.FullTextMapperV2;
+import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.ITypedStruct;
@@ -39,14 +38,16 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
-@Singleton
+@Component
public class AtlasEntityChangeNotifier {
private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityChangeNotifier.class);
@@ -101,7 +102,7 @@ public class AtlasEntityChangeNotifier {
try {
listener.onTraitsAdded(entity, traits);
} catch (AtlasException e) {
- throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e);
+ throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitAdd");
}
}
}
@@ -120,7 +121,7 @@ public class AtlasEntityChangeNotifier {
try {
listener.onTraitsDeleted(entity, traitNames);
} catch (AtlasException e) {
- throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e);
+ throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitDelete");
}
}
}
@@ -140,11 +141,15 @@ public class AtlasEntityChangeNotifier {
try {
listener.onTraitsUpdated(entity, traits);
} catch (AtlasException e) {
- throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e);
+ throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitUpdate");
}
}
}
+ private String getListenerName(EntityChangeListener listener) {
+ return listener.getClass().getSimpleName();
+ }
+
private void notifyListeners(List<AtlasEntityHeader> entityHeaders, EntityOperation operation, boolean isImport) throws AtlasBaseException {
if (CollectionUtils.isEmpty(entityHeaders)) {
return;
@@ -167,7 +172,7 @@ public class AtlasEntityChangeNotifier {
break;
}
} catch (AtlasException e) {
- throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, operation.toString());
+ throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), operation.toString());
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
index 1bfe3b9..8046234 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java
@@ -17,7 +17,6 @@
*/
package org.apache.atlas.repository.store.graph.v1;
-import com.google.inject.Inject;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasEntityDef;
@@ -32,6 +31,7 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
[06/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/integration/EntityDiscoveryJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityDiscoveryJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityDiscoveryJerseyResourceIT.java
new file mode 100755
index 0000000..157bf97
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityDiscoveryJerseyResourceIT.java
@@ -0,0 +1,211 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.discovery.AtlasSearchResult;
+import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult;
+import org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType;
+import org.apache.atlas.model.instance.AtlasEntity.Status;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
+import org.apache.atlas.typesystem.TypesDef;
+import org.apache.atlas.typesystem.types.ClassType;
+import org.apache.atlas.typesystem.types.DataTypes;
+import org.apache.atlas.typesystem.types.EnumTypeDefinition;
+import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
+import org.apache.atlas.typesystem.types.StructTypeDefinition;
+import org.apache.atlas.typesystem.types.TraitType;
+import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+/**
+ * Search V2 Integration Tests.
+ */
+public class EntityDiscoveryJerseyResourceIT extends BaseResourceIT {
+ private String dbName;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+ dbName = "db" + randomString();
+ createTypes();
+ createInstance(createHiveDBInstanceBuiltIn(dbName));
+ }
+
+ @Test
+ public void testSearchByDSL() throws Exception {
+ String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
+
+ AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
+ assertNotNull(searchResult);
+ assertEquals(searchResult.getQueryText(), dslQuery);
+ assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
+
+ List<AtlasEntityHeader> entities = searchResult.getEntities();
+ assertNotNull(entities);
+ assertEquals(entities.size(), 1);
+
+ AtlasEntityHeader dbEntity = entities.get(0);
+ assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
+ assertEquals(dbEntity.getDisplayText(), dbName);
+ assertEquals(dbEntity.getStatus(), Status.ACTIVE);
+ assertNotNull(dbEntity.getGuid());
+ assertNull(searchResult.getAttributes());
+ assertNull(searchResult.getFullTextResult());
+ }
+
+ @Test
+ public void testSearchDSLLimits() throws Exception {
+ String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
+ AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
+ assertNotNull(searchResult);
+
+ //higher limit, all results returned
+ searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);
+ assertEquals(searchResult.getEntities().size(), 1);
+
+ //default limit and offset -1, all results returned
+ searchResult = atlasClientV2.dslSearchWithParams(dslQuery, -1, -1);
+ assertEquals(searchResult.getEntities().size(), 1);
+
+ //uses the limit parameter passed
+ searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 1, 0);
+ assertEquals(searchResult.getEntities().size(), 1);
+
+ //uses the offset parameter passed
+ searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, 1);
+ assertNull(searchResult.getEntities());
+
+ //limit > 0
+ searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 0, 10);
+ assertNull(searchResult.getEntities());
+
+ //limit > maxlimit
+ searchResult = atlasClientV2.dslSearchWithParams(dslQuery, Integer.MAX_VALUE, 10);
+ assertNull(searchResult.getEntities());
+
+ //offset >= 0
+ searchResult = atlasClientV2.dslSearchWithParams(dslQuery, 10, -2);
+ assertEquals(searchResult.getEntities().size(), 1);
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testSearchByDSLForUnknownType() throws Exception {
+ String dslQuery = "from blah";
+ atlasClientV2.dslSearch(dslQuery);
+ }
+
+ @Test
+ public void testSearchUsingDSL() throws Exception {
+ String query = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
+ AtlasSearchResult searchResult = atlasClientV2.dslSearch(query);
+ assertNotNull(searchResult);
+
+ assertEquals(searchResult.getQueryText(), query);
+ assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
+ List<AtlasEntityHeader> entities = searchResult.getEntities();
+ assertNotNull(entities);
+ assertEquals(entities.size(), 1);
+
+ AtlasEntityHeader dbEntity = entities.get(0);
+ assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
+ assertEquals(dbEntity.getDisplayText(), dbName);
+ assertEquals(dbEntity.getStatus(), Status.ACTIVE);
+
+ assertNotNull(dbEntity.getGuid());
+ assertNull(searchResult.getAttributes());
+ assertNull(searchResult.getFullTextResult());
+ }
+
+ @Test
+ public void testSearchFullTextOnDSLFailure() throws Exception {
+ String query = "*";
+ AtlasSearchResult searchResult = atlasClientV2.fullTextSearch(query);
+ assertNotNull(searchResult);
+ assertEquals(searchResult.getQueryText(), query);
+ assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT);
+ }
+
+ @Test(dependsOnMethods = "testSearchDSLLimits")
+ public void testSearchUsingFullText() throws Exception {
+ AtlasSearchResult searchResult = atlasClientV2.fullTextSearchWithParams(dbName, 10, 0);
+ assertNotNull(searchResult);
+
+ assertEquals(searchResult.getQueryText(), dbName);
+ assertEquals(searchResult.getQueryType(), AtlasQueryType.FULL_TEXT);
+
+ List<AtlasFullTextResult> fullTextResults = searchResult.getFullTextResult();
+ assertEquals(fullTextResults.size(), 1);
+
+ AtlasFullTextResult result = fullTextResults.get(0);
+ assertNotNull(result.getEntity());
+ assertEquals(result.getEntity().getTypeName(), DATABASE_TYPE_BUILTIN);
+ assertNotNull(result.getScore());
+
+ //API works without limit and offset
+ String query = dbName;
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("query", query);
+ searchResult = atlasClientV2.fullTextSearch(query);
+ assertNotNull(searchResult);
+ assertEquals(searchResult.getFullTextResult().size(), 1);
+
+ //verify passed in limits and offsets are used
+ //higher limit and 0 offset returns all results
+ searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 0);
+ assertEquals(searchResult.getFullTextResult().size(), 1);
+
+ //offset is used
+ searchResult = atlasClientV2.fullTextSearchWithParams(query, 10, 1);
+ assertEquals(searchResult.getFullTextResult().size(), 1);
+
+ //limit is used
+ searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 0);
+ assertEquals(searchResult.getFullTextResult().size(), 1);
+
+ //higher offset returns 0 results
+ searchResult = atlasClientV2.fullTextSearchWithParams(query, 1, 2);
+ assertEquals(searchResult.getFullTextResult().size(), 1);
+ }
+
+ private void createTypes() throws Exception {
+ HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil
+ .createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
+
+ HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil
+ .createTraitTypeDef("Classification", ImmutableSet.<String>of(),
+ TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
+ TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
+ ImmutableList.of(classificationTraitDefinition), ImmutableList.of(dslTestTypeDefinition));
+ createType(typesDef);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
new file mode 100755
index 0000000..310b2e3
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityJerseyResourceIT.java
@@ -0,0 +1,1101 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasClient;
+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;
+import org.apache.atlas.typesystem.json.InstanceSerialization;
+import org.apache.atlas.typesystem.json.InstanceSerialization$;
+import org.apache.atlas.typesystem.json.TypesSerialization;
+import org.apache.atlas.typesystem.json.TypesSerialization$;
+import org.apache.atlas.typesystem.persistence.Id;
+import org.apache.atlas.typesystem.types.ClassType;
+import org.apache.atlas.typesystem.types.DataTypes;
+import org.apache.atlas.typesystem.types.EnumTypeDefinition;
+import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
+import org.apache.atlas.typesystem.types.StructTypeDefinition;
+import org.apache.atlas.typesystem.types.TraitType;
+import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.apache.atlas.utils.AuthenticationUtil;
+import org.apache.commons.lang.RandomStringUtils;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.fail;
+
+
+/**
+ * Integration tests for Entity Jersey Resource.
+ */
+public class EntityJerseyResourceIT extends BaseResourceIT {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EntityJerseyResourceIT.class);
+
+ private static final String TRAITS = "traits";
+
+ private NotificationInterface notificationInterface = NotificationProvider.get();
+ private NotificationConsumer<EntityNotification> notificationConsumer;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+
+ createTypeDefinitionsV1();
+
+ List<NotificationConsumer<EntityNotification>> consumers =
+ notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);
+
+ notificationConsumer = consumers.iterator().next();
+ }
+
+ @Test
+ public void testCreateNestedEntities() throws Exception {
+
+ Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
+ databaseInstance.set("name", "db1");
+ databaseInstance.set("description", "foo database");
+
+ int nTables = 5;
+ int colsPerTable=3;
+ List<Referenceable> tables = new ArrayList<>();
+ List<Referenceable> allColumns = new ArrayList<>();
+
+ for(int i = 0; i < nTables; i++) {
+ String tableName = "db1-table-" + i;
+
+ Referenceable tableInstance =
+ new Referenceable(HIVE_TABLE_TYPE);
+ tableInstance.set("name", tableName);
+ tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
+ tableInstance.set("db", databaseInstance);
+ tableInstance.set("description", tableName + " table");
+ tables.add(tableInstance);
+
+ List<Referenceable> columns = new ArrayList<>();
+ for(int j = 0; j < colsPerTable; j++) {
+ Referenceable columnInstance = new Referenceable(COLUMN_TYPE);
+ columnInstance.set("name", tableName + "-col-" + j);
+ columnInstance.set("dataType", "String");
+ columnInstance.set("comment", "column " + j + " for table " + i);
+ allColumns.add(columnInstance);
+ columns.add(columnInstance);
+ }
+ tableInstance.set("columns", columns);
+ }
+
+ //Create the tables. The database and columns should be created automatically, since
+ //the tables reference them.
+ List<String> entityGUIDs = atlasClientV1.createEntity(tables);
+ assertNotNull(entityGUIDs);
+ assertEquals(entityGUIDs.size(), nTables * (colsPerTable + 1) + 1);
+ }
+
+
+ @Test
+ public void testSubmitEntity() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(referenceable);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+ }
+
+ @Test
+ public void testRequestUser() throws Exception {
+ Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName = randomString();
+ entity.set("name", dbName);
+ entity.set(QUALIFIED_NAME, dbName);
+ entity.set("clusterName", randomString());
+ entity.set("description", randomString());
+ entity.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ entity.set("owner", "user1");
+ entity.set("clusterName", "cl1");
+ entity.set("parameters", Collections.EMPTY_MAP);
+ entity.set("location", "/tmp");
+
+
+ String user = "admin";
+ AtlasClient localClient = null;
+ if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
+ localClient = new AtlasClient(atlasUrls, new String[]{"admin", "admin"});
+ } else {
+ localClient = new AtlasClient(atlasUrls);
+ }
+ String entityId = localClient.createEntity(entity).get(0);
+
+ List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(entityId, (short) 10);
+ assertEquals(events.size(), 1);
+ assertEquals(events.get(0).getUser(), user);
+ }
+
+ @Test
+ //API should accept single entity (or jsonarray of entities)
+ public void testSubmitSingleEntity() throws Exception {
+ Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName = randomString();
+ databaseInstance.set("name", dbName);
+ databaseInstance.set(QUALIFIED_NAME, dbName);
+ databaseInstance.set("clusterName", randomString());
+ databaseInstance.set("description", randomString());
+ databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ databaseInstance.set("owner", "user1");
+ databaseInstance.set("clusterName", "cl1");
+ databaseInstance.set("parameters", Collections.EMPTY_MAP);
+ databaseInstance.set("location", "/tmp");
+
+ JSONObject response = atlasClientV1
+ .callAPIWithBody(AtlasClient.API.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true));
+ assertNotNull(response);
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ EntityResult entityResult = EntityResult.fromString(response.toString());
+ assertEquals(entityResult.getCreatedEntities().size(), 1);
+ assertNotNull(entityResult.getCreatedEntities().get(0));
+ }
+
+ @Test
+ public void testEntityDeduping() throws Exception {
+ final String dbName = "db" + randomString();
+ Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbIdReference = createInstance(HiveDBInstance);
+ final String dbId = dbIdReference._getId();
+
+ assertEntityAudit(dbId, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE);
+
+ waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
+ @Override
+ public boolean evaluate(EntityNotification notification) throws Exception {
+ return notification != null && notification.getEntity().getId()._getId().equals(dbId);
+ }
+ });
+
+ JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
+ assertEquals(results.length(), 1);
+
+ //create entity again shouldn't create another instance with same unique attribute value
+ List<String> entityResults = atlasClientV1.createEntity(HiveDBInstance);
+ assertEquals(entityResults.size(), 0);
+ try {
+ waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
+ @Override
+ public boolean evaluate(EntityNotification notification) throws Exception {
+ return notification != null && notification.getEntity().getId()._getId().equals(dbId);
+ }
+ });
+ } catch (Exception e) {
+ //expected timeout
+ }
+
+ results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
+ assertEquals(results.length(), 1);
+
+ //Test the same across references
+ Referenceable table = new Referenceable(HIVE_TABLE_TYPE_BUILTIN);
+ final String tableName = randomString();
+ Referenceable tableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbIdReference);
+ atlasClientV1.createEntity(tableInstance);
+ results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
+ assertEquals(results.length(), 1);
+ }
+
+ private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
+ throws Exception {
+ List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
+ for (EntityAuditEvent event : events) {
+ if (event.getAction() == auditAction) {
+ return;
+ }
+ }
+ fail("Expected audit event with action = " + auditAction);
+ }
+
+ @Test
+ public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
+ //create type
+ HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil
+ .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE));
+ atlasClientV1.createType(TypesSerialization.toJson(typeDefinition, false));
+
+ //create entity for the type
+ Referenceable instance = new Referenceable(typeDefinition.typeName);
+ instance.set("name", randomString());
+ String guid = atlasClientV1.createEntity(instance).get(0);
+
+ //update type - add attribute
+ typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
+ TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE));
+ TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
+ ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
+ ImmutableList.of(typeDefinition));
+ atlasClientV1.updateType(typeDef);
+
+ //Get definition after type update - new attributes should be null
+ Referenceable entity = atlasClientV1.getEntity(guid);
+ Assert.assertNull(entity.get("description"));
+ Assert.assertEquals(entity.get("name"), instance.get("name"));
+ }
+
+ @DataProvider
+ public Object[][] invalidAttrValues() {
+ return new Object[][]{{null}, {""}};
+ }
+
+ @Test(dataProvider = "invalidAttrValues")
+ public void testEntityInvalidValue(String value) throws Exception {
+ Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
+ databaseInstance.set("name", randomString());
+ databaseInstance.set("description", value);
+
+ try {
+ createInstance(databaseInstance);
+ Assert.fail("Expected AtlasServiceException");
+ } catch (AtlasServiceException e) {
+ Assert.assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
+ }
+ }
+
+ @Test
+ public void testGetEntityByAttribute() throws Exception {
+ Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName = randomString();
+ db1.set(NAME, dbName);
+ db1.set(DESCRIPTION, randomString());
+ db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ db1.set("owner", "user1");
+ db1.set(CLUSTER_NAME, "cl1");
+ db1.set("parameters", Collections.EMPTY_MAP);
+ db1.set("location", "/tmp");
+ createInstance(db1);
+
+ //get entity by attribute
+ Referenceable referenceable = atlasClientV1.getEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName);
+ Assert.assertEquals(referenceable.getTypeName(), DATABASE_TYPE_BUILTIN);
+ Assert.assertEquals(referenceable.get(QUALIFIED_NAME), dbName);
+ }
+
+ @Test
+ public void testSubmitEntityWithBadDateFormat() throws Exception {
+ try {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ hiveTableInstance.set("lastAccessTime", "2014-07-11");
+ Id tableId = createInstance(hiveTableInstance);
+ Assert.fail("Was expecting an exception here ");
+ } catch (AtlasServiceException e) {
+ Assert.assertTrue(
+ e.getMessage().contains("\"error\":\"Cannot convert value '2014-07-11' to datatype date\""));
+ }
+ }
+
+ @Test
+ public void testAddProperty() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(referenceable);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+ //add property
+ String description = "bar table - new desc";
+ addProperty(guid, "description", description);
+
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
+ Assert.assertNotNull(response);
+
+ referenceable.set("description", description);
+
+ //invalid property for the type
+ try {
+ addProperty(guid, "invalid_property", "bar table");
+ Assert.fail("Expected AtlasServiceException");
+ } catch (AtlasServiceException e) {
+ Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
+ }
+
+ String currentTime = String.valueOf(new DateTime());
+
+ // updating date attribute as string not supported in v2
+ // addProperty(guid, "createTime", currentTime);
+
+ response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
+ Assert.assertNotNull(response);
+
+ referenceable.set("createTime", currentTime);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testAddNullProperty() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ //add property
+ addProperty(guid, null, "foo bar");
+ Assert.fail();
+ }
+
+ @Test(enabled = false)
+ public void testAddNullPropertyValue() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ //add property
+ try {
+ addProperty(guid, "description", null);
+ Assert.fail("Expected AtlasServiceException");
+ } catch(AtlasServiceException e) {
+ Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
+ }
+ }
+
+ @Test
+ public void testAddReferenceProperty() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ //Create new db instance
+ dbName = "db" + randomString();
+ Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
+ databaseInstance.set(NAME, dbName);
+ databaseInstance.set(QUALIFIED_NAME, dbName);
+ databaseInstance.set(CLUSTER_NAME, randomString());
+ databaseInstance.set("description", "new database");
+ databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ databaseInstance.set("owner", "user1");
+ databaseInstance.set(CLUSTER_NAME, "cl1");
+ databaseInstance.set("parameters", Collections.EMPTY_MAP);
+ databaseInstance.set("location", "/tmp");
+
+ Id dbInstance = createInstance(databaseInstance);
+ String newDBId = dbInstance._getId();
+
+ //Add reference property
+ addProperty(guid, "db", newDBId);
+ }
+
+ @Test
+ public void testGetEntityDefinition() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ Referenceable entity = atlasClientV1.getEntity(guid);
+ Assert.assertNotNull(entity);
+ }
+
+ private void addProperty(String guid, String property, String value) throws AtlasServiceException {
+ EntityResult entityResult = atlasClientV1.updateEntityAttribute(guid, property, value);
+ assertEquals(entityResult.getUpdateEntities().size(), 1);
+ assertEquals(entityResult.getUpdateEntities().get(0), guid);
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testGetInvalidEntityDefinition() throws Exception {
+
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, "blah");
+
+ Assert.assertNotNull(response);
+
+ Assert.assertNotNull(response.get(AtlasClient.ERROR));
+ }
+
+ @Test
+ public void testGetEntityList() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ List<String> entities = atlasClientV1.listEntities(HIVE_TABLE_TYPE_BUILTIN);
+ Assert.assertNotNull(entities);
+ Assert.assertTrue(entities.contains(guid));
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testGetEntityListForBadEntityType() throws Exception {
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("type", "blah");
+
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
+ assertNotNull(response);
+ Assert.assertNotNull(response.get(AtlasClient.ERROR));
+ }
+
+
+ @Test
+ public void testGetEntityListForNoInstances() throws Exception {
+ String typeName = addNewType();
+
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("type", typeName);
+
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
+ assertNotNull(response);
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
+ Assert.assertEquals(list.length(), 0);
+ }
+
+ private String addNewType() throws Exception {
+ String typeName = "test" + randomString();
+ HierarchicalTypeDefinition<ClassType> testTypeDefinition = TypesUtil
+ .createClassTypeDef(typeName, ImmutableSet.<String>of(),
+ TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
+
+ String typesAsJSON = TypesSerialization.toJson(testTypeDefinition, false);
+ createType(typesAsJSON);
+ return typeName;
+ }
+
+ @Test
+ public void testGetTraitNames() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ List<String> traits = atlasClientV1.listTraits(guid);
+ assertNotNull(traits);
+ Assert.assertEquals(traits.size(), 7);
+ }
+
+ @Test
+ public void testAddTrait() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ String traitName = "PII_Trait" + randomString();
+ HierarchicalTypeDefinition<TraitType> piiTrait =
+ TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
+ LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
+ createType(traitDefinitionAsJSON);
+
+ Struct traitInstance = new Struct(traitName);
+
+ atlasClientV1.addTrait(guid, traitInstance);
+ assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
+ }
+
+ @Test
+ public void testGetTraitDefinitionForEntity() throws Exception{
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ String traitName = "PII_Trait" + randomString();
+ HierarchicalTypeDefinition<TraitType> piiTrait =
+ TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
+ LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
+ createType(traitDefinitionAsJSON);
+
+ Struct traitInstance = new Struct(traitName);
+ atlasClientV1.addTrait(guid, traitInstance);
+ Struct traitDef = atlasClientV1.getTraitDefinition(guid, traitName);
+ Assert.assertEquals(traitDef.getTypeName(), traitName);
+
+
+ List<Struct> allTraitDefs = atlasClientV1.listTraitDefinitions(guid);
+ System.out.println(allTraitDefs.toString());
+ Assert.assertEquals(allTraitDefs.size(), 8);
+ }
+
+ @Test
+ public void testAddExistingTrait() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ String traitName = "PII_Trait" + randomString();
+ HierarchicalTypeDefinition<TraitType> piiTrait =
+ TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
+ LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
+ createType(traitDefinitionAsJSON);
+
+ Struct traitInstance = new Struct(traitName);
+ atlasClientV1.addTrait(guid, traitInstance);
+
+ try {
+ atlasClientV1.addTrait(guid, traitInstance);
+ fail("Duplicate trait addition should've failed");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
+ }
+ }
+
+ @Test
+ public void testAddTraitWithAttribute() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ final String traitName = "PII_Trait" + randomString();
+ HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
+ .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
+ TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
+ String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
+ LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
+ createType(traitDefinitionAsJSON);
+
+ Struct traitInstance = new Struct(traitName);
+ traitInstance.set("type", "SSN");
+ atlasClientV1.addTrait(guid, traitInstance);
+
+ // verify the response
+ Referenceable entity = atlasClientV1.getEntity(guid);
+ Assert.assertNotNull(entity);
+ Assert.assertEquals(entity.getId()._getId(), guid);
+
+ assertNotNull(entity.getTrait(traitName));
+ assertEquals(entity.getTrait(traitName).get("type"), traitInstance.get("type"));
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testAddTraitWithNoRegistration() throws Exception {
+ final String traitName = "PII_Trait" + randomString();
+ HierarchicalTypeDefinition<TraitType> piiTrait =
+ TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
+ LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
+
+ Struct traitInstance = new Struct(traitName);
+ String traitInstanceAsJSON = InstanceSerialization$.MODULE$.toJson(traitInstance, true);
+ LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
+
+ atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS);
+ }
+
+ @Test
+ public void testDeleteTrait() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ String traitName = "PII_Trait" + randomString();
+ HierarchicalTypeDefinition<TraitType> piiTrait =
+ TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
+ LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
+ createType(traitDefinitionAsJSON);
+
+ Struct traitInstance = new Struct(traitName);
+
+ atlasClientV1.addTrait(guid, traitInstance);
+ assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
+
+ atlasClientV1.deleteTrait(guid, traitName);
+
+ try {
+ atlasClientV1.getTraitDefinition(guid, traitName);
+ fail("Deleted trait definition shouldn't exist");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND);
+ assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
+ }
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testDeleteTraitNonExistent() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ final String traitName = "blah_trait";
+ atlasClientV1.deleteTrait(guid, traitName);
+ fail("trait=" + traitName + " should be defined in type system before it can be deleted");
+ }
+
+ @Test
+ public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id id = createInstance(hiveTableInstance);
+
+ final String guid = id._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ final String traitName = "PII_Trait" + randomString();
+ HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
+ .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
+ TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
+ String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
+ createType(traitDefinitionAsJSON);
+
+ try {
+ atlasClientV1.deleteTrait(guid, traitName);
+ fail("Call should've failed for deletion of invalid trait");
+ } catch (AtlasServiceException e) {
+ assertNotNull(e);
+ assertNotNull(e.getStatus());
+ assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND);
+ }
+ }
+
+ private String random() {
+ return RandomStringUtils.random(10);
+ }
+
+ @Test
+ public void testUTF8() throws Exception {
+ //Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
+ String classType = randomString();
+ String attrName = random();
+ String attrValue = random();
+
+ HierarchicalTypeDefinition<ClassType> classTypeDefinition = TypesUtil
+ .createClassTypeDef(classType, ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef(attrName, DataTypes.STRING_TYPE));
+ TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
+ ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
+ ImmutableList.of(classTypeDefinition));
+ createType(typesDef);
+
+ Referenceable instance = new Referenceable(classType);
+ instance.set(attrName, attrValue);
+ Id guid = createInstance(instance);
+
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid._getId());
+ Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.getString(AtlasClient.DEFINITION), true);
+ Assert.assertEquals(getReferenceable.get(attrName), attrValue);
+ }
+
+
+ @Test
+ public void testPartialUpdate() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id tableId = createInstance(hiveTableInstance);
+
+ final String guid = tableId._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ String colName = "col1"+randomString();
+ final List<Referenceable> columns = new ArrayList<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put(NAME, colName);
+ values.put("comment", "col1 comment");
+ values.put(QUALIFIED_NAME, "default.table.col1@"+colName);
+ values.put("comment", "col1 comment");
+ values.put("type", "string");
+ values.put("owner", "user1");
+ values.put("position", 0);
+ values.put("description", "col1");
+ values.put("table", tableId); //table is a required reference, can't be null
+
+ Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
+ columns.add(ref);
+ Referenceable tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {{
+ put("columns", columns);
+ }});
+
+ LOG.debug("Updating entity= {}", tableUpdated);
+ EntityResult entityResult = atlasClientV1.updateEntity(guid, tableUpdated);
+ assertEquals(entityResult.getUpdateEntities().size(), 1);
+ assertEquals(entityResult.getUpdateEntities().get(0), guid);
+
+ Referenceable entity = atlasClientV1.getEntity(guid);
+ List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
+
+ Assert.assertTrue(refs.get(0).equalsContents(columns.get(0)));
+
+ //Update by unique attribute
+ values.put("type", "int");
+ ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
+ columns.set(0, ref);
+ tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {{
+ put("columns", columns);
+ }});
+
+ LOG.debug("Updating entity= {}", tableUpdated);
+ entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
+ (String) hiveTableInstance.get(QUALIFIED_NAME), tableUpdated);
+ assertEquals(entityResult.getUpdateEntities().size(), 2);
+ assertEquals(entityResult.getUpdateEntities().get(1), guid);
+
+ entity = atlasClientV1.getEntity(guid);
+ refs = (List<Referenceable>) entity.get("columns");
+
+ Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
+ Assert.assertEquals(refs.get(0).get("type"), "int");
+ }
+
+ @Test
+ public void testCompleteUpdate() throws Exception {
+ String dbName = "db" + randomString();
+ String tableName = "table" + randomString();
+ Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
+ Id dbId = createInstance(hiveDBInstance);
+ Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
+ Id tableId = createInstance(hiveTableInstance);
+
+ final String guid = tableId._getId();
+ try {
+ Assert.assertNotNull(UUID.fromString(guid));
+ } catch (IllegalArgumentException e) {
+ Assert.fail("Response is not a guid, " + guid);
+ }
+
+ final List<Referenceable> columns = new ArrayList<>();
+ Map<String, Object> values1 = new HashMap<>();
+ values1.put(NAME, "col3");
+ values1.put(QUALIFIED_NAME, "default.table.col3@cl1");
+ values1.put("comment", "col3 comment");
+ values1.put("type", "string");
+ values1.put("owner", "user1");
+ values1.put("position", 0);
+ values1.put("description", "col3");
+ values1.put("table", tableId);
+
+
+ Map<String, Object> values2 = new HashMap<>();
+ values2.put(NAME, "col4");
+ values2.put(QUALIFIED_NAME, "default.table.col4@cl1");
+ values2.put("comment", "col4 comment");
+ values2.put("type", "string");
+ values2.put("owner", "user2");
+ values2.put("position", 1);
+ values2.put("description", "col4");
+ values2.put("table", tableId);
+
+ Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values1);
+ Referenceable ref2 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values2);
+ columns.add(ref1);
+ columns.add(ref2);
+ hiveTableInstance.set("columns", columns);
+ LOG.debug("Replacing entity= {}", hiveTableInstance);
+
+ EntityResult updateEntity = atlasClientV1.updateEntities(hiveTableInstance);
+
+ assertNotNull(updateEntity.getUpdateEntities());
+
+ hiveTableInstance = atlasClientV1.getEntity(guid);
+ List<Referenceable> refs = (List<Referenceable>) hiveTableInstance.get("columns");
+ Assert.assertEquals(refs.size(), 2);
+
+ Assert.assertTrue(refs.get(0).getValuesMap().equals(values1));
+ Assert.assertTrue(refs.get(1).getValuesMap().equals(values2));
+ }
+
+ @Test
+ public void testDeleteEntitiesViaRestApi() throws Exception {
+ // Create 2 database entities
+ Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName = randomString();
+ db1.set(NAME, dbName);
+ db1.set(DESCRIPTION, randomString());
+ db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ db1.set("owner", "user1");
+ db1.set(CLUSTER_NAME, "cl1");
+ db1.set("parameters", Collections.EMPTY_MAP);
+ db1.set("location", "/tmp");
+ Id db1Id = createInstance(db1);
+
+ Referenceable db2 = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName2 = randomString();
+ db2.set(NAME, dbName2);
+ db2.set(QUALIFIED_NAME, dbName2);
+ db2.set(CLUSTER_NAME, randomString());
+ db2.set(DESCRIPTION, randomString());
+ db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
+ db2.set("owner", "user2");
+ db2.set(CLUSTER_NAME, "cl1");
+ db2.set("parameters", Collections.EMPTY_MAP);
+ db2.set("location", "/tmp");
+ Id db2Id = createInstance(db2);
+
+ // Delete the database entities
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId());
+ queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId());
+
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.DELETE_ENTITIES, queryParams);
+ List<String> deletedGuidsList = EntityResult.fromString(response.toString()).getDeletedEntities();
+ Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
+ Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
+
+ // Verify entities were deleted from the repository.
+ for (String guid : deletedGuidsList) {
+ Referenceable entity = atlasClientV1.getEntity(guid);
+ assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
+ }
+ }
+
+ @Test
+ public void testDeleteEntitiesViaClientApi() throws Exception {
+ // Create 2 database entities
+ Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName = randomString();
+ db1.set("name", dbName);
+ db1.set("description", randomString());
+ db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ db1.set("owner", "user1");
+ db1.set(CLUSTER_NAME, "cl1");
+ db1.set("parameters", Collections.EMPTY_MAP);
+ db1.set("location", "/tmp");
+ Id db1Id = createInstance(db1);
+ Referenceable db2 = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName2 = randomString();
+ db2.set("name", dbName2);
+ db2.set(QUALIFIED_NAME, dbName2);
+ db2.set(CLUSTER_NAME, randomString());
+ db2.set("description", randomString());
+ db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
+ db2.set("owner", "user2");
+ db2.set("clusterName", "cl1");
+ db2.set("parameters", Collections.EMPTY_MAP);
+ db2.set("location", "/tmp");
+ Id db2Id = createInstance(db2);
+
+ // Delete the database entities
+ List<String> deletedGuidsList =
+ atlasClientV1.deleteEntities(db1Id._getId(), db2Id._getId()).getDeletedEntities();
+ // Verify that deleteEntities() response has database entity guids
+ Assert.assertEquals(deletedGuidsList.size(), 2);
+ Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
+ Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
+
+ // Verify entities were deleted from the repository.
+ for (String guid : deletedGuidsList) {
+ Referenceable entity = atlasClientV1.getEntity(guid);
+ assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
+ }
+ }
+
+ @Test
+ public void testDeleteEntityByUniqAttribute() throws Exception {
+ // Create database entity
+ Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
+ String dbName = randomString();
+ db1.set(NAME, dbName);
+ db1.set(QUALIFIED_NAME, dbName);
+ db1.set(CLUSTER_NAME, randomString());
+ db1.set(DESCRIPTION, randomString());
+ db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
+ db1.set("owner", "user1");
+ db1.set(CLUSTER_NAME, "cl1");
+ db1.set("parameters", Collections.EMPTY_MAP);
+ db1.set("location", "/tmp");
+ Id db1Id = createInstance(db1);
+
+ // Delete the database entity
+ List<String> deletedGuidsList = atlasClientV1.deleteEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName).getDeletedEntities();
+
+ // Verify that deleteEntities() response has database entity guids
+ Assert.assertEquals(deletedGuidsList.size(), 1);
+ Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
+
+ // Verify entities were deleted from the repository.
+ for (String guid : deletedGuidsList) {
+ Referenceable entity = atlasClientV1.getEntity(guid);
+ assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
new file mode 100644
index 0000000..55c56c2
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityLineageJerseyResourceIT.java
@@ -0,0 +1,190 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.gson.Gson;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasClient;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
+import org.apache.atlas.model.lineage.AtlasLineageInfo;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.persistence.Id;
+import org.codehaus.jettison.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+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 String salesFactTable;
+ private String salesMonthlyTable;
+ private String salesDBName;
+ Gson gson = new Gson();
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+
+ createTypeDefinitionsV1();
+ setupInstances();
+ }
+
+ @Test
+ public void testInputLineageInfo() throws Exception {
+ String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
+ AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
+
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION);
+ queryParams.add(DEPTH_PARAM, "5");
+ JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
+ Assert.assertNotNull(response);
+ System.out.println("input lineage info = " + response
+ );
+
+ AtlasLineageInfo inputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
+
+ Map<String, AtlasEntityHeader> entities = inputLineageInfo.getGuidEntityMap();
+ Assert.assertNotNull(entities);
+
+ Set<AtlasLineageInfo.LineageRelation> relations = inputLineageInfo.getRelations();
+ Assert.assertNotNull(relations);
+
+ Assert.assertEquals(entities.size(), 6);
+ Assert.assertEquals(relations.size(), 5);
+ Assert.assertEquals(inputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.INPUT);
+ Assert.assertEquals(inputLineageInfo.getLineageDepth(), 5);
+ Assert.assertEquals(inputLineageInfo.getBaseEntityGuid(), tableId);
+ }
+
+ @Test
+ public void testOutputLineageInfo() throws Exception {
+ String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
+ AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
+
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
+ queryParams.add(DEPTH_PARAM, "5");
+ JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
+
+ Assert.assertNotNull(response);
+ System.out.println("output lineage info = " + response);
+
+ AtlasLineageInfo outputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
+
+ Map<String, AtlasEntityHeader> entities = outputLineageInfo.getGuidEntityMap();
+ Assert.assertNotNull(entities);
+
+ Set<AtlasLineageInfo.LineageRelation> relations = outputLineageInfo.getRelations();
+ Assert.assertNotNull(relations);
+
+ Assert.assertEquals(entities.size(), 5);
+ Assert.assertEquals(relations.size(), 4);
+ Assert.assertEquals(outputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.OUTPUT);
+ Assert.assertEquals(outputLineageInfo.getLineageDepth(), 5);
+ Assert.assertEquals(outputLineageInfo.getBaseEntityGuid(), tableId);
+ }
+
+ @Test
+ public void testLineageInfo() throws Exception {
+ String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
+ AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
+
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
+ queryParams.add(DEPTH_PARAM, "5");
+ JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
+
+ Assert.assertNotNull(response);
+ System.out.println("both lineage info = " + response);
+
+ AtlasLineageInfo bothLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
+
+ Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap();
+ Assert.assertNotNull(entities);
+
+ Set<AtlasLineageInfo.LineageRelation> relations = bothLineageInfo.getRelations();
+ Assert.assertNotNull(relations);
+
+ Assert.assertEquals(entities.size(), 6);
+ Assert.assertEquals(relations.size(), 5);
+ Assert.assertEquals(bothLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
+ Assert.assertEquals(bothLineageInfo.getLineageDepth(), 5);
+ Assert.assertEquals(bothLineageInfo.getBaseEntityGuid(), tableId);
+ }
+
+ private void setupInstances() throws Exception {
+ salesDBName = "Sales" + randomString();
+ Id salesDB = database(salesDBName, "Sales Database", "John ETL", "hdfs://host:8000/apps/warehouse/sales");
+
+ List<Referenceable> salesFactColumns = ImmutableList
+ .of(column("time_id", "int", "time id"), column("product_id", "int", "product id"),
+ column("customer_id", "int", "customer id"),
+ column("sales", "double", "product id"));
+
+ salesFactTable = "sales_fact" + randomString();
+ Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns);
+
+ List<Referenceable> timeDimColumns = ImmutableList
+ .of(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"),
+ column("weekDay", "int", "week Day"));
+
+ Id timeDim =
+ table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL",
+ timeDimColumns);
+
+ Id reportingDB =
+ database("Reporting" + randomString(), "reporting database", "Jane BI",
+ "hdfs://host:8000/apps/warehouse/reporting");
+
+ Id salesFactDaily =
+ table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB,
+ "Joe BI", "MANAGED", salesFactColumns);
+
+ loadProcess("loadSalesDaily" + randomString(), "John ETL", ImmutableList.of(salesFact, timeDim),
+ ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph");
+
+ salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
+ Id salesFactMonthly =
+ table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI",
+ "MANAGED", salesFactColumns);
+
+ loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily),
+ ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph");
+ }
+}
[03/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
deleted file mode 100755
index f2af208..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityJerseyResourceIT.java
+++ /dev/null
@@ -1,953 +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.web.resources;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.AtlasServiceException;
-import org.apache.atlas.EntityAuditEvent;
-import org.apache.atlas.model.instance.GuidMapping;
-import org.apache.atlas.notification.NotificationConsumer;
-import org.apache.atlas.notification.NotificationInterface;
-import org.apache.atlas.notification.NotificationModule;
-import org.apache.atlas.notification.entity.EntityNotification;
-import org.apache.atlas.type.AtlasType;
-import org.apache.atlas.typesystem.IStruct;
-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.InstanceSerialization$;
-import org.apache.atlas.typesystem.json.TypesSerialization;
-import org.apache.atlas.typesystem.json.TypesSerialization$;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes;
-import org.apache.atlas.typesystem.types.EnumTypeDefinition;
-import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
-import org.apache.atlas.typesystem.types.StructTypeDefinition;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.apache.atlas.utils.AuthenticationUtil;
-import org.apache.commons.lang.RandomStringUtils;
-import org.codehaus.jettison.json.JSONArray;
-import org.codehaus.jettison.json.JSONObject;
-import org.joda.time.DateTime;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Guice;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.gson.Gson;
-import com.google.gson.JsonSyntaxException;
-import com.google.inject.Inject;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-
-/**
- * Integration tests for Entity Jersey Resource.
- */
-@Guice(modules = NotificationModule.class)
-public class EntityJerseyResourceIT extends BaseResourceIT {
-
- private static final Logger LOG = LoggerFactory.getLogger(EntityJerseyResourceIT.class);
-
- private final String DATABASE_NAME = "db" + randomString();
- private final String TABLE_NAME = "table" + randomString();
- private static final String TRAITS = "traits";
- private Referenceable tableInstance;
- private Id tableId;
- private Id dbId;
- private String traitName;
-
- @Inject
- private NotificationInterface notificationInterface;
- private NotificationConsumer<EntityNotification> notificationConsumer;
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
-
- createTypeDefinitionsV1();
- Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(DATABASE_NAME);
- dbId = createInstance(HiveDBInstance);
-
- List<NotificationConsumer<EntityNotification>> consumers =
- notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);
-
- notificationConsumer = consumers.iterator().next();
- }
-
- @Test
- public void testCreateNestedEntities() throws Exception {
-
- Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
- databaseInstance.set("name", "db1");
- databaseInstance.set("description", "foo database");
-
- int nTables = 5;
- int colsPerTable=3;
- List<Referenceable> tables = new ArrayList<>();
- List<Referenceable> allColumns = new ArrayList<>();
-
- for(int i = 0; i < nTables; i++) {
- String tableName = "db1-table-" + i;
-
- Referenceable tableInstance =
- new Referenceable(HIVE_TABLE_TYPE);
- tableInstance.set("name", tableName);
- tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
- tableInstance.set("db", databaseInstance);
- tableInstance.set("description", tableName + " table");
- tables.add(tableInstance);
-
- List<Referenceable> columns = new ArrayList<>();
- for(int j = 0; j < colsPerTable; j++) {
- Referenceable columnInstance = new Referenceable(COLUMN_TYPE);
- columnInstance.set("name", tableName + "-col-" + j);
- columnInstance.set("dataType", "String");
- columnInstance.set("comment", "column " + j + " for table " + i);
- allColumns.add(columnInstance);
- columns.add(columnInstance);
- }
- tableInstance.set("columns", columns);
- }
-
- //Create the tables. The database and columns should be created automatically, since
- //the tables reference them.
- JSONArray entityArray = new JSONArray(tables.size());
- for(int i = 0; i < tables.size(); i++) {
- Referenceable table = tables.get(i);
- entityArray.put(InstanceSerialization.toJson(table, true));
- }
- String json = entityArray.toString();
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.CREATE_ENTITY, json);
-
- GuidMapping guidMapping = AtlasType.fromJson(response.toString(), GuidMapping.class);
-
- Map<String,String> guidsCreated = guidMapping.getGuidAssignments();
- assertEquals(guidsCreated.size(), nTables * colsPerTable + nTables + 1);
- assertNotNull(guidsCreated.get(databaseInstance.getId()._getId()));
- for(Referenceable r : allColumns) {
- assertNotNull(guidsCreated.get(r.getId()._getId()));
- }
- for(Referenceable r : tables) {
- assertNotNull(guidsCreated.get(r.getId()._getId()));
- }
- }
-
-
- @Test
- public void testSubmitEntity() throws Exception {
- tableInstance = createHiveTableInstanceBuiltIn(DATABASE_NAME, TABLE_NAME, dbId);
- tableId = createInstance(tableInstance);
-
- final String guid = tableId._getId();
- try {
- Assert.assertNotNull(UUID.fromString(guid));
- } catch (IllegalArgumentException e) {
- Assert.fail("Response is not a guid, " + guid);
- }
- }
-
- @Test
- public void testRequestUser() throws Exception {
- Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName = randomString();
- entity.set("name", dbName);
- entity.set(QUALIFIED_NAME, dbName);
- entity.set("clusterName", randomString());
- entity.set("description", randomString());
- entity.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- entity.set("owner", "user1");
- entity.set("clusterName", "cl1");
- entity.set("parameters", Collections.EMPTY_MAP);
- entity.set("location", "/tmp");
-
-
- String user = "admin";
- AtlasClient localClient = null;
- if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
- localClient = new AtlasClient(atlasUrls, new String[]{"admin", "admin"});
- } else {
- localClient = new AtlasClient(atlasUrls);
- }
- String entityId = localClient.createEntity(entity).get(0);
-
- List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(entityId, (short) 10);
- assertEquals(events.size(), 1);
- assertEquals(events.get(0).getUser(), user);
- }
-
- @Test
- //API should accept single entity (or jsonarray of entities)
- public void testSubmitSingleEntity() throws Exception {
- Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName = randomString();
- databaseInstance.set("name", dbName);
- databaseInstance.set(QUALIFIED_NAME, dbName);
- databaseInstance.set("clusterName", randomString());
- databaseInstance.set("description", randomString());
- databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- databaseInstance.set("owner", "user1");
- databaseInstance.set("clusterName", "cl1");
- databaseInstance.set("parameters", Collections.EMPTY_MAP);
- databaseInstance.set("location", "/tmp");
-
- JSONObject response = atlasClientV1
- .callAPIWithBody(AtlasClient.API.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true));
- assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- AtlasClient.EntityResult entityResult = AtlasClient.EntityResult.fromString(response.toString());
- assertEquals(entityResult.getCreatedEntities().size(), 1);
- assertNotNull(entityResult.getCreatedEntities().get(0));
- }
-
- @Test
- public void testEntityDeduping() throws Exception {
- final Referenceable db = new Referenceable(DATABASE_TYPE_BUILTIN);
- final String dbName = "db" + randomString();
- Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
- Id dbIdReference = createInstance(HiveDBInstance);
- final String dbId = dbIdReference._getId();
-
- assertEntityAudit(dbId, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE);
-
- waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
- @Override
- public boolean evaluate(EntityNotification notification) throws Exception {
- return notification != null && notification.getEntity().getId()._getId().equals(dbId);
- }
- });
-
- JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
- assertEquals(results.length(), 1);
-
- //create entity again shouldn't create another instance with same unique attribute value
- List<String> entityResults = atlasClientV1.createEntity(HiveDBInstance);
- assertEquals(entityResults.size(), 0);
- try {
- waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
- @Override
- public boolean evaluate(EntityNotification notification) throws Exception {
- return notification != null && notification.getEntity().getId()._getId().equals(dbId);
- }
- });
- } catch (Exception e) {
- //expected timeout
- }
-
- results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
- assertEquals(results.length(), 1);
-
- //Test the same across references
- Referenceable table = new Referenceable(HIVE_TABLE_TYPE_BUILTIN);
- final String tableName = randomString();
- Referenceable tableInstance = createHiveTableInstanceBuiltIn(DATABASE_NAME, tableName, dbIdReference);
- atlasClientV1.createEntity(tableInstance);
- results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName));
- assertEquals(results.length(), 1);
- }
-
- private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
- throws Exception {
- List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
- for (EntityAuditEvent event : events) {
- if (event.getAction() == auditAction) {
- return;
- }
- }
- fail("Expected audit event with action = " + auditAction);
- }
-
- @Test
- public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
- //create type
- HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil
- .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE));
- atlasClientV1.createType(TypesSerialization.toJson(typeDefinition, false));
-
- //create entity for the type
- Referenceable instance = new Referenceable(typeDefinition.typeName);
- instance.set("name", randomString());
- String guid = atlasClientV1.createEntity(instance).get(0);
-
- //update type - add attribute
- typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName, ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
- TypesUtil.createOptionalAttrDef("description", DataTypes.STRING_TYPE));
- TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
- ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
- ImmutableList.of(typeDefinition));
- atlasClientV1.updateType(typeDef);
-
- //Get definition after type update - new attributes should be null
- Referenceable entity = atlasClientV1.getEntity(guid);
- Assert.assertNull(entity.get("description"));
- Assert.assertEquals(entity.get("name"), instance.get("name"));
- }
-
- @DataProvider
- public Object[][] invalidAttrValues() {
- return new Object[][]{{null}, {""}};
- }
-
- @Test(dataProvider = "invalidAttrValues")
- public void testEntityInvalidValue(String value) throws Exception {
- Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
- databaseInstance.set("name", randomString());
- databaseInstance.set("description", value);
-
- try {
- createInstance(databaseInstance);
- Assert.fail("Expected AtlasServiceException");
- } catch (AtlasServiceException e) {
- Assert.assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
- }
- }
-
- @Test
- public void testGetEntityByAttribute() throws Exception {
- Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName = randomString();
- db1.set(NAME, dbName);
- db1.set(DESCRIPTION, randomString());
- db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- db1.set("owner", "user1");
- db1.set(CLUSTER_NAME, "cl1");
- db1.set("parameters", Collections.EMPTY_MAP);
- db1.set("location", "/tmp");
- createInstance(db1);
-
- //get entity by attribute
- Referenceable referenceable = atlasClientV1.getEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName);
- Assert.assertEquals(referenceable.getTypeName(), DATABASE_TYPE_BUILTIN);
- Assert.assertEquals(referenceable.get(QUALIFIED_NAME), dbName);
- }
-
- @Test
- public void testSubmitEntityWithBadDateFormat() throws Exception {
- try {
- Referenceable tableInstance = createHiveTableInstanceBuiltIn("db" + randomString(), "table" + randomString(), dbId);
- tableInstance.set("lastAccessTime", "2014-07-11");
- tableId = createInstance(tableInstance);
- Assert.fail("Was expecting an exception here ");
- } catch (AtlasServiceException e) {
- Assert.assertTrue(
- e.getMessage().contains("\"error\":\"Cannot convert value '2014-07-11' to datatype date\""));
- }
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testAddProperty() throws Exception {
- final String guid = tableId._getId();
- //add property
- String description = "bar table - new desc";
- addProperty(guid, "description", description);
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
- Assert.assertNotNull(response);
-
- tableInstance.set("description", description);
-
- //invalid property for the type
- try {
- addProperty(guid, "invalid_property", "bar table");
- Assert.fail("Expected AtlasServiceException");
- } catch (AtlasServiceException e) {
- Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
- }
-
- String currentTime = String.valueOf(new DateTime());
-
- // updating date attribute as string not supported in v2
- // addProperty(guid, "createTime", currentTime);
-
- response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
- Assert.assertNotNull(response);
-
- tableInstance.set("createTime", currentTime);
- }
-
- @Test(dependsOnMethods = "testSubmitEntity", expectedExceptions = IllegalArgumentException.class)
- public void testAddNullProperty() throws Exception {
- final String guid = tableId._getId();
- //add property
- addProperty(guid, null, "foo bar");
- Assert.fail();
- }
-
- @Test(enabled = false)
- public void testAddNullPropertyValue() throws Exception {
- final String guid = tableId._getId();
- //add property
- try {
- addProperty(guid, "description", null);
- Assert.fail("Expected AtlasServiceException");
- } catch(AtlasServiceException e) {
- Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
- }
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testAddReferenceProperty() throws Exception {
- //Create new db instance
- Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName = randomString();
- databaseInstance.set(NAME, dbName);
- databaseInstance.set(QUALIFIED_NAME, dbName);
- databaseInstance.set(CLUSTER_NAME, randomString());
- databaseInstance.set("description", "new database");
- databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- databaseInstance.set("owner", "user1");
- databaseInstance.set(CLUSTER_NAME, "cl1");
- databaseInstance.set("parameters", Collections.EMPTY_MAP);
- databaseInstance.set("location", "/tmp");
-
- Id dbInstance = createInstance(databaseInstance);
- String dbId = dbInstance._getId();
-
- //Add reference property
- final String guid = tableId._getId();
- addProperty(guid, "db", dbId);
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testGetEntityDefinition() throws Exception {
- final String guid = tableId._getId();
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
-
- Assert.assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- final String definition = response.getString(AtlasClient.DEFINITION);
- Assert.assertNotNull(definition);
- LOG.debug("tableInstanceAfterGet = {}", definition);
- InstanceSerialization.fromJsonReferenceable(definition, true);
- }
-
- private void addProperty(String guid, String property, String value) throws AtlasServiceException {
- AtlasClient.EntityResult entityResult = atlasClientV1.updateEntityAttribute(guid, property, value);
- assertEquals(entityResult.getUpdateEntities().size(), 1);
- assertEquals(entityResult.getUpdateEntities().get(0), guid);
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testGetInvalidEntityDefinition() throws Exception {
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, "blah");
-
- Assert.assertNotNull(response);
-
- Assert.assertNotNull(response.get(AtlasClient.ERROR));
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testGetEntityList() throws Exception {
- List<String> entities = atlasClientV1.listEntities(HIVE_TABLE_TYPE_BUILTIN);
- Assert.assertNotNull(entities);
- Assert.assertTrue(entities.contains(tableId._getId()));
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testGetEntityListForBadEntityType() throws Exception {
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("type", "blah");
-
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
- assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.ERROR));
- }
-
-
- @Test
- public void testGetEntityListForNoInstances() throws Exception {
- String typeName = addNewType();
-
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add("type", typeName);
-
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GET_ENTITY, queryParams);
- assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
- Assert.assertEquals(list.length(), 0);
- }
-
- private String addNewType() throws Exception {
- String typeName = "test" + randomString();
- HierarchicalTypeDefinition<ClassType> testTypeDefinition = TypesUtil
- .createClassTypeDef(typeName, ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
- TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
-
- String typesAsJSON = TypesSerialization.toJson(testTypeDefinition, false);
- createType(typesAsJSON);
- return typeName;
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testGetTraitNames() throws Exception {
- final String guid = tableId._getId();
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TRAITS, null, guid, TRAITS);
- assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
- Assert.assertEquals(list.length(), 7);
- }
-
- @Test(dependsOnMethods = "testGetTraitNames")
- public void testAddTrait() throws Exception {
- traitName = "PII_Trait" + randomString();
- HierarchicalTypeDefinition<TraitType> piiTrait =
- TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
- String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
- LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
- createType(traitDefinitionAsJSON);
-
- Struct traitInstance = new Struct(traitName);
- String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true);
- LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
-
- final String guid = tableId._getId();
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
- assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testgetTraitDefinitionForEntity() throws Exception{
- traitName = "PII_Trait" + randomString();
- HierarchicalTypeDefinition<TraitType> piiTrait =
- TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
- String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
- LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
- createType(traitDefinitionAsJSON);
-
- Struct traitInstance = new Struct(traitName);
- String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true);
- LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
-
- final String guid = tableId._getId();
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
- assertNotNull(response);
- Struct traitDef = atlasClientV1.getTraitDefinition(guid, traitName);
- System.out.println(traitDef.toString());
- JSONObject responseAsJSON = new JSONObject(InstanceSerialization.toJson(traitDef, true));
- Assert.assertEquals(responseAsJSON.get("typeName"), traitName);
-
-
- List<Struct> allTraitDefs = atlasClientV1.listTraitDefinitions(guid);
- System.out.println(allTraitDefs.toString());
- Assert.assertEquals(allTraitDefs.size(), 9);
- }
-
- @Test(dependsOnMethods = "testAddTrait", expectedExceptions = AtlasServiceException.class)
- public void testAddExistingTrait() throws Exception {
- final String traitName = "PII_Trait" + randomString();
-
- Struct traitInstance = new Struct(traitName);
- String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true);
- LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
-
- final String guid = tableId._getId();
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
- assertNotNull(response);
- }
-
- @Test(dependsOnMethods = "testGetTraitNames")
- public void testAddTraitWithAttribute() throws Exception {
- final String traitName = "PII_Trait" + randomString();
- HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
- .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
- String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
- LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
- createType(traitDefinitionAsJSON);
-
- Struct traitInstance = new Struct(traitName);
- traitInstance.set("type", "SSN");
- String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true);
- LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
-
- final String guid = tableId._getId();
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.ADD_TRAITS, traitInstanceAsJSON, guid, TRAITS);
- assertNotNull(response);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- // verify the response
- response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
-
- final String definition = response.getString(AtlasClient.DEFINITION);
- Assert.assertNotNull(definition);
- Referenceable entityRef = InstanceSerialization.fromJsonReferenceable(definition, true);
- IStruct traitRef = entityRef.getTrait(traitName);
- String type = (String) traitRef.get("type");
- Assert.assertEquals(type, "SSN");
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testAddTraitWithNoRegistration() throws Exception {
- final String traitName = "PII_Trait" + randomString();
- HierarchicalTypeDefinition<TraitType> piiTrait =
- TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
- String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
- LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
-
- Struct traitInstance = new Struct(traitName);
- String traitInstanceAsJSON = InstanceSerialization$.MODULE$.toJson(traitInstance, true);
- LOG.debug("traitInstanceAsJSON = {}", traitInstanceAsJSON);
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.CREATE_ENTITY, traitInstanceAsJSON, "random", TRAITS);
- }
-
- @Test(dependsOnMethods = "testAddTrait")
- public void testDeleteTrait() throws Exception {
- final String guid = tableId._getId();
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.DELETE_TRAITS, null, guid, TRAITS, traitName);
- Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
- Assert.assertNotNull(response.get("traitName"));
- assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
- }
-
- @Test(expectedExceptions = AtlasServiceException.class)
- public void testDeleteTraitNonExistent() throws Exception {
- final String traitName = "blah_trait";
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.DELETE_TRAITS, null, "random", TRAITS);
-
- Assert.assertNotNull(response.get(AtlasClient.ERROR));
- Assert.assertEquals(response.getString(AtlasClient.ERROR),
- "trait=" + traitName + " should be defined in type system before it can be deleted");
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
-
- final String guid = tableId._getId();
- final String traitName = "PII_Trait" + randomString();
- HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil
- .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
- TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
- String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
- createType(traitDefinitionAsJSON);
-
- try {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.DELETE_TRAITS, null, guid, TRAITS, traitName);
- fail("Call should've failed for deletion of invalid trait");
- } catch (AtlasServiceException e) {
- assertNotNull(e);
- assertNotNull(e.getStatus());
- assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND);
- }
- }
-
- private String random() {
- return RandomStringUtils.random(10);
- }
-
- @Test
- public void testUTF8() throws Exception {
- //Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
- String classType = randomString();
- String attrName = random();
- String attrValue = random();
-
- HierarchicalTypeDefinition<ClassType> classTypeDefinition = TypesUtil
- .createClassTypeDef(classType, ImmutableSet.<String>of(),
- TypesUtil.createUniqueRequiredAttrDef(attrName, DataTypes.STRING_TYPE));
- TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
- ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
- ImmutableList.of(classTypeDefinition));
- createType(typesDef);
-
- Referenceable instance = new Referenceable(classType);
- instance.set(attrName, attrValue);
- Id guid = createInstance(instance);
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, guid._getId());
- Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.getString(AtlasClient.DEFINITION), true);
- Assert.assertEquals(getReferenceable.get(attrName), attrValue);
- }
-
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testPartialUpdate() throws Exception {
- String colName = "col1"+randomString();
- final List<Referenceable> columns = new ArrayList<>();
- Map<String, Object> values = new HashMap<>();
- values.put(NAME, colName);
- values.put("comment", "col1 comment");
- values.put(QUALIFIED_NAME, "default.table.col1@"+colName);
- values.put("comment", "col1 comment");
- values.put("type", "string");
- values.put("owner", "user1");
- values.put("position", 0);
- values.put("description", "col1");
- values.put("table", tableId ); //table is a required reference, can't be null
-
- Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
- columns.add(ref);
- Referenceable tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {{
- put("columns", columns);
- }});
-
- LOG.debug("Updating entity= {}", tableUpdated);
- AtlasClient.EntityResult entityResult = atlasClientV1.updateEntity(tableId._getId(), tableUpdated);
- assertEquals(entityResult.getUpdateEntities().size(), 1);
- assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
-
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, tableId._getId());
- Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.getString(AtlasClient.DEFINITION), true);
- List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns");
-
- Assert.assertTrue(refs.get(0).equalsContents(columns.get(0)));
-
- //Update by unique attribute
- values.put("type", "int");
- ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
- columns.set(0, ref);
- tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {{
- put("columns", columns);
- }});
-
- LOG.debug("Updating entity= {}", tableUpdated);
- entityResult = atlasClientV1.updateEntity(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME,
- (String) tableInstance.get(QUALIFIED_NAME), tableUpdated);
- assertEquals(entityResult.getUpdateEntities().size(), 2);
- assertEquals(entityResult.getUpdateEntities().get(1), tableId._getId());
-
- response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, tableId._getId());
- getReferenceable = InstanceSerialization.fromJsonReferenceable(response.getString(AtlasClient.DEFINITION), true);
- refs = (List<Referenceable>) getReferenceable.get("columns");
-
- Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
- Assert.assertEquals(refs.get(0).get("type"), "int");
- }
-
- @Test(dependsOnMethods = "testSubmitEntity")
- public void testCompleteUpdate() throws Exception {
- final List<Referenceable> columns = new ArrayList<>();
- Map<String, Object> values1 = new HashMap<>();
- values1.put(NAME, "col3");
- values1.put(QUALIFIED_NAME, "default.table.col3@cl1");
- values1.put("comment", "col3 comment");
- values1.put("type", "string");
- values1.put("owner", "user1");
- values1.put("position", 0);
- values1.put("description", "col3");
- values1.put("table", tableId);
-
-
- Map<String, Object> values2 = new HashMap<>();
- values2.put(NAME, "col4");
- values2.put(QUALIFIED_NAME, "default.table.col4@cl1");
- values2.put("comment", "col4 comment");
- values2.put("type", "string");
- values2.put("owner", "user2");
- values2.put("position", 1);
- values2.put("description", "col4");
- values2.put("table", tableId);
-
- Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values1);
- Referenceable ref2 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values2);
- columns.add(ref1);
- columns.add(ref2);
- tableInstance.set("columns", columns);
- String entityJson = InstanceSerialization.toJson(tableInstance, true);
- JSONArray entityArray = new JSONArray(1);
- entityArray.put(entityJson);
- LOG.debug("Replacing entity= {}", tableInstance);
-
- JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.UPDATE_ENTITY, entityArray);
-
- // ATLAS-586: verify response entity can be parsed by GSON.
- Gson gson = new Gson();
- try {
- UpdateEntitiesResponse updateEntitiesResponse = gson.fromJson(response.toString(), UpdateEntitiesResponse.class);
- }
- catch (JsonSyntaxException e) {
- Assert.fail("Response entity from not parse-able by GSON", e);
- }
-
- response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.GET_ENTITY, null, tableId._getId());
- LOG.info("Response = {}", response.toString());
- Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(response.getString(AtlasClient.DEFINITION), true);
- List<Referenceable> refs = (List<Referenceable>) getReferenceable.get("columns");
- Assert.assertEquals(refs.size(), 2);
-
- Assert.assertTrue(refs.get(0).getValuesMap().equals(values1));
- Assert.assertTrue(refs.get(1).getValuesMap().equals(values2));
- }
-
- private static class UpdateEntitiesResponse {
- String requestId;
- AtlasClient.EntityResult entities;
- AtlasEntity definition;
- }
-
- private static class AtlasEntity {
- String typeName;
- final Map<String, Object> values = new HashMap<>();
- }
-
- @Test
- public void testDeleteEntitiesViaRestApi() throws Exception {
- // Create 2 database entities
- Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName = randomString();
- db1.set(NAME, dbName);
- db1.set(DESCRIPTION, randomString());
- db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- db1.set("owner", "user1");
- db1.set(CLUSTER_NAME, "cl1");
- db1.set("parameters", Collections.EMPTY_MAP);
- db1.set("location", "/tmp");
- Id db1Id = createInstance(db1);
-
- Referenceable db2 = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName2 = randomString();
- db2.set(NAME, dbName2);
- db2.set(QUALIFIED_NAME, dbName2);
- db2.set(CLUSTER_NAME, randomString());
- db2.set(DESCRIPTION, randomString());
- db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
- db2.set("owner", "user2");
- db2.set(CLUSTER_NAME, "cl1");
- db2.set("parameters", Collections.EMPTY_MAP);
- db2.set("location", "/tmp");
- Id db2Id = createInstance(db2);
-
- // Delete the database entities
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(AtlasClient.GUID.toLowerCase(), db1Id._getId());
- queryParams.add(AtlasClient.GUID.toLowerCase(), db2Id._getId());
-
- JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.DELETE_ENTITIES, queryParams);
- List<String> deletedGuidsList = AtlasClient.EntityResult.fromString(response.toString()).getDeletedEntities();
- Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
- Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
-
- // Verify entities were deleted from the repository.
- for (String guid : deletedGuidsList) {
- Referenceable entity = atlasClientV1.getEntity(guid);
- assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
- }
- }
-
- @Test
- public void testDeleteEntitiesViaClientApi() throws Exception {
- // Create 2 database entities
- Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName = randomString();
- db1.set("name", dbName);
- db1.set("description", randomString());
- db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- db1.set("owner", "user1");
- db1.set(CLUSTER_NAME, "cl1");
- db1.set("parameters", Collections.EMPTY_MAP);
- db1.set("location", "/tmp");
- Id db1Id = createInstance(db1);
- Referenceable db2 = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName2 = randomString();
- db2.set("name", dbName2);
- db2.set(QUALIFIED_NAME, dbName2);
- db2.set(CLUSTER_NAME, randomString());
- db2.set("description", randomString());
- db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
- db2.set("owner", "user2");
- db2.set("clusterName", "cl1");
- db2.set("parameters", Collections.EMPTY_MAP);
- db2.set("location", "/tmp");
- Id db2Id = createInstance(db2);
-
- // Delete the database entities
- List<String> deletedGuidsList =
- atlasClientV1.deleteEntities(db1Id._getId(), db2Id._getId()).getDeletedEntities();
- // Verify that deleteEntities() response has database entity guids
- Assert.assertEquals(deletedGuidsList.size(), 2);
- Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
- Assert.assertTrue(deletedGuidsList.contains(db2Id._getId()));
-
- // Verify entities were deleted from the repository.
- for (String guid : deletedGuidsList) {
- Referenceable entity = atlasClientV1.getEntity(guid);
- assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
- }
- }
-
- @Test
- public void testDeleteEntityByUniqAttribute() throws Exception {
- // Create database entity
- Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
- String dbName = randomString();
- db1.set(NAME, dbName);
- db1.set(QUALIFIED_NAME, dbName);
- db1.set(CLUSTER_NAME, randomString());
- db1.set(DESCRIPTION, randomString());
- db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
- db1.set("owner", "user1");
- db1.set(CLUSTER_NAME, "cl1");
- db1.set("parameters", Collections.EMPTY_MAP);
- db1.set("location", "/tmp");
- Id db1Id = createInstance(db1);
-
- // Delete the database entity
- List<String> deletedGuidsList = atlasClientV1.deleteEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName).getDeletedEntities();
-
- // Verify that deleteEntities() response has database entity guids
- Assert.assertEquals(deletedGuidsList.size(), 1);
- Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
-
- // Verify entities were deleted from the repository.
- for (String guid : deletedGuidsList) {
- Referenceable entity = atlasClientV1.getEntity(guid);
- assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/EntityLineageJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityLineageJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityLineageJerseyResourceIT.java
deleted file mode 100644
index 4f8badf..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityLineageJerseyResourceIT.java
+++ /dev/null
@@ -1,190 +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.web.resources;
-
-import com.google.common.collect.ImmutableList;
-import com.google.gson.Gson;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import org.apache.atlas.AtlasClient;
-import org.apache.atlas.model.instance.AtlasEntityHeader;
-import org.apache.atlas.model.lineage.AtlasLineageInfo;
-import org.apache.atlas.typesystem.Referenceable;
-import org.apache.atlas.typesystem.persistence.Id;
-import org.codehaus.jettison.json.JSONObject;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-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 String salesFactTable;
- private String salesMonthlyTable;
- private String salesDBName;
- Gson gson = new Gson();
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
-
- createTypeDefinitionsV1();
- setupInstances();
- }
-
- @Test
- public void testInputLineageInfo() throws Exception {
- String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
- AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
-
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(DIRECTION_PARAM, INPUT_DIRECTION);
- queryParams.add(DEPTH_PARAM, "5");
- JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
- Assert.assertNotNull(response);
- System.out.println("input lineage info = " + response
- );
-
- AtlasLineageInfo inputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
-
- Map<String, AtlasEntityHeader> entities = inputLineageInfo.getGuidEntityMap();
- Assert.assertNotNull(entities);
-
- Set<AtlasLineageInfo.LineageRelation> relations = inputLineageInfo.getRelations();
- Assert.assertNotNull(relations);
-
- Assert.assertEquals(entities.size(), 6);
- Assert.assertEquals(relations.size(), 5);
- Assert.assertEquals(inputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.INPUT);
- Assert.assertEquals(inputLineageInfo.getLineageDepth(), 5);
- Assert.assertEquals(inputLineageInfo.getBaseEntityGuid(), tableId);
- }
-
- @Test
- public void testOutputLineageInfo() throws Exception {
- String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
- AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesFactTable).getId()._getId();
-
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(DIRECTION_PARAM, OUTPUT_DIRECTION);
- queryParams.add(DEPTH_PARAM, "5");
- JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
-
- Assert.assertNotNull(response);
- System.out.println("output lineage info = " + response);
-
- AtlasLineageInfo outputLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
-
- Map<String, AtlasEntityHeader> entities = outputLineageInfo.getGuidEntityMap();
- Assert.assertNotNull(entities);
-
- Set<AtlasLineageInfo.LineageRelation> relations = outputLineageInfo.getRelations();
- Assert.assertNotNull(relations);
-
- Assert.assertEquals(entities.size(), 5);
- Assert.assertEquals(relations.size(), 4);
- Assert.assertEquals(outputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.OUTPUT);
- Assert.assertEquals(outputLineageInfo.getLineageDepth(), 5);
- Assert.assertEquals(outputLineageInfo.getBaseEntityGuid(), tableId);
- }
-
- @Test
- public void testLineageInfo() throws Exception {
- String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
- AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
-
- MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
- queryParams.add(DIRECTION_PARAM, BOTH_DIRECTION);
- queryParams.add(DEPTH_PARAM, "5");
- JSONObject response = atlasClientV1.callAPI(LINEAGE_V2_API, JSONObject.class, queryParams, tableId);
-
- Assert.assertNotNull(response);
- System.out.println("both lineage info = " + response);
-
- AtlasLineageInfo bothLineageInfo = gson.fromJson(response.toString(), AtlasLineageInfo.class);
-
- Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap();
- Assert.assertNotNull(entities);
-
- Set<AtlasLineageInfo.LineageRelation> relations = bothLineageInfo.getRelations();
- Assert.assertNotNull(relations);
-
- Assert.assertEquals(entities.size(), 6);
- Assert.assertEquals(relations.size(), 5);
- Assert.assertEquals(bothLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
- Assert.assertEquals(bothLineageInfo.getLineageDepth(), 5);
- Assert.assertEquals(bothLineageInfo.getBaseEntityGuid(), tableId);
- }
-
- private void setupInstances() throws Exception {
- salesDBName = "Sales" + randomString();
- Id salesDB = database(salesDBName, "Sales Database", "John ETL", "hdfs://host:8000/apps/warehouse/sales");
-
- List<Referenceable> salesFactColumns = ImmutableList
- .of(column("time_id", "int", "time id"), column("product_id", "int", "product id"),
- column("customer_id", "int", "customer id"),
- column("sales", "double", "product id"));
-
- salesFactTable = "sales_fact" + randomString();
- Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns);
-
- List<Referenceable> timeDimColumns = ImmutableList
- .of(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"),
- column("weekDay", "int", "week Day"));
-
- Id timeDim =
- table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL",
- timeDimColumns);
-
- Id reportingDB =
- database("Reporting" + randomString(), "reporting database", "Jane BI",
- "hdfs://host:8000/apps/warehouse/reporting");
-
- Id salesFactDaily =
- table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB,
- "Joe BI", "MANAGED", salesFactColumns);
-
- loadProcess("loadSalesDaily" + randomString(), "John ETL", ImmutableList.of(salesFact, timeDim),
- ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph");
-
- salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
- Id salesFactMonthly =
- table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI",
- "MANAGED", salesFactColumns);
-
- loadProcess("loadSalesMonthly" + randomString(), "John ETL", ImmutableList.of(salesFactDaily),
- ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java b/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java
index 21060d1..ff8cb59 100644
--- a/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/EntityResourceTest.java
@@ -17,33 +17,23 @@
*/
package org.apache.atlas.web.resources;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.ws.rs.core.Response;
-
-import com.vividsolutions.jts.util.CollectionUtil;
-import org.apache.atlas.AtlasClient.EntityResult;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations;
-import org.apache.atlas.repository.converters.AtlasInstanceConverter;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
-import org.apache.atlas.services.MetadataService;
-import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.collections.CollectionUtils;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.Mockito.when;
+
/**
* Unit test of {@link EntityResource}
*/
[05/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
new file mode 100755
index 0000000..98a7abc
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/EntityV2JerseyResourceIT.java
@@ -0,0 +1,769 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.sun.jersey.api.client.ClientResponse;
+import org.apache.atlas.AtlasClient;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.EntityAuditEvent;
+import org.apache.atlas.kafka.NotificationProvider;
+import org.apache.atlas.model.instance.AtlasClassification;
+import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
+import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
+import org.apache.atlas.model.instance.AtlasEntityHeader;
+import org.apache.atlas.model.instance.AtlasObjectId;
+import org.apache.atlas.model.instance.EntityMutationResponse;
+import org.apache.atlas.model.instance.EntityMutations;
+import org.apache.atlas.model.typedef.AtlasClassificationDef;
+import org.apache.atlas.model.typedef.AtlasEntityDef;
+import org.apache.atlas.model.typedef.AtlasTypesDef;
+import org.apache.atlas.notification.NotificationConsumer;
+import org.apache.atlas.notification.NotificationInterface;
+import org.apache.atlas.notification.entity.EntityNotification;
+import org.apache.atlas.type.AtlasTypeUtil;
+import org.apache.atlas.typesystem.types.TypeUtils;
+import org.apache.commons.lang.RandomStringUtils;
+import org.codehaus.jettison.json.JSONArray;
+import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.testng.Assert.*;
+
+
+/**
+ * Integration tests for Entity Jersey Resource.
+ */
+public class EntityV2JerseyResourceIT extends BaseResourceIT {
+
+ private static final Logger LOG = LoggerFactory.getLogger(EntityV2JerseyResourceIT.class);
+
+ private final String DATABASE_NAME = "db" + randomString();
+ private final String TABLE_NAME = "table" + randomString();
+ private String traitName;
+
+ private AtlasEntity dbEntity;
+ private AtlasEntity tableEntity;
+ private NotificationInterface notificationInterface = NotificationProvider.get();
+ private NotificationConsumer<EntityNotification> notificationConsumer;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+
+ createTypeDefinitionsV2();
+
+ List<NotificationConsumer<EntityNotification>> consumers =
+ notificationInterface.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);
+
+ notificationConsumer = consumers.iterator().next();
+ }
+
+ @Test
+ public void testSubmitEntity() throws Exception {
+ TypeUtils.Pair dbAndTable = createDBAndTable();
+ assertNotNull(dbAndTable);
+ assertNotNull(dbAndTable.left);
+ assertNotNull(dbAndTable.right);
+ }
+
+ @Test
+ public void testCreateNestedEntities() throws Exception {
+ AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo();
+
+ AtlasEntity databaseInstance = new AtlasEntity(DATABASE_TYPE_V2, "name", "db1");
+ databaseInstance.setAttribute("name", "db1");
+ databaseInstance.setAttribute("description", "foo database");
+ databaseInstance.setAttribute("owner", "user1");
+ databaseInstance.setAttribute("locationUri", "/tmp");
+ databaseInstance.setAttribute("createTime",1000);
+ entities.addEntity(databaseInstance);
+
+ int nTables = 5;
+ int colsPerTable=3;
+
+ for(int i = 0; i < nTables; i++) {
+ String tableName = "db1-table-" + i;
+
+ AtlasEntity tableInstance = new AtlasEntity(HIVE_TABLE_TYPE_V2, "name", tableName);
+ tableInstance.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
+ tableInstance.setAttribute("db", AtlasTypeUtil.getAtlasObjectId(databaseInstance));
+ tableInstance.setAttribute("description", tableName + " table");
+ entities.addEntity(tableInstance);
+
+ List<AtlasObjectId> columns = new ArrayList<>();
+ for(int j = 0; j < colsPerTable; j++) {
+ AtlasEntity columnInstance = new AtlasEntity(COLUMN_TYPE_V2);
+ columnInstance.setAttribute("name", tableName + "-col-" + j);
+ columnInstance.setAttribute("dataType", "String");
+ columnInstance.setAttribute("comment", "column " + j + " for table " + i);
+
+ columns.add(AtlasTypeUtil.getAtlasObjectId(columnInstance));
+
+ entities.addReferredEntity(columnInstance);
+ }
+ tableInstance.setAttribute("columns", columns);
+ }
+
+ //Create the tables. The database and columns should be created automatically, since
+ //the tables reference them.
+
+ EntityMutationResponse response = atlasClientV2.createEntities(entities);
+ Assert.assertNotNull(response);
+
+ Map<String,String> guidsCreated = response.getGuidAssignments();
+ assertEquals(guidsCreated.size(), nTables * colsPerTable + nTables + 1);
+ assertNotNull(guidsCreated.get(databaseInstance.getGuid()));
+
+ for(AtlasEntity r : entities.getEntities()) {
+ assertNotNull(guidsCreated.get(r.getGuid()));
+ }
+
+ for(AtlasEntity r : entities.getReferredEntities().values()) {
+ assertNotNull(guidsCreated.get(r.getGuid()));
+ }
+ }
+
+ @Test
+ public void testRequestUser() throws Exception {
+ AtlasEntity hiveDBInstanceV2 = createHiveDB(randomString());
+ List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(hiveDBInstanceV2.getGuid(), (short) 10);
+ assertEquals(events.size(), 1);
+ assertEquals(events.get(0).getUser(), "admin");
+ }
+
+ @Test
+ public void testEntityDeduping() throws Exception {
+ JSONArray results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
+ assertEquals(results.length(), 1);
+
+ final AtlasEntity hiveDBInstanceV2 = createHiveDB();
+ // Do the notification thing here
+ waitForNotification(notificationConsumer, MAX_WAIT_TIME, new NotificationPredicate() {
+ @Override
+ public boolean evaluate(EntityNotification notification) throws Exception {
+ return notification != null && notification.getEntity().getId()._getId().equals(hiveDBInstanceV2.getGuid());
+ }
+ });
+
+
+ results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
+ assertEquals(results.length(), 1);
+
+ //Test the same across references
+ final String tableName = randomString();
+ AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(hiveDBInstanceV2, tableName);
+ hiveTableInstanceV2.setAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
+
+ EntityMutationResponse entity = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(hiveTableInstanceV2));
+ assertNotNull(entity);
+ assertNotNull(entity.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
+ results = searchByDSL(String.format("%s where name='%s'", DATABASE_TYPE_V2, DATABASE_NAME));
+ assertEquals(results.length(), 1);
+ }
+
+ private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
+ throws Exception {
+ List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
+ for (EntityAuditEvent event : events) {
+ if (event.getAction() == auditAction) {
+ return;
+ }
+ }
+ fail("Expected audit event with action = " + auditAction);
+ }
+
+ @Test
+ public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
+ //create type
+ AtlasEntityDef entityDef = AtlasTypeUtil
+ .createClassTypeDef(randomString(),
+ ImmutableSet.<String>of(),
+ AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string")
+ );
+ AtlasTypesDef typesDef = new AtlasTypesDef();
+ typesDef.getEntityDefs().add(entityDef);
+
+ AtlasTypesDef created = atlasClientV2.createAtlasTypeDefs(typesDef);
+ assertNotNull(created);
+ assertNotNull(created.getEntityDefs());
+ assertEquals(created.getEntityDefs().size(), 1);
+
+ //create entity for the type
+ AtlasEntity instance = new AtlasEntity(entityDef.getName());
+ instance.setAttribute("name", randomString());
+ EntityMutationResponse mutationResponse = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(instance));
+ assertNotNull(mutationResponse);
+ assertNotNull(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
+ assertEquals(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(),1 );
+ String guid = mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
+
+ //update type - add attribute
+ entityDef = AtlasTypeUtil.createClassTypeDef(entityDef.getName(), ImmutableSet.<String>of(),
+ AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("description", "string"));
+
+ typesDef = new AtlasTypesDef();
+ typesDef.getEntityDefs().add(entityDef);
+
+ AtlasTypesDef updated = atlasClientV2.updateAtlasTypeDefs(typesDef);
+ assertNotNull(updated);
+ assertNotNull(updated.getEntityDefs());
+ assertEquals(updated.getEntityDefs().size(), 1);
+
+ //Get definition after type update - new attributes should be null
+ AtlasEntity entityByGuid = getEntityByGuid(guid);
+ assertNull(entityByGuid.getAttribute("description"));
+ assertEquals(entityByGuid.getAttribute("name"), instance.getAttribute("name"));
+ }
+
+ @Test
+ public void testEntityInvalidValue() throws Exception {
+ AtlasEntity databaseInstance = new AtlasEntity(DATABASE_TYPE_V2);
+ String dbName = randomString();
+ String nullString = null;
+ String emptyString = "";
+ databaseInstance.setAttribute("name", dbName);
+ databaseInstance.setAttribute("description", nullString);
+ AtlasEntityHeader created = createEntity(databaseInstance);
+
+ // null valid value for required attr - description
+ assertNull(created);
+
+ databaseInstance.setAttribute("description", emptyString);
+ created = createEntity(databaseInstance);
+
+ // empty string valid value for required attr
+ assertNotNull(created);
+
+ databaseInstance.setGuid(created.getGuid());
+ databaseInstance.setAttribute("owner", nullString);
+ databaseInstance.setAttribute("locationUri", emptyString);
+
+ created = updateEntity(databaseInstance);
+
+ // null/empty string valid value for optional attr
+ assertNotNull(created);
+ }
+
+ @Test
+ public void testGetEntityByAttribute() throws Exception {
+ AtlasEntity hiveDB = createHiveDB();
+ String qualifiedName = (String) hiveDB.getAttribute(NAME);
+ //get entity by attribute
+
+ AtlasEntity byAttribute = atlasClientV2.getEntityByAttribute(DATABASE_TYPE_V2, toMap(NAME, qualifiedName)).getEntity();
+ assertEquals(byAttribute.getTypeName(), DATABASE_TYPE_V2);
+ assertEquals(byAttribute.getAttribute(NAME), qualifiedName);
+ }
+
+ @Test
+ public void testSubmitEntityWithBadDateFormat() throws Exception {
+ AtlasEntity hiveDBEntity = createHiveDBInstanceV2("db" + randomString());
+ AtlasEntityHeader hiveDBHeader = createEntity(hiveDBEntity);
+ hiveDBEntity.setGuid(hiveDBHeader.getGuid());
+
+ AtlasEntity tableInstance = createHiveTableInstanceV2(hiveDBEntity, "table" + randomString());
+ //Dates with an invalid format are simply nulled out. This does not produce
+ //an error. See AtlasBuiltInTypes.AtlasDateType.getNormalizedValue().
+ tableInstance.setAttribute("lastAccessTime", 1107201407);
+ AtlasEntityHeader tableEntityHeader = createEntity(tableInstance);
+ assertNotNull(tableEntityHeader);
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testAddProperty() throws Exception {
+ //add property
+ String description = "bar table - new desc";
+ addProperty(createHiveTable().getGuid(), "description", description);
+
+ AtlasEntity entityByGuid = getEntityByGuid(createHiveTable().getGuid());
+ Assert.assertNotNull(entityByGuid);
+
+ entityByGuid.setAttribute("description", description);
+
+ // TODO: This behavior should've been consistent across APIs
+// //invalid property for the type
+// try {
+// addProperty(table.getGuid(), "invalid_property", "bar table");
+// Assert.fail("Expected AtlasServiceException");
+// } catch (AtlasServiceException e) {
+// assertNotNull(e.getStatus());
+// assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
+// }
+
+ //non-string property, update
+ Object currentTime = new DateTime();
+ addProperty(createHiveTable().getGuid(), "createTime", currentTime);
+
+ entityByGuid = getEntityByGuid(createHiveTable().getGuid());
+ Assert.assertNotNull(entityByGuid);
+ }
+
+ @Test
+ public void testAddNullPropertyValue() throws Exception {
+ // FIXME: Behavior has changed between v1 and v2
+ //add property
+// try {
+ addProperty(createHiveTable().getGuid(), "description", null);
+// Assert.fail("Expected AtlasServiceException");
+// } catch(AtlasServiceException e) {
+// Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
+// }
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testGetInvalidEntityDefinition() throws Exception {
+ getEntityByGuid("blah");
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity", enabled = false)
+ public void testGetEntityList() throws Exception {
+ // TODO: Can only be done when there's a search API exposed from entity REST
+ }
+
+ @Test(enabled = false)
+ public void testGetEntityListForBadEntityType() throws Exception {
+ // FIXME: Complete test when search interface is in place
+ }
+
+ @Test(enabled = false)
+ public void testGetEntityListForNoInstances() throws Exception {
+ // FIXME: Complete test when search interface is in place
+ /*
+ String typeName = "";
+
+ ClientResponse clientResponse =
+ service.path(ENTITIES).queryParam("type", typeName).accept(Servlets.JSON_MEDIA_TYPE)
+ .type(Servlets.JSON_MEDIA_TYPE).method(HttpMethod.GET, ClientResponse.class);
+ Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
+
+ String responseAsString = clientResponse.getEntity(String.class);
+ Assert.assertNotNull(responseAsString);
+
+ JSONObject response = new JSONObject(responseAsString);
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
+ Assert.assertEquals(list.length(), 0);
+ */
+ }
+
+ private String addNewType() throws Exception {
+ String typeName = "test" + randomString();
+ AtlasEntityDef classTypeDef = AtlasTypeUtil
+ .createClassTypeDef(typeName, ImmutableSet.<String>of(),
+ AtlasTypeUtil.createRequiredAttrDef("name", "string"),
+ AtlasTypeUtil.createRequiredAttrDef("description", "string"));
+ AtlasTypesDef typesDef = new AtlasTypesDef();
+ typesDef.getEntityDefs().add(classTypeDef);
+ createType(typesDef);
+ return typeName;
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testGetTraitNames() throws Exception {
+ AtlasClassifications classifications = atlasClientV2.getClassifications(createHiveTable().getGuid());
+ assertNotNull(classifications);
+ assertTrue(classifications.getList().size() > 0);
+ assertEquals(classifications.getList().size(), 8);
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testCommonAttributes() throws Exception{
+ AtlasEntity entity = getEntityByGuid(createHiveTable().getGuid());
+ Assert.assertNotNull(entity.getStatus());
+ Assert.assertNotNull(entity.getVersion());
+ Assert.assertNotNull(entity.getCreatedBy());
+ Assert.assertNotNull(entity.getCreateTime());
+ Assert.assertNotNull(entity.getUpdatedBy());
+ Assert.assertNotNull(entity.getUpdateTime());
+ }
+
+ private void addProperty(String guid, String property, Object value) throws AtlasServiceException {
+
+ AtlasEntity entityByGuid = getEntityByGuid(guid);
+ entityByGuid.setAttribute(property, value);
+ EntityMutationResponse response = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(entityByGuid));
+ assertNotNull(response);
+ assertNotNull(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
+ }
+
+ private AtlasEntity createHiveDB() {
+ if (dbEntity == null) {
+ dbEntity = createHiveDB(DATABASE_NAME);
+ }
+ return dbEntity;
+ }
+
+ private AtlasEntity createHiveDB(String dbName) {
+ AtlasEntity hiveDBInstanceV2 = createHiveDBInstanceV2(dbName);
+ AtlasEntityHeader entityHeader = createEntity(hiveDBInstanceV2);
+ assertNotNull(entityHeader);
+ assertNotNull(entityHeader.getGuid());
+ hiveDBInstanceV2.setGuid(entityHeader.getGuid());
+ return hiveDBInstanceV2;
+ }
+
+ private TypeUtils.Pair<AtlasEntity, AtlasEntity> createDBAndTable() throws Exception {
+ AtlasEntity dbInstanceV2 = createHiveDB();
+ AtlasEntity hiveTableInstanceV2 = createHiveTable();
+ return TypeUtils.Pair.of(dbInstanceV2, hiveTableInstanceV2);
+ }
+
+ private AtlasEntity createHiveTable() throws Exception {
+ if (tableEntity == null) {
+ tableEntity = createHiveTable(createHiveDB(), TABLE_NAME);
+ }
+ return tableEntity;
+
+ }
+
+ private AtlasEntity createHiveTable(AtlasEntity dbInstanceV2, String tableName) throws Exception {
+ AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(dbInstanceV2, tableName);
+ AtlasEntityHeader createdHeader = createEntity(hiveTableInstanceV2);
+ assertNotNull(createdHeader);
+ assertNotNull(createdHeader.getGuid());
+ hiveTableInstanceV2.setGuid(createdHeader.getGuid());
+ tableEntity = hiveTableInstanceV2;
+ return hiveTableInstanceV2;
+ }
+
+ @Test(dependsOnMethods = "testGetTraitNames")
+ public void testAddTrait() throws Exception {
+ traitName = "PII_Trait" + randomString();
+ AtlasClassificationDef piiTrait =
+ AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ AtlasTypesDef typesDef = new AtlasTypesDef();
+ typesDef.getClassificationDefs().add(piiTrait);
+ createType(typesDef);
+
+ atlasClientV2.addClassifications(createHiveTable().getGuid(), ImmutableList.of(new AtlasClassification(piiTrait.getName())));
+
+ assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_ADD);
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testGetTraitDefinitionForEntity() throws Exception{
+ traitName = "PII_Trait" + randomString();
+ AtlasClassificationDef piiTrait =
+ AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ AtlasTypesDef typesDef = new AtlasTypesDef();
+ typesDef.getClassificationDefs().add(piiTrait);
+ createType(typesDef);
+
+ AtlasClassificationDef classificationByName = atlasClientV2.getClassificationDefByName(traitName);
+ assertNotNull(classificationByName);
+
+ AtlasEntity hiveTable = createHiveTable();
+ assertEquals(hiveTable.getClassifications().size(), 7);
+
+ AtlasClassification piiClassification = new AtlasClassification(piiTrait.getName());
+
+ atlasClientV2.addClassifications(hiveTable.getGuid(), Lists.newArrayList(piiClassification));
+
+ AtlasClassifications classifications = atlasClientV2.getClassifications(hiveTable.getGuid());
+ assertNotNull(classifications);
+ assertTrue(classifications.getList().size() > 0);
+ assertEquals(classifications.getList().size(), 8);
+ }
+
+
+ @Test(dependsOnMethods = "testGetTraitNames")
+ public void testAddTraitWithAttribute() throws Exception {
+ final String traitName = "PII_Trait" + randomString();
+ AtlasClassificationDef piiTrait = AtlasTypeUtil
+ .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
+ AtlasTypeUtil.createRequiredAttrDef("type", "string"));
+ AtlasTypesDef typesDef = new AtlasTypesDef();
+ typesDef.getClassificationDefs().add(piiTrait);
+ createType(typesDef);
+
+ AtlasClassification traitInstance = new AtlasClassification(traitName);
+ traitInstance.setAttribute("type", "SSN");
+
+ final String guid = createHiveTable().getGuid();
+ atlasClientV2.addClassifications(guid, ImmutableList.of(traitInstance));
+
+ // verify the response
+ AtlasEntity withAssociationByGuid = atlasClientV2.getEntityByGuid(guid).getEntity();
+ assertNotNull(withAssociationByGuid);
+ assertFalse(withAssociationByGuid.getClassifications().isEmpty());
+
+ boolean found = false;
+ for (AtlasClassification atlasClassification : withAssociationByGuid.getClassifications()) {
+ String attribute = (String)atlasClassification.getAttribute("type");
+ if (attribute != null && attribute.equals("SSN")) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue(found);
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testAddTraitWithNoRegistration() throws Exception {
+ final String traitName = "PII_Trait" + randomString();
+ AtlasTypeUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+
+ AtlasClassification traitInstance = new AtlasClassification(traitName);
+
+ atlasClientV2.addClassifications("random", ImmutableList.of(traitInstance));
+ }
+
+ @Test(dependsOnMethods = "testAddTrait")
+ public void testDeleteTrait() throws Exception {
+ final String guid = createHiveTable().getGuid();
+
+ try {
+ atlasClientV2.deleteClassification(guid, traitName);
+ } catch (AtlasServiceException ex) {
+ fail("Deletion should've succeeded");
+ }
+ assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
+ }
+
+ @Test
+ public void testDeleteTraitNonExistent() throws Exception {
+ final String traitName = "blah_trait";
+
+ try {
+ atlasClientV2.deleteClassification("random", traitName);
+ fail("Deletion for bogus names shouldn't have succeeded");
+ } catch (AtlasServiceException ex) {
+ assertNotNull(ex.getStatus());
+// assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
+ assertEquals(ex.getStatus(), ClientResponse.Status.BAD_REQUEST);
+ // Should it be a 400 or 404
+ }
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
+
+ final String guid = createHiveTable().getGuid();
+ final String traitName = "PII_Trait" + randomString();
+ AtlasClassificationDef piiTrait = AtlasTypeUtil
+ .createTraitTypeDef(traitName, ImmutableSet.<String>of(),
+ AtlasTypeUtil.createRequiredAttrDef("type", "string"));
+ AtlasTypesDef typesDef = new AtlasTypesDef();
+ typesDef.getClassificationDefs().add(piiTrait);
+ createType(typesDef);
+
+ try {
+ atlasClientV2.deleteClassification(guid, traitName);
+ fail("Deletion should've failed for non-existent trait association");
+ } catch (AtlasServiceException ex) {
+ Assert.assertNotNull(ex.getStatus());
+ assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
+ }
+ }
+
+ private String random() {
+ return RandomStringUtils.random(10);
+ }
+
+ @Test
+ public void testUTF8() throws Exception {
+ String classType = randomString();
+ String attrName = random();
+ String attrValue = random();
+
+ AtlasEntityDef classTypeDef = AtlasTypeUtil
+ .createClassTypeDef(classType, ImmutableSet.<String>of(),
+ AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string"));
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+ atlasTypesDef.getEntityDefs().add(classTypeDef);
+ createType(atlasTypesDef);
+
+ AtlasEntity instance = new AtlasEntity(classType);
+ instance.setAttribute(attrName, attrValue);
+ AtlasEntityHeader entity = createEntity(instance);
+ assertNotNull(entity);
+ assertNotNull(entity.getGuid());
+
+ AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid());
+ assertEquals(entityByGuid.getAttribute(attrName), attrValue);
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testPartialUpdate() throws Exception {
+ final List<AtlasEntity> columns = new ArrayList<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("name", "col1");
+ values.put(NAME, "qualifiedName.col1");
+ values.put("type", "string");
+ values.put("comment", "col1 comment");
+
+ AtlasEntity colEntity = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values);
+ columns.add(colEntity);
+ AtlasEntity hiveTable = createHiveTable();
+ AtlasEntity tableUpdated = hiveTable;
+
+ hiveTable.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
+
+ AtlasEntityWithExtInfo entityInfo = new AtlasEntityWithExtInfo(tableUpdated);
+ entityInfo.addReferredEntity(colEntity);
+
+ LOG.debug("Full Update entity= " + tableUpdated);
+ EntityMutationResponse updateResult = atlasClientV2.updateEntity(entityInfo);
+ assertNotNull(updateResult);
+ assertNotNull(updateResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
+ assertTrue(updateResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size() > 0);
+
+ String guid = hiveTable.getGuid();
+ AtlasEntity entityByGuid1 = getEntityByGuid(guid);
+ assertNotNull(entityByGuid1);
+ entityByGuid1.getAttribute("columns");
+
+ values.put("type", "int");
+ colEntity = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values);
+ columns.clear();
+ columns.add(colEntity);
+
+ tableUpdated = new AtlasEntity(HIVE_TABLE_TYPE_V2, "name", entityByGuid1.getAttribute("name"));
+ tableUpdated.setGuid(entityByGuid1.getGuid());
+ tableUpdated.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
+
+ // tableUpdated = hiveTable;
+ // tableUpdated.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
+
+ LOG.debug("Partial Update entity by unique attributes= " + tableUpdated);
+ Map<String, String> uniqAttributes = new HashMap<>();
+ uniqAttributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, (String) hiveTable.getAttribute("name"));
+
+ entityInfo = new AtlasEntityWithExtInfo(tableUpdated);
+ entityInfo.addReferredEntity(colEntity);
+
+ EntityMutationResponse updateResponse = atlasClientV2.updateEntityByAttribute(BaseResourceIT.HIVE_TABLE_TYPE_V2, uniqAttributes, entityInfo);
+
+ assertNotNull(updateResponse);
+ assertNotNull(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE));
+ assertTrue(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).size() > 0);
+
+ AtlasEntity entityByGuid2 = getEntityByGuid(guid);
+ assertNotNull(entityByGuid2);
+ }
+
+ private AtlasEntity getEntityByGuid(String guid) throws AtlasServiceException {
+ return atlasClientV2.getEntityByGuid(guid).getEntity();
+ }
+
+ @Test(dependsOnMethods = "testSubmitEntity")
+ public void testCompleteUpdate() throws Exception {
+ final List<AtlasEntity> columns = new ArrayList<>();
+ Map<String, Object> values1 = new HashMap<>();
+ values1.put("name", "col3");
+ values1.put(NAME, "qualifiedName.col3");
+ values1.put("type", "string");
+ values1.put("comment", "col3 comment");
+
+ Map<String, Object> values2 = new HashMap<>();
+ values2.put("name", "col4");
+ values2.put(NAME, "qualifiedName.col4");
+ values2.put("type", "string");
+ values2.put("comment", "col4 comment");
+
+ AtlasEntity colEntity1 = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values1);
+ AtlasEntity colEntity2 = new AtlasEntity(BaseResourceIT.COLUMN_TYPE_V2, values2);
+ columns.add(colEntity1);
+ columns.add(colEntity2);
+ AtlasEntity hiveTable = createHiveTable();
+ hiveTable.setAttribute("columns", AtlasTypeUtil.toObjectIds(columns));
+
+ AtlasEntityWithExtInfo entityInfo = new AtlasEntityWithExtInfo(hiveTable);
+ entityInfo.addReferredEntity(colEntity1);
+ entityInfo.addReferredEntity(colEntity2);
+
+ EntityMutationResponse updateEntityResult = atlasClientV2.updateEntity(entityInfo);
+ assertNotNull(updateEntityResult);
+ assertNotNull(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
+ assertNotNull(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
+ //2 columns are being created, and 1 hiveTable is being updated
+ assertEquals(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).size(), 1);
+ assertEquals(updateEntityResult.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(), 2);
+
+ AtlasEntity entityByGuid = getEntityByGuid(hiveTable.getGuid());
+ List<AtlasObjectId> refs = (List<AtlasObjectId>) entityByGuid.getAttribute("columns");
+ assertEquals(refs.size(), 2);
+ }
+
+ @Test
+ public void testDeleteEntities() throws Exception {
+ // Create 2 database entities
+ AtlasEntity db1 = new AtlasEntity(DATABASE_TYPE_V2);
+ String dbName1 = randomString();
+ db1.setAttribute("name", dbName1);
+ db1.setAttribute(NAME, dbName1);
+ db1.setAttribute("clusterName", randomString());
+ db1.setAttribute("description", randomString());
+ AtlasEntityHeader entity1Header = createEntity(db1);
+ AtlasEntity db2 = new AtlasEntity(DATABASE_TYPE_V2);
+ String dbName2 = randomString();
+ db2.setAttribute("name", dbName2);
+ db2.setAttribute(NAME, dbName2);
+ db2.setAttribute("clusterName", randomString());
+ db2.setAttribute("description", randomString());
+ AtlasEntityHeader entity2Header = createEntity(db2);
+
+ // Delete the database entities
+ EntityMutationResponse deleteResponse = atlasClientV2.deleteEntitiesByGuids(ImmutableList.of(entity1Header.getGuid(), entity2Header.getGuid()));
+
+ // Verify that deleteEntities() response has database entity guids
+ assertNotNull(deleteResponse);
+ assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
+ assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 2);
+
+ // Verify entities were deleted from the repository.
+ }
+
+ @Test
+ public void testDeleteEntityByUniqAttribute() throws Exception {
+ // Create database entity
+ AtlasEntity hiveDB = createHiveDB(DATABASE_NAME + random());
+
+ // Delete the database entity
+ EntityMutationResponse deleteResponse = atlasClientV2.deleteEntityByAttribute(DATABASE_TYPE_V2, toMap(NAME, (String) hiveDB.getAttribute(NAME)));
+
+ // Verify that deleteEntities() response has database entity guids
+ assertNotNull(deleteResponse);
+ assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
+ assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 1);
+
+ // Verify entities were deleted from the repository.
+ }
+
+ private Map<String, String> toMap(final String name, final String value) {
+ return new HashMap<String, String>() {{
+ put(name, value);
+ }};
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
new file mode 100755
index 0000000..3fa85b1
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/MetadataDiscoveryJerseyResourceIT.java
@@ -0,0 +1,267 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasClient;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.typesystem.Referenceable;
+import org.apache.atlas.typesystem.Struct;
+import org.apache.atlas.typesystem.TypesDef;
+import org.apache.atlas.typesystem.persistence.Id;
+import org.apache.atlas.typesystem.types.ClassType;
+import org.apache.atlas.typesystem.types.DataTypes;
+import org.apache.atlas.typesystem.types.EnumTypeDefinition;
+import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
+import org.apache.atlas.typesystem.types.StructTypeDefinition;
+import org.apache.atlas.typesystem.types.TraitType;
+import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.fail;
+
+/**
+ * Search Integration Tests.
+ */
+public class MetadataDiscoveryJerseyResourceIT extends BaseResourceIT {
+
+ private String tagName;
+ private String dbName;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+ dbName = "db"+randomString();
+ createTypes();
+ createInstance( createHiveDBInstanceV1(dbName) );
+ }
+
+ @Test
+ public void testSearchByDSL() throws Exception {
+ 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);
+
+ Assert.assertNotNull(response);
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ assertEquals(response.getString("query"), dslQuery);
+ assertEquals(response.getString("queryType"), "dsl");
+
+ JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
+ assertNotNull(results);
+ assertEquals(results.length(), 1);
+
+ int numRows = response.getInt(AtlasClient.COUNT);
+ assertEquals(numRows, 1);
+ }
+
+ @Test
+ public void testSearchDSLLimits() throws Exception {
+
+ //search without new parameters of limit and offset should work
+ 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);
+ assertNotNull(response);
+
+ //higher limit, all results returned
+ JSONArray results = atlasClientV1.searchByDSL(dslQuery, 10, 0);
+ assertEquals(results.length(), 1);
+
+ //default limit and offset -1, all results returned
+ results = atlasClientV1.searchByDSL(dslQuery, -1, -1);
+ assertEquals(results.length(), 1);
+
+ //uses the limit parameter passed
+ results = atlasClientV1.searchByDSL(dslQuery, 1, 0);
+ assertEquals(results.length(), 1);
+
+ //uses the offset parameter passed
+ results = atlasClientV1.searchByDSL(dslQuery, 10, 1);
+ assertEquals(results.length(), 0);
+
+ //limit > 0
+ try {
+ atlasClientV1.searchByDSL(dslQuery, 0, 10);
+ fail("Expected BAD_REQUEST");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
+ }
+
+ //limit > maxlimit
+ try {
+ atlasClientV1.searchByDSL(dslQuery, Integer.MAX_VALUE, 10);
+ fail("Expected BAD_REQUEST");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
+ }
+
+ //offset >= 0
+ try {
+ atlasClientV1.searchByDSL(dslQuery, 10, -2);
+ fail("Expected BAD_REQUEST");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST, "Got " + e.getStatus());
+ }
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testSearchByDSLForUnknownType() throws Exception {
+ String dslQuery = "from blah";
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("query", dslQuery);
+ atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_DSL, queryParams);
+ }
+
+ @Test
+ public void testSearchUsingGremlin() throws Exception {
+ String query = "g.V.has('type', '" + BaseResourceIT.HIVE_TABLE_TYPE + "').toList()";
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("query", query);
+
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.GREMLIN_SEARCH, queryParams);
+
+ assertNotNull(response);
+ assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ assertEquals(response.getString("query"), query);
+ assertEquals(response.getString("queryType"), "gremlin");
+ }
+
+ @Test
+ public void testSearchUsingDSL() throws Exception {
+ //String query = "from dsl_test_type";
+ 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);
+
+ Assert.assertNotNull(response);
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ assertEquals(response.getString("query"), query);
+ assertEquals(response.getString("queryType"), "dsl");
+ }
+
+ @Test
+ public void testSearchFullTextOnDSLFailure() throws Exception {
+ String query = "*";
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("query", query);
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH, queryParams);
+
+ Assert.assertNotNull(response);
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ assertEquals(response.getString("query"), query);
+ assertEquals(response.getString("queryType"), "full-text");
+ }
+
+ @Test(dependsOnMethods = "testSearchDSLLimits")
+ public void testSearchUsingFullText() throws Exception {
+ JSONObject response = atlasClientV1.searchByFullText(dbName, 10, 0);
+ assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ assertEquals(response.getString("query"), dbName);
+ assertEquals(response.getString("queryType"), "full-text");
+
+ JSONArray results = response.getJSONArray(AtlasClient.RESULTS);
+ assertEquals(results.length(), 1, "Results: " + results);
+
+ JSONObject row = results.getJSONObject(0);
+ assertNotNull(row.get("guid"));
+ assertEquals(row.getString("typeName"), DATABASE_TYPE);
+ assertNotNull(row.get("score"));
+
+ int numRows = response.getInt(AtlasClient.COUNT);
+ assertEquals(numRows, 1);
+
+ //API works without limit and offset
+ String query = dbName;
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("query", query);
+ response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.SEARCH_FULL_TEXT, queryParams);
+ results = response.getJSONArray(AtlasClient.RESULTS);
+ assertEquals(results.length(), 1);
+
+ //verify passed in limits and offsets are used
+ //higher limit and 0 offset returns all results
+ results = atlasClientV1.searchByFullText(query, 10, 0).getJSONArray(AtlasClient.RESULTS);
+ assertEquals(results.length(), 1);
+
+ //offset is used
+ results = atlasClientV1.searchByFullText(query, 10, 1).getJSONArray(AtlasClient.RESULTS);
+ assertEquals(results.length(), 0);
+
+ //limit is used
+ results = atlasClientV1.searchByFullText(query, 1, 0).getJSONArray(AtlasClient.RESULTS);
+ assertEquals(results.length(), 1);
+
+ //higher offset returns 0 results
+ results = atlasClientV1.searchByFullText(query, 1, 2).getJSONArray(AtlasClient.RESULTS);
+ assertEquals(results.length(), 0);
+ }
+
+ private void createTypes() throws Exception {
+ createTypeDefinitionsV1();
+
+ HierarchicalTypeDefinition<ClassType> dslTestTypeDefinition = TypesUtil
+ .createClassTypeDef("dsl_test_type", ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE));
+
+ HierarchicalTypeDefinition<TraitType> classificationTraitDefinition = TypesUtil
+ .createTraitTypeDef("Classification", ImmutableSet.<String>of(),
+ TypesUtil.createRequiredAttrDef("tag", DataTypes.STRING_TYPE));
+ TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
+ ImmutableList.of(classificationTraitDefinition), ImmutableList.of(dslTestTypeDefinition));
+ createType(typesDef);
+ }
+
+ private Id createInstance() throws Exception {
+ Referenceable entityInstance = new Referenceable("dsl_test_type", "Classification");
+ entityInstance.set("name", randomString());
+ entityInstance.set("description", randomString());
+
+
+ Struct traitInstance = (Struct) entityInstance.getTrait("Classification");
+ tagName = randomString();
+ traitInstance.set("tag", tagName);
+
+ List<String> traits = entityInstance.getTraits();
+ assertEquals(traits.size(), 1);
+
+ return createInstance(entityInstance);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java
new file mode 100644
index 0000000..c46689c
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java
@@ -0,0 +1,370 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableSet;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasClientV2;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.model.SearchFilter;
+import org.apache.atlas.model.TypeCategory;
+import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
+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.AtlasStructDef.AtlasAttributeDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
+import org.apache.atlas.model.typedef.AtlasTypesDef;
+import org.apache.atlas.type.AtlasTypeUtil;
+import org.apache.atlas.typesystem.types.DataTypes;
+import org.apache.atlas.utils.AuthenticationUtil;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.util.Collections;
+
+import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
+import static org.apache.atlas.type.AtlasTypeUtil.createClassTypeDef;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+/**
+ * Integration test for types jersey resource.
+ */
+public class TypedefsJerseyResourceIT extends BaseResourceIT {
+
+ private AtlasTypesDef typeDefinitions;
+
+ private AtlasClientV2 clientV2;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+
+ typeDefinitions = createHiveTypesV2();
+
+ if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
+ clientV2 = new AtlasClientV2(atlasUrls, new String[]{"admin", "admin"});
+ } else {
+ clientV2 = new AtlasClientV2(atlasUrls);
+ }
+ }
+
+ @AfterClass
+ public void tearDown() throws Exception {
+ emptyTypeDefs(typeDefinitions);
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ createType(typeDefinitions);
+
+ for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) {
+ AtlasEnumDef byName = atlasClientV2.getEnumDefByName(enumDef.getName());
+ assertNotNull(byName);
+ }
+ for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
+ AtlasStructDef byName = atlasClientV2.getStructDefByName(structDef.getName());
+ assertNotNull(byName);
+ }
+ for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
+ AtlasClassificationDef byName = atlasClientV2.getClassificationDefByName(classificationDef.getName());
+ assertNotNull(byName);
+ }
+ for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
+ AtlasEntityDef byName = atlasClientV2.getEntityDefByName(entityDef.getName());
+ assertNotNull(byName);
+ }
+
+ }
+
+ @Test
+ public void testDuplicateCreate() throws Exception {
+ AtlasEntityDef type = createClassTypeDef(randomString(),
+ ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
+ AtlasTypesDef typesDef = new AtlasTypesDef();
+ typesDef.getEntityDefs().add(type);
+
+ AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
+ assertNotNull(created);
+
+ try {
+ created = clientV2.createAtlasTypeDefs(typesDef);
+ fail("Expected 409");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
+ }
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ String entityType = randomString();
+ AtlasEntityDef typeDefinition =
+ createClassTypeDef(entityType, ImmutableSet.<String>of(),
+ AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
+
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+ atlasTypesDef.getEntityDefs().add(typeDefinition);
+
+ AtlasTypesDef createdTypeDefs = clientV2.createAtlasTypeDefs(atlasTypesDef);
+ assertNotNull(createdTypeDefs);
+ assertEquals(createdTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
+
+ //Add attribute description
+ typeDefinition = createClassTypeDef(typeDefinition.getName(),
+ ImmutableSet.<String>of(),
+ AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("description", "string"));
+
+ emptyTypeDefs(atlasTypesDef);
+
+ atlasTypesDef.getEntityDefs().add(typeDefinition);
+
+ AtlasTypesDef updatedTypeDefs = clientV2.updateAtlasTypeDefs(atlasTypesDef);
+ assertNotNull(updatedTypeDefs);
+ assertEquals(updatedTypeDefs.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
+ assertEquals(updatedTypeDefs.getEntityDefs().get(0).getName(), atlasTypesDef.getEntityDefs().get(0).getName());
+
+ MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl();
+ filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY");
+ AtlasTypesDef allTypeDefs = clientV2.getAllTypeDefs(new SearchFilter(filterParams));
+ assertNotNull(allTypeDefs);
+ Boolean entityDefFound = false;
+ for (AtlasEntityDef atlasEntityDef : allTypeDefs.getEntityDefs()){
+ if (atlasEntityDef.getName().equals(typeDefinition.getName())) {
+ assertEquals(atlasEntityDef.getAttributeDefs().size(), 2);
+ entityDefFound = true;
+ break;
+ }
+ }
+ assertTrue(entityDefFound, "Required entityDef not found.");
+ }
+
+ @Test(dependsOnMethods = "testCreate")
+ public void testGetDefinition() throws Exception {
+ if (CollectionUtils.isNotEmpty(typeDefinitions.getEnumDefs())) {
+ for (AtlasEnumDef atlasEnumDef : typeDefinitions.getEnumDefs()) {
+ verifyByNameAndGUID(atlasEnumDef);
+ }
+ }
+
+ if (CollectionUtils.isNotEmpty(typeDefinitions.getStructDefs())) {
+ for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
+ verifyByNameAndGUID(structDef);
+ }
+ }
+
+ if (CollectionUtils.isNotEmpty(typeDefinitions.getClassificationDefs())) {
+ for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
+ verifyByNameAndGUID(classificationDef);
+ }
+ }
+
+ if (CollectionUtils.isNotEmpty(typeDefinitions.getEntityDefs())) {
+ for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
+ verifyByNameAndGUID(entityDef);
+ }
+ }
+ }
+
+ @Test
+ public void testInvalidGets() throws Exception {
+ try {
+ AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+ try {
+ AtlasEnumDef byGuid = clientV2.getEnumDefByGuid("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+ try {
+ AtlasStructDef byName = clientV2.getStructDefByName("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+ try {
+ AtlasStructDef byGuid = clientV2.getStructDefByGuid("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+ try {
+ AtlasClassificationDef byName = clientV2.getClassificationDefByName("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+ try {
+ AtlasClassificationDef byGuid = clientV2.getClassificationDefByGuid("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+ try {
+ AtlasEntityDef byName = clientV2.getEntityDefByName("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+ try {
+ AtlasEntityDef byGuid = clientV2.getEntityDefByGuid("blah");
+ fail("Get for invalid name should have reported a failure");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
+ "Should've returned a 404");
+ }
+
+
+ }
+
+ @Test
+ public void testListTypesByFilter() throws Exception {
+ AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
+ AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr);
+ AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(classDefA.getName()), attr);
+ AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr);
+ AtlasEntityDef classDefC = AtlasTypeUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(classDefB.getName(), classDefA.getName()), attr);
+
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+ atlasTypesDef.getEntityDefs().add(classDefA);
+ atlasTypesDef.getEntityDefs().add(classDefA1);
+ atlasTypesDef.getEntityDefs().add(classDefB);
+ atlasTypesDef.getEntityDefs().add(classDefC);
+
+ AtlasTypesDef created = clientV2.createAtlasTypeDefs(atlasTypesDef);
+ assertNotNull(created);
+ assertEquals(created.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
+
+ MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
+ searchParams.add(SearchFilter.PARAM_TYPE, "CLASS");
+ searchParams.add(SearchFilter.PARAM_SUPERTYPE, classDefA.getName());
+ SearchFilter searchFilter = new SearchFilter(searchParams);
+ AtlasTypesDef searchDefs = clientV2.getAllTypeDefs(searchFilter);
+ assertNotNull(searchDefs);
+ assertEquals(searchDefs.getEntityDefs().size(), 2);
+
+ searchParams.add(SearchFilter.PARAM_NOT_SUPERTYPE, classDefB.getName());
+ searchFilter = new SearchFilter(searchParams);
+ searchDefs = clientV2.getAllTypeDefs(searchFilter);
+ assertNotNull(searchDefs);
+ assertEquals(searchDefs.getEntityDefs().size(), 1);
+ }
+
+ private AtlasTypesDef createHiveTypesV2() throws Exception {
+ AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
+
+ AtlasEntityDef databaseTypeDefinition =
+ createClassTypeDef("database", ImmutableSet.<String>of(),
+ AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
+ AtlasTypeUtil.createRequiredAttrDef("description", "string"));
+ atlasTypesDef.getEntityDefs().add(databaseTypeDefinition);
+
+ AtlasEntityDef tableTypeDefinition =
+ createClassTypeDef("table", ImmutableSet.<String>of(),
+ AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"),
+ AtlasTypeUtil.createRequiredAttrDef("description", "string"),
+ AtlasTypeUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName("string")),
+ AtlasTypeUtil.createOptionalAttrDef("created", "date"),
+ AtlasTypeUtil.createOptionalAttrDef("parameters",
+ DataTypes.mapTypeName("string", "string")),
+ AtlasTypeUtil.createRequiredAttrDef("type", "string"),
+ new AtlasAttributeDef("database", "database",
+ false,
+ Cardinality.SINGLE, 1, 1,
+ true, true,
+ Collections.<AtlasConstraintDef>emptyList()));
+ atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
+
+ AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil
+ .createTraitTypeDef("fetl", ImmutableSet.<String>of(),
+ AtlasTypeUtil.createRequiredAttrDef("level", "int"));
+ atlasTypesDef.getClassificationDefs().add(fetlTypeDefinition);
+
+ return atlasTypesDef;
+ }
+
+ private void verifyByNameAndGUID(AtlasBaseTypeDef typeDef) {
+ try {
+ AtlasBaseTypeDef byName = null;
+ if (typeDef.getCategory() == TypeCategory.ENUM) {
+ byName = clientV2.getEnumDefByName(typeDef.getName());
+ } else if (typeDef.getCategory() == TypeCategory.ENTITY) {
+ byName = clientV2.getEntityDefByName(typeDef.getName());
+ } else if (typeDef.getCategory() == TypeCategory.CLASSIFICATION) {
+ byName = clientV2.getClassificationDefByName(typeDef.getName());
+ } else if (typeDef.getCategory() == TypeCategory.STRUCT) {
+ byName = clientV2.getStructDefByName(typeDef.getName());
+ }
+ assertNotNull(byName);
+ } catch (AtlasServiceException e) {
+ fail("Get byName should've succeeded", e);
+ }
+ if (StringUtils.isNotBlank(typeDef.getGuid())) {
+ try {
+ AtlasBaseTypeDef byGuid = null;
+ if (typeDef.getCategory() == TypeCategory.ENUM) {
+ byGuid = clientV2.getEnumDefByGuid(typeDef.getGuid());
+ } else if (typeDef.getCategory() == TypeCategory.ENTITY) {
+ byGuid = clientV2.getEntityDefByGuid(typeDef.getGuid());
+ } else if (typeDef.getCategory() == TypeCategory.CLASSIFICATION) {
+ byGuid = clientV2.getClassificationDefByGuid(typeDef.getGuid());
+ } else if (typeDef.getCategory() == TypeCategory.STRUCT) {
+ byGuid = clientV2.getStructDefByGuid(typeDef.getGuid());
+ }
+ assertNotNull(byGuid);
+ } catch (AtlasServiceException e) {
+ fail("Get byGuid should've succeeded", e);
+ }
+ }
+ }
+
+ private void emptyTypeDefs(AtlasTypesDef def) {
+ def.getEnumDefs().clear();
+ def.getStructDefs().clear();
+ def.getClassificationDefs().clear();
+ def.getEntityDefs().clear();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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
new file mode 100755
index 0000000..ded3e05
--- /dev/null
+++ b/webapp/src/test/java/org/apache/atlas/web/integration/TypesJerseyResourceIT.java
@@ -0,0 +1,262 @@
+/**
+ * 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.web.integration;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.atlas.AtlasClient;
+import org.apache.atlas.AtlasServiceException;
+import org.apache.atlas.typesystem.TypesDef;
+import org.apache.atlas.typesystem.json.TypesSerialization;
+import org.apache.atlas.typesystem.json.TypesSerialization$;
+import org.apache.atlas.typesystem.types.AttributeDefinition;
+import org.apache.atlas.typesystem.types.ClassType;
+import org.apache.atlas.typesystem.types.DataTypes;
+import org.apache.atlas.typesystem.types.EnumTypeDefinition;
+import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition;
+import org.apache.atlas.typesystem.types.Multiplicity;
+import org.apache.atlas.typesystem.types.StructTypeDefinition;
+import org.apache.atlas.typesystem.types.TraitType;
+import org.apache.atlas.typesystem.types.utils.TypesUtil;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.fail;
+
+/**
+ * Integration test for types jersey resource.
+ */
+public class TypesJerseyResourceIT extends BaseResourceIT {
+
+ private List<HierarchicalTypeDefinition> typeDefinitions;
+
+ @BeforeClass
+ public void setUp() throws Exception {
+ super.setUp();
+
+ typeDefinitions = createHiveTypes();
+ }
+
+ @AfterClass
+ public void tearDown() throws Exception {
+ typeDefinitions.clear();
+ }
+
+ @Test
+ public void testSubmit() throws Exception {
+ for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
+ try{
+ atlasClientV1.getType(typeDefinition.typeName);
+ } catch (AtlasServiceException ase){
+ String typesAsJSON = TypesSerialization.toJson(typeDefinition, false);
+ System.out.println("typesAsJSON = " + typesAsJSON);
+
+ JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.CREATE_TYPE, typesAsJSON);
+ Assert.assertNotNull(response);
+
+
+ JSONArray typesAdded = response.getJSONArray(AtlasClient.TYPES);
+ assertEquals(typesAdded.length(), 1);
+ assertEquals(typesAdded.getJSONObject(0).getString(NAME), typeDefinition.typeName);
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));}
+ }
+ }
+
+ @Test
+ public void testDuplicateSubmit() throws Exception {
+ HierarchicalTypeDefinition<ClassType> type = TypesUtil.createClassTypeDef(randomString(),
+ ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
+ TypesDef typesDef =
+ TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(),
+ ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(type));
+ atlasClientV1.createType(typesDef);
+
+ try {
+ atlasClientV1.createType(typesDef);
+ fail("Expected 409");
+ } catch (AtlasServiceException e) {
+ assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
+ }
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil
+ .createClassTypeDef(randomString(), ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE));
+ List<String> typesCreated = atlasClientV1.createType(TypesSerialization.toJson(typeDefinition, false));
+ assertEquals(typesCreated.size(), 1);
+ assertEquals(typesCreated.get(0), typeDefinition.typeName);
+
+ //Add attribute description
+ typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.typeName,
+ ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
+ createOptionalAttrDef(DESCRIPTION, DataTypes.STRING_TYPE));
+ TypesDef typeDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
+ ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
+ ImmutableList.of(typeDefinition));
+ List<String> typesUpdated = atlasClientV1.updateType(typeDef);
+ assertEquals(typesUpdated.size(), 1);
+ Assert.assertTrue(typesUpdated.contains(typeDefinition.typeName));
+
+ TypesDef updatedTypeDef = atlasClientV1.getType(typeDefinition.typeName);
+ assertNotNull(updatedTypeDef);
+
+ HierarchicalTypeDefinition<ClassType> updatedType = updatedTypeDef.classTypesAsJavaList().get(0);
+ assertEquals(updatedType.attributeDefinitions.length, 2);
+ }
+
+ @Test(dependsOnMethods = "testSubmit")
+ public void testGetDefinition() throws Exception {
+ for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
+ System.out.println("typeName = " + typeDefinition.typeName);
+
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName);
+
+ Assert.assertNotNull(response);
+ Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ String typesJson = response.getString(AtlasClient.DEFINITION);
+ final TypesDef typesDef = TypesSerialization.fromJson(typesJson);
+ List<HierarchicalTypeDefinition<ClassType>> hierarchicalTypeDefinitions = typesDef.classTypesAsJavaList();
+ for (HierarchicalTypeDefinition<ClassType> classType : hierarchicalTypeDefinitions) {
+ for (AttributeDefinition attrDef : classType.attributeDefinitions) {
+ if (NAME.equals(attrDef.name)) {
+ assertEquals(attrDef.isIndexable, true);
+ assertEquals(attrDef.isUnique, true);
+ }
+ }
+ }
+ }
+ }
+
+ @Test(expectedExceptions = AtlasServiceException.class)
+ public void testGetDefinitionForNonexistentType() throws Exception {
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, "blah");
+ }
+
+ @Test(dependsOnMethods = "testSubmit")
+ public void testGetTypeNames() throws Exception {
+ JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, (String[]) null);
+ Assert.assertNotNull(response);
+
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
+ Assert.assertNotNull(list);
+
+ //Verify that primitive and core types are not returned
+ String typesString = list.join(" ");
+ Assert.assertFalse(typesString.contains(" \"__IdType\" "));
+ Assert.assertFalse(typesString.contains(" \"string\" "));
+ }
+
+ @Test
+ public void testGetTraitNames() throws Exception {
+ String[] traitsAdded = addTraits();
+
+ MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
+ queryParams.add("type", DataTypes.TypeCategory.TRAIT.name());
+
+ JSONObject response = atlasClientV1.callAPIWithQueryParams(AtlasClient.API.LIST_TYPES, queryParams);
+ Assert.assertNotNull(response);
+
+ Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
+
+ final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
+ Assert.assertNotNull(list);
+ Assert.assertTrue(list.length() >= traitsAdded.length);
+ }
+
+ @Test
+ public void testListTypesByFilter() throws Exception {
+ AttributeDefinition attr = TypesUtil.createOptionalAttrDef("attr", DataTypes.STRING_TYPE);
+ String a = createType(TypesSerialization.toJson(
+ TypesUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr), false)).get(0);
+ String a1 = createType(TypesSerialization.toJson(
+ TypesUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(a), attr), false)).get(0);
+ String b = createType(TypesSerialization.toJson(
+ TypesUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr), false)).get(0);
+ String c = createType(TypesSerialization.toJson(
+ TypesUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(a, b), attr), false)).get(0);
+
+ List<String> results = atlasClientV1.listTypes(DataTypes.TypeCategory.CLASS, a, b);
+ assertEquals(results, Arrays.asList(a1), "Results: " + results);
+ }
+
+ private String[] addTraits() throws Exception {
+ String[] traitNames = {"class_trait", "secure_trait", "pii_trait", "ssn_trait", "salary_trait", "sox_trait",};
+
+ for (String traitName : traitNames) {
+ HierarchicalTypeDefinition<TraitType> traitTypeDef =
+ TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of());
+ String json = TypesSerialization$.MODULE$.toJson(traitTypeDef, true);
+ createType(json);
+ }
+
+ return traitNames;
+ }
+
+ private List<HierarchicalTypeDefinition> createHiveTypes() throws Exception {
+ ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>();
+
+ HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil
+ .createClassTypeDef("database", ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE));
+ typeDefinitions.add(databaseTypeDefinition);
+
+ HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil
+ .createClassTypeDef("table", ImmutableSet.<String>of(),
+ TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE),
+ TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE),
+ createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)),
+ createOptionalAttrDef("created", DataTypes.DATE_TYPE),
+ createOptionalAttrDef("parameters",
+ DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE)),
+ TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE),
+ new AttributeDefinition("database", "database", Multiplicity.REQUIRED, false, "database"));
+ typeDefinitions.add(tableTypeDefinition);
+
+ HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil
+ .createTraitTypeDef("fetl", ImmutableSet.<String>of(),
+ TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
+ typeDefinitions.add(fetlTypeDefinition);
+
+ return typeDefinitions;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java b/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java
deleted file mode 100644
index da221fc..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/listeners/TestGuiceServletConfig.java
+++ /dev/null
@@ -1,82 +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.web.listeners;
-
-import javax.servlet.ServletContextEvent;
-
-import org.apache.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
-import org.apache.atlas.repository.graphdb.AtlasGraph;
-import org.apache.commons.configuration.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.Module;
-
-public class TestGuiceServletConfig extends GuiceServletConfig {
-
- private static final Logger LOG = LoggerFactory.getLogger(TestGuiceServletConfig.class);
- private boolean servicesEnabled;
-
- @Override
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- LOG.info("Initializing test servlet listener");
- super.contextInitialized(servletContextEvent);
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- super.contextDestroyed(servletContextEvent);
-
- if(injector != null) {
- AtlasGraph graph = AtlasGraphProvider.getGraphInstance();
-
- LOG.info("Clearing graph store");
- try {
- AtlasGraphProvider.cleanup();
- } catch (Exception e) {
- LOG.warn("Clearing graph store failed ", e);
- }
- }
- }
-
- @Override
- protected Module getRepositoryModule() {
- return new TestModule();
- }
-
- @Override
- protected void startServices() {
- try {
- Configuration conf = ApplicationProperties.get();
- servicesEnabled = conf.getBoolean("atlas.services.enabled", true);
- if (servicesEnabled) {
- super.startServices();
- }
- } catch (AtlasException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- protected void stopServices() {
- if (servicesEnabled) {
- super.stopServices();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java b/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java
deleted file mode 100644
index b00080f..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/listeners/TestModule.java
+++ /dev/null
@@ -1,34 +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.web.listeners;
-
-import com.google.inject.Binder;
-
-import org.apache.atlas.RepositoryMetadataModule;
-import org.apache.atlas.repository.audit.EntityAuditRepository;
-import org.apache.atlas.repository.audit.InMemoryEntityAuditRepository;
-import org.apache.commons.configuration.Configuration;
-
-public class TestModule extends RepositoryMetadataModule {
- @Override
- protected void bindAuditRepository(Binder binder, Configuration configuration) {
- //Map EntityAuditRepository interface to hbase based implementation
- binder.bind(EntityAuditRepository.class).to(InMemoryEntityAuditRepository.class).asEagerSingleton();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/AdminJerseyResourceIT.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/AdminJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/resources/AdminJerseyResourceIT.java
deleted file mode 100755
index 177785c..0000000
--- a/webapp/src/test/java/org/apache/atlas/web/resources/AdminJerseyResourceIT.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.web.resources;
-
-import org.apache.atlas.AtlasClient;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.codehaus.jettison.json.JSONObject;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-/**
- * Integration test for Admin jersey resource.
- */
-public class AdminJerseyResourceIT extends BaseResourceIT {
-
- @BeforeClass
- public void setUp() throws Exception {
- super.setUp();
- }
-
- @Test
- public void testGetVersion() throws Exception {
- JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.VERSION, null, (String[]) null);
- Assert.assertNotNull(response);
-
- PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
-
- Assert.assertEquals(response.get("Version"), buildConfiguration.getString("build.version"));
- Assert.assertEquals(response.get("Name"), buildConfiguration.getString("project.name"));
- Assert.assertEquals(response.get("Description"), buildConfiguration.getString("project.description"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
----------------------------------------------------------------------
diff --git a/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java b/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
index c0bbf09..1fe3119 100644
--- a/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
+++ b/webapp/src/test/java/org/apache/atlas/web/resources/AdminResourceTest.java
@@ -48,7 +48,7 @@ public class AdminResourceTest {
when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.ACTIVE);
- AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
+ AdminResource adminResource = new AdminResource(serviceState, null, null, null, null, null);
Response response = adminResource.getStatus();
assertEquals(response.getStatus(), HttpServletResponse.SC_OK);
JSONObject entity = (JSONObject) response.getEntity();
@@ -59,7 +59,7 @@ public class AdminResourceTest {
public void testResourceGetsValueFromServiceState() throws JSONException {
when(serviceState.getState()).thenReturn(ServiceState.ServiceStateValue.PASSIVE);
- AdminResource adminResource = new AdminResource(serviceState, null, null, null, null);
+ AdminResource adminResource = new AdminResource(serviceState, null, null, null, null, null);
Response response = adminResource.getStatus();
verify(serviceState).getState();
[09/12] incubator-atlas git commit: ATLAS-1198: Spring Framework (v4
with Spring security) over Guice
Posted by ap...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 c08fbc9..26dc6a8 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
@@ -21,10 +21,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject;
import org.apache.atlas.CreateUpdateEntitiesResult;
-import org.apache.atlas.TestOnlyModule;
import org.apache.atlas.TestUtils;
import org.apache.atlas.repository.MetadataRepository;
-import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.types.AttributeDefinition;
@@ -40,7 +38,6 @@ import org.apache.atlas.typesystem.types.utils.TypesUtil;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.Arrays;
@@ -52,9 +49,7 @@ import java.util.Map;
* Verifies automatic update of reverse references
*
*/
-@Guice(modules = TestOnlyModule.class)
public abstract class ReverseReferenceUpdateTestBase {
-
@Inject
MetadataRepository repositoryService;
@@ -63,8 +58,6 @@ public abstract class ReverseReferenceUpdateTestBase {
protected ClassType typeA;
protected ClassType typeB;
- abstract DeleteHandler getDeleteHandler(TypeSystem typeSystem);
-
abstract void assertTestOneToOneReference(Object actual, ITypedReferenceableInstance expectedValue, ITypedReferenceableInstance referencingInstance) throws Exception;
abstract void assertTestOneToManyReference(Object refValue, ITypedReferenceableInstance referencingInstance) throws Exception;
@@ -73,8 +66,6 @@ public abstract class ReverseReferenceUpdateTestBase {
typeSystem = TypeSystem.getInstance();
typeSystem.reset();
- new GraphBackedSearchIndexer(new AtlasTypeRegistry());
-
HierarchicalTypeDefinition<ClassType> aDef = TypesUtil.createClassTypeDef("A", ImmutableSet.<String>of(),
TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE),
new AttributeDefinition("b", "B", Multiplicity.OPTIONAL, false, "a"), // 1-1
@@ -95,7 +86,6 @@ public abstract class ReverseReferenceUpdateTestBase {
typeA = typeSystem.getDataType(ClassType.class, "A");
typeB = typeSystem.getDataType(ClassType.class, "B");
- repositoryService = new GraphBackedMetadataRepository(getDeleteHandler(typeSystem));
repositoryService = TestUtils.addTransactionWrapper(repositoryService);
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
index b34db82..b835d22 100644
--- a/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/impexp/ExportServiceTest.java
@@ -18,8 +18,7 @@
package org.apache.atlas.repository.impexp;
-import com.google.inject.Inject;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.impexp.AtlasExportRequest;
@@ -33,20 +32,21 @@ import org.apache.atlas.repository.store.graph.v1.AtlasEntityChangeNotifier;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStoreV1;
import org.apache.atlas.repository.store.graph.v1.AtlasEntityStream;
import org.apache.atlas.repository.store.graph.v1.DeleteHandlerV1;
+import org.apache.atlas.repository.store.graph.v1.EntityGraphMapper;
import org.apache.atlas.repository.store.graph.v1.SoftDeleteHandlerV1;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeRegistry;
+import org.powermock.reflect.Whitebox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
-import org.powermock.reflect.Whitebox;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import scala.actors.threadpool.Arrays;
+import javax.inject.Inject;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
@@ -61,7 +61,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class ExportServiceTest {
private static final Logger LOG = LoggerFactory.getLogger(ExportServiceTest.class);
@@ -71,6 +71,9 @@ public class ExportServiceTest {
@Inject
private AtlasTypeDefStore typeDefStore;
+ @Inject
+ private EntityGraphMapper graphMapper;
+ @Inject
ExportService exportService;
private DeleteHandlerV1 deleteHandler = mock(SoftDeleteHandlerV1.class);;
private AtlasEntityChangeNotifier mockChangeNotifier = mock(AtlasEntityChangeNotifier.class);
@@ -78,7 +81,7 @@ public class ExportServiceTest {
@BeforeClass
public void setupSampleData() throws AtlasBaseException {
- entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier);;
+ entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier, graphMapper);;
AtlasTypesDef sampleTypes = TestUtilsV2.defineDeptEmployeeTypes();
AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(sampleTypes, typeRegistry);
@@ -94,11 +97,6 @@ public class ExportServiceTest {
LOG.debug("==> setupSampleData: ", AtlasEntity.dumpObjects(hrDept.getEntities(), null).toString());
}
- @BeforeTest
- public void setupExportService () throws AtlasBaseException {
- exportService = new ExportService(typeRegistry);
- }
-
@AfterClass
public void clear() {
AtlasGraphProvider.cleanup();
@@ -257,33 +255,33 @@ public class ExportServiceTest {
@Test
public void verifyOverallStatus() throws Exception {
- ExportService service = new ExportService(typeRegistry);
- assertEquals(AtlasExportResult.OperationStatus.FAIL, Whitebox.invokeMethod(service,
+// ExportService service = new ExportService(typeRegistry);
+ assertEquals(AtlasExportResult.OperationStatus.FAIL, Whitebox.invokeMethod(exportService,
"getOverallOperationStatus"));
- assertEquals(AtlasExportResult.OperationStatus.SUCCESS, Whitebox.invokeMethod(service,
+ assertEquals(AtlasExportResult.OperationStatus.SUCCESS, Whitebox.invokeMethod(exportService,
"getOverallOperationStatus",
AtlasExportResult.OperationStatus.SUCCESS));
- assertEquals(AtlasExportResult.OperationStatus.SUCCESS, Whitebox.invokeMethod(service,
+ assertEquals(AtlasExportResult.OperationStatus.SUCCESS, Whitebox.invokeMethod(exportService,
"getOverallOperationStatus",
AtlasExportResult.OperationStatus.SUCCESS,
AtlasExportResult.OperationStatus.SUCCESS,
AtlasExportResult.OperationStatus.SUCCESS));
- assertEquals(AtlasExportResult.OperationStatus.PARTIAL_SUCCESS, Whitebox.invokeMethod(service,
+ assertEquals(AtlasExportResult.OperationStatus.PARTIAL_SUCCESS, Whitebox.invokeMethod(exportService,
"getOverallOperationStatus",
AtlasExportResult.OperationStatus.FAIL,
AtlasExportResult.OperationStatus.PARTIAL_SUCCESS,
AtlasExportResult.OperationStatus.SUCCESS));
- assertEquals(AtlasExportResult.OperationStatus.PARTIAL_SUCCESS, Whitebox.invokeMethod(service,
+ assertEquals(AtlasExportResult.OperationStatus.PARTIAL_SUCCESS, Whitebox.invokeMethod(exportService,
"getOverallOperationStatus",
AtlasExportResult.OperationStatus.FAIL,
AtlasExportResult.OperationStatus.FAIL,
AtlasExportResult.OperationStatus.PARTIAL_SUCCESS));
- assertEquals(AtlasExportResult.OperationStatus.FAIL, Whitebox.invokeMethod(service,
+ assertEquals(AtlasExportResult.OperationStatus.FAIL, Whitebox.invokeMethod(exportService,
"getOverallOperationStatus",
AtlasExportResult.OperationStatus.FAIL,
AtlasExportResult.OperationStatus.FAIL,
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceReportingTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceReportingTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceReportingTest.java
index f9a0584..0aaaa70 100644
--- a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceReportingTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceReportingTest.java
@@ -18,7 +18,7 @@
package org.apache.atlas.repository.impexp;
import com.google.inject.Inject;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeRegistry;
@@ -26,7 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Guice;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class ImportServiceReportingTest {
private static final Logger LOG = LoggerFactory.getLogger(ImportServiceReportingTest.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
index 91966f8..08e9ee8 100644
--- a/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/impexp/ImportServiceTest.java
@@ -18,7 +18,7 @@
package org.apache.atlas.repository.impexp;
import com.google.inject.Inject;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.store.AtlasTypeDefStore;
@@ -36,7 +36,7 @@ import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.getZip
import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadModelFromJson;
import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.runAndVerifyQuickStart_v1_Import;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class ImportServiceTest {
private static final Logger LOG = LoggerFactory.getLogger(ImportServiceTest.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStoreV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStoreV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStoreV1Test.java
index 31fba33..5f01136 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStoreV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasEntityDefStoreV1Test.java
@@ -22,7 +22,7 @@ import com.google.inject.Inject;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.RepositoryMetadataModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
@@ -34,14 +34,10 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
/**
* Tests for AtlasEntityStoreV1
*/
-@Guice(modules = RepositoryMetadataModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class AtlasEntityDefStoreV1Test {
@Inject
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
index 9b977db..9f7214c 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStoreTest.java
@@ -18,7 +18,7 @@
package org.apache.atlas.repository.store.graph;
import com.google.inject.Inject;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter;
@@ -28,12 +28,10 @@ import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.store.AtlasTypeDefStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
-import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -44,7 +42,7 @@ import java.util.List;
import static org.testng.Assert.*;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class AtlasTypeDefGraphStoreTest {
private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStoreTest.class);
@@ -52,11 +50,6 @@ public class AtlasTypeDefGraphStoreTest {
private
AtlasTypeDefStore typeDefStore;
- @AfterClass
- public void clear(){
- AtlasGraphProvider.cleanup();
- }
-
@Test(priority = 1)
public void testGet() {
try {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
index 9a11e08..9331e35 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasDeleteHandlerV1Test.java
@@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException;
import org.apache.atlas.RequestContextV1;
-import org.apache.atlas.TestOnlyModule;
import org.apache.atlas.TestUtils;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException;
@@ -39,7 +38,6 @@ import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.AtlasEdgeLabel;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
-import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasVertex;
@@ -63,7 +61,6 @@ import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import javax.inject.Inject;
@@ -81,7 +78,6 @@ import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-@Guice(modules = TestOnlyModule.class)
public abstract class AtlasDeleteHandlerV1Test {
@Inject
@@ -90,6 +86,7 @@ public abstract class AtlasDeleteHandlerV1Test {
@Inject
AtlasTypeDefStore typeDefStore;
+ @Inject
AtlasEntityStore entityStore;
@Inject
@@ -101,13 +98,9 @@ public abstract class AtlasDeleteHandlerV1Test {
private TypeSystem typeSystem = TypeSystem.getInstance();
- AtlasEntityChangeNotifier mockChangeNotifier = mock(AtlasEntityChangeNotifier.class);
-
-
@BeforeClass
public void setUp() throws Exception {
metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
- new GraphBackedSearchIndexer(typeRegistry);
final AtlasTypesDef deptTypesDef = TestUtilsV2.defineDeptEmployeeTypes();
typeDefStore.createTypesDef(deptTypesDef);
@@ -144,8 +137,6 @@ public abstract class AtlasDeleteHandlerV1Test {
@BeforeTest
public void init() throws Exception {
- DeleteHandlerV1 deleteHandler = getDeleteHandler(typeRegistry);
- entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier);
RequestContextV1.clear();
}
@@ -155,8 +146,6 @@ public abstract class AtlasDeleteHandlerV1Test {
AtlasGraphProvider.cleanup();
}
- abstract DeleteHandlerV1 getDeleteHandler(AtlasTypeRegistry typeRegistry);
-
@Test
public void testDeleteAndCreate() throws Exception {
init();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
index 1dd7276..44067b9 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
@@ -20,8 +20,8 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
+import org.apache.atlas.TestModules;
import org.apache.atlas.RequestContextV1;
-import org.apache.atlas.TestOnlyModule;
import org.apache.atlas.TestUtils;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.exception.AtlasBaseException;
@@ -83,7 +83,7 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class AtlasEntityStoreV1Test {
private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityStoreV1Test.class);
@@ -106,6 +106,8 @@ public class AtlasEntityStoreV1Test {
private AtlasEntityWithExtInfo tblEntity;
AtlasEntityChangeNotifier mockChangeNotifier = mock(AtlasEntityChangeNotifier.class);
+ @Inject
+ private EntityGraphMapper graphMapper;
@BeforeClass
@@ -137,7 +139,7 @@ public class AtlasEntityStoreV1Test {
@BeforeTest
public void init() throws Exception {
- entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier);
+ entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier, graphMapper);
RequestContextV1.clear();
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1Test.java
index 4403b12..407ebff 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/HardDeleteHandlerV1Test.java
@@ -20,6 +20,7 @@ package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity;
@@ -28,11 +29,11 @@ import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasVertex;
-import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.IStruct;
import org.apache.atlas.typesystem.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.ITypedStruct;
import org.testng.Assert;
+import org.testng.annotations.Guice;
import java.util.List;
import java.util.Map;
@@ -44,13 +45,9 @@ import static org.testng.Assert.assertNull;
import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertNotNull;
+@Guice(modules = TestModules.HardDeleteModule.class)
public class HardDeleteHandlerV1Test extends AtlasDeleteHandlerV1Test {
- @Override
- DeleteHandlerV1 getDeleteHandler(AtlasTypeRegistry typeRegistry) {
- return new HardDeleteHandlerV1(typeRegistry);
- }
-
@Override
protected void assertTableForTestDeleteReference(String tableId) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateHardDeleteV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateHardDeleteV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateHardDeleteV1Test.java
index 6a23807..d54adeb 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateHardDeleteV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateHardDeleteV1Test.java
@@ -18,10 +18,11 @@
package org.apache.atlas.repository.store.graph.v1;
import com.google.common.collect.ImmutableList;
+import org.apache.atlas.TestModules;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
-import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
+import org.testng.annotations.Guice;
import java.util.Map;
@@ -31,15 +32,10 @@ import static org.testng.Assert.assertTrue;
/**
* Inverse reference update test with {@link HardDeleteHandlerV1}
*/
+@Guice(modules = TestModules.HardDeleteModule.class)
public class InverseReferenceUpdateHardDeleteV1Test extends InverseReferenceUpdateV1Test {
@Override
- protected DeleteHandlerV1 getDeleteHandler(AtlasTypeRegistry typeRegistry) {
-
- return new HardDeleteHandlerV1(typeRegistry);
- }
-
- @Override
protected void verify_testInverseReferenceAutoUpdate_NonComposite_OneToMany(AtlasEntity jane) throws Exception {
// Max should have been removed from the subordinates list, leaving only John.
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateSoftDeleteV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateSoftDeleteV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateSoftDeleteV1Test.java
index ae6731c..884ab54 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateSoftDeleteV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateSoftDeleteV1Test.java
@@ -18,10 +18,11 @@
package org.apache.atlas.repository.store.graph.v1;
import com.google.common.collect.ImmutableList;
+import org.apache.atlas.TestModules;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
-import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil;
+import org.testng.annotations.Guice;
import java.util.Map;
@@ -32,15 +33,10 @@ import static org.testng.Assert.assertTrue;
/**
* Inverse reference update test with {@link SoftDeleteHandlerV1}
*/
+@Guice(modules = TestModules.SoftDeleteModule.class)
public class InverseReferenceUpdateSoftDeleteV1Test extends InverseReferenceUpdateV1Test {
@Override
- protected DeleteHandlerV1 getDeleteHandler(AtlasTypeRegistry typeRegistry) {
-
- return new SoftDeleteHandlerV1(typeRegistry);
- }
-
- @Override
protected void verify_testInverseReferenceAutoUpdate_NonComposite_OneToMany(AtlasEntity jane)
throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
index c90f716..e2a8010 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/InverseReferenceUpdateV1Test.java
@@ -20,7 +20,6 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.atlas.RequestContextV1;
-import org.apache.atlas.TestOnlyModule;
import org.apache.atlas.TestUtils;
import org.apache.atlas.TestUtilsV2;
import org.apache.atlas.model.instance.AtlasEntity;
@@ -31,7 +30,6 @@ import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
-import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.repository.store.bootstrap.AtlasTypeDefStoreInitializer;
import org.apache.atlas.repository.store.graph.AtlasEntityStore;
import org.apache.atlas.services.MetadataService;
@@ -42,7 +40,6 @@ import org.apache.atlas.type.AtlasTypeUtil;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import javax.inject.Inject;
@@ -52,7 +49,6 @@ import java.util.List;
import java.util.Map;
import static org.apache.atlas.TestUtils.NAME;
-import static org.mockito.Mockito.mock;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
@@ -61,35 +57,26 @@ import static org.testng.Assert.assertTrue;
* Test automatic inverse reference updating in V1 (V2?) code path.
*
*/
-@Guice(modules = TestOnlyModule.class)
public abstract class InverseReferenceUpdateV1Test {
-
@Inject
AtlasTypeRegistry typeRegistry;
@Inject
AtlasTypeDefStore typeDefStore;
+ @Inject
AtlasEntityStore entityStore;
@Inject
MetadataService metadataService;
- @Inject
- DeleteHandlerV1 deleteHandler;
-
private AtlasEntitiesWithExtInfo deptEntity;
- AtlasEntityChangeNotifier mockChangeNotifier = mock(AtlasEntityChangeNotifier.class);
-
protected Map<String, AtlasObjectId> nameIdMap = new HashMap<>();
- protected abstract DeleteHandlerV1 getDeleteHandler(AtlasTypeRegistry typeRegistry);
-
@BeforeClass
public void setUp() throws Exception {
metadataService = TestUtils.addSessionCleanupWrapper(metadataService);
- new GraphBackedSearchIndexer(typeRegistry);
AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(),
TestUtilsV2.defineInverseReferenceTestTypes()
@@ -104,8 +91,6 @@ public abstract class InverseReferenceUpdateV1Test {
}
deptEntity = TestUtilsV2.createDeptEg2();
- DeleteHandlerV1 deleteHandler = getDeleteHandler(typeRegistry);
- entityStore = new AtlasEntityStoreV1(deleteHandler, typeRegistry, mockChangeNotifier);
init();
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(deptEntity), false);
for (AtlasEntityHeader entityHeader : response.getCreatedEntities()) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java
index 8935faf..3f1ed03 100644
--- a/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java
+++ b/repository/src/test/java/org/apache/atlas/repository/store/graph/v1/SoftDeleteHandlerV1Test.java
@@ -19,6 +19,7 @@ package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.AtlasClient;
+import org.apache.atlas.TestModules;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader;
@@ -27,13 +28,13 @@ import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.services.MetadataService;
-import org.apache.atlas.type.AtlasTypeRegistry;
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.persistence.Id;
import org.testng.Assert;
+import org.testng.annotations.Guice;
import javax.inject.Inject;
import java.util.List;
@@ -44,17 +45,13 @@ import static org.apache.atlas.TestUtils.NAME;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
+@Guice(modules = TestModules.SoftDeleteModule.class)
public class SoftDeleteHandlerV1Test extends AtlasDeleteHandlerV1Test {
@Inject
MetadataService metadataService;
@Override
- DeleteHandlerV1 getDeleteHandler(final AtlasTypeRegistry typeRegistry) {
- return new SoftDeleteHandlerV1(typeRegistry);
- }
-
- @Override
protected void assertDeletedColumn(final AtlasEntity.AtlasEntityWithExtInfo tableInstance) throws AtlasBaseException {
final List<AtlasObjectId> columns = (List<AtlasObjectId>) tableInstance.getEntity().getAttribute(COLUMNS_ATTR_NAME);
Assert.assertEquals(columns.size(), 3);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java b/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
index 65cd938..6e3dabb 100755
--- a/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
@@ -21,10 +21,9 @@ package org.apache.atlas.repository.typestore;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.repository.RepositoryException;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
@@ -50,7 +49,7 @@ import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAt
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createStructTypeDef;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class GraphBackedTypeStoreTest {
private static final String DESCRIPTION = "_description";
@@ -70,7 +69,7 @@ public class GraphBackedTypeStoreTest {
@AfterClass
public void tearDown() throws Exception {
ts.reset();
- AtlasGraphProvider.cleanup();
+// AtlasGraphProvider.cleanup();
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheConfigurationTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheConfigurationTest.java b/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheConfigurationTest.java
deleted file mode 100644
index 6c5dcfc..0000000
--- a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheConfigurationTest.java
+++ /dev/null
@@ -1,42 +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.repository.typestore;
-
-import com.google.inject.Inject;
-import org.apache.atlas.typesystem.types.cache.TypeCache;
-import org.testng.Assert;
-import org.testng.annotations.Guice;
-import org.testng.annotations.Test;
-
-/**
- * Verify Guice can successfully instantiate and inject StoreBackTypeCache.
- * StoreBackedTypeCacheTestModule Guice module uses Atlas configuration
- * which has type cache implementation class set to {@link StoreBackedTypeCache}.
- */
-@Guice(modules = StoreBackedTypeCacheTestOnlyModule.class)
-public class StoreBackedTypeCacheConfigurationTest {
-
- @Inject
- private TypeCache typeCache;
-
- @Test
- public void testConfigureAsTypeCache() throws Exception {
- // Verify Guice successfully instantiated and injected StoreBackTypeCache
- Assert.assertTrue(typeCache instanceof StoreBackedTypeCache);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java b/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java
index 1608bd7..2ea63ff 100644
--- a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java
+++ b/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java
@@ -20,9 +20,8 @@ package org.apache.atlas.repository.typestore;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
-import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.typesystem.types.AttributeInfo;
import org.apache.atlas.typesystem.types.ClassType;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
@@ -46,7 +45,7 @@ import java.util.Map;
/**
* Unit test for {@link StoreBackedTypeCache}
*/
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class StoreBackedTypeCacheTest {
@Inject
@@ -87,7 +86,7 @@ public class StoreBackedTypeCacheTest {
@AfterClass
public void tearDown() throws Exception {
ts.reset();
- AtlasGraphProvider.cleanup();
+// AtlasGraphProvider.cleanup();
}
@BeforeMethod
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTestOnlyModule.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTestOnlyModule.java b/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTestOnlyModule.java
deleted file mode 100644
index 7fb0155..0000000
--- a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTestOnlyModule.java
+++ /dev/null
@@ -1,44 +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.repository.typestore;
-
-import org.apache.atlas.ApplicationProperties;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestOnlyModule;
-import org.apache.atlas.util.AtlasRepositoryConfiguration;
-import org.apache.commons.configuration.Configuration;
-
-
-/**
- * Guice module which sets TypeCache implementation class configuration property to {@link StoreBackedTypeCache}.
- *
- */
-public class StoreBackedTypeCacheTestOnlyModule extends TestOnlyModule {
-
- @Override
- protected Configuration getConfiguration() {
- try {
- Configuration configuration = ApplicationProperties.get();
- configuration.setProperty(AtlasRepositoryConfiguration.TYPE_CACHE_IMPLEMENTATION_PROPERTY,
- StoreBackedTypeCache.class.getName());
- return configuration;
- } catch (AtlasException e) {
- throw new RuntimeException(e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 7e2edd8..d8d8d91 100644
--- a/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/service/DefaultMetadataServiceTest.java
@@ -24,14 +24,15 @@ import com.google.inject.Inject;
import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.EntityAuditEvent;
+import org.apache.atlas.TestModules;
import org.apache.atlas.RequestContext;
-import org.apache.atlas.TestOnlyModule;
import org.apache.atlas.TestUtils;
import org.apache.atlas.discovery.graph.GraphBackedDiscoveryService;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.ChangedTypeDefs;
import org.apache.atlas.listener.EntityChangeListener;
import org.apache.atlas.listener.TypeDefChangeListener;
+import org.apache.atlas.model.legacy.EntityResult;
import org.apache.atlas.query.QueryParams;
import org.apache.atlas.repository.audit.EntityAuditRepository;
import org.apache.atlas.repository.audit.HBaseBasedAuditRepository;
@@ -85,7 +86,7 @@ import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeD
import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
import static org.testng.Assert.*;
-@Guice(modules = TestOnlyModule.class)
+@Guice(modules = TestModules.TestOnlyModule.class)
public class DefaultMetadataServiceTest {
@Inject
private MetadataService metadataService;
@@ -150,7 +151,7 @@ public class DefaultMetadataServiceTest {
AtlasGraphProvider.cleanup();
}
}
- private AtlasClient.EntityResult updateInstance(Referenceable entity) throws Exception {
+ private EntityResult updateInstance(Referenceable entity) throws Exception {
RequestContext.createContext();
ParamChecker.notNull(entity, "Entity");
ParamChecker.notNull(entity.getId(), "Entity");
@@ -296,7 +297,7 @@ public class DefaultMetadataServiceTest {
assertAuditEvents(id, EntityAuditEvent.EntityAuditAction.ENTITY_DELETE);
}
- private AtlasClient.EntityResult deleteEntities(String... guids) throws AtlasException {
+ private EntityResult deleteEntities(String... guids) throws AtlasException {
RequestContext.createContext();
return metadataService.deleteEntities(Arrays.asList(guids));
}
@@ -529,7 +530,7 @@ public class DefaultMetadataServiceTest {
assertEquals(actualColumns, updatedColNameList);
}
- private AtlasClient.EntityResult updateEntityPartial(String guid, Referenceable entity) throws AtlasException {
+ private EntityResult updateEntityPartial(String guid, Referenceable entity) throws AtlasException {
RequestContext.createContext();
return metadataService.updateEntityPartialByGuid(guid, entity).getEntityResult();
}
@@ -547,7 +548,7 @@ public class DefaultMetadataServiceTest {
put(COLUMNS_ATTR_NAME, columns);
}});
- AtlasClient.EntityResult entityResult = updateEntityPartial(tableId._getId(), tableUpdated);
+ EntityResult entityResult = updateEntityPartial(tableId._getId(), tableUpdated);
assertEquals(entityResult.getCreatedEntities().size(), 1); //col1 created
assertEquals(entityResult.getUpdateEntities().size(), 1); //table updated
assertEquals(entityResult.getUpdateEntities().get(0), tableId._getId());
@@ -1020,7 +1021,7 @@ public class DefaultMetadataServiceTest {
//Delete one column
String columnId = table1Columns.get(0).getId()._getId();
- AtlasClient.EntityResult entityResult = deleteEntities(columnId);
+ EntityResult entityResult = deleteEntities(columnId);
//column is deleted and table is updated
assertEquals(entityResult.getDeletedEntities().get(0), columnId);
assertEquals(entityResult.getUpdateEntities().get(0), table1Entity.getId()._getId());
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/service/StoreBackedTypeCacheMetadataServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/service/StoreBackedTypeCacheMetadataServiceTest.java b/repository/src/test/java/org/apache/atlas/service/StoreBackedTypeCacheMetadataServiceTest.java
index 217fc8d..5c37b9e 100644
--- a/repository/src/test/java/org/apache/atlas/service/StoreBackedTypeCacheMetadataServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/service/StoreBackedTypeCacheMetadataServiceTest.java
@@ -19,12 +19,11 @@ package org.apache.atlas.service;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import com.google.inject.Inject;
+import org.apache.atlas.TestModules;
import org.apache.atlas.TestUtils;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.typestore.ITypeStore;
import org.apache.atlas.repository.typestore.StoreBackedTypeCache;
-import org.apache.atlas.repository.typestore.StoreBackedTypeCacheTestOnlyModule;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.typesystem.TypesDef;
import org.apache.atlas.typesystem.json.TypesSerialization;
@@ -44,14 +43,17 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
+import javax.inject.Inject;
+
/**
* Verify MetadataService type operations trigger StoreBackedTypeCache to load non-cached types from the store.
* StoreBackedTypeCacheTestModule Guice module sets Atlas configuration
* to use {@link StoreBackedTypeCache} as the TypeCache implementation class.
*/
-@Guice(modules = StoreBackedTypeCacheTestOnlyModule.class)
-public class StoreBackedTypeCacheMetadataServiceTest {
+@Guice(modules = TestModules.StoreBackedTypeCacheTestModule.class)
+public class StoreBackedTypeCacheMetadataServiceTest
+{
@Inject
private MetadataService metadataService;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/java/org/apache/atlas/services/EntityDiscoveryServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/services/EntityDiscoveryServiceTest.java b/repository/src/test/java/org/apache/atlas/services/EntityDiscoveryServiceTest.java
index d503ef7..d490083 100644
--- a/repository/src/test/java/org/apache/atlas/services/EntityDiscoveryServiceTest.java
+++ b/repository/src/test/java/org/apache/atlas/services/EntityDiscoveryServiceTest.java
@@ -17,7 +17,7 @@
*/
package org.apache.atlas.services;
-import org.apache.atlas.TestOnlyModule;
+import org.apache.atlas.TestModules.TestOnlyModule;
import org.apache.atlas.discovery.EntityDiscoveryService;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasEntityDef;
@@ -28,7 +28,6 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
-
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala
----------------------------------------------------------------------
diff --git a/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala b/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala
index 60464be..a948d16 100755
--- a/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala
+++ b/repository/src/test/scala/org/apache/atlas/query/GremlinTest.scala
@@ -41,7 +41,7 @@ class GremlinTest extends BaseGremlinTest {
@BeforeClass
def beforeAll() {
TypeSystem.getInstance().reset()
- var repo = new GraphBackedMetadataRepository(null)
+ var repo = new GraphBackedMetadataRepository(null, new AtlasGraphProvider().get())
TestUtils.setupGraphProvider(repo)
//force graph to be initialized first
AtlasGraphProvider.getGraphInstance()
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala
----------------------------------------------------------------------
diff --git a/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala b/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala
index cc22865..880a0c6 100755
--- a/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala
+++ b/repository/src/test/scala/org/apache/atlas/query/GremlinTest2.scala
@@ -43,7 +43,7 @@ class GremlinTest2 extends BaseGremlinTest {
def beforeAll() {
TypeSystem.getInstance().reset()
QueryTestsUtils.setupTypes
- var repo = new GraphBackedMetadataRepository(null);
+ var repo = new GraphBackedMetadataRepository(null, null);
gp = new DefaultGraphPersistenceStrategy(repo)
g = QueryTestsUtils.setupTestGraph(repo)
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala
----------------------------------------------------------------------
diff --git a/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala b/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala
index 3a3c967..b01cbf8 100755
--- a/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala
+++ b/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala
@@ -43,7 +43,7 @@ class LineageQueryTest extends BaseGremlinTest {
@BeforeClass
def beforeAll() {
TypeSystem.getInstance().reset()
- var repo = new GraphBackedMetadataRepository(null);
+ var repo = new GraphBackedMetadataRepository(null, new AtlasGraphProvider().get());
TestUtils.setupGraphProvider(repo);
//force graph to be initialized first
AtlasGraphProvider.getGraphInstance();
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/server-api/pom.xml
----------------------------------------------------------------------
diff --git a/server-api/pom.xml b/server-api/pom.xml
index 278184f..7761a71 100644
--- a/server-api/pom.xml
+++ b/server-api/pom.xml
@@ -37,11 +37,6 @@
</dependency>
<dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-typesystem</artifactId>
</dependency>
@@ -60,58 +55,5 @@
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-client</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- </dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>aspectj-maven-plugin</artifactId>
- <configuration>
- <complianceLevel>1.7</complianceLevel>
- <showWeaveInfo>true</showWeaveInfo>
- <verbose>true</verbose>
- <forceAjcCompile>true</forceAjcCompile>
- <includes>
- <include>**/*.java</include>
- <include>**/*.aj</include>
- </includes>
- </configuration>
- <executions>
- <execution>
- <id>compile_with_aspectj</id>
- <goals>
- <goal>compile</goal>
- </goals>
- <configuration>
- <aspectDirectory>src/main/java</aspectDirectory>
- </configuration>
- </execution>
- <execution>
- <id>test-compile_with_aspectj</id>
- <goals>
- <goal>test-compile</goal>
- </goals>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>${aspectj.runtime.version}</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjtools</artifactId>
- <version>${aspectj.runtime.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/server-api/src/main/java/org/apache/atlas/aspect/AtlasAspect.java
----------------------------------------------------------------------
diff --git a/server-api/src/main/java/org/apache/atlas/aspect/AtlasAspect.java b/server-api/src/main/java/org/apache/atlas/aspect/AtlasAspect.java
deleted file mode 100644
index 3579dd2..0000000
--- a/server-api/src/main/java/org/apache/atlas/aspect/AtlasAspect.java
+++ /dev/null
@@ -1,68 +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.aspect;
-
-import org.apache.atlas.RequestContext;
-import org.apache.atlas.metrics.Metrics;
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.Signature;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Arrays;
-import java.util.List;
-
-@Aspect
-public class AtlasAspect {
-
- public static final Logger LOG = LoggerFactory.getLogger(AtlasAspect.class);
-
- @Around("@annotation(org.apache.atlas.aspect.Monitored) && execution(* *(..))")
- public Object collectMetricsForMonitored(ProceedingJoinPoint joinPoint) throws Throwable {
- Signature methodSign = joinPoint.getSignature();
- Metrics metrics = RequestContext.getMetrics();
- String metricName = methodSign.getDeclaringType().getSimpleName() + "." + methodSign.getName();
- long start = System.currentTimeMillis();
-
- try {
- Object response = joinPoint.proceed();
- return response;
- } finally {
- metrics.record(metricName, (System.currentTimeMillis() - start));
- }
- }
-
- @Around("@annotation(org.apache.atlas.aspect.Loggable) && execution(* *(..))")
- public Object logAroundLoggable(ProceedingJoinPoint joinPoint) throws Throwable {
- Signature methodSign = joinPoint.getSignature();
- String methodName = methodSign.getDeclaringType().getSimpleName() + "." + methodSign.getName();
-
- if (LOG.isDebugEnabled()) {
- LOG.debug(String.format("==> %s(%s)", methodName, Arrays.toString(joinPoint.getArgs())));
- }
- Object response = joinPoint.proceed();
- if (LOG.isDebugEnabled()) {
- LOG.debug(String.format("<== %s(%s): %s", methodName, Arrays.toString(joinPoint.getArgs()),
- response instanceof List ? ((List)response).size() : response));
- }
- return response;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 31ef7b5..7fb3d3f 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
@@ -18,11 +18,11 @@
package org.apache.atlas.services;
-import org.apache.atlas.AtlasClient;
import org.apache.atlas.AtlasException;
import org.apache.atlas.CreateUpdateEntitiesResult;
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.ITypedReferenceableInstance;
import org.apache.atlas.typesystem.ITypedStruct;
@@ -267,7 +267,7 @@ public interface MetadataService {
* @return List of guids for deleted entities
* @throws AtlasException
*/
- AtlasClient.EntityResult deleteEntities(List<String> guids) throws AtlasException;
+ EntityResult deleteEntities(List<String> guids) throws AtlasException;
/**
* Register a listener for entity change.
@@ -292,8 +292,8 @@ public interface MetadataService {
* @return List of guids for deleted entities (including their composite references)
* @throws AtlasException
*/
- AtlasClient.EntityResult deleteEntityByUniqueAttribute(String typeName, String uniqueAttributeName,
- String attrValue) throws AtlasException;
+ EntityResult deleteEntityByUniqueAttribute(String typeName, String uniqueAttributeName,
+ String attrValue) throws AtlasException;
/**
* Returns entity audit events for entity id in the decreasing order of timestamp
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
index c853ec6..262f784 100755
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
+++ b/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
@@ -20,7 +20,6 @@ package org.apache.atlas.typesystem.types;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-
import org.apache.atlas.AtlasException;
import org.apache.atlas.classification.InterfaceAudience;
import org.apache.atlas.typesystem.TypesDef;
@@ -31,6 +30,7 @@ import org.apache.atlas.typesystem.types.cache.TypeCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.inject.Singleton;
import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -41,8 +41,6 @@ import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
-import javax.inject.Singleton;
-
@Singleton
@InterfaceAudience.Private
@Deprecated
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystemProvider.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystemProvider.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystemProvider.java
deleted file mode 100644
index 4e1cd36..0000000
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystemProvider.java
+++ /dev/null
@@ -1,28 +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.typesystem.types;
-
-import com.google.inject.Provider;
-
-public class TypeSystemProvider implements Provider<TypeSystem> {
- @Override
- public TypeSystem get() {
- return TypeSystem.getInstance();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/typesystem/src/main/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCache.java
----------------------------------------------------------------------
diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCache.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCache.java
index ce750af..0d86474 100644
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCache.java
+++ b/typesystem/src/main/java/org/apache/atlas/typesystem/types/cache/DefaultTypeCache.java
@@ -17,8 +17,8 @@
*/
package org.apache.atlas.typesystem.types.cache;
-import com.google.inject.Singleton;
import org.apache.atlas.AtlasException;
+import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
import org.apache.atlas.typesystem.types.ClassType;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
import org.apache.atlas.typesystem.types.EnumType;
@@ -29,7 +29,9 @@ import org.apache.atlas.typesystem.types.TraitType;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -41,8 +43,10 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* Caches the types in-memory within the same process space.
*/
-@Singleton
@SuppressWarnings("rawtypes")
+@Singleton
+@Component
+@ConditionalOnAtlasProperty(property = "atlas.TypeCache.impl", isDefault = true)
public class DefaultTypeCache implements TypeCache {
private static final Logger LOG = LoggerFactory.getLogger(DefaultTypeCache.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/typesystem/src/main/resources/atlas-log4j.xml
----------------------------------------------------------------------
diff --git a/typesystem/src/main/resources/atlas-log4j.xml b/typesystem/src/main/resources/atlas-log4j.xml
index 8312657..c30403e 100755
--- a/typesystem/src/main/resources/atlas-log4j.xml
+++ b/typesystem/src/main/resources/atlas-log4j.xml
@@ -75,6 +75,21 @@
<appender-ref ref="console"/>
</logger>
+ <logger name="org.springframework" additivity="false">
+ <level value="warn"/>
+ <appender-ref ref="console"/>
+ </logger>
+
+ <logger name="org.eclipse" additivity="false">
+ <level value="warn"/>
+ <appender-ref ref="console"/>
+ </logger>
+
+ <logger name="com.sun.jersey" additivity="false">
+ <level value="warn"/>
+ <appender-ref ref="console"/>
+ </logger>
+
<logger name="AUDIT" additivity="false">
<level value="info"/>
<appender-ref ref="console"/>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/pom.xml
----------------------------------------------------------------------
diff --git a/webapp/pom.xml b/webapp/pom.xml
index 045ccdb..4132912 100755
--- a/webapp/pom.xml
+++ b/webapp/pom.xml
@@ -172,11 +172,6 @@
<artifactId>atlas-catalog</artifactId>
</dependency>
- <dependency>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-graphdb-impls</artifactId>
- <type>pom</type>
- </dependency>
<!-- Zookeeper, curator -->
<dependency>
<groupId>org.apache.curator</groupId>
@@ -276,18 +271,29 @@
</dependency>
<dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ <version>${guice.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>com.google.inject.extensions</groupId>
- <artifactId>guice-servlet</artifactId>
+ <artifactId>guice-throwingproviders</artifactId>
+ <version>${guice.version}</version>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>com.google.code.gson</groupId>
- <artifactId>gson</artifactId>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-multibindings</artifactId>
+ <version>${guice.version}</version>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>com.sun.jersey.contribs</groupId>
- <artifactId>jersey-guice</artifactId>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
</dependency>
<dependency>
@@ -311,55 +317,94 @@
</dependency>
<dependency>
- <groupId>com.google.inject</groupId>
- <artifactId>guice</artifactId>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${spring.version}</version>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <version>${spring.version}</version>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
- <version>${spring.version}</version>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>spring-security-core</artifactId>
- <version>${spring.security.version}</version>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>spring-security-web</artifactId>
- <version>${spring.security.version}</version>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>spring-security-config</artifactId>
- <version>${spring.security.version}</version>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-ldap</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.ldap</groupId>
+ <artifactId>spring-ldap-core</artifactId>
</dependency>
+ <!-- Jersey + Spring -->
+ <dependency>
+ <groupId>com.sun.jersey.contribs</groupId>
+ <artifactId>jersey-spring</artifactId>
+ <version>1.8</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>spring-security-ldap</artifactId>
- <version>${spring.security.version}</version>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
</dependency>
+ <!-- Required for Spring configuration processing -->
<dependency>
- <groupId>org.springframework.ldap</groupId>
- <artifactId>spring-ldap-core</artifactId>
- <version>${spring-ldap-core.version}</version>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.8.9</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>1.8.9</version>
</dependency>
<dependency>
<groupId>org.apache.atlas</groupId>
@@ -367,11 +412,6 @@
<type>war</type>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- <version>${javax.servlet.version}</version>
- </dependency>
- <dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
@@ -390,7 +430,8 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
- <dependency>
+
+ <dependency>
<groupId>org.apache.atlas</groupId>
<artifactId>atlas-repository</artifactId>
<classifier>tests</classifier>
@@ -414,10 +455,11 @@
</exclusion>
</exclusions>
</dependency>
-
<dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
+ <groupId>org.apache.atlas</groupId>
+ <artifactId>atlas-repository</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
</dependency>
<dependency>
@@ -644,46 +686,6 @@
</plugin>
<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>aspectj-maven-plugin</artifactId>
- <configuration>
- <complianceLevel>1.7</complianceLevel>
- <includes>
- <include>**/*.java</include>
- <include>**/*.aj</include>
- </includes>
- <XaddSerialVersionUID>true</XaddSerialVersionUID>
- <showWeaveInfo>true</showWeaveInfo>
- <aspectLibraries>
- <aspectLibrary>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-server-api</artifactId>
- </aspectLibrary>
- </aspectLibraries>
- </configuration>
- <executions>
- <execution>
- <id>compile_with_aspectj</id>
- <goals>
- <goal>compile</goal>
- </goals>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjtools</artifactId>
- <version>${aspectj.runtime.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.atlas</groupId>
- <artifactId>atlas-server-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </plugin>
- <plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<configuration>
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/Atlas.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/Atlas.java b/webapp/src/main/java/org/apache/atlas/Atlas.java
index 14c43cc..e29254b 100755
--- a/webapp/src/main/java/org/apache/atlas/Atlas.java
+++ b/webapp/src/main/java/org/apache/atlas/Atlas.java
@@ -19,9 +19,7 @@
package org.apache.atlas;
import org.apache.atlas.security.SecurityProperties;
-import org.apache.atlas.setup.SetupException;
import org.apache.atlas.web.service.EmbeddedServer;
-import org.apache.atlas.web.setup.AtlasSetup;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
@@ -33,6 +31,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.util.ShutdownHookManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.bridge.SLF4JBridgeHandler;
import java.util.Iterator;
@@ -48,7 +47,7 @@ public final class Atlas {
private static final String ATLAS_LOG_DIR = "atlas.log.dir";
public static final String ATLAS_SERVER_HTTPS_PORT = "atlas.server.https.port";
public static final String ATLAS_SERVER_HTTP_PORT = "atlas.server.http.port";
- public static final String ATLAS_SERVER_RUN_SETUP_KEY = "atlas.server.run.setup.on.start";
+
private static EmbeddedServer server;
@@ -111,28 +110,12 @@ public final class Atlas {
final boolean enableTLS = isTLSEnabled(enableTLSFlag, appPort);
configuration.setProperty(SecurityProperties.TLS_ENABLED, String.valueOf(enableTLS));
- runSetupIfRequired(configuration);
showStartupInfo(buildConfiguration, enableTLS, appPort);
server = EmbeddedServer.newServer(appPort, appPath, enableTLS);
- server.start();
- }
+ installLogBridge();
- private static void runSetupIfRequired(Configuration configuration) throws SetupException {
- boolean shouldRunSetup = configuration.getBoolean(ATLAS_SERVER_RUN_SETUP_KEY, false);
- if (shouldRunSetup) {
- LOG.warn("Running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
- AtlasSetup atlasSetup = new AtlasSetup();
- try {
- atlasSetup.run();
- } catch (SetupException se) {
- LOG.error("Failed running setup. Will not start the server.");
- throw se;
- }
- LOG.warn("Finished running setup.");
- } else {
- LOG.info("Not running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
- }
+ server.start();
}
private static void setApplicationHome() {
@@ -204,4 +187,14 @@ public final class Atlas {
LOG.info("Server starting with TLS ? {} on port {}", enableTLS, appPort);
LOG.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
}
+
+ private static void installLogBridge() {
+ // Optionally remove existing handlers attached to j.u.l root logger
+ SLF4JBridgeHandler.removeHandlersForRootLogger(); // (since SLF4J 1.6.5)
+
+ // add SLF4JBridgeHandler to j.u.l's root logger, should be done once during
+ // the initialization phase of your application
+ SLF4JBridgeHandler.install();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java b/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
index f3af37d..6eadc96 100644
--- a/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
+++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationEntityChangeListener.java
@@ -18,7 +18,6 @@
package org.apache.atlas.notification;
import com.google.common.annotations.VisibleForTesting;
-import com.google.inject.Inject;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
import org.apache.atlas.listener.EntityChangeListener;
@@ -35,7 +34,9 @@ import org.apache.atlas.typesystem.types.TypeSystem;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.configuration.Configuration;
+import org.springframework.stereotype.Component;
+import javax.inject.Inject;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -48,6 +49,7 @@ import java.util.Set;
/**
* Listen to the repository for entity changes and produce entity change notifications.
*/
+@Component
public class NotificationEntityChangeListener implements EntityChangeListener {
private final NotificationInterface notificationInterface;
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/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 e6d5697..2f8245d 100644
--- a/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
+++ b/webapp/src/main/java/org/apache/atlas/notification/NotificationHookConsumer.java
@@ -19,7 +19,6 @@ package org.apache.atlas.notification;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import com.google.inject.Singleton;
import kafka.consumer.ConsumerTimeoutException;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException;
@@ -45,6 +44,8 @@ import org.apache.atlas.web.util.DateTimeHelper;
import org.apache.commons.configuration.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -68,7 +69,8 @@ import static org.apache.atlas.notification.hook.HookNotification.HookNotificati
/**
* Consumer of notifications from hooks e.g., hive hook etc.
*/
-@Singleton
+@Component
+@Order(4)
public class NotificationHookConsumer implements Service, ActiveStateChangeHandler {
private static final Logger LOG = LoggerFactory.getLogger(NotificationHookConsumer.class);
private static final String LOCALHOST = "localhost";
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java b/webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java
index 9042e88..98bd381 100644
--- a/webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java
+++ b/webapp/src/main/java/org/apache/atlas/web/errors/AllExceptionMapper.java
@@ -20,20 +20,19 @@ package org.apache.atlas.web.errors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
-import java.util.concurrent.ThreadLocalRandom;
-
-import javax.inject.Singleton;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
+import java.util.concurrent.ThreadLocalRandom;
/**
* Exception mapper for Jersey.
* @param <E>
*/
@Provider
-@Singleton
+@Component
public class AllExceptionMapper implements ExceptionMapper<Exception> {
private static final Logger LOGGER = LoggerFactory.getLogger(AllExceptionMapper.class);
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java b/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
index ec1767c..f4b8d67 100755
--- a/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
+++ b/webapp/src/main/java/org/apache/atlas/web/errors/AtlasBaseExceptionMapper.java
@@ -21,8 +21,8 @@ package org.apache.atlas.web.errors;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.type.AtlasType;
+import org.springframework.stereotype.Component;
-import javax.inject.Singleton;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
@@ -34,7 +34,7 @@ import java.util.concurrent.ThreadLocalRandom;
* AtlasBaseException mapper for Jersey.
*/
@Provider
-@Singleton
+@Component
public class AtlasBaseExceptionMapper implements ExceptionMapper<AtlasBaseException> {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java b/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
index 9f97bb2..a33d8d7 100644
--- a/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
+++ b/webapp/src/main/java/org/apache/atlas/web/errors/NotFoundExceptionMapper.java
@@ -18,15 +18,15 @@
package org.apache.atlas.web.errors;
import org.apache.atlas.typesystem.exception.NotFoundException;
+import org.springframework.stereotype.Component;
-import javax.inject.Singleton;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import java.util.concurrent.ThreadLocalRandom;
@Provider
-@Singleton
+@Component
public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> {
@Override
public Response toResponse(NotFoundException e) {
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/35e5828f/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
index ecc67a7..36f2688 100644
--- a/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
+++ b/webapp/src/main/java/org/apache/atlas/web/filters/ActiveServerFilter.java
@@ -23,9 +23,9 @@ import org.apache.atlas.web.service.ServiceState;
import org.apache.hadoop.http.HtmlQuoting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
import javax.inject.Inject;
-import javax.inject.Singleton;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -46,7 +46,7 @@ import java.io.IOException;
* an error SERVICE_UNAVAILABLE. Identification of this state is carried out using
* {@link ServiceState} and {@link ActiveInstanceState}.
*/
-@Singleton
+@Component
public class ActiveServerFilter implements Filter {
private static final Logger LOG = LoggerFactory.getLogger(ActiveServerFilter.class);