Java Code Examples for org.apache.atlas.model.instance.AtlasEntity#getAttribute()

The following examples show how to use org.apache.atlas.model.instance.AtlasEntity#getAttribute() . 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: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test(dependsOnMethods = "testCreate")
public void testMapOfPrimitivesUpdate() throws Exception {
    AtlasEntity              tableEntity  = new AtlasEntity(tblEntity.getEntity());
    AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntitiesWithExtInfo(tableEntity);

    entitiesInfo.addReferredEntity(tableEntity);

    //Add a new entry
    Map<String, String> paramsMap = (Map<String, String>) tableEntity.getAttribute("parametersMap");
    paramsMap.put("newParam", "value");
    init();
    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1);
    AtlasEntityHeader updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));

    //Remove an entry
    paramsMap.remove("key1");
    init();
    response = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    validateMutationResponse(response, EntityMutations.EntityOperation.UPDATE, 1);
    updatedTable = response.getFirstUpdatedEntityByTypeName(TABLE_TYPE);
    validateEntity(entitiesInfo, getEntityFromStore(updatedTable));
}
 
Example 2
Source File: ImportTransformsTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void transformEntityWithExtInfo() throws AtlasBaseException {
    addColumnTransform(transform);

    AtlasEntityWithExtInfo entityWithExtInfo = getAtlasEntityWithExtInfo();
    AtlasEntity            entity            = entityWithExtInfo.getEntity();
    String                 attrValue         = (String) entity.getAttribute(ATTR_NAME_QUALIFIED_NAME);
    String[]               expectedValues    = getExtEntityExpectedValues(entityWithExtInfo);

    transform.apply(entityWithExtInfo);

    assertEquals(entityWithExtInfo.getEntity().getAttribute(ATTR_NAME_QUALIFIED_NAME), applyDefaultTransform(attrValue));

    for (int i = 0; i < expectedValues.length; i++) {
        assertEquals(entityWithExtInfo.getReferredEntities().get(Integer.toString(i)).getAttribute(ATTR_NAME_QUALIFIED_NAME), expectedValues[i]);
    }
}
 
Example 3
Source File: ImportTransforms.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public  AtlasEntity apply(AtlasEntity entity) throws AtlasBaseException {
    if(entity != null) {
        Map<String, List<ImportTransformer>> entityTransforms = getTransforms(entity.getTypeName());

        if (MapUtils.isNotEmpty(entityTransforms)) {
            for (Map.Entry<String, List<ImportTransformer>> entry : entityTransforms.entrySet()) {
                String                   attributeName  = entry.getKey();
                List<ImportTransformer> attrTransforms = entry.getValue();

                if (!entity.hasAttribute(attributeName)) {
                    continue;
                }

                Object transformedValue = entity.getAttribute(attributeName);

                for (ImportTransformer attrTransform : attrTransforms) {
                    transformedValue = attrTransform.apply(transformedValue);
                }

                entity.setAttribute(attributeName, transformedValue);
            }
        }
    }

    return entity;
}
 
Example 4
Source File: TransformationHandlerTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testHiveDatabaseNameRenameHandler() {
    // replace dbName: from hr to hr_backup
    AttributeTransform p = new AttributeTransform(Collections.singletonMap("hive_db.name", "EQUALS: hr"),
                                                  Collections.singletonMap("hive_db.name", "SET: hr_backup"));

    List<BaseEntityHandler> handlers = initializeHandlers(Collections.singletonList(p));

    for (AtlasEntity entity : getAllEntities()) {
        String  qualifiedName   = (String) entity.getAttribute(ATTR_NAME_QUALIFIED_NAME);
        boolean startsWithHrDot = qualifiedName.startsWith("hr."); // for tables, columns
        boolean startsWithHrAt  = qualifiedName.startsWith("hr@"); // for databases

        applyTransforms(entity, handlers);

        if (startsWithHrDot) {
            assertTrue(((String) entity.getAttribute(ATTR_NAME_QUALIFIED_NAME)).startsWith("hr_backup."));
        } else if (startsWithHrAt) {
            assertTrue(((String) entity.getAttribute(ATTR_NAME_QUALIFIED_NAME)).startsWith("hr_backup@"));
        } else {
            assertEquals(qualifiedName, (String) entity.getAttribute(ATTR_NAME_QUALIFIED_NAME), "not expected to change");
        }
    }
}
 
