Repository: incubator-atlas Updated Branches: refs/heads/master 5e724675b -> 915595780
ATLAS-692 Create abstraction layer for graph databases (jnhagelb via yhemanth) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/91559578 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/91559578 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/91559578 Branch: refs/heads/master Commit: 9155957803b8b0d5030e5fd988ba8679185da489 Parents: 5e72467 Author: Hemanth Yamijala <[email protected]> Authored: Wed May 11 17:25:18 2016 +0530 Committer: Hemanth Yamijala <[email protected]> Committed: Wed May 11 17:25:18 2016 +0530 ---------------------------------------------------------------------- .gitignore | 9 + graphdb/api/pom.xml | 50 ++++ .../atlas/repository/graphdb/AtlasEdge.java | 60 +++++ .../repository/graphdb/AtlasEdgeDirection.java | 27 ++ .../atlas/repository/graphdb/AtlasElement.java | 74 ++++++ .../atlas/repository/graphdb/AtlasGraph.java | 250 +++++++++++++++++++ .../graphdb/AtlasGraphManagement.java | 98 ++++++++ .../repository/graphdb/AtlasGraphQuery.java | 71 ++++++ .../repository/graphdb/AtlasIndexQuery.java | 59 +++++ .../graphdb/AtlasSchemaViolationException.java | 29 +++ .../atlas/repository/graphdb/AtlasVertex.java | 81 ++++++ .../repository/graphdb/AtlasVertexQuery.java | 56 +++++ .../atlas/repository/graphdb/GraphDatabase.java | 44 ++++ .../repository/graphdb/GremlinVersion.java | 29 +++ graphdb/pom.xml | 38 +++ pom.xml | 1 + release-log.txt | 1 + 17 files changed, 977 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index b5a1c74..20db282 100755 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,9 @@ # Maven target +dependency-reduced-pom.xml +core*.dmp + # IntelliJ *.iml @@ -27,6 +30,7 @@ target .cache .classpath .project + .settings .externalToolBuilders maven-eclipse.xml @@ -52,3 +56,8 @@ test-output #hbase package downloaded distro/hbase/*.tar.gz +.cache-main + +# emacs files +*# +*~ http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/pom.xml ---------------------------------------------------------------------- diff --git a/graphdb/api/pom.xml b/graphdb/api/pom.xml new file mode 100644 index 0000000..5c05a40 --- /dev/null +++ b/graphdb/api/pom.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.atlas</groupId> + <artifactId>atlas-graphdb</artifactId> + <version>0.7-incubating-SNAPSHOT</version> + </parent> + <artifactId>atlas-graphdb-api</artifactId> + <description>Apache Atlas Graph Datbase API</description> + <name>Apache Atlas Graph Database API</name> + <packaging>jar</packaging> + + <dependencies> + + <dependency> + <groupId>org.apache.atlas</groupId> + <artifactId>atlas-typesystem</artifactId> + </dependency> + + <dependency> + <groupId>org.codehaus.jettison</groupId> + <artifactId>jettison</artifactId> + </dependency> + </dependencies> + + +</project> http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdge.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdge.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdge.java new file mode 100644 index 0000000..71b577b --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdge.java @@ -0,0 +1,60 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.graphdb; + +/** + * Represent an edge in the graph + * + * @param <V> vertex class used by the graph + * @param <E> edge class used by the graph + */ +public interface AtlasEdge<V,E> extends AtlasElement { + + /** + * Gets the incoming vertex for this edge + * @param in + * @return + */ + AtlasVertex<V,E> getInVertex(); + + /** + * Gets the outgoing vertex for this edge + * + * @param in + * @return + */ + AtlasVertex<V,E> getOutVertex(); + + /** + * Gets the label associated with this edge. + * + * @return + */ + String getLabel(); + + /** + * Converts the edge to an instance of the underlying implementation class. This + * is syntactic sugar that allows the graph database implementation code to be strongly typed. This + * should not be called in other places. + * + * @return + */ + public E getE(); + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdgeDirection.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdgeDirection.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdgeDirection.java new file mode 100644 index 0000000..e7da1c9 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasEdgeDirection.java @@ -0,0 +1,27 @@ +/** + * 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.graphdb; +/** + * Enumeration of edge directions to query for. + */ +public enum AtlasEdgeDirection { + IN, + OUT, + BOTH +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasElement.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasElement.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasElement.java new file mode 100644 index 0000000..3c41693 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasElement.java @@ -0,0 +1,74 @@ +/** + * 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.graphdb; + +import java.util.Collection; +import java.util.Set; + +import org.codehaus.jettison.json.JSONException; +import org.codehaus.jettison.json.JSONObject; + +/** + * Represents a graph element. + * + */ +public interface AtlasElement { + + /** + * Gets the id of this element + * @return + */ + Object getId(); + + /** + * Gets the names of the properties associated with this element. + * @return + */ + Collection<? extends String> getPropertyKeys(); + + /** + * Gets the value of the element property with the given name + * + * @param propertyName + * @return + */ + <T> T getProperty(String propertyName); + + /** + * Removes a property from the vertex. + */ + void removeProperty(String propertyName); + + /** + * Sets a single-valued property to the given value. + * + * @param propertyName + * @param value + */ + <T> void setProperty(String propertyName, T value); + + + /** + * Creates a Jettison JSONObject from this Element + * + * @param propertyKeys The property keys at the root of the element to serialize. If null, then all keys are serialized. + */ + JSONObject toJson(Set<String> propertyKeys) throws JSONException; + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java new file mode 100644 index 0000000..f312117 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraph.java @@ -0,0 +1,250 @@ +/** + * 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.graphdb; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; +import java.util.Set; + +import javax.script.Bindings; +import javax.script.ScriptException; + +/** + * Represents a graph + * + * @param <V> vertex implementation class + * @param <E> edge implementation class + */ +public interface AtlasGraph<V,E> { + + /** + * Adds an edge to the graph + * + * @param outVertex + * @param inVertex + * @param label + * @return + */ + AtlasEdge<V,E> addEdge(AtlasVertex<V,E> outVertex, AtlasVertex<V,E> inVertex, String label); + + /** + * Adds a vertex to the graph + * + * @return + */ + AtlasVertex<V,E> addVertex(); + + /** + * Removes the specified edge from the graph + * + * @param edge + */ + void removeEdge(AtlasEdge<V,E> edge); + + /** + * Removes the specified vertex from the graph. + * + * @param vertex + */ + void removeVertex(AtlasVertex<V,E> vertex); + + /** + * Retrieves the edge with the specified id + * @param edgeId + * @return + */ + AtlasEdge<V,E> getEdge(String edgeId); + + /** + * Gets all the edges in the graph. + * @return + */ + Iterable<AtlasEdge<V,E>> getEdges(); + + /** + * Gets all the vertices in the graph. + * @return + */ + Iterable<AtlasVertex<V,E>> getVertices(); + + /** + * Gets the vertex with the specified id + * + * @param vertexId + * @return + */ + AtlasVertex<V, E> getVertex(String vertexId); + + /** + * Gets the names of the indexes on edges + * type. + * + * @param type + * @return + */ + Set<String> getEdgeIndexKeys(); + + + /** + * Gets the names of the indexes on vertices. + * type. + * + * @param type + * @return + */ + Set<String> getVertexIndexKeys(); + + + /** + * Finds the vertices where the given property key + * has the specified value. For multi-valued properties, + * finds the vertices where the value list contains + * the specified value. + * + * @param key + * @param value + * @return + */ + Iterable<AtlasVertex<V,E>> getVertices(String key, Object value); + + /** + * Creates a graph query + * @return + */ + AtlasGraphQuery<V,E> query(); + + /** + * Creates an index query + * + * @param indexName index name + * @param queryString the query + * + * @see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html">Elastic Search Reference</a> for query syntax + */ + AtlasIndexQuery<V,E> indexQuery(String indexName, String queryString); + + /** + * Gets the management object associated with this graph and opens a transaction + * for changes that are made. + * @return + */ + AtlasGraphManagement getManagementSystem(); + + /** + * Commits changes made to the graph in the current transaction. + */ + void commit(); + + /** + * Rolls back changes made to the graph in the current transaction. + */ + void rollback(); + + /** + * Unloads and releases any resources associated with the graph. + */ + void shutdown(); + + /** + * deletes everything in the graph. For testing only + */ + void clear(); + + /** + * Converts the graph to gson and writes it to the specified stream + * + * @param os + * @throws IOException + */ + void exportToGson(OutputStream os) throws IOException; + + //the following methods insulate Atlas from the details + //of the interaction with Gremlin + + + /** + * + * When we construct Gremlin select queries, the information we request + * is grouped by the vertex the information is coming from. Each vertex + * is assigned a column name which uniquely identifies it. The queries + * are specially formatted so that the value associated with each of + * these column names is an array with the various things we need + * about that particular vertex. The query evaluator creates a mapping + * that knows what index each bit of information is stored at within + * this array. + * <p/> + * When we execute a Gremlin query, the exact java objects we get + * back vary depending on whether Gremlin 2 or Gremlin 3 is being used. + * This method takes as input a raw row result that was obtained by + * executing a Gremlin query and extracts the value that was found + * at the given index in the array for the given column name. + * <p/> + * If the value found is a vertex or edge, it is automatically converted + * to an AtlasVertex/AtlasEdge. + * + * @param rowValue the raw row value that was returned by Gremin + * @param colName the column name to use + * @param idx the index of the value within the column to retrieve. + * + */ + Object getGremlinColumnValue(Object rowValue, String colName, int idx); + + /** + * When Gremlin queries are executed, they return + * Vertex and Edge objects that are specific to the underlying + * graph database. This method provides a way to convert these + * objects back into the AtlasVertex/AtlasEdge objects that + * Atlas requires. + * + * @param rawValue the value that was obtained from Gremlin + * @return either an AtlasEdge, an AtlasVertex, or the original + * value depending on whether the rawValue represents an edge, + * vertex, or something else. + * + */ + Object convertGremlinValue(Object rawValue); + + /** + * Gremlin 2 and Gremlin 3 represent the results of "path" + * queries differently. This method takes as input the + * path from Gremlin and returns the list of objects in the path. + * + * @param rawValue + * @return + */ + List<Object> convertPathQueryResultToList(Object rawValue); + + /** + * Gets the version of Gremlin that this graph uses. + * + * @return + */ + GremlinVersion getSupportedGremlinVersion(); + + /** + * Executes a gremlin query, returns an object with the raw + * result. + * + * @param gremlinQuery + * @return + */ + Object executeGremlinScript(String gremlinQuery) throws ScriptException; + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java new file mode 100644 index 0000000..2776b22 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphManagement.java @@ -0,0 +1,98 @@ +/** + * 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.graphdb; + +import org.apache.atlas.typesystem.types.Multiplicity; + +/** + * Management interface for a graph + * + */ +public interface AtlasGraphManagement { + + /** + * Checks whether a property with the given key has been defined in the graph schema. + * + * @param key + * @return + */ + boolean containsPropertyKey(String key); + + /** + * Creates a mixed Vertex index for the graph + * + * @param index the name of the index to create + * @param backingIndex the name of the backing index to use + */ + void buildMixedVertexIndex(String index, String backingIndex); + + + /** + * Creates a mixed Edge index for the graph + * + * @param index the name of the index to create + * @param backingIndex the name of the backing index to use + */ + void buildMixedEdgeIndex(String index, String backingIndex); + + + /** + * Creates a full text index for the given property + * + * @param indexName the name of the index to create + * @param propertyKey the name of the property + * @param backingIndex the name of the backing index to use + */ + void createFullTextIndex(String indexName, String propertyKey, String backingIndex); + + /** + * Rolls back the changes that have been made to the management system. + */ + void rollback(); + + /** + * Commits the changes that have been made to the management system. + */ + + void commit(); + + /** + * Creates a composite index for the given property. + * + * @param propertyName name of the property being indexed + * @param propertyClass the java class of the property value(s) + * @param multiplicity the multiplicity of the property + * @param isUnique whether the property values must be unique + */ + void createCompositeIndex(String propertyName, Class propertyClass, Multiplicity multiplicity, + boolean isUnique); + + /** + * Creates an index for a property. + * + * @param propertyName name of the property being indexed + * @param vertexIndexName name of the index to create + * @param propertyClass the java class of the property value(s) + * @param multiplicity the multiplicity of the property + */ + void createBackingIndex(String propertyName, String vertexIndexName, Class propertyClass, + Multiplicity multiplicity); + + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphQuery.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphQuery.java new file mode 100644 index 0000000..f0dca9a --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasGraphQuery.java @@ -0,0 +1,71 @@ +/** + * 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.graphdb; + +/** + * Represents a query against the graph. + * + * @param <V> vertex class used by the graph + * @param <E> edge class used by the graph + */ +public interface AtlasGraphQuery<V,E> { + + /** + * Adds a predicate that the returned elements must have the specified + * property and that one of the values of the property must be the + * given value. + * + * @param propertyKey + * @param value + * @return + */ + AtlasGraphQuery<V,E> has(String propertyKey, Object value); + + /** + * Executes the query and returns the matching vertices. + * @return + */ + Iterable<AtlasVertex<V, E>> vertices(); + + + /** + * Executes the query and returns the matching edges. + * @return + */ + Iterable<AtlasEdge<V, E>> edges(); + + + + /** + * Adds a predicate that the returned elements must have the specified + * property and that its value matches the criterion specified. + * + * @param propertyKey + * @param value + * @return + */ + AtlasGraphQuery<V,E> has(String propertyKey, ComparisionOperator compMethod, Object value); + + public static enum ComparisionOperator { + GREATER_THAN_EQUAL, + EQUAL, + LESS_THAN_EQUAL + } + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasIndexQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasIndexQuery.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasIndexQuery.java new file mode 100644 index 0000000..7ee6b28 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasIndexQuery.java @@ -0,0 +1,59 @@ +/** + * 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.graphdb; + +import java.util.Iterator; + +/** + * A graph query that runs directly against a particular index. + * + * @param <V> vertex class used by the graph + * @param <E> edge class used by the graph + */ +public interface AtlasIndexQuery<V,E> { + + /** + * Gets the query results. + * + * @return + */ + Iterator<Result<V,E>> vertices(); + + /** + * Query result from an index query. + * + * @param <V> + * @param <E> + */ + public interface Result<V,E> { + + /** + * Gets the vertex for this result + */ + AtlasVertex<V,E> getVertex(); + + /** + * Gets the score for this result. + * + */ + double getScore(); + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasSchemaViolationException.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasSchemaViolationException.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasSchemaViolationException.java new file mode 100644 index 0000000..fda83b8 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasSchemaViolationException.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.graphdb; + +/** + * + */ +public class AtlasSchemaViolationException extends RuntimeException { + + public AtlasSchemaViolationException(Throwable cause) { + super(cause); + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertex.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertex.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertex.java new file mode 100644 index 0000000..e027b69 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertex.java @@ -0,0 +1,81 @@ +/** + * 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.graphdb; + +import java.util.Collection; + +/** + * Represents a Vertex + * + * @param <V> vertex class used by the graph + * @param <E> edge class used by the graph + */ +public interface AtlasVertex<V,E> extends AtlasElement { + + + + + /** + * Gets the edges incident to this vertex going the + * specified direction that have the specified edgeLabel. If + * the edgeLabel is null, it is ignored. + * + * @param in + * @return + */ + Iterable<AtlasEdge<V,E>> getEdges(AtlasEdgeDirection out, String edgeLabel); + + /** + * Gets the edges associated with this vertex going the + * specified direction. + * + * @param in + * @return + */ + Iterable<AtlasEdge<V,E>> getEdges(AtlasEdgeDirection in); + + /** + * Adds a value to a multiplicity many property. + * + * @param propertyName + * @param value + */ + <T> void addProperty(String propertyName, T value); + + /** + * Gets all of the values of the given property. + * @param propertyName + * @return + */ + <T> Collection<T> getPropertyValues(String propertyName); + + /** + * Creates a vertex query. + * @return + */ + AtlasVertexQuery<V,E> query(); + + /** + * Syntactic sugar to get the vertex as an instance of its + * implementation type. This allows the graph database implementation + * code to be strongly typed. + * + * @return + */ + V getV(); +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertexQuery.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertexQuery.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertexQuery.java new file mode 100644 index 0000000..fd20a65 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/AtlasVertexQuery.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.graphdb; + +/** + * A query against a particular vertex. + * + * @param <V> vertex class used by the graph + * @param <E> edge class used by the graph + */ +public interface AtlasVertexQuery<V,E> { + + /** + * Specifies the edge direction that should be query + * + * @param queryDirection + * @return + */ + AtlasVertexQuery<V,E> direction(AtlasEdgeDirection queryDirection); + + /** + * Returns the vertices that satisfy the query condition. + * + * @return + */ + Iterable<AtlasVertex<V,E>> vertices(); + + /** + * Returns the incident edges that satisfy the query condition. + * @return + */ + Iterable<AtlasEdge<V,E>> edges(); + + /** + * Returns the number of elements that match the query. + * @return + */ + long count(); + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GraphDatabase.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GraphDatabase.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GraphDatabase.java new file mode 100644 index 0000000..a608eb2 --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GraphDatabase.java @@ -0,0 +1,44 @@ +/** + * 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.graphdb; + +/** + * Represents a graph database + * + * @param <V> vertex class used by the graph database + * @param <E> edge class used by the graph database + */ +public interface GraphDatabase<V,E> { + + /** + * Returns whether the graph has been loaded. + * @return + */ + boolean isGraphLoaded(); + + /** + * Gets the graph, loading it if it has not been loaded already + * @return + */ + AtlasGraph<V,E> getGraph(); + + /** + * Unloads the graph (used testing) + */ + void unloadGraph(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GremlinVersion.java ---------------------------------------------------------------------- diff --git a/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GremlinVersion.java b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GremlinVersion.java new file mode 100644 index 0000000..e817cba --- /dev/null +++ b/graphdb/api/src/main/java/org/apache/atlas/repository/graphdb/GremlinVersion.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.atlas.repository.graphdb; + +/** + * Enumeration of the supported versions of Gremlin + * + * + */ +public enum GremlinVersion { + TWO, + THREE +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/graphdb/pom.xml ---------------------------------------------------------------------- diff --git a/graphdb/pom.xml b/graphdb/pom.xml new file mode 100644 index 0000000..666fe5a --- /dev/null +++ b/graphdb/pom.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +~ Licensed to the Apache Software Foundation (ASF) under one +~ or more contributor license agreements. See the NOTICE file +~ distributed with this work for additional information +~ regarding copyright ownership. The ASF licenses this file +~ to you under the Apache License, Version 2.0 (the +~ "License"); you may not use this file except in compliance +~ with the License. You may obtain a copy of the License at +~ +~ http://www.apache.org/licenses/LICENSE-2.0 +~ +~ Unless required by applicable law or agreed to in writing, software +~ distributed under the License is distributed on an "AS IS" BASIS, +~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +~ See the License for the specific language governing permissions and +~ limitations under the License. +--> + +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>apache-atlas</artifactId> + <groupId>org.apache.atlas</groupId> + <version>0.7-incubating-SNAPSHOT</version> + </parent> + + <artifactId>atlas-graphdb</artifactId> + <description>Apache Atlas Graph Database Projects</description> + <name>Apache Atlas Graph Database Projects</name> + <packaging>pom</packaging> + + <modules> + <module>api</module> + </modules> +</project> http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0606d80..5e2871e 100755 --- a/pom.xml +++ b/pom.xml @@ -460,6 +460,7 @@ <module>server-api</module> <module>notification</module> <module>client</module> + <module>graphdb</module> <module>titan</module> <module>repository</module> <!-- <module>dashboard</module> --> http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/91559578/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 6c04359..7e3149c 100644 --- a/release-log.txt +++ b/release-log.txt @@ -20,6 +20,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags) ALL CHANGES: +ATLAS-692 Create abstraction layer for graph databases (jnhagelb via yhemanth) ATLAS-689 Migrate Atlas-Storm integration to use Storm 1.0 dependencies. (svimal2106 via yhemanth) ATLAS-754 InstanceSerialization does not serialize Reference in the values array of Reference.(harishjp via sumasai) ATLAS-626 Hive temporary table metadata is captured in atlas (sumasai)
