Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
5273b41f
Commit
5273b41f
authored
Dec 11, 2014
by
Venkatesh Seetharam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed an issue with persisting to graph db. guava lib confilt. Contributed by Venkatesh Seetharam
parent
c8aabc11
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
57 deletions
+152
-57
pom.xml
pom.xml
+0
-6
GraphBackedMetadataRepositoryService.java
...tadata/services/GraphBackedMetadataRepositoryService.java
+64
-27
GraphService.java
...ava/org/apache/hadoop/metadata/services/GraphService.java
+1
-1
TitanGraphService.java
...rg/apache/hadoop/metadata/services/TitanGraphService.java
+21
-22
GraphUtils.java
...main/java/org/apache/hadoop/metadata/util/GraphUtils.java
+65
-0
GraphResource.java
...g/apache/hadoop/metadata/web/resources/GraphResource.java
+1
-1
No files found.
pom.xml
View file @
5273b41f
...
@@ -438,12 +438,6 @@
...
@@ -438,12 +438,6 @@
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
18.0
</version>
</dependency>
<dependency>
<groupId>
joda-time
</groupId>
<groupId>
joda-time
</groupId>
<artifactId>
joda-time
</artifactId>
<artifactId>
joda-time
</artifactId>
<version>
2.5
</version>
<version>
2.5
</version>
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/GraphBackedMetadataRepositoryService.java
View file @
5273b41f
...
@@ -19,16 +19,18 @@
...
@@ -19,16 +19,18 @@
package
org
.
apache
.
hadoop
.
metadata
.
services
;
package
org
.
apache
.
hadoop
.
metadata
.
services
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Preconditions
;
import
com.t
hinkaurelius.titan.core.Titan
Graph
;
import
com.t
inkerpop.blueprints.
Graph
;
import
com.tinkerpop.blueprints.GraphQuery
;
import
com.tinkerpop.blueprints.GraphQuery
;
import
com.tinkerpop.blueprints.TransactionalGraph
;
import
com.tinkerpop.blueprints.Vertex
;
import
com.tinkerpop.blueprints.Vertex
;
import
org.apache.hadoop.metadata.service.Services
;
import
org.apache.hadoop.metadata.service.Services
;
import
org.apache.hadoop.metadata.util.GraphUtils
;
import
org.json.simple.JSONValue
;
import
org.json.simple.JSONValue
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.
HashMap
;
import
java.util.
Collections
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -74,6 +76,7 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
...
@@ -74,6 +76,7 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
@Override
@Override
public
void
stop
()
{
public
void
stop
()
{
// do nothing
// do nothing
graphService
=
null
;
}
}
/**
/**
...
@@ -89,8 +92,12 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
...
@@ -89,8 +92,12 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
stop
();
stop
();
}
}
private
TitanGraph
getGraph
()
{
private
Graph
getBlueprintsGraph
()
{
return
((
TitanGraphService
)
graphService
).
getTitanGraph
();
return
graphService
.
getBlueprintsGraph
();
}
private
TransactionalGraph
getTransactionalGraph
()
{
return
graphService
.
getTransactionalGraph
();
}
}
@Override
@Override
...
@@ -103,18 +110,21 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
...
@@ -103,18 +110,21 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
// todo check if this is a duplicate
// todo check if this is a duplicate
final
String
guid
=
UUID
.
randomUUID
().
toString
();
final
String
guid
=
UUID
.
randomUUID
().
toString
();
final
TransactionalGraph
transactionalGraph
=
getTransactionalGraph
();
try
{
try
{
getGraph
().
newTransaction
();
transactionalGraph
.
rollback
();
Vertex
entityVertex
=
getGraph
()
.
addVertex
(
null
);
Vertex
entityVertex
=
transactionalGraph
.
addVertex
(
null
);
entityVertex
.
setProperty
(
"guid"
,
guid
);
entityVertex
.
setProperty
(
"guid"
,
guid
);
entityVertex
.
setProperty
(
"entityName"
,
entityName
);
entityVertex
.
setProperty
(
"entityName"
,
entityName
);
entityVertex
.
setProperty
(
"entityType"
,
entityType
);
entityVertex
.
setProperty
(
"entityType"
,
entityType
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
properties
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
properties
.
entrySet
())
{
entityVertex
.
setProperty
(
entry
.
getKey
(),
entry
.
getValue
());
entityVertex
.
setProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
}
catch
(
Exception
e
)
{
transactionalGraph
.
rollback
();
}
finally
{
}
finally
{
getGraph
()
.
commit
();
transactionalGraph
.
commit
();
}
}
return
guid
;
return
guid
;
...
@@ -122,36 +132,63 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
...
@@ -122,36 +132,63 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
@Override
@Override
public
String
getEntityDefinition
(
String
entityName
,
String
entityType
)
{
public
String
getEntityDefinition
(
String
entityName
,
String
entityType
)
{
Vertex
entityVertex
=
findVertex
(
entityName
,
entityType
);
Vertex
entityVertex
=
GraphUtils
.
findVertex
(
getBlueprintsGraph
(),
entityName
,
entityType
);
if
(
entityVertex
==
null
)
{
if
(
entityVertex
==
null
)
{
return
null
;
return
null
;
}
}
Map
<
String
,
String
>
properties
=
extractProperties
(
entityVertex
);
Map
<
String
,
String
>
properties
=
GraphUtils
.
extractProperties
(
entityVertex
);
return
JSONValue
.
toJSONString
(
properties
);
return
JSONValue
.
toJSONString
(
properties
);
}
}
protected
Vertex
findVertex
(
String
entityName
,
String
entityType
)
{
@Override
LOG
.
debug
(
"Finding vertex for: name={}, type={}"
,
entityName
,
entityType
);
public
List
<
String
>
getEntityList
(
String
entityType
)
{
return
Collections
.
emptyList
();
GraphQuery
query
=
getGraph
().
query
()
.
has
(
"entityName"
,
entityName
)
.
has
(
"entityType"
,
entityType
);
Iterator
<
Vertex
>
results
=
query
.
vertices
().
iterator
();
return
results
.
hasNext
()
?
results
.
next
()
:
null
;
// returning one since name/type is unique
}
}
private
Map
<
String
,
String
>
extractProperties
(
Vertex
entityVertex
)
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Map
<
String
,
String
>
properties
=
new
HashMap
<>();
TitanGraphService
titanGraphService
=
new
TitanGraphService
();
for
(
String
key
:
entityVertex
.
getPropertyKeys
())
{
titanGraphService
.
start
();
properties
.
put
(
key
,
String
.
valueOf
(
entityVertex
.
getProperty
(
key
)));
Services
.
get
().
register
(
titanGraphService
);
}
return
properties
;
GraphBackedMetadataRepositoryService
service
=
new
GraphBackedMetadataRepositoryService
();
}
try
{
service
.
start
();
String
guid
=
UUID
.
randomUUID
().
toString
();
final
TransactionalGraph
graph
=
service
.
getTransactionalGraph
();
System
.
out
.
println
(
"graph = "
+
graph
);
System
.
out
.
println
(
"graph.getVertices() = "
+
graph
.
getVertices
());
Vertex
entityVertex
=
null
;
try
{
graph
.
rollback
();
entityVertex
=
graph
.
addVertex
(
null
);
entityVertex
.
setProperty
(
"guid"
,
guid
);
entityVertex
.
setProperty
(
"entityName"
,
"entityName"
);
entityVertex
.
setProperty
(
"entityType"
,
"entityType"
);
}
catch
(
Exception
e
)
{
graph
.
rollback
();
e
.
printStackTrace
();
}
finally
{
graph
.
commit
();
}
@Override
System
.
out
.
println
(
"vertex = "
+
GraphUtils
.
vertexString
(
entityVertex
));
public
List
<
String
>
getEntityList
(
String
entityType
)
{
return
null
;
GraphQuery
query
=
graph
.
query
()
.
has
(
"entityName"
,
"entityName"
)
.
has
(
"entityType"
,
"entityType"
);
Iterator
<
Vertex
>
results
=
query
.
vertices
().
iterator
();
if
(
results
.
hasNext
())
{
Vertex
vertexFromQuery
=
results
.
next
();
System
.
out
.
println
(
"vertex = "
+
GraphUtils
.
vertexString
(
vertexFromQuery
));
}
}
finally
{
service
.
stop
();
titanGraphService
.
stop
();
}
}
}
}
}
repository/src/main/java/org/apache/hadoop/metadata/services/GraphService.java
View file @
5273b41f
...
@@ -35,7 +35,7 @@ public interface GraphService extends Service {
...
@@ -35,7 +35,7 @@ public interface GraphService extends Service {
*
*
* @return an handle to the graph db
* @return an handle to the graph db
*/
*/
Graph
getGraph
();
Graph
get
Blueprints
Graph
();
KeyIndexableGraph
getIndexableGraph
();
KeyIndexableGraph
getIndexableGraph
();
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/TitanGraphService.java
View file @
5273b41f
...
@@ -23,7 +23,6 @@ import com.thinkaurelius.titan.core.PropertyKey;
...
@@ -23,7 +23,6 @@ import com.thinkaurelius.titan.core.PropertyKey;
import
com.thinkaurelius.titan.core.TitanFactory
;
import
com.thinkaurelius.titan.core.TitanFactory
;
import
com.thinkaurelius.titan.core.TitanGraph
;
import
com.thinkaurelius.titan.core.TitanGraph
;
import
com.thinkaurelius.titan.core.schema.TitanManagement
;
import
com.thinkaurelius.titan.core.schema.TitanManagement
;
import
com.thinkaurelius.titan.graphdb.blueprints.TitanBlueprintsGraph
;
import
com.tinkerpop.blueprints.Edge
;
import
com.tinkerpop.blueprints.Edge
;
import
com.tinkerpop.blueprints.Element
;
import
com.tinkerpop.blueprints.Element
;
import
com.tinkerpop.blueprints.Graph
;
import
com.tinkerpop.blueprints.Graph
;
...
@@ -51,11 +50,11 @@ public class TitanGraphService implements GraphService {
...
@@ -51,11 +50,11 @@ public class TitanGraphService implements GraphService {
/**
/**
* Constant for the configuration property that indicates the prefix.
* Constant for the configuration property that indicates the prefix.
*/
*/
private
static
final
String
METADATA_PREFIX
=
"metadata.
g
raph."
;
private
static
final
String
METADATA_PREFIX
=
"metadata.
titanG
raph."
;
private
static
final
String
METADATA_INDEX_KEY
=
"index.name"
;
private
static
final
String
METADATA_INDEX_KEY
=
"index.name"
;
private
Configuration
graphConfig
;
private
Configuration
graphConfig
;
private
Graph
g
raph
;
private
TitanGraph
titanG
raph
;
private
Set
<
String
>
vertexIndexedKeys
;
private
Set
<
String
>
vertexIndexedKeys
;
private
Set
<
String
>
edgeIndexedKeys
;
private
Set
<
String
>
edgeIndexedKeys
;
...
@@ -76,13 +75,13 @@ public class TitanGraphService implements GraphService {
...
@@ -76,13 +75,13 @@ public class TitanGraphService implements GraphService {
*/
*/
@Override
@Override
public
void
start
()
throws
Exception
{
public
void
start
()
throws
Exception
{
graphConfig
=
getConfiguration
();
//
graphConfig = getConfiguration();
g
raph
=
initializeGraphDB
();
titanG
raph
=
initializeGraphDB
();
// createIndicesForVertexKeys();
// createIndicesForVertexKeys();
// todo - create Edge Cardinality Constraints
// todo - create Edge Cardinality Constraints
LOG
.
info
(
"Initialized
graph db: {}"
,
g
raph
);
LOG
.
info
(
"Initialized
titanGraph db: {}"
,
titanG
raph
);
vertexIndexedKeys
=
getIndexableGraph
().
getIndexedKeys
(
Vertex
.
class
);
vertexIndexedKeys
=
getIndexableGraph
().
getIndexedKeys
(
Vertex
.
class
);
LOG
.
info
(
"Init vertex property keys: {}"
,
vertexIndexedKeys
);
LOG
.
info
(
"Init vertex property keys: {}"
,
vertexIndexedKeys
);
...
@@ -91,12 +90,14 @@ public class TitanGraphService implements GraphService {
...
@@ -91,12 +90,14 @@ public class TitanGraphService implements GraphService {
LOG
.
info
(
"Init edge property keys: {}"
,
edgeIndexedKeys
);
LOG
.
info
(
"Init edge property keys: {}"
,
edgeIndexedKeys
);
}
}
protected
Graph
initializeGraphDB
()
{
protected
TitanGraph
initializeGraphDB
()
{
LOG
.
info
(
"Initializing graph db"
);
LOG
.
info
(
"Initializing titanGraph db"
);
// return GraphFactory.open(graphConfig);
// todo: externalize this
Configuration
graphConfig
=
new
PropertiesConfiguration
();
Configuration
graphConfig
=
new
PropertiesConfiguration
();
graphConfig
.
setProperty
(
"storage.backend"
,
"berkeleyje"
);
graphConfig
.
setProperty
(
"storage.backend"
,
"berkeleyje"
);
graphConfig
.
setProperty
(
"storage.directory"
,
"target/data/graphdb"
);
graphConfig
.
setProperty
(
"storage.directory"
,
"target/data/graphdb"
);
return
TitanFactory
.
open
(
graphConfig
);
return
TitanFactory
.
open
(
graphConfig
);
}
}
...
@@ -124,12 +125,12 @@ public class TitanGraphService implements GraphService {
...
@@ -124,12 +125,12 @@ public class TitanGraphService implements GraphService {
* com.tinkerpop.blueprints.KeyIndexableGraph#createKeyIndex does not create an index.
* com.tinkerpop.blueprints.KeyIndexableGraph#createKeyIndex does not create an index.
*/
*/
protected
void
createIndicesForVertexKeys
()
{
protected
void
createIndicesForVertexKeys
()
{
if
(!((
KeyIndexableGraph
)
g
raph
).
getIndexedKeys
(
Vertex
.
class
).
isEmpty
())
{
if
(!((
KeyIndexableGraph
)
titanG
raph
).
getIndexedKeys
(
Vertex
.
class
).
isEmpty
())
{
LOG
.
info
(
"Indexes already exist for
g
raph"
);
LOG
.
info
(
"Indexes already exist for
titanG
raph"
);
return
;
return
;
}
}
LOG
.
info
(
"Indexes does not exist, Creating indexes for
g
raph"
);
LOG
.
info
(
"Indexes does not exist, Creating indexes for
titanG
raph"
);
// todo - externalize this
// todo - externalize this
String
indexName
=
graphConfig
.
getString
(
METADATA_INDEX_KEY
);
String
indexName
=
graphConfig
.
getString
(
METADATA_INDEX_KEY
);
PropertyKey
guid
=
createPropertyKey
(
"guid"
,
String
.
class
,
Cardinality
.
SINGLE
);
PropertyKey
guid
=
createPropertyKey
(
"guid"
,
String
.
class
,
Cardinality
.
SINGLE
);
...
@@ -169,7 +170,9 @@ public class TitanGraphService implements GraphService {
...
@@ -169,7 +170,9 @@ public class TitanGraphService implements GraphService {
*/
*/
@Override
@Override
public
void
stop
()
{
public
void
stop
()
{
if
(
titanGraph
!=
null
)
{
titanGraph
.
shutdown
();
}
}
}
/**
/**
...
@@ -186,26 +189,22 @@ public class TitanGraphService implements GraphService {
...
@@ -186,26 +189,22 @@ public class TitanGraphService implements GraphService {
}
}
@Override
@Override
public
Graph
getGraph
()
{
public
Graph
get
Blueprints
Graph
()
{
return
g
raph
;
return
titanG
raph
;
}
}
@Override
@Override
public
KeyIndexableGraph
getIndexableGraph
()
{
public
KeyIndexableGraph
getIndexableGraph
()
{
return
(
KeyIndexableGraph
)
g
raph
;
return
titanG
raph
;
}
}
@Override
@Override
public
TransactionalGraph
getTransactionalGraph
()
{
public
TransactionalGraph
getTransactionalGraph
()
{
return
(
TransactionalGraph
)
graph
;
return
titanGraph
;
}
protected
TitanBlueprintsGraph
getTitanBlueprintsGraph
()
{
return
(
TitanBlueprintsGraph
)
graph
;
}
}
public
TitanGraph
getTitanGraph
()
{
public
TitanGraph
getTitanGraph
()
{
return
(
TitanGraph
)
g
raph
;
return
titanG
raph
;
}
}
@Override
@Override
...
...
repository/src/main/java/org/apache/hadoop/metadata/util/GraphUtils.java
0 → 100644
View file @
5273b41f
package
org
.
apache
.
hadoop
.
metadata
.
util
;
import
com.tinkerpop.blueprints.Direction
;
import
com.tinkerpop.blueprints.Edge
;
import
com.tinkerpop.blueprints.Graph
;
import
com.tinkerpop.blueprints.GraphQuery
;
import
com.tinkerpop.blueprints.Vertex
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
/**
* Utility class for graph operations.
*/
public
final
class
GraphUtils
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GraphUtils
.
class
);
private
GraphUtils
()
{
}
public
static
Vertex
findVertex
(
Graph
blueprintsGraph
,
String
entityName
,
String
entityType
)
{
LOG
.
debug
(
"Finding vertex for: name={}, type={}"
,
entityName
,
entityType
);
GraphQuery
query
=
blueprintsGraph
.
query
()
.
has
(
"entityName"
,
entityName
)
.
has
(
"entityType"
,
entityType
);
Iterator
<
Vertex
>
results
=
query
.
vertices
().
iterator
();
// returning one since name/type is unique
return
results
.
hasNext
()
?
results
.
next
()
:
null
;
}
public
static
Map
<
String
,
String
>
extractProperties
(
Vertex
entityVertex
)
{
Map
<
String
,
String
>
properties
=
new
HashMap
<>();
for
(
String
key
:
entityVertex
.
getPropertyKeys
())
{
properties
.
put
(
key
,
String
.
valueOf
(
entityVertex
.
getProperty
(
key
)));
}
return
properties
;
}
public
static
String
vertexString
(
final
Vertex
vertex
)
{
StringBuilder
properties
=
new
StringBuilder
();
for
(
String
propertyKey
:
vertex
.
getPropertyKeys
())
{
properties
.
append
(
propertyKey
)
.
append
(
"="
).
append
(
vertex
.
getProperty
(
propertyKey
))
.
append
(
", "
);
}
return
"v["
+
vertex
.
getId
()
+
"], Properties["
+
properties
+
"]"
;
}
public
static
String
edgeString
(
final
Edge
edge
)
{
return
"e["
+
edge
.
getLabel
()
+
"], ["
+
edge
.
getVertex
(
Direction
.
OUT
).
getProperty
(
"name"
)
+
" -> "
+
edge
.
getLabel
()
+
" -> "
+
edge
.
getVertex
(
Direction
.
IN
).
getProperty
(
"name"
)
+
"]"
;
}
}
\ No newline at end of file
webapp/src/main/java/org/apache/hadoop/metadata/web/resources/GraphResource.java
View file @
5273b41f
...
@@ -75,7 +75,7 @@ public class GraphResource {
...
@@ -75,7 +75,7 @@ public class GraphResource {
}
}
protected
Graph
getGraph
()
{
protected
Graph
getGraph
()
{
return
graphService
.
getGraph
();
return
graphService
.
get
Blueprints
Graph
();
}
}
protected
Set
<
String
>
getVertexIndexedKeys
()
{
protected
Set
<
String
>
getVertexIndexedKeys
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment