Search in sources :

Example 36 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class EntityJerseyResourceIT method testDeleteEntityByUniqAttribute.

@Test
public void testDeleteEntityByUniqAttribute() throws Exception {
    // Create database entity
    Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    db1.set(NAME, dbName);
    db1.set(QUALIFIED_NAME, dbName);
    db1.set(CLUSTER_NAME, randomString());
    db1.set(DESCRIPTION, randomString());
    db1.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    db1.set("owner", "user1");
    db1.set(CLUSTER_NAME, "cl1");
    db1.set("parameters", Collections.EMPTY_MAP);
    db1.set("location", "/tmp");
    Id db1Id = createInstance(db1);
    // Delete the database entity
    List<String> deletedGuidsList = atlasClientV1.deleteEntity(DATABASE_TYPE_BUILTIN, QUALIFIED_NAME, dbName).getDeletedEntities();
    // Verify that deleteEntities() response has database entity guids
    Assert.assertEquals(deletedGuidsList.size(), 1);
    Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
    // Verify entities were deleted from the repository.
    for (String guid : deletedGuidsList) {
        Referenceable entity = atlasClientV1.getEntity(guid);
        assertEquals(entity.getId().getState(), Id.EntityState.DELETED);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 37 with Id

use of org.apache.atlas.v1.model.instance.Id 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 38 with Id

use of org.apache.atlas.v1.model.instance.Id 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)

Example 39 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class EntityJerseyResourceIT method testPartialUpdateByGuid.

@Test
public void testPartialUpdateByGuid() 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 tableId = createInstance(hiveTableInstance);
    final String guid = tableId._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String colName = "col1" + randomString();
    final List<Referenceable> columns = new ArrayList<>();
    Map<String, Object> values = new HashMap<>();
    values.put(NAME, colName);
    values.put("comment", "col1 comment");
    values.put(QUALIFIED_NAME, "default.table.col1@" + colName);
    values.put("comment", "col1 comment");
    values.put("type", "string");
    values.put("owner", "user1");
    values.put("position", 0);
    values.put("description", "col1");
    // table is a required reference, can't be null
    values.put("table", tableId);
    Referenceable ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
    columns.add(ref);
    Referenceable tableUpdated = new Referenceable(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, new HashMap<String, Object>() {

        {
            put("columns", columns);
        }
    });
    LOG.debug("Updating entity= {}", tableUpdated);
    EntityResult entityResult = atlasClientV1.updateEntity(guid, tableUpdated);
    assertEquals(entityResult.getUpdateEntities().size(), 1);
    assertEquals(entityResult.getUpdateEntities().get(0), guid);
    Referenceable entity = atlasClientV1.getEntity(guid);
    List<Referenceable> refs = (List<Referenceable>) entity.get("columns");
    Referenceable column = refs.get(0);
    assertEquals(columns.get(0).getValues(), column.getValues());
    assertEquals(columns.get(0).getTypeName(), column.getTypeName());
    assertEquals(columns.get(0).getTraits(), column.getTraits());
    assertEquals(columns.get(0).getTraitNames(), column.getTraitNames());
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 40 with Id

use of org.apache.atlas.v1.model.instance.Id in project atlas by apache.

the class EntityJerseyResourceIT method testGetTraitDefinitionForEntity.

@Test
public void testGetTraitDefinitionForEntity() 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());
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    String traitDefinitionAsJSON = AtlasType.toV1Json(typesDef);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    createType(AtlasType.toV1Json(typesDef));
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    Struct traitDef = atlasClientV1.getTraitDefinition(guid, traitName);
    Assert.assertEquals(traitDef.getTypeName(), traitName);
    List<Struct> allTraitDefs = atlasClientV1.listTraitDefinitions(guid);
    System.out.println(allTraitDefs.toString());
    Assert.assertEquals(allTraitDefs.size(), 8);
}
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)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)62 Test (org.testng.annotations.Test)39 Id (org.apache.atlas.v1.model.instance.Id)38 Struct (org.apache.atlas.v1.model.instance.Struct)15 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)11 List (java.util.List)7 AtlasException (org.apache.atlas.AtlasException)6 AtlasServiceException (org.apache.atlas.AtlasServiceException)6 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)5 HashMap (java.util.HashMap)4 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)4 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)4 Feed (org.apache.falcon.entity.v0.feed.Feed)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3