use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class EntityV2JerseyResourceIT method testEntityDefinitionAcrossTypeUpdate.
@Test
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
// create type
AtlasEntityDef entityDef = AtlasTypeUtil.createClassTypeDef(randomString(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(entityDef);
AtlasTypesDef created = atlasClientV2.createAtlasTypeDefs(typesDef);
assertNotNull(created);
assertNotNull(created.getEntityDefs());
assertEquals(created.getEntityDefs().size(), 1);
// create entity for the type
AtlasEntity instance = new AtlasEntity(entityDef.getName());
instance.setAttribute("name", randomString());
EntityMutationResponse mutationResponse = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(instance));
assertNotNull(mutationResponse);
assertNotNull(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
assertEquals(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(), 1);
String guid = mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
// update type - add attribute
entityDef = AtlasTypeUtil.createClassTypeDef(entityDef.getName(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string"));
typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(entityDef);
AtlasTypesDef updated = atlasClientV2.updateAtlasTypeDefs(typesDef);
assertNotNull(updated);
assertNotNull(updated.getEntityDefs());
assertEquals(updated.getEntityDefs().size(), 1);
// Get definition after type update - new attributes should be null
AtlasEntity entityByGuid = getEntityByGuid(guid);
assertNull(entityByGuid.getAttribute("description"));
assertEquals(entityByGuid.getAttribute("name"), instance.getAttribute("name"));
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class TypedefsJerseyResourceIT method testDuplicateCreate.
@Test
public void testDuplicateCreate() throws Exception {
AtlasEntityDef type = createClassTypeDef(randomString(), Collections.<String>emptySet(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getEntityDefs().add(type);
AtlasTypesDef created = clientV2.createAtlasTypeDefs(typesDef);
assertNotNull(created);
try {
created = clientV2.createAtlasTypeDefs(typesDef);
fail("Expected 409");
} catch (AtlasServiceException e) {
assertEquals(e.getStatus().getStatusCode(), Response.Status.CONFLICT.getStatusCode());
}
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class TestEntityREST method setUp.
@BeforeClass
public void setUp() throws Exception {
AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes();
typeStore.createTypesDef(typesDef);
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class BasicSearchIT method setUp.
@BeforeClass
@Override
public void setUp() throws Exception {
super.setUp();
String smallDatasetFileName = "hive-db-50-tables.zip";
atlasClientV2.importData(new AtlasImportRequest(), TestResourceFileUtils.getTestFilePath(smallDatasetFileName));
// Create a test tag
if (!atlasClientV2.typeWithNameExists("fooTag")) {
AtlasClassificationDef testClassificationDef = AtlasTypeUtil.createTraitTypeDef("fooTag", "Test tag", "1.0", Collections.<String>emptySet());
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(testClassificationDef);
atlasClientV2.createAtlasTypeDefs(typesDef);
}
try {
atlasClientV2.getEntityByAttribute("hdfs_path", new HashMap<String, String>() {
{
put("qualifiedName", URLEncoder.encode("test$1test+ - && || ! ( ) { } [ ] ^ < > ; : \" % * ` ~", "UTF-8"));
}
});
} catch (AtlasServiceException e) {
AtlasEntity hdfsEntity = new AtlasEntity("hdfs_path");
hdfsEntity.setGuid("-1");
hdfsEntity.setAttribute("description", "1test+ - && || ! ( ) { } [ ] ^ < > ; : \" % * ` ~");
hdfsEntity.setAttribute("name", "1test+ - && || ! ( ) { } [ ] ^ < > ; : \" % * ` ~");
hdfsEntity.setAttribute("owner", "test");
hdfsEntity.setAttribute("qualifiedName", "test$1test+ - && || ! ( ) { } [ ] ^ < > ; : \" % * ` ~");
hdfsEntity.setAttribute("path", "/test/foo");
hdfsEntity.setClassifications(new ArrayList<AtlasClassification>());
hdfsEntity.getClassifications().add(new AtlasClassification("fooTag"));
EntityMutationResponse entityMutationResponse = atlasClientV2.createEntity(new AtlasEntity.AtlasEntityWithExtInfo(hdfsEntity));
if (entityMutationResponse.getCreatedEntities() != null) {
assertEquals(entityMutationResponse.getCreatedEntities().size(), 1);
} else if (entityMutationResponse.getUpdatedEntities() != null) {
assertEquals(entityMutationResponse.getUpdatedEntities().size(), 1);
} else {
fail("Entity should've been created or updated");
}
}
// Add a 5s mandatory sleep for allowing index to catch up
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
LOG.error("Sleep was interrupted. The search results might be inconsistent.");
}
}
use of org.apache.atlas.model.typedef.AtlasTypesDef in project atlas by apache.
the class HiveHookIT method createTrait.
private String createTrait(String guid) throws AtlasServiceException {
// add trait
// valid type names in v2 must consist of a letter followed by a sequence of letter, number, or _ characters
String traitName = "PII_Trait" + random();
AtlasClassificationDef piiTrait = AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet());
atlasClientV2.createAtlasTypeDefs(new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList()));
atlasClientV2.addClassifications(guid, Collections.singletonList(new AtlasClassification(piiTrait.getName())));
return traitName;
}
Aggregations