Java Code Examples for org.apache.atlas.model.discovery.AtlasSearchResult#getEntities()

The following examples show how to use org.apache.atlas.model.discovery.AtlasSearchResult#getEntities() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportImportAuditService.java    From atlas with Apache License 2.0 6 votes vote down vote up
private List<ExportImportAuditEntry> toExportImportAuditEntry(AtlasSearchResult result) {
    List<ExportImportAuditEntry> ret = new ArrayList<>();
    if(CollectionUtils.isEmpty(result.getEntities())) {
        return ret;
    }

    for (AtlasEntityHeader entityHeader : result.getEntities()) {
        ExportImportAuditEntry entry = ExportImportAuditEntryDTO.from(entityHeader.getGuid(),
                                                                        entityHeader.getAttributes());
        if(entry == null) {
            continue;
        }

        ret.add(entry);
    }

    return ret;
}
 
Example 2
Source File: AtlasAuditService.java    From atlas with Apache License 2.0 6 votes vote down vote up
private List<AtlasAuditEntry> toAtlasAuditEntries(AtlasSearchResult result) {
    List<AtlasAuditEntry> ret = new ArrayList<>();

    if(CollectionUtils.isNotEmpty(result.getEntities())) {
        for (AtlasEntityHeader entityHeader : result.getEntities()) {
            AtlasAuditEntry entry = AtlasAuditEntryDTO.from(entityHeader.getGuid(),
                    entityHeader.getAttributes());
            if (entry == null) {
                continue;
            }

            ret.add(entry);
        }
    }

    return ret;
}
 
Example 3
Source File: QuickStartV2.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void search() throws Exception {
    System.out.println("\nSample DSL Queries: ");

    for (String dslQuery : getDSLQueries()) {
        AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);

        if (results != null) {
            List<AtlasEntityHeader>   entitiesResult  = results.getEntities();
            List<AtlasFullTextResult> fullTextResults = results.getFullTextResult();
            AttributeSearchResult     attribResult    = results.getAttributes();

            if (CollectionUtils.isNotEmpty(entitiesResult)) {
                System.out.println("query [" + dslQuery + "] returned [" + entitiesResult.size() + "] rows.");
            } else if (CollectionUtils.isNotEmpty(fullTextResults)) {
                System.out.println("query [" + dslQuery + "] returned [" + fullTextResults.size() + "] rows.");
            } else if (attribResult != null) {
                System.out.println("query [" + dslQuery + "] returned [" + attribResult.getValues().size() + "] rows.");
            }
        } else {
            System.out.println("query [" + dslQuery + "] failed, results:" + results);
        }
    }
}
 
Example 4
Source File: EntityDiscoveryJerseyResourceIT.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchByDSL() throws Exception {
    String dslQuery = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";

    AtlasSearchResult searchResult = atlasClientV2.dslSearch(dslQuery);
    assertNotNull(searchResult);
    assertEquals(searchResult.getQueryText(), dslQuery);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);

    List<AtlasEntityHeader> entities = searchResult.getEntities();
    assertNotNull(entities);
    assertEquals(entities.size(), 1);

    AtlasEntityHeader dbEntity = entities.get(0);
    assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
    assertEquals(dbEntity.getDisplayText(), dbName);
    assertEquals(dbEntity.getStatus(), Status.ACTIVE);
    assertNotNull(dbEntity.getGuid());
    assertNull(searchResult.getAttributes());
    assertNull(searchResult.getFullTextResult());
}
 
Example 5
Source File: EntityDiscoveryJerseyResourceIT.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchUsingDSL() throws Exception {
    String query = "from "+ DATABASE_TYPE_BUILTIN + " " + QUALIFIED_NAME + "=\"" + dbName + "\"";
    AtlasSearchResult searchResult = atlasClientV2.dslSearch(query);
    assertNotNull(searchResult);

    assertEquals(searchResult.getQueryText(), query);
    assertEquals(searchResult.getQueryType(), AtlasQueryType.DSL);
    List<AtlasEntityHeader> entities = searchResult.getEntities();
    assertNotNull(entities);
    assertEquals(entities.size(), 1);

    AtlasEntityHeader dbEntity = entities.get(0);
    assertEquals(dbEntity.getTypeName(), DATABASE_TYPE_BUILTIN);
    assertEquals(dbEntity.getDisplayText(), dbName);
    assertEquals(dbEntity.getStatus(), Status.ACTIVE);

    assertNotNull(dbEntity.getGuid());
    assertNull(searchResult.getAttributes());
    assertNull(searchResult.getFullTextResult());
}
 
