Java Code Examples for org.apache.ranger.plugin.model.RangerServiceDef#setResources()

The following examples show how to use org.apache.ranger.plugin.model.RangerServiceDef#setResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatchForHiveServiceDefUpdate_J10030.java    From ranger with Apache License 2.0 6 votes vote down vote up
private boolean updateServiceDef(RangerServiceDef serviceDef, RangerServiceDef embeddedHiveServiceDef ) throws Exception {
	boolean ret = false;

	List<RangerServiceDef.RangerResourceDef> embeddedHiveResourceDefs   = null;

	embeddedHiveResourceDefs = embeddedHiveServiceDef.getResources();

		if (checkHiveURLResourceMatcherPresent(embeddedHiveResourceDefs)) {
		// This is to check if URL resource matcher is added to the resource definition, if so update the resource def
		if (embeddedHiveResourceDefs != null) {
			serviceDef.setResources(embeddedHiveResourceDefs);
		}
		ret = true;
	}

	RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
	validator.validate(serviceDef, Action.UPDATE);
	svcStore.updateServiceDef(serviceDef);

	return ret;
}
 
Example 2
Source File: RangerSecurityZoneValidatorTest.java    From ranger with Apache License 2.0 6 votes vote down vote up
@Test
       public void testValidateSecurityZoneWitoutRangerServiceDefResourceForCreateThrowsError() throws Exception{
	RangerService rangerSvc = getRangerService();
	RangerServiceDef rangerSvcDef = rangerServiceDef();
	rangerSvcDef.setResources(null);
               RangerSecurityZone suppliedSecurityZone = getRangerSecurityZone();

	Mockito.when(_store.getSecurityZone("MyZone")).thenReturn(null);
	Mockito.when(_store.getServiceByName("hdfsSvc")).thenReturn(rangerSvc);
	Mockito.when(_store.getServiceDefByName("1")).thenReturn(rangerSvcDef);
	
	try {
		rangerSecurityZoneValidator.validate(suppliedSecurityZone,
				RangerValidator.Action.CREATE);
	} catch (Exception ex) {
		Assert.assertEquals(
				ex.getMessage(),
				"(0) Validation failure: error code[3042], reason[Invalid resource hierarchy specified for service:[hdfsSvc], resource-hierarchy:[[hdfs]]], field[security zone resource hierarchy], subfield[null], type[] ");
	}
}
 
Example 3
Source File: PatchForHiveServiceDefUpdate_J10017.java    From ranger with Apache License 2.0 5 votes vote down vote up
private boolean updateServiceDef(RangerServiceDef serviceDef, RangerServiceDef embeddedHiveServiceDef ) throws Exception {
	boolean ret = false;

	List<RangerServiceDef.RangerResourceDef> embeddedHiveResourceDefs   = null;
	List<RangerServiceDef.RangerAccessTypeDef> 	embeddedHiveAccessTypes = null;

	embeddedHiveResourceDefs = embeddedHiveServiceDef.getResources();
	embeddedHiveAccessTypes  = embeddedHiveServiceDef.getAccessTypes();

	if (checkHiveGlobalresourcePresent(embeddedHiveResourceDefs)) {
		// This is to check if HIVESERVICE def is added to the resource definition, if so update the resource def and accessType def
		if (embeddedHiveResourceDefs != null) {
			serviceDef.setResources(embeddedHiveResourceDefs);
		}
		if (embeddedHiveAccessTypes != null) {
			if(!embeddedHiveAccessTypes.toString().equalsIgnoreCase(serviceDef.getAccessTypes().toString())) {
				serviceDef.setAccessTypes(embeddedHiveAccessTypes);
			}
		}
		ret = true;
	}

	RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
	validator.validate(serviceDef, Action.UPDATE);
	svcStore.updateServiceDef(serviceDef);

	return ret;
}
 
