com.alibaba.dubbo.common.utils.CollectionUtils Java Examples

The following examples show how to use com.alibaba.dubbo.common.utils.CollectionUtils. 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: Overrides.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context){
    List<String> serviceList = new ArrayList<String>();
    List<String> applicationList = new ArrayList<String>();
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    if(StringUtils.isNotEmpty(application)){
        serviceList.addAll(providerService.findServicesByApplication(application));
        serviceList.addAll(consumerService.findServicesByApplication(application));
        context.put("serviceList", serviceList);
    }else if(StringUtils.isNotEmpty(service)){
        applicationList.addAll(providerService.findApplicationsByServiceName(service));
        applicationList.addAll(consumerService.findApplicationsByServiceName(service));
        context.put("applicationList", applicationList);
    }else{
        serviceList.addAll(providerService.findServices());
        serviceList.addAll(consumerService.findServices());
        providerService.findServicesByApplication(application);
        consumerService.findServicesByApplication(application);
    }
    context.put("serviceList", serviceList);
    
    if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    }
}
 
Example #2
Source File: Unregister.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected String doExecute(Map<String,Object> context) throws Exception {
	Map<String, String[]> params = request.getParameterMap();
    if (params == null || params.size() == 0) {
    	throw new IllegalArgumentException("The url parameters is null! Usage: " + request.getRequestURL().toString() + "?com.xxx.XxxService=http://" + operatorAddress + "/xxxService");
    }
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        if (entry.getKey() != null && entry.getKey().length() > 0
                && entry.getValue() != null && entry.getValue().length > 0
                && entry.getValue()[0] != null && entry.getValue()[0].length() > 0) {
            if (! currentUser.hasServicePrivilege(entry.getKey())) {
                throw new IllegalStateException("The user " + operator + " have no privilege of service " + entry.getKey());
            }
            for(Entry<String,String> e : CollectionUtils.split(Arrays.asList(entry.getValue()), "?").entrySet()){
               Provider provider = providervice.findByServiceAndAddress(entry.getKey(), e.getKey());
                if (provider != null) {
                    providervice.deleteStaticProvider(provider.getId());
                }
            }
        }
    }
   
    return "Unregister " + params.size() + " services.";
}
 
Example #3
Source File: Weights.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * load页面供新增操作
 * @param context
 */
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #4
Source File: Loadbalances.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #5
Source File: Weights.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * load页面供新增操作
 * @param context
 */
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #6
Source File: Loadbalances.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #7
Source File: RoutesController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Load new route page
 *
 */
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "add", "routes");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        model.addAttribute("service", service);
        model.addAttribute("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    } else {
        List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
        model.addAttribute("serviceList", serviceList);
    }

    //if (input != null) model.addAttribute("input", input);
    return "governance/screen/routes/add";
}
 
Example #8
Source File: UnregisterController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected String doExecute(Map<String, Object> context) throws Exception {
    Map<String, String[]> params = request.getParameterMap();
    if (params == null || params.size() == 0) {
        throw new IllegalArgumentException("The url parameters is null! Usage: " + request.getRequestURL().toString() + "?com.xxx.XxxService=http://" + operatorAddress + "/xxxService");
    }
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        if (entry.getKey() != null && entry.getKey().length() > 0
                && entry.getValue() != null && entry.getValue().length > 0
                && entry.getValue()[0] != null && entry.getValue()[0].length() > 0) {
            if (!currentUser.hasServicePrivilege(entry.getKey())) {
                throw new IllegalStateException("The user " + operator + " have no privilege of service " + entry.getKey());
            }
            for (Entry<String, String> e : CollectionUtils.split(Arrays.asList(entry.getValue()), "?").entrySet()) {
                Provider provider = providervice.findByServiceAndAddress(entry.getKey(), e.getKey());
                if (provider != null) {
                    providervice.deleteStaticProvider(provider.getId());
                }
            }
        }
    }

    return "UnregisterController " + params.size() + " services.";
}
 
Example #9
Source File: Overrides.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context){
    List<String> serviceList = new ArrayList<String>();
    List<String> applicationList = new ArrayList<String>();
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    if(StringUtils.isNotEmpty(application)){
        serviceList.addAll(providerService.findServicesByApplication(application));
        serviceList.addAll(consumerService.findServicesByApplication(application));
        context.put("serviceList", serviceList);
    }else if(StringUtils.isNotEmpty(service)){
        applicationList.addAll(providerService.findApplicationsByServiceName(service));
        applicationList.addAll(consumerService.findApplicationsByServiceName(service));
        context.put("applicationList", applicationList);
    }else{
        serviceList.addAll(providerService.findServices());
        serviceList.addAll(consumerService.findServices());
        providerService.findServicesByApplication(application);
        consumerService.findServicesByApplication(application);
    }
    context.put("serviceList", serviceList);
    
    if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    }
}
 
