Java Code Examples for org.apache.atlas.exception.AtlasBaseException#getMessage()

The following examples show how to use org.apache.atlas.exception.AtlasBaseException#getMessage() . 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: TestAtlasTypeRegistry.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testEntityDefInvalidHierarchy_Self() {
    AtlasEntityDef entDef1 = new AtlasEntityDef("entDef-1");

    entDef1.addSuperType(entDef1.getName());

    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addType(entDef1);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNotNull(failureMsg, "expected invalid supertype failure");
}
 
Example 2
Source File: TestAtlasTypeRegistry.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testClassificationDefInvalidHierarchy_Self() {
    AtlasClassificationDef classifiDef1 = new AtlasClassificationDef("classifiDef-1");

    classifiDef1.addSuperType(classifiDef1.getName());

    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addType(classifiDef1);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNotNull(failureMsg, "expected invalid supertype failure");
}
 
Example 3
Source File: AtlasTypeDefGraphStore.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void tryUpdateByName(String name, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    try {
        ttr.updateTypeByName(name, typeDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 4
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidConstraints() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    String                     failureMsg   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDef());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        AtlasEntityType typeTable  = ttr.getEntityTypeByName(TYPE_TABLE);
        AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN);

        assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef());
        assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName());
        assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef());
        assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS);
        assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS));

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN);
}
 
Example 5
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void tryUpdateByGUID(String guid, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    try {
        ttr.updateTypeByGuid(guid, typeDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 6
Source File: AtlasTypeDefGraphStore.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships{})",
                CollectionUtils.size(typesDef.getEnumDefs()),
                CollectionUtils.size(typesDef.getStructDefs()),
                CollectionUtils.size(typesDef.getClassificationDefs()),
                CollectionUtils.size(typesDef.getEntityDefs()),
                CollectionUtils.size(typesDef.getRelationshipDefs()));
    }

    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();

    // Translate any NOT FOUND errors to BAD REQUEST
    try {
        ttr.updateTypes(typesDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }

    AtlasTypesDef ret = updateGraphStore(typesDef, ttr);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})",
                CollectionUtils.size(typesDef.getEnumDefs()),
                CollectionUtils.size(typesDef.getStructDefs()),
                CollectionUtils.size(typesDef.getClassificationDefs()),
                CollectionUtils.size(typesDef.getEntityDefs()),
                CollectionUtils.size(typesDef.getRelationshipDefs()));
    }

    return ret;

}
 
Example 7
Source File: TestAtlasTypeRegistry.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testNestedUpdates() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;
    AtlasClassificationDef     testTag1     = new AtlasClassificationDef("testTag1");
    AtlasClassificationDef     testTag2     = new AtlasClassificationDef("testTag2");

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addType(testTag1);

        // changes should not be seen in typeRegistry until lock is released
        assertFalse(typeRegistry.isRegisteredType(testTag1.getName()),
                    "type added should be seen in typeRegistry only after commit");

        boolean isNestedUpdateSuccess = addType(typeRegistry, testTag2);

        assertTrue(isNestedUpdateSuccess);

        // changes made in nested commit, inside addType(), should not be seen in typeRegistry until lock is released here
        assertFalse(typeRegistry.isRegisteredType(testTag2.getName()),
                    "type added within nested commit should be seen in typeRegistry only after outer commit");

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);
    assertTrue(typeRegistry.isRegisteredType(testTag1.getName()));
    assertTrue(typeRegistry.isRegisteredType(testTag2.getName()));
}
 
Example 8
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testReorderDynAttributes() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    String                     failureMsg   = null;

    entityDefs.add(createTableEntityDefForTopSort());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);
        //options are read in the table,
        AtlasEntityType typeTable  = ttr.getEntityTypeByName(TYPE_TABLE);

        // Expect attributes in this order: ATTR_DESCRIPTION, ATTR_OWNER, ATTR_NAME, ATTR_LOCATION
        assertEquals(typeTable.getDynEvalAttributes().get(0).getName(), ATTR_DESCRIPTION);
        assertEquals(typeTable.getDynEvalAttributes().get(1).getName(), ATTR_OWNER);
        assertEquals(typeTable.getDynEvalAttributes().get(2).getName(), ATTR_NAME);
        assertEquals(typeTable.getDynEvalAttributes().get(3).getName(), ATTR_LOCATION);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN);
}
 
Example 9
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testDynAttributeFlags() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    String                     failureMsg   = null;

    entityDefs.add(createTableEntityDefWithOptions());
    entityDefs.add(createColumnEntityDef());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);
        //options are read in the table,
        AtlasEntityType typeTable  = ttr.getEntityTypeByName(TYPE_TABLE);
        AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN);

        assertTrue(typeTable.getAttribute(ATTR_NAME).getIsDynAttributeEvalTrigger());
        assertFalse(typeTable.getAttribute(ATTR_NAME).getIsDynAttribute());
        assertFalse(typeTable.getAttribute(ATTR_OWNER).getIsDynAttributeEvalTrigger());
        assertTrue(typeTable.getAttribute(ATTR_OWNER).getIsDynAttribute());

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN);
}
 
