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
39c84bd6
Commit
39c84bd6
authored
Feb 02, 2015
by
Venkatesh Seetharam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move search to Discovery interface from repository. Contributed by Venkatesh Seetharam
parent
18981168
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
220 additions
and
380 deletions
+220
-380
GraphBackedDiscoveryService.java
...adoop/metadata/discovery/GraphBackedDiscoveryService.java
+0
-0
MetadataRepository.java
...apache/hadoop/metadata/repository/MetadataRepository.java
+0
-35
GraphBackedMetadataRepository.java
...adata/repository/graph/GraphBackedMetadataRepository.java
+0
-226
TestUtils.java
...y/src/test/java/org/apache/hadoop/metadata/TestUtils.java
+129
-0
GraphBackedDiscoveryServiceTest.java
...p/metadata/discovery/GraphBackedDiscoveryServiceTest.java
+88
-0
GraphBackedMetadataRepositoryTest.java
...a/repository/graph/GraphBackedMetadataRepositoryTest.java
+3
-119
No files found.
repository/src/main/java/org/apache/hadoop/metadata/discovery/GraphBackedDiscoveryService.java
View file @
39c84bd6
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/hadoop/metadata/repository/MetadataRepository.java
View file @
39c84bd6
...
@@ -20,15 +20,10 @@ package org.apache.hadoop.metadata.repository;
...
@@ -20,15 +20,10 @@ package org.apache.hadoop.metadata.repository;
import
org.apache.hadoop.metadata.IReferenceableInstance
;
import
org.apache.hadoop.metadata.IReferenceableInstance
;
import
org.apache.hadoop.metadata.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.MetadataException
;
import
org.apache.hadoop.metadata.service.Service
;
import
org.apache.hadoop.metadata.service.Service
;
import
org.apache.hadoop.metadata.storage.RepositoryException
;
import
org.apache.hadoop.metadata.storage.RepositoryException
;
import
org.codehaus.jettison.json.JSONObject
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
/**
* An interface for persisting metadata into a blueprints enabled graph db.
* An interface for persisting metadata into a blueprints enabled graph db.
...
@@ -41,34 +36,4 @@ public interface MetadataRepository extends Service {
...
@@ -41,34 +36,4 @@ public interface MetadataRepository extends Service {
ITypedReferenceableInstance
getEntityDefinition
(
String
guid
)
throws
RepositoryException
;
ITypedReferenceableInstance
getEntityDefinition
(
String
guid
)
throws
RepositoryException
;
List
<
String
>
getEntityList
(
String
entityType
)
throws
RepositoryException
;
List
<
String
>
getEntityList
(
String
entityType
)
throws
RepositoryException
;
/**
* Assumes the User is familiar with the persistence structure of the Repository.
* The given query is run uninterpreted against the underlying Graph Store.
* The results are returned as a List of Rows. each row is a Map of Key,Value pairs.
*
* @param gremlinQuery query in gremlin dsl format
* @return List of Maps
* @throws org.apache.hadoop.metadata.MetadataException
*/
List
<
Map
<
String
,
String
>>
searchByGremlin
(
String
gremlinQuery
)
throws
MetadataException
;
/**
* Simple direct graph search and depth traversal.
* @param searchText is plain text
* @param prop is the Vertex property to search.
*/
Map
<
String
,
HashMap
<
String
,
JSONObject
>>
textSearch
(
String
searchText
,
int
depth
,
String
prop
);
/**
* Simple graph walker for search interface, which allows following of specific edges only.
* @param edgesToFollow is a comma-separated-list of edges to follow.
*/
Map
<
String
,
HashMap
<
String
,
JSONObject
>>
relationshipWalk
(
String
guid
,
int
depth
,
String
edgesToFollow
);
/**
* Return a Set of indexed properties in the graph.
* No parameters.
*/
Set
<
String
>
getGraphIndexedFields
();
}
}
repository/src/main/java/org/apache/hadoop/metadata/repository/graph/GraphBackedMetadataRepository.java
View file @
39c84bd6
This diff is collapsed.
Click to expand it.
repository/src/test/java/org/apache/hadoop/metadata/TestUtils.java
0 → 100644
View file @
39c84bd6
/**
* 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
.
hadoop
.
metadata
;
import
com.google.common.collect.ImmutableList
;
import
org.apache.hadoop.metadata.types.AttributeDefinition
;
import
org.apache.hadoop.metadata.types.ClassType
;
import
org.apache.hadoop.metadata.types.DataTypes
;
import
org.apache.hadoop.metadata.types.HierarchicalTypeDefinition
;
import
org.apache.hadoop.metadata.types.IDataType
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.StructTypeDefinition
;
import
org.apache.hadoop.metadata.types.TraitType
;
import
org.apache.hadoop.metadata.types.TypeSystem
;
import
org.testng.Assert
;
/**
* Test utility class.
*/
public
final
class
TestUtils
{
private
TestUtils
()
{
}
/**
* Class Hierarchy is:
* Department(name : String, employees : Array[Person])
* Person(name : String, department : Department, manager : Manager)
* Manager(subordinates : Array[Person]) extends Person
* <p/>
* Persons can have SecurityClearance(level : Int) clearance.
*/
public
static
void
defineDeptEmployeeTypes
(
TypeSystem
ts
)
throws
MetadataException
{
HierarchicalTypeDefinition
<
ClassType
>
deptTypeDef
=
createClassTypeDef
(
"Department"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"employees"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
true
,
"department"
)
);
HierarchicalTypeDefinition
<
ClassType
>
personTypeDef
=
createClassTypeDef
(
"Person"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"department"
,
"Department"
,
Multiplicity
.
REQUIRED
,
false
,
"employees"
),
new
AttributeDefinition
(
"manager"
,
"Manager"
,
Multiplicity
.
OPTIONAL
,
false
,
"subordinates"
)
);
HierarchicalTypeDefinition
<
ClassType
>
managerTypeDef
=
createClassTypeDef
(
"Manager"
,
ImmutableList
.
of
(
"Person"
),
new
AttributeDefinition
(
"subordinates"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
false
,
"manager"
)
);
HierarchicalTypeDefinition
<
TraitType
>
securityClearanceTypeDef
=
createTraitTypeDef
(
"SecurityClearance"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"level"
,
DataTypes
.
INT_TYPE
)
);
ts
.
defineTypes
(
ImmutableList
.<
StructTypeDefinition
>
of
(),
ImmutableList
.
of
(
securityClearanceTypeDef
),
ImmutableList
.
of
(
deptTypeDef
,
personTypeDef
,
managerTypeDef
));
}
public
static
Referenceable
createDeptEg1
(
TypeSystem
ts
)
throws
MetadataException
{
Referenceable
hrDept
=
new
Referenceable
(
"Department"
);
Referenceable
john
=
new
Referenceable
(
"Person"
);
Referenceable
jane
=
new
Referenceable
(
"Manager"
,
"SecurityClearance"
);
hrDept
.
set
(
"name"
,
"hr"
);
john
.
set
(
"name"
,
"John"
);
john
.
set
(
"department"
,
hrDept
);
jane
.
set
(
"name"
,
"Jane"
);
jane
.
set
(
"department"
,
hrDept
);
john
.
set
(
"manager"
,
jane
);
hrDept
.
set
(
"employees"
,
ImmutableList
.
of
(
john
,
jane
));
jane
.
set
(
"subordinates"
,
ImmutableList
.
of
(
john
));
jane
.
getTrait
(
"SecurityClearance"
).
set
(
"level"
,
1
);
ClassType
deptType
=
ts
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
Assert
.
assertNotNull
(
hrDept2
);
return
hrDept
;
}
public
static
AttributeDefinition
createRequiredAttrDef
(
String
name
,
IDataType
dataType
)
{
return
new
AttributeDefinition
(
name
,
dataType
.
getName
(),
Multiplicity
.
REQUIRED
,
false
,
null
);
}
@SuppressWarnings
(
"unchecked"
)
public
static
HierarchicalTypeDefinition
<
TraitType
>
createTraitTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeDefinition
...
attrDefs
)
{
return
new
HierarchicalTypeDefinition
(
TraitType
.
class
,
name
,
superTypes
,
attrDefs
);
}
@SuppressWarnings
(
"unchecked"
)
public
static
HierarchicalTypeDefinition
<
ClassType
>
createClassTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeDefinition
...
attrDefs
)
{
return
new
HierarchicalTypeDefinition
(
ClassType
.
class
,
name
,
superTypes
,
attrDefs
);
}
}
repository/src/test/java/org/apache/hadoop/metadata/discovery/GraphBackedDiscoveryServiceTest.java
0 → 100644
View file @
39c84bd6
/**
* 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
.
hadoop
.
metadata
.
discovery
;
import
org.apache.hadoop.metadata.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.Referenceable
;
import
org.apache.hadoop.metadata.RepositoryMetadataModule
;
import
org.apache.hadoop.metadata.TestUtils
;
import
org.apache.hadoop.metadata.repository.graph.GraphBackedMetadataRepository
;
import
org.apache.hadoop.metadata.types.ClassType
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.TypeSystem
;
import
org.testng.annotations.AfterMethod
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Guice
;
import
org.testng.annotations.Test
;
import
javax.inject.Inject
;
@Guice
(
modules
=
RepositoryMetadataModule
.
class
)
public
class
GraphBackedDiscoveryServiceTest
{
private
TypeSystem
typeSystem
;
@Inject
private
GraphBackedMetadataRepository
repositoryService
;
@Inject
private
GraphBackedDiscoveryService
discoveryService
;
@BeforeMethod
public
void
setUp
()
throws
Exception
{
typeSystem
=
TypeSystem
.
getInstance
();
}
@AfterMethod
public
void
tearDown
()
throws
Exception
{
}
@Test
public
void
testRawSearch1
()
throws
Exception
{
Referenceable
hrDept
=
TestUtils
.
createDeptEg1
(
typeSystem
);
ClassType
deptType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
repositoryService
.
createEntity
(
hrDept2
,
"Department"
);
// Query for all Vertices in Graph
Object
r
=
discoveryService
.
searchByGremlin
(
"g.V.toList()"
);
System
.
out
.
println
(
"search result = "
+
r
);
// Query for all Vertices of a Type
r
=
discoveryService
.
searchByGremlin
(
"g.V.filter{it.typeName == 'Department'}.toList()"
);
System
.
out
.
println
(
"search result = "
+
r
);
// Property Query: list all Person names
r
=
discoveryService
.
searchByGremlin
(
"g.V.filter{it.typeName == 'Person'}.'Person.name'.toList()"
);
System
.
out
.
println
(
"search result = "
+
r
);
}
@Test
public
void
testTextSearch
()
throws
Exception
{
}
@Test
public
void
testRelationshipWalk
()
throws
Exception
{
}
}
\ No newline at end of file
repository/src/test/java/org/apache/hadoop/metadata/repository/graph/GraphBackedMetadataRepositoryTest.java
View file @
39c84bd6
...
@@ -18,23 +18,16 @@
...
@@ -18,23 +18,16 @@
package
org
.
apache
.
hadoop
.
metadata
.
repository
.
graph
;
package
org
.
apache
.
hadoop
.
metadata
.
repository
.
graph
;
import
com.google.common.collect.ImmutableList
;
import
com.thinkaurelius.titan.core.TitanGraph
;
import
com.thinkaurelius.titan.core.TitanGraph
;
import
com.tinkerpop.blueprints.Direction
;
import
com.tinkerpop.blueprints.Direction
;
import
com.tinkerpop.blueprints.Edge
;
import
com.tinkerpop.blueprints.Edge
;
import
com.tinkerpop.blueprints.Vertex
;
import
com.tinkerpop.blueprints.Vertex
;
import
org.apache.hadoop.metadata.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.MetadataException
;
import
org.apache.hadoop.metadata.Referenceable
;
import
org.apache.hadoop.metadata.Referenceable
;
import
org.apache.hadoop.metadata.RepositoryMetadataModule
;
import
org.apache.hadoop.metadata.RepositoryMetadataModule
;
import
org.apache.hadoop.metadata.
types.AttributeDefinition
;
import
org.apache.hadoop.metadata.
TestUtils
;
import
org.apache.hadoop.metadata.types.ClassType
;
import
org.apache.hadoop.metadata.types.ClassType
;
import
org.apache.hadoop.metadata.types.DataTypes
;
import
org.apache.hadoop.metadata.types.HierarchicalTypeDefinition
;
import
org.apache.hadoop.metadata.types.IDataType
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.StructTypeDefinition
;
import
org.apache.hadoop.metadata.types.TraitType
;
import
org.apache.hadoop.metadata.types.TypeSystem
;
import
org.apache.hadoop.metadata.types.TypeSystem
;
import
org.testng.Assert
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.BeforeClass
;
...
@@ -74,12 +67,12 @@ public class GraphBackedMetadataRepositoryTest {
...
@@ -74,12 +67,12 @@ public class GraphBackedMetadataRepositoryTest {
ts
=
TypeSystem
.
getInstance
();
ts
=
TypeSystem
.
getInstance
();
defineDeptEmployeeTypes
(
ts
);
TestUtils
.
defineDeptEmployeeTypes
(
ts
);
}
}
@Test
@Test
public
void
testSubmitEntity
()
throws
Exception
{
public
void
testSubmitEntity
()
throws
Exception
{
Referenceable
hrDept
=
createDeptEg1
(
ts
);
Referenceable
hrDept
=
TestUtils
.
createDeptEg1
(
ts
);
ClassType
deptType
=
ts
.
getDataType
(
ClassType
.
class
,
"Department"
);
ClassType
deptType
=
ts
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
...
@@ -118,113 +111,4 @@ public class GraphBackedMetadataRepositoryTest {
...
@@ -118,113 +111,4 @@ public class GraphBackedMetadataRepositoryTest {
Assert
.
assertNotNull
(
entityList
);
Assert
.
assertNotNull
(
entityList
);
Assert
.
assertEquals
(
entityList
.
size
(),
1
);
// one department
Assert
.
assertEquals
(
entityList
.
size
(),
1
);
// one department
}
}
@Test
public
void
testRawSearch1
()
throws
Exception
{
Referenceable
hrDept
=
createDeptEg1
(
ts
);
ClassType
deptType
=
ts
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
guid
=
repositoryService
.
createEntity
(
hrDept2
,
ENTITY_TYPE
);
// Query for all Vertices in Graph
Object
r
=
repositoryService
.
searchByGremlin
(
"g.V.toList()"
);
System
.
out
.
println
(
"search result = "
+
r
);
// Query for all Vertices of a Type
r
=
repositoryService
.
searchByGremlin
(
"g.V.filter{it.typeName == 'Department'}.toList()"
);
System
.
out
.
println
(
"search result = "
+
r
);
// Property Query: list all Person names
r
=
repositoryService
.
searchByGremlin
(
"g.V.filter{it.typeName == 'Person'}.'Person.name'.toList()"
);
System
.
out
.
println
(
"search result = "
+
r
);
}
/*
* Class Hierarchy is:
* Department(name : String, employees : Array[Person])
* Person(name : String, department : Department, manager : Manager)
* Manager(subordinates : Array[Person]) extends Person
*
* Persons can have SecurityClearance(level : Int) clearance.
*/
protected
void
defineDeptEmployeeTypes
(
TypeSystem
ts
)
throws
MetadataException
{
HierarchicalTypeDefinition
<
ClassType
>
deptTypeDef
=
createClassTypeDef
(
"Department"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"employees"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
true
,
"department"
)
);
HierarchicalTypeDefinition
<
ClassType
>
personTypeDef
=
createClassTypeDef
(
"Person"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
"department"
,
"Department"
,
Multiplicity
.
REQUIRED
,
false
,
"employees"
),
new
AttributeDefinition
(
"manager"
,
"Manager"
,
Multiplicity
.
OPTIONAL
,
false
,
"subordinates"
)
);
HierarchicalTypeDefinition
<
ClassType
>
managerTypeDef
=
createClassTypeDef
(
"Manager"
,
ImmutableList
.
of
(
"Person"
),
new
AttributeDefinition
(
"subordinates"
,
String
.
format
(
"array<%s>"
,
"Person"
),
Multiplicity
.
COLLECTION
,
false
,
"manager"
)
);
HierarchicalTypeDefinition
<
TraitType
>
securityClearanceTypeDef
=
createTraitTypeDef
(
"SecurityClearance"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"level"
,
DataTypes
.
INT_TYPE
)
);
ts
.
defineTypes
(
ImmutableList
.<
StructTypeDefinition
>
of
(),
ImmutableList
.
of
(
securityClearanceTypeDef
),
ImmutableList
.
of
(
deptTypeDef
,
personTypeDef
,
managerTypeDef
));
}
protected
Referenceable
createDeptEg1
(
TypeSystem
ts
)
throws
MetadataException
{
Referenceable
hrDept
=
new
Referenceable
(
"Department"
);
Referenceable
john
=
new
Referenceable
(
"Person"
);
Referenceable
jane
=
new
Referenceable
(
"Manager"
,
"SecurityClearance"
);
hrDept
.
set
(
"name"
,
"hr"
);
john
.
set
(
"name"
,
"John"
);
john
.
set
(
"department"
,
hrDept
);
jane
.
set
(
"name"
,
"Jane"
);
jane
.
set
(
"department"
,
hrDept
);
john
.
set
(
"manager"
,
jane
);
hrDept
.
set
(
"employees"
,
ImmutableList
.
of
(
john
,
jane
));
jane
.
set
(
"subordinates"
,
ImmutableList
.
of
(
john
));
jane
.
getTrait
(
"SecurityClearance"
).
set
(
"level"
,
1
);
ClassType
deptType
=
ts
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
Assert
.
assertNotNull
(
hrDept2
);
return
hrDept
;
}
public
static
AttributeDefinition
createRequiredAttrDef
(
String
name
,
IDataType
dataType
)
{
return
new
AttributeDefinition
(
name
,
dataType
.
getName
(),
Multiplicity
.
REQUIRED
,
false
,
null
);
}
@SuppressWarnings
(
"unchecked"
)
protected
HierarchicalTypeDefinition
<
TraitType
>
createTraitTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeDefinition
...
attrDefs
)
{
return
new
HierarchicalTypeDefinition
(
TraitType
.
class
,
name
,
superTypes
,
attrDefs
);
}
@SuppressWarnings
(
"unchecked"
)
protected
HierarchicalTypeDefinition
<
ClassType
>
createClassTypeDef
(
String
name
,
ImmutableList
<
String
>
superTypes
,
AttributeDefinition
...
attrDefs
)
{
return
new
HierarchicalTypeDefinition
(
ClassType
.
class
,
name
,
superTypes
,
attrDefs
);
}
}
}
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