Example #10
Source File: Weights.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
/**
 * load页面供新增操作
 * @param context
 */
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #11
Source File: Overrides.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context){
    List<String> serviceList = new ArrayList<String>();
    List<String> applicationList = new ArrayList<String>();
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    if(StringUtils.isNotEmpty(application)){
        serviceList.addAll(providerService.findServicesByApplication(application));
        serviceList.addAll(consumerService.findServicesByApplication(application));
        context.put("serviceList", serviceList);
    }else if(StringUtils.isNotEmpty(service)){
        applicationList.addAll(providerService.findApplicationsByServiceName(service));
        applicationList.addAll(consumerService.findApplicationsByServiceName(service));
        context.put("applicationList", applicationList);
    }else{
        serviceList.addAll(providerService.findServices());
        serviceList.addAll(consumerService.findServices());
        providerService.findServicesByApplication(application);
        consumerService.findServicesByApplication(application);
    }
    context.put("serviceList", serviceList);
    
    if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    }
}
 
Example #12
Source File: Loadbalances.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #13
Source File: Unregister.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected String doExecute(Map<String,Object> context) throws Exception {
	Map<String, String[]> params = request.getParameterMap();
    if (params == null || params.size() == 0) {
    	throw new IllegalArgumentException("The url parameters is null! Usage: " + request.getRequestURL().toString() + "?com.xxx.XxxService=http://" + operatorAddress + "/xxxService");
    }
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        if (entry.getKey() != null && entry.getKey().length() > 0
                && entry.getValue() != null && entry.getValue().length > 0
                && entry.getValue()[0] != null && entry.getValue()[0].length() > 0) {
            if (! currentUser.hasServicePrivilege(entry.getKey())) {
                throw new IllegalStateException("The user " + operator + " have no privilege of service " + entry.getKey());
            }
            for(Entry<String,String> e : CollectionUtils.split(Arrays.asList(entry.getValue()), "?").entrySet()){
               Provider provider = providervice.findByServiceAndAddress(entry.getKey(), e.getKey());
                if (provider != null) {
                    providervice.deleteStaticProvider(provider.getId());
                }
            }
        }
    }
   
    return "Unregister " + params.size() + " services.";
}
 
Example #14
Source File: Weights.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * load页面供新增操作
 * @param context
 */
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #15
Source File: Loadbalances.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #16
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
@Override
public UserEntity login(LoginReq loginReq) {

    // 校验参数
    checkParam(loginReq);

    // 创建用户查询请求
    UserQueryReq userQueryReq = buildUserQueryReq(loginReq);

    // 查询用户
    List<UserEntity> userEntityList = userDAO.findUsers(userQueryReq);

    // 查询失败
    if (CollectionUtils.isEmpty(userEntityList)) {
        throw new CommonBizException(ExpCodeEnum.LOGIN_FAIL);
    }

    // 查询成功
    return userEntityList.get(0);
}
 
Example #17
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
private void checkParam(RolePermissionReq rolePermissionReq) {
    // 参数不能为空
    if (rolePermissionReq==null) {
        throw new CommonBizException(ExpCodeEnum.PARAM_NULL);
    }

    // roleId不能为空 & TODO roleId 必须存在
    if (StringUtils.isEmpty(rolePermissionReq.getRoleId())) {
        throw new CommonBizException(ExpCodeEnum.ROLEID_NULL);
    }

    // 权限Id列表不能为空 & 权限Id必须都存在
    if (CollectionUtils.isEmpty(rolePermissionReq.getPermissionIdList())) {
        throw new CommonBizException(ExpCodeEnum.PERMISSIONIDLIST_NULL);
    }
}
 
Example #18
Source File: Unregister.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected String doExecute(Map<String,Object> context) throws Exception {
	Map<String, String[]> params = request.getParameterMap();
    if (params == null || params.size() == 0) {
    	throw new IllegalArgumentException("The url parameters is null! Usage: " + request.getRequestURL().toString() + "?com.xxx.XxxService=http://" + operatorAddress + "/xxxService");
    }
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        if (entry.getKey() != null && entry.getKey().length() > 0
                && entry.getValue() != null && entry.getValue().length > 0
                && entry.getValue()[0] != null && entry.getValue()[0].length() > 0) {
            if (! currentUser.hasServicePrivilege(entry.getKey())) {
                throw new IllegalStateException("The user " + operator + " have no privilege of service " + entry.getKey());
            }
            for(Entry<String,String> e : CollectionUtils.split(Arrays.asList(entry.getValue()), "?").entrySet()){
               Provider provider = providervice.findByServiceAndAddress(entry.getKey(), e.getKey());
                if (provider != null) {
                    providervice.deleteStaticProvider(provider.getId());
                }
            }
        }
    }
   
    return "Unregister " + params.size() + " services.";
}
 
