Search in sources :

Example 31 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class ServiceDBStore method updateServiceDef.

@Override
public RangerServiceDef updateServiceDef(RangerServiceDef serviceDef) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> ServiceDBStore.updateServiceDef(" + serviceDef + ")");
    }
    Long serviceDefId = serviceDef.getId();
    XXServiceDef existing = daoMgr.getXXServiceDef().getById(serviceDefId);
    if (existing == null) {
        throw restErrorUtil.createRESTException("no service-def exists with ID=" + serviceDef.getId(), MessageEnums.DATA_NOT_FOUND);
    }
    String existingName = existing.getName();
    boolean renamed = !StringUtils.equalsIgnoreCase(serviceDef.getName(), existingName);
    if (renamed) {
        XXServiceDef renamedSVCDef = daoMgr.getXXServiceDef().findByName(serviceDef.getName());
        if (renamedSVCDef != null) {
            throw restErrorUtil.createRESTException("another service-def already exists with name '" + serviceDef.getName() + "'. ID=" + renamedSVCDef.getId(), MessageEnums.DATA_NOT_UPDATABLE);
        }
    }
    List<RangerServiceConfigDef> configs = serviceDef.getConfigs() != null ? serviceDef.getConfigs() : new ArrayList<RangerServiceConfigDef>();
    List<RangerResourceDef> resources = serviceDef.getResources() != null ? serviceDef.getResources() : new ArrayList<RangerResourceDef>();
    List<RangerAccessTypeDef> accessTypes = serviceDef.getAccessTypes() != null ? serviceDef.getAccessTypes() : new ArrayList<RangerAccessTypeDef>();
    List<RangerPolicyConditionDef> policyConditions = serviceDef.getPolicyConditions() != null ? serviceDef.getPolicyConditions() : new ArrayList<RangerPolicyConditionDef>();
    List<RangerContextEnricherDef> contextEnrichers = serviceDef.getContextEnrichers() != null ? serviceDef.getContextEnrichers() : new ArrayList<RangerContextEnricherDef>();
    List<RangerEnumDef> enums = serviceDef.getEnums() != null ? serviceDef.getEnums() : new ArrayList<RangerEnumDef>();
    RangerDataMaskDef dataMaskDef = serviceDef.getDataMaskDef();
    RangerRowFilterDef rowFilterDef = serviceDef.getRowFilterDef();
    RangerServiceDefHelper defHelper = new RangerServiceDefHelper(serviceDef, false);
    defHelper.patchServiceDefWithDefaultValues();
    serviceDef.setCreateTime(existing.getCreateTime());
    serviceDef.setGuid(existing.getGuid());
    serviceDef.setVersion(existing.getVersion());
    serviceDef = serviceDefService.update(serviceDef);
    XXServiceDef createdSvcDef = daoMgr.getXXServiceDef().getById(serviceDefId);
    updateChildObjectsOfServiceDef(createdSvcDef, configs, resources, accessTypes, policyConditions, contextEnrichers, enums, dataMaskDef, rowFilterDef);
    RangerServiceDef updatedSvcDef = getServiceDef(serviceDefId);
    dataHistService.createObjectDataHistory(updatedSvcDef, RangerDataHistService.ACTION_UPDATE);
    postUpdate(updatedSvcDef);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== ServiceDBStore.updateServiceDef(" + serviceDef + "): " + serviceDef);
    }
    return updatedSvcDef;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerDataMaskDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskDef) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) VXString(org.apache.ranger.view.VXString) RangerPolicyConditionDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef) RangerRowFilterDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerRowFilterDef) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef) RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerContextEnricherDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef) RangerServiceDefHelper(org.apache.ranger.plugin.model.validation.RangerServiceDefHelper) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef)

Example 32 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class TestRangerServiceDefServiceBase method rangerServiceDef.

