Java Code Examples for org.apache.atlas.model.instance.EntityMutationResponse#getEntitiesByOperation()

The following examples show how to use org.apache.atlas.model.instance.EntityMutationResponse#getEntitiesByOperation() . 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: TestEntityRESTDelete.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void createEntities() throws Exception {
    dbEntities.clear();

    for (int i = 1; i <= 2; i++) {
        AtlasEntity dbEntity = TestUtilsV2.createDBEntity();

        final EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntity.AtlasEntitiesWithExtInfo(dbEntity));

        assertNotNull(response);
        List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);

        assertNotNull(entitiesMutated);
        Assert.assertEquals(entitiesMutated.size(), 1);
        assertNotNull(entitiesMutated.get(0));
        dbEntity.setGuid(entitiesMutated.get(0).getGuid());

        dbEntities.add(dbEntity);
    }
}
 
Example 2
Source File: AtlasEntityStoreV2Test.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultValueForPrimitiveTypes() throws Exception  {
    init();

    EntityMutationResponse  response                   = entityStore.createOrUpdate(new AtlasEntityStream(primitiveEntity), false);
    List<AtlasEntityHeader> entitiesCreatedResponse    = response.getEntitiesByOperation(EntityOperation.CREATE);
    List<AtlasEntityHeader> entitiesCreatedwithdefault = response.getMutatedEntities().get(EntityOperation.CREATE);
    AtlasEntity             entityCreated              = getEntityFromStore(entitiesCreatedResponse.get(0));

    Map     attributesMap = entityCreated.getAttributes();
    String  description   = (String) attributesMap.get("description");
    String  check         = (String) attributesMap.get("check");
    String  sourceCode    = (String) attributesMap.get("sourcecode");
    float   diskUsage     = (float) attributesMap.get("diskUsage");
    boolean isstoreUse    = (boolean) attributesMap.get("isstoreUse");
    int     cost          = (int) attributesMap.get("Cost");

    assertEquals(description,"test");
    assertEquals(check,"check");

    //defaultValue
    assertEquals(diskUsage,70.5f);
    assertEquals(isstoreUse,true);
    assertEquals(sourceCode,"Hello World");
    assertEquals(cost,30);
}
 
Example 3
Source File: TestEntitiesREST.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateOrUpdateEntities() throws Exception {
    AtlasEntitiesWithExtInfo entities = new AtlasEntitiesWithExtInfo();

    entities.addEntity(dbEntity);
    entities.addEntity(tableEntity);
    for (AtlasEntity column : columns) {
        entities.addReferredEntity(column);
    }

    EntityMutationResponse response = entityREST.createOrUpdate(entities);
    List<AtlasEntityHeader> guids = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);

    Assert.assertNotNull(guids);
    Assert.assertEquals(guids.size(), 3);

    for (AtlasEntityHeader header : guids) {
        createdGuids.add(header.getGuid());
    }
}
 
Example 4
Source File: QuickStartV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntity createInstance(AtlasEntityWithExtInfo entityWithExtInfo) throws Exception {
    AtlasEntity             ret      = null;
    EntityMutationResponse  response = atlasClientV2.createEntity(entityWithExtInfo);
    List<AtlasEntityHeader> entities = response.getEntitiesByOperation(EntityOperation.CREATE);

    if (CollectionUtils.isNotEmpty(entities)) {
        AtlasEntityWithExtInfo getByGuidResponse = atlasClientV2.getEntityByGuid(entities.get(0).getGuid());

        ret = getByGuidResponse.getEntity();

        System.out.println("Created entity of type [" + ret.getTypeName() + "], guid: " + ret.getGuid());
    }

    return ret;
}
 
Example 5
Source File: TestEntitiesREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testTagSearchBySystemAttributes")
public void testUpdateWithSerializedEntities() throws  Exception {

    //Check with serialization and deserialization of entity attributes for the case
    // where attributes which are de-serialized into a map
    AtlasEntity dbEntity    = TestUtilsV2.createDBEntity();
    AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);

    final AtlasEntity colEntity = TestUtilsV2.createColumnEntity(tableEntity);
    List<AtlasEntity> columns = new ArrayList<AtlasEntity>() {{ add(colEntity); }};
    tableEntity.setAttribute("columns", getObjIdList(columns));

    AtlasEntity newDBEntity = serDeserEntity(dbEntity);
    AtlasEntity newTableEntity = serDeserEntity(tableEntity);

    AtlasEntitiesWithExtInfo newEntities = new AtlasEntitiesWithExtInfo();
    newEntities.addEntity(newDBEntity);
    newEntities.addEntity(newTableEntity);
    for (AtlasEntity column : columns) {
        newEntities.addReferredEntity(serDeserEntity(column));
    }

    EntityMutationResponse response2 = entityREST.createOrUpdate(newEntities);

    List<AtlasEntityHeader> newGuids = response2.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
    Assert.assertNotNull(newGuids);
    Assert.assertEquals(newGuids.size(), 3);
}
 
