Java源码示例:com.netflix.config.PollResult

示例1
@Test
public void testPullFroGivenURL() throws Exception {
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  URL test1URL = loader.getResource("test1.yaml");
  URL test2URL = loader.getResource("test2.yaml");
  System.setProperty("servicecomb.configurationSource.additionalUrls", test1URL.toString() + "," + test2URL.toString());
  MicroserviceConfigurationSource configSource = yamlConfigSource();
  PollResult result = configSource.poll(true, null);
  Map<String, Object> configMap = result.getComplete();

  assertEquals(3, configSource.getConfigModels().size());
  assertNotNull(configMap);
  assertEquals(36, configMap.size());
  assertNotNull(configMap.get("trace.handler.sampler.percent"));
  assertEquals(0.5, configMap.get("trace.handler.sampler.percent"));

  System.getProperties().remove("servicecomb.configurationSource.additionalUrls");
}
 
示例2
@Override
public PollResult poll(boolean initial, Object checkPoint) throws Exception {
  Map<String, Object> result = new HashMap<>();
  environment
      .getPropertySources()
      .iterator()
      .forEachRemaining(
          source -> {
            if (source instanceof EnumerablePropertySource) {
              EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
              for (String key : enumerable.getPropertyNames()) {
                result.putIfAbsent(key, enumerable.getProperty(key));
              }
            }
          });
  return PollResult.createFull(result);
}
 
示例3
public PollResult poll(boolean b, Object o) throws Exception {
  Map<String, Object> configurations = new LinkedHashMap<>();

  for (ConfigModel configModel : configModels) {
    configurations.putAll(YAMLUtil.retrieveItems("", configModel.getConfig()));
  }

  return PollResult.createFull(configurations);
}
 
示例4
@Test
public void testPullFromClassPath() throws Exception {
  MicroserviceConfigurationSource configSource = yamlConfigSource();
  PollResult result = configSource.poll(true, null);
  Map<String, Object> configMap = result.getComplete();
  assertNotNull(configMap);
  assertEquals(25, configMap.size());
  assertNotNull(configMap.get("trace.handler.sampler.percent"));
  assertEquals(0.5, configMap.get("trace.handler.sampler.percent"));
}
 
示例5
@Override
public PollResult poll(boolean initial, Object checkPoint) throws Exception {
    return PollResult.createFull(
            secretsGroup.stream().filter(Config.active()).reverse().uniquePrimaryKey().toJavaStream().
            collect(Collectors.toMap(e -> secretsGroup.srn(e.secretIdentifier).toSrn(), e -> e.toJsonBlob())
            ));
}
 
示例6
public PollResult poll(boolean initial, Object checkPoint) throws Exception {
			LOG.info("Poll policy from eagle service " +  config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST) +
					":" + config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT) );
			Map<String, Map<String, AlertDefinitionAPIEntity>> newAlertDefs = 
					dao.findActiveAlertDefsGroupbyAlertExecutorId(config.getString("eagleProps.site"),
                            config.getString("eagleProps.dataSource"));
			
			// compare runtime alertDefs with cachedAlertDefs and figure out what are added/deleted/updated
			Map<String, Object> added = new HashMap<String, Object>();
			Map<String, Object> changed = new HashMap<String, Object>();
			Map<String, Object> deleted = new HashMap<String, Object>();
			
			Set<String> newAlertExecutorIds = newAlertDefs.keySet();
			Set<String> cachedAlertExecutorIds = cachedAlertDefs.keySet();
			
			// dynamically adding new alert executor is not supported, because alert executor is pre-built while program starts up
			Collection<String> addedAlertExecutorIds = CollectionUtils.subtract(newAlertExecutorIds, cachedAlertExecutorIds);
			if(addedAlertExecutorIds != null && addedAlertExecutorIds.size() > 0){
				LOG.warn("New alertExecutorIds are found : " + addedAlertExecutorIds);
			}
			
			// if one alert executor is missing, it means all policy under that alert executor should be removed
			Collection<String> deletedAlertExecutorIds = CollectionUtils.subtract(cachedAlertExecutorIds, newAlertExecutorIds);
			if(deletedAlertExecutorIds != null && deletedAlertExecutorIds.size() > 0){
				LOG.warn("Some alertExecutorIds are deleted : " + deletedAlertExecutorIds);
				for(String deletedAlertExecutorId : deletedAlertExecutorIds){
					deleted.put(deletedAlertExecutorId, cachedAlertDefs.get(deletedAlertExecutorId));
				}
			}
			
			// we need calculate added/updated/deleted policy for all executors which are not deleted
//			Collection<String> updatedAlertExecutorIds = CollectionUtils.intersection(newAlertExecutorIds, cachedAlertExecutorIds);
            Collection<String> updatedAlertExecutorIds = newAlertExecutorIds;
			for(String updatedAlertExecutorId : updatedAlertExecutorIds){
				Map<String, AlertDefinitionAPIEntity> newPolicies = newAlertDefs.get(updatedAlertExecutorId);
				Map<String, AlertDefinitionAPIEntity> cachedPolicies = cachedAlertDefs.get(updatedAlertExecutorId);
				PolicyComparator.compare(updatedAlertExecutorId, newPolicies, cachedPolicies, added, changed, deleted);
			}
			
			cachedAlertDefs = newAlertDefs;
			return PollResult.createIncremental(added, changed, deleted, new Date().getTime());
		}