use of org.apache.ranger.entity.XXService in project ranger by apache.
the class TagDBStore method createResourceForServiceResource.
private void createResourceForServiceResource(Long resourceId, RangerServiceResource serviceResource) {
String serviceName = serviceResource.getServiceName();
XXService xService = daoManager.getXXService().findByName(serviceName);
if (xService == null) {
throw errorUtil.createRESTException("No Service found with name: " + serviceName, MessageEnums.ERROR_CREATING_OBJECT);
}
XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById(xService.getType());
if (xServiceDef == null) {
throw errorUtil.createRESTException("No Service-Def found with ID: " + xService.getType(), MessageEnums.ERROR_CREATING_OBJECT);
}
Map<String, RangerPolicy.RangerPolicyResource> resElements = serviceResource.getResourceElements();
for (Map.Entry<String, RangerPolicyResource> resElement : resElements.entrySet()) {
XXResourceDef xResDef = daoManager.getXXResourceDef().findByNameAndServiceDefId(resElement.getKey(), xServiceDef.getId());
if (xResDef == null) {
LOG.error("TagDBStore.createResource: ResourceType is not valid [" + resElement.getKey() + "]");
throw errorUtil.createRESTException("Resource Type is not valid [" + resElement.getKey() + "]", MessageEnums.DATA_NOT_FOUND);
}
RangerPolicyResource policyRes = resElement.getValue();
XXServiceResourceElement resourceElement = new XXServiceResourceElement();
resourceElement.setIsExcludes(policyRes.getIsExcludes());
resourceElement.setIsRecursive(policyRes.getIsRecursive());
resourceElement.setResDefId(xResDef.getId());
resourceElement.setResourceId(resourceId);
resourceElement = rangerAuditFields.populateAuditFieldsForCreate(resourceElement);
resourceElement = daoManager.getXXServiceResourceElement().create(resourceElement);
int sortOrder = 1;
for (String resVal : policyRes.getValues()) {
XXServiceResourceElementValue resourceElementValue = new XXServiceResourceElementValue();
resourceElementValue.setResElementId(resourceElement.getId());
resourceElementValue.setValue(resVal);
resourceElementValue.setSortOrder(sortOrder);
resourceElementValue = rangerAuditFields.populateAuditFieldsForCreate(resourceElementValue);
resourceElementValue = daoManager.getXXServiceResourceElementValue().create(resourceElementValue);
sortOrder++;
}
}
}
use of org.apache.ranger.entity.XXService in project ranger by apache.
the class TagDBStore method getServiceResourceByServiceAndResourceSignature.
@Override
public RangerServiceResource getServiceResourceByServiceAndResourceSignature(String serviceName, String resourceSignature) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TagDBStore.getServiceResourceByServiceAndResourceSignature(" + serviceName + ", " + resourceSignature + ")");
}
RangerServiceResource ret = null;
XXService service = daoManager.getXXService().findByName(serviceName);
if (service != null) {
ret = rangerServiceResourceService.getByServiceAndResourceSignature(service.getId(), resourceSignature);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== TagDBStore.getServiceResourceByServiceAndResourceSignature(" + serviceName + ", " + resourceSignature + "): " + ret);
}
return ret;
}
use of org.apache.ranger.entity.XXService in project ranger by apache.
the class TagDBStore method getServiceTags.
@Override
public ServiceTags getServiceTags(String serviceName) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TagDBStore.getServiceTags(" + serviceName + ")");
}
ServiceTags ret = null;
XXService xxService = daoManager.getXXService().findByName(serviceName);
if (xxService == null) {
throw new Exception("service does not exist. name=" + serviceName);
}
XXServiceVersionInfo serviceVersionInfoDbObj = daoManager.getXXServiceVersionInfo().findByServiceName(serviceName);
if (serviceVersionInfoDbObj == null) {
LOG.warn("serviceVersionInfo does not exist for service [" + serviceName + "]");
}
RangerServiceDef serviceDef = svcStore.getServiceDef(xxService.getType());
if (serviceDef == null) {
throw new Exception("service-def does not exist. id=" + xxService.getType());
}
RangerTagDBRetriever tagDBRetriever = new RangerTagDBRetriever(daoManager, xxService);
Map<Long, RangerTagDef> tagDefMap = tagDBRetriever.getTagDefs();
Map<Long, RangerTag> tagMap = tagDBRetriever.getTags();
List<RangerServiceResource> resources = tagDBRetriever.getServiceResources();
List<RangerTagResourceMap> tagResourceMaps = tagDBRetriever.getTagResourceMaps();
Map<Long, List<Long>> resourceToTagIds = new HashMap<Long, List<Long>>();
if (CollectionUtils.isNotEmpty(tagResourceMaps)) {
Long resourceId = null;
List<Long> tagIds = null;
for (RangerTagResourceMap tagResourceMap : tagResourceMaps) {
if (!tagResourceMap.getResourceId().equals(resourceId)) {
if (resourceId != null) {
resourceToTagIds.put(resourceId, tagIds);
}
resourceId = tagResourceMap.getResourceId();
tagIds = new ArrayList<Long>();
}
tagIds.add(tagResourceMap.getTagId());
}
if (resourceId != null) {
resourceToTagIds.put(resourceId, tagIds);
}
}
ret = new ServiceTags();
ret.setServiceName(xxService.getName());
ret.setTagVersion(serviceVersionInfoDbObj == null ? null : serviceVersionInfoDbObj.getTagVersion());
ret.setTagUpdateTime(serviceVersionInfoDbObj == null ? null : serviceVersionInfoDbObj.getTagUpdateTime());
ret.setTagDefinitions(tagDefMap);
ret.setTags(tagMap);
ret.setServiceResources(resources);
ret.setResourceToTagIds(resourceToTagIds);
if (LOG.isDebugEnabled()) {
LOG.debug("<== TagDBStore.getServiceTags(" + serviceName + ")");
}
return ret;
}
use of org.apache.ranger.entity.XXService in project ranger by apache.
the class TestRangerPolicyService method xService.
private XXService xService() {
XXService xService = new XXService();
xService.setAddedByUserId(Id);
xService.setCreateTime(new Date());
xService.setDescription("Hdfs service");
xService.setGuid("serviceguid");
xService.setId(Id);
xService.setIsEnabled(true);
xService.setName("Hdfs");
xService.setPolicyUpdateTime(new Date());
xService.setPolicyVersion(1L);
xService.setType(1L);
xService.setUpdatedByUserId(Id);
xService.setUpdateTime(new Date());
return xService;
}
use of org.apache.ranger.entity.XXService in project ranger by apache.
the class TestRangerPolicyServiceBase method test3mapEntityToViewBean.
@Test
public void test3mapEntityToViewBean() {
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
XXService xService = Mockito.mock(XXService.class);
RangerPolicy rangerPolicy = rangerPolicy();
XXPolicy policy = policy();
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.getById(policy.getService())).thenReturn(xService);
RangerPolicy dbRangerPolicy = policyService.mapEntityToViewBean(rangerPolicy, policy);
Assert.assertNotNull(dbRangerPolicy);
Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId());
Assert.assertEquals(dbRangerPolicy.getGuid(), rangerPolicy.getGuid());
Assert.assertEquals(dbRangerPolicy.getName(), rangerPolicy.getName());
Assert.assertEquals(dbRangerPolicy.getIsEnabled(), rangerPolicy.getIsEnabled());
Assert.assertEquals(dbRangerPolicy.getVersion(), rangerPolicy.getVersion());
Assert.assertEquals(dbRangerPolicy.getDescription(), rangerPolicy.getDescription());
Mockito.verify(daoManager).getXXService();
}
Aggregations