Example 6
Source File: TestEntityREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void createTestEntity() throws Exception {
    AtlasEntity dbEntity = TestUtilsV2.createDBEntity();

    final EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));

    Assert.assertNotNull(response);
    List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);

    Assert.assertNotNull(entitiesMutated);
    Assert.assertEquals(entitiesMutated.size(), 1);
    Assert.assertNotNull(entitiesMutated.get(0));
    dbEntity.setGuid(entitiesMutated.get(0).getGuid());

    this.dbEntity = dbEntity;
}
 
Example 7
Source File: TestEntityREST.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testDeleteClassificationByUniqueAttribute")
public void  testDeleteEntityById() throws Exception {

    EntityMutationResponse response = entityREST.deleteByGuid(dbEntity.getGuid());
    List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE);
    Assert.assertNotNull(entitiesMutated);
    Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbEntity.getGuid());
}
 
Example 8
Source File: HiveMetaStoreBridge.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Registers an entity in atlas
 * @param entity
 * @return
 * @throws Exception
 */
private AtlasEntityWithExtInfo registerInstance(AtlasEntityWithExtInfo entity) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("creating {} entity: {}", entity.getEntity().getTypeName(), entity);
    }

    AtlasEntityWithExtInfo  ret             = null;
    EntityMutationResponse  response        = atlasClientV2.createEntity(entity);
    List<AtlasEntityHeader> createdEntities = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);

    if (CollectionUtils.isNotEmpty(createdEntities)) {
        for (AtlasEntityHeader createdEntity : createdEntities) {
            if (ret == null) {
                ret = atlasClientV2.getEntityByGuid(createdEntity.getGuid());

                LOG.info("Created {} entity: name={}, guid={}", ret.getEntity().getTypeName(), ret.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME), ret.getEntity().getGuid());
            } else if (ret.getEntity(createdEntity.getGuid()) == null) {
                AtlasEntityWithExtInfo newEntity = atlasClientV2.getEntityByGuid(createdEntity.getGuid());

                ret.addReferredEntity(newEntity.getEntity());

                if (MapUtils.isNotEmpty(newEntity.getReferredEntities())) {
                    for (Map.Entry<String, AtlasEntity> entry : newEntity.getReferredEntities().entrySet()) {
                        ret.addReferredEntity(entry.getKey(), entry.getValue());
                    }
                }

                LOG.info("Created {} entity: name={}, guid={}", newEntity.getEntity().getTypeName(), newEntity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME), newEntity.getEntity().getGuid());
            }
        }
    }

    clearRelationshipAttributes(ret);

    return ret;
}
 
Example 9
Source File: HiveMetaStoreBridge.java    From atlas with Apache License 2.0 5 votes vote down vote up
/**
 * Registers an entity in atlas
 * @param entities
 * @return
 * @throws Exception
 */
private AtlasEntitiesWithExtInfo registerInstances(AtlasEntitiesWithExtInfo entities) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("creating {} entities: {}", entities.getEntities().size(), entities);
    }

    AtlasEntitiesWithExtInfo ret = null;
    EntityMutationResponse   response        = atlasClientV2.createEntities(entities);
    List<AtlasEntityHeader>  createdEntities = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);

    if (CollectionUtils.isNotEmpty(createdEntities)) {
        ret = new AtlasEntitiesWithExtInfo();

        for (AtlasEntityHeader createdEntity : createdEntities) {
            AtlasEntityWithExtInfo entity = atlasClientV2.getEntityByGuid(createdEntity.getGuid());

            ret.addEntity(entity.getEntity());

            if (MapUtils.isNotEmpty(entity.getReferredEntities())) {
                for (Map.Entry<String, AtlasEntity> entry : entity.getReferredEntities().entrySet()) {
                    ret.addReferredEntity(entry.getKey(), entry.getValue());
                }
            }

            LOG.info("Created {} entity: name={}, guid={}", entity.getEntity().getTypeName(), entity.getEntity().getAttribute(ATTRIBUTE_QUALIFIED_NAME), entity.getEntity().getGuid());
        }
    }

    clearRelationshipAttributes(ret);

    return ret;
}
 
Example 10
Source File: QuickStartV2.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntity createInstance(AtlasEntity entity, String[] traitNames) throws Exception {
    AtlasEntity ret = null;
    EntityMutationResponse  response = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(entity));
    List<AtlasEntityHeader> entities = response.getEntitiesByOperation(EntityOperation.CREATE);

    if (CollectionUtils.isNotEmpty(entities)) {
        AtlasEntityWithExtInfo getByGuidResponse = atlasClientV2.getEntityByGuid(entities.get(0).getGuid());
        ret = getByGuidResponse.getEntity();
        System.out.println("Created entity of type [" + ret.getTypeName() + "], guid: " + ret.getGuid());
    }

    return ret;
}
 
