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
018bbd62
Commit
018bbd62
authored
May 29, 2015
by
Suma Shivaprasad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 38086 - Entity creation should fail with a meaningful error
parent
deaf3164
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
24 deletions
+30
-24
DefaultMetadataService.java
...ache/hadoop/metadata/services/DefaultMetadataService.java
+30
-24
No files found.
repository/src/main/java/org/apache/hadoop/metadata/services/DefaultMetadataService.java
View file @
018bbd62
...
@@ -20,13 +20,20 @@ package org.apache.hadoop.metadata.services;
...
@@ -20,13 +20,20 @@ package org.apache.hadoop.metadata.services;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Preconditions
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
com.google.inject.Guice
;
import
com.google.inject.Injector
;
import
com.google.inject.Injector
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
org.apache.hadoop.metadata.MetadataException
;
import
org.apache.hadoop.metadata.MetadataException
;
import
org.apache.hadoop.metadata.MetadataServiceClient
;
import
org.apache.hadoop.metadata.MetadataServiceClient
;
import
org.apache.hadoop.metadata.ParamChecker
;
import
org.apache.hadoop.metadata.RepositoryMetadataModule
;
import
org.apache.hadoop.metadata.discovery.SearchIndexer
;
import
org.apache.hadoop.metadata.discovery.SearchIndexer
;
import
org.apache.hadoop.metadata.listener.EntityChangeListener
;
import
org.apache.hadoop.metadata.listener.EntityChangeListener
;
import
org.apache.hadoop.metadata.listener.TypesChangeListener
;
import
org.apache.hadoop.metadata.listener.TypesChangeListener
;
import
org.apache.hadoop.metadata.repository.MetadataRepository
;
import
org.apache.hadoop.metadata.repository.MetadataRepository
;
import
org.apache.hadoop.metadata.repository.graph.GraphBackedMetadataRepository
;
import
org.apache.hadoop.metadata.repository.graph.GraphBackedSearchIndexer
;
import
org.apache.hadoop.metadata.repository.typestore.GraphBackedTypeStore
;
import
org.apache.hadoop.metadata.repository.typestore.ITypeStore
;
import
org.apache.hadoop.metadata.repository.typestore.ITypeStore
;
import
org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.typesystem.ITypedStruct
;
import
org.apache.hadoop.metadata.typesystem.ITypedStruct
;
...
@@ -45,10 +52,13 @@ import scala.tools.cmd.Meta;
...
@@ -45,10 +52,13 @@ import scala.tools.cmd.Meta;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
import
java.util.LinkedHashSet
;
import
java.io.IOException
;
import
java.util.List
;
import
java.io.InputStream
;
import
java.util.Map
;
import
java.io.InputStreamReader
;
import
java.util.Set
;
import
java.net.URL
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
/**
* Simple wrapper over TypeSystem and MetadataRepository services with hooks
* Simple wrapper over TypeSystem and MetadataRepository services with hooks
...
@@ -101,8 +111,7 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -101,8 +111,7 @@ public class DefaultMetadataService implements MetadataService {
@Override
@Override
public
JSONObject
createType
(
String
typeDefinition
)
throws
MetadataException
{
public
JSONObject
createType
(
String
typeDefinition
)
throws
MetadataException
{
try
{
try
{
Preconditions
.
checkNotNull
(
typeDefinition
,
"type definition cannot be null"
);
ParamChecker
.
notEmpty
(
typeDefinition
,
"type definition cannot be empty"
);
Preconditions
.
checkArgument
(!
typeDefinition
.
equals
(
""
),
"type definition cannot be an empty string"
);
TypesDef
typesDef
=
TypesSerialization
.
fromJson
(
typeDefinition
);
TypesDef
typesDef
=
TypesSerialization
.
fromJson
(
typeDefinition
);
if
(
typesDef
.
isEmpty
())
if
(
typesDef
.
isEmpty
())
...
@@ -164,8 +173,8 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -164,8 +173,8 @@ public class DefaultMetadataService implements MetadataService {
*/
*/
@Override
@Override
public
String
createEntity
(
String
entityInstanceDefinition
)
throws
MetadataException
{
public
String
createEntity
(
String
entityInstanceDefinition
)
throws
MetadataException
{
P
reconditions
.
checkNotNull
(
entityInstanceDefinition
,
P
aramChecker
.
notEmpty
(
entityInstanceDefinition
,
"
entity instance definition cannot be null
"
);
"
Entity instance definition cannot be empty
"
);
ITypedReferenceableInstance
entityTypedInstance
=
ITypedReferenceableInstance
entityTypedInstance
=
deserializeClassInstance
(
entityInstanceDefinition
);
deserializeClassInstance
(
entityInstanceDefinition
);
...
@@ -179,17 +188,14 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -179,17 +188,14 @@ public class DefaultMetadataService implements MetadataService {
private
ITypedReferenceableInstance
deserializeClassInstance
(
private
ITypedReferenceableInstance
deserializeClassInstance
(
String
entityInstanceDefinition
)
throws
MetadataException
{
String
entityInstanceDefinition
)
throws
MetadataException
{
try
{
final
Referenceable
entityInstance
=
InstanceSerialization
.
fromJsonReferenceable
(
final
Referenceable
entityInstance
=
InstanceSerialization
.
fromJsonReferenceable
(
entityInstanceDefinition
,
true
);
entityInstanceDefinition
,
true
);
final
String
entityTypeName
=
entityInstance
.
getTypeName
();
final
String
entityTypeName
=
entityInstance
.
getTypeName
();
Preconditions
.
checkNotNull
(
entityTypeName
,
"e
ntity type cannot be null"
);
ParamChecker
.
notEmpty
(
entityTypeName
,
"E
ntity type cannot be null"
);
ClassType
entityType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
entityTypeName
);
ClassType
entityType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
entityTypeName
);
return
entityType
.
convert
(
entityInstance
,
Multiplicity
.
REQUIRED
);
return
entityType
.
convert
(
entityInstance
,
Multiplicity
.
REQUIRED
);
}
catch
(
Exception
e
)
{
throw
new
MetadataException
(
"Error deserializing class instance"
,
e
);
}
}
}
/**
/**
...
@@ -200,7 +206,7 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -200,7 +206,7 @@ public class DefaultMetadataService implements MetadataService {
*/
*/
@Override
@Override
public
String
getEntityDefinition
(
String
guid
)
throws
MetadataException
{
public
String
getEntityDefinition
(
String
guid
)
throws
MetadataException
{
P
reconditions
.
checkNotNull
(
guid
,
"guid cannot be null"
);
P
aramChecker
.
notEmpty
(
guid
,
"guid cannot be null"
);
final
ITypedReferenceableInstance
instance
=
repository
.
getEntityDefinition
(
guid
);
final
ITypedReferenceableInstance
instance
=
repository
.
getEntityDefinition
(
guid
);
return
InstanceSerialization
.
toJson
(
instance
,
true
);
return
InstanceSerialization
.
toJson
(
instance
,
true
);
...
@@ -221,15 +227,15 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -221,15 +227,15 @@ public class DefaultMetadataService implements MetadataService {
@Override
@Override
public
void
updateEntity
(
String
guid
,
String
property
,
String
value
)
throws
MetadataException
{
public
void
updateEntity
(
String
guid
,
String
property
,
String
value
)
throws
MetadataException
{
P
reconditions
.
checkNotNull
(
guid
,
"guid cannot be null"
);
P
aramChecker
.
notEmpty
(
guid
,
"guid cannot be null"
);
P
reconditions
.
checkNotNull
(
property
,
"property cannot be null"
);
P
aramChecker
.
notEmpty
(
property
,
"property cannot be null"
);
P
reconditions
.
checkNotNull
(
value
,
"property value cannot be null"
);
P
aramChecker
.
notEmpty
(
value
,
"property value cannot be null"
);
repository
.
updateEntity
(
guid
,
property
,
value
);
repository
.
updateEntity
(
guid
,
property
,
value
);
}
}
private
void
validateTypeExists
(
String
entityType
)
throws
MetadataException
{
private
void
validateTypeExists
(
String
entityType
)
throws
MetadataException
{
P
reconditions
.
checkNotNull
(
entityType
,
"entity type cannot be null"
);
P
aramChecker
.
notEmpty
(
entityType
,
"entity type cannot be null"
);
// verify if the type exists
// verify if the type exists
if
(!
typeSystem
.
isRegistered
(
entityType
))
{
if
(!
typeSystem
.
isRegistered
(
entityType
))
{
...
@@ -246,7 +252,7 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -246,7 +252,7 @@ public class DefaultMetadataService implements MetadataService {
*/
*/
@Override
@Override
public
List
<
String
>
getTraitNames
(
String
guid
)
throws
MetadataException
{
public
List
<
String
>
getTraitNames
(
String
guid
)
throws
MetadataException
{
P
reconditions
.
checkNotNull
(
guid
,
"entity GUID cannot be null"
);
P
aramChecker
.
notEmpty
(
guid
,
"entity GUID cannot be null"
);
return
repository
.
getTraitNames
(
guid
);
return
repository
.
getTraitNames
(
guid
);
}
}
...
@@ -260,8 +266,8 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -260,8 +266,8 @@ public class DefaultMetadataService implements MetadataService {
@Override
@Override
public
void
addTrait
(
String
guid
,
public
void
addTrait
(
String
guid
,
String
traitInstanceDefinition
)
throws
MetadataException
{
String
traitInstanceDefinition
)
throws
MetadataException
{
P
reconditions
.
checkNotNull
(
guid
,
"entity GUID cannot be null"
);
P
aramChecker
.
notEmpty
(
guid
,
"entity GUID cannot be null"
);
P
reconditions
.
checkNotNull
(
traitInstanceDefinition
,
"Trait instance cannot be null"
);
P
aramChecker
.
notEmpty
(
traitInstanceDefinition
,
"Trait instance cannot be null"
);
ITypedStruct
traitInstance
=
deserializeTraitInstance
(
traitInstanceDefinition
);
ITypedStruct
traitInstance
=
deserializeTraitInstance
(
traitInstanceDefinition
);
final
String
traitName
=
traitInstance
.
getTypeName
();
final
String
traitName
=
traitInstance
.
getTypeName
();
...
@@ -282,7 +288,7 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -282,7 +288,7 @@ public class DefaultMetadataService implements MetadataService {
Struct
traitInstance
=
InstanceSerialization
.
fromJsonStruct
(
Struct
traitInstance
=
InstanceSerialization
.
fromJsonStruct
(
traitInstanceDefinition
,
true
);
traitInstanceDefinition
,
true
);
final
String
entityTypeName
=
traitInstance
.
getTypeName
();
final
String
entityTypeName
=
traitInstance
.
getTypeName
();
P
reconditions
.
checkNotNull
(
entityTypeName
,
"entity type cannot be null"
);
P
aramChecker
.
notEmpty
(
entityTypeName
,
"entity type cannot be null"
);
TraitType
traitType
=
typeSystem
.
getDataType
(
TraitType
.
class
,
entityTypeName
);
TraitType
traitType
=
typeSystem
.
getDataType
(
TraitType
.
class
,
entityTypeName
);
return
traitType
.
convert
(
return
traitType
.
convert
(
...
@@ -302,8 +308,8 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -302,8 +308,8 @@ public class DefaultMetadataService implements MetadataService {
@Override
@Override
public
void
deleteTrait
(
String
guid
,
public
void
deleteTrait
(
String
guid
,
String
traitNameToBeDeleted
)
throws
MetadataException
{
String
traitNameToBeDeleted
)
throws
MetadataException
{
P
reconditions
.
checkNotNull
(
guid
,
"entity GUID cannot be null"
);
P
aramChecker
.
notEmpty
(
guid
,
"entity GUID cannot be null"
);
P
reconditions
.
checkNotNull
(
traitNameToBeDeleted
,
"Trait name cannot be null"
);
P
aramChecker
.
notEmpty
(
traitNameToBeDeleted
,
"Trait name cannot be null"
);
// ensure trait type is already registered with the TS
// ensure trait type is already registered with the TS
Preconditions
.
checkArgument
(
typeSystem
.
isRegistered
(
traitNameToBeDeleted
),
Preconditions
.
checkArgument
(
typeSystem
.
isRegistered
(
traitNameToBeDeleted
),
...
...
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