Search in sources :

Example 1 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters 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 2 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class UserProfileServiceTest method atteptsToAddAlreadyExistingQueryForAnExistingUser.

@Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser" }, expectedExceptions = AtlasBaseException.class)
public void atteptsToAddAlreadyExistingQueryForAnExistingUser() throws AtlasBaseException {
    SearchParameters expectedSearchParameter = getActualSearchParameters();
    for (int i = 0; i < 2; i++) {
        String userName = getIndexBasedUserName(i);
        for (int j = 0; j < max_searches; j++) {
            String queryName = getIndexBasedQueryName(j);
            AtlasUserSavedSearch expected = getDefaultSavedSearch(userName, queryName, expectedSearchParameter);
            AtlasUserSavedSearch actual = userProfileService.addSavedSearch(expected);
            assertNotNull(actual);
            assertNotNull(actual.getGuid());
            assertEquals(actual.getOwnerName(), expected.getOwnerName());
            assertEquals(actual.getName(), expected.getName());
            assertEquals(actual.getSearchType(), expected.getSearchType());
            assertEquals(actual.getSearchParameters(), expected.getSearchParameters());
        }
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 3 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class UserProfileServiceTest method savesQueryForAnNonExistentUser.

@Test(dependsOnMethods = "createsNewProfile")
public void savesQueryForAnNonExistentUser() throws AtlasBaseException {
    String expectedUserName = getIndexBasedUserName(0);
    String expectedQueryName = "testQuery";
    SearchParameters expectedSearchParam = getActualSearchParameters();
    AtlasUserSavedSearch expectedSavedSearch = getDefaultSavedSearch(expectedUserName, expectedQueryName, expectedSearchParam);
    AtlasUserSavedSearch actual = userProfileService.addSavedSearch(expectedSavedSearch);
    assertEquals(actual.getOwnerName(), expectedUserName);
    assertEquals(actual.getName(), expectedQueryName);
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 4 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class UserProfileServiceTest method savesExistingQueryForAnExistingUser.

@Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser", "atteptsToAddAlreadyExistingQueryForAnExistingUser" })
public void savesExistingQueryForAnExistingUser() throws AtlasBaseException {
    SearchParameters expectedSearchParameter = getActualSearchParameters();
    for (int i = 0; i < 2; i++) {
        String userName = getIndexBasedUserName(i);
        for (int j = 4; j < max_searches + 6; j++) {
            String queryName = getIndexBasedQueryName(j);
            AtlasUserSavedSearch actual = userProfileService.addSavedSearch(getDefaultSavedSearch(userName, queryName, expectedSearchParameter));
            assertNotNull(actual);
            AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName, queryName);
            assertNotNull(savedSearch);
            assertEquals(savedSearch.getSearchParameters(), expectedSearchParameter);
        }
    }
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters) AtlasUserSavedSearch(org.apache.atlas.model.profile.AtlasUserSavedSearch) Test(org.testng.annotations.Test)

Example 5 with SearchParameters

use of org.apache.atlas.model.discovery.SearchParameters in project atlas by apache.

the class UserProfileServiceTest method getActualSearchParameters.

private SearchParameters getActualSearchParameters() {
    SearchParameters sp = new SearchParameters();
    sp.setClassification("test-classification");
    sp.setQuery("g.v().has('__guid').__guid.toList()");
    sp.setLimit(10);
    sp.setTypeName("some-type");
    return sp;
}
Also used : SearchParameters(org.apache.atlas.model.discovery.SearchParameters)

Aggregations

SearchParameters (org.apache.atlas.model.discovery.SearchParameters)9 AtlasUserSavedSearch (org.apache.atlas.model.profile.AtlasUserSavedSearch)6 Test (org.testng.annotations.Test)5 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 AtlasClientV2 (org.apache.atlas.AtlasClientV2)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 SearchFilter (org.apache.atlas.model.SearchFilter)1 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)1 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)1 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)1 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)1 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)1 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)1