Example 10
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidConstraints() {
    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    List<AtlasEntityDef>       entityDefs   = new ArrayList<>();
    String                     failureMsg   = null;

    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDef());

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(entityDefs);

        AtlasEntityType typeTable  = ttr.getEntityTypeByName(TYPE_TABLE);
        AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN);

        assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef());
        assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName());
        assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef());
        assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS);
        assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS));

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN);
}
 
Example 11
Source File: AtlasClassificationType.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void addValidationMessageIfNotPresent(AtlasBaseException excp, List<String> messages) {
    String msg = excp.getMessage();

    if (messages != null && !messages.contains(msg)) {
        messages.add(msg);
    }
}
 
Example 12
Source File: AtlasTypeDefGraphStore.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void tryTypeCreation(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    // Translate any NOT FOUND errors to BAD REQUEST
    try {
        ttr.addTypes(typesDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_NAME_NOT_FOUND == e.getAtlasErrorCode() ||
                AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 13
Source File: AtlasTypeDefGraphStore.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void tryUpdateByGUID(String guid, AtlasBaseTypeDef typeDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    try {
        ttr.updateTypeByGuid(guid, typeDef);
    } catch (AtlasBaseException e) {
        if (AtlasErrorCode.TYPE_GUID_NOT_FOUND == e.getAtlasErrorCode()) {
            throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, e.getMessage());
        } else {
            throw e;
        }
    }
}
 
Example 14
Source File: TestAtlasTypeRegistry.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testClassificationDefValidHierarchy() throws AtlasBaseException {
    AtlasClassificationDef classifiL0   = new AtlasClassificationDef("L0");
    AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1");
    AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2");
    AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1");
    AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2");
    AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3");
    AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4");

    classifiL1_1.addSuperType(classifiL0.getName());
    classifiL1_2.addSuperType(classifiL0.getName());
    classifiL2_1.addSuperType(classifiL1_1.getName());
    classifiL2_2.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_2.getName());
    classifiL2_4.addSuperType(classifiL1_2.getName());

    classifiL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));

    AtlasTypesDef typesDef = new AtlasTypesDef();

    typesDef.getClassificationDefs().add(classifiL0);
    typesDef.getClassificationDefs().add(classifiL1_1);
    typesDef.getClassificationDefs().add(classifiL1_2);
    typesDef.getClassificationDefs().add(classifiL2_1);
    typesDef.getClassificationDefs().add(classifiL2_2);
    typesDef.getClassificationDefs().add(classifiL2_3);
    typesDef.getClassificationDefs().add(classifiL2_4);

    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(typesDef);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);


    validateAllSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateAllSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
    validateAllSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
    validateAllSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateAllSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateAllSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
    validateAllSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));

    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2")));
    validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
    validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());

    validateAllSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
    validateAllSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
    validateAllSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
    validateAllSubTypes(typeRegistry, "L2-1", new HashSet<String>());
    validateAllSubTypes(typeRegistry, "L2-2", new HashSet<String>());
    validateAllSubTypes(typeRegistry, "L2-3", new HashSet<String>());
    validateAllSubTypes(typeRegistry, "L2-4", new HashSet<String>());

    validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
    validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
    validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
    validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
    validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
    validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
    validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
 
Example 15
Source File: TestAtlasTypeRegistry.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testClassificationDefInvalidHierarchy_CircularRef() throws AtlasBaseException {
    AtlasClassificationDef classifiL0   = new AtlasClassificationDef("L0");
    AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1");
    AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2");
    AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1");
    AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2");
    AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3");
    AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4");

    classifiL1_1.addSuperType(classifiL0.getName());
    classifiL1_2.addSuperType(classifiL0.getName());
    classifiL2_1.addSuperType(classifiL1_1.getName());
    classifiL2_2.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_2.getName());
    classifiL2_4.addSuperType(classifiL1_2.getName());
    classifiL0.addSuperType(classifiL2_3.getName()); // circular-ref

    AtlasTypesDef typesDef = new AtlasTypesDef();

    typesDef.getClassificationDefs().add(classifiL0);
    typesDef.getClassificationDefs().add(classifiL1_1);
    typesDef.getClassificationDefs().add(classifiL1_2);
    typesDef.getClassificationDefs().add(classifiL2_1);
    typesDef.getClassificationDefs().add(classifiL2_2);
    typesDef.getClassificationDefs().add(classifiL2_3);
    typesDef.getClassificationDefs().add(classifiL2_4);

    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(typesDef);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNotNull(failureMsg, "expected invalid supertype failure");
}
 