Example 5
Source File: TransformationHandlerTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testHdfsClusterRenameHandler() {
    // Rename clusterName from cl1 to cl2
    AttributeTransform p1 = new AttributeTransform(Collections.singletonMap("hdfs_path.clusterName", "EQUALS: cl1"),
                                                   Collections.singletonMap("hdfs_path.clusterName", "SET: cl2"));

    List<BaseEntityHandler> handlers = initializeHandlers(Collections.singletonList(p1));

    for (AtlasEntity hdfsPath : getHdfsPathEntities()) {
        String  qualifiedName = (String) hdfsPath.getAttribute(ATTR_NAME_QUALIFIED_NAME);
        boolean endsWithCl1   = qualifiedName.endsWith("@cl1");

        applyTransforms(hdfsPath, handlers);

        String transformedValue = (String) hdfsPath.getAttribute(ATTR_NAME_QUALIFIED_NAME);

        if (endsWithCl1) {
            assertTrue(transformedValue.endsWith("@cl2"), transformedValue + ": expected to end with @cl2");
        } else {
            assertEquals(qualifiedName, transformedValue, "not expected to change");
        }
    }
}
 
Example 6
Source File: AtlasEntityGraphDiscoveryV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
void visitEntity(AtlasEntityType entityType, AtlasEntity entity) throws AtlasBaseException {
    List<String> visitedAttributes = new ArrayList<>();

    // visit relationship attributes
    visitRelationships(entityType, entity, visitedAttributes);

    // visit struct attributes
    for (AtlasAttribute attribute : entityType.getAllAttributes().values()) {
        AtlasType attrType = attribute.getAttributeType();
        String    attrName = attribute.getName();
        Object    attrVal  = entity.getAttribute(attrName);

        if (entity.hasAttribute(attrName) && !visitedAttributes.contains(attrName)) {
            visitAttribute(attrType, attrVal);
        }
    }
}
 
Example 7
Source File: InverseReferenceUpdateV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected void verifyReferenceValue(AtlasEntity entity, String refName, String expectedGuid) {
    Object refValue = entity.getAttribute(refName);
    if (expectedGuid == null) {
        assertNull(refValue);
    }
    else {
        assertTrue(refValue instanceof AtlasObjectId);
        AtlasObjectId referencedObjectId = (AtlasObjectId) refValue;
        assertEquals(referencedObjectId.getGuid(), expectedGuid);
    }
}
 
Example 8
Source File: HiveDatabaseEntityHandler.java    From atlas with Apache License 2.0 5 votes vote down vote up
public HiveDatabaseEntity(AtlasEntity entity) {
    super(entity);

    this.databaseName = (String) entity.getAttribute(NAME_ATTRIBUTE);

    String qualifiedName = (String) entity.getAttribute(QUALIFIED_NAME_ATTRIBUTE);

    if (qualifiedName != null) {
        int clusterSeparatorIdx = qualifiedName.lastIndexOf(CLUSTER_DELIMITER);

        this.clusterName = clusterSeparatorIdx != -1 ? qualifiedName.substring(clusterSeparatorIdx + 1) : "";
    } else {
        this.clusterName = "";
    }
}
 
Example 9
Source File: InverseReferenceUpdateHardDeleteV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected void verify_testInverseReferenceAutoUpdate_Map(AtlasEntity a1, AtlasEntity b1,
    AtlasEntity b2, AtlasEntity b3) {

    Object value = a1.getAttribute("mapToB");
    assertTrue(value instanceof Map);
    Map<String, AtlasObjectId> refMap = (Map<String, AtlasObjectId>) value;
    assertEquals(refMap.size(), 1);
    AtlasObjectId referencedEntityId = refMap.get("b3");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b3));
    verifyReferenceValue(b1, "mappedFromA", null);
    verifyReferenceValue(b2, "mappedFromA", null);
}
 
