Search in sources :

Example 51 with Referenceable

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

the class EntityJerseyResourceIT method testAddProperty.

@Test
public void testAddProperty() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(referenceable);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    // add property
    String description = "bar table - new desc";
    addProperty(guid, "description", description);
    ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
    Assert.assertNotNull(response);
    referenceable.set("description", description);
    // invalid property for the type
    try {
        addProperty(guid, "invalid_property", "bar table");
        Assert.fail("Expected AtlasServiceException");
    } catch (AtlasServiceException e) {
        Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
    }
    String currentTime = String.valueOf(new DateTime());
    // updating date attribute as string not supported in v2
    // addProperty(guid, "createTime", currentTime);
    response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid);
    Assert.assertNotNull(response);
    referenceable.set("createTime", currentTime);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 52 with Referenceable

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

the class EntityJerseyResourceIT method testPartialUpdateByUniqueAttributes.

@Test
public void testPartialUpdateByUniqueAttributes() 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);
    // Update by unique attribute
    values.put("type", "int");
    ref = new Referenceable(BaseResourceIT.COLUMN_TYPE_BUILTIN, values);
    columns.set(0, 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(BaseResourceIT.HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, (String) hiveTableInstance.get(QUALIFIED_NAME), 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");
    Assert.assertTrue(refs.get(0).getValuesMap().equals(values));
    Assert.assertEquals(refs.get(0).get("type"), "int");
}
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 53 with Referenceable

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

the class EntityJerseyResourceIT method testAddNullPropertyValue.

@Test(enabled = false)
public void testAddNullPropertyValue() 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);
    }
    // add property
    try {
        addProperty(guid, "description", null);
        Assert.fail("Expected AtlasServiceException");
    } catch (AtlasServiceException e) {
        Assert.assertEquals(e.getStatus().getStatusCode(), Response.Status.BAD_REQUEST.getStatusCode());
    }
}
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 54 with Referenceable

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

the class EntityJerseyResourceIT method testDeleteEntitiesViaClientApi.

@Test
public void testDeleteEntitiesViaClientApi() throws Exception {
    // Create 2 database entities
    Referenceable db1 = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    db1.set("name", dbName);
    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);
    Referenceable db2 = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName2 = randomString();
    db2.set("name", dbName2);
    db2.set(QUALIFIED_NAME, dbName2);
    db2.set(CLUSTER_NAME, randomString());
    db2.set("description", randomString());
    db2.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName2);
    db2.set("owner", "user2");
    db2.set("clusterName", "cl1");
    db2.set("parameters", Collections.EMPTY_MAP);
    db2.set("location", "/tmp");
    Id db2Id = createInstance(db2);
    // Delete the database entities
    List<String> deletedGuidsList = atlasClientV1.deleteEntities(db1Id._getId(), db2Id._getId()).getDeletedEntities();
    // Verify that deleteEntities() response has database entity guids
    Assert.assertEquals(deletedGuidsList.size(), 2);
    Assert.assertTrue(deletedGuidsList.contains(db1Id._getId()));
    Assert.assertTrue(deletedGuidsList.contains(db2Id._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 55 with Referenceable

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

the class EntityJerseyResourceIT method testAddNullProperty.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testAddNullProperty() 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);
    }
    // add property
    addProperty(guid, null, "foo bar");
    Assert.fail();
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)143 Test (org.testng.annotations.Test)64 Id (org.apache.atlas.v1.model.instance.Id)37 Struct (org.apache.atlas.v1.model.instance.Struct)23 ArrayList (java.util.ArrayList)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 HashMap (java.util.HashMap)12 List (java.util.List)10 AtlasException (org.apache.atlas.AtlasException)10 HookNotification (org.apache.atlas.model.notification.HookNotification)10 Map (java.util.Map)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 AtlasServiceException (org.apache.atlas.AtlasServiceException)8 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)8 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)7 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)5