Search in sources :

Example 21 with Id

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

the class EntityJerseyResourceIT method testGetEntityDefinition.

@Test
public void testGetEntityDefinition() 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);
    }
    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNotNull(entity);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 22 with Id

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

the class EntityJerseyResourceIT method testGetTraitNames.

@Test
public void testGetTraitNames() 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);
    }
    List<String> traits = atlasClientV1.listTraits(guid);
    assertNotNull(traits);
    Assert.assertEquals(traits.size(), 7);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 23 with Id

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

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

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

the class EntityJerseyResourceIT method testCompleteUpdate.

@Test
public void testCompleteUpdate() 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);
    }
    final List<Referenceable> columns = new ArrayList<>();
    Map<String, Object> values1 = new HashMap<>();
    values1.put(NAME, "col3");
    values1.put(QUALIFIED_NAME, "default.table.col3@cl1");
    values1.put("comment", "col3 comment");
    values1.put("type", "string");
    values1.put("owner", "user1");
    values1.put("position", 0);
    values1.put("description", "col3");
    values1.put("table", tableId);
    Map<String, Object> values2 = new HashMap<>();
    values2.put(NAME, "col4");
    values2.put(QUALIFIED_NAME, "default.table.col4@cl1");
    values2.put("comment", "col4 comment");
    values2.put("type", "string");
    values2.put("owner", "user2");
    values2.put("position", 1);
    values2.put("description", "col4");
    values2.put("table", tableId);
    Referenceable ref1 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values1);
    Referenceable ref2 = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values2);
    columns.add(ref1);
    columns.add(ref2);
    hiveTableInstance.set("columns", columns);
    LOG.debug("Replacing entity= {}", hiveTableInstance);
    EntityResult updateEntity = atlasClientV1.updateEntities(hiveTableInstance);
    assertNotNull(updateEntity.getUpdateEntities());
    hiveTableInstance = atlasClientV1.getEntity(guid);
    List<Referenceable> refs = (List<Referenceable>) hiveTableInstance.get("columns");
    Assert.assertEquals(refs.size(), 2);
    Assert.assertTrue(refs.get(0).getValuesMap().equals(values1));
    Assert.assertTrue(refs.get(1).getValuesMap().equals(values2));
}
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)

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