use of org.apache.atlas.model.typedef.AtlasTypesDef in project incubator-atlas by apache.
the class AtlasTypeDefGraphStore method updateGraphStore.
private AtlasTypesDef updateGraphStore(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);
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
ret.getEnumDefs().add(enumDefStore.update(enumDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
ret.getStructDefs().add(structDefStore.update(structDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
ret.getClassificationDefs().add(classifiDefStore.update(classifiDef));
}
}
if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
ret.getEntityDefs().add(entityDefStore.update(entityDef));
}
}
return ret;
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project nifi by apache.
the class NiFiAtlasClient method registerNiFiTypeDefs.
/**
* Create or update NiFi types in Atlas type system.
* @param update If false, doesn't perform anything if there is existing type def for the name.
*/
public void registerNiFiTypeDefs(boolean update) throws AtlasServiceException {
final Set<String> typeNames = ENTITIES.keySet();
final Map<String, AtlasEntityDef> existingDefs = getTypeDefs(typeNames.toArray(new String[typeNames.size()])).getEntityDefs().stream().collect(Collectors.toMap(AtlasEntityDef::getName, Function.identity()));
final AtomicBoolean shouldUpdate = new AtomicBoolean(false);
final AtlasTypesDef type = new AtlasTypesDef();
typeNames.stream().filter(typeName -> {
final AtlasEntityDef existingDef = existingDefs.get(typeName);
if (existingDef != null) {
// type is already defined.
if (!update) {
return false;
}
shouldUpdate.set(true);
}
return true;
}).forEach(typeName -> {
final NiFiTypes.EntityDefinition def = ENTITIES.get(typeName);
final AtlasEntityDef entity = new AtlasEntityDef();
type.getEntityDefs().add(entity);
entity.setName(typeName);
Set<String> superTypes = new HashSet<>();
List<AtlasAttributeDef> attributes = new ArrayList<>();
def.define(entity, superTypes, attributes);
entity.setSuperTypes(superTypes);
entity.setAttributeDefs(attributes);
});
// Create or Update.
final AtlasTypesDef atlasTypeDefsResult = shouldUpdate.get() ? atlasClient.updateAtlasTypeDefs(type) : atlasClient.createAtlasTypeDefs(type);
logger.debug("Result={}", atlasTypeDefsResult);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class TypesREST method getAllTypeDefs.
/**
* Bulk retrieval API for retrieving all type definitions in Atlas
* @return A composite wrapper object with lists of all type definitions
* @throws Exception
* @HTTP 200 {@link AtlasTypesDef} with type definitions matching the search criteria or else returns empty list of type definitions
*/
@GET
@Path("/typedefs")
@Produces(Servlets.JSON_MEDIA_TYPE)
public AtlasTypesDef getAllTypeDefs(@Context HttpServletRequest httpServletRequest) throws AtlasBaseException {
SearchFilter searchFilter = getSearchFilter(httpServletRequest);
AtlasTypesDef typesDef = typeDefStore.searchTypesDef(searchFilter);
return typesDef;
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class EntityV2JerseyResourceIT method testGetTraitDefinitionForEntity.
@Test(dependsOnMethods = "testSubmitEntity")
public void testGetTraitDefinitionForEntity() throws Exception {
traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet());
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(piiTrait);
createType(typesDef);
AtlasClassificationDef classificationByName = atlasClientV2.getClassificationDefByName(traitName);
assertNotNull(classificationByName);
AtlasEntity hiveTable = createHiveTable();
assertEquals(hiveTable.getClassifications().size(), 7);
AtlasClassification piiClassification = new AtlasClassification(piiTrait.getName());
atlasClientV2.addClassifications(hiveTable.getGuid(), Lists.newArrayList(piiClassification));
AtlasClassifications classifications = atlasClientV2.getClassifications(hiveTable.getGuid());
assertNotNull(classifications);
assertTrue(classifications.getList().size() > 0);
assertEquals(classifications.getList().size(), 8);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class EntityV2JerseyResourceIT method testDeleteExistentTraitNonExistentForEntity.
@Test(dependsOnMethods = "testSubmitEntity")
public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
final String guid = createHiveTable().getGuid();
final String traitName = "PII_Trait" + randomString();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet(), AtlasTypeUtil.createRequiredAttrDef("type", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(piiTrait);
createType(typesDef);
try {
atlasClientV2.deleteClassification(guid, traitName);
fail("Deletion should've failed for non-existent trait association");
} catch (AtlasServiceException ex) {
Assert.assertNotNull(ex.getStatus());
assertEquals(ex.getStatus(), ClientResponse.Status.BAD_REQUEST);
}
}
Aggregations