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
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
151 additions
and
56 deletions
+151
-56
pom.xml
pom.xml
+0
-6
GraphBackedMetadataRepositoryService.java
...tadata/services/GraphBackedMetadataRepositoryService.java
+63
-26
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 @@
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
18.0
</version>
</dependency>
<dependency>
<groupId>
joda-time
</groupId>
<artifactId>
joda-time
</artifactId>
<version>
2.5
</version>
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/GraphBackedMetadataRepositoryService.java
View file @
5273b41f
...
...
@@ -19,16 +19,18 @@
package
org
.
apache
.
hadoop
.
metadata
.
services
;
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.TransactionalGraph
;
import
com.tinkerpop.blueprints.Vertex
;
import
org.apache.hadoop.metadata.service.Services
;
import
org.apache.hadoop.metadata.util.GraphUtils
;
import
org.json.simple.JSONValue
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.util.
HashMap
;
import
java.util.
Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -74,6 +76,7 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
@Override
public
void
stop
()
{
// do nothing
graphService
=
null
;
}
/**
...
...
@@ -89,8 +92,12 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
stop
();
}
private
TitanGraph
getGraph
()
{
return
((
TitanGraphService
)
graphService
).
getTitanGraph
();
private
Graph
getBlueprintsGraph
()
{
return
graphService
.
getBlueprintsGraph
();
}
private
TransactionalGraph
getTransactionalGraph
()
{
return
graphService
.
getTransactionalGraph
();
}
@Override
...
...
@@ -103,18 +110,21 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
// todo check if this is a duplicate
final
String
guid
=
UUID
.
randomUUID
().
toString
();
final
TransactionalGraph
transactionalGraph
=
getTransactionalGraph
();
try
{
getGraph
().
newTransaction
();
transactionalGraph
.
rollback
();
Vertex
entityVertex
=
getGraph
()
.
addVertex
(
null
);
Vertex
entityVertex
=
transactionalGraph
.
addVertex
(
null
);
entityVertex
.
setProperty
(
"guid"
,
guid
);
entityVertex
.
setProperty
(
"entityName"
,
entityName
);
entityVertex
.
setProperty
(
"entityType"
,
entityType
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
properties
.
entrySet
())
{
entityVertex
.
setProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
catch
(
Exception
e
)
{
transactionalGraph
.
rollback
();
}
finally
{
getGraph
()
.
commit
();
transactionalGraph
.
commit
();
}
return
guid
;
...
...
@@ -122,36 +132,63 @@ public class GraphBackedMetadataRepositoryService implements MetadataRepositoryS
@Override
public
String
getEntityDefinition
(
String
entityName
,
String
entityType
)
{
Vertex
entityVertex
=
findVertex
(
entityName
,
entityType
);
Vertex
entityVertex
=
GraphUtils
.
findVertex
(
getBlueprintsGraph
(),
entityName
,
entityType
);
if
(
entityVertex
==
null
)
{
return
null
;
}
Map
<
String
,
String
>
properties
=
extractProperties
(
entityVertex
);
Map
<
String
,
String
>
properties
=
GraphUtils
.
extractProperties
(
entityVertex
);
return
JSONValue
.
toJSONString
(
properties
);
}
protected
Vertex
findVertex
(
String
entityName
,
String
entityType
)
{
LOG
.
debug
(
"Finding vertex for: name={}, type={}"
,
entityName
,
entityType
);
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
@Override
public
List
<
String
>
getEntityList
(
String
entityType
)
{
return
Collections
.
emptyList
();
}
private
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
)));
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
TitanGraphService
titanGraphService
=
new
TitanGraphService
();
titanGraphService
.
start
();
Services
.
get
().
register
(
titanGraphService
);
GraphBackedMetadataRepositoryService
service
=
new
GraphBackedMetadataRepositoryService
();
try
{
service
.
start
();
String
guid
=
UUID
.
randomUUID
().
toString
();
return
properties
;
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
public
List
<
String
>
getEntityList
(
String
entityType
)
{
return
null
;
System
.
out
.
println
(
"vertex = "
+
GraphUtils
.
vertexString
(
entityVertex
));
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 {
*
* @return an handle to the graph db
*/
Graph
getGraph
();
Graph
get
Blueprints
Graph
();
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;
import
com.thinkaurelius.titan.core.TitanFactory
;
import
com.thinkaurelius.titan.core.TitanGraph
;
import
com.thinkaurelius.titan.core.schema.TitanManagement
;
import
com.thinkaurelius.titan.graphdb.blueprints.TitanBlueprintsGraph
;
import
com.tinkerpop.blueprints.Edge
;
import
com.tinkerpop.blueprints.Element
;
import
com.tinkerpop.blueprints.Graph
;
...
...
@@ -51,11 +50,11 @@ public class TitanGraphService implements GraphService {
/**
* 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
Configuration
graphConfig
;
private
Graph
g
raph
;
private
TitanGraph
titanG
raph
;
private
Set
<
String
>
vertexIndexedKeys
;
private
Set
<
String
>
edgeIndexedKeys
;
...
...
@@ -76,13 +75,13 @@ public class TitanGraphService implements GraphService {
*/
@Override
public
void
start
()
throws
Exception
{
graphConfig
=
getConfiguration
();
//
graphConfig = getConfiguration();
g
raph
=
initializeGraphDB
();
titanG
raph
=
initializeGraphDB
();
// createIndicesForVertexKeys();
// todo - create Edge Cardinality Constraints
LOG
.
info
(
"Initialized
graph db: {}"
,
g
raph
);
LOG
.
info
(
"Initialized
titanGraph db: {}"
,
titanG
raph
);
vertexIndexedKeys
=
getIndexableGraph
().
getIndexedKeys
(
Vertex
.
class
);
LOG
.
info
(
"Init vertex property keys: {}"
,
vertexIndexedKeys
);
...
...
@@ -91,12 +90,14 @@ public class TitanGraphService implements GraphService {
LOG
.
info
(
"Init edge property keys: {}"
,
edgeIndexedKeys
);
}
protected
Graph
initializeGraphDB
()
{
LOG
.
info
(
"Initializing graph db"
);
// return GraphFactory.open(graphConfig);
protected
TitanGraph
initializeGraphDB
()
{
LOG
.
info
(
"Initializing titanGraph db"
);
// todo: externalize this
Configuration
graphConfig
=
new
PropertiesConfiguration
();
graphConfig
.
setProperty
(
"storage.backend"
,
"berkeleyje"
);
graphConfig
.
setProperty
(
"storage.directory"
,
"target/data/graphdb"
);
return
TitanFactory
.
open
(
graphConfig
);
}
...
...
@@ -124,12 +125,12 @@ public class TitanGraphService implements GraphService {
* com.tinkerpop.blueprints.KeyIndexableGraph#createKeyIndex does not create an index.
*/
protected
void
createIndicesForVertexKeys
()
{
if
(!((
KeyIndexableGraph
)
g
raph
).
getIndexedKeys
(
Vertex
.
class
).
isEmpty
())
{
LOG
.
info
(
"Indexes already exist for
g
raph"
);
if
(!((
KeyIndexableGraph
)
titanG
raph
).
getIndexedKeys
(
Vertex
.
class
).
isEmpty
())
{
LOG
.
info
(
"Indexes already exist for
titanG
raph"
);
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
String
indexName
=
graphConfig
.
getString
(
METADATA_INDEX_KEY
);
PropertyKey
guid
=
createPropertyKey
(
"guid"
,
String
.
class
,
Cardinality
.
SINGLE
);
...
...
@@ -169,7 +170,9 @@ public class TitanGraphService implements GraphService {
*/
@Override
public
void
stop
()
{
if
(
titanGraph
!=
null
)
{
titanGraph
.
shutdown
();
}
}
/**
...
...
@@ -186,26 +189,22 @@ public class TitanGraphService implements GraphService {
}
@Override
public
Graph
getGraph
()
{
return
g
raph
;
public
Graph
get
Blueprints
Graph
()
{
return
titanG
raph
;
}
@Override
public
KeyIndexableGraph
getIndexableGraph
()
{
return
(
KeyIndexableGraph
)
g
raph
;
return
titanG
raph
;
}
@Override
public
TransactionalGraph
getTransactionalGraph
()
{
return
(
TransactionalGraph
)
graph
;
}
protected
TitanBlueprintsGraph
getTitanBlueprintsGraph
()
{
return
(
TitanBlueprintsGraph
)
graph
;
return
titanGraph
;
}
public
TitanGraph
getTitanGraph
()
{
return
(
TitanGraph
)
g
raph
;
return
titanG
raph
;
}
@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 {
}
protected
Graph
getGraph
()
{
return
graphService
.
getGraph
();
return
graphService
.
get
Blueprints
Graph
();
}
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