use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class TypedefsJerseyResourceIT method testListTypesByFilter.
@Test
public void testListTypesByFilter() throws Exception {
AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr);
AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(classDefA.getName()), attr);
AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr);
AtlasEntityDef classDefC = AtlasTypeUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(classDefB.getName(), classDefA.getName()), attr);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEntityDefs().add(classDefA);
atlasTypesDef.getEntityDefs().add(classDefA1);
atlasTypesDef.getEntityDefs().add(classDefB);
atlasTypesDef.getEntityDefs().add(classDefC);
AtlasTypesDef created = clientV2.createAtlasTypeDefs(atlasTypesDef);
assertNotNull(created);
assertEquals(created.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
searchParams.add(SearchFilter.PARAM_TYPE, "CLASS");
searchParams.add(SearchFilter.PARAM_SUPERTYPE, classDefA.getName());
SearchFilter searchFilter = new SearchFilter(searchParams);
AtlasTypesDef searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 2);
searchParams.add(SearchFilter.PARAM_NOT_SUPERTYPE, classDefB.getName());
searchFilter = new SearchFilter(searchParams);
searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 1);
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class TypedefsJerseyResourceIT method testCreate.
@Test
public void testCreate() throws Exception {
createType(typeDefinitions);
for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) {
AtlasEnumDef byName = atlasClientV2.getEnumDefByName(enumDef.getName());
assertNotNull(byName);
}
for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
AtlasStructDef byName = atlasClientV2.getStructDefByName(structDef.getName());
assertNotNull(byName);
}
for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
AtlasClassificationDef byName = atlasClientV2.getClassificationDefByName(classificationDef.getName());
assertNotNull(byName);
}
for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
AtlasEntityDef byName = atlasClientV2.getEntityDefByName(entityDef.getName());
assertNotNull(byName);
}
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class RestUtilsTest method convertV2toV1.
private List<HierarchicalTypeDefinition<ClassType>> convertV2toV1(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
AtlasTypeRegistry reg = createRegistry(toConvert);
List<HierarchicalTypeDefinition<ClassType>> result = new ArrayList<>(toConvert.size());
for (int i = 0; i < toConvert.size(); i++) {
AtlasEntityDef entityDef = toConvert.get(i);
AtlasEntityType entity = reg.getEntityTypeByName(entityDef.getName());
HierarchicalTypeDefinition<ClassType> converted = TypeConverterUtil.toTypesDef(entity, reg).classTypesAsJavaList().get(0);
result.add(converted);
}
return result;
}
use of org.apache.atlas.model.typedef.AtlasEntityDef 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.AtlasEntityDef 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);
}
Aggregations