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);
}
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");
}
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());
}
}
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);
}
}
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();
}
Aggregations