Beispiel #1
0
 public void execute(Context context) {
   Set<String> applications = new HashSet<String>();
   Set<String> services = new HashSet<String>();
   List<Provider> pList = new ArrayList<Provider>();
   try {
     pList = providerService.findAll();
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   }
   for (Provider p : pList) {
     applications.add(p.getApplication());
     services.add(p.getService());
   }
   List<Consumer> cList = new ArrayList<Consumer>();
   try {
     cList = consumerService.findAll();
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   }
   for (Consumer c : cList) {
     applications.add(c.getApplication());
     services.add(c.getService());
   }
   context.put("rootContextPath", new RootContextPath(request.getContextPath()));
   context.put("services", services.size());
   context.put("providers", pList.size());
   context.put("consumers", cList.size());
   context.put("applications", applications.size());
 }
Beispiel #2
0
 private List<Owner> toOverrideLiset(List<Provider> pList, List<Override> cList) {
   Map<String, Owner> oList = new HashMap<String, Owner>();
   for (Provider p : pList) {
     if (p.getUsername() != null) {
       for (String username : Constants.COMMA_SPLIT_PATTERN.split(p.getUsername())) {
         Owner o = new Owner();
         o.setService(p.getService());
         o.setUsername(username);
         oList.put(o.getService() + "/" + o.getUsername(), o);
       }
     }
   }
   for (Override c : cList) {
     Map<String, String> params = StringUtils.parseQueryString(c.getParams());
     String usernames = params.get("owner");
     if (usernames != null && usernames.length() > 0) {
       for (String username : Constants.COMMA_SPLIT_PATTERN.split(usernames)) {
         Owner o = new Owner();
         o.setService(c.getService());
         o.setUsername(username);
         oList.put(o.getService() + "/" + o.getUsername(), o);
       }
     }
   }
   return new ArrayList<Owner>(oList.values());
 }
  public void disableProvider(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 + "=true");
        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("false")) {
            overrideService.deleteOverride(o.getId());
          }
        }
      }
    } else {
      oldProvider.setEnabled(false);
      updateProvider(oldProvider);
    }
  }