Search in sources :

Example 26 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasRelationshipDefStoreV1 method updateVertexPreCreate.

private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException {
    AtlasRelationshipEndDef end1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef end2 = relationshipDef.getEndDef2();
    // check whether the names added on the relationship Ends are reserved if required.
    final boolean allowReservedKeywords;
    try {
        allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true);
    } catch (AtlasException e) {
        throw new AtlasBaseException(e);
    }
    if (!allowReservedKeywords) {
        if (QueryParser.isKeyword(end1.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END1_NAME_INVALID, end1.getName());
        }
        if (QueryParser.isKeyword(end2.getName())) {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END2_NAME_INVALID, end2.getName());
        }
    }
    AtlasStructDefStoreV1.updateVertexPreCreate(relationshipDef, relationshipType, vertex, typeDefStore);
    // Update ends
    setVertexPropertiesFromRelationshipDef(relationshipDef, vertex);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasException(org.apache.atlas.AtlasException) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 27 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class AtlasEntityChangeNotifier method doFullTextMapping.

private void doFullTextMapping(List<AtlasEntityHeader> atlasEntityHeaders) {
    if (CollectionUtils.isEmpty(atlasEntityHeaders)) {
        return;
    }
    try {
        if (!AtlasRepositoryConfiguration.isFullTextSearchEnabled()) {
            return;
        }
    } catch (AtlasException e) {
        LOG.warn("Unable to determine if FullText is disabled. Proceeding with FullText mapping");
    }
    for (AtlasEntityHeader atlasEntityHeader : atlasEntityHeaders) {
        String guid = atlasEntityHeader.getGuid();
        AtlasVertex atlasVertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (atlasVertex == null) {
            continue;
        }
        try {
            String fullText = fullTextMapperV2.getIndexTextForEntity(guid);
            GraphHelper.setProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText);
        } catch (AtlasBaseException e) {
            LOG.error("FullText mapping failed for Vertex[ guid = {} ]", guid, e);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasException(org.apache.atlas.AtlasException)

Example 28 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class DefaultMetadataServiceTest method testTypeUpdateFailureShouldRollBack.

@Test
public void testTypeUpdateFailureShouldRollBack() throws AtlasException, JSONException {
    String typeName = "test_type_" + RandomStringUtils.randomAlphanumeric(10);
    HierarchicalTypeDefinition<ClassType> typeDef = TypesUtil.createClassTypeDef(typeName, ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE));
    TypesDef typesDef = new TypesDef(typeDef, false);
    JSONObject type = metadataService.createType(TypesSerialization.toJson(typesDef));
    Assert.assertNotNull(type.get(AtlasClient.TYPES));
    HierarchicalTypeDefinition<ClassType> updatedTypeDef = TypesUtil.createClassTypeDef(typeName, ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("test_type_attribute", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("test_type_invalid_attribute$", DataTypes.STRING_TYPE));
    TypesDef updatedTypesDef = new TypesDef(updatedTypeDef, false);
    try {
        metadataService.updateType(TypesSerialization.toJson(updatedTypesDef));
        fail("Expected AtlasException");
    } catch (AtlasException e) {
    // expected
    }
    // type definition should reflect old type
    String typeDefinition = metadataService.getTypeDefinition(typeName);
    typesDef = TypesSerialization.fromJson(typeDefinition);
    assertEquals(typesDef.classTypes().head().attributeDefinitions.length, 1);
}
Also used : TypesDef(org.apache.atlas.typesystem.TypesDef) JSONObject(org.codehaus.jettison.json.JSONObject) ClassType(org.apache.atlas.typesystem.types.ClassType) AtlasException(org.apache.atlas.AtlasException) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 29 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructInstance method setBigDecimal.

public void setBigDecimal(String attrName, BigDecimal val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.BIGDECIMAL_TYPE) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.BIGDECIMAL_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = val == null;
    bigDecimals[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Example 30 with AtlasException

use of org.apache.atlas.AtlasException in project incubator-atlas by apache.

the class StructInstance method setNull.

public void setNull(String attrName) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = true;
    explicitSets[nullPos] = true;
    int pos = fieldMapping.fieldPos.get(attrName);
    if (i.dataType() == DataTypes.BIGINTEGER_TYPE) {
        bigIntegers[pos] = null;
    } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) {
        bigDecimals[pos] = null;
    } else if (i.dataType() == DataTypes.DATE_TYPE) {
        dates[pos] = null;
    } else if (i.dataType() == DataTypes.INT_TYPE) {
        ints[pos] = 0;
    } else if (i.dataType() == DataTypes.BOOLEAN_TYPE) {
        bools[pos] = false;
    } else if (i.dataType() == DataTypes.STRING_TYPE) {
        strings[pos] = null;
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) {
        arrays[pos] = null;
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) {
        maps[pos] = null;
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.STRUCT || i.dataType().getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
        structs[pos] = null;
    } else if (i.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) {
        ids[pos] = null;
        referenceables[pos] = null;
    } else {
        throw new AtlasException(String.format("Unknown datatype %s", i.dataType()));
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) AtlasException(org.apache.atlas.AtlasException)

Aggregations

AtlasException (org.apache.atlas.AtlasException)139 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)36 IOException (java.io.IOException)27 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)26 Configuration (org.apache.commons.configuration.Configuration)19 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)14 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)13 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)13 ArrayList (java.util.ArrayList)12 RepositoryException (org.apache.atlas.repository.RepositoryException)12 JSONObject (org.codehaus.jettison.json.JSONObject)12 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)10 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)9 HashMap (java.util.HashMap)8 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)8 Properties (java.util.Properties)7 File (java.io.File)6 InputStream (java.io.InputStream)6 EntityChangeListener (org.apache.atlas.listener.EntityChangeListener)6