Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E8637200BB3 for ; Wed, 19 Oct 2016 03:34:15 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E6B3E160AF7; Wed, 19 Oct 2016 01:34:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B1DD4160AE5 for ; Wed, 19 Oct 2016 03:34:13 +0200 (CEST) Received: (qmail 15763 invoked by uid 500); 19 Oct 2016 01:34:12 -0000 Mailing-List: contact commits-help@atlas.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@atlas.incubator.apache.org Delivered-To: mailing list commits@atlas.incubator.apache.org Received: (qmail 15754 invoked by uid 99); 19 Oct 2016 01:34:12 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2016 01:34:12 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 56B49C24C3 for ; Wed, 19 Oct 2016 01:34:12 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id TghwMLMZpzTG for ; Wed, 19 Oct 2016 01:34:09 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id AFE105F257 for ; Wed, 19 Oct 2016 01:34:06 +0000 (UTC) Received: (qmail 15720 invoked by uid 99); 19 Oct 2016 01:34:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2016 01:34:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A6C34E0FC4; Wed, 19 Oct 2016 01:34:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: madhan@apache.org To: commits@atlas.incubator.apache.org Date: Wed, 19 Oct 2016 01:34:05 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] incubator-atlas git commit: ATLAS-1230: updated AtlasTypeRegistry to support batch, atomic type updates archived-at: Wed, 19 Oct 2016 01:34:16 -0000 Repository: incubator-atlas Updated Branches: refs/heads/master 4d9cf4564 -> eb6e656be http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/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 14cc7c4..12047bf 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 @@ -20,7 +20,6 @@ package org.apache.atlas.repository.store.graph; import org.apache.atlas.GraphTransaction; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.SearchFilter; -import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef.AtlasClassificationDefs; import org.apache.atlas.model.typedef.AtlasEntityDef; @@ -33,7 +32,7 @@ import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.repository.util.FilterUtil; import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.type.AtlasTypeRegistry; -import org.apache.atlas.util.TypeDefSorter; +import org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.slf4j.Logger; @@ -41,7 +40,6 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; @@ -52,60 +50,58 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStore.class); - private AtlasTypeRegistry typeRegistry; - private AtlasEnumDefStore enumDefStore; - private AtlasStructDefStore structDefStore; - private AtlasClassificationDefStore classificationDefStore; - private AtlasEntityDefStore entityDefStore; + private final AtlasTypeRegistry typeRegistry; - protected AtlasTypeDefGraphStore() { + protected AtlasTypeDefGraphStore(AtlasTypeRegistry typeRegistry) { + this.typeRegistry = typeRegistry; } - protected void init(AtlasEnumDefStore enumDefStore, - AtlasStructDefStore structDefStore, - AtlasClassificationDefStore classificationDefStore, - AtlasEntityDefStore entityDefStore) throws AtlasBaseException { - AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); + protected abstract AtlasEnumDefStore getEnumDefStore(AtlasTypeRegistry typeRegistry); - typeRegistry.addTypesWithNoRefResolve(enumDefStore.getAll()); - typeRegistry.addTypesWithNoRefResolve(structDefStore.getAll()); - typeRegistry.addTypesWithNoRefResolve(classificationDefStore.getAll()); - typeRegistry.addTypesWithNoRefResolve(entityDefStore.getAll()); + protected abstract AtlasStructDefStore getStructDefStore(AtlasTypeRegistry typeRegistry); - typeRegistry.resolveReferences(); + protected abstract AtlasClassificationDefStore getClassificationDefStore(AtlasTypeRegistry typeRegistry); - this.enumDefStore = enumDefStore; - this.structDefStore = structDefStore; - this.classificationDefStore = classificationDefStore; - this.entityDefStore = entityDefStore; - this.typeRegistry = typeRegistry; - } - - public AtlasTypeRegistry getTypeRegistry() { - return typeRegistry; - } + protected abstract AtlasEntityDefStore getEntityDefStore(AtlasTypeRegistry typeRegistry); @Override public void init() throws AtlasBaseException { + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + AtlasTypesDef typesDef = new AtlasTypesDef(getEnumDefStore(ttr).getAll(), + getStructDefStore(ttr).getAll(), + getClassificationDefStore(ttr).getAll(), + getEntityDefStore(ttr).getAll()); + ttr.addTypes(typesDef); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasBaseException { - AtlasEnumDef ret = enumDefStore.create(enumDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.addType(enumDef); + + AtlasEnumDef ret = getEnumDefStore(ttr).create(enumDef); - typeRegistry.addType(ret); + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @Override @GraphTransaction - public List createEnumDefs(List atlasEnumDefs) throws AtlasBaseException { - List ret = enumDefStore.create(atlasEnumDefs); + public List createEnumDefs(List enumDefs) throws AtlasBaseException { + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - typeRegistry.addTypes(ret); + ttr.addTypes(enumDefs); + + List ret = getEnumDefStore(ttr).create(enumDefs); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -143,9 +139,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public AtlasEnumDef updateEnumDefByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException { - AtlasEnumDef ret = enumDefStore.updateByName(name, enumDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.updateTypeByName(name, enumDef); + + AtlasEnumDef ret = getEnumDefStore(ttr).updateByName(name, enumDef); - typeRegistry.updateTypeByName(name, ret); + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -153,9 +153,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException { - AtlasEnumDef ret = enumDefStore.updateByGuid(guid, enumDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - typeRegistry.updateTypeByGuid(guid, ret); + ttr.updateTypeByGuid(guid, enumDef); + + AtlasEnumDef ret = getEnumDefStore(ttr).updateByGuid(guid, enumDef); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -163,31 +167,43 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public void deleteEnumDefByName(String name) throws AtlasBaseException { - enumDefStore.deleteByName(name); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.removeTypeByName(name); - typeRegistry.removeTypeByName(name); + getEnumDefStore(ttr).deleteByName(name); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public void deleteEnumDefByGuid(String guid) throws AtlasBaseException { - enumDefStore.deleteByGuid(guid); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.removeTypeByGuid(guid); - typeRegistry.removeTypeByGuid(guid); + getEnumDefStore(ttr).deleteByGuid(guid); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public AtlasEnumDefs searchEnumDefs(SearchFilter filter) throws AtlasBaseException { - return enumDefStore.search(filter); + return getEnumDefStore(typeRegistry).search(filter); } @Override @GraphTransaction public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasBaseException { - AtlasStructDef ret = structDefStore.create(structDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.addType(structDef); - typeRegistry.addType(structDef); + AtlasStructDef ret = getStructDefStore(ttr).create(structDef); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -195,9 +211,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public List createStructDefs(List structDefs) throws AtlasBaseException { - List ret = structDefStore.create(structDefs); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.addTypes(structDefs); + + List ret = getStructDefStore(ttr).create(structDefs); - typeRegistry.addTypes(ret); + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -235,9 +255,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public AtlasStructDef updateStructDefByName(String name, AtlasStructDef structDef) throws AtlasBaseException { - AtlasStructDef ret = structDefStore.updateByName(name, structDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - typeRegistry.updateTypeByName(name, ret); + ttr.updateTypeByName(name, structDef); + + AtlasStructDef ret = getStructDefStore(ttr).updateByName(name, structDef); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -245,9 +269,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public AtlasStructDef updateStructDefByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException { - AtlasStructDef ret = structDefStore.updateByGuid(guid, structDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.updateTypeByGuid(guid, structDef); + + AtlasStructDef ret = getStructDefStore(ttr).updateByGuid(guid, structDef); - typeRegistry.updateTypeByGuid(guid, ret); + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -255,32 +283,44 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public void deleteStructDefByName(String name) throws AtlasBaseException { - structDefStore.deleteByName(name); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - typeRegistry.removeTypeByName(name); + ttr.removeTypeByName(name); + + getStructDefStore(ttr).deleteByName(name); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public void deleteStructDefByGuid(String guid) throws AtlasBaseException { - structDefStore.deleteByGuid(guid); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.removeTypeByGuid(guid); - typeRegistry.removeTypeByGuid(guid); + getStructDefStore(ttr).deleteByGuid(guid); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public AtlasStructDefs searchStructDefs(SearchFilter filter) throws AtlasBaseException { - return structDefStore.search(filter); + return getStructDefStore(typeRegistry).search(filter); } @Override @GraphTransaction public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) throws AtlasBaseException { - AtlasClassificationDef ret = classificationDefStore.create(classificationDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.addType(classificationDef); - typeRegistry.addType(classificationDef); + AtlasClassificationDef ret = getClassificationDefStore(ttr).create(classificationDef); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -289,9 +329,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @GraphTransaction public List createClassificationDefs(List classificationDefs) throws AtlasBaseException { - List ret = classificationDefStore.create(classificationDefs); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.addTypes(classificationDefs); - typeRegistry.addTypes(ret); + List ret = getClassificationDefStore(ttr).create(classificationDefs); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -330,9 +374,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @GraphTransaction public AtlasClassificationDef updateClassificationDefByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException { - AtlasClassificationDef ret = classificationDefStore.updateByName(name, classificationDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.updateTypeByName(name, classificationDef); + + AtlasClassificationDef ret = getClassificationDefStore(ttr).updateByName(name, classificationDef); - typeRegistry.updateTypeByName(name, ret); + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -341,9 +389,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @GraphTransaction public AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException { - AtlasClassificationDef ret = classificationDefStore.updateByGuid(guid, classificationDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - typeRegistry.updateTypeByGuid(guid, ret); + ttr.updateTypeByGuid(guid, classificationDef); + + AtlasClassificationDef ret = getClassificationDefStore(ttr).updateByGuid(guid, classificationDef); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -351,31 +403,43 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public void deleteClassificationDefByName(String name) throws AtlasBaseException { - classificationDefStore.deleteByName(name); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.removeTypeByName(name); + + getClassificationDefStore(ttr).deleteByName(name); - typeRegistry.removeTypeByName(name); + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public void deleteClassificationDefByGuid(String guid) throws AtlasBaseException { - classificationDefStore.deleteByGuid(guid); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - typeRegistry.removeTypeByGuid(guid); + ttr.removeTypeByGuid(guid); + + getClassificationDefStore(ttr).deleteByGuid(guid); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public AtlasClassificationDefs searchClassificationDefs(SearchFilter filter) throws AtlasBaseException { - return classificationDefStore.search(filter); + return getClassificationDefStore(typeRegistry).search(filter); } @Override @GraphTransaction public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException { - AtlasEntityDef ret = entityDefStore.create(entityDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.addType(entityDef); - typeRegistry.addType(ret); + AtlasEntityDef ret = getEntityDefStore(ttr).create(entityDef); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -383,9 +447,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public List createEntityDefs(List entityDefs) throws AtlasBaseException { - List ret = entityDefStore.create(entityDefs); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.addTypes(entityDefs); - typeRegistry.addTypes(ret); + List ret = getEntityDefStore(ttr).create(entityDefs); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -423,9 +491,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException { - AtlasEntityDef ret = entityDefStore.updateByName(name, entityDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.updateTypeByName(name, entityDef); - typeRegistry.updateTypeByName(name, ret); + AtlasEntityDef ret = getEntityDefStore(ttr).updateByName(name, entityDef); + + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -433,9 +505,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException { - AtlasEntityDef ret = entityDefStore.updateByGuid(guid, entityDef); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.updateTypeByGuid(guid, entityDef); + + AtlasEntityDef ret = getEntityDefStore(ttr).updateByGuid(guid, entityDef); - typeRegistry.updateTypeByGuid(guid, ret); + typeRegistry.commitTransientTypeRegistry(ttr); return ret; } @@ -443,44 +519,50 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @Override @GraphTransaction public void deleteEntityDefByName(String name) throws AtlasBaseException { - entityDefStore.deleteByName(name); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - typeRegistry.removeTypeByName(name); + ttr.removeTypeByName(name); + + getEntityDefStore(ttr).deleteByName(name); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public void deleteEntityDefByGuid(String guid) throws AtlasBaseException { - entityDefStore.deleteByGuid(guid); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.removeTypeByGuid(guid); - typeRegistry.removeTypeByGuid(guid); + getEntityDefStore(ttr).deleteByGuid(guid); + + typeRegistry.commitTransientTypeRegistry(ttr); } @Override @GraphTransaction public AtlasEntityDefs searchEntityDefs(SearchFilter filter) throws AtlasBaseException { - return entityDefStore.search(filter); + return getEntityDefStore(typeRegistry).search(filter); } @Override @GraphTransaction public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { LOG.info("Creating EnumDefs"); - List enumDefs = enumDefStore.create(typesDef.getEnumDefs()); - List structDefs = structDefStore.create(typesDef.getStructDefs()); - List classifiDefs = classificationDefStore.create(typesDef.getClassificationDefs()); - List entityDefs = entityDefStore.create(typesDef.getEntityDefs()); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); - // typeRegistry should be updated only after resovleReferences() returns success; until then use a temp registry - typeRegistry.addTypes(enumDefs); - typeRegistry.addTypes(structDefs); - typeRegistry.addTypes(classifiDefs); - typeRegistry.addTypes(entityDefs); + ttr.addTypes(typesDef); - typeRegistry.resolveReferences(); + List enumDefs = getEnumDefStore(ttr).create(typesDef.getEnumDefs()); + List structDefs = getStructDefStore(ttr).create(typesDef.getStructDefs()); + List classifiDefs = getClassificationDefStore(ttr).create(typesDef.getClassificationDefs()); + List entityDefs = getEntityDefStore(ttr).create(typesDef.getEntityDefs()); AtlasTypesDef ret = new AtlasTypesDef(enumDefs, structDefs, classifiDefs, entityDefs); + typeRegistry.commitTransientTypeRegistry(ttr); + return ret; } @@ -488,18 +570,16 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { @GraphTransaction public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { LOG.info("Updating EnumDefs"); - List enumDefs = enumDefStore.update(typesDef.getEnumDefs()); - List structDefs = structDefStore.update(typesDef.getStructDefs()); - List classifiDefs = classificationDefStore.update(typesDef.getClassificationDefs()); - List entityDefs = entityDefStore.update(typesDef.getEntityDefs()); + AtlasTransientTypeRegistry ttr = typeRegistry.createTransientTypeRegistry(); + + ttr.updateTypes(typesDef); - // typeRegistry should be updated only after resovleReferences() returns success; until then use a temp registry - typeRegistry.updateTypes(enumDefs); - typeRegistry.updateTypes(structDefs); - typeRegistry.updateTypes(classifiDefs); - typeRegistry.updateTypes(entityDefs); + List enumDefs = getEnumDefStore(ttr).update(typesDef.getEnumDefs()); + List structDefs = getStructDefStore(ttr).update(typesDef.getStructDefs()); + List classifiDefs = getClassificationDefStore(ttr).update(typesDef.getClassificationDefs()); + List entityDefs = getEntityDefStore(ttr).update(typesDef.getEntityDefs()); - typeRegistry.resolveReferences(); + typeRegistry.commitTransientTypeRegistry(ttr); AtlasTypesDef ret = new AtlasTypesDef(enumDefs, structDefs, classifiDefs, entityDefs); @@ -513,7 +593,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { AtlasTypesDef typesDef = new AtlasTypesDef(); Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter); try { - List enumDefs = enumDefStore.getAll(); + List enumDefs = getEnumDefStore(typeRegistry).getAll(); CollectionUtils.filter(enumDefs, searchPredicates); typesDef.setEnumDefs(enumDefs); } catch (AtlasBaseException ex) { @@ -521,7 +601,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { } try { - List structDefs = structDefStore.getAll(); + List structDefs = getStructDefStore(typeRegistry).getAll(); CollectionUtils.filter(structDefs, searchPredicates); typesDef.setStructDefs(structDefs); } catch (AtlasBaseException ex) { @@ -529,7 +609,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { } try { - List classificationDefs = classificationDefStore.getAll(); + List classificationDefs = getClassificationDefStore(typeRegistry).getAll(); CollectionUtils.filter(classificationDefs, searchPredicates); typesDef.setClassificationDefs(classificationDefs); } catch (AtlasBaseException ex) { @@ -537,7 +617,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { } try { - List entityDefs = entityDefStore.getAll(); + List entityDefs = getEntityDefStore(typeRegistry).getAll(); CollectionUtils.filter(entityDefs, searchPredicates); typesDef.setEntityDefs(entityDefs); } catch (AtlasBaseException ex) { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasAbstractDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasAbstractDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasAbstractDefStoreV1.java new file mode 100644 index 0000000..8144ddf --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasAbstractDefStoreV1.java @@ -0,0 +1,33 @@ +/** + * 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.atlas.repository.store.graph.v1; + +import org.apache.atlas.type.AtlasTypeRegistry; + +/** + * Abstract typedef-store for v1 format. + */ +public abstract class AtlasAbstractDefStoreV1 { + protected final AtlasTypeDefGraphStoreV1 typeDefStore; + protected final AtlasTypeRegistry typeRegistry; + + public AtlasAbstractDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) { + this.typeDefStore = typeDefStore; + this.typeRegistry = typeRegistry; + } +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java index bdd65d3..7b6e08a 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasClassificationDefStoreV1.java @@ -26,6 +26,9 @@ import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.store.graph.AtlasClassificationDefStore; import org.apache.atlas.repository.util.FilterUtil; +import org.apache.atlas.type.AtlasClassificationType; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; @@ -33,21 +36,16 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; /** * ClassificationDef store in v1 format. */ -public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStore { +public class AtlasClassificationDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasClassificationDefStore { private static final Logger LOG = LoggerFactory.getLogger(AtlasClassificationDefStoreV1.class); - private final AtlasTypeDefGraphStoreV1 typeDefStore; - - public AtlasClassificationDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore) { - super(); - - this.typeDefStore = typeDefStore; + public AtlasClassificationDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) { + super(typeDefStore, typeRegistry); } @Override @@ -80,20 +78,17 @@ public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStor if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasClassificationDefStoreV1.create({})", classificationDefs); } - List classificationDefList = new LinkedList<>(); - for (AtlasClassificationDef structDef : classificationDefs) { - try { - AtlasClassificationDef atlasClassificationDef = create(structDef); - classificationDefList.add(atlasClassificationDef); - } catch (AtlasBaseException baseException) { - LOG.error("Failed to create {}", structDef); - LOG.error("Exception: {}", baseException); - } + + List ret = new ArrayList<>(); + + for (AtlasClassificationDef classificationDef : classificationDefs) { + ret.add(create(classificationDef)); } + if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasClassificationDefStoreV1.create({}, {})", classificationDefs, classificationDefList); + LOG.debug("<== AtlasClassificationDefStoreV1.create({}, {})", classificationDefs, ret); } - return classificationDefList; + return ret; } @Override @@ -102,17 +97,17 @@ public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStor LOG.debug("==> AtlasClassificationDefStoreV1.getAll()"); } - List classificationDefs = new LinkedList<>(); - Iterator verticesByCategory = typeDefStore.findTypeVerticesByCategory(TypeCategory.TRAIT); - while (verticesByCategory.hasNext()) { - AtlasClassificationDef classificationDef = toClassificationDef(verticesByCategory.next()); - classificationDefs.add(classificationDef); + List ret = new ArrayList<>(); + + Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.TRAIT); + while (vertices.hasNext()) { + ret.add(toClassificationDef(vertices.next())); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasClassificationDefStoreV1.getAll()"); + LOG.debug("<== AtlasClassificationDefStoreV1.getAll(): count={}", ret.size()); } - return classificationDefs; + return ret; } @Override @@ -211,22 +206,17 @@ public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStor LOG.debug("==> AtlasClassificationDefStoreV1.update({})", classificationDefs); } - List updatedClassificationDefs = new ArrayList<>(); + List ret = new ArrayList<>(); for (AtlasClassificationDef classificationDef : classificationDefs) { - try { - AtlasClassificationDef updatedDef = updateByName(classificationDef.getName(), classificationDef); - updatedClassificationDefs.add(updatedDef); - } catch (AtlasBaseException ex) { - LOG.error("Failed to update {}", classificationDef); - } + ret.add(updateByName(classificationDef.getName(), classificationDef)); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasClassificationDefStoreV1.update({}): {}", classificationDefs, updatedClassificationDefs); + LOG.debug("<== AtlasClassificationDefStoreV1.update({}): {}", classificationDefs, ret); } - return updatedClassificationDefs; + return ret; } @Override @@ -255,11 +245,7 @@ public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStor } for (String name : names) { - try { - deleteByName(name); - } catch (AtlasBaseException ex) { - LOG.error("Failed to delete {}", name); - } + deleteByName(name); } if (LOG.isDebugEnabled()) { @@ -293,11 +279,7 @@ public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStor } for (String guid : guids) { - try { - deleteByGuid(guid); - } catch (AtlasBaseException ex) { - LOG.error("Failed to delete {}", guid); - } + deleteByGuid(guid); } if (LOG.isDebugEnabled()) { @@ -313,22 +295,18 @@ public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStor } List classificationDefs = new ArrayList(); - - Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.TRAIT); + Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.TRAIT); while(vertices.hasNext()) { - AtlasVertex vertex = vertices.next(); + AtlasVertex vertex = vertices.next(); AtlasClassificationDef classificationDef = toClassificationDef(vertex); if (classificationDef != null) { - classificationDefs.add(classificationDef); // TODO: add only if this passes filter + classificationDefs.add(classificationDef); } } - if (CollectionUtils.isNotEmpty(classificationDefs)) { - CollectionUtils.filter(classificationDefs, FilterUtil.getPredicateFromSearchFilter(filter)); - } - + CollectionUtils.filter(classificationDefs, FilterUtil.getPredicateFromSearchFilter(filter)); AtlasClassificationDefs ret = new AtlasClassificationDefs(classificationDefs); @@ -339,8 +317,15 @@ public class AtlasClassificationDefStoreV1 implements AtlasClassificationDefStor return ret; } - private void toVertex(AtlasClassificationDef classificationDef, AtlasVertex vertex) { - AtlasStructDefStoreV1.toVertex(classificationDef, vertex, typeDefStore); + private void toVertex(AtlasClassificationDef classificationDef, AtlasVertex vertex) throws AtlasBaseException { + AtlasType type = typeRegistry.getType(classificationDef.getName()); + + if (type.getTypeCategory() != AtlasType.TypeCategory.CLASSIFICATION) { + throw new AtlasBaseException(classificationDef.getName() + ": not a classification type"); + } + + AtlasStructDefStoreV1.toVertex(classificationDef, (AtlasClassificationType)type, + vertex, typeDefStore, typeRegistry); typeDefStore.createSuperTypeEdges(vertex, classificationDef.getSuperTypes()); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java index 191ca56..308a529 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityDefStoreV1.java @@ -21,11 +21,13 @@ import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef.AtlasEntityDefs; -import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.store.graph.AtlasEntityDefStore; import org.apache.atlas.repository.util.FilterUtil; +import org.apache.atlas.type.AtlasEntityType; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; @@ -33,21 +35,16 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; /** * EntityDef store in v1 format. */ -public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { +public class AtlasEntityDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasEntityDefStore { private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityDefStoreV1.class); - private final AtlasTypeDefGraphStoreV1 typeDefStore; - - public AtlasEntityDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore) { - super(); - - this.typeDefStore = typeDefStore; + public AtlasEntityDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) { + super(typeDefStore, typeRegistry); } @Override @@ -80,20 +77,15 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.create({})", entityDefs); } - List entityDefList = new LinkedList<>(); - for (AtlasEntityDef structDef : entityDefs) { - try { - AtlasEntityDef atlasEntityDef = create(structDef); - entityDefList.add(atlasEntityDef); - } catch (AtlasBaseException baseException) { - LOG.error("Failed to create {}", structDef); - LOG.error("Exception: {}", baseException); - } + List ret = new ArrayList<>(); + + for (AtlasEntityDef entityDef : entityDefs) { + ret.add(create(entityDef)); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasEntityDefStoreV1.create({}, {})", entityDefs, entityDefList); + LOG.debug("<== AtlasEntityDefStoreV1.create({}, {})", entityDefs, ret); } - return entityDefList; + return ret; } @Override @@ -102,17 +94,18 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { LOG.debug("==> AtlasEntityDefStoreV1.getAll()"); } - List entityDefs = new LinkedList<>(); - Iterator verticesByCategory = typeDefStore.findTypeVerticesByCategory(TypeCategory.CLASS); - while (verticesByCategory.hasNext()) { - AtlasEntityDef atlasEntityDef = toEntityDef(verticesByCategory.next()); - entityDefs.add(atlasEntityDef); + List ret = new ArrayList<>(); + Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.CLASS); + + while (vertices.hasNext()) { + ret.add(toEntityDef(vertices.next())); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasEntityDefStoreV1.getAll()"); + LOG.debug("<== AtlasEntityDefStoreV1.getAll(): count={}", ret.size()); } - return entityDefs; + + return ret; } @Override @@ -211,22 +204,17 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { LOG.debug("==> AtlasEntityDefStoreV1.update({})", entityDefs); } - List updatedEntityDefs = new ArrayList<>(); + List ret = new ArrayList<>(); for (AtlasEntityDef entityDef : entityDefs) { - try { - AtlasEntityDef atlasEntityDef = updateByName(entityDef.getName(), entityDef); - updatedEntityDefs.add(atlasEntityDef); - } catch (AtlasBaseException ex) { - LOG.error("Failed to update {}", entityDef); - } + ret.add(updateByName(entityDef.getName(), entityDef)); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasEntityDefStoreV1.update({}): {}", entityDefs, updatedEntityDefs); + LOG.debug("<== AtlasEntityDefStoreV1.update({}): {}", entityDefs, ret); } - return updatedEntityDefs; + return ret; } @Override @@ -254,12 +242,8 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { LOG.debug("==> AtlasEntityDefStoreV1.deleteByNames({})", names); } - List updatedDefs = new ArrayList<>(); - for (String name : names) { - try { - deleteByName(name); - } catch (AtlasBaseException ex) {} + deleteByName(name); } if (LOG.isDebugEnabled()) { @@ -292,12 +276,8 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { LOG.debug("==> AtlasEntityDefStoreV1.deleteByGuids({})", guids); } - List updatedDefs = new ArrayList<>(); - for (String guid : guids) { - try { - deleteByGuid(guid); - } catch (AtlasBaseException ex) {} + deleteByGuid(guid); } if (LOG.isDebugEnabled()) { @@ -311,12 +291,11 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { LOG.debug("==> AtlasEntityDefStoreV1.search({})", filter); } - List entityDefs = new ArrayList(); - - Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.CLASS); + List entityDefs = new ArrayList(); + Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.CLASS); while(vertices.hasNext()) { - AtlasVertex vertex = vertices.next(); + AtlasVertex vertex = vertices.next(); AtlasEntityDef entityDef = toEntityDef(vertex); if (entityDef != null) { @@ -324,10 +303,7 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { } } - if (CollectionUtils.isNotEmpty(entityDefs)) { - CollectionUtils.filter(entityDefs, FilterUtil.getPredicateFromSearchFilter(filter)); - } - + CollectionUtils.filter(entityDefs, FilterUtil.getPredicateFromSearchFilter(filter)); AtlasEntityDefs ret = new AtlasEntityDefs(entityDefs); @@ -338,8 +314,14 @@ public class AtlasEntityDefStoreV1 implements AtlasEntityDefStore { return ret; } - private void toVertex(AtlasEntityDef entityDef, AtlasVertex vertex) { - AtlasStructDefStoreV1.toVertex(entityDef, vertex, typeDefStore); + private void toVertex(AtlasEntityDef entityDef, AtlasVertex vertex) throws AtlasBaseException { + AtlasType type = typeRegistry.getType(entityDef.getName()); + + if (type.getTypeCategory() != AtlasType.TypeCategory.ENTITY) { + throw new AtlasBaseException(entityDef.getName() + ": not a entity type"); + } + + AtlasStructDefStoreV1.toVertex(entityDef, (AtlasEntityType)type, vertex, typeDefStore, typeRegistry); typeDefStore.createSuperTypeEdges(vertex, entityDef.getSuperTypes()); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java index 67ff1a0..5c55d42 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEnumDefStoreV1.java @@ -26,6 +26,7 @@ import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.store.graph.AtlasEnumDefStore; import org.apache.atlas.repository.util.FilterUtil; +import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -34,21 +35,16 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; /** * EnumDef store in v1 format. */ -public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { +public class AtlasEnumDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasEnumDefStore { private static final Logger LOG = LoggerFactory.getLogger(AtlasEnumDefStoreV1.class); - private final AtlasTypeDefGraphStoreV1 typeDefStore; - - public AtlasEnumDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore) { - super(); - - this.typeDefStore = typeDefStore; + public AtlasEnumDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) { + super(typeDefStore, typeRegistry); } @Override @@ -77,24 +73,22 @@ public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { } @Override - public List create(List atlasEnumDefs) throws AtlasBaseException { + public List create(List enumDefs) throws AtlasBaseException { if (LOG.isDebugEnabled()) { - LOG.debug("==> AtlasEnumDefStoreV1.create({})", atlasEnumDefs); - } - List enumDefList = new LinkedList<>(); - for (AtlasEnumDef enumDef : atlasEnumDefs) { - try { - AtlasEnumDef atlasEnumDef = create(enumDef); - enumDefList.add(atlasEnumDef); - } catch (AtlasBaseException baseException) { - LOG.error("Failed to create {}", enumDef); - LOG.error("Exception: {}", baseException); - } + LOG.debug("==> AtlasEnumDefStoreV1.create({})", enumDefs); + } + + List ret = new ArrayList<>(); + + for (AtlasEnumDef enumDef : enumDefs) { + ret.add(create(enumDef)); } + if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasEnumDefStoreV1.create({}, {})", atlasEnumDefs, enumDefList); + LOG.debug("<== AtlasEnumDefStoreV1.create({}): {}", enumDefs, ret); } - return enumDefList; + + return ret; } @Override @@ -103,17 +97,18 @@ public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { LOG.debug("==> AtlasEnumDefStoreV1.getAll()"); } - List enumDefs = new LinkedList<>(); - Iterator verticesByCategory = typeDefStore.findTypeVerticesByCategory(TypeCategory.ENUM); - while (verticesByCategory.hasNext()) { - AtlasEnumDef enumDef = toEnumDef(verticesByCategory.next()); - enumDefs.add(enumDef); + List ret = new ArrayList<>(); + + Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.ENUM); + while (vertices.hasNext()) { + ret.add(toEnumDef(vertices.next())); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasEnumDefStoreV1.getAll()"); + LOG.debug("<== AtlasEnumDefStoreV1.getAll(): count={}", ret.size()); } - return enumDefs; + + return ret; } @Override @@ -212,22 +207,17 @@ public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { LOG.debug("==> AtlasEnumDefStoreV1.update({})", enumDefs); } - List updatedEnumDefs = new ArrayList<>(); + List ret = new ArrayList<>(); for (AtlasEnumDef enumDef : enumDefs) { - try { - AtlasEnumDef updatedDef = updateByName(enumDef.getName(), enumDef); - updatedEnumDefs.add(updatedDef); - } catch (AtlasBaseException ex) { - LOG.error("Failed to update {}", enumDef); - } + ret.add(updateByName(enumDef.getName(), enumDef)); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasEnumDefStoreV1.update({}): {}", enumDefs, updatedEnumDefs); + LOG.debug("<== AtlasEnumDefStoreV1.update({}): {}", enumDefs, ret); } - return updatedEnumDefs; + return ret; } @Override @@ -256,11 +246,7 @@ public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { } for (String name : names) { - try { - deleteByName(name); - } catch (AtlasBaseException ex) { - LOG.error("Failed to delete {}", name); - } + deleteByName(name); } if (LOG.isDebugEnabled()) { @@ -294,11 +280,7 @@ public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { } for (String guid : guids) { - try { - deleteByGuid(guid); - } catch (AtlasBaseException ex) { - LOG.error("Failed to delete {}", guid); - } + deleteByGuid(guid); } if (LOG.isDebugEnabled()) { @@ -312,12 +294,11 @@ public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { LOG.debug("==> AtlasEnumDefStoreV1.search({})", filter); } - List enumDefs = new ArrayList(); - + List enumDefs = new ArrayList(); Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.ENUM); while(vertices.hasNext()) { - AtlasVertex vertex = vertices.next(); + AtlasVertex vertex = vertices.next(); AtlasEnumDef enumDef = toEnumDef(vertex); if (enumDef != null) { @@ -325,9 +306,7 @@ public class AtlasEnumDefStoreV1 implements AtlasEnumDefStore { } } - if (CollectionUtils.isNotEmpty(enumDefs)) { - CollectionUtils.filter(enumDefs, FilterUtil.getPredicateFromSearchFilter(filter)); - } + CollectionUtils.filter(enumDefs, FilterUtil.getPredicateFromSearchFilter(filter)); AtlasEnumDefs ret = new AtlasEnumDefs(enumDefs); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java index b26fc13..eeb08d0 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java @@ -41,6 +41,7 @@ import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.compress.archivers.dump.DumpArchiveEntry; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +49,6 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -56,15 +56,11 @@ import java.util.Set; /** * StructDef store in v1 format. */ -public class AtlasStructDefStoreV1 implements AtlasStructDefStore { +public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasStructDefStore { private static final Logger LOG = LoggerFactory.getLogger(AtlasStructDefStoreV1.class); - private final AtlasTypeDefGraphStoreV1 typeDefStore; - - public AtlasStructDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore) { - super(); - - this.typeDefStore = typeDefStore; + public AtlasStructDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) { + super(typeDefStore, typeRegistry); } @Override @@ -79,9 +75,15 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { throw new AtlasBaseException(structDef.getName() + ": type already exists"); } + AtlasType type = typeRegistry.getType(structDef.getName()); + + if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) { + throw new AtlasBaseException(structDef.getName() + ": not a struct type"); + } + vertex = typeDefStore.createTypeVertex(structDef); - toVertex(structDef, vertex, typeDefStore); + toVertex(structDef, (AtlasStructType)type, vertex, typeDefStore, typeRegistry); AtlasStructDef ret = toStructDef(vertex); @@ -97,20 +99,17 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasStructDefStoreV1.create({})", structDefs); } - List structDefList = new LinkedList<>(); + List ret = new ArrayList<>(); + for (AtlasStructDef structDef : structDefs) { - try { - AtlasStructDef atlasStructDef = create(structDef); - structDefList.add(atlasStructDef); - } catch (AtlasBaseException baseException) { - LOG.error("Failed to create {}", structDef); - LOG.error("Exception: {}", baseException); - } + ret.add(create(structDef)); } + if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasStructDefStoreV1.create({}, {})", structDefs, structDefList); + LOG.debug("<== AtlasStructDefStoreV1.create({}, {})", structDefs, ret); } - return structDefList; + + return ret; } @Override @@ -119,17 +118,17 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { LOG.debug("==> AtlasStructDefStoreV1.getAll()"); } - List structDefs = new LinkedList<>(); - Iterator verticesByCategory = typeDefStore.findTypeVerticesByCategory(TypeCategory.STRUCT); - while (verticesByCategory.hasNext()) { - AtlasStructDef atlasStructDef = toStructDef(verticesByCategory.next()); - structDefs.add(atlasStructDef); + List ret = new ArrayList<>(); + + Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.STRUCT); + while (vertices.hasNext()) { + ret.add(toStructDef(vertices.next())); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasStructDefStoreV1.getAll()"); + LOG.debug("<== AtlasStructDefStoreV1.getAll(): count={}", ret.size()); } - return structDefs; + return ret; } @Override @@ -188,7 +187,13 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { throw new AtlasBaseException("no structDef exists with name " + name); } - toVertex(structDef, vertex); + AtlasType type = typeRegistry.getType(structDef.getName()); + + if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) { + throw new AtlasBaseException(structDef.getName() + ": not a struct type"); + } + + toVertex(structDef, (AtlasStructType)type, vertex); AtlasStructDef ret = toStructDef(vertex); @@ -211,7 +216,13 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { throw new AtlasBaseException("no structDef exists with guid " + guid); } - toVertex(structDef, vertex); + AtlasType type = typeRegistry.getType(structDef.getName()); + + if (type.getTypeCategory() != AtlasType.TypeCategory.STRUCT) { + throw new AtlasBaseException(structDef.getName() + ": not a struct type"); + } + + toVertex(structDef, (AtlasStructType)type, vertex); AtlasStructDef ret = toStructDef(vertex); @@ -228,20 +239,17 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { LOG.debug("==> AtlasStructDefStoreV1.update({})", structDefs); } - List updatedDefs = new ArrayList<>(); + List ret = new ArrayList<>(); for (AtlasStructDef structDef : structDefs) { - try { - AtlasStructDef updatedDef = updateByName(structDef.getName(), structDef); - updatedDefs.add(updatedDef); - } catch (AtlasBaseException ex) {} + ret.add(updateByName(structDef.getName(), structDef)); } if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasStructDefStoreV1.update({}): {}", structDefs, updatedDefs); + LOG.debug("<== AtlasStructDefStoreV1.update({}): {}", structDefs, ret); } - return updatedDefs; + return ret; } @Override @@ -269,12 +277,8 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { LOG.debug("==> AtlasStructDefStoreV1.deleteByNames({})", names); } - List updatedDefs = new ArrayList<>(); - for (String name : names) { - try { - deleteByName(name); - } catch (AtlasBaseException ex) {} + deleteByName(name); } if (LOG.isDebugEnabled()) { @@ -307,12 +311,8 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { LOG.debug("==> AtlasStructDefStoreV1.deleteByGuids({})", guids); } - List updatedDefs = new ArrayList<>(); - for (String guid : guids) { - try { - deleteByGuid(guid); - } catch (AtlasBaseException ex) {} + deleteByGuid(guid); } if (LOG.isDebugEnabled()) { @@ -326,22 +326,19 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { LOG.debug("==> AtlasStructDefStoreV1.search({})", filter); } - List structDefs = new ArrayList(); - - Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.STRUCT); + List structDefs = new ArrayList(); + Iterator vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.STRUCT); - while(vertices.hasNext()) { - AtlasVertex AtlasVertex = vertices.next(); - AtlasStructDef structDef = toStructDef(AtlasVertex); + while (vertices.hasNext()) { + AtlasVertex vertex = vertices.next(); + AtlasStructDef structDef = toStructDef(vertex); if (structDef != null) { structDefs.add(structDef); } } - if (CollectionUtils.isNotEmpty(structDefs)) { - CollectionUtils.filter(structDefs, FilterUtil.getPredicateFromSearchFilter(filter)); - } + CollectionUtils.filter(structDefs, FilterUtil.getPredicateFromSearchFilter(filter)); AtlasStructDefs ret = new AtlasStructDefs(structDefs); @@ -352,8 +349,8 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { return ret; } - private void toVertex(AtlasStructDef structDef, AtlasVertex vertex) { - toVertex(structDef, vertex, typeDefStore); + private void toVertex(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex) { + toVertex(structDef, structType, vertex, typeDefStore, typeRegistry); } private AtlasStructDef toStructDef(AtlasVertex vertex) throws AtlasBaseException { @@ -366,15 +363,14 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { return ret; } - public static void toVertex(AtlasStructDef structDef, AtlasVertex vertex, AtlasTypeDefGraphStoreV1 typeDefStore) { - AtlasTypeRegistry typeRegistry = typeDefStore.getTypeRegistry(); - AtlasStructType structType = (AtlasStructType)typeRegistry.getType(structDef.getName()); - List attrNames = new ArrayList<>(structDef.getAttributeDefs().size()); + public static void toVertex(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex, + AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) { + List attrNames = new ArrayList<>(structDef.getAttributeDefs().size()); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { String propertyKey = AtlasGraphUtilsV1.getPropertyKey(structDef, attributeDef.getName()); - AtlasGraphUtilsV1.setProperty(vertex, propertyKey, toJsonFromAttributeDef(attributeDef, structType, typeRegistry)); + AtlasGraphUtilsV1.setProperty(vertex, propertyKey, toJsonFromAttributeDef(attributeDef, structType)); attrNames.add(attributeDef.getName()); addReferencesForAttribute(vertex, attributeDef, typeDefStore); @@ -382,8 +378,7 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { AtlasGraphUtilsV1.setProperty(vertex, AtlasGraphUtilsV1.getPropertyKey(structDef), attrNames); } - public static AtlasStructDef toStructDef(AtlasVertex vertex, - AtlasStructDef structDef, + public static AtlasStructDef toStructDef(AtlasVertex vertex, AtlasStructDef structDef, AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException { AtlasStructDef ret = (structDef != null) ? structDef :new AtlasStructDef(); @@ -406,8 +401,7 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { return ret; } - private static void addReferencesForAttribute(AtlasVertex vertex, - AtlasAttributeDef attributeDef, + private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef, AtlasTypeDefGraphStoreV1 typeDefStore) { Set referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName()); @@ -415,36 +409,34 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { for (String referencedTypeName : referencedTypeNames) { if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) { - AtlasVertex referencedTypeAtlasVertex = typeDefStore.findTypeVertexByName(referencedTypeName); + AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName); - if (referencedTypeAtlasVertex == null) { - // create atlasVertex? + if (referencedTypeVertex == null) { + // create vertex? } - if (referencedTypeAtlasVertex != null) { + if (referencedTypeVertex != null) { String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName()); - typeDefStore.getOrCreateEdge(vertex, referencedTypeAtlasVertex, label); + typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label); } } } } - private static String toJsonFromAttributeDef(AtlasAttributeDef attributeDef, - AtlasStructType structType, - AtlasTypeRegistry typeRegistry) { + private static String toJsonFromAttributeDef(AtlasAttributeDef attributeDef, AtlasStructType structType) { boolean isForeignKey = structType.isForeignKeyAttribute(attributeDef.getName()); boolean isMappedFromRef = structType.isMappedFromRefAttribute(attributeDef.getName()); String reverseAttribName = null; if (isForeignKey) { // check if the referenced entity has foreignKeyRef to this attribute - AtlasType attribType = typeRegistry.getType(attributeDef.getTypeName()); + AtlasType attribType = structType.getAttributeType(attributeDef.getTypeName()); - if (attribType instanceof AtlasArrayType) { + if (attribType.getTypeCategory() == AtlasType.TypeCategory.ARRAY) { attribType = ((AtlasArrayType)attribType).getElementType(); } - if (attribType instanceof AtlasEntityType) { + if (attribType.getTypeCategory() == AtlasType.TypeCategory.ENTITY) { reverseAttribName = ((AtlasStructType)attribType).getMappedFromRefAttribute(structType.getTypeName(), attributeDef.getName()); } @@ -491,73 +483,67 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { } } - if (! AtlasTypeUtil.isBuiltInType(attrTypeName)) { + if (!AtlasTypeUtil.isBuiltInType(attrTypeName)) { AtlasVertex attributeType = typeDefStore.findTypeVertexByName(attrTypeName); // check for isComposite/reverseAttributeName for entity types if (attributeType != null && typeDefStore.isTypeVertex(attributeType, TypeCategory.CLASS)) { - String reverseAttribName = (String) attribInfo.get("reverseAttributeName"); - Boolean isComposite = (Boolean) attribInfo.get("isComposite"); + String reverseAttribName = (String) attribInfo.get("reverseAttributeName"); + Boolean isComposite = (Boolean) attribInfo.get("isComposite"); - // find the attribute that refers to this attribute if (StringUtils.isNotBlank(reverseAttribName) || isComposite) { if (AtlasTypeUtil.isMapType(attrTypeName)) { throw new AtlasBaseException(structDef.getName() + "." + ret.getName() + ": constraints not supported on map type " + attrTypeName); } - if (attributeType != null) { - String refAttributeName = null; - - List attrNames = attributeType.getProperty( + String refAttributeName = null; + List attrNames = attributeType.getProperty( AtlasGraphUtilsV1.getPropertyKey(attrTypeName), List.class); - if (CollectionUtils.isNotEmpty(attrNames)) { - for (String attrName : attrNames) { - String attribJson = attributeType.getProperty( + if (CollectionUtils.isNotEmpty(attrNames)) { + for (String attrName : attrNames) { + String attribJson = attributeType.getProperty( AtlasGraphUtilsV1.getPropertyKey(attrTypeName, attrName), String.class); - Map refAttrInfo = AtlasType.fromJson(attribJson, Map.class); - String refAttribType = (String) refAttrInfo.get("dataType"); - String refAttribRevAttribName = (String) refAttrInfo.get("reverseAttributeName"); + Map refAttrInfo = AtlasType.fromJson(attribJson, Map.class); + String refAttribType = (String) refAttrInfo.get("dataType"); + String refAttribRevAttribName = (String) refAttrInfo.get("reverseAttributeName"); - if (StringUtils.equals(refAttribType, structDef.getName()) && - StringUtils.equals(refAttribRevAttribName, ret.getName())) { - refAttributeName = (String) refAttrInfo.get("name"); + if (StringUtils.equals(refAttribType, structDef.getName()) && + StringUtils.equals(refAttribRevAttribName, ret.getName())) { + refAttributeName = (String) refAttrInfo.get("name"); - break; - } + break; } } + } - if (isComposite) { - if (StringUtils.isNotBlank(refAttributeName)) { // ex: hive_table.columns, hive_column.table - Map params = new HashMap(); - params.put(AtlasConstraintDef.CONSTRAINT_PARAM_REF_ATTRIBUTE, refAttributeName); + if (isComposite) { + if (StringUtils.isNotBlank(refAttributeName)) { // ex: hive_table.columns, hive_column.table + Map params = new HashMap(); + params.put(AtlasConstraintDef.CONSTRAINT_PARAM_REF_ATTRIBUTE, refAttributeName); - ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_MAPPED_FROM_REF, params)); - } else { // ex: hive_table.partitionKeys, with no reverseAttribute-reference - ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_FOREIGN_KEY)); - } + ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_MAPPED_FROM_REF, params)); + } else { // ex: hive_table.partitionKeys, with no reverseAttribute-reference + ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_FOREIGN_KEY)); } + } - if (StringUtils.isNotBlank(reverseAttribName)) { // ex: hive_column.table - Map params = new HashMap<>(); - params.put(CONSTRAINT_PARAM_ON_DELETE, CONSTRAINT_PARAM_VAL_CASCADE); + if (StringUtils.isNotBlank(reverseAttribName)) { // ex: hive_column.table + Map params = new HashMap<>(); + params.put(CONSTRAINT_PARAM_ON_DELETE, CONSTRAINT_PARAM_VAL_CASCADE); - ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_FOREIGN_KEY, params)); - } + ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_FOREIGN_KEY, params)); } } } } - - Map multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class); - Number minCount = (Number) multiplicity.get("lower"); - Number maxCount = (Number) multiplicity.get("upper"); - Boolean isUnique = (Boolean) multiplicity.get("isUnique"); - + Map multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class); + Number minCount = (Number) multiplicity.get("lower"); + Number maxCount = (Number) multiplicity.get("upper"); + Boolean isUnique = (Boolean) multiplicity.get("isUnique"); if (minCount == null || minCount.intValue() == 0) { ret.setOptional(true); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java index 4b50aac..6634707 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java @@ -19,6 +19,7 @@ package org.apache.atlas.repository.store.graph.v1; import com.google.common.base.Preconditions; +import com.google.inject.Inject; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasClassificationDef; @@ -31,7 +32,12 @@ import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.AtlasClassificationDefStore; +import org.apache.atlas.repository.store.graph.AtlasEntityDefStore; +import org.apache.atlas.repository.store.graph.AtlasEnumDefStore; +import org.apache.atlas.repository.store.graph.AtlasStructDefStore; import org.apache.atlas.repository.store.graph.AtlasTypeDefGraphStore; +import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -57,8 +63,9 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { protected final AtlasGraph atlasGraph = AtlasGraphProvider.getGraphInstance(); - public AtlasTypeDefGraphStoreV1() { - super(); + @Inject + public AtlasTypeDefGraphStoreV1(AtlasTypeRegistry typeRegistry) { + super(typeRegistry); LOG.info("==> AtlasTypeDefGraphStoreV1()"); @@ -72,16 +79,31 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { } @Override + protected AtlasEnumDefStore getEnumDefStore(AtlasTypeRegistry typeRegistry) { + return new AtlasEnumDefStoreV1(this, typeRegistry); + } + + @Override + protected AtlasStructDefStore getStructDefStore(AtlasTypeRegistry typeRegistry) { + return new AtlasStructDefStoreV1(this, typeRegistry); + } + + @Override + protected AtlasClassificationDefStore getClassificationDefStore(AtlasTypeRegistry typeRegistry) { + return new AtlasClassificationDefStoreV1(this, typeRegistry); + } + + @Override + protected AtlasEntityDefStore getEntityDefStore(AtlasTypeRegistry typeRegistry) { + return new AtlasEntityDefStoreV1(this, typeRegistry); + } + + @Override public void init() throws AtlasBaseException { LOG.info("==> AtlasTypeDefGraphStoreV1.init()"); super.init(); - super.init(new AtlasEnumDefStoreV1(this), - new AtlasStructDefStoreV1(this), - new AtlasClassificationDefStoreV1(this), - new AtlasEntityDefStoreV1(this)); - LOG.info("<== AtlasTypeDefGraphStoreV1.init()"); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/eb6e656b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java index 889c3dd..0658361 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java @@ -64,7 +64,7 @@ public class TypesREST { private HttpServletRequest httpServletRequest; @Inject - public TypesREST(AtlasTypeDefStore typeDefStore, AtlasTypeRegistry atlasTypeRegistry) { + public TypesREST(AtlasTypeDefStore typeDefStore) { LOG.info("new TypesREST"); this.typeDefStore = typeDefStore; }