Example 6
Source File: QuickStartV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void search() throws Exception {
    System.out.println("\nSample DSL Queries: ");

    for (String dslQuery : getDSLQueries()) {
        try {
            AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);

            if (results != null) {
                List<AtlasEntityHeader> entitiesResult = results.getEntities();
                List<AtlasFullTextResult> fullTextResults = results.getFullTextResult();
                AttributeSearchResult attribResult = results.getAttributes();

                if (CollectionUtils.isNotEmpty(entitiesResult)) {
                    System.out.println("query [" + dslQuery + "] returned [" + entitiesResult.size() + "] rows.");
                } else if (CollectionUtils.isNotEmpty(fullTextResults)) {
                    System.out.println("query [" + dslQuery + "] returned [" + fullTextResults.size() + "] rows.");
                } else if (attribResult != null) {
                    System.out.println("query [" + dslQuery + "] returned [" + attribResult.getValues().size() + "] rows.");
                } else {
                    System.out.println("query [" + dslQuery + "] returned [ 0 ] rows.");
                }
            } else {
                System.out.println("query [" + dslQuery + "] failed, results:" + results);
            }
        } catch (Exception e) {
            System.out.println("query [" + dslQuery + "] execution failed!");
        }
    }
}
 
Example 7
Source File: DSLQueriesTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void assertSearchResult(AtlasSearchResult searchResult, int expected, String query) {
    assertNotNull(searchResult);
    if(expected == 0) {
        assertTrue(searchResult.getAttributes() == null || CollectionUtils.isEmpty(searchResult.getAttributes().getValues()));
        assertNull(searchResult.getEntities(), query);
    } else if(searchResult.getEntities() != null) {
        assertEquals(searchResult.getEntities().size(), expected, query);
    } else {
        assertNotNull(searchResult.getAttributes());
        assertNotNull(searchResult.getAttributes().getValues());
        assertEquals(searchResult.getAttributes().getValues().size(), expected, query);
    }
}
 
Example 8
Source File: TableReplicationRequestProcessor.java    From atlas with Apache License 2.0 4 votes vote down vote up
private Set<String> getGuidsToDelete(String dbName, List<String> excludeGUIDs, String sourceCluster) throws AtlasBaseException {

        SearchParameters parameters = getSearchParameters(dbName, sourceCluster);
        Set<String> unsafeGUIDs = new HashSet<>();

        final int max = 10000;
        int fetchedSize = 0;
        int i = 0;
        parameters.setLimit(max);

        while (fetchedSize == (max * i)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("i={}, fetchedSize={}, unsafeGUIDs.size()={}", i, fetchedSize, unsafeGUIDs.size());
            }

            int offset = max * i;
            parameters.setOffset(offset);

            AtlasSearchResult searchResult = discoveryService.searchWithParameters(parameters);

            if (CollectionUtils.isEmpty(searchResult.getEntities())) {
                break;
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("getGuidsToDelete: {}", searchResult.getApproximateCount());
                }
            }

            String classificationName = String.format(REPLICATED_TAG_NAME, sourceCluster);
            for (AtlasEntityHeader entityHeader : searchResult.getEntities()) {
                if (!entityHeader.getClassificationNames().contains(classificationName)) {
                    continue;
                }

                String guid = entityHeader.getGuid();
                if (!excludeGUIDs.contains(guid)) {
                    unsafeGUIDs.add(guid);
                }
            }
            fetchedSize = searchResult.getEntities().size();
            i++;
        }
        return unsafeGUIDs;
    }
 
Example 9
Source File: DSLQueriesTest.java    From atlas with Apache License 2.0 4 votes vote down vote up
private void pollForData() throws InterruptedException {
    Object[][] basicVerificationQueries = new Object[][] {
            {"hive_db", 3},
            {"hive_process", 7},
            {"hive_table", 10},
            {"hive_column", 17},
            {"hive_storagedesc", 1},
            {"Manager", 2},
            {"Employee", 4},
    };

    int pollingAttempts = 5;
    int pollingBackoff  = 0; // in msecs

    boolean success;

    for (int attempt = 0; attempt < pollingAttempts; attempt++, pollingBackoff += attempt * 5000) {
        LOG.debug("Polling -- Attempt {}, Backoff {}", attempt, pollingBackoff);

        success = false;
        for (Object[] verificationQuery : basicVerificationQueries) {
            String query = (String) verificationQuery[0];
            int expected = (int) verificationQuery[1];

            try {
                AtlasSearchResult result = discoveryService.searchUsingDslQuery(query, 25, 0);
                if (result.getEntities() == null || result.getEntities().isEmpty()) {
                    LOG.warn("DSL {} returned no entities", query);
                    success = false;
                } else if (result.getEntities().size() != expected) {
                    LOG.warn("DSL {} returned unexpected number of entities. Expected {} Actual {}", query, expected, result.getEntities().size());
                    success = false;
                } else {
                    success = true;
                }
            } catch (AtlasBaseException e) {
                LOG.error("Got exception for DSL {}, errorCode: {}", query, e.getAtlasErrorCode());
                waitOrBailout(pollingAttempts, pollingBackoff, attempt);
            }
        }
        // DSL queries were successful
        if (success) {
            LOG.info("Polling was success");
            break;
        } else {
            waitOrBailout(pollingAttempts, pollingBackoff, attempt);
        }
    }
}