Example 11
Source File: TestEntitiesREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithSerializedEntities() throws  Exception {
    //Check with serialization and deserialization of entity attributes for the case
    // where attributes which are de-serialized into a map
    AtlasEntity dbEntity    = TestUtilsV2.createDBEntity();
    AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);

    final AtlasEntity colEntity = TestUtilsV2.createColumnEntity(tableEntity);
    List<AtlasEntity> columns = new ArrayList<AtlasEntity>() {{ add(colEntity); }};
    tableEntity.setAttribute("columns", getObjIdList(columns));

    AtlasEntity newDBEntity = serDeserEntity(dbEntity);
    AtlasEntity newTableEntity = serDeserEntity(tableEntity);

    AtlasEntitiesWithExtInfo newEntities = new AtlasEntitiesWithExtInfo();
    newEntities.addEntity(newDBEntity);
    newEntities.addEntity(newTableEntity);
    for (AtlasEntity column : columns) {
        newEntities.addReferredEntity(serDeserEntity(column));
    }

    EntityMutationResponse response2 = entityREST.createOrUpdate(newEntities);

    List<AtlasEntityHeader> newGuids = response2.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);
    Assert.assertNotNull(newGuids);
    Assert.assertEquals(newGuids.size(), 3);
}
 
Example 12
Source File: TestEntityREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void createTestEntity() throws Exception {
    AtlasEntity dbEntity = TestUtilsV2.createDBEntity();

    final EntityMutationResponse response = entityREST.createOrUpdate(new AtlasEntitiesWithExtInfo(dbEntity));

    Assert.assertNotNull(response);
    List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE);

    Assert.assertNotNull(entitiesMutated);
    Assert.assertEquals(entitiesMutated.size(), 1);
    Assert.assertNotNull(entitiesMutated.get(0));
    dbEntity.setGuid(entitiesMutated.get(0).getGuid());

    this.dbEntity = dbEntity;
}
 
Example 13
Source File: TestEntityREST.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods = "testDeleteClassification")
public void  testDeleteEntityById() throws Exception {

    EntityMutationResponse response = entityREST.deleteByGuid(dbEntity.getGuid());
    List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE);
    Assert.assertNotNull(entitiesMutated);
    Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbEntity.getGuid());
}
 
Example 14
Source File: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultValueForPrimitiveTypes() throws Exception  {

    init();

    EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(primitiveEntity), false);
    List<AtlasEntityHeader> entitiesCreatedResponse = response.getEntitiesByOperation(EntityOperation.CREATE);
    final Map<EntityOperation, List<AtlasEntityHeader>> entitiesMutated = response.getMutatedEntities();
    List<AtlasEntityHeader> entitiesCreatedwithdefault = entitiesMutated.get(EntityOperation.CREATE);

    AtlasEntity entityCreated   = getEntityFromStore(entitiesCreatedResponse.get(0));


    Map attributesMap = entityCreated.getAttributes();
    String description = (String) attributesMap.get("description");
    String check = (String) attributesMap.get("check");
    String   sourceCode =  (String) attributesMap.get("sourcecode");
    float   diskUsage =  (float) attributesMap.get("diskUsage");
    boolean   isstoreUse =  (boolean) attributesMap.get("isstoreUse");
    int cost = (int)attributesMap.get("Cost");


    assertEquals(description,"test");
    assertEquals(check,"check");

    //defaultValue
    assertEquals(diskUsage,70.5f);
    assertEquals(isstoreUse,true);
    assertEquals(sourceCode,"Hello World");
    assertEquals(cost,30);
}
 
Example 15
Source File: AtlasEntityTestBase.java    From atlas with Apache License 2.0 4 votes vote down vote up
protected void validateMutationResponse(EntityMutationResponse response, EntityOperation op, int expectedNumCreated) {
    List<AtlasEntityHeader> entitiesCreated = response.getEntitiesByOperation(op);
    Assert.assertNotNull(entitiesCreated);
    Assert.assertEquals(entitiesCreated.size(), expectedNumCreated);
}
 
Example 16
Source File: AtlasEntityStoreV1Test.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
private void validateMutationResponse(EntityMutationResponse response, EntityMutations.EntityOperation op, int expectedNumCreated) {
    List<AtlasEntityHeader> entitiesCreated = response.getEntitiesByOperation(op);
    Assert.assertNotNull(entitiesCreated);
    Assert.assertEquals(entitiesCreated.size(), expectedNumCreated);
}