Repository: incubator-atlas Updated Branches: refs/heads/0.8-incubating f85b1b4c8 -> 478740f72
ATLAS-1762: updated error code returned by type create/updated APIs Signed-off-by: Madhan Neethiraj <[email protected]> (cherry picked from commit b2951a9297896df8bada1bb61f9c31645bf5a9e6) Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/478740f7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/478740f7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/478740f7 Branch: refs/heads/0.8-incubating Commit: 478740f724f23def79a978b7a4c3ed5f69b30e3a Parents: f85b1b4 Author: apoorvnaik <[email protected]> Authored: Mon May 1 13:14:38 2017 -0700 Committer: Madhan Neethiraj <[email protected]> Committed: Mon May 1 17:57:03 2017 -0700 ---------------------------------------------------------------------- .../store/graph/AtlasTypeDefGraphStore.java | 73 ++++++++++++++++---- 1 file changed, 61 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/478740f7/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java index 82465bf..41de29f 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java @@ -137,7 +137,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ public AtlasEnumDef updateEnumDefByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByName(name, enumDef); + tryUpdateByName(name, enumDef, ttr); return getEnumDefStore(ttr).updateByName(name, enumDef); } @@ -147,7 +147,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ public AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByGuid(guid, enumDef); + tryUpdateByGUID(guid, enumDef, ttr); return getEnumDefStore(ttr).updateByGuid(guid, enumDef); } @@ -181,7 +181,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ public AtlasStructDef updateStructDefByName(String name, AtlasStructDef structDef) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByName(name, structDef); + tryUpdateByName(name, structDef, ttr); return getStructDefStore(ttr).updateByName(name, structDef); } @@ -191,7 +191,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ public AtlasStructDef updateStructDefByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByGuid(guid, structDef); + tryUpdateByGUID(guid, structDef, ttr); return getStructDefStore(ttr).updateByGuid(guid, structDef); } @@ -226,7 +226,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByName(name, classificationDef); + tryUpdateByName(name, classificationDef, ttr); return getClassificationDefStore(ttr).updateByName(name, classificationDef); } @@ -237,7 +237,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByGuid(guid, classificationDef); + tryUpdateByGUID(guid, classificationDef, ttr); return getClassificationDefStore(ttr).updateByGuid(guid, classificationDef); } @@ -271,7 +271,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ public AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByName(name, entityDef); + tryUpdateByName(name, entityDef, ttr); return getEntityDefStore(ttr).updateByName(name, entityDef); } @@ -281,7 +281,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ public AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypeByGuid(guid, entityDef); + tryUpdateByGUID(guid, entityDef, ttr); return getEntityDefStore(ttr).updateByGuid(guid, entityDef); } @@ -298,8 +298,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ } AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); + tryTypeCreation(typesDef, ttr); - ttr.addTypes(typesDef); AtlasTypesDef ret = addToGraphStore(typesDef, ttr); @@ -327,7 +327,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ ttr.updateTypesWithNoRefResolve(typesToUpdate); } - ttr.addTypes(typesToCreate); + // Translate any NOT FOUND errors to BAD REQUEST + tryTypeCreation(typesToCreate, ttr); AtlasTypesDef ret = addToGraphStore(typesToCreate, ttr); @@ -379,7 +380,16 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - ttr.updateTypes(typesDef); + // Translate any NOT FOUND errors to BAD REQUEST + try { + ttr.updateTypes(typesDef); + } catch (AtlasBaseException e) { + if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) { + throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage()); + } else { + throw e; + } + } AtlasTypesDef ret = updateGraphStore(typesDef, ttr); @@ -813,6 +823,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ } private class TypeRegistryUpdateHook extends GraphTransactionInterceptor.PostTransactionHook { + private final AtlasTransientTypeRegistry ttr; private TypeRegistryUpdateHook(AtlasTransientTypeRegistry ttr) { @@ -820,7 +831,6 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ this.ttr = ttr; } - @Override public void onComplete(boolean isSuccess) { if (LOG.isDebugEnabled()) { @@ -853,5 +863,44 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ } } } + + } + + private void tryUpdateByName(String name, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException { + try { + ttr.updateTypeByName(name, typeDef); + } catch (AtlasBaseException e) { + if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) { + throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage()); + } else { + throw e; + } + } + } + + private void tryUpdateByGUID(String guid, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException { + try { + ttr.updateTypeByGuid(guid, typeDef); + } catch (AtlasBaseException e) { + if (AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) { + throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage()); + } else { + throw e; + } + } + } + + private void tryTypeCreation(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException { + // Translate any NOT FOUND errors to BAD REQUEST + try { + ttr.addTypes(typesDef); + } catch (AtlasBaseException e) { + if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode() || + AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) { + throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage()); + } else { + throw e; + } + } } }
