Search in sources :

Example 6 with XXService

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++;
        }
    }
}
Also used : XXServiceResourceElementValue(org.apache.ranger.entity.XXServiceResourceElementValue) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicyResource(org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource) XXService(org.apache.ranger.entity.XXService) HashMap(java.util.HashMap) XXTagResourceMap(org.apache.ranger.entity.XXTagResourceMap) Map(java.util.Map) XXResourceDef(org.apache.ranger.entity.XXResourceDef) XXServiceResourceElement(org.apache.ranger.entity.XXServiceResourceElement)

Example 7 with XXService

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;
}
Also used : XXService(org.apache.ranger.entity.XXService)

Example 8 with XXService

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;
}
Also used : HashMap(java.util.HashMap) RangerServiceNotFoundException(org.apache.ranger.plugin.util.RangerServiceNotFoundException) ServiceTags(org.apache.ranger.plugin.util.ServiceTags) ArrayList(java.util.ArrayList) List(java.util.List) PList(org.apache.ranger.plugin.store.PList) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo)

Example 9 with XXService

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;
}
Also used : XXService(org.apache.ranger.entity.XXService) Date(java.util.Date)

Example 10 with XXService

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();
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) XXPolicy(org.apache.ranger.entity.XXPolicy) Test(org.junit.Test)

Aggregations

XXService (org.apache.ranger.entity.XXService)73 XXServiceDef (org.apache.ranger.entity.XXServiceDef)34 RangerService (org.apache.ranger.plugin.model.RangerService)23 Test (org.junit.Test)21 XXServiceDao (org.apache.ranger.db.XXServiceDao)19 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)19 VXString (org.apache.ranger.view.VXString)19 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)17 ArrayList (java.util.ArrayList)14 XXServiceVersionInfo (org.apache.ranger.entity.XXServiceVersionInfo)14 Date (java.util.Date)13 WebApplicationException (javax.ws.rs.WebApplicationException)11 IOException (java.io.IOException)9 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)9 XXServiceVersionInfoDao (org.apache.ranger.db.XXServiceVersionInfoDao)7 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)7 UnknownHostException (java.net.UnknownHostException)6 XXServiceConfigMap (org.apache.ranger.entity.XXServiceConfigMap)6 JSONException (org.codehaus.jettison.json.JSONException)6 HashMap (java.util.HashMap)5