use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class AtlasTypeDefStoreInitializer method loadModelsInFolder.
/**
* Load all the model files in the supplied folder followed by the contents of the patches folder.
* @param typesDir
*/
private void loadModelsInFolder(File typesDir) {
LOG.info("==> AtlasTypeDefStoreInitializer({})", typesDir);
String typesDirName = typesDir.getName();
File[] typeDefFiles = typesDir.exists() ? typesDir.listFiles() : null;
if (typeDefFiles == null || typeDefFiles.length == 0) {
LOG.info("Types directory {} does not exist or not readable or has no typedef files", typesDirName);
} else {
// sort the files by filename
Arrays.sort(typeDefFiles);
for (File typeDefFile : typeDefFiles) {
if (typeDefFile.isFile()) {
try {
String jsonStr = new String(Files.readAllBytes(typeDefFile.toPath()), StandardCharsets.UTF_8);
AtlasTypesDef typesDef = AtlasType.fromJson(jsonStr, AtlasTypesDef.class);
if (typesDef == null || typesDef.isEmpty()) {
LOG.info("No type in file {}", typeDefFile.getAbsolutePath());
continue;
}
AtlasTypesDef typesToCreate = getTypesToCreate(typesDef, atlasTypeRegistry);
AtlasTypesDef typesToUpdate = getTypesToUpdate(typesDef, atlasTypeRegistry, true);
if (!typesToCreate.isEmpty() || !typesToUpdate.isEmpty()) {
atlasTypeDefStore.createUpdateTypesDef(typesToCreate, typesToUpdate);
LOG.info("Created/Updated types defined in file {}", typeDefFile.getAbsolutePath());
} else {
LOG.info("No new type in file {}", typeDefFile.getAbsolutePath());
}
} catch (Throwable t) {
LOG.error("error while registering types in file {}", typeDefFile.getAbsolutePath(), t);
}
}
}
applyTypePatches(typesDir.getPath());
}
LOG.info("<== AtlasTypeDefStoreInitializer({})", typesDir);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class QuickStartV2 method createTypes.
void createTypes() throws Exception {
AtlasTypesDef atlasTypesDef = createTypeDefinitions();
System.out.println("\nCreating sample types: ");
atlasClientV2.createAtlasTypeDefs(atlasTypesDef);
verifyTypesCreated();
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class AtlasEntityStoreV1Test method testTagAssociationAfterRedefinition.
@Test
public void testTagAssociationAfterRedefinition() {
AtlasClassificationDef aTag = new AtlasClassificationDef("testTag");
AtlasAttributeDef attributeDef = new AtlasAttributeDef("testAttribute", "int", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag creation should've succeeded");
}
try {
typeDefStore.deleteTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag deletion should've succeeded");
}
aTag = new AtlasClassificationDef("testTag");
attributeDef = new AtlasAttributeDef("testAttribute", "string", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag re-creation should've succeeded");
}
final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
try {
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
List<AtlasEntityHeader> createdEntity = response.getCreatedEntities();
assertTrue(CollectionUtils.isNotEmpty(createdEntity));
String guid = createdEntity.get(0).getGuid();
entityStore.addClassification(Arrays.asList(guid), new AtlasClassification(aTag.getName(), "testAttribute", "test-string"));
} catch (AtlasBaseException e) {
fail("DB entity creation should've succeeded, e.getMessage() => " + e.getMessage());
}
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class AtlasEntityStoreV1Test method testSpecialCharacters.
@Test(enabled = false)
public // TODO : Failing in typedef creation
void testSpecialCharacters() throws Exception {
// Verify that type can be created with reserved characters in typename, attribute name
final String typeName = TestUtilsV2.randomString(10);
String strAttrName = randomStrWithReservedChars();
String arrayAttrName = randomStrWithReservedChars();
String mapAttrName = randomStrWithReservedChars();
AtlasEntityDef typeDefinition = AtlasTypeUtil.createClassTypeDef(typeName, "Special chars test type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef(strAttrName, "string"), AtlasTypeUtil.createOptionalAttrDef(arrayAttrName, "array<string>"), AtlasTypeUtil.createOptionalAttrDef(mapAttrName, "map<string,string>"));
AtlasTypesDef atlasTypesDef = new AtlasTypesDef(null, null, null, Arrays.asList(typeDefinition));
typeDefStore.createTypesDef(atlasTypesDef);
// verify that entity can be created with reserved characters in string value, array value and map key and value
AtlasEntity entity = new AtlasEntity();
entity.setAttribute(strAttrName, randomStrWithReservedChars());
entity.setAttribute(arrayAttrName, new String[] { randomStrWithReservedChars() });
entity.setAttribute(mapAttrName, new HashMap<String, String>() {
{
put(randomStrWithReservedChars(), randomStrWithReservedChars());
}
});
AtlasEntityWithExtInfo entityWithExtInfo = new AtlasEntityWithExtInfo(entity);
final EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entityWithExtInfo), false);
final AtlasEntityHeader firstEntityCreated = response.getFirstEntityCreated();
validateEntity(entityWithExtInfo, getEntityFromStore(firstEntityCreated));
// Verify that search with reserved characters works - for string attribute
// String query =
// String.format("`%s` where `%s` = '%s'", typeName, strAttrName, entity.getAttribute(strAttrName));
// String responseJson = discoveryService.searchByDSL(query, new QueryParams(1, 0));
// JSONObject response = new JSONObject(responseJson);
// assertEquals(response.getJSONArray("rows").length(), 1);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class AtlasEntityStoreV1Test method setUp.
@BeforeClass
public void setUp() throws Exception {
RequestContextV1.clear();
RequestContextV1.get().setUser(TestUtilsV2.TEST_USER, null);
new GraphBackedSearchIndexer(typeRegistry);
AtlasTypesDef[] testTypesDefs = new AtlasTypesDef[] { TestUtilsV2.defineDeptEmployeeTypes(), TestUtilsV2.defineHiveTypes(), TestUtilsV2.defineTypeWithNestedCollectionAttributes() };
for (AtlasTypesDef typesDef : testTypesDefs) {
AtlasTypesDef typesToCreate = AtlasTypeDefStoreInitializer.getTypesToCreate(typesDef, typeRegistry);
if (!typesToCreate.isEmpty()) {
typeDefStore.createTypesDef(typesToCreate);
}
}
deptEntity = TestUtilsV2.createDeptEg2();
dbEntity = TestUtilsV2.createDBEntityV2();
tblEntity = TestUtilsV2.createTableEntityV2(dbEntity.getEntity());
nestedCollectionAttrEntity = TestUtilsV2.createNestedCollectionAttrEntity();
AtlasTypesDef typesDef11 = new AtlasTypesDef();
List primitiveEntityDef = new ArrayList<AtlasEntityDef>();
primitiveEntityDef.add(TestUtilsV2.createPrimitiveEntityDef());
typesDef11.setEntityDefs(primitiveEntityDef);
typeDefStore.createTypesDef(typesDef11);
primitiveEntity = TestUtilsV2.createprimitiveEntityV2();
}
Aggregations