Search in sources :

Example 86 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class BaseTest method createDeptEg1.

protected Referenceable createDeptEg1(TypeSystem ts) throws AtlasException {
    Referenceable hrDept = new Referenceable("Department");
    Referenceable john = new Referenceable("Person");
    Referenceable jane = new Referenceable("Manager", "SecurityClearance");
    hrDept.set("name", "hr");
    john.set("name", "John");
    john.set("department", hrDept);
    jane.set("name", "Jane");
    jane.set("department", hrDept);
    john.set("manager", jane);
    hrDept.set("employees", ImmutableList.of(john, jane));
    jane.set("subordinates", ImmutableList.of(john));
    jane.getTrait("SecurityClearance").set("level", 1);
    ClassType deptType = ts.getDataType(ClassType.class, "Department");
    deptType.convert(hrDept, Multiplicity.REQUIRED);
    return hrDept;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable)

Example 87 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class ClassTest method test1.

@Test
public void test1() throws AtlasException {
    TypeSystem ts = getTypeSystem();
    defineDeptEmployeeTypes(ts);
    Referenceable hrDept = createDeptEg1(ts);
    ClassType deptType = ts.getDataType(ClassType.class, "Department");
    ITypedReferenceableInstance hrDept2 = deptType.convert(hrDept, Multiplicity.REQUIRED);
    Assert.assertEquals(hrDept2.toString(), "{\n" + "\tid : (type: Department, id: <unassigned>)\n" + "\tname : \thr\n" + "\temployees : \t[{\n" + "\tid : (type: Person, id: <unassigned>)\n" + "\tname : \tJohn\n" + "\tdepartment : (type: Department, id: <unassigned>)\n" + "\tmanager : (type: Manager, id: <unassigned>)\n" + "}, {\n" + "\tid : (type: Manager, id: <unassigned>)\n" + "\tsubordinates : \t[{\n" + "\tid : (type: Person, id: <unassigned>)\n" + "\tname : \tJohn\n" + "\tdepartment : (type: Department, id: <unassigned>)\n" + "\tmanager : (type: Manager, id: <unassigned>)\n" + "}]\n" + "\tname : \tJane\n" + "\tdepartment : (type: Department, id: <unassigned>)\n" + "\tmanager : <null>\n" + "\n" + "\tSecurityClearance : \t{\n" + "\t\tlevel : \t\t1\n" + "\t}}]\n" + "}");
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Test(org.testng.annotations.Test)

Example 88 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class BaseResourceIT method createHiveDBInstanceBuiltIn.

protected Referenceable createHiveDBInstanceBuiltIn(String dbName) {
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
    databaseInstance.set(NAME, dbName);
    databaseInstance.set(QUALIFIED_NAME, dbName);
    databaseInstance.set(CLUSTER_NAME, randomString());
    databaseInstance.set(DESCRIPTION, "foo database");
    return databaseInstance;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable)

Example 89 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class BaseResourceIT method createHiveTableInstanceBuiltIn.

protected Referenceable createHiveTableInstanceBuiltIn(String dbName, String tableName, Id dbId) throws Exception {
    Map<String, Object> values = new HashMap<>();
    values.put(NAME, dbName);
    values.put(DESCRIPTION, "foo database");
    values.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    values.put("owner", "user1");
    values.put(CLUSTER_NAME, "cl1");
    values.put("parameters", Collections.EMPTY_MAP);
    values.put("location", "/tmp");
    Referenceable databaseInstance = new Referenceable(dbId._getId(), dbId.getTypeName(), values);
    Referenceable tableInstance = new Referenceable(HIVE_TABLE_TYPE_BUILTIN, "classification", "pii", "phi", "pci", "sox", "sec", "finance");
    tableInstance.set(NAME, tableName);
    tableInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
    tableInstance.set("db", databaseInstance);
    tableInstance.set(DESCRIPTION, "bar table");
    tableInstance.set("lastAccessTime", "2014-07-11T08:00:00.000Z");
    tableInstance.set("type", "managed");
    tableInstance.set("level", 2);
    // enum
    tableInstance.set("tableType", 1);
    tableInstance.set("compressed", false);
    Struct traitInstance = (Struct) tableInstance.getTrait("classification");
    traitInstance.set("tag", "foundation_etl");
    Struct serde1Instance = new Struct("serdeType");
    serde1Instance.set(NAME, "serde1");
    serde1Instance.set("serde", "serde1");
    tableInstance.set("serde1", serde1Instance);
    Struct serde2Instance = new Struct("serdeType");
    serde2Instance.set(NAME, "serde2");
    serde2Instance.set("serde", "serde2");
    tableInstance.set("serde2", serde2Instance);
    List<String> traits = tableInstance.getTraits();
    Assert.assertEquals(traits.size(), 7);
    return tableInstance;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 90 with Referenceable

use of org.apache.atlas.typesystem.Referenceable in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testSubmitSingleEntity.

@Test
public //API should accept single entity (or jsonarray of entities)
void testSubmitSingleEntity() throws Exception {
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    databaseInstance.set("name", dbName);
    databaseInstance.set(QUALIFIED_NAME, dbName);
    databaseInstance.set("clusterName", randomString());
    databaseInstance.set("description", randomString());
    databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    databaseInstance.set("owner", "user1");
    databaseInstance.set("clusterName", "cl1");
    databaseInstance.set("parameters", Collections.EMPTY_MAP);
    databaseInstance.set("location", "/tmp");
    JSONObject response = atlasClientV1.callAPIWithBody(AtlasClient.API.CREATE_ENTITY, InstanceSerialization.toJson(databaseInstance, true));
    assertNotNull(response);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    EntityResult entityResult = EntityResult.fromString(response.toString());
    assertEquals(entityResult.getCreatedEntities().size(), 1);
    assertNotNull(entityResult.getCreatedEntities().get(0));
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) JSONObject(org.codehaus.jettison.json.JSONObject) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.typesystem.Referenceable)235 Test (org.testng.annotations.Test)114 Id (org.apache.atlas.typesystem.persistence.Id)50 ArrayList (java.util.ArrayList)45 List (java.util.List)25 Struct (org.apache.atlas.typesystem.Struct)25 HashMap (java.util.HashMap)24 BeforeTest (org.testng.annotations.BeforeTest)24 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)22 AfterTest (org.testng.annotations.AfterTest)22 HookNotification (org.apache.atlas.notification.hook.HookNotification)20 IStruct (org.apache.atlas.typesystem.IStruct)18 ClassType (org.apache.atlas.typesystem.types.ClassType)16 JSONObject (org.codehaus.jettison.json.JSONObject)16 ImmutableList (com.google.common.collect.ImmutableList)15 AtlasServiceException (org.apache.atlas.AtlasServiceException)14 TraitType (org.apache.atlas.typesystem.types.TraitType)12 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)12 Date (java.util.Date)11 AtlasException (org.apache.atlas.AtlasException)11