Example 10
Source File: InverseReferenceUpdateSoftDeleteV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected void verify_testInverseReferenceAutoUpdate_Map(AtlasEntity a1, AtlasEntity b1,
    AtlasEntity b2, AtlasEntity b3) {

    Object value = a1.getAttribute("mapToB");
    assertTrue(value instanceof Map);
    Map<String, AtlasObjectId> refMap = (Map<String, AtlasObjectId>) value;
    assertEquals(refMap.size(), 3);
    AtlasObjectId referencedEntityId = refMap.get("b3");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b3));
    verifyReferenceValue(b1, "mappedFromA", a1.getGuid());
    verifyReferenceValue(b2, "mappedFromA", a1.getGuid());
}
 
Example 11
Source File: SoftReferenceTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void assertAttribute(String dbGuid, String storageGuid, int expectedTableCount, int expectedRegionCount) throws AtlasBaseException {
    AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo = entityStore.getById(dbGuid);
    AtlasEntity entity = entityWithExtInfo.getEntity();

    Object val = entity.getAttribute(RDBMS_DB_STORAGE_PROPERTY);
    assertTrue(val instanceof AtlasObjectId);
    assertEquals(((AtlasObjectId) val).getTypeName(), TYPE_RDBMS_STORAGE);
    assertEquals(((AtlasObjectId) val).getGuid(), storageGuid);
    assertNotNull(entity.getAttribute(RDBMS_DB_TABLES_PROPERTY));
    assertEquals(((List) entity.getAttribute(RDBMS_DB_TABLES_PROPERTY)).size(), expectedTableCount);
    assertNotNull(entity.getAttribute(RDBMS_DB_REGIONS_PROPERTY));
    assertEquals(((Map) entity.getAttribute(RDBMS_DB_REGIONS_PROPERTY)).size(), expectedRegionCount);
}
 
Example 12
Source File: AlterTableRename.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void renameStorageDesc(AtlasEntityWithExtInfo oldEntityExtInfo, AtlasEntityWithExtInfo newEntityExtInfo, List<HookNotification> notifications) {
    AtlasEntity oldSd = getStorageDescEntity(oldEntityExtInfo);
    AtlasEntity newSd = new AtlasEntity(getStorageDescEntity(newEntityExtInfo)); // make a copy of newSd, since we will be setting relationshipAttributes to 'null' below
                                                                                 // and we need relationship attributes later during entity full update

    if (oldSd != null && newSd != null) {
        AtlasObjectId oldSdId = new AtlasObjectId(oldSd.getTypeName(), ATTRIBUTE_QUALIFIED_NAME, oldSd.getAttribute(ATTRIBUTE_QUALIFIED_NAME));

        newSd.removeAttribute(ATTRIBUTE_TABLE);
        newSd.setRelationshipAttributes(null);

        notifications.add(new EntityPartialUpdateRequestV2(getUserName(), oldSdId, new AtlasEntityWithExtInfo(newSd)));
    }
}
 
Example 13
Source File: EntityLineageService.java    From atlas with Apache License 2.0 5 votes vote down vote up
private List<String> getColumnIds(AtlasEntity entity) {
    List<String> ret        = new ArrayList<>();
    Object       columnObjs = entity.getAttribute(COLUMNS);

    if (columnObjs instanceof List) {
        for (Object pkObj : (List) columnObjs) {
            if (pkObj instanceof AtlasObjectId) {
                ret.add(((AtlasObjectId) pkObj).getGuid());
            }
        }
    }

    return ret;
}
 
Example 14
Source File: HiveStorageDescriptorEntityHandler.java    From atlas with Apache License 2.0 5 votes vote down vote up
public HiveStorageDescriptorEntity(AtlasEntity entity) {
    super(entity);

    this.location = (String) entity.getAttribute(LOCATION_ATTRIBUTE);

    String qualifiedName = (String) entity.getAttribute(QUALIFIED_NAME_ATTRIBUTE);

    if (qualifiedName != null) {
        int    databaseSeparatorIdx  = qualifiedName.indexOf(DATABASE_DELIMITER);
        int    clusterSeparatorIdx   = qualifiedName.lastIndexOf(CLUSTER_DELIMITER);
        String clusterNameWithSuffix = clusterSeparatorIdx != -1 ? qualifiedName.substring(clusterSeparatorIdx + 1) : "";

        this.databaseName = (databaseSeparatorIdx != -1) ? qualifiedName.substring(0, databaseSeparatorIdx) : "";
        this.tableName    = (databaseSeparatorIdx != -1 && clusterSeparatorIdx != -1) ? qualifiedName.substring(databaseSeparatorIdx + 1, clusterSeparatorIdx) : "";

        if (StringUtils.isNotEmpty(clusterNameWithSuffix)) {
            int idx = clusterNameWithSuffix.lastIndexOf(HIVE_STORAGEDESC_SUFFIX);

            this.clusterName = (idx != -1) ? clusterNameWithSuffix.substring(0, idx) : "";
        } else {
            this.clusterName = "";
        }
    } else {
        this.databaseName = "";
        this.tableName    = "";
        this.clusterName  = "";
    }
}
 
