com.netflix.config.DynamicStringProperty Java Examples

The following examples show how to use com.netflix.config.DynamicStringProperty. 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: RouterRuleCache.java    From spring-cloud-huawei with Apache License 2.0 6 votes vote down vote up
/**
 * 每次序列化额外缓存,配置更新时触发回调函数 返回false即初始化规则失败: 1. 规则解析错误 2. 规则为空
 *
 * @param targetServiceName
 * @return
 */
public static boolean doInit(String targetServiceName) {
  if (!isServerContainRule(targetServiceName)) {
    return false;
  }
  if (!serviceInfoCacheMap.containsKey(targetServiceName)) {
    synchronized (servicePool.intern(targetServiceName)) {
      if (serviceInfoCacheMap.containsKey(targetServiceName)) {
        return true;
      }
      //Yaml not thread-safe
      DynamicStringProperty ruleStr = DynamicPropertyFactory.getInstance().getStringProperty(
          String.format(ROUTE_RULE, targetServiceName), null, () -> {
            refresh(targetServiceName);
            DynamicStringProperty tepRuleStr = DynamicPropertyFactory.getInstance()
                .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
            addAllRule(targetServiceName, tepRuleStr.get());
          });
      return addAllRule(targetServiceName, ruleStr.get());
    }
  }
  return true;
}
 
Example #2
Source File: SurgicalDebugFilter.java    From zuul with Apache License 2.0 6 votes vote down vote up
@Override
public HttpRequestMessage apply(HttpRequestMessage request) {
    DynamicStringProperty routeVip = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_VIP, null);
    DynamicStringProperty routeHost = new DynamicStringProperty(ZuulConstants.ZUUL_DEBUG_HOST, null);

    SessionContext ctx = request.getContext();

    if (routeVip.get() != null || routeHost.get() != null) {

        ctx.set("routeHost", routeHost.get());
        ctx.set("routeVIP", routeVip.get());

        request.getHeaders().set(ZuulHeaders.X_ZUUL_SURGICAL_FILTER, "true");

        HttpQueryParams queryParams = request.getQueryParams();
        queryParams.set("debugRequest", "true");

        ctx.setDebugRequest(true);
        ctx.set("zuulToZuul", true);

    }
    return request;
}
 
Example #3
Source File: RouterRuleCache.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
/**
 * cache and register callback return false when: 1. parsing error 2. rule is null
 *
 * @param targetServiceName
 * @return
 */
public static boolean doInit(String targetServiceName) {
  if (!isServerContainRule(targetServiceName)) {
    return false;
  }
  if (!serviceInfoCacheMap.containsKey(targetServiceName)) {
    synchronized (servicePool.intern(targetServiceName)) {
      if (serviceInfoCacheMap.containsKey(targetServiceName)) {
        return true;
      }
      //Yaml not thread-safe
      DynamicStringProperty ruleStr = DynamicPropertyFactory.getInstance().getStringProperty(
          String.format(ROUTE_RULE, targetServiceName), null, () -> {
            refresh(targetServiceName);
            DynamicStringProperty tepRuleStr = DynamicPropertyFactory.getInstance()
                .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
            addAllRule(targetServiceName, tepRuleStr.get());
          });
      return addAllRule(targetServiceName, ruleStr.get());
    }
  }
  return true;
}
 
Example #4
Source File: RouterRuleCache.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
/**
 * if a server don't have rule , avoid registered too many callback , it may cause memory leak
 *
 * @param targetServiceName
 * @return
 */
public static boolean isServerContainRule(String targetServiceName) {
  DynamicStringProperty lookFor = DynamicPropertyFactory.getInstance()
      .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
  if (StringUtils.isEmpty(lookFor.get())) {
    return false;
  }
  return true;
}
 
Example #5
Source File: DynamicPropertySinkConfigurator.java    From suro with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    DynamicStringProperty sinkDescription = new DynamicStringProperty(SINK_PROPERTY, initialSink) {
        @Override
        protected void propertyChanged() {
            buildSink(get(), false);
        }
    };

    buildSink(sinkDescription.get(), true);
}
 
Example #6
Source File: DynamicPropertyRoutingMapConfigurator.java    From suro with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    DynamicStringProperty routingMapFP = new DynamicStringProperty(ROUTING_MAP_PROPERTY, initialRoutingMap) {
        @Override
        protected void propertyChanged() {
            buildMap(get());
        }
    };

    buildMap(routingMapFP.get());
}
 
Example #7
Source File: DynamicPropertyInputConfigurator.java    From suro with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {
    DynamicStringProperty inputFP = new DynamicStringProperty(INPUT_CONFIG_PROPERTY, initialInputConfig) {
        @Override
        protected void propertyChanged() {
            buildInput(get(), false);
        }
    };

    buildInput(inputFP.get(), true);
}
 
