use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class ServiceDBStore method getServiceDefByName.
@Override
public RangerServiceDef getServiceDefByName(String name) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.getServiceDefByName(" + name + ")");
}
RangerServiceDef ret = null;
XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(name);
if (xServiceDef != null) {
ret = serviceDefService.getPopulatedViewObject(xServiceDef);
}
if (LOG.isDebugEnabled()) {
LOG.debug("== ServiceDBStore.getServiceDefByName(" + name + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class ServiceDBStore method deleteServiceDef.
public void deleteServiceDef(Long serviceDefId, Boolean forceDelete) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
}
bizUtil.blockAuditorRoleUser();
UserSessionBase session = ContextUtil.getCurrentUserSession();
if (session == null) {
throw restErrorUtil.createRESTException("UserSession cannot be null, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
}
if (!session.isKeyAdmin() && !session.isUserAdmin()) {
throw restErrorUtil.createRESTException("User is not allowed to update service-def, only Admin can update service-def", MessageEnums.OPER_NO_PERMISSION);
}
RangerServiceDef serviceDef = getServiceDef(serviceDefId);
if (serviceDef == null) {
throw restErrorUtil.createRESTException("No Service Definiton found for Id: " + serviceDefId, MessageEnums.DATA_NOT_FOUND);
}
List<XXService> serviceList = daoMgr.getXXService().findByServiceDefId(serviceDefId);
if (!forceDelete) {
if (CollectionUtils.isNotEmpty(serviceList)) {
throw restErrorUtil.createRESTException("Services exists under given service definition, can't delete Service-Def: " + serviceDef.getName(), MessageEnums.OPER_NOT_ALLOWED_FOR_ENTITY);
}
}
XXDataMaskTypeDefDao dataMaskDao = daoMgr.getXXDataMaskTypeDef();
List<XXDataMaskTypeDef> dataMaskDefs = dataMaskDao.findByServiceDefId(serviceDefId);
for (XXDataMaskTypeDef dataMaskDef : dataMaskDefs) {
dataMaskDao.remove(dataMaskDef);
}
List<XXAccessTypeDef> accTypeDefs = daoMgr.getXXAccessTypeDef().findByServiceDefId(serviceDefId);
for (XXAccessTypeDef accessType : accTypeDefs) {
deleteXXAccessTypeDef(accessType);
}
XXContextEnricherDefDao xContextEnricherDao = daoMgr.getXXContextEnricherDef();
List<XXContextEnricherDef> contextEnrichers = xContextEnricherDao.findByServiceDefId(serviceDefId);
for (XXContextEnricherDef context : contextEnrichers) {
xContextEnricherDao.remove(context);
}
XXEnumDefDao enumDefDao = daoMgr.getXXEnumDef();
List<XXEnumDef> enumDefList = enumDefDao.findByServiceDefId(serviceDefId);
for (XXEnumDef enumDef : enumDefList) {
List<XXEnumElementDef> enumEleDefList = daoMgr.getXXEnumElementDef().findByEnumDefId(enumDef.getId());
for (XXEnumElementDef eleDef : enumEleDefList) {
daoMgr.getXXEnumElementDef().remove(eleDef);
}
enumDefDao.remove(enumDef);
}
XXPolicyConditionDefDao policyCondDao = daoMgr.getXXPolicyConditionDef();
List<XXPolicyConditionDef> policyCondList = policyCondDao.findByServiceDefId(serviceDefId);
for (XXPolicyConditionDef policyCond : policyCondList) {
List<XXPolicyItemCondition> policyItemCondList = daoMgr.getXXPolicyItemCondition().findByPolicyConditionDefId(policyCond.getId());
for (XXPolicyItemCondition policyItemCond : policyItemCondList) {
daoMgr.getXXPolicyItemCondition().remove(policyItemCond);
}
policyCondDao.remove(policyCond);
}
List<XXResourceDef> resDefList = daoMgr.getXXResourceDef().findByServiceDefId(serviceDefId);
for (XXResourceDef resDef : resDefList) {
deleteXXResourceDef(resDef);
}
XXServiceConfigDefDao configDefDao = daoMgr.getXXServiceConfigDef();
List<XXServiceConfigDef> configDefList = configDefDao.findByServiceDefId(serviceDefId);
for (XXServiceConfigDef configDef : configDefList) {
configDefDao.remove(configDef);
}
if (CollectionUtils.isNotEmpty(serviceList)) {
for (XXService service : serviceList) {
deleteService(service.getId());
}
}
Long version = serviceDef.getVersion();
if (version == null) {
version = Long.valueOf(1);
LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null.");
} else {
version = Long.valueOf(version.longValue() + 1);
}
serviceDef.setVersion(version);
serviceDefService.delete(serviceDef);
LOG.info("ServiceDefinition has been deleted successfully. Service-Def Name: " + serviceDef.getName());
dataHistService.createObjectDataHistory(serviceDef, RangerDataHistService.ACTION_DELETE);
postDelete(serviceDef);
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceDBStore.deleteServiceDef(" + serviceDefId + ", " + forceDelete + ")");
}
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class ServiceDBStore method getServiceDefs.
@Override
public List<RangerServiceDef> getServiceDefs(SearchFilter filter) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.getServiceDefs(" + filter + ")");
}
RangerServiceDefList svcDefList = serviceDefService.searchRangerServiceDefs(filter);
predicateUtil.applyFilter(svcDefList.getServiceDefs(), filter);
List<RangerServiceDef> ret = svcDefList.getServiceDefs();
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.getServiceDefs(" + filter + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class ServiceMgr method getRangerServiceByService.
public RangerBaseService getRangerServiceByService(RangerService service, ServiceStore svcStore) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceMgr.getRangerServiceByService(" + service + ")");
}
RangerBaseService ret = null;
String serviceType = service == null ? null : service.getType();
if (!StringUtils.isEmpty(serviceType)) {
RangerServiceDef serviceDef = svcStore == null ? null : svcStore.getServiceDefByName(serviceType);
if (serviceDef != null) {
Class<RangerBaseService> cls = getClassForServiceType(serviceDef);
if (cls != null) {
ret = cls.newInstance();
ret.init(serviceDef, service);
if (ret instanceof RangerServiceTag) {
((RangerServiceTag) ret).setTagStore(tagStore);
}
} else {
LOG.warn("ServiceMgr.getRangerServiceByService(" + service + "): could not find service class '" + serviceDef.getImplClass() + "' for the service type '" + serviceType + "'");
}
} else {
LOG.warn("ServiceMgr.getRangerServiceByService(" + service + "): could not find the service-def for the service type '" + serviceType + "'");
}
} else {
LOG.warn("ServiceMgr.getRangerServiceByService(" + service + "): could not find the service-type '" + serviceType + "'");
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceMgr.getRangerServiceByService(" + service + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class TestRangerServiceDefService 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;
}
Aggregations