Java Code Examples for org.apache.atlas.v1.model.instance.Id#_getId
The following examples show how to use
org.apache.atlas.v1.model.instance.Id#_getId .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testSubmitEntity() throws Exception { String dbName = "db" + randomString(); String tableName = "table" + randomString(); Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName); Id dbId = createInstance(hiveDBInstance); Referenceable referenceable = createHiveTableInstanceBuiltIn(dbName, tableName, dbId); Id id = createInstance(referenceable); final String guid = id._getId(); try { Assert.assertNotNull(UUID.fromString(guid)); } catch (IllegalArgumentException e) { Assert.fail("Response is not a guid, " + guid); } }
Example 2
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testAddNullProperty() 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); } //add property addProperty(guid, null, "foo bar"); Assert.fail(); }
Example 3
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testGetEntityDefinition() 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); } Referenceable entity = atlasClientV1.getEntity(guid); Assert.assertNotNull(entity); }
Example 4
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testGetEntityList() 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); } List<String> entities = atlasClientV1.listEntities(HIVE_TABLE_TYPE_BUILTIN); Assert.assertNotNull(entities); Assert.assertTrue(entities.contains(guid)); }
Example 5
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testGetTraitNames() 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); } List<String> traits = atlasClientV1.listTraits(guid); assertNotNull(traits); Assert.assertEquals(traits.size(), 7); }
Example 6
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 6 votes |
@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"); }
Example 7
Source File: EntityNotificationIT.java From atlas with Apache License 2.0 | 6 votes |
public void testDeleteEntity() throws Exception { final String tableName = "table-" + randomString(); final String dbName = "db-" + randomString(); final Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(dbName); final Id dbId = createInstance(HiveDBInstance); final Referenceable tableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId); final Id tableId = createInstance(tableInstance); final String guid = tableId._getId(); waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(OperationType.ENTITY_CREATE, HIVE_TABLE_TYPE_BUILTIN, guid)); final String name = (String) tableInstance.get(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME); atlasClientV1.deleteEntity(HIVE_TABLE_TYPE_BUILTIN, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, name); waitForNotification(notificationConsumer, MAX_WAIT_TIME, newNotificationPredicate(OperationType.ENTITY_DELETE, HIVE_TABLE_TYPE_BUILTIN, guid)); }
Example 8
Source File: BaseResourceIT.java From atlas with Apache License 2.0 | 5 votes |
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_TAG, PHI_TAG, PCI_TAG, SOX_TAG, SEC_TAG, FINANCE_TAG); 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); tableInstance.set("tableType", 1); // enum 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.getTraitNames(); Assert.assertEquals(traits.size(), 7); return tableInstance; }
Example 9
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 5 votes |
@Test public void testEntityDeduping() throws Exception { final String dbName = "db" + randomString(); Referenceable HiveDBInstance = createHiveDBInstanceBuiltIn(dbName); Id dbIdReference = createInstance(HiveDBInstance); final String dbId = dbIdReference._getId(); assertEntityAudit(dbId, EntityAuditEvent.EntityAuditAction.ENTITY_CREATE); // Disabling DSL tests until v2 DSL implementation is ready // JSONArray results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName)); // assertEquals(results.length(), 1); // // //create entity again shouldn't create another instance with same unique attribute value // List<String> entityResults = atlasClientV1.createEntity(HiveDBInstance); // assertEquals(entityResults.size(), 0); // // results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName)); // assertEquals(results.length(), 1); // // //Test the same across references // Referenceable table = new Referenceable(HIVE_TABLE_TYPE_BUILTIN); // final String tableName = randomString(); // Referenceable tableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbIdReference); // atlasClientV1.createEntity(tableInstance); // results = searchByDSL(String.format("%s where qualifiedName='%s'", DATABASE_TYPE_BUILTIN, dbName)); // assertEquals(results.length(), 1); }
Example 10
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 5 votes |
@Test public void testAddReferenceProperty() 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); } //Create new db instance dbName = "db" + randomString(); Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN); databaseInstance.set(NAME, dbName); databaseInstance.set(QUALIFIED_NAME, dbName); databaseInstance.set(CLUSTER_NAME, randomString()); databaseInstance.set("description", "new database"); databaseInstance.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName); databaseInstance.set("owner", "user1"); databaseInstance.set(CLUSTER_NAME, "cl1"); databaseInstance.set("parameters", Collections.EMPTY_MAP); databaseInstance.set("location", "/tmp"); Id dbInstance = createInstance(databaseInstance); String newDBId = dbInstance._getId(); //Add reference property EntityResult entityResult = atlasClientV1.updateEntityAttribute(guid, "db", newDBId); assertEquals(entityResult.getUpdateEntities().size(), 2); assertEquals(entityResult.getUpdateEntities().get(0), newDBId); assertEquals(entityResult.getUpdateEntities().get(1), guid); }
Example 11
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 5 votes |
@Test public void testAddTrait() 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); }
Example 12
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 5 votes |
@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); }
Example 13
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 5 votes |
@Test public void testAddTraitWithAttribute() 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)); 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); traitInstance.set("type", "SSN"); atlasClientV1.addTrait(guid, traitInstance); // verify the response Referenceable entity = atlasClientV1.getEntity(guid); Assert.assertNotNull(entity); Assert.assertEquals(entity.getId()._getId(), guid); assertNotNull(entity.getTrait(traitName)); assertEquals(entity.getTrait(traitName).get("type"), traitInstance.get("type")); }
Example 14
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 4 votes |
@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"); values.put("table", tableId); //table is a required reference, can't be null values.put("userDescription", null); values.put("displayName", null); 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()); }
Example 15
Source File: EntityJerseyResourceIT.java From atlas with Apache License 2.0 | 4 votes |
@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); values1.put("userDescription", null); values1.put("displayName", null); 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); values2.put("userDescription", null); values2.put("displayName", null); 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); Referenceable col3 = getReferenceable(refs, "col3"); Referenceable col4 = getReferenceable(refs, "col4"); Assert.assertEquals(col3.getValuesMap(), values1); Assert.assertEquals(col4.getValuesMap(), values2); }