Example #8
Source File: EtcdRibbonClientConfiguration.java    From spring-cloud-etcd with Apache License 2.0 5 votes vote down vote up
protected void setProp(String serviceId, String suffix, String value) {
	// how to set the namespace properly?
	String key = getKey(serviceId, suffix);
	DynamicStringProperty property = getProperty(key);
	if (property.get().equals(VALUE_NOT_SET)) {
		ConfigurationManager.getConfigInstance().setProperty(key, value);
	}
}
 
Example #9
Source File: LatticeRibbonClientConfiguration.java    From spring-cloud-lattice with Apache License 2.0 5 votes vote down vote up
protected void setProp(String serviceId, String suffix, String value) {
	// how to set the namespace properly?
	String key = getKey(serviceId, suffix);
	DynamicStringProperty property = getProperty(key);
	if (property.get().equals(VALUE_NOT_SET)) {
		ConfigurationManager.getConfigInstance().setProperty(key, value);
	}
}
 
Example #10
Source File: RouterDistributorTest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private List<ServiceIns> mainFilter(List<ServiceIns> serverlist, Map<String, String> headermap) {
  RouterDistributor<ServiceIns, ServiceIns> testDistributer = new TestDistributer();
  DynamicPropertyFactory dpf = DynamicPropertyFactory.getInstance();
  DynamicStringProperty strp = new DynamicStringProperty("", ruleStr);
  new Expectations(dpf) {
    {
      dpf.getStringProperty(anyString, null, (Runnable) any);
      result = strp;
    }
  };
  RouterRuleCache.refresh();
  return RouterFilter
      .getFilteredListOfServers(serverlist, targetServiceName, headermap,
          testDistributer);
}
 
Example #11
Source File: RouterRuleCache.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
/**
 * if a server don't have rule , avoid registered too many callback , it may cause memory leak
 *
 * @param targetServiceName
 * @return
 */
public static boolean isServerContainRule(String targetServiceName) {
  DynamicStringProperty lookFor = DynamicPropertyFactory.getInstance()
      .getStringProperty(String.format(ROUTE_RULE, targetServiceName), null);
  if (StringUtils.isEmpty(lookFor.get())) {
    return false;
  }
  return true;
}
 
Example #12
Source File: RouterInvokeFilter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
/**
 * read config and get Header
 */
private boolean loadHeaders() {
  if (!CollectionUtils.isEmpty(allHeader)) {
    return true;
  }
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null, () -> {
        DynamicStringProperty temHeader = DynamicPropertyFactory.getInstance()
            .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
        if (!addAllHeaders(temHeader.get())) {
          allHeader = new ArrayList<>();
        }
      });
  return addAllHeaders(headerStr.get());
}
 
Example #13
Source File: RouterDistributorTest.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private List<ServiceIns> mainFilter(List<ServiceIns> serverlist, Map<String, String> headermap) {
  TestDistributer TestDistributer = new TestDistributer();
  DynamicPropertyFactory dpf = DynamicPropertyFactory.getInstance();
  DynamicStringProperty strp = new DynamicStringProperty("", ruleStr);
  new Expectations(dpf) {
    {
      dpf.getStringProperty(anyString, null, (Runnable) any);
      result = strp;
    }
  };
  RouterRuleCache.refresh();
  return RouterFilter
      .getFilteredListOfServers(serverlist, targetServiceName, headermap,
          TestDistributer);
}
 
Example #14
Source File: HeaderPassUtil.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private static boolean isHaveHeadersRule() {
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
  if (StringUtils.isEmpty(headerStr)) {
    return false;
  }
  return true;
}
 
Example #15
Source File: HeaderPassUtil.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private static boolean loadHeaders() {
  if (!CollectionUtils.isEmpty(passHeader)) {
    return true;
  }
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null, () -> {
        DynamicStringProperty temHeader = DynamicPropertyFactory.getInstance()
            .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
        if (!addAllHeaders(temHeader.get())) {
          passHeader = new ArrayList<>();
        }
      });
  return addAllHeaders(headerStr.get());
}
 