Example 4
Source File: PatchForHiveServiceDefUpdate_J10010.java    From ranger with Apache License 2.0 5 votes vote down vote up
private boolean updateServiceDef(RangerServiceDef serviceDef, RangerServiceDef embeddedHiveServiceDef ) throws Exception {
	boolean ret = false;

	List<RangerServiceDef.RangerResourceDef> embeddedHiveResourceDefs   = null;
	List<RangerServiceDef.RangerAccessTypeDef> 	embeddedHiveAccessTypes = null;

	embeddedHiveResourceDefs = embeddedHiveServiceDef.getResources();
	embeddedHiveAccessTypes  = embeddedHiveServiceDef.getAccessTypes();

	if (checkHiveServiceresourcePresent(embeddedHiveResourceDefs)) {
		// This is to check if HIVESERVICE def is added to the resource definition, if so update the resource def and accessType def
		if (embeddedHiveResourceDefs != null) {
			serviceDef.setResources(embeddedHiveResourceDefs);
		}
		if (embeddedHiveAccessTypes != null) {
			if(!embeddedHiveAccessTypes.toString().equalsIgnoreCase(serviceDef.getAccessTypes().toString())) {
				serviceDef.setAccessTypes(embeddedHiveAccessTypes);
			}
		}
		ret = true;
	}

	RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
	validator.validate(serviceDef, Action.UPDATE);
	svcStore.updateServiceDef(serviceDef);

	return ret;
}
 
Example 5
Source File: PatchForAtlasToAddEntityLabelAndBusinessMetadata_J10034.java    From ranger with Apache License 2.0 5 votes vote down vote up
private void addResourceEntityLabelAndEntityBusinessMetadataInServiceDef() throws Exception {
    RangerServiceDef ret = null;
    RangerServiceDef embeddedAtlasServiceDef = null;
    XXServiceDef xXServiceDefObj = null;
    RangerServiceDef dbAtlasServiceDef = null;
    List<RangerServiceDef.RangerResourceDef> embeddedAtlasResourceDefs = null;
    List<RangerServiceDef.RangerAccessTypeDef> embeddedAtlasAccessTypes = null;

    embeddedAtlasServiceDef = EmbeddedServiceDefsUtil.instance()
            .getEmbeddedServiceDef(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
    if (embeddedAtlasServiceDef != null) {
        xXServiceDefObj = daoMgr.getXXServiceDef()
                .findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
        if (xXServiceDefObj == null) {
            logger.info(xXServiceDefObj + ": service-def not found. No patching is needed");
            return;
        }

        dbAtlasServiceDef = svcDBStore.getServiceDefByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);

        embeddedAtlasResourceDefs = embeddedAtlasServiceDef.getResources();
        embeddedAtlasAccessTypes = embeddedAtlasServiceDef.getAccessTypes();
        if (checkResourcePresent(embeddedAtlasResourceDefs)) {
            dbAtlasServiceDef.setResources(embeddedAtlasResourceDefs);
            if (checkAccessPresent(embeddedAtlasAccessTypes)) {
                dbAtlasServiceDef.setAccessTypes(embeddedAtlasAccessTypes);
            }
        }

        RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
        validator.validate(dbAtlasServiceDef, Action.UPDATE);
        ret = svcStore.updateServiceDef(dbAtlasServiceDef);
        if (ret == null) {
            logger.error("Error while updating " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME
                    + " service-def");
            throw new RuntimeException("Error while updating "
                    + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME + " service-def");
        }
    }
}
 
