Search in sources :

Example 1 with AtlasTypesDef

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

the class AtlasTypeDefGraphStore method addToGraphStore.

private AtlasTypesDef addToGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();
    AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
    AtlasStructDefStore structDefStore = getStructDefStore(ttr);
    AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
    AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
    List<Object> preCreateStructDefs = new ArrayList<>();
    List<Object> preCreateClassifiDefs = new ArrayList<>();
    List<Object> preCreateEntityDefs = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
        for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
            AtlasEnumDef createdDef = enumDefStore.create(enumDef);
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getEnumDefs().add(createdDef);
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            preCreateStructDefs.add(structDefStore.preCreate(structDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            preCreateClassifiDefs.add(classifiDefStore.preCreate(classifiDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            preCreateEntityDefs.add(entityDefStore.preCreate(entityDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        int i = 0;
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            AtlasStructDef createdDef = structDefStore.create(structDef, preCreateStructDefs.get(i));
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getStructDefs().add(createdDef);
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        int i = 0;
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            AtlasClassificationDef createdDef = classifiDefStore.create(classifiDef, preCreateClassifiDefs.get(i));
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getClassificationDefs().add(createdDef);
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        int i = 0;
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            AtlasEntityDef createdDef = entityDefStore.create(entityDef, preCreateEntityDefs.get(i));
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getEntityDefs().add(createdDef);
            i++;
        }
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 2 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project ranger by apache.

the class AtlasRESTTagSource method getAtlasActiveEntities.

private List<RangerAtlasEntityWithTags> getAtlasActiveEntities() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> getAtlasActiveEntities()");
    }
    List<RangerAtlasEntityWithTags> ret = null;
    SearchParameters searchParams = new SearchParameters();
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTypeRegistry.AtlasTransientTypeRegistry tty = null;
    AtlasSearchResult searchResult = null;
    searchParams.setClassification("*");
    searchParams.setIncludeClassificationAttributes(true);
    searchParams.setOffset(0);
    searchParams.setLimit(Integer.MAX_VALUE);
    boolean commitUpdates = false;
    try {
        AtlasClientV2 atlasClient = getAtlasClient();
        searchResult = atlasClient.facetedSearch(searchParams);
        AtlasTypesDef typesDef = atlasClient.getAllTypeDefs(new SearchFilter());
        tty = typeRegistry.lockTypeRegistryForUpdate();
        tty.addTypes(typesDef);
        commitUpdates = true;
    } catch (AtlasServiceException | AtlasBaseException | IOException excp) {
        LOG.error("failed to download tags from Atlas", excp);
    } catch (Exception unexpectedException) {
        LOG.error("Failed to download tags from Atlas due to unexpected exception", unexpectedException);
    } finally {
        if (tty != null) {
            typeRegistry.releaseTypeRegistryForUpdate(tty, commitUpdates);
        }
    }
    if (commitUpdates && searchResult != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(AtlasType.toJson(searchResult));
        }
        ret = new ArrayList<>();
        List<AtlasEntityHeader> entityHeaders = searchResult.getEntities();
        if (CollectionUtils.isNotEmpty(entityHeaders)) {
            for (AtlasEntityHeader header : entityHeaders) {
                if (!header.getStatus().equals(AtlasEntity.Status.ACTIVE)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Skipping entity because it is not ACTIVE, header:[" + header + "]");
                    }
                    continue;
                }
                String typeName = header.getTypeName();
                if (!AtlasResourceMapperUtil.isEntityTypeHandled(typeName)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Not fetching Atlas entities of type:[" + typeName + "]");
                    }
                    continue;
                }
                List<EntityNotificationWrapper.RangerAtlasClassification> allTagsForEntity = new ArrayList<>();
                for (AtlasClassification classification : header.getClassifications()) {
                    List<EntityNotificationWrapper.RangerAtlasClassification> tags = resolveTag(typeRegistry, classification);
                    if (tags != null) {
                        allTagsForEntity.addAll(tags);
                    }
                }
                if (CollectionUtils.isNotEmpty(allTagsForEntity)) {
                    RangerAtlasEntity entity = new RangerAtlasEntity(typeName, header.getGuid(), header.getAttributes());
                    RangerAtlasEntityWithTags entityWithTags = new RangerAtlasEntityWithTags(entity, allTagsForEntity, typeRegistry);
                    ret.add(entityWithTags);
                }
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== getAtlasActiveEntities()");
    }
    return ret;
}
Also used : AtlasClientV2(org.apache.atlas.AtlasClientV2) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) ArrayList(java.util.ArrayList) SearchFilter(org.apache.atlas.model.SearchFilter) IOException(java.io.IOException) AtlasServiceException(org.apache.atlas.AtlasServiceException) IOException(java.io.IOException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult) SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 3 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project nifi by apache.

the class NiFiAtlasClient method getTypeDefs.

private AtlasTypesDef getTypeDefs(String... typeNames) throws AtlasServiceException {
    final AtlasTypesDef typeDefs = new AtlasTypesDef();
    for (int i = 0; i < typeNames.length; i++) {
        final MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
        searchParams.add(SearchFilter.PARAM_NAME, typeNames[i]);
        final AtlasTypesDef typeDef = atlasClient.getAllTypeDefs(new SearchFilter(searchParams));
        typeDefs.getEntityDefs().addAll(typeDef.getEntityDefs());
    }
    logger.debug("typeDefs={}", typeDefs);
    return typeDefs;
}
Also used : MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 4 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.

the class AtlasRelationshipStoreV1Test method setUp.

@BeforeClass
public void setUp() throws Exception {
    new GraphBackedSearchIndexer(typeRegistry);
    // create employee relationship types
    AtlasTypesDef employeeTypes = getDepartmentEmployeeTypes();
    typeDefStore.createTypesDef(employeeTypes);
    AtlasEntitiesWithExtInfo employeeInstances = getDepartmentEmployeeInstances();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(employeeInstances), false);
    for (AtlasEntityHeader entityHeader : response.getCreatedEntities()) {
        employeeNameIdMap.put((String) entityHeader.getAttribute(NAME), getAtlasObjectId(entityHeader));
    }
    init();
    AtlasTypesDef typesDef = getInverseReferenceTestTypes();
    AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
    if (!typesToCreate.isEmpty()) {
        typeDefStore.createTypesDef(typesToCreate);
    }
}
Also used : GraphBackedSearchIndexer(org.apache.atlas.repository.graph.GraphBackedSearchIndexer) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with AtlasTypesDef

use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.

the class UserProfileServiceTest method filterInternalType.

@Test
public void filterInternalType() throws AtlasBaseException {
    SearchFilter searchFilter = new SearchFilter();
    AtlasTypesDef filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
    int maxTypeDefs = filteredTypeDefs.getEntityDefs().size();
    FilterUtil.addParamsToHideInternalType(searchFilter);
    filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
    assertNotNull(filteredTypeDefs);
    assertEquals(filteredTypeDefs.getEntityDefs().size(), maxTypeDefs - 3);
}
Also used : SearchFilter(org.apache.atlas.model.SearchFilter) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)118 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)54 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)39 Test (org.testng.annotations.Test)39 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)30 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)22 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)22 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)20 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)19 ArrayList (java.util.ArrayList)18 SearchFilter (org.apache.atlas.model.SearchFilter)15 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)15 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)14 BeforeClass (org.testng.annotations.BeforeClass)14 HashMap (java.util.HashMap)13 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)13 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)12 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)9 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7