Search in sources :

Example 16 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class AtlasTypeDefGraphStoreTest method testUpdate.

@Test(dependsOnMethods = { "testCreateDept" }, dataProvider = "validUpdateDeptTypes")
public void testUpdate(AtlasTypesDef atlasTypesDef) {
    try {
        AtlasTypesDef updatedTypesDef = typeDefStore.updateTypesDef(atlasTypesDef);
        assertNotNull(updatedTypesDef);
        assertEquals(updatedTypesDef.getEnumDefs().size(), atlasTypesDef.getEnumDefs().size(), "EnumDefs update failed");
        assertEquals(updatedTypesDef.getClassificationDefs().size(), atlasTypesDef.getClassificationDefs().size(), "ClassificationDef update failed");
        assertEquals(updatedTypesDef.getStructDefs().size(), atlasTypesDef.getStructDefs().size(), "StructDef update failed");
        assertEquals(updatedTypesDef.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size(), "EntityDef update failed");
        // Try another update round by name and GUID
        for (AtlasEnumDef enumDef : updatedTypesDef.getEnumDefs()) {
            AtlasEnumDef updated = typeDefStore.updateEnumDefByGuid(enumDef.getGuid(), enumDef);
            assertNotNull(updated);
        }
        for (AtlasEnumDef enumDef : atlasTypesDef.getEnumDefs()) {
            AtlasEnumDef updated = typeDefStore.updateEnumDefByName(enumDef.getName(), enumDef);
            assertNotNull(updated);
        }
        // Try another update round by name and GUID
        for (AtlasClassificationDef classificationDef : updatedTypesDef.getClassificationDefs()) {
            AtlasClassificationDef updated = typeDefStore.updateClassificationDefByGuid(classificationDef.getGuid(), classificationDef);
            assertNotNull(updated);
        }
        for (AtlasClassificationDef classificationDef : atlasTypesDef.getClassificationDefs()) {
            AtlasClassificationDef updated = typeDefStore.updateClassificationDefByName(classificationDef.getName(), classificationDef);
            assertNotNull(updated);
        }
        // Try another update round by name and GUID
        for (AtlasStructDef structDef : updatedTypesDef.getStructDefs()) {
            AtlasStructDef updated = typeDefStore.updateStructDefByGuid(structDef.getGuid(), structDef);
            assertNotNull(updated);
        }
        for (AtlasStructDef structDef : atlasTypesDef.getStructDefs()) {
            AtlasStructDef updated = typeDefStore.updateStructDefByName(structDef.getName(), structDef);
            assertNotNull(updated);
        }
        // Try another update round by name and GUID
        for (AtlasEntityDef entityDef : updatedTypesDef.getEntityDefs()) {
            AtlasEntityDef updated = typeDefStore.updateEntityDefByGuid(entityDef.getGuid(), entityDef);
            assertNotNull(updated);
        }
        for (AtlasEntityDef entityDef : atlasTypesDef.getEntityDefs()) {
            AtlasEntityDef updated = typeDefStore.updateEntityDefByName(entityDef.getName(), entityDef);
            assertNotNull(updated);
        }
    } catch (AtlasBaseException e) {
        fail("TypeDef updates should've succeeded");
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 17 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class BaseResourceIT method batchCreateTypes.

protected void batchCreateTypes(AtlasTypesDef typesDef) throws AtlasServiceException {
    AtlasTypesDef toCreate = new AtlasTypesDef();
    for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
        if (atlasClientV2.typeWithNameExists(enumDef.getName())) {
            LOG.warn("Type with name {} already exists. Skipping", enumDef.getName());
        } else {
            toCreate.getEnumDefs().add(enumDef);
        }
    }
    for (AtlasStructDef structDef : typesDef.getStructDefs()) {
        if (atlasClientV2.typeWithNameExists(structDef.getName())) {
            LOG.warn("Type with name {} already exists. Skipping", structDef.getName());
        } else {
            toCreate.getStructDefs().add(structDef);
        }
    }
    for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
        if (atlasClientV2.typeWithNameExists(entityDef.getName())) {
            LOG.warn("Type with name {} already exists. Skipping", entityDef.getName());
        } else {
            toCreate.getEntityDefs().add(entityDef);
        }
    }
    for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
        if (atlasClientV2.typeWithNameExists(classificationDef.getName())) {
            LOG.warn("Type with name {} already exists. Skipping", classificationDef.getName());
        } else {
            toCreate.getClassificationDefs().add(classificationDef);
        }
    }
    atlasClientV2.createAtlasTypeDefs(toCreate);
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 18 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class DefaultTypeSystem method createType.

