Search in sources :

Example 21 with AtlasEntityHeader

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

the class TestEntitiesREST method testUpdateWithSerializedEntities.

@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);
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) ArrayList(java.util.ArrayList) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) Test(org.testng.annotations.Test)

Example 22 with AtlasEntityHeader

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

the class AtlasDeleteHandlerV1Test method testDeleteTargetOfRequiredMapReference.

@Test
public void testDeleteTargetOfRequiredMapReference() throws Exception {
    // Define type for map value.
    AtlasEntityDef mapValueDef = new AtlasEntityDef("RequiredMapValue", "RequiredMapValue_description", "1.0", Collections.<AtlasStructDef.AtlasAttributeDef>emptyList(), Collections.<String>emptySet());
    AtlasStructDef.AtlasAttributeDef[] mapOwnerAttributes = new AtlasStructDef.AtlasAttributeDef[] { new AtlasStructDef.AtlasAttributeDef("map", "map<string,RequiredMapValue>", false, AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, 1, 1, false, false, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()) };
    AtlasEntityDef mapOwnerDef = new AtlasEntityDef("RequiredMapOwner", "RequiredMapOwner_description", "1.0", Arrays.asList(mapOwnerAttributes), Collections.<String>emptySet());
    AtlasTypesDef typesDef = AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.<AtlasEntityDef>of(mapValueDef, mapOwnerDef));
    typeDefStore.createTypesDef(typesDef);
    AtlasEntityType mapOwnerType = typeRegistry.getEntityTypeByName("RequiredMapOwner");
    AtlasEntityType mapValueType = typeRegistry.getEntityTypeByName("RequiredMapValue");
    // Create instances of RequiredMapOwner and RequiredMapValue.
    // Set RequiredMapOwner.map with one entry that references RequiredMapValue instance.
    AtlasEntity mapOwnerInstance = new AtlasEntity(mapOwnerType.getTypeName());
    AtlasEntity mapValueInstance = new AtlasEntity(mapValueType.getTypeName());
    mapOwnerInstance.setAttribute("map", Collections.singletonMap("value1", AtlasTypeUtil.getAtlasObjectId(mapValueInstance)));
    AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo();
    entities.addReferredEntity(mapValueInstance);
    entities.addEntity(mapOwnerInstance);
    List<AtlasEntityHeader> createEntitiesResult = entityStore.createOrUpdate(new AtlasEntityStream(entities), false).getCreatedEntities();
    Assert.assertEquals(createEntitiesResult.size(), 2);
    List<String> guids = metadataService.getEntityList("RequiredMapOwner");
    Assert.assertEquals(guids.size(), 1);
    String mapOwnerGuid = guids.get(0);
    guids = metadataService.getEntityList("RequiredMapValue");
    Assert.assertEquals(guids.size(), 1);
    String mapValueGuid = guids.get(0);
    // Verify MapOwner.map attribute has expected value.
    final AtlasEntity.AtlasEntityWithExtInfo mapOwnerInstance1 = entityStore.getById(mapOwnerGuid);
    Object object = mapOwnerInstance1.getEntity().getAttribute("map");
    Assert.assertNotNull(object);
    Assert.assertTrue(object instanceof Map);
    Map<String, AtlasObjectId> map = (Map<String, AtlasObjectId>) object;
    Assert.assertEquals(map.size(), 1);
    AtlasObjectId mapValueInstance1 = map.get("value1");
    Assert.assertNotNull(mapValueInstance1);
    Assert.assertEquals(mapValueInstance1.getGuid(), mapValueGuid);
    String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(mapOwnerType, "map");
    String mapEntryLabel = edgeLabel + "." + "value1";
    AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(mapEntryLabel);
    AtlasVertex mapOwnerVertex = GraphHelper.getInstance().getVertexForGUID(mapOwnerGuid);
    object = mapOwnerVertex.getProperty(atlasEdgeLabel.getQualifiedMapKey(), Object.class);
    Assert.assertNotNull(object);
    // Verify deleting the target of required map attribute throws a AtlasBaseException.
    try {
        entityStore.deleteById(mapValueGuid);
        Assert.fail(AtlasBaseException.class.getSimpleName() + " was expected but none thrown.");
    } catch (Exception e) {
        verifyExceptionThrown(e, AtlasBaseException.class);
    }
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEdgeLabel(org.apache.atlas.repository.graph.AtlasEdgeLabel) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasException(org.apache.atlas.AtlasException) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Map(java.util.Map) HashMap(java.util.HashMap) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 23 with AtlasEntityHeader

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

the class AtlasEntityStoreV1Test method testMapOfPrimitivesUpdate.

@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));
}
Also used : 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) TestUtils.randomString(org.apache.atlas.TestUtils.randomString) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 24 with AtlasEntityHeader

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

