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);
}
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);
}
}
}
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);
}
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;
}
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()));
}
}
Aggregations