private void updateAttributeWithNewType(String oldTypeName, String newTypeName, AtlasAttributeDef ad) { if(StringUtils.isEmpty(newTypeName)) { return; } String str = ad.getTypeName().replace(oldTypeName, newTypeName); ad.setTypeName(str); }
private void assertNewTypesDef(AtlasTypesDef newTypes, int traitPrayIndex, int vendorPIIIndex, int financeIndex, String expectedTraitPrayStructName, String expectedVendorPIIStructName, String expectedFinanceStructName) { assertNotNull(newTypes); assertEquals(newTypes.getStructDefs().size(), 4); assertTrue(newTypes.getStructDefs().get(traitPrayIndex).getName().contains(LEGACY_TYPE_NAME_PREFIX)); assertTrue(newTypes.getStructDefs().get(vendorPIIIndex).getName().contains(LEGACY_TYPE_NAME_PREFIX)); assertTrue(newTypes.getStructDefs().get(financeIndex).getName().contains(LEGACY_TYPE_NAME_PREFIX)); assertEquals(newTypes.getStructDefs().get(traitPrayIndex).getName(), expectedTraitPrayStructName); assertEquals(newTypes.getStructDefs().get(vendorPIIIndex).getName(), expectedVendorPIIStructName); assertEquals(newTypes.getStructDefs().get(financeIndex).getName(), expectedFinanceStructName); assertEquals(newTypes.getStructDefs().get(1).getAttributeDefs().size(), 1); assertEquals(newTypes.getEntityDefs().get(0).getAttributeDefs().get(0).getTypeName(), expectedTraitPrayStructName); assertEquals(newTypes.getEntityDefs().get(0).getAttributeDefs().get(1).getTypeName(), String.format("array<%s>", expectedVendorPIIStructName)); assertEquals(newTypes.getEntityDefs().get(0).getAttributeDefs().get(2).getTypeName(), String.format("map<String,%s>", expectedFinanceStructName)); } }
private void assertNewTypesDef(AtlasTypesDef newTypes, int traitPrayIndex, int vendorPIIIndex, int financeIndex, String expectedTraitPrayStructName, String expectedVendorPIIStructName, String expectedFinanceStructName) { assertNotNull(newTypes); assertEquals(newTypes.getStructDefs().size(), 4); assertTrue(newTypes.getStructDefs().get(traitPrayIndex).getName().contains(LEGACY_TYPE_NAME_PREFIX)); assertTrue(newTypes.getStructDefs().get(vendorPIIIndex).getName().contains(LEGACY_TYPE_NAME_PREFIX)); assertTrue(newTypes.getStructDefs().get(financeIndex).getName().contains(LEGACY_TYPE_NAME_PREFIX)); assertEquals(newTypes.getStructDefs().get(traitPrayIndex).getName(), expectedTraitPrayStructName); assertEquals(newTypes.getStructDefs().get(vendorPIIIndex).getName(), expectedVendorPIIStructName); assertEquals(newTypes.getStructDefs().get(financeIndex).getName(), expectedFinanceStructName); assertEquals(newTypes.getStructDefs().get(1).getAttributeDefs().size(), 1); assertEquals(newTypes.getEntityDefs().get(0).getAttributeDefs().get(0).getTypeName(), expectedTraitPrayStructName); assertEquals(newTypes.getEntityDefs().get(0).getAttributeDefs().get(1).getTypeName(), String.format("array<%s>", expectedVendorPIIStructName)); assertEquals(newTypes.getEntityDefs().get(0).getAttributeDefs().get(2).getTypeName(), String.format("map<String,%s>", expectedFinanceStructName)); } }
private void cleanupIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) { final String propertyName = AtlasGraphUtilsV2.encodePropertyKey(typeName + "." + attributeDef.getName()); String attribTypeName = attributeDef.getTypeName(); boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName); boolean isArrayType = isArrayType(attribTypeName); boolean isMapType = isMapType(attribTypeName); try { AtlasType atlasType = typeRegistry.getType(attribTypeName); if (isClassificationType(atlasType) || isEntityType(atlasType)) { LOG.warn("Ignoring non-indexable attribute {}", attribTypeName); } else if (isBuiltInType || isEnumType(atlasType) || isArrayType || isMapType) { cleanupIndex(management, propertyName); } else if (isStructType(atlasType)) { AtlasStructDef structDef = typeRegistry.getStructDefByName(attribTypeName); cleanupIndices(management, structDef); } } catch (AtlasBaseException e) { LOG.error("No type exists for {}", attribTypeName, e); } }
public static void updateVertexPreCreate(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex, AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException { List<String> attrNames = new ArrayList<>(structDef.getAttributeDefs().size()); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { // Validate the mandatory features of an attribute (compatibility with legacy type system) if (StringUtils.isEmpty(attributeDef.getName())) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "name"); } if (StringUtils.isEmpty(attributeDef.getTypeName())) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "typeName"); } String propertyKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef, attributeDef.getName()); String encodedPropertyKey = AtlasGraphUtilsV2.encodePropertyKey(propertyKey); vertex.setProperty(encodedPropertyKey, toJsonFromAttribute(structType.getAttribute(attributeDef.getName()))); attrNames.add(attributeDef.getName()); } String typeNamePropertyKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef); String encodedtypeNamePropertyKey = AtlasGraphUtilsV2.encodePropertyKey(typeNamePropertyKey); vertex.setProperty(encodedtypeNamePropertyKey, attrNames); }
public static void updateVertexPreCreate(AtlasStructDef structDef, AtlasStructType structType, AtlasVertex vertex, AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException { List<String> attrNames = new ArrayList<>(structDef.getAttributeDefs().size()); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { // Validate the mandatory features of an attribute (compatibility with legacy type system) if (StringUtils.isEmpty(attributeDef.getName())) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "name"); } if (StringUtils.isEmpty(attributeDef.getTypeName())) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, structDef.getName(), "typeName"); } String propertyKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef, attributeDef.getName()); String encodedPropertyKey = AtlasGraphUtilsV2.encodePropertyKey(propertyKey); vertex.setProperty(encodedPropertyKey, toJsonFromAttribute(structType.getAttribute(attributeDef.getName()))); attrNames.add(attributeDef.getName()); } String typeNamePropertyKey = AtlasGraphUtilsV2.getTypeDefPropertyKey(structDef); String encodedtypeNamePropertyKey = AtlasGraphUtilsV2.encodePropertyKey(typeNamePropertyKey); vertex.setProperty(encodedtypeNamePropertyKey, attrNames); }
public String getTypeName() { return attributeDef.getTypeName(); }
public AtlasAttributeDef(AtlasAttributeDef other) { if (other != null) { setName(other.getName()); setTypeName(other.getTypeName()); setIsOptional(other.getIsOptional()); setCardinality(other.getCardinality()); setValuesMinCount(other.getValuesMinCount()); setValuesMaxCount(other.getValuesMaxCount()); setIsUnique(other.getIsUnique()); setIsIndexable(other.getIsIndexable()); setIncludeInNotification(other.getIncludeInNotification()); setDefaultValue(other.getDefaultValue()); setConstraints(other.getConstraints()); setDescription((other.getDescription())); } }
public String getTypeName() { return attributeDef.getTypeName(); }
private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef, AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException { Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName()); String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class); for (String referencedTypeName : referencedTypeNames) { if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) { AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName); if (referencedTypeVertex == null) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName()); } String label = AtlasGraphUtilsV2.getEdgeLabel(typeName, attributeDef.getName()); typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label); } } }
public static AttributeDefinition toAttributeDefinition(AtlasAttribute attribute) { final AtlasAttributeDef attrDef = attribute.getAttributeDef(); AttributeDefinition ret = new AttributeDefinition(); ret.setName(attrDef.getName()); ret.setDataTypeName(attrDef.getTypeName()); ret.setMultiplicity(AtlasTypeUtil.getMultiplicity(attrDef)); ret.setIsComposite(attribute.isOwnedRef()); ret.setIsUnique(attrDef.getIsUnique()); ret.setIsIndexable(attrDef.getIsIndexable()); ret.setReverseAttributeName(attribute.getInverseRefAttributeName()); ret.setDescription(attrDef.getDescription()); ret.setDefaultValue(attrDef.getDefaultValue()); return ret; } }
private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef, AtlasTypeDefGraphStoreV2 typeDefStore) throws AtlasBaseException { Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName()); String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class); for (String referencedTypeName : referencedTypeNames) { if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) { AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName); if (referencedTypeVertex == null) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName()); } String label = AtlasGraphUtilsV2.getEdgeLabel(typeName, attributeDef.getName()); typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label); } } }
public AtlasAttributeDef(AtlasAttributeDef other) { if (other != null) { setName(other.getName()); setTypeName(other.getTypeName()); setIsOptional(other.getIsOptional()); setCardinality(other.getCardinality()); setValuesMinCount(other.getValuesMinCount()); setValuesMaxCount(other.getValuesMaxCount()); setIsUnique(other.getIsUnique()); setIsIndexable(other.getIsIndexable()); setDefaultValue(other.getDefaultValue()); setConstraints(other.getConstraints()); } }
public static AttributeDefinition toAttributeDefinition(AtlasAttribute attribute) { final AtlasAttributeDef attrDef = attribute.getAttributeDef(); AttributeDefinition ret = new AttributeDefinition(); ret.setName(attrDef.getName()); ret.setDataTypeName(attrDef.getTypeName()); ret.setMultiplicity(getMultiplicity(attrDef)); ret.setIsComposite(attribute.isOwnedRef()); ret.setIsUnique(attrDef.getIsUnique()); ret.setIsIndexable(attrDef.getIsIndexable()); ret.setReverseAttributeName(attribute.getInverseRefAttributeName()); ret.setDescription(attrDef.getDescription()); ret.setDefaultValue(attrDef.getDefaultValue()); return ret; } }
@Override void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); for (AtlasAttribute attribute : allAttributes.values()) { if (attribute.getInverseRefAttributeName() == null) { continue; } // Set the inverse reference attribute. AtlasType referencedType = typeRegistry.getType(attribute.getAttributeDef().getTypeName()); AtlasEntityType referencedEntityType = getReferencedEntityType(referencedType); AtlasAttribute inverseReference = referencedEntityType.getAttribute(attribute.getInverseRefAttributeName()); attribute.setInverseRefAttribute(inverseReference); } }
@Override public void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { super.resolveReferencesPhase2(typeRegistry); for (AtlasAttribute attribute : allAttributes.values()) { if (attribute.getInverseRefAttributeName() == null) { continue; } // Set the inverse reference attribute. AtlasType referencedType = typeRegistry.getType(attribute.getAttributeDef().getTypeName()); AtlasEntityType referencedEntityType = getReferencedEntityType(referencedType); AtlasAttribute inverseReference = referencedEntityType.getAttribute(attribute.getInverseRefAttributeName()); attribute.setInverseRefAttribute(inverseReference); } }
private void checkAndUpdate(AtlasStructDef structDef) { for (AtlasAttributeDef attrDef : structDef.getAttributeDefs()) { String attrTypeName = getAttributeTypeName(attrDef.getTypeName()); if (classificationIndexMap.containsKey(attrTypeName)) { ClassificationToStructDefName pair = createLegacyStructDefFromClassification(attrTypeName); if (pair != null) { updateAttributeWithNewType(pair.getTypeName(), pair.getLegacyTypeName(), attrDef); addStructDefToTypesDef(structDef.getName(), attrDef.getName(), pair); LOG.info("scrubbed: {}:{} -> {}", structDef.getName(), attrDef.getName(), attrDef.getTypeName()); } } } }
private void updateCollectionWithDifferingAttributes(List<AtlasStructDef.AtlasAttributeDef> difference, AtlasStructDef existing, AtlasStructDef.AtlasAttributeDef incoming) throws AtlasBaseException { AtlasStructDef.AtlasAttributeDef existingAttribute = existing.getAttribute(incoming.getName()); if (existingAttribute == null) { difference.add(incoming); } else { if (!existingAttribute.getTypeName().equals(incoming.getTypeName())) { LOG.error("Attribute definition difference found: {}, {}", existingAttribute, incoming); throw new AtlasBaseException(AtlasErrorCode.INVALID_IMPORT_ATTRIBUTE_TYPE_CHANGED, existing.getName(), existingAttribute.getName(), existingAttribute.getTypeName(), incoming.getTypeName()); } } }
private void addAttributeTypes(AtlasStructType structType, ExportService.ExportContext context) { for (AtlasStructDef.AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) { addType(attributeDef.getTypeName(), context); } }
private void addAttributeTypes(AtlasStructType structType, ExportContext context) { for (AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) { addType(attributeDef.getTypeName(), context); } }