private void createClassificationNameIndexMap(List<AtlasClassificationDef> classificationDefs) { for (int i = 0; i < classificationDefs.size(); i++) { AtlasClassificationDef classificationDef = classificationDefs.get(i); classificationIndexMap.put(classificationDef.getName(), i); } }
public static AtlasClassificationDef createAtlasClassificationDef(String name, String description, String version, Set<String> superTypes, Set<String> entityTypes, AtlasAttributeDef... attrDefs) { return new AtlasClassificationDef(name, description, version, Arrays.asList(attrDefs), superTypes, entityTypes, null); }
private void loadSampleClassificationDefs() throws AtlasBaseException { AtlasClassificationDef tag1 = new AtlasClassificationDef("tag1"); AtlasClassificationDef tag2 = new AtlasClassificationDef("tag2"); AtlasClassificationDef tag3 = new AtlasClassificationDef("tag3"); AtlasClassificationDef tag4 = new AtlasClassificationDef("tag4"); AtlasClassificationDef PII = new AtlasClassificationDef("PII"); PII.addAttribute(new AtlasAttributeDef("type", "string")); PII.addAttribute(new AtlasAttributeDef("valid", "boolean")); typeDefStore.createTypesDef(new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Arrays.asList(tag1, tag2, tag3, tag4, PII), Collections.emptyList(), Collections.emptyList())); }
public AtlasClassificationDef(String name, String description, String typeVersion, List<AtlasAttributeDef> attributeDefs, Set<String> superTypes, Set<String> entityTypes, Map<String, String> options) { super(TypeCategory.CLASSIFICATION, name, description, typeVersion, attributeDefs, options); setSuperTypes(superTypes); setEntityTypes(entityTypes); }
public AtlasClassificationDef(AtlasClassificationDef other) { super(other); setSuperTypes(other != null ? other.getSuperTypes() : null); }
private static TypesDef entityToTypesDef(AtlasEntityType entityType, AtlasTypeRegistry registry) throws AtlasBaseException { String typeName = entityType.getEntityDef().getName(); String typeDesc = entityType.getEntityDef().getDescription(); String typeVersion = entityType.getEntityDef().getTypeVersion(); ImmutableSet superTypes = ImmutableSet.copyOf(entityType.getEntityDef().getSuperTypes()); AttributeDefinition[] attributes = getAttributes(entityType, registry); HierarchicalTypeDefinition<ClassType> classType = TypesUtil.createClassTypeDef(typeName, typeDesc, typeVersion, superTypes, attributes); TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(classType)); return ret; }
@Test public void testClassificationDefInvalidHierarchy_CircularRef() { AtlasClassificationDef classifiL0 = new AtlasClassificationDef("L0"); AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1"); AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2"); AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1"); AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2"); AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3"); AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4"); classifiL1_1.addSuperType(classifiL0.getName()); classifiL1_2.addSuperType(classifiL0.getName()); classifiL2_1.addSuperType(classifiL1_1.getName()); classifiL2_2.addSuperType(classifiL1_1.getName()); classifiL2_3.addSuperType(classifiL1_1.getName()); classifiL2_3.addSuperType(classifiL1_2.getName()); classifiL2_4.addSuperType(classifiL1_2.getName()); classifiL0.addSuperType(classifiL2_3.getName()); // circular-ref
public static AtlasClassificationDef newClassificationDef(AtlasTypeRegistry typesRegistry, AtlasClassificationDef[] superTypes) { int classificationDefIdx = IDX_CLASSIFICATION_DEF.getAndIncrement(); AtlasClassificationDef ret = new AtlasClassificationDef(); ret.setName(PREFIX_CLASSIFICATION_DEF + classificationDefIdx); ret.setDescription(ret.getName()); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); if (superTypes != null) { for (AtlasClassificationDef 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 classification-def", excp); ret = null; } finally { typesRegistry.releaseTypeRegistryForUpdate(ttr, commit); } return ret; }
@Test public void testClassificationDefValidHierarchy() { AtlasClassificationDef classifiL0 = new AtlasClassificationDef("L0"); AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1"); AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2"); AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1"); AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2"); AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3"); AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4"); classifiL1_1.addSuperType(classifiL0.getName()); classifiL1_2.addSuperType(classifiL0.getName()); classifiL2_1.addSuperType(classifiL1_1.getName()); classifiL2_2.addSuperType(classifiL1_1.getName()); classifiL2_3.addSuperType(classifiL1_1.getName()); classifiL2_3.addSuperType(classifiL1_2.getName()); classifiL2_4.addSuperType(classifiL1_2.getName()); classifiL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); classifiL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); classifiL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); classifiL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); classifiL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); classifiL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT)); classifiL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
private void collectTypeHierarchyInfo(AtlasTypeRegistry typeRegistry, Set<String> allSuperTypeNames, Map<String, AtlasAttribute> allAttributes, List<String> visitedTypes) throws AtlasBaseException { if (visitedTypes.contains(classificationDef.getName())) { throw new AtlasBaseException(AtlasErrorCode.CIRCULAR_REFERENCE, classificationDef.getName(), visitedTypes.toString()); } if (CollectionUtils.isNotEmpty(classificationDef.getSuperTypes())) { visitedTypes.add(classificationDef.getName()); for (String superTypeName : classificationDef.getSuperTypes()) { AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName); if (superType != null) { superType.collectTypeHierarchyInfo(typeRegistry, allSuperTypeNames, allAttributes, visitedTypes); } } visitedTypes.remove(classificationDef.getName()); allSuperTypeNames.addAll(classificationDef.getSuperTypes()); } if (CollectionUtils.isNotEmpty(classificationDef.getAttributeDefs())) { for (AtlasAttributeDef attributeDef : classificationDef.getAttributeDefs()) { AtlasType type = typeRegistry.getType(attributeDef.getTypeName()); allAttributes.put(attributeDef.getName(), new AtlasAttribute(this, attributeDef, type)); } } }
private AtlasStructDef getStructDefFromClassificationDef(AtlasClassificationDef classificationDef) { String legacyTypeName = getLegacyTypeNameForStructDef(classificationDef.getName()); return new AtlasStructDef(legacyTypeName, classificationDef.getDescription(), classificationDef.getTypeVersion(), getDefaultAttributeDefsIfNecessary(classificationDef.getAttributeDefs())); }
private AtlasClassificationDef toClassificationDef(AtlasVertex vertex) throws AtlasBaseException { AtlasClassificationDef ret = null; if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.TRAIT)) { ret = new AtlasClassificationDef(); AtlasStructDefStoreV2.toStructDef(vertex, ret, typeDefStore); ret.setSuperTypes(typeDefStore.getSuperTypeNames(vertex)); ret.setEntityTypes(typeDefStore.getEntityTypeNames(vertex)); } return ret; }
@Test public void testNestedUpdates() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; String failureMsg = null; AtlasClassificationDef testTag1 = new AtlasClassificationDef("testTag1"); AtlasClassificationDef testTag2 = new AtlasClassificationDef("testTag2"); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addType(testTag1); // changes should not be seen in typeRegistry until lock is released assertFalse(typeRegistry.isRegisteredType(testTag1.getName()), "type added should be seen in typeRegistry only after commit"); boolean isNestedUpdateSuccess = addType(typeRegistry, testTag2); assertTrue(isNestedUpdateSuccess); // changes made in nested commit, inside addType(), should not be seen in typeRegistry until lock is released here assertFalse(typeRegistry.isRegisteredType(testTag2.getName()), "type added within nested commit should be seen in typeRegistry only after outer commit"); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg); assertTrue(typeRegistry.isRegisteredType(testTag1.getName())); assertTrue(typeRegistry.isRegisteredType(testTag2.getName())); }
assertEquals("test_classification_11", createdTypesDef.getClassificationDefs().get(0).getName()); assertTrue(createdTypesDef.getClassificationDefs().get(0).getAttributeDefs().get(0).getIsIndexable()); String guid = createdTypesDef.getClassificationDefs().get(0).getGuid(); Date createdTime = createdTypesDef.getClassificationDefs().get(0).getCreateTime(); assertEquals("test_classification_11", getBackFromCache.getName()); assertTrue(getBackFromCache.getAttributeDefs().get(0).getIsIndexable()); assertEquals(guid, getBackFromCache.getGuid()); assertNotNull(getBackFromCache.getCreatedBy()); assertEquals(createdTime, getBackFromCache.getCreateTime()); testTypesDefFromJson.getClassificationDefs().get(0).getAttributeDefs().get(0).setIsIndexable(false); AtlasTypesDef updatedTypesDef = typeDefStore.updateTypesDef(testTypesDefFromJson); assertEquals("test_classification_11", updatedTypesDef.getClassificationDefs().get(0).getName()); assertFalse(updatedTypesDef.getClassificationDefs().get(0).getAttributeDefs().get(0).getIsIndexable()); assertEquals(guid, updatedTypesDef.getClassificationDefs().get(0).getGuid()); assertEquals(createdTime, updatedTypesDef.getClassificationDefs().get(0).getCreateTime()); assertEquals("test_classification_11", getBackFromCache.getName()); assertFalse(getBackFromCache.getAttributeDefs().get(0).getIsIndexable()); assertEquals(guid, getBackFromCache.getGuid()); assertEquals(createdTime, getBackFromCache.getCreateTime()); getBackFromCache = typeDefStore.getClassificationDefByGuid(guid); assertEquals("test_classification_11", getBackFromCache.getName()); assertFalse(getBackFromCache.getAttributeDefs().get(0).getIsIndexable()); assertEquals(guid, getBackFromCache.getGuid()); assertEquals(createdTime, getBackFromCache.getCreateTime());
@Override public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferences(typeRegistry); List<AtlasClassificationType> s = new ArrayList<>(); Set<String> allS = new HashSet<>(); Map<String, AtlasAttribute> allA = new HashMap<>(); getTypeHierarchyInfo(typeRegistry, allS, allA); for (String superTypeName : classificationDef.getSuperTypes()) { AtlasType superType = typeRegistry.getType(superTypeName); if (superType instanceof AtlasClassificationType) { s.add((AtlasClassificationType)superType); } else { throw new AtlasBaseException(AtlasErrorCode.INCOMPATIBLE_SUPERTYPE, superTypeName, classificationDef.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.typeAndAllSubTypes.add(this.getTypeName()); }
@Override public AtlasClassificationDef update(AtlasClassificationDef classifiDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasClassificationDefStoreV1.update({})", classifiDef); } validateType(classifiDef); AtlasClassificationDef ret = StringUtils.isNotBlank(classifiDef.getGuid()) ? updateByGuid(classifiDef.getGuid(), classifiDef) : updateByName(classifiDef.getName(), classifiDef); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasClassificationDefStoreV1.update({}): {}", classifiDef, ret); } return ret; }
final Set<String> classificationDefEntityTypes = classificationDef.getEntityTypes(); Set<String> entityTypeNames = superTypeDef.getEntityTypes(); throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATIONDEF_PARENTS_ENTITYTYPES_DISJOINT, this.classificationDef.getName()); throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATIONDEF_ENTITYTYPES_NOT_PARENTS_SUBSET, classificationDef.getName(), classificationDefEntityTypes.toString()); classificationDef.setSubTypes(subTypes);
@Test public void testClassificationDefHasSuperTypeWithNoSuperType() { AtlasClassificationDef classificationDef = ModelTestUtil.getClassificationDef(); for (String superType : classificationDef.getSuperTypes()) { assertTrue(classificationDef.hasSuperType(superType)); } assertFalse(classificationDef.hasSuperType("01234-xyzabc-;''-)(")); }
AtlasClassificationDef updatedDef = new AtlasClassificationDef((AtlasClassificationDef)typeDef); updatedDef.addAttribute(attributeDef); updatedDef.setTypeVersion(patch.getUpdateToVersion());
AtlasClassificationDef updatedDef = new AtlasClassificationDef((AtlasClassificationDef)typeDef); if (updatedDef.getOptions() == null) { updatedDef.setOptions(patch.getTypeDefOptions()); } else { updatedDef.getOptions().putAll(patch.getTypeDefOptions()); updatedDef.setTypeVersion(patch.getUpdateToVersion());