Example 16
Source File: TestAtlasTypeRegistry.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testEntityDefInvalidHierarchy_CircularRef() throws AtlasBaseException {
    AtlasEntityDef entL0   = new AtlasEntityDef("L0");
    AtlasEntityDef entL1_1 = new AtlasEntityDef("L1-1");
    AtlasEntityDef entL1_2 = new AtlasEntityDef("L1-2");
    AtlasEntityDef entL2_1 = new AtlasEntityDef("L2-1");
    AtlasEntityDef entL2_2 = new AtlasEntityDef("L2-2");
    AtlasEntityDef entL2_3 = new AtlasEntityDef("L2-3");
    AtlasEntityDef entL2_4 = new AtlasEntityDef("L2-4");

    entL1_1.addSuperType(entL0.getName());
    entL1_2.addSuperType(entL0.getName());
    entL2_1.addSuperType(entL1_1.getName());
    entL2_2.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_2.getName());
    entL2_4.addSuperType(entL1_2.getName());
    entL0.addSuperType(entL2_3.getName()); // circular-ref

    AtlasTypesDef typesDef = new AtlasTypesDef();

    typesDef.getEntityDefs().add(entL0);
    typesDef.getEntityDefs().add(entL1_1);
    typesDef.getEntityDefs().add(entL1_2);
    typesDef.getEntityDefs().add(entL2_1);
    typesDef.getEntityDefs().add(entL2_2);
    typesDef.getEntityDefs().add(entL2_3);
    typesDef.getEntityDefs().add(entL2_4);

    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(typesDef);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNotNull(failureMsg, "expected invalid supertype failure");
}
 
Example 17
Source File: Servlets.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static Response getErrorResponse(AtlasBaseException e) {
    String message = e.getMessage() == null ? "Failed with " + e.getClass().getName() : e.getMessage();
    Response response = getErrorResponse(message, e.getAtlasErrorCode().getHttpCode());

    return response;
}
 
Example 18
Source File: TestAtlasTypeRegistry.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testEntityDefValidHierarchy() {
    AtlasEntityDef entL0   = new AtlasEntityDef("L0");
    AtlasEntityDef entL1_1 = new AtlasEntityDef("L1-1");
    AtlasEntityDef entL1_2 = new AtlasEntityDef("L1-2");
    AtlasEntityDef entL2_1 = new AtlasEntityDef("L2-1");
    AtlasEntityDef entL2_2 = new AtlasEntityDef("L2-2");
    AtlasEntityDef entL2_3 = new AtlasEntityDef("L2-3");
    AtlasEntityDef entL2_4 = new AtlasEntityDef("L2-4");

    entL1_1.addSuperType(entL0.getName());
    entL1_2.addSuperType(entL0.getName());
    entL2_1.addSuperType(entL1_1.getName());
    entL2_2.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_2.getName());
    entL2_4.addSuperType(entL1_2.getName());

    entL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    entL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));

    AtlasTypesDef typesDef = new AtlasTypesDef();

    typesDef.getEntityDefs().add(entL0);
    typesDef.getEntityDefs().add(entL1_1);
    typesDef.getEntityDefs().add(entL1_2);
    typesDef.getEntityDefs().add(entL2_1);
    typesDef.getEntityDefs().add(entL2_2);
    typesDef.getEntityDefs().add(entL2_3);
    typesDef.getEntityDefs().add(entL2_4);

    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(typesDef);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);

    validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
    validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));

    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
    validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());

    validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
    validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
    validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
    validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
    validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
    validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
    validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
 
Example 19
Source File: TestAtlasTypeRegistry.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testClassificationDefValidHierarchy() {
    AtlasClassificationDef classifiL0   = new AtlasClassificationDef("L0");
    AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1");
    AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2");
    AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1");
    AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2");
    AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3");
    AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4");

    classifiL1_1.addSuperType(classifiL0.getName());
    classifiL1_2.addSuperType(classifiL0.getName());
    classifiL2_1.addSuperType(classifiL1_1.getName());
    classifiL2_2.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_1.getName());
    classifiL2_3.addSuperType(classifiL1_2.getName());
    classifiL2_4.addSuperType(classifiL1_2.getName());

    classifiL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));

    AtlasTypesDef typesDef = new AtlasTypesDef();

    typesDef.getClassificationDefs().add(classifiL0);
    typesDef.getClassificationDefs().add(classifiL1_1);
    typesDef.getClassificationDefs().add(classifiL1_2);
    typesDef.getClassificationDefs().add(classifiL2_1);
    typesDef.getClassificationDefs().add(classifiL2_2);
    typesDef.getClassificationDefs().add(classifiL2_3);
    typesDef.getClassificationDefs().add(classifiL2_4);

    AtlasTypeRegistry          typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr          = null;
    boolean                    commit       = false;
    String                     failureMsg   = null;

    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();

        ttr.addTypes(typesDef);

        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);


    validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
    validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));

    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
    validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());

    validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
    validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
    validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
    validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
    validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
    validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
    validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
 
Example 20
Source File: Servlets.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static Response getErrorResponse(AtlasBaseException e) {
    String message = e.getMessage() == null ? "Failed with " + e.getClass().getName() : e.getMessage();
    Response response = getErrorResponse(message, e.getAtlasErrorCode().getHttpCode());

    return response;
}