use of org.apache.atlas.model.SearchFilter 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;
}
use of org.apache.atlas.model.SearchFilter 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;
}
use of org.apache.atlas.model.SearchFilter 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);
}
use of org.apache.atlas.model.SearchFilter in project atlas by apache.
the class AtlasTypeDefGraphStoreTest method testSearchFunctionality.
@Test(dependsOnMethods = "testGet")
public void testSearchFunctionality() {
SearchFilter searchFilter = new SearchFilter();
searchFilter.setParam(SearchFilter.PARAM_SUPERTYPE, "Person");
try {
AtlasTypesDef typesDef = typeDefStore.searchTypesDef(searchFilter);
assertNotNull(typesDef);
assertNotNull(typesDef.getEntityDefs());
assertEquals(typesDef.getEntityDefs().size(), 3);
} catch (AtlasBaseException e) {
fail("Search should've succeeded", e);
}
}
use of org.apache.atlas.model.SearchFilter in project atlas by apache.
the class TypesREST method getTypeDefHeaders.
/**
* Bulk retrieval API for all type definitions returned as a list of minimal information header
* @return List of AtlasTypeDefHeader {@link AtlasTypeDefHeader}
* @throws AtlasBaseException
* @HTTP 200 Returns a list of {@link AtlasTypeDefHeader} matching the search criteria
* or an empty list if no match.
*/
@GET
@Path("/typedefs/headers")
@Produces(Servlets.JSON_MEDIA_TYPE)
public List<AtlasTypeDefHeader> getTypeDefHeaders(@Context HttpServletRequest httpServletRequest) throws AtlasBaseException {
SearchFilter searchFilter = getSearchFilter(httpServletRequest);
AtlasTypesDef searchTypesDef = typeDefStore.searchTypesDef(searchFilter);
return AtlasTypeUtil.toTypeDefHeader(searchTypesDef);
}
Aggregations