use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.
the class AtlasTypeDefGraphStoreTest method testUpdate.
@Test(dependsOnMethods = { "testCreateDept" }, dataProvider = "validUpdateDeptTypes")
public void testUpdate(AtlasTypesDef atlasTypesDef) {
try {
AtlasTypesDef updatedTypesDef = typeDefStore.updateTypesDef(atlasTypesDef);
assertNotNull(updatedTypesDef);
assertEquals(updatedTypesDef.getEnumDefs().size(), atlasTypesDef.getEnumDefs().size(), "EnumDefs update failed");
assertEquals(updatedTypesDef.getClassificationDefs().size(), atlasTypesDef.getClassificationDefs().size(), "ClassificationDef update failed");
assertEquals(updatedTypesDef.getStructDefs().size(), atlasTypesDef.getStructDefs().size(), "StructDef update failed");
assertEquals(updatedTypesDef.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size(), "EntityDef update failed");
// Try another update round by name and GUID
for (AtlasEnumDef enumDef : updatedTypesDef.getEnumDefs()) {
AtlasEnumDef updated = typeDefStore.updateEnumDefByGuid(enumDef.getGuid(), enumDef);
assertNotNull(updated);
}
for (AtlasEnumDef enumDef : atlasTypesDef.getEnumDefs()) {
AtlasEnumDef updated = typeDefStore.updateEnumDefByName(enumDef.getName(), enumDef);
assertNotNull(updated);
}
// Try another update round by name and GUID
for (AtlasClassificationDef classificationDef : updatedTypesDef.getClassificationDefs()) {
AtlasClassificationDef updated = typeDefStore.updateClassificationDefByGuid(classificationDef.getGuid(), classificationDef);
assertNotNull(updated);
}
for (AtlasClassificationDef classificationDef : atlasTypesDef.getClassificationDefs()) {
AtlasClassificationDef updated = typeDefStore.updateClassificationDefByName(classificationDef.getName(), classificationDef);
assertNotNull(updated);
}
// Try another update round by name and GUID
for (AtlasStructDef structDef : updatedTypesDef.getStructDefs()) {
AtlasStructDef updated = typeDefStore.updateStructDefByGuid(structDef.getGuid(), structDef);
assertNotNull(updated);
}
for (AtlasStructDef structDef : atlasTypesDef.getStructDefs()) {
AtlasStructDef updated = typeDefStore.updateStructDefByName(structDef.getName(), structDef);
assertNotNull(updated);
}
// Try another update round by name and GUID
for (AtlasEntityDef entityDef : updatedTypesDef.getEntityDefs()) {
AtlasEntityDef updated = typeDefStore.updateEntityDefByGuid(entityDef.getGuid(), entityDef);
assertNotNull(updated);
}
for (AtlasEntityDef entityDef : atlasTypesDef.getEntityDefs()) {
AtlasEntityDef updated = typeDefStore.updateEntityDefByName(entityDef.getName(), entityDef);
assertNotNull(updated);
}
} catch (AtlasBaseException e) {
fail("TypeDef updates should've succeeded");
}
}
use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.
the class BaseResourceIT method batchCreateTypes.
protected void batchCreateTypes(AtlasTypesDef typesDef) throws AtlasServiceException {
AtlasTypesDef toCreate = new AtlasTypesDef();
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
if (atlasClientV2.typeWithNameExists(enumDef.getName())) {
LOG.warn("Type with name {} already exists. Skipping", enumDef.getName());
} else {
toCreate.getEnumDefs().add(enumDef);
}
}
for (AtlasStructDef structDef : typesDef.getStructDefs()) {
if (atlasClientV2.typeWithNameExists(structDef.getName())) {
LOG.warn("Type with name {} already exists. Skipping", structDef.getName());
} else {
toCreate.getStructDefs().add(structDef);
}
}
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
if (atlasClientV2.typeWithNameExists(entityDef.getName())) {
LOG.warn("Type with name {} already exists. Skipping", entityDef.getName());
} else {
toCreate.getEntityDefs().add(entityDef);
}
}
for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
if (atlasClientV2.typeWithNameExists(classificationDef.getName())) {
LOG.warn("Type with name {} already exists. Skipping", classificationDef.getName());
} else {
toCreate.getClassificationDefs().add(classificationDef);
}
}
atlasClientV2.createAtlasTypeDefs(toCreate);
}
use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.
the class DefaultTypeSystem method createType.
private <T extends HierarchicalType> void createType(Collection<AttributeDefinition> attributes, Class<T> type, String name, String description, boolean isTrait) throws ResourceAlreadyExistsException {
try {
List<AtlasStructDef.AtlasAttributeDef> attrDefs = new ArrayList<>();
for (AttributeDefinition attrDefinition : attributes) {
attrDefs.add(TypeConverterUtil.toAtlasAttributeDef(attrDefinition));
}
if (isTrait) {
AtlasClassificationDef classificationDef = new AtlasClassificationDef(name, description, "1.0", attrDefs, ImmutableSet.of(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE));
AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.of(classificationDef), ImmutableList.<AtlasEntityDef>of());
typeDefStore.createTypesDef(typesDef);
} else {
AtlasEntityDef entityDef = new AtlasEntityDef(name, description, "1.0", attrDefs);
AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.of(entityDef));
typeDefStore.createTypesDef(typesDef);
}
} catch (AtlasBaseException e) {
if (e.getAtlasErrorCode() == AtlasErrorCode.TYPE_ALREADY_EXISTS) {
throw new ResourceAlreadyExistsException(String.format("Type '%s' already exists", name));
} else {
throw new CatalogRuntimeException(String.format("Unable to create type '%s' in type system: %s", name, e), e);
}
}
}
use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.
the class DefaultTypeSystem method createSuperTypes.
@InterfaceAudience.Private
private void createSuperTypes() throws AtlasBaseException {
AtlasClassificationDef termClassification = AtlasTypeUtil.createTraitTypeDef(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE, TaxonomyResourceProvider.TAXONOMY_TERM_TYPE, ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, "string"));
createTraitType(termClassification);
}
use of org.apache.atlas.model.typedef.AtlasClassificationDef in project incubator-atlas by apache.
the class TypeDefSorter method addToResult.
private static <T extends AtlasStructDef> void addToResult(T type, List<T> result, Set<T> processed, Map<String, T> typesByName) {
if (processed.contains(type)) {
return;
}
processed.add(type);
Set<String> superTypeNames = new HashSet<>();
if (type.getClass().equals(AtlasClassificationDef.class)) {
try {
AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
superTypeNames.addAll(classificationDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to ClassificationDef failed");
}
}
if (type.getClass().equals(AtlasEntityDef.class)) {
try {
AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
superTypeNames.addAll(entityDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to AtlasEntityDef failed");
}
}
for (String superTypeName : superTypeNames) {
// Recursively add any supertypes first to the result.
T superType = typesByName.get(superTypeName);
if (superType != null) {
addToResult(superType, result, processed, typesByName);
}
}
result.add(type);
}
Aggregations