use of org.apache.atlas.catalog.exception.CatalogRuntimeException in project incubator-atlas by apache.
the class DefaultTypeSystem method deleteEntity.
@Override
public void deleteEntity(ResourceDefinition definition, Request request) throws ResourceNotFoundException {
String typeName = definition.getTypeName();
String cleanIdPropName = definition.getIdPropertyName();
String idValue = request.getProperty(cleanIdPropName);
try {
// transaction handled by atlas repository
metadataService.deleteEntityByUniqueAttribute(typeName, cleanIdPropName, idValue);
} catch (EntityNotFoundException e) {
throw new ResourceNotFoundException(String.format("The specified entity doesn't exist: type=%s, %s=%s", typeName, cleanIdPropName, idValue));
} catch (AtlasException e) {
throw new CatalogRuntimeException(String.format("An unexpected error occurred while attempting to delete entity: type=%s, %s=%s : %s", typeName, cleanIdPropName, idValue, e), e);
}
}
use of org.apache.atlas.catalog.exception.CatalogRuntimeException in project incubator-atlas by apache.
the class DefaultTypeSystem method createTraitInstance.
@Override
public void createTraitInstance(String guid, String typeName, Map<String, Object> properties) throws ResourceAlreadyExistsException {
try {
// not using the constructor with properties argument because it is marked 'InterfaceAudience.Private'
Struct struct = new Struct(typeName);
for (Map.Entry<String, Object> propEntry : properties.entrySet()) {
struct.set(propEntry.getKey(), propEntry.getValue());
}
//add Taxonomy Namespace
struct.set(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, TaxonomyResourceProvider.TAXONOMY_NS);
metadataService.addTrait(guid, metadataService.createTraitInstance(struct));
} catch (IllegalArgumentException e) {
//todo: unfortunately, IllegalArgumentException can be thrown for other reasons
if (e.getMessage().contains("is already defined for entity")) {
throw new ResourceAlreadyExistsException(String.format("Tag '%s' already associated with the entity", typeName));
} else {
throw e;
}
} catch (AtlasException e) {
throw new CatalogRuntimeException(String.format("Unable to create trait instance '%s' in type system: %s", typeName, e), e);
}
}
use of org.apache.atlas.catalog.exception.CatalogRuntimeException in project incubator-atlas by apache.
the class DefaultTypeSystem method createType.
private <T extends HierarchicalType> void createType(Collection<AttributeDefinition> attributes, Class<T> type, String name, String description, boolean isTrait) throws ResourceAlreadyExistsException {
try {
List<AtlasStructDef.AtlasAttributeDef> attrDefs = new ArrayList<>();
for (AttributeDefinition attrDefinition : attributes) {
attrDefs.add(TypeConverterUtil.toAtlasAttributeDef(attrDefinition));
}
if (isTrait) {
AtlasClassificationDef classificationDef = new AtlasClassificationDef(name, description, "1.0", attrDefs, ImmutableSet.of(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE));
AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.of(classificationDef), ImmutableList.<AtlasEntityDef>of());
typeDefStore.createTypesDef(typesDef);
} else {
AtlasEntityDef entityDef = new AtlasEntityDef(name, description, "1.0", attrDefs);
AtlasTypesDef typesDef = new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.of(entityDef));
typeDefStore.createTypesDef(typesDef);
}
} catch (AtlasBaseException e) {
if (e.getAtlasErrorCode() == AtlasErrorCode.TYPE_ALREADY_EXISTS) {
throw new ResourceAlreadyExistsException(String.format("Type '%s' already exists", name));
} else {
throw new CatalogRuntimeException(String.format("Unable to create type '%s' in type system: %s", name, e), e);
}
}
}
use of org.apache.atlas.catalog.exception.CatalogRuntimeException in project incubator-atlas by apache.
the class JsonSerializer method serialize.
public String serialize(Result result, UriInfo ui) {
Writer json = new StringWriter();
JsonWriter writer = new JsonWriter(json);
writer.setIndent(" ");
try {
writeValue(writer, result.getPropertyMaps(), ui.getBaseUri().toASCIIString());
} catch (IOException e) {
throw new CatalogRuntimeException("Unable to write JSON response.", e);
}
return json.toString();
}
use of org.apache.atlas.catalog.exception.CatalogRuntimeException in project incubator-atlas by apache.
the class DefaultTypeSystem method createEntity.
@Override
public String createEntity(ResourceDefinition definition, Request request) throws ResourceAlreadyExistsException {
String typeName = definition.getTypeName();
try {
createClassType(definition, typeName, typeName + " Definition");
} catch (ResourceAlreadyExistsException e) {
// ok if type already exists
}
try {
Referenceable entity = new Referenceable(typeName, request.getQueryProperties());
//add Taxonomy Namespace
entity.set(TaxonomyResourceProvider.NAMESPACE_ATTRIBUTE_NAME, TaxonomyResourceProvider.TAXONOMY_NS);
ITypedReferenceableInstance typedInstance = metadataService.getTypedReferenceableInstance(entity);
ITypedReferenceableInstance[] entitiesToCreate = Collections.singletonList(typedInstance).toArray(new ITypedReferenceableInstance[1]);
final List<String> entities = metadataService.createEntities(entitiesToCreate).getCreatedEntities();
return entities != null && entities.size() > 0 ? entities.get(0) : null;
} catch (EntityExistsException e) {
throw new ResourceAlreadyExistsException("Attempted to create an entity which already exists: " + request.getQueryProperties());
} catch (AtlasException e) {
throw new CatalogRuntimeException("An expected exception occurred creating an entity: " + e, e);
}
}
Aggregations