Example 15
Source File: TestEntityREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void  testUpdateGetDeleteEntityByUniqueAttribute() throws Exception {
    AtlasEntity            dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));
    String                 dbGuid   = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();

    Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(dbGuid));

    final String prevDBName    = (String) dbEntity.getAttribute(TestUtilsV2.NAME);
    final String updatedDBName = prevDBName + ":updated";

    dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName);

    response = entityREST.partialUpdateEntityByUniqueAttrs(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, prevDBName), new AtlasEntityWithExtInfo(dbEntity));

    Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).get(0).getGuid(), dbGuid);

    //Get By unique attribute
    AtlasEntityWithExtInfo entity = entityREST.getByUniqueAttributes(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, updatedDBName));
    Assert.assertNotNull(entity);
    Assert.assertNotNull(entity.getEntity().getGuid());
    Assert.assertEquals(entity.getEntity().getGuid(), dbGuid);
    TestEntitiesREST.verifyAttributes(entity.getEntity().getAttributes(), dbEntity.getAttributes());

    final EntityMutationResponse deleteResponse = entityREST.deleteByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, toHttpServletRequest(TestUtilsV2.NAME, (String) dbEntity.getAttribute(TestUtilsV2.NAME)));

    Assert.assertNotNull(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE));
    Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).size(), 1);
    Assert.assertEquals(deleteResponse.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE).get(0).getGuid(), dbGuid);
}
 
Example 16
Source File: RdbmsPreprocessor.java    From atlas with Apache License 2.0 5 votes vote down vote up
private String getDbQualifiedName(AtlasEntity tableEntity) {
    String ret              = null;
    Object tblQualifiedName = tableEntity.getAttribute(ATTRIBUTE_QUALIFIED_NAME);  // dbName.tblName@clusterName
    Object tblName          = tableEntity.getAttribute(ATTRIBUTE_NAME);  // tblName

    if (tblQualifiedName != null && tblName != null) {
        ret = tblQualifiedName.toString().replace("." + tblName.toString() + "@", "@"); // dbName@clusterName
    }

    return ret;
}
 
Example 17
Source File: InverseReferenceUpdateV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_Map() throws Exception {
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b1 = new AtlasEntity("B");
    b1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b2 = new AtlasEntity("B");
    b2.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b3 = new AtlasEntity("B");
    b3.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(b1);
    atlasEntitiesWithExtInfo.addEntity(b2);
    atlasEntitiesWithExtInfo.addEntity(b3);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntityType aType = typeRegistry.getEntityTypeByName("A");
    AtlasEntity aForPartialUpdate = new AtlasEntity("A");
    aForPartialUpdate.setAttribute("mapToB", ImmutableMap.<String, AtlasObjectId>of("b1", AtlasTypeUtil.getAtlasObjectId(b1), "b2", AtlasTypeUtil.getAtlasObjectId(b2)));
    init();
    response = entityStore.updateByUniqueAttributes(aType, Collections.<String, Object>singletonMap(NAME, a1.getAttribute(NAME)), new AtlasEntityWithExtInfo(aForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set a1.mapToB to "b1"->b1, "b2"->b2
    // * set b1.mappedFromA to a1
    // * set b2.mappedFromA to a1
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b2.getGuid(), b1.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    Object value = storedEntity.getAttribute("mapToB");
    assertTrue(value instanceof Map);
    Map<String, AtlasObjectId> refMap = (Map<String, AtlasObjectId>) value;
    assertEquals(refMap.size(), 2);
    AtlasObjectId referencedEntityId = refMap.get("b1");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b1));
    referencedEntityId = refMap.get("b2");
    assertEquals(referencedEntityId, AtlasTypeUtil.getAtlasObjectId(b2));
    storedEntity = storedEntities.getEntity(b1.getGuid());
    verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid());
    storedEntity = storedEntities.getEntity(b2.getGuid());
    verifyReferenceValue(storedEntity, "mappedFromA", a1.getGuid());

    aForPartialUpdate.setAttribute("mapToB", ImmutableMap.<String, AtlasObjectId>of("b3", AtlasTypeUtil.getAtlasObjectId(b3)));
    init();
    response = entityStore.updateByUniqueAttributes(aType, Collections.<String, Object>singletonMap(NAME, a1.getAttribute(NAME)), new AtlasEntityWithExtInfo(aForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 4 entities were updated:
    // * set a1.mapToB to "b3"->b3
    // * set b3.mappedFromA to a1
    // * disconnect b1.mappedFromA
    // * disconnect b2.mappedFromA
    assertEquals(partialUpdatedEntities.size(), 4);
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b2.getGuid(), b1.getGuid(), b3.getGuid()));
    AtlasEntity storedB3 = storedEntities.getEntity(b3.getGuid());
    verifyReferenceValue(storedB3, "mappedFromA", a1.getGuid());
    verify_testInverseReferenceAutoUpdate_Map(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(b1.getGuid()), storedEntities.getEntity(b2.getGuid()), storedB3);
}
 
