use of org.apache.atlas.AtlasException in project atlas by apache.
the class EntityResource method partialUpdateEntityByGuid.
private Response partialUpdateEntityByGuid(String guid, HttpServletRequest request) {
String entityJson = null;
try {
guid = ParamChecker.notEmpty(guid, "Guid property cannot be null");
entityJson = Servlets.getRequestPayload(request);
if (LOG.isDebugEnabled()) {
LOG.debug("partially updating entity for guid {} : {} ", guid, entityJson);
}
Referenceable updatedEntity = AtlasType.fromV1Json(entityJson, Referenceable.class);
// update referenceable with Id if not specified in payload
Id updateId = updatedEntity.getId();
if (updateId != null && !AtlasTypeUtil.isAssignedGuid(updateId.getId())) {
updatedEntity.setId(new Id(guid, 0, updatedEntity.getTypeName()));
}
AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntity(updatedEntity);
EntityMutationResponse mutationResponse = entitiesStore.createOrUpdate(new AtlasEntityStream(entitiesInfo), true);
CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
if (LOG.isDebugEnabled()) {
LOG.debug("Updated entities: {}", result.getEntityResult());
}
String response = getResponse(result);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
throw toWebApplicationException(e);
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to update entity by GUID {} {}", guid, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to update entity by GUID {} {} ", guid, entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
}
use of org.apache.atlas.AtlasException in project atlas by apache.
the class EntityResource method deleteEntities.
/**
* Delete entities from the repository identified by their guids (including their composite references)
* or
* Deletes a single entity identified by its type and unique attribute value from the repository (including their composite references)
*
* @param guids list of deletion candidate guids
* or
* @param entityType the entity type
* @param attribute the unique attribute used to identify the entity
* @param value the unique attribute value used to identify the entity
* @return response payload as json - including guids of entities(including composite references from that entity) that were deleted
*/
@DELETE
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response deleteEntities(@QueryParam("guid") List<String> guids, @QueryParam("type") String entityType, @QueryParam("property") final String attribute, @QueryParam("value") final String value) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> EntityResource.deleteEntities({}, {}, {}, {})", guids, entityType, attribute, value);
}
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.deleteEntities(" + guids + ", " + entityType + ", " + attribute + ", " + value + ")");
}
EntityResult entityResult;
if (guids != null && !guids.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting entities {}", guids);
}
EntityMutationResponse mutationResponse = entityREST.deleteByGuids(guids);
entityResult = restAdapters.toCreateUpdateEntitiesResult(mutationResponse).getEntityResult();
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting entity type={} with property {}={}", entityType, attribute, value);
}
Map<String, Object> attributes = new HashMap<>();
attributes.put(attribute, value);
EntityMutationResponse mutationResponse = entitiesStore.deleteByUniqueAttributes(getEntityType(entityType), attributes);
entityResult = restAdapters.toCreateUpdateEntitiesResult(mutationResponse).getEntityResult();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Deleted entity result: {}", entityResult);
}
String response = getResponse(entityResult);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw toWebApplicationException(e);
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to delete entities {} {} {} {} ", guids, entityType, attribute, value, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== EntityResource.deleteEntities({}, {}, {}, {})", guids, entityType, attribute, value);
}
}
}
use of org.apache.atlas.AtlasException in project atlas by apache.
the class EntityResource method updateEntities.
/**
* Complete update of a set of entities - the values not specified will be replaced with null/removed
* Adds/Updates given entities identified by its GUID or unique attribute
* @return response payload as json
*/
@PUT
@Consumes({ Servlets.JSON_MEDIA_TYPE, MediaType.APPLICATION_JSON })
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response updateEntities(@Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> EntityResource.updateEntities()");
}
String entityJson = null;
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityResource.updateEntities()");
}
entityJson = Servlets.getRequestPayload(request);
// Handle backward compatibility - if entities is not JSONArray, convert to JSONArray
String[] jsonStrings;
try {
ArrayNode jsonEntities = AtlasJson.parseToV1ArrayNode(entityJson);
jsonStrings = new String[jsonEntities.size()];
for (int i = 0; i < jsonEntities.size(); i++) {
jsonStrings[i] = AtlasJson.toV1Json(jsonEntities.get(i));
}
} catch (IOException e) {
jsonStrings = new String[1];
jsonStrings[0] = entityJson;
}
if (LOG.isDebugEnabled()) {
LOG.debug("Updating entities: count={}; entities-json={}", jsonStrings.length, entityJson);
}
AtlasEntitiesWithExtInfo entitiesInfo = restAdapters.toAtlasEntities(jsonStrings);
EntityMutationResponse mutationResponse = entityREST.createOrUpdate(entitiesInfo);
CreateUpdateEntitiesResult result = restAdapters.toCreateUpdateEntitiesResult(mutationResponse);
if (LOG.isDebugEnabled()) {
LOG.debug("Updated entities: {}", result.getEntityResult());
}
String response = getResponse(result);
return Response.ok(response).build();
} catch (AtlasBaseException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw toWebApplicationException(e);
} catch (AtlasException | IllegalArgumentException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (WebApplicationException e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw e;
} catch (Throwable e) {
LOG.error("Unable to persist entity instance entityDef={}", entityJson, e);
throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
} finally {
AtlasPerfTracer.log(perf);
if (LOG.isDebugEnabled()) {
LOG.debug("<== EntityResource.updateEntities()");
}
}
}
use of org.apache.atlas.AtlasException in project atlas by apache.
the class SecureClientUtils method getSSLClientFile.
private static File getSSLClientFile() throws AtlasException {
String confLocation = System.getProperty("atlas.conf");
File sslDir;
try {
if (confLocation == null) {
String persistDir = null;
URL resource = SecureClientUtils.class.getResource("/");
if (resource != null) {
persistDir = resource.toURI().getPath();
}
assert persistDir != null;
sslDir = new File(persistDir);
} else {
sslDir = new File(confLocation);
}
LOG.info("ssl-client.xml will be created in {}", sslDir);
} catch (Exception e) {
throw new AtlasException("Failed to find client configuration directory", e);
}
return new File(sslDir, SecurityProperties.SSL_CLIENT_PROPERTIES);
}
use of org.apache.atlas.AtlasException in project atlas by apache.
the class AtlasAuthorizerFactory method getAtlasAuthorizer.
public static AtlasAuthorizer getAtlasAuthorizer() throws AtlasAuthorizationException {
AtlasAuthorizer ret = INSTANCE;
if (ret == null) {
synchronized (AtlasAuthorizerFactory.class) {
if (INSTANCE == null) {
Configuration configuration = null;
try {
configuration = ApplicationProperties.get();
} catch (AtlasException e) {
LOG.error("Exception while fetching configuration", e);
}
String authorizerClass = configuration != null ? configuration.getString("atlas.authorizer.impl") : "SIMPLE";
if (StringUtils.isNotEmpty(authorizerClass)) {
if (StringUtils.equalsIgnoreCase(authorizerClass, "SIMPLE")) {
authorizerClass = SIMPLE_AUTHORIZER;
} else if (StringUtils.equalsIgnoreCase(authorizerClass, "RANGER")) {
authorizerClass = RANGER_AUTHORIZER;
} else if (StringUtils.equalsIgnoreCase(authorizerClass, "NONE")) {
authorizerClass = NONE_AUTHORIZER;
}
} else {
authorizerClass = SIMPLE_AUTHORIZER;
}
LOG.info("Initializing Authorizer {}", authorizerClass);
try {
Class authorizerMetaObject = Class.forName(authorizerClass);
if (authorizerMetaObject != null) {
INSTANCE = (AtlasAuthorizer) authorizerMetaObject.newInstance();
INSTANCE.init();
}
} catch (Exception e) {
LOG.error("Error while creating authorizer of type {}", authorizerClass, e);
throw new AtlasAuthorizationException("Error while creating authorizer of type '" + authorizerClass + "'", e);
}
}
ret = INSTANCE;
}
}
return ret;
}
Aggregations