final NiFiTypes.EntityDefinition def = ENTITIES.get(typeName); final AtlasEntityDef entity = new AtlasEntityDef(); type.getEntityDefs().add(entity); entity.setName(typeName); entity.setSuperTypes(superTypes); entity.setAttributeDefs(attributes); });
public AtlasEntity(AtlasEntityDef entityDef) { this(entityDef != null ? entityDef.getName() : null, null); }
public AtlasEntityDef(AtlasEntityDef other) { super(other); setSuperTypes(other != null ? other.getSuperTypes() : null); }
private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException { String typeName = structType.getStructDef().getName(); String typeDesc = structType.getStructDef().getDescription(); String typeVersion = structType.getStructDef().getTypeVersion(); AttributeDefinition[] attributes = getAttributes(structType, registry); StructTypeDefinition structTypeDef = TypesUtil.createStructTypeDef(typeName, typeDesc, typeVersion, attributes); TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(structTypeDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); return ret; }
private AtlasEntityDef getAtlasEntityDefWithAttributes(String... attributeNames) { AtlasEntityDef e = new AtlasEntityDef(); for (AtlasStructDef.AtlasAttributeDef a : getAtlasAttributeDefs(attributeNames)) { e.addAttribute(a); } return e; }
@Test public void testEntityDefValidHierarchy() { AtlasEntityDef entL0 = new AtlasEntityDef("L0"); AtlasEntityDef entL1_1 = new AtlasEntityDef("L1-1"); AtlasEntityDef entL1_2 = new AtlasEntityDef("L1-2"); AtlasEntityDef entL2_1 = new AtlasEntityDef("L2-1"); AtlasEntityDef entL2_2 = new AtlasEntityDef("L2-2"); AtlasEntityDef entL2_3 = new AtlasEntityDef("L2-3"); AtlasEntityDef entL2_4 = new AtlasEntityDef("L2-4"); entL1_1.addSuperType(entL0.getName()); entL1_2.addSuperType(entL0.getName()); entL2_1.addSuperType(entL1_1.getName()); entL2_2.addSuperType(entL1_1.getName()); entL2_3.addSuperType(entL1_1.getName()); entL2_3.addSuperType(entL1_2.getName()); entL2_4.addSuperType(entL1_2.getName()); entL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); entL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); entL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); entL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); entL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); entL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); entL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
public static AtlasEntityDef createClassTypeDef(String name, String description, String version, Set<String> superTypes, AtlasAttributeDef... attrDefs) { return new AtlasEntityDef(name, description, version, Arrays.asList(attrDefs), superTypes); }
public static AtlasEntityDef newEntityDef(AtlasTypeRegistry typesRegistry, AtlasEntityDef[] superTypes) { int entDefIdx = IDX_ENTITY_DEF.getAndIncrement(); AtlasEntityDef ret = new AtlasEntityDef(); ret.setName(PREFIX_ENTITY_DEF + entDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); if (superTypes != null) { for (AtlasEntityDef superType : superTypes) { ret.addSuperType(superType.getName()); } } AtlasTransientTypeRegistry ttr = null; boolean commit = false; try { ttr = typesRegistry.lockTypeRegistryForUpdate(); ttr.addType(ret); commit = true; } catch (AtlasBaseException excp) { LOG.error("failed to create entity-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) { String typeName = entityType.getEntityDef().getName(); String typeDesc = entityType.getEntityDef().getDescription(); String typeVersion = entityType.getEntityDef().getTypeVersion(); Set<String> superTypes = entityType.getEntityDef().getSuperTypes(); List<AttributeDefinition> attributes = getAttributes(entityType, registry); ClassTypeDefinition classTypeDef = new ClassTypeDefinition(typeName, typeDesc, typeVersion, attributes, superTypes); TypesDef ret = new TypesDef(null, null, null, Arrays.asList(classTypeDef)); return ret; }
@Override public AtlasEntityDef update(AtlasEntityDef entityDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.update({})", entityDef); } validateType(entityDef); AtlasEntityDef ret = StringUtils.isNotBlank(entityDef.getGuid()) ? updateByGuid(entityDef.getGuid(), entityDef) : updateByName(entityDef.getName(), entityDef); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.update({}): {}", entityDef, ret); } return ret; }
private AtlasEntityDef toEntityDef(AtlasVertex vertex) throws AtlasBaseException { AtlasEntityDef ret = null; if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.CLASS)) { ret = new AtlasEntityDef(); AtlasStructDefStoreV2.toStructDef(vertex, ret, typeDefStore); ret.setSuperTypes(typeDefStore.getSuperTypeNames(vertex)); } return ret; } }
@Test public void testEntityDefSetSuperTypes() { AtlasEntityDef entityDef = ModelTestUtil.newEntityDefWithSuperTypes(); Set<String> oldSuperTypes = entityDef.getSuperTypes(); Set<String> newSuperTypes = new HashSet<>(); newSuperTypes.add("newType-abcd-1234"); entityDef.setSuperTypes(newSuperTypes); for (String superType : oldSuperTypes) { assertFalse(entityDef.hasSuperType(superType)); } for (String superType : newSuperTypes) { assertTrue(entityDef.hasSuperType(superType)); } // restore old sypertypes entityDef.setSuperTypes(oldSuperTypes); }
private void collectTypeHierarchyInfo(AtlasTypeRegistry typeRegistry, Set<String> allSuperTypeNames, Map<String, AtlasAttribute> allAttributes, List<String> visitedTypes) throws AtlasBaseException { if (visitedTypes.contains(entityDef.getName())) { throw new AtlasBaseException(AtlasErrorCode.CIRCULAR_REFERENCE, entityDef.getName(), visitedTypes.toString()); } if (CollectionUtils.isNotEmpty(entityDef.getSuperTypes())) { visitedTypes.add(entityDef.getName()); for (String superTypeName : entityDef.getSuperTypes()) { AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName); if (superType != null) { superType.collectTypeHierarchyInfo(typeRegistry, allSuperTypeNames, allAttributes, visitedTypes); } } visitedTypes.remove(entityDef.getName()); allSuperTypeNames.addAll(entityDef.getSuperTypes()); } if (CollectionUtils.isNotEmpty(entityDef.getAttributeDefs())) { for (AtlasAttributeDef attributeDef : entityDef.getAttributeDefs()) { AtlasType type = typeRegistry.getType(attributeDef.getTypeName()); allAttributes.put(attributeDef.getName(), new AtlasAttribute(this, attributeDef, type)); } } }
@Test public void testEntityDefInvalidHierarchy_Self() { AtlasEntityDef entDef1 = new AtlasEntityDef("entDef-1"); entDef1.addSuperType(entDef1.getName()); AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; String failureMsg = null; try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addType(entDef1); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNotNull(failureMsg, "expected invalid supertype failure"); }
@Test public void testEntityDefHasSuperTypeWithNoSuperType() { AtlasEntityDef entityDef = ModelTestUtil.getEntityDef(); for (String superType : entityDef.getSuperTypes()) { assertTrue(entityDef.hasSuperType(superType)); } assertFalse(entityDef.hasSuperType("01234-xyzabc-;''-)(")); }
for (String superTypeName : entityDef.getSuperTypes()) { AtlasType superType = typeRegistry.getType(superTypeName); s.add((AtlasEntityType) superType); } else { throw new AtlasBaseException(AtlasErrorCode.INCOMPATIBLE_SUPERTYPE, superTypeName, entityDef.getName()); Map<String, String> typeDefOptions = entityDef.getOptions(); String jsonList = typeDefOptions != null ? typeDefOptions.get(OPTION_SCHEMA_ATTRIBUTES) : null; List<String> schemaAttributeNames = StringUtils.isNotEmpty(jsonList) ? AtlasType.fromJson(jsonList, List.class) : null;
AtlasEntityDef updatedDef = new AtlasEntityDef((AtlasEntityDef)typeDef); updatedDef.addAttribute(attributeDef); updatedDef.setTypeVersion(patch.getUpdateToVersion());
public Set<String> getSuperTypes() { return entityDef.getSuperTypes(); }
@Test public void testEntityDefRemoveElement() { AtlasEntityDef entityDef = ModelTestUtil.newEntityDefWithSuperTypes(); for (String superType : entityDef.getSuperTypes()) { entityDef.removeSuperType(superType); assertFalse(entityDef.hasSuperType(superType)); } }
@Override public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferences(typeRegistry); List<AtlasEntityType> s = new ArrayList<>(); Set<String> allS = new HashSet<>(); Map<String, AtlasAttribute> allA = new HashMap<>(); getTypeHierarchyInfo(typeRegistry, allS, allA); for (String superTypeName : entityDef.getSuperTypes()) { AtlasType superType = typeRegistry.getType(superTypeName); if (superType instanceof AtlasEntityType) { s.add((AtlasEntityType)superType); } else { throw new AtlasBaseException(AtlasErrorCode.INCOMPATIBLE_SUPERTYPE, superTypeName, entityDef.getName()); } } this.superTypes = Collections.unmodifiableList(s); this.allSuperTypes = Collections.unmodifiableSet(allS); this.allAttributes = Collections.unmodifiableMap(allA); this.uniqAttributes = getUniqueAttributes(this.allAttributes); this.allSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2() this.typeAndAllSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2() this.relationshipAttributes = new HashMap<>(); // this will be populated in resolveReferencesPhase3() this.relationshipAttributesType = new HashMap<>(); // this will be populated in resolveReferencesPhase3() this.typeAndAllSubTypes.add(this.getTypeName()); this.typeAndAllSuperTypes = new HashSet<>(this.allSuperTypes); this.typeAndAllSuperTypes.add(this.getTypeName()); this.typeAndAllSuperTypes = Collections.unmodifiableSet(this.typeAndAllSuperTypes); }