use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class GraphSandboxUtil method create.
public static void create(String sandboxName) {
Configuration configuration;
try {
configuration = ApplicationProperties.get();
String newStorageDir = System.getProperty("atlas.data") + File.separatorChar + "storage" + File.separatorChar + sandboxName;
configuration.setProperty("atlas.graph.storage.directory", newStorageDir);
String newIndexerDir = System.getProperty("atlas.data") + File.separatorChar + "index" + File.separatorChar + sandboxName;
configuration.setProperty("atlas.graph.index.search.directory", newIndexerDir);
LOG.debug("New Storage dir : {}", newStorageDir);
LOG.debug("New Indexer dir : {}", newIndexerDir);
} catch (AtlasException ignored) {
}
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class DefaultGraphPersistenceStrategy method constructInstance.
@Override
public <U> U constructInstance(IDataType<U> dataType, Object value) {
try {
switch(dataType.getTypeCategory()) {
case PRIMITIVE:
case ENUM:
return dataType.convert(value, Multiplicity.OPTIONAL);
case ARRAY:
DataTypes.ArrayType arrType = (DataTypes.ArrayType) dataType;
IDataType<?> elemType = arrType.getElemType();
ImmutableCollection.Builder result = ImmutableList.builder();
List list = (List) value;
for (Object listElement : list) {
Object collectionEntry = constructCollectionEntry(elemType, listElement);
if (collectionEntry != null) {
result.add(collectionEntry);
}
}
return (U) result.build();
case MAP:
// todo
break;
case STRUCT:
AtlasVertex structVertex = (AtlasVertex) value;
StructType structType = (StructType) dataType;
ITypedStruct structInstance = structType.createInstance();
TypeSystem.IdType idType = TypeSystem.getInstance().getIdType();
if (dataType.getName().equals(idType.getName())) {
structInstance.set(idType.typeNameAttrName(), GraphHelper.getSingleValuedProperty(structVertex, typeAttributeName(), String.class));
structInstance.set(idType.idAttrName(), GraphHelper.getSingleValuedProperty(structVertex, idAttributeName(), String.class));
String stateValue = GraphHelper.getSingleValuedProperty(structVertex, stateAttributeName(), String.class);
if (stateValue != null) {
structInstance.set(idType.stateAttrName(), stateValue);
}
structInstance.set(idType.versionAttrName(), structVertex.getProperty(versionAttributeName(), Integer.class));
} else {
metadataRepository.getGraphToInstanceMapper().mapVertexToInstance(structVertex, structInstance, structType.fieldMapping().fields);
}
return dataType.convert(structInstance, Multiplicity.OPTIONAL);
case TRAIT:
AtlasVertex traitVertex = (AtlasVertex) value;
TraitType traitType = (TraitType) dataType;
ITypedStruct traitInstance = traitType.createInstance();
// todo - this is not right, we should load the Instance associated with this
// trait. for now just loading the trait struct.
// metadataRepository.getGraphToInstanceMapper().mapVertexToTraitInstance(
// traitVertex, dataType.getName(), , traitType, traitInstance);
metadataRepository.getGraphToInstanceMapper().mapVertexToInstance(traitVertex, traitInstance, traitType.fieldMapping().fields);
break;
case CLASS:
AtlasVertex classVertex = (AtlasVertex) value;
String guid = classVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
// Check if the instance we need was previously loaded.
ITypedReferenceableInstance classInstance = RequestContext.get().getInstanceV1(guid);
if (classInstance == null) {
classInstance = metadataRepository.getGraphToInstanceMapper().mapGraphToTypedInstance(guid, classVertex);
}
return dataType.convert(classInstance, Multiplicity.OPTIONAL);
default:
throw new UnsupportedOperationException("Load for type " + dataType + "is not supported");
}
} catch (AtlasException e) {
LOG.error("error while constructing an instance", e);
}
return null;
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class EntityGraphMapper method mapMapValue.
private Map<String, Object> mapMapValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> mapMapValue({})", ctx);
}
@SuppressWarnings("unchecked") Map<Object, Object> newVal = (Map<Object, Object>) ctx.getValue();
Map<String, Object> newMap = new HashMap<>();
AtlasMapType mapType = (AtlasMapType) ctx.getAttrType();
try {
AtlasAttribute attribute = ctx.getAttribute();
List<String> currentKeys = GraphHelper.getListProperty(ctx.getReferringVertex(), ctx.getVertexProperty());
Map<String, Object> currentMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(currentKeys)) {
for (String key : currentKeys) {
String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), GraphHelper.encodePropertyKey(key));
Object propertyValueForKey = getMapValueProperty(mapType.getValueType(), ctx.getReferringVertex(), propertyNameForKey);
currentMap.put(key, propertyValueForKey);
}
}
if (MapUtils.isNotEmpty(newVal)) {
boolean isReference = AtlasGraphUtilsV1.isReference(mapType.getValueType());
AtlasAttribute inverseRefAttribute = attribute.getInverseRefAttribute();
for (Map.Entry<Object, Object> entry : newVal.entrySet()) {
String key = entry.getKey().toString();
String propertyName = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), GraphHelper.encodePropertyKey(key));
AtlasEdge existingEdge = getEdgeIfExists(mapType, currentMap, key);
AttributeMutationContext mapCtx = new AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), attribute, entry.getValue(), propertyName, mapType.getValueType(), existingEdge);
//Add/Update/Remove property value
Object newEntry = mapCollectionElementsToVertex(mapCtx, context);
setMapValueProperty(mapType.getValueType(), ctx.getReferringVertex(), propertyName, newEntry);
newMap.put(key, newEntry);
// update the inverse reference value.
if (isReference && newEntry instanceof AtlasEdge && inverseRefAttribute != null) {
AtlasEdge newEdge = (AtlasEdge) newEntry;
addInverseReference(mapCtx, inverseRefAttribute, newEdge);
}
}
}
Map<String, Object> finalMap = removeUnusedMapEntries(attribute, ctx.getReferringVertex(), ctx.getVertexProperty(), currentMap, newMap);
for (Object newEntry : newMap.values()) {
updateInConsistentOwnedMapVertices(ctx, mapType, newEntry);
}
Set<String> newKeys = new LinkedHashSet<>(newMap.keySet());
newKeys.addAll(finalMap.keySet());
// for dereference on way out
GraphHelper.setListProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), new ArrayList<>(newKeys));
} catch (AtlasException e) {
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== mapMapValue({})", ctx);
}
return newMap;
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class UserDao method loadFileLoginsDetails.
void loadFileLoginsDetails() {
InputStream inStr = null;
try {
Configuration configuration = ApplicationProperties.get();
inStr = ApplicationProperties.getFileAsInputStream(configuration, "atlas.authentication.method.file.filename", DEFAULT_USER_CREDENTIALS_PROPERTIES);
userLogins = new Properties();
userLogins.load(inStr);
} catch (IOException | AtlasException e) {
LOG.error("Error while reading user.properties file", e);
throw new RuntimeException(e);
} finally {
if (inStr != null) {
try {
inStr.close();
} catch (Exception excp) {
// ignore
}
}
}
}
use of org.apache.atlas.AtlasException in project incubator-atlas by apache.
the class BaseResourceDefinition method registerProperty.
protected void registerProperty(AttributeDefinition propertyDefinition) {
try {
propertyDefs.put(propertyDefinition.name, propertyDefinition);
properties.put(propertyDefinition.name, new AttributeInfo(typeSystem, propertyDefinition, null));
} catch (AtlasException e) {
throw new CatalogRuntimeException("Unable to create attribute: " + propertyDefinition.name, e);
}
}
Aggregations