use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class AbstractPredicateUtil method addPredicateForServiceTypeId.
private Predicate addPredicateForServiceTypeId(final String serviceTypeId, List<Predicate> predicates) {
if (StringUtils.isEmpty(serviceTypeId)) {
return null;
}
Predicate ret = new Predicate() {
@Override
public boolean evaluate(Object object) {
if (object == null) {
return false;
}
boolean ret = false;
if (object instanceof RangerServiceDef) {
RangerServiceDef serviceDef = (RangerServiceDef) object;
Long svcDefId = serviceDef.getId();
if (svcDefId != null) {
ret = StringUtils.equals(serviceTypeId, svcDefId.toString());
}
} else {
ret = true;
}
return ret;
}
};
if (predicates != null) {
predicates.add(ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class AbstractServiceStore method updateTagServiceDefForDeletingAccessTypes.
private void updateTagServiceDefForDeletingAccessTypes(String serviceDefName) throws Exception {
if (EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME.equals(serviceDefName)) {
return;
}
RangerServiceDef tagServiceDef;
try {
tagServiceDef = this.getServiceDef(EmbeddedServiceDefsUtil.instance().getTagServiceDefId());
} catch (Exception e) {
LOG.error("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes(" + serviceDefName + "): could not find TAG ServiceDef.. ", e);
throw e;
}
if (tagServiceDef == null) {
LOG.error("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes(" + serviceDefName + "): could not find TAG ServiceDef.. ");
return;
}
List<RangerServiceDef.RangerAccessTypeDef> accessTypes = new ArrayList<>();
for (RangerServiceDef.RangerAccessTypeDef accessType : tagServiceDef.getAccessTypes()) {
if (accessType.getName().startsWith(serviceDefName + COMPONENT_ACCESSTYPE_SEPARATOR)) {
accessTypes.add(accessType);
}
}
tagServiceDef.getAccessTypes().removeAll(accessTypes);
updateTagServiceDefForDeletingDataMaskDef(tagServiceDef, serviceDefName);
updateTagServiceDefForDeletingRowFilterDef(tagServiceDef, serviceDefName);
updateResourceInTagServiceDef(tagServiceDef);
try {
updateServiceDef(tagServiceDef);
LOG.info("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes -- updated TAG service def with " + serviceDefName + " access types");
} catch (Exception e) {
LOG.error("AbstractServiceStore.updateTagServiceDefForDeletingAccessTypes -- Failed to update TAG ServiceDef.. ", e);
throw e;
}
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class AbstractServiceStore method updateTagServiceDefForUpdatingAccessTypes.
private void updateTagServiceDefForUpdatingAccessTypes(RangerServiceDef serviceDef) throws Exception {
if (StringUtils.equals(serviceDef.getName(), EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME)) {
return;
}
if (EmbeddedServiceDefsUtil.instance().getTagServiceDefId() == -1) {
LOG.info("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes(" + serviceDef.getName() + "): tag service-def does not exist");
}
RangerServiceDef tagServiceDef;
try {
tagServiceDef = this.getServiceDef(EmbeddedServiceDefsUtil.instance().getTagServiceDefId());
} catch (Exception e) {
LOG.error("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes" + serviceDef.getName() + "): could not find TAG ServiceDef.. ", e);
throw e;
}
if (tagServiceDef == null) {
LOG.error("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes(" + serviceDef.getName() + "): could not find TAG ServiceDef.. ");
return;
}
String serviceDefName = serviceDef.getName();
String prefix = serviceDefName + COMPONENT_ACCESSTYPE_SEPARATOR;
List<RangerServiceDef.RangerAccessTypeDef> svcDefAccessTypes = serviceDef.getAccessTypes();
List<RangerServiceDef.RangerAccessTypeDef> tagDefAccessTypes = tagServiceDef.getAccessTypes();
long itemIdOffset = serviceDef.getId() * (MAX_ACCESS_TYPES_IN_SERVICE_DEF + 1);
boolean updateNeeded = updateTagAccessTypeDefs(svcDefAccessTypes, tagDefAccessTypes, itemIdOffset, prefix);
if (updateTagServiceDefForUpdatingDataMaskDef(tagServiceDef, serviceDef, itemIdOffset, prefix)) {
updateNeeded = true;
}
if (updateTagServiceDefForUpdatingRowFilterDef(tagServiceDef, serviceDef, itemIdOffset, prefix)) {
updateNeeded = true;
}
boolean resourceUpdated = updateResourceInTagServiceDef(tagServiceDef);
updateNeeded = updateNeeded || resourceUpdated;
if (updateNeeded) {
try {
updateServiceDef(tagServiceDef);
LOG.info("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes -- updated TAG service def with " + serviceDefName + " access types");
} catch (Exception e) {
LOG.error("AbstractServiceStore.updateTagServiceDefForUpdatingAccessTypes -- Failed to update TAG ServiceDef.. ", e);
throw e;
}
}
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class EmbeddedServiceDefsUtil method getOrCreateServiceDef.
private RangerServiceDef getOrCreateServiceDef(ServiceStore store, String serviceDefName) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> EmbeddedServiceDefsUtil.getOrCreateServiceDef(" + serviceDefName + ")");
}
RangerServiceDef ret = null;
boolean createServiceDef = (CollectionUtils.isEmpty(supportedServiceDefs) || supportedServiceDefs.contains(serviceDefName));
try {
ret = store.getServiceDefByName(serviceDefName);
if (ret == null && createEmbeddedServiceDefs && createServiceDef) {
ret = ServiceDefUtil.normalize(loadEmbeddedServiceDef(serviceDefName));
LOG.info("creating embedded service-def " + serviceDefName);
if (ret.getId() != null) {
store.setPopulateExistingBaseFields(true);
try {
ret = store.createServiceDef(ret);
} finally {
store.setPopulateExistingBaseFields(false);
}
} else {
ret = store.createServiceDef(ret);
}
LOG.info("created embedded service-def " + serviceDefName);
}
} catch (Exception excp) {
LOG.fatal("EmbeddedServiceDefsUtil.getOrCreateServiceDef(): failed to load/create serviceType " + serviceDefName, excp);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== EmbeddedServiceDefsUtil.getOrCreateServiceDef(" + serviceDefName + "): " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef in project ranger by apache.
the class EmbeddedServiceDefsUtil method loadEmbeddedServiceDef.
private RangerServiceDef loadEmbeddedServiceDef(String serviceType) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> EmbeddedServiceDefsUtil.loadEmbeddedServiceDef(" + serviceType + ")");
}
RangerServiceDef ret = null;
String resource = "/service-defs/ranger-servicedef-" + serviceType + ".json";
InputStream inStream = getClass().getResourceAsStream(resource);
InputStreamReader reader = new InputStreamReader(inStream);
ret = gsonBuilder.fromJson(reader, RangerServiceDef.class);
if (LOG.isDebugEnabled()) {
LOG.debug("==> EmbeddedServiceDefsUtil.loadEmbeddedServiceDef(" + serviceType + ")");
}
return ret;
}
Aggregations