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