Example #16
Source File: InitializeServletListener.java    From s2g-zuul with MIT License 5 votes vote down vote up
private void registerEureka() {
	DynamicBooleanProperty eurekaEnabled = DynamicPropertyFactory.getInstance().getBooleanProperty("eureka.enabled",
			true);
	if (!eurekaEnabled.get())
		return;

	EurekaInstanceConfig eurekaInstanceConfig = new PropertiesInstanceConfig() {
	};
       ConfigurationManager.getConfigInstance().setProperty("eureka.statusPageUrl","http://"+ getTurbineInstance());

	DiscoveryManager.getInstance().initComponent(eurekaInstanceConfig, new DefaultEurekaClientConfig());

	final DynamicStringProperty serverStatus = DynamicPropertyFactory.getInstance()
			.getStringProperty("server." + IPUtil.getLocalIP() + ".status", "up");
	DiscoveryManager.getInstance().getDiscoveryClient().registerHealthCheckCallback(new HealthCheckCallback() {
		@Override
		public boolean isHealthy() {
			return serverStatus.get().toLowerCase().equals("up");
		}
	});

	String version = String.valueOf(System.currentTimeMillis());
	String group = ConfigurationManager.getConfigInstance().getString("server.group", "default");
	String dataCenter = ConfigurationManager.getConfigInstance().getString("server.data-center", "default");

	Map<String, String> metadata = new HashMap<String, String>();
	metadata.put("version", version);
	metadata.put("group", group);
	metadata.put("dataCenter", dataCenter);

	String turbineInstance = getTurbineInstance();
	if (turbineInstance != null) {
		metadata.put("turbine.instance", turbineInstance);
	}

	ApplicationInfoManager.getInstance().registerAppMetadata(metadata);
}
 
Example #17
Source File: RouterInvokeFilter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
/**
 * if don't have headers rule , avoid registered too many callback
 */
private boolean isHaveHeadersRule() {
  DynamicStringProperty headerStr = DynamicPropertyFactory.getInstance()
      .getStringProperty(SERVICECOMB_ROUTER_HEADER, null);
  if (StringUtils.isEmpty(headerStr)) {
    return false;
  }
  return true;
}
 
Example #18
Source File: TransportConfig.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public static String getAddress() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.rest.address", null);
  return address.get();
}
 
Example #19
Source File: HighwayConfig.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public static String getAddress() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.highway.address", null);
  return address.get();
}
 
Example #20
Source File: ConfigSubscriber.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
@Override
public String getString(String key, String defaultValue, Runnable callback) {
    final DynamicStringProperty property = DynamicPropertyFactory.getInstance().getStringProperty(key, defaultValue, callback);
    return property.get();
}
 
Example #21
Source File: ServiceRegistryConfigBuilder.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public HttpVersion getHttpVersion() {
  DynamicStringProperty property =
      DynamicPropertyFactory.getInstance()
          .getStringProperty("servicecomb.service.registry.client.httpVersion", "HTTP_1_1");
  return HttpVersion.valueOf(property.get());
}
 
Example #22
Source File: LatticeRibbonClientConfiguration.java    From spring-cloud-lattice with Apache License 2.0 4 votes vote down vote up
protected DynamicStringProperty getProperty(String key) {
	return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET);
}
 
Example #23
Source File: DynamicPropertiesImpl.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public String getStringProperty(String propertyName, Consumer<String> consumer, String defaultValue) {
  DynamicStringProperty prop = propertyFactoryInstance().getStringProperty(propertyName, defaultValue);
  prop.addCallback(() -> consumer.accept(prop.get()));
  return prop.get();
}
 
Example #24
Source File: EtcdRibbonClientConfiguration.java    From spring-cloud-etcd with Apache License 2.0 4 votes vote down vote up
protected DynamicStringProperty getProperty(String key) {
	return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET);
}
 
Example #25
Source File: ArchaiusConnectionPoolConfiguration.java    From dyno with Apache License 2.0 4 votes vote down vote up
public void setDualWriteClusterName(DynamicStringProperty stringProperty) {
    this.dualWriteClusterName = stringProperty;
}
 
Example #26
Source File: ServletConfig.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public static String getServletUrlPattern() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty(KEY_SERVLET_URL_PATTERN, null);
  return address.get();
}
 
Example #27
Source File: ServletConfig.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public static String getLocalServerAddress() {
  DynamicStringProperty address =
      DynamicPropertyFactory.getInstance().getStringProperty(SERVICECOMB_REST_ADDRESS, null);
  return address.get();
}
 
Example #28
Source File: InstanceCacheCheckTask.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public DynamicStringProperty getManualCheckProperty() {
  return manualCheckProperty;
}
 
Example #29
Source File: ConfigSubscriber.java    From AsuraFramework with Apache License 2.0 2 votes vote down vote up
/**
 * @param key
 *         配置项的key
 * @param defaultValue
 *         如果取回的配置项值为空, 应该返回的默认值
 *
 * @return 配置项的值
 */
@Override
public String getString(String key, String defaultValue) {
    final DynamicStringProperty property = DynamicPropertyFactory.getInstance().getStringProperty(key, defaultValue);
    return property.get();
}