Example #19
Source File: UserServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 根据userState将userId分组
 * @param userStateReqs 修改用户状态的请求
 * @return 分组后结果(key:用户状态、value:该状态下对应的userid列表)
 */
private Map<Integer, List<String>> groupUserIdByUserState(BatchReq<UserStateReq> userStateReqs) {
    // 创建结果集
    Map<Integer, List<String>> userStateMap = Maps.newHashMap();

    // 遍历UserStateEnum
    if (UserStateEnum.values().length > 0) {
        for (UserStateEnum userStateEnum : UserStateEnum.values()) {
            // 获取当前用户状态下的所有userid
            List<String> userIdList = Lists.newArrayList();
            if (CollectionUtils.isNotEmpty(userStateReqs.getReqList())) {
                for (UserStateReq userStateReq : userStateReqs.getReqList()) {
                    if (userStateReq.getUserState() == userStateEnum.getCode()) {
                        userIdList.add(userStateReq.getUserId());
                    }
                }
                userStateMap.put(userStateEnum.getCode(), userIdList);
            }
        }
    }

    return userStateMap;
}
 
Example #20
Source File: Processor.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 处理函数
 * @param orderProcessContext
 */
public void handle(OrderProcessContext orderProcessContext) {
    overrideSuperComponentList();

    // componentList为空
    if (CollectionUtils.isEmpty(componentList)) {
        logger.error(this.getClass().getSimpleName() + "中componentList为空!");
        throw new CommonSysException(ExpCodeEnum.COMPONENT_NULL);
    }

    // 依次执行所有业务组件
    for (BaseComponent component : componentList) {
        component.handle(orderProcessContext);
        // 终止
        if (orderProcessContext.isStop()) {
            break;
        }
    }
}
 
Example #21
Source File: Loadbalances.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #22
Source File: Overrides.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context){
    List<String> serviceList = new ArrayList<String>();
    List<String> applicationList = new ArrayList<String>();
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    if(StringUtils.isNotEmpty(application)){
        serviceList.addAll(providerService.findServicesByApplication(application));
        serviceList.addAll(consumerService.findServicesByApplication(application));
        context.put("serviceList", serviceList);
    }else if(StringUtils.isNotEmpty(service)){
        applicationList.addAll(providerService.findApplicationsByServiceName(service));
        applicationList.addAll(consumerService.findApplicationsByServiceName(service));
        context.put("applicationList", applicationList);
    }else{
        serviceList.addAll(providerService.findServices());
        serviceList.addAll(consumerService.findServices());
        providerService.findServicesByApplication(application);
        consumerService.findServicesByApplication(application);
    }
    context.put("serviceList", serviceList);
    
    if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    }
}
 
Example #23
Source File: BaseIdempotencyComponent.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 检查幂等性
 * @param curOrderState 订单当前的状态
 * @param allowStateList 订单允许的状态列表
 */
private void checkIdempotency(OrderStateEnum curOrderState, List<OrderStateEnum> allowStateList) {

    // allowStateList为空
    if (CollectionUtils.isEmpty(allowStateList)) {
        throw new CommonSysException(ExpCodeEnum.AllowStateList_NULL);
    }

    for (OrderStateEnum orderStateEnum : allowStateList) {
        if (orderStateEnum == curOrderState) {
            // 幂等性检查通过
            return;
        }
    }

    // 幂等性检查不通过
    throw new CommonBizException(ExpCodeEnum.NO_REPEAT);
}
 
Example #24
Source File: Weights.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
/**
 * load页面供新增操作
 * @param context
 */
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for(Provider provider : providerList){
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        context.put("addressList", addressList);
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        context.put("serviceList", serviceList);
    }
    if(context.get("input") != null) context.put("input", context.get("input"));
}
 
Example #25
Source File: AccessAuthHandle.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
/**
 * 检查当前用户是否拥有访问该接口的权限
 * @param userEntity 用户信息
 * @param accessAuthEntity 接口权限信息
 */
private void checkPermission(UserEntity userEntity, AccessAuthEntity accessAuthEntity) {
    // 获取接口权限
    String accessPermission = accessAuthEntity.getPermission();

    // 获取用户权限
    List<PermissionEntity> userPermissionList = userEntity.getRoleEntity().getPermissionList();

    // 判断用户是否包含接口权限
    if (CollectionUtils.isNotEmpty(userPermissionList)) {
        for (PermissionEntity permissionEntity : userPermissionList) {
            if (permissionEntity.getPermission().equals(accessPermission)) {
                return;
            }
        }
    }

    // 没有权限
    throw new CommonBizException(ExpCodeEnum.NO_PERMISSION);
}
 
