Exemplo n.º 1
0
  public RangerTagResourceMap preCreateTagResourceMap(String tagGuid, String resourceGuid)
      throws Exception {
    if (StringUtils.isBlank(resourceGuid) || StringUtils.isBlank(tagGuid)) {
      throw new Exception("Both resourceGuid and resourceId need to be non-empty");
    }

    RangerTagResourceMap existing =
        tagStore.getTagResourceMapForTagAndResourceGuid(tagGuid, resourceGuid);

    if (existing != null) {
      throw new Exception(
          "Attempt to create existing association between resourceId="
              + resourceGuid
              + " and tagId="
              + tagGuid);
    }

    RangerServiceResource existingServiceResource = tagStore.getServiceResourceByGuid(resourceGuid);

    if (existingServiceResource == null) {
      throw new Exception("No resource found for guid=" + resourceGuid);
    }

    RangerTag existingTag = tagStore.getTagByGuid(tagGuid);

    if (existingTag == null) {
      throw new Exception("No tag found for guid=" + tagGuid);
    }

    RangerTagResourceMap newTagResourceMap = new RangerTagResourceMap();
    newTagResourceMap.setResourceId(existingServiceResource.getId());
    newTagResourceMap.setTagId(existingTag.getId());

    return newTagResourceMap;
  }
Exemplo n.º 2
0
  public RangerTag preCreateTag(final RangerTag tag) throws Exception {
    if (StringUtils.isBlank(tag.getType())) {
      throw new Exception("Tag has no type");
    }

    RangerTag ret = null;

    String guid = tag.getGuid();
    if (!StringUtils.isBlank(guid)) {
      ret = tagStore.getTagByGuid(guid);
    }

    return ret;
  }
Exemplo n.º 3
0
  public RangerTag preDeleteTagByGuid(String guid) throws Exception {
    RangerTag exiting = tagStore.getTagByGuid(guid);

    if (exiting == null) {
      throw new Exception("Attempt to delete nonexistent tag, guid=" + guid);
    }

    List<RangerTagResourceMap> associations = tagStore.getTagResourceMapsForTagId(exiting.getId());
    if (CollectionUtils.isNotEmpty(associations)) {
      throw new Exception(
          "Attempt to delete tag which is associated with a service-resource, guid=" + guid);
    }
    return exiting;
  }
Exemplo n.º 4
0
  public RangerTag preDeleteTag(Long id) throws Exception {
    if (id == null) {
      throw new Exception("Invalid/null id");
    }

    RangerTag existing = tagStore.getTag(id);

    if (existing == null) {
      throw new Exception("Attempt to delete nonexistent tag, id=" + id);
    }

    List<RangerTagResourceMap> associations = tagStore.getTagResourceMapsForTagId(existing.getId());
    if (CollectionUtils.isNotEmpty(associations)) {
      throw new Exception(
          "Attempt to delete tag which is associated with a service-resource, id=" + id);
    }
    return existing;
  }
Exemplo n.º 5
0
  public void preUpdateTagByGuid(String guid, final RangerTag tag) throws Exception {
    if (StringUtils.isBlank(tag.getType())) {
      throw new Exception("Tag has no type");
    }

    RangerTag existing = tagStore.getTagByGuid(guid);
    if (existing == null) {
      throw new Exception("Attempt to update nonexistent tag, guid=" + guid);
    }

    tag.setId(existing.getId());
    tag.setGuid(existing.getGuid());
  }
Exemplo n.º 6
0
  public void preUpdateTag(final Long id, final RangerTag tag) throws Exception {
    if (StringUtils.isBlank(tag.getType())) {
      throw new Exception("Tag has no type");
    }

    if (id == null) {
      throw new Exception("Invalid/null id");
    }

    RangerTag existing = tagStore.getTag(id);

    if (existing == null) {
      throw new Exception("Attempt to update nonexistant tag, id=" + id);
    }

    tag.setId(existing.getId());
    tag.setGuid(existing.getGuid());
  }