Search in sources :

Example 61 with Referenceable

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);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasClient(org.apache.atlas.AtlasClient) Test(org.testng.annotations.Test)

Example 62 with Referenceable

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);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Example 63 with Referenceable

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);
    }
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasServiceException(org.apache.atlas.AtlasServiceException) Test(org.testng.annotations.Test)

Example 64 with Referenceable

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));
}
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 65 with Referenceable

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);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Struct(org.apache.atlas.v1.model.instance.Struct)

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