Example #26
Source File: Overrides.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void add(Map<String, Object> context){
    List<String> serviceList = new ArrayList<String>();
    List<String> applicationList = new ArrayList<String>();
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    if(StringUtils.isNotEmpty(application)){
        serviceList.addAll(providerService.findServicesByApplication(application));
        serviceList.addAll(consumerService.findServicesByApplication(application));
        context.put("serviceList", serviceList);
    }else if(StringUtils.isNotEmpty(service)){
        applicationList.addAll(providerService.findApplicationsByServiceName(service));
        applicationList.addAll(consumerService.findApplicationsByServiceName(service));
        context.put("applicationList", applicationList);
    }else{
        serviceList.addAll(providerService.findServices());
        serviceList.addAll(consumerService.findServices());
        providerService.findServicesByApplication(application);
        consumerService.findServicesByApplication(application);
    }
    context.put("serviceList", serviceList);
    
    if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    }
}
 
Example #27
Source File: FailbackRegistryTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
     * Test method for
     * {@link com.alibaba.dubbo.registry.internal.FailbackRegistry#doRetry()}.
     * 
     * @throws Exception
     */
    @Test
    public void testDoRetry() throws Exception {

        final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
        final CountDownLatch latch = new CountDownLatch(3);//全部共调用3次。成功才会减1. subscribe register的失败尝试不会在做了

        NotifyListener listner = new NotifyListener() {
            public void notify(List<URL> urls) {
                notified.set(Boolean.TRUE);
            }
        };
        registry = new MockRegistry(registryUrl, latch);
        registry.setBad(true);
        registry.register(serviceUrl);
        registry.unregister(serviceUrl);
        registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);
        registry.unsubscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);

        //失败的情况不能调用到listener.
        assertEquals(false, notified.get());
        assertEquals(3, latch.getCount());

        registry.setBad(false);

        for (int i = 0; i < trytimes; i++) {
            System.out.println("failback registry retry ,times:" + i);
            //System.out.println(latch.getCount());
            if (latch.getCount() == 0)
                break;
            Thread.sleep(sleeptime);
        }
//        Thread.sleep(100000);//for debug
        assertEquals(0, latch.getCount());
        //unsubscribe时会清除failedsubcribe对应key
        assertEquals(false, notified.get());
    }
 
Example #28
Source File: Routes.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 载入新增路由页面
 * @param context
 */
public void add(Map<String, Object> context) {
    String service = (String)context.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        context.put("service", service);
        context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    } else {
        List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
        context.put("serviceList", serviceList);
    }
    
    if(context.get("input") != null) context.put("input", context.get("input"));
    
}
 
Example #29
Source File: FailbackRegistryTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
    public void testDoRetry_register() throws Exception {

        final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
        final CountDownLatch latch = new CountDownLatch(1);//全部共调用4次。成功才会减1. subscribe的失败尝试不会在做了

        NotifyListener listner = new NotifyListener() {
            public void notify(List<URL> urls) {
                notified.set(Boolean.TRUE);
            }
        };
        registry = new MockRegistry(registryUrl, latch);
        registry.setBad(true);
        registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);

        //失败的情况不能调用到listener.
        assertEquals(false, notified.get());
        assertEquals(1, latch.getCount());

        registry.setBad(false);

        for (int i = 0; i < trytimes; i++) {
            System.out.println("failback registry retry ,times:" + i);
            //System.out.println(latch.getCount());
            if (latch.getCount() == 0)
                break;
            Thread.sleep(sleeptime);
        }
//        Thread.sleep(100000);
        assertEquals(0, latch.getCount());
        //unsubscribe时会清除failedsubcribe对应key
        assertEquals(true, notified.get());
    }
 
Example #30
Source File: FailbackRegistryTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoRetry_nofify() throws Exception {

    //初始值0
    final AtomicInteger count = new AtomicInteger(0);

    NotifyListener listner = new NotifyListener() {
        public void notify(List<URL> urls) {
            count.incrementAndGet();
            //第一次抛出异常,看后面是否会再次调用到incrementAndGet
            if(count.get() == 1l ){
                throw new  RuntimeException("test exception please ignore");
            }
        }
    };
    registry = new MockRegistry(registryUrl, new CountDownLatch(0));
    registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);

    assertEquals(1, count.get()); //确保subscribe调用完成后刚调用过一次count.incrementAndGet
    //等定时器.
    for (int i = 0; i < trytimes; i++) {
        System.out.println("failback notify retry ,times:" + i);
        if (count.get() == 2)
            break;
        Thread.sleep(sleeptime);
    }
    assertEquals(2, count.get());
}