Example 6
Source File: PatchForKafkaServiceDefUpdate_J10033.java    From ranger with Apache License 2.0 4 votes vote down vote up
private void updateKafkaServiceDef(){
	RangerServiceDef ret                = null;
	RangerServiceDef embeddedKafkaServiceDef = null;
	RangerServiceDef dbKafkaServiceDef         = null;
	List<RangerServiceDef.RangerResourceDef>   embeddedKafkaResourceDefs  = null;
	List<RangerServiceDef.RangerAccessTypeDef>     embeddedKafkaAccessTypes   = null;
	XXServiceDef xXServiceDefObj         = null;
	try{
		embeddedKafkaServiceDef=EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
		if(embeddedKafkaServiceDef!=null){

			xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
			Map<String, String> serviceDefOptionsPreUpdate=null;
			String jsonStrPreUpdate=null;
			if(xXServiceDefObj!=null) {
				jsonStrPreUpdate=xXServiceDefObj.getDefOptions();
				serviceDefOptionsPreUpdate=jsonStringToMap(jsonStrPreUpdate);
				xXServiceDefObj=null;
			}
			dbKafkaServiceDef=svcDBStore.getServiceDefByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);

			if(dbKafkaServiceDef!=null){
				embeddedKafkaResourceDefs = embeddedKafkaServiceDef.getResources();
				embeddedKafkaAccessTypes  = embeddedKafkaServiceDef.getAccessTypes();

				if (checkNewKafkaresourcePresent(embeddedKafkaResourceDefs)) {
					// This is to check if CONSUMERGROUP resource is added to the resource definition, if so update the resource def and accessType def
					if (embeddedKafkaResourceDefs != null) {
						dbKafkaServiceDef.setResources(embeddedKafkaResourceDefs);
					}
					if (embeddedKafkaAccessTypes != null) {
						if(!embeddedKafkaAccessTypes.toString().equalsIgnoreCase(dbKafkaServiceDef.getAccessTypes().toString())) {
							dbKafkaServiceDef.setAccessTypes(embeddedKafkaAccessTypes);
						}
					}
				}

				RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
				validator.validate(dbKafkaServiceDef, Action.UPDATE);

				ret = svcStore.updateServiceDef(dbKafkaServiceDef);
				if(ret==null){
					logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def");
					throw new RuntimeException("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def");
				}
				xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
				if(xXServiceDefObj!=null) {
					String jsonStrPostUpdate=xXServiceDefObj.getDefOptions();
					Map<String, String> serviceDefOptionsPostUpdate=jsonStringToMap(jsonStrPostUpdate);
					if (serviceDefOptionsPostUpdate != null && serviceDefOptionsPostUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
						if(serviceDefOptionsPreUpdate == null || !serviceDefOptionsPreUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
							String preUpdateValue = serviceDefOptionsPreUpdate == null ? null : serviceDefOptionsPreUpdate.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							if (preUpdateValue == null) {
								serviceDefOptionsPostUpdate.remove(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							} else {
								serviceDefOptionsPostUpdate.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, preUpdateValue);
							}
							xXServiceDefObj.setDefOptions(mapToJsonString(serviceDefOptionsPostUpdate));
							daoMgr.getXXServiceDef().update(xXServiceDefObj);
						}
					}
					createDefaultPolicyForNewResources();
				}
			}
		}
	}catch(Exception e)
	{
		logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def", e);
	}
}
 
Example 7
Source File: PatchForAtlasResourceAndAccessTypeUpdate_J10016.java    From ranger with Apache License 2.0 4 votes vote down vote up
private void updateAtlasResourceAndAccessType() {
	RangerServiceDef ret = null;
	RangerServiceDef embeddedAtlasServiceDef = null;
	XXServiceDef xXServiceDefObj = null;
	RangerServiceDef dbAtlasServiceDef = null;
	List<RangerServiceDef.RangerResourceDef> embeddedAtlasResourceDefs = null;
	List<RangerServiceDef.RangerAccessTypeDef> embeddedAtlasAccessTypes = null;

	try {
		embeddedAtlasServiceDef = EmbeddedServiceDefsUtil.instance()
				.getEmbeddedServiceDef(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
		if (embeddedAtlasServiceDef != null) {
			xXServiceDefObj = daoMgr.getXXServiceDef()
					.findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
			if (xXServiceDefObj == null) {
				logger.info(xXServiceDefObj + ": service-def not found. No patching is needed");
				return;
			}

			dbAtlasServiceDef = svcDBStore
					.getServiceDefByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME);
			embeddedAtlasResourceDefs = embeddedAtlasServiceDef.getResources();
			embeddedAtlasAccessTypes = embeddedAtlasServiceDef.getAccessTypes();
			if (checkResourcePresent(embeddedAtlasResourceDefs)) {
				dbAtlasServiceDef.setResources(embeddedAtlasResourceDefs);
				if (checkAccessPresent(embeddedAtlasAccessTypes)) {
					dbAtlasServiceDef.setAccessTypes(embeddedAtlasAccessTypes);
				}
			}

			RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
			validator.validate(dbAtlasServiceDef, Action.UPDATE);
			ret = svcStore.updateServiceDef(dbAtlasServiceDef);
			if (ret == null) {
				logger.error("Error while updating " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME
						+ " service-def");
				throw new RuntimeException("Error while updating "
						+ EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME + " service-def");
			} else {
				createDefaultPolicyToExistingService();
				updatePolicyForRelationshipType();
			}
		}
	} catch (Exception e) {
		logger.error("Error while updating " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME + " service-def",e);
	}

}
 