private RangerServiceDef rangerServiceDef() {
    List<RangerServiceConfigDef> configs = new ArrayList<RangerServiceConfigDef>();
    List<RangerResourceDef> resources = new ArrayList<RangerResourceDef>();
    List<RangerAccessTypeDef> accessTypes = new ArrayList<RangerAccessTypeDef>();
    List<RangerPolicyConditionDef> policyConditions = new ArrayList<RangerPolicyConditionDef>();
    List<RangerContextEnricherDef> contextEnrichers = new ArrayList<RangerContextEnricherDef>();
    List<RangerEnumDef> enums = new ArrayList<RangerEnumDef>();
    RangerServiceDef rangerServiceDef = new RangerServiceDef();
    rangerServiceDef.setId(Id);
    rangerServiceDef.setImplClass("RangerServiceHdfs");
    rangerServiceDef.setLabel("HDFS Repository");
    rangerServiceDef.setDescription("HDFS Repository");
    rangerServiceDef.setRbKeyDescription(null);
    rangerServiceDef.setUpdatedBy("Admin");
    rangerServiceDef.setUpdateTime(new Date());
    rangerServiceDef.setConfigs(configs);
    rangerServiceDef.setResources(resources);
    rangerServiceDef.setAccessTypes(accessTypes);
    rangerServiceDef.setPolicyConditions(policyConditions);
    rangerServiceDef.setContextEnrichers(contextEnrichers);
    rangerServiceDef.setEnums(enums);
    return rangerServiceDef;
}
Also used : RangerServiceConfigDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef) ArrayList(java.util.ArrayList) RangerEnumDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef) RangerPolicyConditionDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef) Date(java.util.Date) RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) RangerContextEnricherDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerResourceDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)

Example 33 with RangerAccessTypeDef

use of org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef in project ranger by apache.

the class TestRangerServiceDefServiceBase method test7populateRangerAccessTypeDefToXX.

@Test
public void test7populateRangerAccessTypeDefToXX() {
    RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
    rangerAccessTypeDefObj.setLabel("Read");
    rangerAccessTypeDefObj.setName("read");
    rangerAccessTypeDefObj.setRbKeyLabel(null);
    XXAccessTypeDef accessTypeDefObj = new XXAccessTypeDef();
    accessTypeDefObj.setAddedByUserId(Id);
    accessTypeDefObj.setCreateTime(new Date());
    accessTypeDefObj.setDefid(Id);
    accessTypeDefObj.setId(Id);
    accessTypeDefObj.setLabel("Read");
    accessTypeDefObj.setName("read");
    accessTypeDefObj.setOrder(null);
    accessTypeDefObj.setRbkeylabel(null);
    accessTypeDefObj.setUpdatedByUserId(Id);
    accessTypeDefObj.setUpdateTime(new Date());
    XXServiceDef serviceDefObj = new XXServiceDef();
    serviceDefObj.setAddedByUserId(Id);
    serviceDefObj.setCreateTime(new Date());
    serviceDefObj.setDescription("HDFS Repository");
    serviceDefObj.setGuid("1427365526516_835_0");
    serviceDefObj.setId(Id);
    Mockito.when((XXAccessTypeDef) rangerAuditFields.populateAuditFields(accessTypeDefObj, serviceDefObj)).thenReturn(accessTypeDefObj);
    XXAccessTypeDef dbAccessTypeDef = rangerServiceDefService.populateRangerAccessTypeDefToXX(rangerAccessTypeDefObj, accessTypeDefObj, serviceDefObj, 1);
    Assert.assertNotNull(dbAccessTypeDef);
    Assert.assertEquals(dbAccessTypeDef, accessTypeDefObj);
    Assert.assertEquals(dbAccessTypeDef.getName(), accessTypeDefObj.getName());
    Assert.assertEquals(dbAccessTypeDef.getLabel(), accessTypeDefObj.getLabel());
    Assert.assertEquals(dbAccessTypeDef.getRbkeylabel(), accessTypeDefObj.getRbkeylabel());
    Assert.assertEquals(dbAccessTypeDef.getDefid(), accessTypeDefObj.getDefid());
    Assert.assertEquals(dbAccessTypeDef.getId(), accessTypeDefObj.getId());
    Assert.assertEquals(dbAccessTypeDef.getCreateTime(), accessTypeDefObj.getCreateTime());
    Assert.assertEquals(dbAccessTypeDef.getOrder(), accessTypeDefObj.getOrder());
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)33 ArrayList (java.util.ArrayList)22 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)17 RangerResourceDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef)13 RangerContextEnricherDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerContextEnricherDef)11 RangerEnumDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerEnumDef)11 RangerPolicyConditionDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerPolicyConditionDef)11 RangerServiceConfigDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef)11 Date (java.util.Date)10 Test (org.junit.Test)9 XXServiceDef (org.apache.ranger.entity.XXServiceDef)8 VXString (org.apache.ranger.view.VXString)7 HashSet (java.util.HashSet)6 XXAccessTypeDef (org.apache.ranger.entity.XXAccessTypeDef)5 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)5 XXServiceDao (org.apache.ranger.db.XXServiceDao)4 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)4 XXService (org.apache.ranger.entity.XXService)4 RangerDataMaskDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskDef)3 RangerDataMaskTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerDataMaskTypeDef)3