Search in sources :

Example 11 with AtlasException

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));
    }
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasException(org.apache.atlas.AtlasException) AtlasEntityStream(org.apache.atlas.repository.store.graph.v1.AtlasEntityStream) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) Id(org.apache.atlas.v1.model.instance.Id)

Example 12 with AtlasException

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 13 with AtlasException

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()");
        }
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 14 with AtlasException

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);
}
Also used : AtlasException(org.apache.atlas.AtlasException) File(java.io.File) URL(java.net.URL) DelegationTokenAuthenticatedURL(org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) AtlasException(org.apache.atlas.AtlasException)

Example 15 with AtlasException

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;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AtlasException(org.apache.atlas.AtlasException) 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