Search in sources :

Example 26 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class ServiceTagsProcessor method delete.

private void delete(ServiceTags serviceTags) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceTagsProcessor.delete()");
    }
    // We dont expect any resourceId->tagId mappings in delete operation, so ignoring them if specified
    List<RangerServiceResource> serviceResources = serviceTags.getServiceResources();
    if (CollectionUtils.isNotEmpty(serviceResources)) {
        for (RangerServiceResource serviceResource : serviceResources) {
            RangerServiceResource objToDelete = null;
            try {
                if (StringUtils.isNotBlank(serviceResource.getGuid())) {
                    objToDelete = tagStore.getServiceResourceByGuid(serviceResource.getGuid());
                }
                if (objToDelete == null) {
                    if (MapUtils.isNotEmpty(serviceResource.getResourceElements())) {
                        RangerServiceResourceSignature serializer = new RangerServiceResourceSignature(serviceResource);
                        String serviceResourceSignature = serializer.getSignature();
                        objToDelete = tagStore.getServiceResourceByServiceAndResourceSignature(serviceResource.getServiceName(), serviceResourceSignature);
                    }
                }
                if (objToDelete != null) {
                    List<RangerTagResourceMap> tagResourceMaps = tagStore.getTagResourceMapsForResourceGuid(objToDelete.getGuid());
                    if (CollectionUtils.isNotEmpty(tagResourceMaps)) {
                        for (RangerTagResourceMap tagResourceMap : tagResourceMaps) {
                            tagStore.deleteTagResourceMap(tagResourceMap.getId());
                        }
                    }
                    tagStore.deleteServiceResource(objToDelete.getId());
                }
            } catch (Exception exception) {
                LOG.error("deleteServiceResourceByGuid failed, guid=" + serviceResource.getGuid(), exception);
                throw exception;
            }
        }
    }
    Map<Long, RangerTag> tagsMap = serviceTags.getTags();
    if (MapUtils.isNotEmpty(tagsMap)) {
        for (Map.Entry<Long, RangerTag> entry : tagsMap.entrySet()) {
            RangerTag tag = entry.getValue();
            try {
                RangerTag objToDelete = tagStore.getTagByGuid(tag.getGuid());
                if (objToDelete != null) {
                    tagStore.deleteTag(objToDelete.getId());
                }
            } catch (Exception exception) {
                LOG.error("deleteTag failed, guid=" + tag.getGuid(), exception);
                throw exception;
            }
        }
    }
    Map<Long, RangerTagDef> tagDefsMap = serviceTags.getTagDefinitions();
    if (MapUtils.isNotEmpty(tagDefsMap)) {
        for (Map.Entry<Long, RangerTagDef> entry : tagDefsMap.entrySet()) {
            RangerTagDef tagDef = entry.getValue();
            try {
                RangerTagDef objToDelete = tagStore.getTagDefByGuid(tagDef.getGuid());
                if (objToDelete != null) {
                    tagStore.deleteTagDef(objToDelete.getId());
                }
            } catch (Exception exception) {
                LOG.error("deleteTagDef failed, guid=" + tagDef.getGuid(), exception);
                throw exception;
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceTagsProcessor.delete()");
    }
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) RangerServiceResourceSignature(org.apache.ranger.plugin.store.RangerServiceResourceSignature) RangerTag(org.apache.ranger.plugin.model.RangerTag) RangerTagResourceMap(org.apache.ranger.plugin.model.RangerTagResourceMap) RangerTagResourceMap(org.apache.ranger.plugin.model.RangerTagResourceMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class TagREST method deleteServiceResourceByGuid.

@DELETE
@Path(TagRESTConstants.RESOURCE_RESOURCE + "guid/{guid}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("hasRole('ROLE_SYS_ADMIN')")
public void deleteServiceResourceByGuid(@PathParam("guid") String guid, @DefaultValue("false") @QueryParam("deleteReferences") boolean deleteReferences) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TagREST.deleteServiceResourceByGuid(" + guid + ", " + deleteReferences + ")");
    }
    try {
        RangerServiceResource exist = validator.preDeleteServiceResourceByGuid(guid, deleteReferences);
        if (deleteReferences) {
            List<RangerTagResourceMap> tagResourceMaps = tagStore.getTagResourceMapsForResourceGuid(exist.getGuid());
            if (CollectionUtils.isNotEmpty(tagResourceMaps)) {
                for (RangerTagResourceMap tagResourceMap : tagResourceMaps) {
                    deleteTagResourceMap(tagResourceMap.getId());
                }
            }
        }
        tagStore.deleteServiceResource(exist.getId());
    } catch (Exception excp) {
        LOG.error("deleteServiceResourceByGuid(" + guid + ", " + deleteReferences + ") failed", excp);
        throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagREST.deleteServiceResourceByGuid(" + guid + ", " + deleteReferences + ")");
    }
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) RangerTagResourceMap(org.apache.ranger.plugin.model.RangerTagResourceMap) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 28 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class TagREST method updateServiceResource.

@PUT
@Path(TagRESTConstants.RESOURCE_RESOURCE + "{id}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("hasRole('ROLE_SYS_ADMIN')")
public RangerServiceResource updateServiceResource(@PathParam("id") Long id, RangerServiceResource resource) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> TagREST.updateServiceResource(" + id + ")");
    }
    RangerServiceResource ret;
    try {
        validator.preUpdateServiceResource(id, resource);
        ret = tagStore.updateServiceResource(resource);
    } catch (Exception excp) {
        LOG.error("updateServiceResource(" + resource + ") failed", excp);
        throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagREST.updateServiceResource(" + id + "): " + ret);
    }
    return ret;
}
Also used : RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) PUT(javax.ws.rs.PUT)

Example 29 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class RangerServiceResourceService method getByServiceId.

public List<RangerServiceResource> getByServiceId(Long serviceId) {
    List<RangerServiceResource> ret = new ArrayList<RangerServiceResource>();
    List<XXServiceResource> xxServiceResources = daoMgr.getXXServiceResource().findByServiceId(serviceId);
    if (CollectionUtils.isNotEmpty(xxServiceResources)) {
        for (XXServiceResource xxServiceResource : xxServiceResources) {
            RangerServiceResource serviceResource = populateViewBean(xxServiceResource);
            ret.add(serviceResource);
        }
    }
    return ret;
}
Also used : XXServiceResource(org.apache.ranger.entity.XXServiceResource) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ArrayList(java.util.ArrayList)

Example 30 with RangerServiceResource

use of org.apache.ranger.plugin.model.RangerServiceResource in project ranger by apache.

the class RangerServiceResourceService method getServiceResourceByGuid.

public RangerServiceResource getServiceResourceByGuid(String guid) {
    RangerServiceResource ret = null;
    XXServiceResource xxServiceResource = daoMgr.getXXServiceResource().findByGuid(guid);
    if (xxServiceResource != null) {
        ret = populateViewBean(xxServiceResource);
    }
    return ret;
}
Also used : XXServiceResource(org.apache.ranger.entity.XXServiceResource) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource)

Aggregations

RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)65 Test (org.junit.Test)42 HashMap (java.util.HashMap)37 RangerAtlasEntity (org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity)30 WebApplicationException (javax.ws.rs.WebApplicationException)17 ExpectedException (org.junit.rules.ExpectedException)14 ArrayList (java.util.ArrayList)10 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)7 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)5 Predicate (org.apache.commons.collections.Predicate)4 XXServiceResource (org.apache.ranger.entity.XXServiceResource)4 RangerTag (org.apache.ranger.plugin.model.RangerTag)4 Map (java.util.Map)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 PUT (javax.ws.rs.PUT)2 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2