Search in sources :

Example 51 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class AtlasTypeDefGraphStoreTest method testUpdate.

@Test(dependsOnMethods = { "testCreateDept" }, dataProvider = "validUpdateDeptTypes")
public void testUpdate(AtlasTypesDef atlasTypesDef) {
    try {
        AtlasTypesDef updatedTypesDef = typeDefStore.updateTypesDef(atlasTypesDef);
        assertNotNull(updatedTypesDef);
        assertEquals(updatedTypesDef.getEnumDefs().size(), atlasTypesDef.getEnumDefs().size(), "EnumDefs update failed");
        assertEquals(updatedTypesDef.getClassificationDefs().size(), atlasTypesDef.getClassificationDefs().size(), "ClassificationDef update failed");
        assertEquals(updatedTypesDef.getStructDefs().size(), atlasTypesDef.getStructDefs().size(), "StructDef update failed");
        assertEquals(updatedTypesDef.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size(), "EntityDef update failed");
        // Try another update round by name and GUID
        for (AtlasEnumDef enumDef : updatedTypesDef.getEnumDefs()) {
            AtlasEnumDef updated = typeDefStore.updateEnumDefByGuid(enumDef.getGuid(), enumDef);
            assertNotNull(updated);
        }
        for (AtlasEnumDef enumDef : atlasTypesDef.getEnumDefs()) {
            AtlasEnumDef updated = typeDefStore.updateEnumDefByName(enumDef.getName(), enumDef);
            assertNotNull(updated);
        }
        // Try another update round by name and GUID
        for (AtlasClassificationDef classificationDef : updatedTypesDef.getClassificationDefs()) {
            AtlasClassificationDef updated = typeDefStore.updateClassificationDefByGuid(classificationDef.getGuid(), classificationDef);
            assertNotNull(updated);
        }
        for (AtlasClassificationDef classificationDef : atlasTypesDef.getClassificationDefs()) {
            AtlasClassificationDef updated = typeDefStore.updateClassificationDefByName(classificationDef.getName(), classificationDef);
            assertNotNull(updated);
        }
        // Try another update round by name and GUID
        for (AtlasStructDef structDef : updatedTypesDef.getStructDefs()) {
            AtlasStructDef updated = typeDefStore.updateStructDefByGuid(structDef.getGuid(), structDef);
            assertNotNull(updated);
        }
        for (AtlasStructDef structDef : atlasTypesDef.getStructDefs()) {
            AtlasStructDef updated = typeDefStore.updateStructDefByName(structDef.getName(), structDef);
            assertNotNull(updated);
        }
        // Try another update round by name and GUID
        for (AtlasEntityDef entityDef : updatedTypesDef.getEntityDefs()) {
            AtlasEntityDef updated = typeDefStore.updateEntityDefByGuid(entityDef.getGuid(), entityDef);
            assertNotNull(updated);
        }
        for (AtlasEntityDef entityDef : atlasTypesDef.getEntityDefs()) {
            AtlasEntityDef updated = typeDefStore.updateEntityDefByName(entityDef.getName(), entityDef);
            assertNotNull(updated);
        }
    } catch (AtlasBaseException e) {
        fail("TypeDef updates should've succeeded");
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 52 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef 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 53 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class TypeAttributeDifferenceTest method different_ReturnsDifference.

@Test
public void different_ReturnsDifference() throws Exception {
    AtlasEntityDef existing = getAtlasEntityDefWithAttributes("name");
    AtlasEntityDef incoming = getAtlasEntityDefWithAttributes("name", "qualifiedName");
    List<AtlasStructDef.AtlasAttributeDef> expectedAttributes = getAtlasAttributeDefs("qualifiedName");
    List<AtlasStructDef.AtlasAttributeDef> actualAttributes = invokeGetAttributesAbsentInExisting(existing, incoming);
    Assert.assertEquals(actualAttributes, expectedAttributes);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) Test(org.testng.annotations.Test)

Example 54 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class TypeAttributeDifferenceTest method entityDefWithNoAttributes.

@Test
public void entityDefWithNoAttributes() throws Exception {
    AtlasEntityDef existing = new AtlasEntityDef();
    AtlasEntityDef incoming = new AtlasEntityDef();
    List<AtlasStructDef.AtlasAttributeDef> expectedAttributes = new ArrayList<>();
    List<AtlasStructDef.AtlasAttributeDef> actualAttributes = invokeGetAttributesAbsentInExisting(existing, incoming);
    Assert.assertEquals(actualAttributes, expectedAttributes);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 55 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class TestRelationshipUtilsV2 method getDepartmentEmployeeTypes.

public static AtlasTypesDef getDepartmentEmployeeTypes() throws AtlasBaseException {
    /**
     ***** Person Type ******
     */
    AtlasEntityDef personType = createClassTypeDef(PERSON_TYPE, description(PERSON_TYPE), superType(null), createUniqueRequiredAttrDef("name", "string"), createOptionalAttrDef("address", ADDRESS_TYPE), createOptionalAttrDef("birthday", "date"), createOptionalAttrDef("hasPets", "boolean"), createOptionalAttrDef("numberOfCars", "byte"), createOptionalAttrDef("houseNumber", "short"), createOptionalAttrDef("carMileage", "int"), createOptionalAttrDef("age", "float"), createOptionalAttrDef("numberOfStarsEstimate", "biginteger"), createOptionalAttrDef("approximationOfPi", "bigdecimal"));
    /**
     ***** Employee Type ******
     */
    AtlasEntityDef employeeType = createClassTypeDef(EMPLOYEE_TYPE, description(EMPLOYEE_TYPE), superType(PERSON_TYPE), createOptionalAttrDef("orgLevel", ORG_LEVEL_TYPE), createOptionalAttrDef("shares", "long"), createOptionalAttrDef("salary", "double"));
    /**
     ***** Department Type ******
     */
    AtlasEntityDef departmentType = createClassTypeDef(DEPARTMENT_TYPE, description(DEPARTMENT_TYPE), superType(null), createUniqueRequiredAttrDef("name", "string"));
    /**
     ***** Manager Type ******
     */
    AtlasEntityDef managerType = createClassTypeDef(MANAGER_TYPE, description(MANAGER_TYPE), superType(EMPLOYEE_TYPE));
    /**
     ***** Address Type ******
     */
    AtlasStructDef addressType = createStructTypeDef(ADDRESS_TYPE, description(ADDRESS_TYPE), createRequiredAttrDef("street", "string"), createRequiredAttrDef("city", "string"));
    /**
     ***** Organization Level Type ******
     */
    AtlasEnumDef orgLevelType = new AtlasEnumDef(ORG_LEVEL_TYPE, description(ORG_LEVEL_TYPE), DEFAULT_VERSION, getOrgLevelElements());
    /**
     ***** Security Clearance Type ******
     */
    AtlasClassificationDef securityClearanceType = createTraitTypeDef(SECURITY_CLEARANCE_TYPE, description(SECURITY_CLEARANCE_TYPE), superType(null), createRequiredAttrDef("level", "int"));
    /**
     ***** [Department -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeDepartmentType = new AtlasRelationshipDef(EMPLOYEE_DEPARTMENT_TYPE, description(EMPLOYEE_DEPARTMENT_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "department", SINGLE), new AtlasRelationshipEndDef(DEPARTMENT_TYPE, "employees", SET, true));
    /**
     ***** [Manager -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeManagerType = new AtlasRelationshipDef(EMPLOYEE_MANAGER_TYPE, description(EMPLOYEE_MANAGER_TYPE), DEFAULT_VERSION, AGGREGATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "manager", SINGLE), new AtlasRelationshipEndDef(MANAGER_TYPE, "subordinates", SET, true));
    /**
     ***** [Mentor -> Employee] Relationship ******
     */
    AtlasRelationshipDef employeeMentorType = new AtlasRelationshipDef(EMPLOYEE_MENTOR_TYPE, description(EMPLOYEE_MENTOR_TYPE), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentor", SINGLE), new AtlasRelationshipEndDef(EMPLOYEE_TYPE, "mentees", SET));
    return new AtlasTypesDef(ImmutableList.of(orgLevelType), ImmutableList.of(addressType), ImmutableList.of(securityClearanceType), ImmutableList.of(personType, employeeType, departmentType, managerType), ImmutableList.of(employeeDepartmentType, employeeManagerType, employeeMentorType));
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)141 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)55 Test (org.testng.annotations.Test)51 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)40 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)37 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)35 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)31 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)31 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)30 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)21 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)14 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)13 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)13 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)13 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)9 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)8