private void addClassificationType(String typeName, ExportService.ExportContext context) { if (!context.classificationTypes.contains(typeName)) { AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(typeName); addClassificationType(classificationType, context); } }
@Override public AtlasEntityType getEntityType() { AtlasEntityType ret = typeRegistry.getEntityTypeByName(entityTypeName); return ret; }
private void createLabelIfNeeded(final AtlasGraphManagement management, final String propertyName, final String attribTypeName) { // If any of the referenced typename is of type Entity or Struct then the edge label needs to be created for (String typeName : AtlasTypeUtil.getReferencedTypeNames(attribTypeName)) { if (typeRegistry.getEntityDefByName(typeName) != null || typeRegistry.getStructDefByName(typeName) != null) { // Create the edge label upfront to avoid running into concurrent call issue (ATLAS-2092) createEdgeLabel(management, propertyName); } } }
Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter); for(AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) { if (searchPredicates.evaluate(enumType)) { typesDef.getEnumDefs().add(enumType.getEnumDef()); for(AtlasStructType structType : typeRegistry.getAllStructTypes()) { if (searchPredicates.evaluate(structType)) { typesDef.getStructDefs().add(structType.getStructDef()); for(AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) { if (searchPredicates.evaluate(classificationType)) { typesDef.getClassificationDefs().add(classificationType.getClassificationDef()); for(AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) { if (searchPredicates.evaluate(entityType)) { typesDef.getEntityDefs().add(entityType.getEntityDef()); for(AtlasRelationshipType relationshipType : typeRegistry.getAllRelationshipTypes()) { if (searchPredicates.evaluate(relationshipType)) { typesDef.getRelationshipDefs().add(relationshipType.getRelationshipDef());
public static Map<String, Map<String, List<String>>> getVertexPropertiesForCollectionAttributes(AtlasTypeRegistry typeRegistry) { Map<String, Map<String, List<String>>> ret = new HashMap<>(); addVertexPropertiesForCollectionAttributes(typeRegistry.getAllEntityTypes(), ret); addVertexPropertiesForCollectionAttributes(typeRegistry.getAllStructTypes(), ret); addVertexPropertiesForCollectionAttributes(typeRegistry.getAllClassificationTypes(), ret); displayInfo("types with properties: ", ret); return ret; }
private void processTypesDef(ExportContext context) { AtlasTypesDef typesDef = context.result.getData().getTypesDef(); for (String entityType : context.entityTypes) { AtlasEntityDef entityDef = typeRegistry.getEntityDefByName(entityType); typesDef.getEntityDefs().add(entityDef); } for (String classificationType : context.classificationTypes) { AtlasClassificationDef classificationDef = typeRegistry.getClassificationDefByName(classificationType); typesDef.getClassificationDefs().add(classificationDef); } for (String structType : context.structTypes) { AtlasStructDef structDef = typeRegistry.getStructDefByName(structType); typesDef.getStructDefs().add(structDef); } for (String enumType : context.enumTypes) { AtlasEnumDef enumDef = typeRegistry.getEnumDefByName(enumType); typesDef.getEnumDefs().add(enumDef); } }
@Test public void testConstraintInValidInverseRef_InvalidAttributeType() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithInvalidInverseAttributeType()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - invalid refAttribute type"); }
@Test public void typeCreationFromFile() throws IOException, AtlasBaseException { String typesDefJson = TestResourceFileUtils.getJson(TYPESDEF_FILE_NAME); AtlasTypesDef typesDef = AtlasType.fromJson(typesDefJson, AtlasTypesDef.class); assertNotNull(typesDef); typeDefStore.createTypesDef(typesDef); dbType = typeRegistry.getType(TYPE_RDBMS_DB); assertNotNull(dbType); AtlasEntityDef dbType = typeRegistry.getEntityDefByName(TYPE_RDBMS_DB); assertNotNull(dbType); assertTrue(dbType.getAttribute(RDBMS_DB_STORAGE_PROPERTY).isSoftReferenced()); assertTrue(dbType.getAttribute(RDBMS_DB_TABLES_PROPERTY).isSoftReferenced()); assertTrue(dbType.getAttribute(RDBMS_DB_REGIONS_PROPERTY).isSoftReferenced()); assertNotNull(typeRegistry.getEntityDefByName(TYPE_RDBMS_STORAGE)); assertNotNull(typeRegistry.getEntityDefByName(TYPE_RDBMS_TABLES)); }
private void createTypes(List<? extends AtlasBaseTypeDef> typeDefs) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(typeDefs); typeRegistry.releaseTypeRegistryForUpdate(ttr, true); }
@Override public AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasClassificationDefStoreV1.updateByName({}, {})", name, classificationDef); } AtlasClassificationDef existingDef = typeRegistry.getClassificationDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update classification-def ", name); validateType(classificationDef); AtlasType type = typeRegistry.getType(classificationDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex); updateVertexAddReferences(classificationDef, vertex); AtlasClassificationDef ret = toClassificationDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasClassificationDefStoreV1.updateByName({}, {}): {}", name, classificationDef, ret); } return ret; }
@Override public AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException { AtlasClassificationDef ret = typeRegistry.getClassificationDefByName(name); if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } return ret; }
Collection<String> typeNames = typeRegistry.getAllTypeNames(); if (CollectionUtils.isNotEmpty(typeNames)) { typeCount = typeNames.size(); Map<String, Number> deletedCountMap = new HashMap<>(); List<String> classificationDefNames = typeRegistry.getAllClassificationDefNames() .stream() .map(x -> "'" + x + "'") List<String> entityDefNames = typeRegistry.getAllEntityDefNames() .stream() .map(x -> "'" + x + "'") Map<String, Number> deletedEntityCount = new HashMap<>(); for (String entityDefName : typeRegistry.getAllEntityDefNames()) { Number activeCount = activeCountMap.getOrDefault(entityDefName, null); Number deletedCount = deletedCountMap.getOrDefault(entityDefName, null); for (String classificationName : typeRegistry.getAllClassificationDefNames()) { Object count = activeCountMap.getOrDefault(classificationName, null); if (count != null) {
@Override public AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException { AtlasEntityDef ret = typeRegistry.getEntityDefByName(name); if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } return ret; }
public AtlasTransientTypeRegistry lockTypeRegistryForUpdate() throws AtlasBaseException { return lockTypeRegistryForUpdate(DEFAULT_LOCK_MAX_WAIT_TIME_IN_SECONDS); }
public static Map<String, TypeInfo> get(AtlasTypeRegistry typeRegistry) { Map<String, TypeInfo> ret = new HashMap<>(); for (AtlasRelationshipType relType : typeRegistry.getAllRelationshipTypes()) { AtlasRelationshipDef relDef = relType.getRelationshipDef(); String relTypeName = relType.getTypeName(); add(ret, getKey(relDef.getEndDef1()), relTypeName, relDef.getPropagateTags()); add(ret, getKey(relDef.getEndDef2()), relTypeName, getEnd2PropagateTag(relDef.getPropagateTags())); } return ret; }
private void processTypesDef(ExportContext context) { AtlasTypesDef typesDef = context.result.getData().getTypesDef(); for (String entityType : context.entityTypes) { AtlasEntityDef entityDef = typeRegistry.getEntityDefByName(entityType); typesDef.getEntityDefs().add(entityDef); } for (String classificationType : context.classificationTypes) { AtlasClassificationDef classificationDef = typeRegistry.getClassificationDefByName(classificationType); typesDef.getClassificationDefs().add(classificationDef); } for (String structType : context.structTypes) { AtlasStructDef structDef = typeRegistry.getStructDefByName(structType); typesDef.getStructDefs().add(structDef); } for (String enumType : context.enumTypes) { AtlasEnumDef enumDef = typeRegistry.getEnumDefByName(enumType); typesDef.getEnumDefs().add(enumDef); } }
@Test public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute"); }
Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter); for(AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) { if (searchPredicates.evaluate(enumType)) { typesDef.getEnumDefs().add(enumType.getEnumDef()); for(AtlasStructType structType : typeRegistry.getAllStructTypes()) { if (searchPredicates.evaluate(structType)) { typesDef.getStructDefs().add(structType.getStructDef()); for(AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) { if (searchPredicates.evaluate(classificationType)) { typesDef.getClassificationDefs().add(classificationType.getClassificationDef()); for(AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) { if (searchPredicates.evaluate(entityType)) { typesDef.getEntityDefs().add(entityType.getEntityDef()); for(AtlasRelationshipType relationshipType : typeRegistry.getAllRelationshipTypes()) { if (searchPredicates.evaluate(relationshipType)) { typesDef.getRelationshipDefs().add(relationshipType.getRelationshipDef());
@Override public AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.updateByName({}, {})", name, entityDef); } AtlasEntityDef existingDef = typeRegistry.getEntityDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update entity-def ", name); validateType(entityDef); AtlasType type = typeRegistry.getType(entityDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex); updateVertexAddReferences(entityDef, vertex); AtlasEntityDef ret = toEntityDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.updateByName({}, {}): {}", name, entityDef, ret); } return ret; }