示例#1
0
  public static Provider url2Provider(Pair<Long, URL> pair) {
    if (pair == null) {
      return null;
    }

    Long id = pair.getKey();
    URL url = pair.getValue();

    if (url == null) return null;

    Provider p = new Provider();
    p.setId(id);
    p.setService(url.getServiceKey());
    p.setAddress(url.getAddress());
    p.setApplication(url.getParameter(Constants.APPLICATION_KEY));
    p.setUrl(url.toIdentityString());
    p.setParameters(url.toParameterString());

    p.setDynamic(url.getParameter("dynamic", true));
    p.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
    p.setWeight(url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT));
    p.setUsername(url.getParameter("owner"));

    return p;
  }
示例#2
0
  public static Consumer url2Consumer(Pair<Long, URL> pair) {
    if (pair == null) {
      return null;
    }

    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url) return null;

    Consumer c = new Consumer();
    c.setId(id);
    c.setService(url.getServiceKey());
    c.setAddress(url.getHost());
    c.setApplication(url.getParameter(Constants.APPLICATION_KEY));
    c.setParameters(url.toParameterString());

    return c;
  }
示例#3
0
  public static Route url2Route(Pair<Long, URL> pair) {
    if (pair == null) {
      return null;
    }

    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url) return null;

    Route r = new Route();
    r.setId(id);
    r.setName(url.getParameter("name"));
    r.setService(url.getServiceKey());
    r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
    r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
    r.setForce(url.getParameter(Constants.FORCE_KEY, false));
    r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
    return r;
  }
示例#4
0
  public static com.dubbo.domain.Override url2Override(Pair<Long, URL> pair) {
    if (pair == null) {
      return null;
    }

    Long id = pair.getKey();
    URL url = pair.getValue();

    if (null == url) return null;

    Override o = new Override();
    o.setId(id);

    Map<String, String> parameters = new HashMap<String, String>(url.getParameters());

    o.setService(url.getServiceKey());
    parameters.remove(Constants.INTERFACE_KEY);
    parameters.remove(Constants.GROUP_KEY);
    parameters.remove(Constants.VERSION_KEY);
    parameters.remove(Constants.APPLICATION_KEY);
    parameters.remove(Constants.CATEGORY_KEY);
    parameters.remove(Constants.DYNAMIC_KEY);
    parameters.remove(Constants.ENABLED_KEY);

    o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));

    String host = url.getHost();
    boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
    if (!anyhost || !"0.0.0.0".equals(host)) {
      o.setAddress(url.getAddress());
    }

    o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
    parameters.remove(Constants.VERSION_KEY);

    o.setParams(StringUtils.toQueryString(parameters));

    return o;
  }