http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/test/java/org/apache/atlas/catalog/query/AtlasEntityQueryTest.java ---------------------------------------------------------------------- diff --git a/catalog/src/test/java/org/apache/atlas/catalog/query/AtlasEntityQueryTest.java b/catalog/src/test/java/org/apache/atlas/catalog/query/AtlasEntityQueryTest.java deleted file mode 100644 index 528c83a..0000000 --- a/catalog/src/test/java/org/apache/atlas/catalog/query/AtlasEntityQueryTest.java +++ /dev/null @@ -1,277 +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.catalog.query; - -import com.thinkaurelius.titan.core.TitanGraph; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.gremlin.java.GremlinPipeline; -import com.tinkerpop.pipes.Pipe; - -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.VertexWrapper; -import org.apache.atlas.catalog.definition.ResourceDefinition; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.easymock.Capture; -import org.testng.annotations.Test; - -import java.util.*; - -import static org.easymock.EasyMock.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -/** - * Unit tests for AtlasEntityQuery. - */ -@SuppressWarnings("unchecked") -public class AtlasEntityQueryTest { - //todo: add tests for instance query and getInitialPipeline() - @Test - public void testExecute_Collection() throws Exception { - AtlasGraph graph = createStrictMock(AtlasGraph.class); - QueryExpression expression = createStrictMock(QueryExpression.class); - ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class); - Request request = createStrictMock(Request.class); - GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class); - Pipe queryPipe = createStrictMock(Pipe.class); - Pipe expressionPipe = createStrictMock(Pipe.class); - Pipe notDeletedPipe = createStrictMock(Pipe.class); - GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class); - Vertex vertex1 = createStrictMock(Vertex.class); - VertexWrapper vertex1Wrapper = createStrictMock(VertexWrapper.class); - - List<Vertex> results = new ArrayList<>(); - results.add(vertex1); - - Map<String, Object> vertex1PropertyMap = new HashMap<>(); - vertex1PropertyMap.put("prop1", "prop1.value1"); - vertex1PropertyMap.put("prop2", "prop2.value1"); - - Map<String, Object> filteredVertex1PropertyMap = new HashMap<>(); - filteredVertex1PropertyMap.put("prop1", "prop1.value1"); - - // mock expectations - expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline); - expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline); - expect(initialPipeline.as("root")).andReturn(rootPipeline); - expect(expression.asPipe()).andReturn(expressionPipe); - expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline); - expect(expressionPipeline.back("root")).andReturn(rootPipeline); - expect(rootPipeline.toList()).andReturn(results); - graph.commit(); - expect(vertex1Wrapper.getPropertyMap()).andReturn(vertex1PropertyMap); - expect(resourceDefinition.filterProperties(request, vertex1PropertyMap)).andReturn(filteredVertex1PropertyMap); - expect(resourceDefinition.resolveHref(filteredVertex1PropertyMap)).andReturn("/foo/bar"); - expect(request.getCardinality()).andReturn(Request.Cardinality.COLLECTION); - - replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, - notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, - vertex1, vertex1Wrapper); - // end mock expectations - - AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, - initialPipeline, queryPipe, notDeletedPipe, graph, vertex1Wrapper); - - // invoke method being tested - Collection<Map<String, Object>> queryResults = query.execute(); - - assertEquals(queryResults.size(), 1); - Map<String, Object> queryResultMap = queryResults.iterator().next(); - assertEquals(queryResultMap.size(), 2); - assertEquals(queryResultMap.get("prop1"), "prop1.value1"); - assertEquals(queryResultMap.get("href"), "/foo/bar"); - - verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, - notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, - vertex1, vertex1Wrapper); - } - - @Test - public void testExecute_Collection_rollbackOnException() throws Exception { - AtlasGraph graph = createStrictMock(AtlasGraph.class); - QueryExpression expression = createStrictMock(QueryExpression.class); - ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class); - Request request = createStrictMock(Request.class); - GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class); - Pipe queryPipe = createStrictMock(Pipe.class); - Pipe expressionPipe = createStrictMock(Pipe.class); - Pipe notDeletedPipe = createStrictMock(Pipe.class); - GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class); - - // mock expectations - expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline); - expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline); - expect(initialPipeline.as("root")).andReturn(rootPipeline); - expect(expression.asPipe()).andReturn(expressionPipe); - expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline); - expect(expressionPipeline.back("root")).andReturn(rootPipeline); - expect(rootPipeline.toList()).andThrow(new RuntimeException("something bad happened")); - graph.rollback(); - - replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, - notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline); - // end mock expectations - - AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, - initialPipeline, queryPipe, notDeletedPipe, graph, null); - - try { - // invoke method being tested - query.execute(); - fail("expected exception"); - } catch (RuntimeException e) { - assertEquals(e.getMessage(), "something bad happened"); - } - - verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, - notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline); - } - - @Test - public void testExecute_Collection_update() throws Exception { - AtlasGraph graph = createStrictMock(AtlasGraph.class); - QueryExpression expression = createStrictMock(QueryExpression.class); - ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class); - Request request = createStrictMock(Request.class); - GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class); - Pipe queryPipe = createStrictMock(Pipe.class); - Pipe expressionPipe = createStrictMock(Pipe.class); - Pipe notDeletedPipe = createStrictMock(Pipe.class); - GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class); - GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class); - Vertex vertex1 = createStrictMock(Vertex.class); - VertexWrapper vertex1Wrapper = createStrictMock(VertexWrapper.class); - Capture<Long> modifiedTimestampCapture = newCapture(); - - List<Vertex> results = new ArrayList<>(); - results.add(vertex1); - - Map<String, Object> vertex1PropertyMap = new HashMap<>(); - vertex1PropertyMap.put("prop1", "prop1.value1"); - vertex1PropertyMap.put("prop2", "prop2.value1"); - - Map<String, Object> filteredVertex1PropertyMap = new HashMap<>(); - filteredVertex1PropertyMap.put("prop1", "prop1.value1"); - - Map<String, Object> updateProperties = new HashMap<>(); - updateProperties.put("prop3", "newValue"); - - // mock expectations - expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline); - expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline); - expect(initialPipeline.as("root")).andReturn(rootPipeline); - expect(expression.asPipe()).andReturn(expressionPipe); - expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline); - expect(expressionPipeline.back("root")).andReturn(rootPipeline); - expect(rootPipeline.toList()).andReturn(results); - graph.commit(); - vertex1Wrapper.setProperty("prop3", "newValue"); - vertex1Wrapper.setProperty(eq(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY), capture(modifiedTimestampCapture)); - expect(vertex1Wrapper.getPropertyMap()).andReturn(vertex1PropertyMap); - expect(resourceDefinition.filterProperties(request, vertex1PropertyMap)).andReturn(filteredVertex1PropertyMap); - expect(resourceDefinition.resolveHref(filteredVertex1PropertyMap)).andReturn("/foo/bar"); - expect(request.getCardinality()).andReturn(Request.Cardinality.COLLECTION); - - replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, - notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, - vertex1, vertex1Wrapper); - // end mock expectations - - AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, - initialPipeline, queryPipe, notDeletedPipe, graph, vertex1Wrapper); - - long startTime = System.currentTimeMillis(); - // invoke method being tested - Collection<Map<String, Object>> queryResults = query.execute(updateProperties); - long endTime = System.currentTimeMillis(); - - assertEquals(queryResults.size(), 1); - Map<String, Object> queryResultMap = queryResults.iterator().next(); - assertEquals(queryResultMap.size(), 2); - assertEquals(queryResultMap.get("prop1"), "prop1.value1"); - assertEquals(queryResultMap.get("href"), "/foo/bar"); - - long modifiedTimestamp = modifiedTimestampCapture.getValue(); - assertTrue(modifiedTimestamp >= startTime && modifiedTimestamp <= endTime); - - verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, - notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, - vertex1, vertex1Wrapper); - } - - private class TestAtlasEntityQuery extends AtlasEntityQuery { - private final GremlinPipeline initialPipeline; - private final Pipe queryPipe; - private final Pipe notDeletedPipe; - private final AtlasGraph graph; - private final VertexWrapper vWrapper; - - public TestAtlasEntityQuery(QueryExpression queryExpression, - ResourceDefinition resourceDefinition, - Request request, - GremlinPipeline initialPipeline, - Pipe queryPipe, - Pipe notDeletedPipe, - AtlasGraph graph, - VertexWrapper vWrapper) { - - super(queryExpression, resourceDefinition, request); - this.initialPipeline = initialPipeline; - this.queryPipe = queryPipe; - this.notDeletedPipe = notDeletedPipe; - this.graph = graph; - this.vWrapper = vWrapper; - } - - @Override - protected GremlinPipeline getRootVertexPipeline() { - return initialPipeline; - } - - @Override - protected Pipe getQueryPipe() { - return queryPipe; - } - - @Override - protected Pipe getNotDeletedPipe() { - return notDeletedPipe; - } - - @Override - protected AtlasGraph getGraph() { - return graph; - } - - @Override - protected VertexWrapper wrapVertex(Vertex v) { - return vWrapper; - } - } -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/catalog/src/test/java/org/apache/atlas/catalog/query/QueryFactoryTest.java ---------------------------------------------------------------------- diff --git a/catalog/src/test/java/org/apache/atlas/catalog/query/QueryFactoryTest.java b/catalog/src/test/java/org/apache/atlas/catalog/query/QueryFactoryTest.java deleted file mode 100644 index 36cb6dc..0000000 --- a/catalog/src/test/java/org/apache/atlas/catalog/query/QueryFactoryTest.java +++ /dev/null @@ -1,209 +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.catalog.query; - -import org.apache.atlas.catalog.CollectionRequest; -import org.apache.atlas.catalog.InstanceRequest; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.TermPath; -import org.apache.atlas.catalog.definition.EntityResourceDefinition; -import org.apache.atlas.catalog.definition.EntityTagResourceDefinition; -import org.testng.annotations.Test; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.testng.Assert.assertEquals; - -/** - * Unit tests for QueryFactory. - */ -public class QueryFactoryTest { - @Test - public void testCreateTaxonomyQuery() throws Exception { - Map<String, Object> requestProps = new HashMap<>(); - requestProps.put("name", "test_taxonomy"); - Request request = new InstanceRequest(requestProps); - - QueryFactory factory = new QueryFactory(); - AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), TermQueryExpression.class); - assertEquals(queryExpression.getField(), "name"); - assertEquals(queryExpression.getExpectedValue(), "test_taxonomy"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy"); - } - - @Test - public void testCreateTermQuery() throws Exception { - Map<String, Object> requestProps = new HashMap<>(); - requestProps.put("name", "test_taxonomy.term1"); - requestProps.put("termPath", new TermPath("test_taxonomy.term1")); - Request request = new InstanceRequest(requestProps); - - - - QueryFactory factory = new QueryFactory(); - AtlasTermQuery query = (AtlasTermQuery) factory.createTermQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), TermQueryExpression.class); - assertEquals(queryExpression.getField(), "name"); - assertEquals(queryExpression.getExpectedValue(), "test_taxonomy.term1"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Term"); - } - - @Test - public void testCreateEntityQuery() throws Exception { - Map<String, Object> requestProps = new HashMap<>(); - requestProps.put("id", "foo"); - Request request = new InstanceRequest(requestProps); - - QueryFactory factory = new QueryFactory(); - AtlasEntityQuery query = (AtlasEntityQuery) factory.createEntityQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), TermQueryExpression.class); - assertEquals(queryExpression.getField(), "id"); - assertEquals(queryExpression.getExpectedValue(), "foo"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getClass(), EntityResourceDefinition.class); - } - - @Test - public void testCreateEntityTagQuery() throws Exception { - Map<String, Object> requestProps = new HashMap<>(); - requestProps.put("id", "entity_id"); - requestProps.put("name", "test_taxonomy.term1"); - Request request = new InstanceRequest(requestProps); - - QueryFactory factory = new QueryFactory(); - AtlasEntityTagQuery query = (AtlasEntityTagQuery) factory.createEntityTagQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), TermQueryExpression.class); - assertEquals(queryExpression.getField(), "name"); - assertEquals(queryExpression.getExpectedValue(), "test_taxonomy.term1"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getClass(), EntityTagResourceDefinition.class); - } - - @Test - public void testCollectionQuery_TermQuery() throws Exception { - String queryString = "name:test_taxonomy"; - Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - - QueryFactory factory = new QueryFactory(); - AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), TermQueryExpression.class); - assertEquals(queryExpression.getField(), "name"); - assertEquals(queryExpression.getExpectedValue(), "test_taxonomy"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy"); - } - - @Test - public void testCollectionQuery_PrefixQuery() throws Exception { - String queryString = "name:t*"; - Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - - QueryFactory factory = new QueryFactory(); - AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), PrefixQueryExpression.class); - assertEquals(queryExpression.getField(), "name"); - assertEquals(queryExpression.getExpectedValue(), "t"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy"); - } - - @Test - public void testCollectionQuery_TermRangeQuery() throws Exception { - String queryString = "creation_time:[2013-01-01:07:29:00 TO 2017-01-02]"; - Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - - QueryFactory factory = new QueryFactory(); - AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), TermRangeQueryExpression.class); - assertEquals(queryExpression.getField(), "creation_time"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy"); - } - - @Test - public void testCollectionQuery_WildcardQuery() throws Exception { - String queryString = "name:ta?onomy"; - Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - - QueryFactory factory = new QueryFactory(); - AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), WildcardQueryExpression.class); - assertEquals(queryExpression.getField(), "name"); - assertEquals(queryExpression.getExpectedValue(), "ta?onomy"); - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy"); - } - - @Test - public void testCollectionQuery_BooleanQuery() throws Exception { - String queryString = "name:foo OR name:bar"; - Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - - QueryFactory factory = new QueryFactory(); - AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), BooleanQueryExpression.class); - - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy"); - } - - @Test - public void testCollectionQuery_ProjectionQuery() throws Exception { - String queryString = "relation/name:foo"; - Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - - QueryFactory factory = new QueryFactory(); - AtlasTaxonomyQuery query = (AtlasTaxonomyQuery) factory.createTaxonomyQuery(request); - - QueryExpression queryExpression = query.getQueryExpression(); - assertEquals(queryExpression.getClass(), ProjectionQueryExpression.class); - - ProjectionQueryExpression projectionExpression = (ProjectionQueryExpression) queryExpression; - QueryExpression underlyingExpression = projectionExpression.getUnderlyingExpression(); - assertEquals(underlyingExpression.getClass(), TermQueryExpression.class); - assertEquals(underlyingExpression.getField(), QueryFactory.escape("relation/name")); - assertEquals(underlyingExpression.getExpectedValue(), "foo"); - - assertEquals(query.getRequest(), request); - assertEquals(query.getResourceDefinition().getTypeName(), "Taxonomy"); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/distro/src/conf/atlas-application.properties ---------------------------------------------------------------------- diff --git a/distro/src/conf/atlas-application.properties b/distro/src/conf/atlas-application.properties index 585a579..9e8adca 100755 --- a/distro/src/conf/atlas-application.properties +++ b/distro/src/conf/atlas-application.properties @@ -200,18 +200,12 @@ atlas.authorizer.impl=SIMPLE #atlas.graph.storage.lock.retries=10 #atlas.graph.storage.cache.db-cache-time=120000 -######### Business Catalog ######### -atlas.taxonomy.default.name=Catalog - ######### CSRF Configs ######### atlas.rest-csrf.enabled=true atlas.rest-csrf.browser-useragents-regex=^Mozilla.*,^Opera.*,^Chrome.* atlas.rest-csrf.methods-to-ignore=GET,OPTIONS,HEAD,TRACE atlas.rest-csrf.custom-header=X-XSRF-HEADER -######### Enable Taxonomy ######### -atlas.feature.taxonomy.enable=true - ############ KNOX Configs ################ #atlas.sso.knox.browser.useragent=Mozilla,Chrome,Opera #atlas.sso.knox.enabled=true http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/distro/src/conf/policy-store.txt ---------------------------------------------------------------------- diff --git a/distro/src/conf/policy-store.txt b/distro/src/conf/policy-store.txt index c804b8d..58d4d4c 100644 --- a/distro/src/conf/policy-store.txt +++ b/distro/src/conf/policy-store.txt @@ -2,8 +2,8 @@ ##r-READ, w-WRITE, u-UPDATE, d-DELETE ##Policy_Name;;User_Name1:Operations_Allowed,User_Name2:Operations_Allowed;;Group_Name1:Operations_Allowed,Group_Name2:Operations_Allowed;;Resource_Type1:Resource_Name,Resource_Type2:Resource_Name ## -adminPolicy;;admin:rwud;;ROLE_ADMIN:rwud;;type:*,entity:*,operation:*,taxonomy:*,term:*,relationship:* -dataScientistPolicy;;;;DATA_SCIENTIST:r;;type:*,entity:*,taxonomy:*,term:*,relationship:* -dataStewardPolicy;;;;DATA_STEWARD:rwu;;type:*,entity:*,taxonomy:*,term:*,relationship:* -hadoopPolicy;;;;hadoop:rwud;;type:*,entity:*,operation:*,taxonomy:*,term:*,relationship:* +adminPolicy;;admin:rwud;;ROLE_ADMIN:rwud;;type:*,entity:*,operation:*,relationship:* +dataScientistPolicy;;;;DATA_SCIENTIST:r;;type:*,entity:*,relationship:* +dataStewardPolicy;;;;DATA_STEWARD:rwu;;type:*,entity:*,relationship:* +hadoopPolicy;;;;hadoop:rwud;;type:*,entity:*,operation:*,relationship:* rangerTagSyncPolicy;;;;RANGER_TAG_SYNC:r;;type:*,entity:* http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 3bbfdd9..f01c341 100644 --- a/pom.xml +++ b/pom.xml @@ -665,7 +665,6 @@ <module>shaded/hbase-server-shaded</module> <module>repository</module> <module>authorization</module> - <module>catalog</module> <module>dashboardv2</module> <module>webapp</module> <module>docs</module> @@ -1498,12 +1497,6 @@ <dependency> <groupId>org.apache.atlas</groupId> - <artifactId>atlas-catalog</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.atlas</groupId> <artifactId>hive-bridge-shim</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/typesystem/src/test/resources/policy-store.txt ---------------------------------------------------------------------- diff --git a/typesystem/src/test/resources/policy-store.txt b/typesystem/src/test/resources/policy-store.txt index 47583c1..048affe 100644 --- a/typesystem/src/test/resources/policy-store.txt +++ b/typesystem/src/test/resources/policy-store.txt @@ -2,8 +2,8 @@ ##r-READ, w-WRITE, u-UPDATE, d-DELETE ##Policy_Name;;User_Name1:Operations_Allowed,User_Name2:Operations_Allowed;;Group_Name1:Operations_Allowed,Group_Name2:Operations_Allowed;;Resource_Type1:Resource_Name,Resource_Type2:Resource_Name ## -adminPolicy;;admin:rwud;;ROLE_ADMIN:rwud;;type:*,entity:*,operation:*,taxonomy:*,term:* -dataScientistPolicy;;;;DATA_SCIENTIST:r;;type:*,entity:*,taxonomy:*,term:* -dataStewardPolicy;;;;DATA_STEWARD:rwu;;type:*,entity:*,taxonomy:*,term:* -hadoopPolicy;;;;hadoop:rwud;;type:*,entity:*,operation:*,taxonomy:*,term:* +adminPolicy;;admin:rwud;;ROLE_ADMIN:rwud;;type:*,entity:*,operation:* +dataScientistPolicy;;;;DATA_SCIENTIST:r;;type:*,entity:* +dataStewardPolicy;;;;DATA_STEWARD:rwu;;type:*,entity:* +hadoopPolicy;;;;hadoop:rwud;;type:*,entity:*,operation:* rangerTagSyncPolicy;;;;RANGER_TAG_SYNC:r;;type:*,entity:* http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/webapp/pom.xml ---------------------------------------------------------------------- diff --git a/webapp/pom.xml b/webapp/pom.xml index bfa79e8..7a86808 100755 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -70,45 +70,6 @@ <log4j.configuration.url>file:/${project.build.directory}/../../distro/src/conf/atlas-log4j.xml</log4j.configuration.url> </properties> </profile> - <profile> - <id>titan1</id> - <!-- remove conflicting lucene/titan versions from catalog when using titan 1 --> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.apache.atlas</groupId> - <artifactId>atlas-catalog</artifactId> - <version>${project.version}</version> - <exclusions> - <exclusion> - <groupId>com.thinkaurelius.titan</groupId> - <artifactId>titan-core</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-core</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-queryparser</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-analyzers-common</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - </dependencyManagement> - - <dependencies> - <dependency> - <groupId>org.apache.atlas</groupId> - <artifactId>atlas-catalog</artifactId> - <scope>provided</scope> - </dependency> - </dependencies> - </profile> </profiles> <dependencies> @@ -172,11 +133,6 @@ <artifactId>hadoop-hdfs</artifactId> </dependency> - <dependency> - <groupId>org.apache.atlas</groupId> - <artifactId>atlas-catalog</artifactId> - </dependency> - <!-- Zookeeper, curator --> <dependency> <groupId>org.apache.curator</groupId> http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/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 82a4d4e..de77c51 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 @@ -101,7 +101,6 @@ public class AdminResource { private static final String BROWSER_USER_AGENT_PARAM = "atlas.rest-csrf.browser-useragents-regex"; private static final String CUSTOM_METHODS_TO_IGNORE_PARAM = "atlas.rest-csrf.methods-to-ignore"; private static final String CUSTOM_HEADER_PARAM = "atlas.rest-csrf.custom-header"; - private static final String isTaxonomyEnabled = "atlas.feature.taxonomy.enable"; private static final String isEntityUpdateAllowed = "atlas.entity.update.allowed"; private static final String isEntityCreateAllowed = "atlas.entity.create.allowed"; private static final String editableEntityTypes = "atlas.ui.editable.entity.types"; @@ -242,12 +241,7 @@ public class AdminResource { } Response response; - Boolean enableTaxonomy = false; try { - if(atlasProperties != null) { - enableTaxonomy = atlasProperties.getBoolean(isTaxonomyEnabled, false); - } - boolean isEntityUpdateAccessAllowed = false; boolean isEntityCreateAccessAllowed = false; Authentication auth = SecurityContextHolder.getContext().getAuthentication(); @@ -272,7 +266,6 @@ public class AdminResource { responseData.put(BROWSER_USER_AGENT_PARAM, AtlasCSRFPreventionFilter.BROWSER_USER_AGENTS_DEFAULT); responseData.put(CUSTOM_METHODS_TO_IGNORE_PARAM, AtlasCSRFPreventionFilter.METHODS_TO_IGNORE_DEFAULT); responseData.put(CUSTOM_HEADER_PARAM, AtlasCSRFPreventionFilter.HEADER_DEFAULT); - responseData.put(isTaxonomyEnabled, enableTaxonomy); responseData.put(isEntityUpdateAllowed, isEntityUpdateAccessAllowed); responseData.put(isEntityCreateAllowed, isEntityCreateAccessAllowed); responseData.put(editableEntityTypes, getEditableEntityTypes(atlasProperties)); http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java b/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java deleted file mode 100644 index a013494..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/BaseService.java +++ /dev/null @@ -1,157 +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.gson.Gson; -import com.google.gson.JsonSyntaxException; -import org.apache.atlas.catalog.JsonSerializer; -import org.apache.atlas.catalog.Request; -import org.apache.atlas.catalog.ResourceProvider; -import org.apache.atlas.catalog.Result; -import org.apache.atlas.catalog.exception.CatalogException; -import org.apache.atlas.catalog.exception.CatalogRuntimeException; -import org.apache.atlas.catalog.exception.InvalidPayloadException; -import org.apache.atlas.catalog.exception.InvalidQueryException; -import org.apache.atlas.catalog.exception.ResourceNotFoundException; -import org.apache.atlas.repository.graph.AtlasGraphProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.core.Context; -import javax.ws.rs.core.UriInfo; -import javax.xml.bind.annotation.XmlRootElement; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.Collection; -import java.util.Map; - -/** - * Base class for all v1 API services. - */ -public abstract class BaseService { - private static final Gson gson = new Gson(); - private final Logger LOG = LoggerFactory.getLogger(getClass()); - private final static JsonSerializer serializer = new JsonSerializer(); - - protected Result getResource(ResourceProvider provider, Request request) - throws ResourceNotFoundException { - - try { - return provider.getResourceById(request); - } catch (RuntimeException e) { - throw wrapRuntimeException(e); - } - } - - protected Result getResources(ResourceProvider provider, Request request) - throws ResourceNotFoundException, InvalidQueryException { - - try { - return provider.getResources(request); - } catch (RuntimeException e) { - LOG.error("Error while retrieving taxonomy ", e); - throw wrapRuntimeException(e); - } - } - - protected void createResource(ResourceProvider provider, Request request) throws CatalogException { - try { - provider.createResource(request); - } catch (RuntimeException e) { - throw wrapRuntimeException(e); - } - } - - protected void updateResource(ResourceProvider provider, Request request) throws CatalogException { - try { - provider.updateResourceById(request); - } catch (RuntimeException e) { - throw wrapRuntimeException(e); - } - } - - protected void deleteResource(ResourceProvider provider, Request request) throws CatalogException { - try { - provider.deleteResourceById(request); - - } catch (RuntimeException e) { - throw wrapRuntimeException(e); - } - } - - protected Collection<String> createResources(ResourceProvider provider, Request request) throws CatalogException { - try { - return provider.createResources(request); - } catch (RuntimeException e) { - throw wrapRuntimeException(e); - } - } - - protected String getQueryString(@Context UriInfo ui) { - String uri = ui.getRequestUri().toASCIIString(); - int qsBegin = uri.indexOf("?"); - return (qsBegin == -1) ? null : uri.substring(qsBegin + 1); - } - - protected <T extends Map> T parsePayload(String body) throws InvalidPayloadException { - T properties; - - try { - properties = gson.<T>fromJson(body, Map.class); - } catch (JsonSyntaxException e) { - LOG.info("Unable to parse json in request body", e); - throw new InvalidPayloadException("Request payload contains invalid JSON: " + e.getMessage()); - } - - return properties; - } - - protected String decode(String s) throws CatalogException { - try { - return s == null ? null : URLDecoder.decode(s, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new CatalogException("Unable to decode URL: " + e.getMessage(), 500); - } - } - - protected JsonSerializer getSerializer() { - return serializer; - } - - - private RuntimeException wrapRuntimeException(RuntimeException e) { - return e instanceof CatalogRuntimeException ? e : new CatalogRuntimeException(e); - } - - @XmlRootElement - // the name of this class is used as the collection name in the returned json when returning a collection - public static class Results { - public String href; - public int status; - - public Results() { - // required by JAXB - } - - public Results(String href, int status) { - this.href = href; - this.status = status; - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/webapp/src/main/java/org/apache/atlas/web/resources/CatalogExceptionMapper.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/CatalogExceptionMapper.java b/webapp/src/main/java/org/apache/atlas/web/resources/CatalogExceptionMapper.java deleted file mode 100644 index 4f7da2e..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/CatalogExceptionMapper.java +++ /dev/null @@ -1,62 +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.catalog.exception.CatalogException; -import org.apache.atlas.web.util.Servlets; - -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * Exception mapper for CatalogException. - */ -@Provider -public class CatalogExceptionMapper implements ExceptionMapper<CatalogException> { - @Override - public Response toResponse(CatalogException e) { - return Response.status(e.getStatus()).entity( - new ErrorBean(e)).type(Servlets.JSON_MEDIA_TYPE).build(); - } - - @XmlRootElement - public static class ErrorBean { - public int status; - public String message; - - public ErrorBean() { - // required for JAXB - } - - public ErrorBean(CatalogException ex) { - this.status = ex.getStatus(); - this.message = ex.getMessage(); - } - - public int getStatus() { - return status; - } - - public String getMessage() { - return message; - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/webapp/src/main/java/org/apache/atlas/web/resources/CatalogRuntimeExceptionMapper.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/CatalogRuntimeExceptionMapper.java b/webapp/src/main/java/org/apache/atlas/web/resources/CatalogRuntimeExceptionMapper.java deleted file mode 100644 index e11d6d1..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/CatalogRuntimeExceptionMapper.java +++ /dev/null @@ -1,78 +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.catalog.exception.CatalogRuntimeException; -import org.apache.atlas.web.util.Servlets; - -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; -import javax.xml.bind.annotation.XmlRootElement; -import java.io.PrintWriter; -import java.io.StringWriter; - -/** - * Exception mapper for CatalogRuntimeException - */ -@Provider -public class CatalogRuntimeExceptionMapper implements ExceptionMapper<CatalogRuntimeException> { - @Override - public Response toResponse(CatalogRuntimeException e) { - return Response.status(e.getStatusCode()).entity( - new ErrorBean(e)).type(Servlets.JSON_MEDIA_TYPE).build(); - } - - @XmlRootElement - public static class ErrorBean { - private static final String MSG_PREFIX = "An unexpected error has occurred. "; - public int status; - public String message; - public String stackTrace; - //todo: error code, developerMsg ... - - public ErrorBean() { - // required for JAXB - } - - public ErrorBean(CatalogRuntimeException ex) { - this.status = 500; - this.message = String.format("%s%s : %s", MSG_PREFIX, ex.toString(), ex.getCause().toString()); - this.stackTrace = getStackTraceFromException(ex); - } - - public int getStatus() { - return status; - } - - public String getMessage() { - return message; - } - - public String getStackTrace() { - return stackTrace; - } - - private String getStackTraceFromException(RuntimeException e) { - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - return sw.toString(); - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/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 deleted file mode 100644 index 77115d7..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/EntityService.java +++ /dev/null @@ -1,247 +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 org.apache.atlas.catalog.BaseRequest; -import org.apache.atlas.catalog.CollectionRequest; -import org.apache.atlas.catalog.DefaultTypeSystem; -import org.apache.atlas.catalog.EntityResourceProvider; -import org.apache.atlas.catalog.EntityTagResourceProvider; -import org.apache.atlas.catalog.InstanceRequest; -import org.apache.atlas.catalog.Result; -import org.apache.atlas.catalog.exception.CatalogException; -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.services.MetadataService; -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; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.GenericEntity; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * Service which handles API requests for v1 entity resources. - */ -@Path("v1/entities") -@Singleton -@Service -public class EntityService extends BaseService { - private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.EntityService"); - - private final EntityResourceProvider entityResourceProvider; - private final EntityTagResourceProvider entityTagResourceProvider; - - @Inject - public EntityService(MetadataService metadataService, AtlasTypeDefStore typeDefStore) throws AtlasBaseException { - DefaultTypeSystem typeSystem = new DefaultTypeSystem(metadataService, typeDefStore); - entityResourceProvider = new EntityResourceProvider(typeSystem); - entityTagResourceProvider = new EntityTagResourceProvider(typeSystem); - } - - @GET - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getEntities(@Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntities()"); - } - - String queryString = decode(getQueryString(ui)); - - BaseRequest request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - Result result = getResources(entityResourceProvider, request); - - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @GET - @Path("{entityId}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getEntity(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("entityId") String entityId) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntity(" + entityId + ")"); - } - - BaseRequest request = new InstanceRequest(Collections.<String, Object>singletonMap("id", entityId)); - Result result = getResource(entityResourceProvider, request); - - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @GET - @Path("{entityId}/tags/{tag}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getEntityTag(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("entityId") String entityId, - @PathParam("tag") String tagName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntityTag(" + entityId + ", " + tagName + ")"); - } - - Map<String, Object> properties = new HashMap<>(); - properties.put("id", entityId); - properties.put("name", tagName); - Result result = getResource(entityTagResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @GET - @Path("{entityId}/tags") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getEntityTags(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("entityId") String entityGuid) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.getEntityTags(" + entityGuid + ")"); - } - - BaseRequest request = new CollectionRequest(Collections.<String, Object>singletonMap("id", entityGuid), - decode(getQueryString(ui))); - Result result = getResources(entityTagResourceProvider, request); - - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @POST - @Path("{entityId}/tags/{tag}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response tagEntity(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("entityId") String entityId, - @PathParam("tag") String tagName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntity(" + entityId + ", " + tagName + ")"); - } - - Map<String, Object> properties = new HashMap<>(); - properties.put("id", entityId); - properties.put("name", tagName); - createResource(entityTagResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.CREATED).entity( - new Results(ui.getRequestUri().toString(), 201)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @POST - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response tagEntities(String body, - @Context HttpHeaders headers, - @Context UriInfo ui) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.tagEntities()"); - } - - Map<String, Object> properties = parsePayload(body); - - if (properties.get("tags") == null || properties.size() != 1) { - throw new CatalogException( - "Invalid Request, no 'tags' property specified. Creation of entity resource not supported.", 400); - - } - String queryString = decode(getQueryString(ui)); - Collection<String> createResults = createResources( - entityTagResourceProvider, new CollectionRequest(properties, queryString)); - - Collection<Results> result = new ArrayList<>(); - for (String relativeUrl : createResults) { - result.add(new Results(ui.getBaseUri().toString() + relativeUrl, 201)); - } - - return Response.status(Response.Status.CREATED).entity( - new GenericEntity<Collection<Results>>(result) { - }).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @DELETE - @Path("{entityId}/tags/{tag}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response deleteEntityTag(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("entityId") String entityId, - @PathParam("tag") String tagName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityService.deleteEntityTag()"); - } - - Map<String, Object> properties = new HashMap<>(); - properties.put("id", entityId); - properties.put("name", tagName); - deleteResource(entityTagResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.OK).entity( - new Results(ui.getRequestUri().toString(), 200)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/96da2306/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 deleted file mode 100644 index 05b197f..0000000 --- a/webapp/src/main/java/org/apache/atlas/web/resources/TaxonomyService.java +++ /dev/null @@ -1,441 +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 org.apache.atlas.catalog.*; -import org.apache.atlas.catalog.exception.CatalogException; -import org.apache.atlas.catalog.exception.InvalidPayloadException; -import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.services.MetadataService; -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.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.PathSegment; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Service which handles API requests for taxonomy and term resources. - */ -@Path("v1/taxonomies") -@Component -public class TaxonomyService extends BaseService { - private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("rest.TaxonomyService"); - - private ResourceProvider taxonomyResourceProvider; - private ResourceProvider termResourceProvider; - - @Inject - public void setMetadataService(MetadataService metadataService, AtlasTypeDefStore typeDefStore) throws AtlasBaseException { - DefaultTypeSystem typeSystem = new DefaultTypeSystem(metadataService, typeDefStore); - taxonomyResourceProvider = createTaxonomyResourceProvider(typeSystem); - termResourceProvider = createTermResourceProvider(typeSystem); - } - - @GET - @Path("{taxonomyName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getTaxonomy(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomy(" + taxonomyName + ")"); - } - - Map<String, Object> properties = new HashMap<>(); - properties.put("name", taxonomyName); - Result result = getResource(taxonomyResourceProvider, new InstanceRequest(properties)); - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @GET - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getTaxonomies(@Context HttpHeaders headers, @Context UriInfo ui) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomies()"); - } - - String queryString = decode(getQueryString(ui)); - Request request = new CollectionRequest(Collections.<String, Object>emptyMap(), queryString); - Result result = getResources(taxonomyResourceProvider, request); - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @POST - @Path("{taxonomyName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response createTaxonomy(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.createTaxonomy(" + taxonomyName + ")"); - } - - Map<String, Object> properties = parsePayload(body); - properties.put("name", taxonomyName); - - createResource(taxonomyResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.CREATED).entity( - new Results(ui.getRequestUri().toString(), 201)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @PUT - @Path("{taxonomyName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response updateTaxonomy(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTaxonomy(" + taxonomyName + ")"); - } - - Map<String, Object> queryProperties = new HashMap<>(); - queryProperties.put("name", taxonomyName); - Map<String, Object> updateProperties = parsePayload(body); - updateResource(taxonomyResourceProvider, new InstanceRequest(queryProperties, updateProperties)); - - return Response.status(Response.Status.OK).entity( - new Results(ui.getRequestUri().toString(), 200)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @DELETE - @Path("{taxonomyName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response deleteTaxonomy(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.deleteTaxonomy(" + taxonomyName + ")"); - } - - Map<String, Object> properties = new HashMap<>(); - properties.put("name", taxonomyName); - - deleteResource(taxonomyResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.OK).entity( - new Results(ui.getRequestUri().toString(), 200)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @GET - @Path("{taxonomyName}/terms/{termName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getTaxonomyTerm(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("termName") String termName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomyTerm(" + taxonomyName + ", " + termName + ")"); - } - - TermPath termPath = new TermPath(taxonomyName, termName); - Map<String, Object> properties = new HashMap<>(); - properties.put("termPath", termPath); - Result result = getResource(termResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @GET - @Path("{taxonomyName}/terms") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getTaxonomyTerms(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getTaxonomyTerms(" + taxonomyName + ")"); - } - - String queryString = decode(getQueryString(ui)); - TermPath termPath = new TermPath(taxonomyName, null); - Request request = new CollectionRequest( - Collections.<String, Object>singletonMap("termPath", termPath), queryString); - Result result = getResources(termResourceProvider, request); - - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @GET - @Path("{taxonomyName}/terms/{rootTerm}/{remainder:.*}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response getSubTerms(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("rootTerm") String rootTerm, - @PathParam("remainder") String remainder) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getSubTerms(" + taxonomyName + ", " + rootTerm + ", " + remainder + ")"); - } - - Result result; - String termName = String.format("%s%s", rootTerm, - remainder.replaceAll("/?terms/?([.]*)", "$1.")); - String queryString = decode(getQueryString(ui)); - TermPath termPath = new TermPath(taxonomyName, termName); - - Map<String, Object> properties = new HashMap<>(); - properties.put("termPath", termPath); - - List<PathSegment> pathSegments = ui.getPathSegments(); - int lastIndex = pathSegments.size() - 1; - String lastSegment = pathSegments.get(lastIndex).getPath(); - if (lastSegment.equals("terms") || (lastSegment.isEmpty() && pathSegments.get(lastIndex - 1).getPath().equals("terms"))) { - result = getResources(termResourceProvider, new CollectionRequest(properties, queryString)); - } else { - result = getResource(termResourceProvider, new InstanceRequest(properties)); - } - - return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @POST - @Path("{taxonomyName}/terms/{termName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response createTerm(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("termName") String termName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.createTerm(" + taxonomyName + ", " + termName + ")"); - } - - Map<String, Object> properties = parsePayload(body); - validateName(termName); - properties.put("termPath", new TermPath(taxonomyName, termName)); - createResource(termResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.CREATED).entity( - new Results(ui.getRequestUri().toString(), 201)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @POST - @Path("{taxonomyName}/terms/{termName}/{remainder:.*}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response createSubTerm(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("termName") String termName, - @PathParam("remainder") String remainder) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.createSubTerm(" + taxonomyName + ", " + termName + ", " + remainder + ")"); - } - - Map<String, Object> properties = parsePayload(body); - String[] pathTokens = remainder.split("/"); - validateName(pathTokens[pathTokens.length - 1]); - properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName, - remainder.replaceAll("/?terms/?([.]*)", "$1.")))); - createResource(termResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.CREATED).entity( - new Results(ui.getRequestUri().toString(), 201)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @PUT - @Path("{taxonomyName}/terms/{termName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response updateTerm(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("termName") String termName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateTerm(" + taxonomyName + ", " + termName + ")"); - } - - Map<String, Object> queryProperties = new HashMap<>(); - queryProperties.put("termPath", new TermPath(taxonomyName, termName)); - - Map<String, Object> updateProperties = parsePayload(body); - updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties)); - - return Response.status(Response.Status.OK).entity( - new Results(ui.getRequestUri().toString(), 200)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @PUT - @Path("{taxonomyName}/terms/{termName}/{remainder:.*}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response updateSubTerm(String body, - @Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("termName") String termName, - @PathParam("remainder") String remainder) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.updateSubTerm(" + taxonomyName + ", " + termName + ", " + remainder + ")"); - } - - Map<String, Object> queryProperties = new HashMap<>(); - queryProperties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName, - remainder.replaceAll("/?terms/?([.]*)", "$1.")))); - - Map<String, Object> updateProperties = parsePayload(body); - updateResource(termResourceProvider, new InstanceRequest(queryProperties, updateProperties)); - - return Response.status(Response.Status.OK).entity( - new Results(ui.getRequestUri().toString(), 200)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @DELETE - @Path("{taxonomyName}/terms/{termName}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response deleteTerm(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("termName") String termName) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.deleteTerm(" + taxonomyName + ", " + termName + ")"); - } - - Map<String, Object> properties = new HashMap<>(); - properties.put("termPath", new TermPath(taxonomyName, termName)); - deleteResource(termResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.OK).entity( - new Results(ui.getRequestUri().toString(), 200)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - @DELETE - @Path("{taxonomyName}/terms/{termName}/{remainder:.*}") - @Produces(Servlets.JSON_MEDIA_TYPE) - public Response deleteSubTerm(@Context HttpHeaders headers, - @Context UriInfo ui, - @PathParam("taxonomyName") String taxonomyName, - @PathParam("termName") String termName, - @PathParam("remainder") String remainder) throws CatalogException { - AtlasPerfTracer perf = null; - try { - if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { - perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.deleteSubTerm(" + taxonomyName + ", " + termName + ", " + remainder + ")"); - } - - Map<String, Object> properties = new HashMap<>(); - properties.put("termPath", new TermPath(taxonomyName, String.format("%s%s", termName, - remainder.replaceAll("/?terms/?([.]*)", "$1.")))); - deleteResource(termResourceProvider, new InstanceRequest(properties)); - - return Response.status(Response.Status.OK).entity( - new Results(ui.getRequestUri().toString(), 200)).build(); - } finally { - AtlasPerfTracer.log(perf); - } - } - - protected ResourceProvider createTaxonomyResourceProvider(AtlasTypeSystem typeSystem) { - return new TaxonomyResourceProvider(typeSystem); - } - - protected ResourceProvider createTermResourceProvider(AtlasTypeSystem typeSystem) { - return new TermResourceProvider(typeSystem); - } - - private void validateName(String name) throws InvalidPayloadException { - if (name.contains(".")) { - throw new InvalidPayloadException("The \"name\" property may not contain the character '.'"); - } - } -}