Example 8
Source File: PatchForHiveServiceDefUpdate_J10007.java    From ranger with Apache License 2.0 4 votes vote down vote up
private void updateHiveServiceDef(){
	RangerServiceDef ret  					= null;
	RangerServiceDef embeddedHiveServiceDef = null;
	RangerServiceDef dbHiveServiceDef 		= null;
	List<RangerServiceDef.RangerResourceDef> 	embeddedHiveResourceDefs  = null;
	List<RangerServiceDef.RangerAccessTypeDef> 	embeddedHiveAccessTypes   = null;
	XXServiceDef xXServiceDefObj			= null;
	try{
		embeddedHiveServiceDef=EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME);
		if(embeddedHiveServiceDef!=null){

			xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME);
			Map<String, String> serviceDefOptionsPreUpdate=null;
			String jsonStrPreUpdate=null;
			if(xXServiceDefObj!=null) {
				jsonStrPreUpdate=xXServiceDefObj.getDefOptions();
				serviceDefOptionsPreUpdate=jsonStringToMap(jsonStrPreUpdate);
				xXServiceDefObj=null;
			}
			dbHiveServiceDef=svcDBStore.getServiceDefByName(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME);
			
			if(dbHiveServiceDef!=null){
				embeddedHiveResourceDefs = embeddedHiveServiceDef.getResources();
				embeddedHiveAccessTypes  = embeddedHiveServiceDef.getAccessTypes();

				if (checkURLresourcePresent(embeddedHiveResourceDefs)) {
					// This is to check if URL def is added to the resource definition, if so update the resource def and accessType def
					if (embeddedHiveResourceDefs != null) {
						dbHiveServiceDef.setResources(embeddedHiveResourceDefs);
					}
					if (embeddedHiveAccessTypes != null) {
						if(!embeddedHiveAccessTypes.toString().equalsIgnoreCase(dbHiveServiceDef.getAccessTypes().toString())) {
							dbHiveServiceDef.setAccessTypes(embeddedHiveAccessTypes);
						}
					}
				}

				RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
				validator.validate(dbHiveServiceDef, Action.UPDATE);

				ret = svcStore.updateServiceDef(dbHiveServiceDef);
				if(ret==null){
					logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME+"service-def");
					throw new RuntimeException("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME+"service-def");
				}
				xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME);
				if(xXServiceDefObj!=null) {
					String jsonStrPostUpdate=xXServiceDefObj.getDefOptions();
					Map<String, String> serviceDefOptionsPostUpdate=jsonStringToMap(jsonStrPostUpdate);
					if (serviceDefOptionsPostUpdate != null && serviceDefOptionsPostUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
						if(serviceDefOptionsPreUpdate == null || !serviceDefOptionsPreUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
							String preUpdateValue = serviceDefOptionsPreUpdate == null ? null : serviceDefOptionsPreUpdate.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							if (preUpdateValue == null) {
								serviceDefOptionsPostUpdate.remove(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							} else {
								serviceDefOptionsPostUpdate.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, preUpdateValue);
							}
							xXServiceDefObj.setDefOptions(mapToJsonString(serviceDefOptionsPostUpdate));
							daoMgr.getXXServiceDef().update(xXServiceDefObj);
						}
					}
				}
			}
		}
		}catch(Exception e)
		{
			logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_HIVE_NAME+"service-def", e);
		}
}
 
