use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049 method updateAllServiceDef.
private void updateAllServiceDef() throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("==> PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049.updateAllServiceDef()");
}
List<XXServiceDef> allXXServiceDefs;
allXXServiceDefs = daoMgr.getXXServiceDef().getAll();
if (CollectionUtils.isNotEmpty(allXXServiceDefs)) {
logger.info("Found " + allXXServiceDefs.size() + " services-defs");
for (XXServiceDef xxServiceDef : allXXServiceDefs) {
String serviceDefName = xxServiceDef.getName();
try {
RangerServiceConfigDef defualtAuditFiltersSvcConfDef = getDefaultAuditFiltersByServiceDef(serviceDefName);
if (defualtAuditFiltersSvcConfDef == null) {
logger.info("No default audit-filter available for service-def " + serviceDefName + ". Skipped");
continue;
}
RangerServiceDef serviceDef = svcDBStore.getServiceDefByName(serviceDefName);
if (serviceDef != null) {
List<RangerServiceConfigDef> svcConfDefList = serviceDef.getConfigs();
boolean defaultAuditFiltresFound = false;
for (RangerServiceConfigDef svcConfDef : svcConfDefList) {
if (StringUtils.equals(svcConfDef.getName(), ServiceDBStore.RANGER_PLUGIN_AUDIT_FILTERS)) {
defaultAuditFiltresFound = true;
break;
}
}
if (!defaultAuditFiltresFound) {
logger.info("adding default audit-filter for service-def:[" + serviceDefName + "]");
int sortOrder = serviceDef.getConfigs().size() - 1;
addDefaultAuditFilterConfig(defualtAuditFiltersSvcConfDef, xxServiceDef, sortOrder);
logger.info("Completed adding default audit-filter for service-def:[" + serviceDefName + "]");
} else {
logger.info("default audit-filter already available for service-def " + serviceDefName + ". Skipped");
}
} else {
logger.info("No service-def:[" + serviceDefName + "] found");
}
} catch (Exception e) {
logger.error("Error while adding default audit-filter service-def:[" + serviceDefName + "]", e);
}
}
} else {
logger.info("No service-def found");
}
if (logger.isDebugEnabled()) {
logger.debug("<== PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049.updateAllServiceDef()");
}
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049 method getDefaultAuditFiltersByServiceDef.
private RangerServiceConfigDef getDefaultAuditFiltersByServiceDef(String serviceDefName) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("==> PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049.getDefaultAuditFiltersByServiceDef() for serviceDefName:[" + serviceDefName + "]");
}
RangerServiceConfigDef ret = null;
RangerServiceDef embeddedAtlasServiceDef = null;
embeddedAtlasServiceDef = EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(serviceDefName);
List<RangerServiceConfigDef> svcConfDefList = embeddedAtlasServiceDef.getConfigs();
for (RangerServiceConfigDef svcConfDef : svcConfDefList) {
if (StringUtils.equals(svcConfDef.getName(), ServiceDBStore.RANGER_PLUGIN_AUDIT_FILTERS)) {
ret = svcConfDef;
break;
}
}
if (logger.isDebugEnabled()) {
logger.debug("<== PatchForAllServiceDefUpdateForDefaultAuditFilters_J10049.getDefaultAuditFiltersByServiceDef() for serviceDefName:[" + serviceDefName + "] ret : " + ret);
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method test_isValid_happyPath.
@Test
public void test_isValid_happyPath() throws Exception {
// create a service def with some required parameters
Object[][] serviceDefInput = new Object[][] { { "param1", true }, { "param2", true }, { "param3", false }, { "param4", false }, { "param5", true } };
List<RangerServiceConfigDef> configDefs = _utils.createServiceConditionDefs(serviceDefInput);
RangerServiceDef serviceDef = mock(RangerServiceDef.class);
when(serviceDef.getConfigs()).thenReturn(configDefs);
// create a service with some parameters on it
RangerService service = mock(RangerService.class);
when(service.getName()).thenReturn("aName");
when(service.getDisplayName()).thenReturn("aDisplayName");
when(service.getType()).thenReturn("aType");
// contains an extra parameter (param6) and one optional is missing(param4)
String[] configs = new String[] { "param1", "param2", "param3", "param5", "param6" };
Map<String, String> configMap = _utils.createMap(configs);
when(service.getConfigs()).thenReturn(configMap);
// wire then into the store
// service does not exists
when(_store.getServiceByName("aName")).thenReturn(null);
// service def exists
when(_store.getServiceDefByName("aType")).thenReturn(serviceDef);
Assert.assertTrue(_validator.isValid(service, Action.CREATE, _failures));
// for update to work the only additional requirement is that id is required and service should exist
// if name is not null and it points to a service then it should match the id
when(service.getId()).thenReturn(7L);
RangerService existingService = mock(RangerService.class);
when(existingService.getId()).thenReturn(Long.valueOf(7L));
when(_store.getService(7L)).thenReturn(existingService);
when(_store.getServiceByName("aName")).thenReturn(existingService);
Assert.assertTrue(_validator.isValid(service, Action.UPDATE, _failures));
// name need not point to a service for update to work, of course.
when(_store.getServiceByName("aName")).thenReturn(null);
Assert.assertTrue(_validator.isValid(service, Action.UPDATE, _failures));
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameCreationWithOutSpecialCharacters.
@Test
public void testIsValidServiceNameCreationWithOutSpecialCharacters() throws Exception {
String serviceName = "c1_yarn";
String serviceDisplayName = serviceName;
RangerService rangerService = new RangerService();
rangerService.setName(serviceName);
rangerService.setDisplayName(serviceDisplayName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, Action.CREATE, _failures);
Assert.assertEquals(0, _failures.size());
Assert.assertTrue(valid);
}
use of org.apache.ranger.plugin.model.RangerServiceDef.RangerServiceConfigDef in project ranger by apache.
the class TestRangerServiceValidator method testIsValidServiceNameCreationWithSpaceCharacter.
@Test
public void testIsValidServiceNameCreationWithSpaceCharacter() throws Exception {
String serviceName = "Cluster 1_c1_yarn";
String serviceDisplayName = serviceName;
ValidationErrorCode vErrCod = ValidationErrorCode.SERVICE_VALIDATION_ERR_SPECIAL_CHARACTERS_SERVICE_NAME;
String errorMessage = vErrCod.getMessage(serviceName);
int errorCode = vErrCod.getErrorCode();
RangerService rangerService = new RangerService();
rangerService.setName(serviceName);
rangerService.setDisplayName(serviceDisplayName);
rangerService.setType("yarn");
rangerService.setTagService("");
RangerServiceConfigDef configDef = new RangerServiceConfigDef();
configDef.setMandatory(true);
List<RangerServiceConfigDef> listRangerServiceConfigDef = new ArrayList<RangerServiceDef.RangerServiceConfigDef>();
listRangerServiceConfigDef.add(configDef);
configDef.setName("myconfig1");
Map<String, String> testMap = new HashMap<String, String>();
testMap.put("myconfig1", "myconfig1");
rangerService.setConfigs(testMap);
RangerServiceDef rangerServiceDef = new RangerServiceDef();
rangerServiceDef.setConfigs(listRangerServiceConfigDef);
when(_store.getServiceDefByName("yarn")).thenReturn(rangerServiceDef);
boolean valid = _validator.isValid(rangerService, _action, _failures);
ValidationFailureDetails failureMessage = _failures.get(0);
Assert.assertFalse(valid);
Assert.assertEquals("name", failureMessage.getFieldName());
Assert.assertEquals(errorMessage, failureMessage._reason);
Assert.assertEquals(errorCode, failureMessage._errorCode);
}
Aggregations