use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class EntityJerseyResourceIT method testCreateNestedEntities.
@Test
public void testCreateNestedEntities() throws Exception {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
databaseInstance.set("name", "db_" + randomString());
databaseInstance.set("description", "foo database");
int nTables = 5;
int colsPerTable = 3;
List<Referenceable> tables = new ArrayList<>();
List<Referenceable> allColumns = new ArrayList<>();
for (int i = 0; i < nTables; i++) {
String tableName = "db1-table-" + i + randomString();
Referenceable tableInstance = new Referenceable(HIVE_TABLE_TYPE);
tableInstance.set("name", tableName);
tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
tableInstance.set("db", databaseInstance);
tableInstance.set("description", tableName + " table");
tables.add(tableInstance);
List<Referenceable> columns = new ArrayList<>();
for (int j = 0; j < colsPerTable; j++) {
Referenceable columnInstance = new Referenceable(COLUMN_TYPE);
columnInstance.set("name", tableName + "-col-" + j + randomString());
columnInstance.set("dataType", "String");
columnInstance.set("comment", "column " + j + " for table " + i);
allColumns.add(columnInstance);
columns.add(columnInstance);
}
tableInstance.set("columns", columns);
}
// Create the tables. The database and columns should be created automatically, since
// the tables reference them.
List<String> entityGUIDs = atlasClientV1.createEntity(tables);
assertNotNull(entityGUIDs);
assertEquals(entityGUIDs.size(), nTables * (colsPerTable + 1) + 1);
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class EntityJerseyResourceIT method testDeleteTraitNonExistent.
@Test(expectedExceptions = AtlasServiceException.class)
public void testDeleteTraitNonExistent() 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 = "blah_trait";
atlasClientV1.deleteTrait(guid, traitName);
fail("trait=" + traitName + " should be defined in type system before it can be deleted");
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class EntityJerseyResourceIT method testSubmitEntityWithBadDateFormat.
@Test
public void testSubmitEntityWithBadDateFormat() {
String dbName = "db" + randomString();
String tableName = "table" + randomString();
Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
Id dbId = null;
try {
dbId = createInstance(hiveDBInstance);
Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
hiveTableInstance.set("lastAccessTime", "2014-07-11");
createInstance(hiveTableInstance);
} catch (AtlasServiceException e) {
// Should catch the exception
assertEquals(e.getStatus().getStatusCode(), BAD_REQUEST.getStatusCode());
} catch (Exception e) {
// ignore
}
}
use of org.apache.atlas.v1.model.instance.Referenceable 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);
}
}
use of org.apache.atlas.v1.model.instance.Referenceable 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);
}
}
Aggregations