Search in sources :

Example 1 with RangerTag

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

the class AtlasNotificationMapper method buildServiceTags.

private static ServiceTags buildServiceTags(RangerAtlasEntityWithTags entityWithTags, Map<String, ServiceTags> serviceTagsMap) {
    ServiceTags ret = null;
    RangerAtlasEntity entity = entityWithTags.getEntity();
    RangerServiceResource serviceResource = AtlasResourceMapperUtil.getRangerServiceResource(entity);
    if (serviceResource != null) {
        List<RangerTag> tags = getTags(entityWithTags);
        List<RangerTagDef> tagDefs = getTagDefs(entityWithTags);
        String serviceName = serviceResource.getServiceName();
        ret = createOrGetServiceTags(serviceTagsMap, serviceName);
        if (serviceTagsMap == null || CollectionUtils.isNotEmpty(tags)) {
            serviceResource.setId((long) ret.getServiceResources().size());
            ret.getServiceResources().add(serviceResource);
            List<Long> tagIds = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(tags)) {
                for (RangerTag tag : tags) {
                    tag.setId((long) ret.getTags().size());
                    ret.getTags().put(tag.getId(), tag);
                    tagIds.add(tag.getId());
                }
            }
            ret.getResourceToTagIds().put(serviceResource.getId(), tagIds);
            if (CollectionUtils.isNotEmpty(tagDefs)) {
                for (RangerTagDef tagDef : tagDefs) {
                    tagDef.setId((long) ret.getTagDefinitions().size());
                    ret.getTagDefinitions().put(tagDef.getId(), tagDef);
                }
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Entity " + entityWithTags + " does not have any tags associated with it when full-sync is being done.");
                LOG.debug("Will not add this entity to serviceTags, so that this entity, if exists,  will be removed from ranger");
            }
        }
    } else {
        LOG.error("Failed to build serviceResource for entity:" + entity.getGuid());
    }
    return ret;
}
Also used : RangerTagDef(org.apache.ranger.plugin.model.RangerTagDef) RangerAtlasEntity(org.apache.ranger.tagsync.source.atlasrest.RangerAtlasEntity) RangerServiceResource(org.apache.ranger.plugin.model.RangerServiceResource) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList)

Example 2 with RangerTag

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

the class AtlasNotificationMapper method getTags.

private static List<RangerTag> getTags(RangerAtlasEntityWithTags entityWithTags) {
    List<RangerTag> ret = new ArrayList<>();
    if (entityWithTags != null && CollectionUtils.isNotEmpty(entityWithTags.getTags())) {
        List<EntityNotificationWrapper.RangerAtlasClassification> tags = entityWithTags.getTags();
        for (EntityNotificationWrapper.RangerAtlasClassification tag : tags) {
            RangerTag rangerTag = new RangerTag(null, tag.getName(), tag.getAttributes(), RangerTag.OWNER_SERVICERESOURCE);
            List<RangerValiditySchedule> validityPeriods = tag.getValidityPeriods();
            if (CollectionUtils.isNotEmpty(validityPeriods)) {
                rangerTag.setValidityPeriods(validityPeriods);
            }
            ret.add(rangerTag);
        }
    }
    return ret;
}
Also used : RangerValiditySchedule(org.apache.ranger.plugin.model.RangerValiditySchedule) RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList)

Example 3 with RangerTag

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

the class TestTagREST method test21deleteTag.

@Test
public void test21deleteTag() {
    RangerTag oldTag = new RangerTag();
    oldTag.setId(id);
    try {
        Mockito.when(validator.preDeleteTag(id)).thenReturn(oldTag);
    } catch (Exception e) {
    }
    try {
        Mockito.doNothing().when(tagStore).deleteTag(id);
    } catch (Exception e) {
    }
    tagREST.deleteTag(id);
    Assert.assertNotNull(oldTag.getId());
    try {
        Mockito.verify(validator).preDeleteTag(id);
    } catch (Exception e) {
    }
    try {
        Mockito.verify(tagStore).deleteTag(id);
    } catch (Exception e) {
    }
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 4 with RangerTag

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

the class TestTagREST method test19createTag.

@Test
public void test19createTag() {
    RangerTag oldTag = new RangerTag();
    oldTag.setId(id);
    try {
        Mockito.when(validator.preCreateTag(oldTag)).thenReturn(oldTag);
    } catch (Exception e) {
    }
    Mockito.when(restErrorUtil.createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean())).thenThrow(new WebApplicationException());
    thrown.expect(WebApplicationException.class);
    tagREST.createTag(oldTag, false);
    try {
        Mockito.verify(validator).preCreateTag(oldTag);
    } catch (Exception e) {
    }
    Mockito.verify(restErrorUtil).createRESTException(Mockito.anyInt(), Mockito.anyString(), Mockito.anyBoolean());
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerTag(org.apache.ranger.plugin.model.RangerTag) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 5 with RangerTag

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

the class TestTagREST method test25getTagsByType.

@Test
public void test25getTagsByType() {
    String type = "file";
    List<RangerTag> tag = new ArrayList<RangerTag>();
    RangerTag rTag = new RangerTag();
    rTag.setType(type);
    tag.add(rTag);
    try {
        Mockito.when(tagStore.getTagsByType(type)).thenReturn(tag);
    } catch (Exception e) {
    }
    List<RangerTag> rangerTag = tagREST.getTagsByType(type);
    Assert.assertEquals(rangerTag.get(0).getType(), tag.get(0).getType());
    try {
        Mockito.verify(tagStore).getTagsByType(type);
    } catch (Exception e) {
    }
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList) ExpectedException(org.junit.rules.ExpectedException) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Aggregations

RangerTag (org.apache.ranger.plugin.model.RangerTag)30 WebApplicationException (javax.ws.rs.WebApplicationException)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 ExpectedException (org.junit.rules.ExpectedException)10 XXTag (org.apache.ranger.entity.XXTag)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)4 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)4 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Predicate (org.apache.commons.collections.Predicate)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 HashSet (java.util.HashSet)2 List (java.util.List)2 PUT (javax.ws.rs.PUT)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)2