use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class EntityJerseyResourceIT method testRequestUser.
@Test
public void testRequestUser() throws Exception {
Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
String dbName = randomString();
entity.set("name", dbName);
entity.set(QUALIFIED_NAME, dbName);
entity.set("clusterName", randomString());
entity.set("description", randomString());
entity.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
entity.set("owner", "user1");
entity.set("clusterName", "cl1");
entity.set("parameters", Collections.EMPTY_MAP);
entity.set("location", "/tmp");
String user = "admin";
AtlasClient localClient = null;
if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
localClient = new AtlasClient(atlasUrls, new String[] { "admin", "admin" });
} else {
localClient = new AtlasClient(atlasUrls);
}
String entityId = localClient.createEntity(entity).get(0);
List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(entityId, (short) 10);
assertEquals(events.size(), 1);
assertEquals(events.get(0).getUser(), user);
}
use of org.apache.atlas.v1.model.instance.Referenceable 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);
}
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class EntityJerseyResourceIT method testEntityInvalidValue.
@Test(dataProvider = "invalidAttrValues")
public void testEntityInvalidValue(String value) throws Exception {
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
databaseInstance.set("name", randomString());
databaseInstance.set("description", value);
try {
createInstance(databaseInstance);
Assert.fail("Expected AtlasServiceException");
} catch (AtlasServiceException e) {
Assert.assertEquals(e.getStatus(), BAD_REQUEST);
}
}
use of org.apache.atlas.v1.model.instance.Referenceable 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));
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class MetadataDiscoveryJerseyResourceIT method createInstance.
private Id createInstance() throws Exception {
Referenceable entityInstance = new Referenceable("dsl_test_type", "Classification");
entityInstance.set("name", randomString());
entityInstance.set("description", randomString());
Struct traitInstance = (Struct) entityInstance.getTrait("Classification");
tagName = randomString();
traitInstance.set("tag", tagName);
List<String> traits = entityInstance.getTraitNames();
assertEquals(traits.size(), 1);
return createInstance(entityInstance);
}
Aggregations