@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; }
@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; }
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); } } }
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); } }
@Override public AtlasVertex preDeleteByName(String name) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.preDeleteByName({})", name); } AtlasEntityDef existingDef = typeRegistry.getEntityDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete entity-def ", name); AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); if (AtlasGraphUtilsV2.typeHasInstanceVertex(name)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, name); } if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } // error if we are trying to delete an entityDef that has a relationshipDef if (typeDefStore.hasIncomingEdgesWithLabel(ret, AtlasGraphUtilsV2.RELATIONSHIPTYPE_EDGE_LABEL)){ throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_RELATIONSHIPS, name); } typeDefStore.deleteTypeVertexOutEdges(ret); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.preDeleteByName({}): {}", name, ret); } return ret; }
@Override public AtlasVertex preDeleteByName(String name) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.preDeleteByName({})", name); } AtlasEntityDef existingDef = typeRegistry.getEntityDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete entity-def ", name); AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); if (AtlasGraphUtilsV2.typeHasInstanceVertex(name)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, name); } if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } // error if we are trying to delete an entityDef that has a relationshipDef if (typeDefStore.hasIncomingEdgesWithLabel(ret, AtlasGraphUtilsV2.RELATIONSHIPTYPE_EDGE_LABEL)){ throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_RELATIONSHIPS, name); } typeDefStore.deleteTypeVertexOutEdges(ret); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.preDeleteByName({}): {}", name, ret); } return ret; }
@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 updateEntityDef(AtlasTypesDef typeDefinitionMap, AtlasImportResult result) throws AtlasBaseException { for (AtlasEntityDef def : typeDefinitionMap.getEntityDefs()) { AtlasEntityDef existing = typeRegistry.getEntityDefByName(def.getName()); if (existing != null && addAttributes(existing, def)) { typeDefStore.updateEntityDefByName(existing.getName(), existing); result.incrementMeticsCounter("typedef:entitydef:update"); } } }
private void updateEntityDef(AtlasTypesDef typeDefinitionMap, AtlasImportResult result) throws AtlasBaseException { for (AtlasEntityDef def: typeDefinitionMap.getEntityDefs()) { AtlasEntityDef existing = typeRegistry.getEntityDefByName(def.getName()); if(existing != null && addAttributes(existing, def)) { typeDefStore.updateEntityDefByName(existing.getName(), existing); result.incrementMeticsCounter("typedef:entitydef:update"); } } }
assertNotNull(typeRegistry.getStructDefByName(structType), structType + ": struct not found"); assertNotNull(typeRegistry.getClassificationDefByName(classificationType), classificationType + ": classification not found"); assertNotNull(typeRegistry.getEntityDefByName(entityType), entityType + ": entity not found");
AtlasEntityDef oldEntityDef = typeRegistry.getEntityDefByName(newEntityDef.getName());
@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; }
@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; }
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); } }
assertNotNull(typeRegistry.getStructDefByName(structType), structType + ": struct not found"); assertNotNull(typeRegistry.getClassificationDefByName(classificationType), classificationType + ": classification not found"); assertNotNull(typeRegistry.getEntityDefByName(entityType), entityType + ": entity not found");
AtlasEntityDef oldEntityDef = typeRegistry.getEntityDefByName(newEntityDef.getName());