Example 9
Source File: PatchForKafkaServiceDefUpdate_J10015.java    From ranger with Apache License 2.0 4 votes vote down vote up
private void updateHiveServiceDef(){
	RangerServiceDef ret  					 = null;
	RangerServiceDef embeddedKafkaServiceDef = null;
	RangerServiceDef dbKafkaServiceDef 		 = null;
	List<RangerServiceDef.RangerResourceDef> 	embeddedKafkaResourceDefs  = null;
	List<RangerServiceDef.RangerAccessTypeDef> 	embeddedKafkaAccessTypes   = null;
	XXServiceDef xXServiceDefObj			= null;
	try{
		embeddedKafkaServiceDef=EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
		if(embeddedKafkaServiceDef!=null){

			xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
			Map<String, String> serviceDefOptionsPreUpdate=null;
			String jsonStrPreUpdate=null;
			if(xXServiceDefObj!=null) {
				jsonStrPreUpdate=xXServiceDefObj.getDefOptions();
				serviceDefOptionsPreUpdate=jsonStringToMap(jsonStrPreUpdate);
				xXServiceDefObj=null;
			}
			dbKafkaServiceDef=svcDBStore.getServiceDefByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);

			if(dbKafkaServiceDef!=null){
				embeddedKafkaResourceDefs = embeddedKafkaServiceDef.getResources();
				embeddedKafkaAccessTypes  = embeddedKafkaServiceDef.getAccessTypes();

				if (checkNewKafkaresourcePresent(embeddedKafkaResourceDefs)) {
					// This is to check if URL def is added to the resource definition, if so update the resource def and accessType def
					if (embeddedKafkaResourceDefs != null) {
						dbKafkaServiceDef.setResources(embeddedKafkaResourceDefs);
					}
					if (embeddedKafkaAccessTypes != null) {
						if(!embeddedKafkaAccessTypes.toString().equalsIgnoreCase(dbKafkaServiceDef.getAccessTypes().toString())) {
							dbKafkaServiceDef.setAccessTypes(embeddedKafkaAccessTypes);
						}
					}
				}

				RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
				validator.validate(dbKafkaServiceDef, Action.UPDATE);

				ret = svcStore.updateServiceDef(dbKafkaServiceDef);
				if(ret==null){
					logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def");
					throw new RuntimeException("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def");
				}
				xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
				if(xXServiceDefObj!=null) {
					String jsonStrPostUpdate=xXServiceDefObj.getDefOptions();
					Map<String, String> serviceDefOptionsPostUpdate=jsonStringToMap(jsonStrPostUpdate);
					if (serviceDefOptionsPostUpdate != null && serviceDefOptionsPostUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
						if(serviceDefOptionsPreUpdate == null || !serviceDefOptionsPreUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
							String preUpdateValue = serviceDefOptionsPreUpdate == null ? null : serviceDefOptionsPreUpdate.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							if (preUpdateValue == null) {
								serviceDefOptionsPostUpdate.remove(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							} else {
								serviceDefOptionsPostUpdate.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, preUpdateValue);
							}
							xXServiceDefObj.setDefOptions(mapToJsonString(serviceDefOptionsPostUpdate));
							daoMgr.getXXServiceDef().update(xXServiceDefObj);
						}
					}
				}
			}
		}
		}catch(Exception e)
		{
			logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def", e);
		}
}
 
