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