Search in sources :

Example 71 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class BaseResourceIT method createHiveDBInstanceV2.

protected AtlasEntity createHiveDBInstanceV2(String dbName) {
    AtlasEntity atlasEntity = new AtlasEntity(DATABASE_TYPE_V2);
    atlasEntity.setAttribute(NAME, dbName);
    atlasEntity.setAttribute(DESCRIPTION, "foo database");
    atlasEntity.setAttribute(CLUSTER_NAME, "fooCluster");
    atlasEntity.setAttribute("owner", "user1");
    atlasEntity.setAttribute("locationUri", "/tmp");
    atlasEntity.setAttribute("createTime", 1000);
    return atlasEntity;
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 72 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class ExportService method processEntity.

private void processEntity(String guid, ExportContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> processEntity({})", guid);
    }
    if (!context.guidsProcessed.contains(guid)) {
        TraversalDirection direction = context.guidDirection.get(guid);
        AtlasEntityWithExtInfo entityWithExtInfo = entityGraphRetriever.toAtlasEntityWithExtInfo(guid);
        context.result.getData().getEntityCreationOrder().add(entityWithExtInfo.getEntity().getGuid());
        addEntity(entityWithExtInfo, context);
        addTypes(entityWithExtInfo.getEntity(), context);
        context.guidsProcessed.add(entityWithExtInfo.getEntity().getGuid());
        getConntedEntitiesBasedOnOption(entityWithExtInfo.getEntity(), context, direction);
        if (entityWithExtInfo.getReferredEntities() != null) {
            for (AtlasEntity e : entityWithExtInfo.getReferredEntities().values()) {
                addTypes(e, context);
                getConntedEntitiesBasedOnOption(e, context, direction);
            }
            context.guidsProcessed.addAll(entityWithExtInfo.getReferredEntities().keySet());
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== processEntity({})", guid);
    }
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 73 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class InverseReferenceUpdateV1Test method testInverseReferenceAutoUpdate_NonCompositeManyToOne.

@Test
public void testInverseReferenceAutoUpdate_NonCompositeManyToOne() throws Exception {
    AtlasEntityType bType = typeRegistry.getEntityTypeByName("B");
    AtlasEntity a1 = new AtlasEntity("A");
    a1.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a2 = new AtlasEntity("A");
    a2.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity a3 = new AtlasEntity("A");
    a3.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity b = new AtlasEntity("B");
    b.setAttribute(NAME, TestUtils.randomString());
    AtlasEntitiesWithExtInfo atlasEntitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    atlasEntitiesWithExtInfo.addEntity(a1);
    atlasEntitiesWithExtInfo.addEntity(a2);
    atlasEntitiesWithExtInfo.addEntity(a3);
    atlasEntitiesWithExtInfo.addEntity(b);
    AtlasEntityStream entityStream = new AtlasEntityStream(atlasEntitiesWithExtInfo);
    EntityMutationResponse response = entityStore.createOrUpdate(entityStream, false);
    AtlasEntity bForPartialUpdate = new AtlasEntity("B");
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    List<AtlasEntityHeader> partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 3 entities were updated:
    // * set b.manyA reference to a1 and a2
    // * set inverse a1.oneB reference to b
    // * set inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 3);
    AtlasEntitiesWithExtInfo storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), b.getGuid()));
    AtlasEntity storedEntity = storedEntities.getEntity(a1.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(a2.getGuid());
    verifyReferenceValue(storedEntity, "oneB", b.getGuid());
    storedEntity = storedEntities.getEntity(b.getGuid());
    verifyReferenceList(storedEntity, "manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a1), AtlasTypeUtil.getAtlasObjectId(a2)));
    bForPartialUpdate.setAttribute("manyA", ImmutableList.of(AtlasTypeUtil.getAtlasObjectId(a3)));
    init();
    response = entityStore.updateByUniqueAttributes(bType, Collections.<String, Object>singletonMap(NAME, b.getAttribute(NAME)), new AtlasEntityWithExtInfo(bForPartialUpdate));
    partialUpdatedEntities = response.getPartialUpdatedEntities();
    // Verify 4 entities were updated:
    // * set b.manyA reference to a3
    // * set inverse a3.oneB reference to b
    // * disconnect inverse a1.oneB reference to b
    // * disconnect inverse a2.oneB reference to b
    assertEquals(partialUpdatedEntities.size(), 4);
    init();
    storedEntities = entityStore.getByIds(ImmutableList.of(a1.getGuid(), a2.getGuid(), a3.getGuid(), b.getGuid()));
    verifyReferenceValue(storedEntities.getEntity(a3.getGuid()), "oneB", b.getGuid());
    verify_testInverseReferenceAutoUpdate_NonCompositeManyToOne(storedEntities.getEntity(a1.getGuid()), storedEntities.getEntity(a2.getGuid()), storedEntities.getEntity(a3.getGuid()), storedEntities.getEntity(b.getGuid()));
}
Also used : AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test)

Example 74 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class QuickStartV2IT method getTable.

private AtlasEntity getTable(String tableName) throws AtlasServiceException {
    Map<String, String> attributes = new HashMap<>();
    attributes.put(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, tableName);
    AtlasEntity tableEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.TABLE_TYPE, attributes).getEntity();
    return tableEntity;
}
Also used : HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 75 with AtlasEntity

use of org.apache.atlas.model.instance.AtlasEntity in project incubator-atlas by apache.

the class QuickStartV2IT method getDB.

private AtlasEntity getDB(String dbName) throws AtlasServiceException, JSONException {
    Map<String, String> attributes = new HashMap<>();
    attributes.put("name", dbName);
    AtlasEntity dbEntity = atlasClientV2.getEntityByAttribute(QuickStartV2.DATABASE_TYPE, attributes).getEntity();
    return dbEntity;
}
Also used : HashMap(java.util.HashMap) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Aggregations

AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)58 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)43 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)36 HashMap (java.util.HashMap)25 BeforeTest (org.testng.annotations.BeforeTest)25 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)24 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)24 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)21 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 ArrayList (java.util.ArrayList)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)14 Map (java.util.Map)12 List (java.util.List)11 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)11 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)9 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)9 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)7 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7