Example 18
Source File: InverseReferenceUpdateV2Test.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testInverseReferenceAutoUpdate_NonComposite_OneToOne() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, TestUtilsV2.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(b);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream , false);

    AtlasEntity bForPartialUpdate = new AtlasEntity("B");
    bForPartialUpdate.setAttribute("a", AtlasTypeUtil.getAtlasObjectId(a1));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 2 entities were updated:
    // * set b.a reference to a1
    // * set inverse a1.b reference to b
    assertEquals(partialUpdatedEntities.size(), 2);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), b.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceValue(storedEntity, "b", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceValue(storedEntity, "a", a1.getGuid());

    // Update b.a to reference a2.
    bForPartialUpdate.setAttribute("a", AtlasTypeUtil.getAtlasObjectId(a2));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.a reference to a2
    // * set a2.b reference to b
    // * disconnect a1.b reference
    assertEquals(partialUpdatedEntities.size(), 3);
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceValue(storedEntity, "b", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceValue(storedEntity, "a", a2.getGuid());
    storedEntity = storedEntities.getEntity(a1.getGuid());
    Object refValue = storedEntity.getAttribute("b");
    verify_testInverseReferenceAutoUpdate_NonComposite_OneToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(b.getGuid()));
}
 
Example 19
Source File: HiveITBase.java    From atlas with Apache License 2.0 4 votes vote down vote up
protected static void addDataset(StringBuilder buffer, AtlasEntity ref) {
    buffer.append(SEP);
    String dataSetQlfdName = (String) ref.getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME);
    // '/' breaks query parsing on ATLAS
    buffer.append(dataSetQlfdName.toLowerCase().replaceAll("/", ""));
}
 