the class AtlasDeleteHandlerV1Test method testDeleteByUniqueAttribute.

@Test
public void testDeleteByUniqueAttribute() throws Exception {
    // Create a table entity, with 3 composite column entities
    init();
    final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
    EntityMutationResponse dbCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
    final AtlasEntity tableEntity = TestUtilsV2.createTableEntity(dbEntity);
    AtlasEntity.AtlasEntitiesWithExtInfo entitiesInfo = new AtlasEntity.AtlasEntitiesWithExtInfo(tableEntity);
    final AtlasEntity columnEntity1 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity1);
    final AtlasEntity columnEntity2 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity2);
    final AtlasEntity columnEntity3 = TestUtilsV2.createColumnEntity(tableEntity);
    entitiesInfo.addReferredEntity(columnEntity3);
    tableEntity.setAttribute(COLUMNS_ATTR_NAME, Arrays.asList(AtlasTypeUtil.getAtlasObjectId(columnEntity1), AtlasTypeUtil.getAtlasObjectId(columnEntity2), AtlasTypeUtil.getAtlasObjectId(columnEntity3)));
    init();
    final EntityMutationResponse tblCreationResponse = entityStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), false);
    final AtlasEntityHeader column1Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity1.getAttribute(NAME));
    final AtlasEntityHeader column2Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity2.getAttribute(NAME));
    final AtlasEntityHeader column3Created = tblCreationResponse.getCreatedEntityByTypeNameAndAttribute(COLUMN_TYPE, NAME, (String) columnEntity3.getAttribute(NAME));
    // Retrieve the table entities from the Repository, to get their guids and the composite column guids.
    ITypedReferenceableInstance tableInstance = metadataService.getEntityDefinitionReference(TestUtils.TABLE_TYPE, NAME, (String) tableEntity.getAttribute(NAME));
    List<IReferenceableInstance> columns = (List<IReferenceableInstance>) tableInstance.get(COLUMNS_ATTR_NAME);
    //Delete column
    String colId = columns.get(0).getId()._getId();
    String tableId = tableInstance.getId()._getId();
    init();
    Map<String, Object> uniqueAttrs = new HashMap<>();
    uniqueAttrs.put(NAME, column1Created.getAttribute(NAME));
    AtlasEntityType columnType = typeRegistry.getEntityTypeByName(COLUMN_TYPE);
    EntityMutationResponse deletionResponse = entityStore.deleteByUniqueAttributes(columnType, uniqueAttrs);
    assertEquals(deletionResponse.getDeletedEntities().size(), 1);
    assertEquals(deletionResponse.getDeletedEntities().get(0).getGuid(), colId);
    assertEquals(deletionResponse.getUpdatedEntities().size(), 1);
    assertEquals(deletionResponse.getUpdatedEntities().get(0).getGuid(), tableId);
    assertEntityDeleted(colId);
}
Also used : HashMap(java.util.HashMap) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 25 with AtlasEntityHeader

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

the class AtlasDeleteHandlerV1Test method createMapOwnerAndValueEntities.

private AtlasEntity.AtlasEntityWithExtInfo createMapOwnerAndValueEntities() throws AtlasException, AtlasBaseException {
    final AtlasEntity mapOwnerInstance = new AtlasEntity(compositeMapOwnerType.getTypeName());
    mapOwnerInstance.setAttribute(NAME, TestUtils.randomString());
    AtlasEntity mapValueInstance = new AtlasEntity(compositeMapValueType.getTypeName());
    mapValueInstance.setAttribute(NAME, TestUtils.randomString());
    mapOwnerInstance.setAttribute("map", Collections.singletonMap("value1", AtlasTypeUtil.getAtlasObjectId(mapValueInstance)));
    AtlasEntity.AtlasEntitiesWithExtInfo entities = new AtlasEntity.AtlasEntitiesWithExtInfo();
    entities.addReferredEntity(mapValueInstance);
    entities.addEntity(mapOwnerInstance);
    List<AtlasEntityHeader> createEntitiesResult = entityStore.createOrUpdate(new AtlasEntityStream(entities), false).getCreatedEntities();
    Assert.assertEquals(createEntitiesResult.size(), 2);
    AtlasEntity.AtlasEntityWithExtInfo entityDefinition = entityStore.getByUniqueAttributes(compositeMapOwnerType, new HashMap<String, Object>() {

        {
            put(NAME, mapOwnerInstance.getAttribute(NAME));
        }
    });
    return entityDefinition;
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader)

Aggregations

AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)65 Test (org.testng.annotations.Test)46 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)38 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)34 BeforeTest (org.testng.annotations.BeforeTest)22 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)15 ArrayList (java.util.ArrayList)14 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)14 HashMap (java.util.HashMap)12 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)12 List (java.util.List)10 Map (java.util.Map)8 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)8 LineageRelation (org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)6 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)5 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)5