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()");
}
}
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 + ")");
}
}
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;
}
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;
}
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;
}
Aggregations