Example 10
Source File: PatchForKafkaServiceDefUpdate_J10025.java    From ranger with Apache License 2.0 4 votes vote down vote up
private void updateKafkaServiceDef(){
	RangerServiceDef ret                = null;
	RangerServiceDef embeddedKafkaServiceDef = null;
	RangerServiceDef dbKafkaServiceDef         = null;
	List<RangerServiceDef.RangerResourceDef>   embeddedKafkaResourceDefs  = null;
	List<RangerServiceDef.RangerAccessTypeDef>     embeddedKafkaAccessTypes   = null;
	XXServiceDef xXServiceDefObj         = null;
	try{
		embeddedKafkaServiceDef=EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
		if(embeddedKafkaServiceDef!=null){

			xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
			Map<String, String> serviceDefOptionsPreUpdate=null;
			String jsonStrPreUpdate=null;
			if(xXServiceDefObj!=null) {
				jsonStrPreUpdate=xXServiceDefObj.getDefOptions();
				serviceDefOptionsPreUpdate=jsonStringToMap(jsonStrPreUpdate);
				xXServiceDefObj=null;
			}
			dbKafkaServiceDef=svcDBStore.getServiceDefByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);

			if(dbKafkaServiceDef!=null){
				embeddedKafkaResourceDefs = embeddedKafkaServiceDef.getResources();
				embeddedKafkaAccessTypes  = embeddedKafkaServiceDef.getAccessTypes();

				if (checkNewKafkaresourcePresent(embeddedKafkaResourceDefs)) {
					// This is to check if CLUSTER resource is added to the resource definition, if so update the resource def and accessType def
					if (embeddedKafkaResourceDefs != null) {
						dbKafkaServiceDef.setResources(embeddedKafkaResourceDefs);
					}
					if (embeddedKafkaAccessTypes != null) {
						if(!embeddedKafkaAccessTypes.toString().equalsIgnoreCase(dbKafkaServiceDef.getAccessTypes().toString())) {
							dbKafkaServiceDef.setAccessTypes(embeddedKafkaAccessTypes);
						}
					}
				}

				RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
				validator.validate(dbKafkaServiceDef, Action.UPDATE);

				ret = svcStore.updateServiceDef(dbKafkaServiceDef);
				if(ret==null){
					logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def");
					throw new RuntimeException("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def");
				}
				xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME);
				if(xXServiceDefObj!=null) {
					String jsonStrPostUpdate=xXServiceDefObj.getDefOptions();
					Map<String, String> serviceDefOptionsPostUpdate=jsonStringToMap(jsonStrPostUpdate);
					if (serviceDefOptionsPostUpdate != null && serviceDefOptionsPostUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
						if(serviceDefOptionsPreUpdate == null || !serviceDefOptionsPreUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
							String preUpdateValue = serviceDefOptionsPreUpdate == null ? null : serviceDefOptionsPreUpdate.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							if (preUpdateValue == null) {
								serviceDefOptionsPostUpdate.remove(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
							} else {
								serviceDefOptionsPostUpdate.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, preUpdateValue);
							}
							xXServiceDefObj.setDefOptions(mapToJsonString(serviceDefOptionsPostUpdate));
							daoMgr.getXXServiceDef().update(xXServiceDefObj);
						}
					}
					createDefaultPolicyForNewResources();
				}
			}
		}
	}catch(Exception e)
	{
		logger.error("Error while updating "+SERVICEDBSTORE_SERVICEDEFBYNAME_KAFKA_NAME+"service-def", e);
	}
}
 
Example 11
Source File: PatchForPrestoToSupportPresto333_J10038.java    From ranger with Apache License 2.0 4 votes vote down vote up
private void addPresto333Support() throws Exception {
  RangerServiceDef ret = null;
  RangerServiceDef embeddedPrestoServiceDef = null;
  XXServiceDef xXServiceDefObj = null;
  RangerServiceDef dbPrestoServiceDef = null;
  List<RangerServiceDef.RangerResourceDef> embeddedPrestoResourceDefs = null;
  List<RangerServiceDef.RangerAccessTypeDef> embeddedPrestoAccessTypes = null;

  embeddedPrestoServiceDef = EmbeddedServiceDefsUtil.instance()
    .getEmbeddedServiceDef(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_PRESTO_NAME);

  if (embeddedPrestoServiceDef != null) {
    xXServiceDefObj = daoMgr.getXXServiceDef()
      .findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_PRESTO_NAME);
    if (xXServiceDefObj == null) {
      logger.info(xXServiceDefObj + ": service-def not found. No patching is needed");
      return;
    }

    dbPrestoServiceDef = svcDBStore.getServiceDefByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_PRESTO_NAME);

    embeddedPrestoResourceDefs = embeddedPrestoServiceDef.getResources();
    embeddedPrestoAccessTypes = embeddedPrestoServiceDef.getAccessTypes();
    if (checkResourcePresent(PRESTO_RESOURCES, embeddedPrestoResourceDefs)) {
      dbPrestoServiceDef.setResources(embeddedPrestoResourceDefs);
      if (checkAccessPresent(PRESTO_ACCESS_TYPES, embeddedPrestoAccessTypes)) {
        dbPrestoServiceDef.setAccessTypes(embeddedPrestoAccessTypes);
      }
    }

    RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
    validator.validate(dbPrestoServiceDef, RangerValidator.Action.UPDATE);
    ret = svcStore.updateServiceDef(dbPrestoServiceDef);
    if (ret == null) {
      logger.error("Error while updating " + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME
        + " service-def");
      throw new RuntimeException("Error while updating "
        + EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_ATLAS_NAME + " service-def");
    }

  }
}