Java Code Examples for org.apache.atlas.v1.model.instance.Referenceable#get()
The following examples show how to use
org.apache.atlas.v1.model.instance.Referenceable#get() .
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 testUTF8() throws Exception { String attrName = randomUTF8(); String attrValue = randomUTF8(); String classType = randomString(); //Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType() ClassTypeDefinition classTypeDefinition = TypesUtil.createClassTypeDef(classType, null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef(attrName, AtlasBaseTypeDef.ATLAS_TYPE_STRING)); TypesDef typesDef = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Collections.singletonList(classTypeDefinition)); createType(typesDef); Referenceable entityToCreate = new Referenceable(classType, Collections.singletonMap(attrName, attrValue)); Id guid = createInstance(entityToCreate); ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId()); Object objResponse = response.get(AtlasClient.DEFINITION); String jsonResponse = AtlasType.toJson(objResponse); Referenceable createdEntity = AtlasType.fromV1Json(jsonResponse, Referenceable.class); Object entityAttrValue = createdEntity.get(attrName); Assert.assertEquals(entityAttrValue, attrValue, "attrName=" + attrName + "; attrValue=" + attrValue + "; entityToCreate=" + entityToCreate + "; entityId=" + guid + "; getEntityResponse_Obj=" + objResponse + "; getEntityResponse_Json=" + jsonResponse + "; getEntityResponse_Entity=" + createdEntity); }
Example 2
Source File: QuickStartIT.java From atlas with Apache License 2.0 | 6 votes |
@Test public void testProcessIsAdded() throws AtlasServiceException { Referenceable loadProcess = atlasClientV1.getEntity(QuickStart.LOAD_PROCESS_TYPE, AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, QuickStart.LOAD_SALES_DAILY_PROCESS); assertEquals(QuickStart.LOAD_SALES_DAILY_PROCESS, loadProcess.get(AtlasClient.NAME)); assertEquals(QuickStart.LOAD_SALES_DAILY_PROCESS_DESCRIPTION, loadProcess.get("description")); List<Id> inputs = (List<Id>)loadProcess.get(QuickStart.INPUTS_ATTRIBUTE); List<Id> outputs = (List<Id>)loadProcess.get(QuickStart.OUTPUTS_ATTRIBUTE); assertEquals(2, inputs.size()); String salesFactTableId = getTableId(QuickStart.SALES_FACT_TABLE); String timeDimTableId = getTableId(QuickStart.TIME_DIM_TABLE); String salesFactDailyMVId = getTableId(QuickStart.SALES_FACT_DAILY_MV_TABLE); assertEquals(salesFactTableId, inputs.get(0)._getId()); assertEquals(timeDimTableId, inputs.get(1)._getId()); assertEquals(salesFactDailyMVId, outputs.get(0)._getId()); }
Example 3
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 4
Source File: TestAwsS3Directory.java From nifi with Apache License 2.0 | 6 votes |
private void assertAnalysisResult(DataSetRefs refs, String directory) { String expectedDirectoryQualifiedName = String.format("s3a://%s%s@%s", AWS_BUCKET, directory, ATLAS_NAMESPACE); String expectedBucketQualifiedName = String.format("s3a://%s@%s", AWS_BUCKET, ATLAS_NAMESPACE); assertEquals(0, refs.getInputs().size()); assertEquals(1, refs.getOutputs().size()); Referenceable directoryRef = refs.getOutputs().iterator().next(); assertEquals("aws_s3_pseudo_dir", directoryRef.getTypeName()); assertEquals(expectedDirectoryQualifiedName, directoryRef.get(ATTR_QUALIFIED_NAME)); assertEquals(directory, directoryRef.get(ATTR_NAME)); assertEquals(directory, directoryRef.get("objectPrefix")); Referenceable bucketRef = (Referenceable) directoryRef.get("bucket"); assertNotNull(bucketRef); assertEquals("aws_s3_bucket", bucketRef.getTypeName()); assertEquals(expectedBucketQualifiedName, bucketRef.get(ATTR_QUALIFIED_NAME)); assertEquals(AWS_BUCKET, bucketRef.get(ATTR_NAME)); }
Example 5
Source File: TestNotificationSender.java From nifi with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void assertUpdateFlowPathMessage(Notifier notifier, int notificationIndex, Referenceable ... expects) { assertTrue(notifier.notifications.size() > notificationIndex); final List<HookNotification> messages = notifier.notifications.get(notificationIndex); assertEquals(expects.length, messages.size()); for (int i = 0; i < expects.length; i++) { final Referenceable expect = expects[i]; final HookNotificationV1.EntityPartialUpdateRequest actual = (HookNotificationV1.EntityPartialUpdateRequest) messages.get(i); assertEquals(expect.getTypeName(), actual.getTypeName()); assertEquals(ATTR_QUALIFIED_NAME, actual.getAttribute()); assertEquals(expect.get(ATTR_QUALIFIED_NAME), actual.getAttributeValue()); final Collection expIn = (Collection) expect.get(ATTR_INPUTS); final Collection expOut = (Collection) expect.get(ATTR_OUTPUTS); assertTrue(expIn.containsAll((Collection) actual.getEntity().get(ATTR_INPUTS))); assertTrue(expOut.containsAll((Collection) actual.getEntity().get(ATTR_OUTPUTS))); } }
Example 6
Source File: QuickStartIT.java From atlas with Apache License 2.0 | 5 votes |
private void verifyColumnsAreAddedToTable(Referenceable table) { List<Referenceable> columns = (List<Referenceable>) table.get(QuickStart.COLUMNS_ATTRIBUTE); assertEquals(4, columns.size()); Referenceable column = columns.get(0); assertEquals(QuickStart.TIME_ID_COLUMN, column.get("name")); assertEquals("int", column.get("dataType")); }
Example 7
Source File: ColumnLineageUtils.java From atlas with Apache License 2.0 | 5 votes |
static void populateColumnReferenceableMap(Map<String, Referenceable> m, Referenceable r) { if (r.getTypeName().equals(HiveDataTypes.HIVE_TABLE.getName())) { String qName = (String) r.get(ATTRIBUTE_QUALIFIED_NAME); String[] qNameComps = extractComponents(qName); for (Referenceable col : (List<Referenceable>) r.get(ATTRIBUTE_COLUMNS)) { String cName = (String) col.get(ATTRIBUTE_QUALIFIED_NAME); String[] colQNameComps = extractComponents(cName); String colQName = colQNameComps[0] + "." + colQNameComps[1] + "." + colQNameComps[2]; m.put(colQName, col); } String tableQName = qNameComps[0] + "." + qNameComps[1]; m.put(tableQName, r); } }
Example 8
Source File: TestNotificationSender.java From nifi with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void assertIOReferences(Referenceable expect, Referenceable actual, String attrName) { final Collection<Referenceable> expectedRefs = (Collection<Referenceable>) expect.get(attrName); if (expectedRefs != null) { final Collection<Referenceable> actualRefs = (Collection<Referenceable>) actual.get(attrName); assertEquals(expectedRefs.size(), actualRefs.size()); final Iterator<Referenceable> actualIterator = actualRefs.iterator(); for (Referenceable expectedRef : expectedRefs) { final Referenceable actualRef = actualIterator.next(); assertEquals(expectedRef.getTypeName(), actualRef.getTypeName()); assertEquals(expectedRef.get(ATTR_QUALIFIED_NAME), actualRef.get(ATTR_QUALIFIED_NAME)); } } }
Example 9
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 10
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); }