Example 20
Source File: HBaseAtlasHook.java    From atlas with Apache License 2.0 4 votes vote down vote up
private AtlasEntity buildColumnFamily(HBaseOperationContext hbaseOperationContext, ColumnFamilyDescriptor columnFamilyDescriptor, AtlasEntity nameSpace, AtlasEntity table) {
    AtlasEntity columnFamily      = new AtlasEntity(HBaseDataTypes.HBASE_COLUMN_FAMILY.getName());
    String      columnFamilyName  = columnFamilyDescriptor.getNameAsString();
    String      tableName         = (String) table.getAttribute(ATTR_NAME);
    String      nameSpaceName     = (String) nameSpace.getAttribute(ATTR_NAME);
    String      columnFamilyQName = getColumnFamilyQualifiedName(getMetadataNamespace(), nameSpaceName, tableName, columnFamilyName);
    Date        now               = new Date(System.currentTimeMillis());

    columnFamily.setAttribute(ATTR_NAME, columnFamilyName);
    columnFamily.setAttribute(ATTR_DESCRIPTION, columnFamilyName);
    columnFamily.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME, columnFamilyQName);
    columnFamily.setAttribute(ATTR_OWNER, hbaseOperationContext.getOwner());
    columnFamily.setRelationshipAttribute(ATTR_TABLE, AtlasTypeUtil.getAtlasRelatedObjectId(table, RELATIONSHIP_HBASE_TABLE_COLUMN_FAMILIES));

    if (columnFamilyDescriptor!= null) {
        columnFamily.setAttribute(ATTR_CF_BLOCK_CACHE_ENABLED, columnFamilyDescriptor.isBlockCacheEnabled());
        columnFamily.setAttribute(ATTR_CF_BLOOMFILTER_TYPE, (columnFamilyDescriptor.getBloomFilterType() != null ? columnFamilyDescriptor.getBloomFilterType().name():null));
        columnFamily.setAttribute(ATTR_CF_CACHED_BLOOM_ON_WRITE, columnFamilyDescriptor.isCacheBloomsOnWrite());
        columnFamily.setAttribute(ATTR_CF_CACHED_DATA_ON_WRITE, columnFamilyDescriptor.isCacheDataOnWrite());
        columnFamily.setAttribute(ATTR_CF_CACHED_INDEXES_ON_WRITE, columnFamilyDescriptor.isCacheIndexesOnWrite());
        columnFamily.setAttribute(ATTR_CF_COMPACTION_COMPRESSION_TYPE, (columnFamilyDescriptor.getCompactionCompressionType() != null ? columnFamilyDescriptor.getCompactionCompressionType().name():null));
        columnFamily.setAttribute(ATTR_CF_COMPRESSION_TYPE, (columnFamilyDescriptor.getCompressionType() != null ? columnFamilyDescriptor.getCompressionType().name():null));
        columnFamily.setAttribute(ATTR_CF_DATA_BLOCK_ENCODING, (columnFamilyDescriptor.getDataBlockEncoding() != null ? columnFamilyDescriptor.getDataBlockEncoding().name():null));
        columnFamily.setAttribute(ATTR_CF_ENCRYPTION_TYPE, columnFamilyDescriptor.getEncryptionType());
        columnFamily.setAttribute(ATTR_CF_EVICT_BLOCK_ONCLOSE, columnFamilyDescriptor.isEvictBlocksOnClose());
        columnFamily.setAttribute(ATTR_CF_INMEMORY_COMPACTION_POLICY, (columnFamilyDescriptor.getInMemoryCompaction() != null ? columnFamilyDescriptor.getInMemoryCompaction().name():null));
        columnFamily.setAttribute(ATTR_CF_KEEP_DELETE_CELLS, ( columnFamilyDescriptor.getKeepDeletedCells() != null ? columnFamilyDescriptor.getKeepDeletedCells().name():null));
        columnFamily.setAttribute(ATTR_CF_MAX_VERSIONS, columnFamilyDescriptor.getMaxVersions());
        columnFamily.setAttribute(ATTR_CF_MIN_VERSIONS, columnFamilyDescriptor.getMinVersions());
        columnFamily.setAttribute(ATTR_CF_NEW_VERSION_BEHAVIOR, columnFamilyDescriptor.isNewVersionBehavior());
        columnFamily.setAttribute(ATTR_CF_MOB_ENABLED, columnFamilyDescriptor.isMobEnabled());
        columnFamily.setAttribute(ATTR_CF_MOB_COMPATCTPARTITION_POLICY, ( columnFamilyDescriptor.getMobCompactPartitionPolicy() != null ? columnFamilyDescriptor.getMobCompactPartitionPolicy().name():null));
        columnFamily.setAttribute(ATTR_CF_PREFETCH_BLOCK_ONOPEN, columnFamilyDescriptor.isPrefetchBlocksOnOpen());
        columnFamily.setAttribute(ATTR_CF_STORAGE_POLICY, columnFamilyDescriptor.getStoragePolicy());
        columnFamily.setAttribute(ATTR_CF_TTL, columnFamilyDescriptor.getTimeToLive());
    }

    switch (hbaseOperationContext.getOperation()) {
        case CREATE_COLUMN_FAMILY:
        case CREATE_TABLE:
            columnFamily.setAttribute(ATTR_CREATE_TIME, now);
            columnFamily.setAttribute(ATTR_MODIFIED_TIME, now);
            break;

        case ALTER_COLUMN_FAMILY:
            columnFamily.setAttribute(ATTR_MODIFIED_TIME, now);
            break;

        default:
            break;
    }

    return columnFamily;
}