com.alibaba.dubbo.registry.common.domain.Override Java Examples
The following examples show how to use
com.alibaba.dubbo.registry.common.domain.Override.
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: OverrideUtils.java From dubbo3 with Apache License 2.0 | 6 votes |
public int compare(Override o1, Override o2) { if (o1 == null && o2 == null) { return 0; } if (o1 == null) { return -1; } if (o2 == null) { return 1; } int cmp = cmp(o1.getAddress(), o2.getAddress()); if (cmp != 0) { return cmp; } cmp = cmp(o1.getApplication(), o2.getApplication()); if (cmp != 0) { return cmp; } return cmp(o1.getService(), o2.getService()); }
Example #2
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 6 votes |
public static List<Weight> overridesToWeights(List<Override> overrides){ List<Weight> weights = new ArrayList<Weight>(); if(overrides == null){ return weights; } for(Override o : overrides){ if(StringUtils.isEmpty(o.getParams())){ continue; }else{ Map<String,String> params = StringUtils.parseQueryString(o.getParams()); for(Map.Entry<String, String> entry : params.entrySet()){ if(entry.getKey().equals("weight")){ Weight weight = new Weight(); weight.setAddress(o.getAddress()); weight.setId(o.getId()); weight.setService(o.getService()); weight.setWeight(Integer.valueOf(entry.getValue())); weights.add(weight); } } } } return weights; }
Example #3
Source File: OverrideUtils.java From dubbo3 with Apache License 2.0 | 6 votes |
public static List<Weight> overridesToWeights(List<Override> overrides){ List<Weight> weights = new ArrayList<Weight>(); if(overrides == null){ return weights; } for(Override o : overrides){ if(StringUtils.isEmpty(o.getParams())){ continue; }else{ Map<String,String> params = StringUtils.parseQueryString(o.getParams()); for(Map.Entry<String, String> entry : params.entrySet()){ if(entry.getKey().equals("weight")){ Weight weight = new Weight(); weight.setAddress(o.getAddress()); weight.setId(o.getId()); weight.setService(o.getService()); weight.setWeight(Integer.valueOf(entry.getValue())); weights.add(weight); } } } } return weights; }
Example #4
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 6 votes |
public int compare(Override o1, Override o2) { if (o1 == null && o2 == null) { return 0; } if (o1 == null) { return -1; } if (o2 == null) { return 1; } int cmp = cmp(o1.getAddress(), o2.getAddress()); if (cmp != 0) { return cmp; } cmp = cmp(o1.getApplication(), o2.getApplication()); if (cmp != 0) { return cmp; } return cmp(o1.getService(), o2.getService()); }
Example #5
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 6 votes |
public int compare(Override o1, Override o2) { if (o1 == null && o2 == null) { return 0; } if (o1 == null) { return -1; } if (o2 == null) { return 1; } int cmp = cmp(o1.getAddress(), o2.getAddress()); if (cmp != 0) { return cmp; } cmp = cmp(o1.getApplication(), o2.getApplication()); if (cmp != 0) { return cmp; } return cmp(o1.getService(), o2.getService()); }
Example #6
Source File: OverrideUtils.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public static void setProviderOverrides(Provider provider, List<Override> overrides) { if (provider == null || overrides == null) { return; } List<Override> result = new ArrayList<Override>(overrides.size()); for(Override override : overrides){ if (! override.isEnabled()) { continue; } if (override.isMatch(provider)) { result.add(override); } if (override.isUniqueMatch(provider)) { provider.setOverride(override); } } provider.setOverrides(overrides); }
Example #7
Source File: Overrides.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public void index(Map<String, Object> context) { String service = (String) context.get("service"); String application = (String) context.get("application"); String address = (String) context.get("address"); List<Override> overrides; if (StringUtils.isNotEmpty(service)) { overrides = overrideService.findByService(service); } else if(StringUtils.isNotEmpty(application)){ overrides = overrideService.findByApplication(application); }else if(StringUtils.isNotEmpty(address)){ overrides = overrideService.findByAddress(address); } else{ overrides = overrideService.findAll(); } context.put("overrides", overrides); }
Example #8
Source File: Overrides.java From dubbo3 with Apache License 2.0 | 6 votes |
public void index(Map<String, Object> context) { String service = (String) context.get("service"); String application = (String) context.get("application"); String address = (String) context.get("address"); List<Override> overrides; if (StringUtils.isNotEmpty(service)) { overrides = overrideService.findByService(service); } else if(StringUtils.isNotEmpty(application)){ overrides = overrideService.findByApplication(application); }else if(StringUtils.isNotEmpty(address)){ overrides = overrideService.findByAddress(address); } else{ overrides = overrideService.findAll(); } context.put("overrides", overrides); }
Example #9
Source File: OverrideServiceImpl.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void updateOverride(Override override) { Long id = override.getId(); if(id == null) { throw new IllegalStateException("no override id"); } URL oldOverride = findOverrideUrl(id); if(oldOverride == null) { throw new IllegalStateException("Route was changed!"); } URL newOverride = getUrlFromOverride(override); registryService.unregister(oldOverride); registryService.register(newOverride); }
Example #10
Source File: OverrideUtils.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public static Override weightToOverride(Weight weight){ Override override = new Override(); override.setId(weight.getId()); override.setAddress(weight.getAddress()); override.setEnabled(true); override.setParams("weight=" + weight.getWeight()); override.setService(weight.getService()); return override; }
Example #11
Source File: ProviderServiceImpl.java From dubbox with Apache License 2.0 | 5 votes |
public void enableProvider(Long id) { if(id == null) { throw new IllegalStateException("no provider id"); } Provider oldProvider = findProvider(id); if(oldProvider == null) { throw new IllegalStateException("Provider was changed!"); } if (oldProvider.isDynamic()) { //保证disable的override唯一 if(!oldProvider.isEnabled()){ Override override = new Override(); override.setAddress(oldProvider.getAddress()); override.setService(oldProvider.getService()); override.setEnabled(true); override.setParams(Constants.DISABLED_KEY+"=false"); overrideService.saveOverride(override); return; } List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress()); for(Override o : oList){ Map<String, String> params = StringUtils.parseQueryString(o.getParams()); if(params.containsKey(Constants.DISABLED_KEY)){ if(params.get(Constants.DISABLED_KEY) .equals("true")){ overrideService.deleteOverride(o.getId()); } } } } else { oldProvider.setEnabled(true); updateProvider(oldProvider); } }
Example #12
Source File: ProviderServiceImpl.java From dubbox with Apache License 2.0 | 5 votes |
public void enableProvider(Long id) { if(id == null) { throw new IllegalStateException("no provider id"); } Provider oldProvider = findProvider(id); if(oldProvider == null) { throw new IllegalStateException("Provider was changed!"); } if (oldProvider.isDynamic()) { //保证disable的override唯一 if(!oldProvider.isEnabled()){ Override override = new Override(); override.setAddress(oldProvider.getAddress()); override.setService(oldProvider.getService()); override.setEnabled(true); override.setParams(Constants.DISABLED_KEY+"=false"); overrideService.saveOverride(override); return; } List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress()); for(Override o : oList){ Map<String, String> params = StringUtils.parseQueryString(o.getParams()); if(params.containsKey(Constants.DISABLED_KEY)){ if(params.get(Constants.DISABLED_KEY) .equals("true")){ overrideService.deleteOverride(o.getId()); } } } } else { oldProvider.setEnabled(true); updateProvider(oldProvider); } }
Example #13
Source File: Tool.java From dubbox with Apache License 2.0 | 5 votes |
public String getOverridesMock(List<Override> overrides){ if(overrides != null && overrides.size() > 0) { for(Override override : overrides) { Map<String, String> params = StringUtils.parseQueryString(override.getParams()); String mock = params.get("mock"); if (mock != null && mock.length() > 0) { return mock; } } } return ""; }
Example #14
Source File: Overrides.java From dubbox with Apache License 2.0 | 5 votes |
public void show(Long id, Map<String, Object> context) { Override override = overrideService.findById(id); Map<String, String> parameters = parseQueryString(override.getParams()); if(parameters.get(DEFAULT_MOCK_JSON_KEY) != null) { String mock = URL.decode(parameters.get(DEFAULT_MOCK_JSON_KEY)); String[] tokens = parseMock(mock); context.put(FORM_DEFAULT_MOCK_METHOD_FORCE, tokens[0]); context.put(FORM_DEFAULT_MOCK_METHOD_JSON, tokens[1]); parameters.remove(DEFAULT_MOCK_JSON_KEY); } Map<String, String> method2Force = new LinkedHashMap<String, String>(); Map<String, String> method2Json = new LinkedHashMap<String, String>(); for (Iterator<Map.Entry<String, String>> iterator = parameters.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, String> e = iterator.next(); String key = e.getKey(); if(key.endsWith(MOCK_JSON_KEY_POSTFIX)) { String m = key.substring(0, key.length() - MOCK_JSON_KEY_POSTFIX.length()); parseMock(m, e.getValue(), method2Force, method2Json); iterator.remove(); } } context.put("methodForces", method2Force); context.put("methodJsons", method2Json); context.put("parameters", parameters); context.put("override", override); }
Example #15
Source File: Tool.java From dubbox with Apache License 2.0 | 5 votes |
public static int getProviderWeight(Provider provider, List<Override> oList) { for(Override o : oList){ if (o.isMatch(provider)) { Map<String, String> params = StringUtils.parseQueryString(o.getParams()); String weight = params.get(Constants.WEIGHT_KEY); if(weight != null && weight.length() > 0){ return Integer.parseInt(weight); } } } return provider.getWeight(); }
Example #16
Source File: Tool.java From dubbox with Apache License 2.0 | 5 votes |
public static boolean isProviderEnabled(Provider provider, List<Override> oList){ for(Override o : oList){ if (o.isMatch(provider)) { Map<String, String> params = StringUtils.parseQueryString(o.getParams()); String disbaled = params.get(Constants.DISABLED_KEY); if(disbaled != null && disbaled.length() > 0){ return ! "true".equals(disbaled); } } } return provider.isEnabled(); }
Example #17
Source File: Providers.java From dubbox with Apache License 2.0 | 5 votes |
public void show(Long id, Map<String, Object> context) { Provider provider = providerService.findProvider(id); if (provider != null && provider.isDynamic()) { List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress()); OverrideUtils.setProviderOverrides(provider, overrides); } context.put("provider", provider); }
Example #18
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static Override weightToOverride(Weight weight){ Override override = new Override(); override.setId(weight.getId()); override.setAddress(weight.getAddress()); override.setEnabled(true); override.setParams("weight=" + weight.getWeight()); override.setService(weight.getService()); return override; }
Example #19
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static List<LoadBalance> overridesToLoadBalances(List<Override> overrides){ List<LoadBalance> loadBalances = new ArrayList<LoadBalance>(); if(overrides == null){ return loadBalances; } for(Override o : overrides){ if(StringUtils.isEmpty(o.getParams())){ continue; }else{ Map<String,String> params = StringUtils.parseQueryString(o.getParams()); for(Map.Entry<String, String> entry : params.entrySet()){ if(entry.getKey().endsWith("loadbalance")){ LoadBalance loadBalance = new LoadBalance(); String method = null; if(entry.getKey().endsWith(".loadbalance")){ method = entry.getKey().split(".loadbalance")[0]; }else{ method = "*"; } loadBalance.setMethod(method); loadBalance.setId(o.getId()); loadBalance.setService(o.getService()); loadBalance.setStrategy(entry.getValue()); loadBalances.add(loadBalance); } } } } return loadBalances; }
Example #20
Source File: OverrideServiceImpl.java From dubbo3 with Apache License 2.0 | 5 votes |
public void updateOverride(Override override) { Long id = override.getId(); if(id == null) { throw new IllegalStateException("no override id"); } URL oldOverride = findOverrideUrl(id); if(oldOverride == null) { throw new IllegalStateException("Route was changed!"); } URL newOverride = getUrlFromOverride(override); registryService.unregister(oldOverride); registryService.register(newOverride); }
Example #21
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static Override loadBalanceToOverride(LoadBalance loadBalance){ Override override = new Override(); override.setId(loadBalance.getId()); override.setService(loadBalance.getService()); override.setEnabled(true); String method = loadBalance.getMethod(); String strategy = loadBalance.getStrategy(); if(StringUtils.isEmpty(method) ||method.equals("*")){ override.setParams("loadbalance=" + strategy); }else{ override.setParams(method + ".loadbalance=" + strategy); } return override; }
Example #22
Source File: Overrides.java From dubbo3 with Apache License 2.0 | 5 votes |
public void show(Long id, Map<String, Object> context) { Override override = overrideService.findById(id); Map<String, String> parameters = parseQueryString(override.getParams()); if(parameters.get(DEFAULT_MOCK_JSON_KEY) != null) { String mock = URL.decode(parameters.get(DEFAULT_MOCK_JSON_KEY)); String[] tokens = parseMock(mock); context.put(FORM_DEFAULT_MOCK_METHOD_FORCE, tokens[0]); context.put(FORM_DEFAULT_MOCK_METHOD_JSON, tokens[1]); parameters.remove(DEFAULT_MOCK_JSON_KEY); } Map<String, String> method2Force = new LinkedHashMap<String, String>(); Map<String, String> method2Json = new LinkedHashMap<String, String>(); for (Iterator<Map.Entry<String, String>> iterator = parameters.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, String> e = iterator.next(); String key = e.getKey(); if(key.endsWith(MOCK_JSON_KEY_POSTFIX)) { String m = key.substring(0, key.length() - MOCK_JSON_KEY_POSTFIX.length()); parseMock(m, e.getValue(), method2Force, method2Json); iterator.remove(); } } context.put("methodForces", method2Force); context.put("methodJsons", method2Json); context.put("parameters", parameters); context.put("override", override); }
Example #23
Source File: Overrides.java From dubbox with Apache License 2.0 | 5 votes |
public boolean update(Override override,Map<String, Object> context) { Override o = overrideService.findById(override.getId()); override.setService(o.getService()); override.setAddress(o.getAddress()); override.setApplication(o.getApplication()); if(!catchParams(override, context)) return false; overrideService.updateOverride(override); return true; }
Example #24
Source File: Overrides.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void show(Long id, Map<String, Object> context) { Override override = overrideService.findById(id); Map<String, String> parameters = parseQueryString(override.getParams()); if(parameters.get(DEFAULT_MOCK_JSON_KEY) != null) { String mock = URL.decode(parameters.get(DEFAULT_MOCK_JSON_KEY)); String[] tokens = parseMock(mock); context.put(FORM_DEFAULT_MOCK_METHOD_FORCE, tokens[0]); context.put(FORM_DEFAULT_MOCK_METHOD_JSON, tokens[1]); parameters.remove(DEFAULT_MOCK_JSON_KEY); } Map<String, String> method2Force = new LinkedHashMap<String, String>(); Map<String, String> method2Json = new LinkedHashMap<String, String>(); for (Iterator<Map.Entry<String, String>> iterator = parameters.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, String> e = iterator.next(); String key = e.getKey(); if(key.endsWith(MOCK_JSON_KEY_POSTFIX)) { String m = key.substring(0, key.length() - MOCK_JSON_KEY_POSTFIX.length()); parseMock(m, e.getValue(), method2Force, method2Json); iterator.remove(); } } context.put("methodForces", method2Force); context.put("methodJsons", method2Json); context.put("parameters", parameters); context.put("override", override); }
Example #25
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static Override loadBalanceToOverride(LoadBalance loadBalance){ Override override = new Override(); override.setId(loadBalance.getId()); override.setService(loadBalance.getService()); override.setEnabled(true); String method = loadBalance.getMethod(); String strategy = loadBalance.getStrategy(); if(StringUtils.isEmpty(method) ||method.equals("*")){ override.setParams("loadbalance=" + strategy); }else{ override.setParams(method + ".loadbalance=" + strategy); } return override; }
Example #26
Source File: Overrides.java From dubbox with Apache License 2.0 | 5 votes |
public boolean update(Override override,Map<String, Object> context) { Override o = overrideService.findById(override.getId()); override.setService(o.getService()); override.setAddress(o.getAddress()); override.setApplication(o.getApplication()); if(!catchParams(override, context)) return false; overrideService.updateOverride(override); return true; }
Example #27
Source File: Providers.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void show(Long id, Map<String, Object> context) { Provider provider = providerService.findProvider(id); if (provider != null && provider.isDynamic()) { List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress()); OverrideUtils.setProviderOverrides(provider, overrides); } context.put("provider", provider); }
Example #28
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static Override loadBalanceToOverride(LoadBalance loadBalance){ Override override = new Override(); override.setId(loadBalance.getId()); override.setService(loadBalance.getService()); override.setEnabled(true); String method = loadBalance.getMethod(); String strategy = loadBalance.getStrategy(); if(StringUtils.isEmpty(method) ||method.equals("*")){ override.setParams("loadbalance=" + strategy); }else{ override.setParams(method + ".loadbalance=" + strategy); } return override; }
Example #29
Source File: Tool.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public static int getProviderWeight(Provider provider, List<Override> oList) { for(Override o : oList){ if (o.isMatch(provider)) { Map<String, String> params = StringUtils.parseQueryString(o.getParams()); String weight = params.get(Constants.WEIGHT_KEY); if(weight != null && weight.length() > 0){ return Integer.parseInt(weight); } } } return provider.getWeight(); }
Example #30
Source File: Tool.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public static boolean isProviderEnabled(Provider provider, List<Override> oList){ for(Override o : oList){ if (o.isMatch(provider)) { Map<String, String> params = StringUtils.parseQueryString(o.getParams()); String disbaled = params.get(Constants.DISABLED_KEY); if(disbaled != null && disbaled.length() > 0){ return ! "true".equals(disbaled); } } } return provider.isEnabled(); }