Search in sources :

Example 71 with AtlasTypesDef

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"));
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 72 with AtlasTypesDef

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());
    }
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 73 with AtlasTypesDef

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);
}
Also used : AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 74 with AtlasTypesDef

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.");
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasImportRequest(org.apache.atlas.model.impexp.AtlasImportRequest) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) BeforeClass(org.testng.annotations.BeforeClass)

Example 75 with AtlasTypesDef

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;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Aggregations

AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)119 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)54 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)39 Test (org.testng.annotations.Test)39 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)30 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)22 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)22 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)20 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)19 ArrayList (java.util.ArrayList)17 SearchFilter (org.apache.atlas.model.SearchFilter)15 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)15 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)14 BeforeClass (org.testng.annotations.BeforeClass)14 HashMap (java.util.HashMap)13 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)13 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)12 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)9 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)8 AtlasServiceException (org.apache.atlas.AtlasServiceException)7