Search in sources :

Example 6 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class EntityJerseyResourceIT method testAddTraitWithAttribute.

@Test
public void testAddTraitWithAttribute() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    final String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("type", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(typesDef);
    Struct traitInstance = new Struct(traitName);
    traitInstance.set("type", "SSN");
    atlasClientV1.addTrait(guid, traitInstance);
    // verify the response
    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNotNull(entity);
    Assert.assertEquals(entity.getId()._getId(), guid);
    assertNotNull(entity.getTrait(traitName));
    assertEquals(entity.getTrait(traitName).get("type"), traitInstance.get("type"));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 7 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class EntityJerseyResourceIT method testAddExistingTrait.

@Test
public void testAddExistingTrait() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(typesDef);
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    try {
        atlasClientV1.addTrait(guid, traitInstance);
        fail("Duplicate trait addition should've failed");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), BAD_REQUEST);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 8 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class EntityJerseyResourceIT method testEntityDefinitionAcrossTypeUpdate.

@Test
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
    // create type
    ClassTypeDefinition typeDefinition = TypesUtil.createClassTypeDef(randomString(), null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.singletonList(typeDefinition));
    atlasClientV1.createType(AtlasType.toV1Json(typesDef));
    // create entity for the type
    Referenceable instance = new Referenceable(typeDefinition.getTypeName());
    instance.set("name", randomString());
    String guid = atlasClientV1.createEntity(instance).get(0);
    // update type - add attribute
    typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.getTypeName(), null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createOptionalAttrDef("description", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typeDef = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Arrays.asList(typeDefinition));
    atlasClientV1.updateType(typeDef);
    // Get definition after type update - new attributes should be null
    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNull(entity.get("description"));
    Assert.assertEquals(entity.get("name"), instance.get("name"));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Test(org.testng.annotations.Test)

Example 9 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class EntityJerseyResourceIT method testDeleteExistentTraitNonExistentForEntity.

@Test
public void testDeleteExistentTraitNonExistentForEntity() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    final String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("type", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(AtlasType.toV1Json(typesDef));
    try {
        atlasClientV1.deleteTrait(guid, traitName);
        fail("Call should've failed for deletion of invalid trait");
    } catch (AtlasServiceException e) {
        assertNotNull(e);
        assertNotNull(e.getStatus());
        assertEquals(e.getStatus(), ClientResponse.Status.BAD_REQUEST);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 10 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef in project atlas by apache.

the class EntityJerseyResourceIT method testDeleteTrait.

@Test
public void testDeleteTrait() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(typesDef);
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
    atlasClientV1.deleteTrait(guid, traitName);
    try {
        atlasClientV1.getTraitDefinition(guid, traitName);
        fail("Deleted trait definition shouldn't exist");
    } catch (AtlasServiceException e) {
        assertEquals(e.getStatus(), ClientResponse.Status.NOT_FOUND);
        assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)8 Test (org.testng.annotations.Test)8 Id (org.apache.atlas.v1.model.instance.Id)7 TypesDef (org.apache.atlas.v1.model.typedef.TypesDef)7 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)6 Struct (org.apache.atlas.v1.model.instance.Struct)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)3 AttributeDefinition (org.apache.atlas.v1.model.typedef.AttributeDefinition)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 TraitTypeDefinition (org.apache.atlas.v1.model.typedef.TraitTypeDefinition)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)1 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)1 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)1