private <T extends HierarchicalType> void createType(Collection<AttributeDefinition> attributes, Class<T> type, String name, String description, boolean isTrait) throws ResourceAlreadyExistsException {
    try {
        List<AtlasStructDef.AtlasAttributeDef> attrDefs = new ArrayList<>();
        for (AttributeDefinition attrDefinition : attributes) {
            attrDefs.add(TypeConverterUtil.toAtlasAttributeDef(attrDefinition));
        }
        if (isTrait) {
            AtlasClassificationDef classificationDef = new AtlasClassificationDef(name, description, "1.0", attrDefs, ImmutableSet.of(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE));
            AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.of(classificationDef), ImmutableList.<AtlasEntityDef>of());
            typeDefStore.createTypesDef(typesDef);
        } else {
            AtlasEntityDef entityDef = new AtlasEntityDef(name, description, "1.0", attrDefs);
            AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.of(entityDef));
            typeDefStore.createTypesDef(typesDef);
        }
    } catch (AtlasBaseException e) {
        if (e.getAtlasErrorCode() == AtlasErrorCode.TYPE_ALREADY_EXISTS) {
            throw new ResourceAlreadyExistsException(String.format("Type '%s' already exists", name));
        } else {
            throw new CatalogRuntimeException(String.format("Unable to create type '%s' in type system: %s", name, e), e);
        }
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ResourceAlreadyExistsException(org.apache.atlas.catalog.exception.ResourceAlreadyExistsException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 19 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class DefaultTypeSystem method createSuperTypes.

@InterfaceAudience.Private
private void createSuperTypes() throws AtlasBaseException {
    AtlasClassificationDef termClassification = AtlasTypeUtil.createTraitTypeDef(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE, TaxonomyResourceProvider.TAXONOMY_TERM_TYPE, ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, "string"));
    createTraitType(termClassification);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef)

Example 20 with AtlasClassificationDef

use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.

the class TypeDefSorter method addToResult.

private static <T extends AtlasStructDef> void addToResult(T type, List<T> result, Set<T> processed, Map<String, T> typesByName) {
    if (processed.contains(type)) {
        return;
    }
    processed.add(type);
    Set<String> superTypeNames = new HashSet<>();
    if (type.getClass().equals(AtlasClassificationDef.class)) {
        try {
            AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
            superTypeNames.addAll(classificationDef.getSuperTypes());
        } catch (ClassCastException ex) {
            LOG.warn("Casting to ClassificationDef failed");
        }
    }
    if (type.getClass().equals(AtlasEntityDef.class)) {
        try {
            AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
            superTypeNames.addAll(entityDef.getSuperTypes());
        } catch (ClassCastException ex) {
            LOG.warn("Casting to AtlasEntityDef failed");
        }
    }
    for (String superTypeName : superTypeNames) {
        // Recursively add any supertypes first to the result.
        T superType = typesByName.get(superTypeName);
        if (superType != null) {
            addToResult(superType, result, processed, typesByName);
        }
    }
    result.add(type);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashSet(java.util.HashSet)

Aggregations

AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)45 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)24 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)22 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)21 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)18 Test (org.testng.annotations.Test)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 ArrayList (java.util.ArrayList)8 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)8 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)5 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 HashMap (java.util.HashMap)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2