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

The following examples show how to use com.alibaba.dubbo.common.utils.CollectionUtils. These examples are extracted from open source projects. 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 Project: dubbox   Source File: Weights.java    License: 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 2
@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 3
Source Project: open-capacity-platform   Source File: RoutesController.java    License: 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 4
Source Project: dubbox   Source File: Weights.java    License: 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 5
Source Project: dubbox   Source File: Loadbalances.java    License: 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 6
@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 7
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 8
/**
 * 根据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 9
Source Project: SpringBoot-Dubbo-Docker-Jenkins   Source File: Processor.java    License: 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 10
/**
 * 检查幂等性
 * @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 11
/**
 * 检查当前用户是否拥有访问该接口的权限
 * @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 12
Source Project: dubbox   Source File: Unregister.java    License: 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 13
Source Project: dubbox   Source File: Weights.java    License: 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 14
Source Project: dubbox   Source File: Overrides.java    License: 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 15
Source Project: dubbox   Source File: Loadbalances.java    License: 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 Project: dubbox   Source File: Overrides.java    License: 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 17
Source Project: dubbox-hystrix   Source File: Weights.java    License: 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 18
Source Project: dubbox-hystrix   Source File: Overrides.java    License: 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 19
Source Project: dubbox-hystrix   Source File: Loadbalances.java    License: 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 20
Source Project: dubbo3   Source File: Unregister.java    License: 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 21
Source Project: dubbox   Source File: Loadbalances.java    License: 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 Project: dubbox   Source File: Overrides.java    License: 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 Project: dubbo3   Source File: Weights.java    License: 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 24
Source Project: dubbo3   Source File: Overrides.java    License: 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 25
Source Project: dubbo3   Source File: Loadbalances.java    License: 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 26
Source Project: dubbox   Source File: Unregister.java    License: 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 27
Source Project: dubbo-2.6.5   Source File: FailbackRegistryTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * Test method for
     * {@link com.alibaba.dubbo.registry.support.FailbackRegistry#retry()}.
     *
     * @throws Exception
     */
    @Test
    public void testDoRetry() throws Exception {

        final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false);
        final CountDownLatch latch = new CountDownLatch(3);//All of them are called 3 times. Successful attempts to reduce the failure of 1. subscribe register will not be done again

        NotifyListener listner = new NotifyListener() {
            @Override
            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);

        //Failure can not be called to 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());
        //The failedsubcribe corresponding key will be cleared when unsubscribing
        assertEquals(false, notified.get());
    }
 
Example 28
Source Project: dubbo-2.6.5   Source File: FailbackRegistryTest.java    License: 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);//All of them are called 4 times. A successful attempt to lose 1. subscribe will not be done

        NotifyListener listner = new NotifyListener() {
            @Override
            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);

        //Failure can not be called to 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());
        //The failedsubcribe corresponding key will be cleared when unsubscribing
        assertEquals(true, notified.get());
    }
 
Example 29
Source Project: dubbo-2.6.5   Source File: FailbackRegistryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDoRetry_nofify() throws Exception {

    //Initial value 0
    final AtomicInteger count = new AtomicInteger(0);

    NotifyListener listner = new NotifyListener() {
        @Override
        public void notify(List<URL> urls) {
            count.incrementAndGet();
            //The exception is thrown for the first time to see if the back will be called again to 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()); //Make sure that the subscribe call has just been called once count.incrementAndGet after the call is completed
    //Wait for the timer.
    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());
}
 
Example 30
Source Project: open-capacity-platform   Source File: RegisterController.java    License: Apache License 2.0 5 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://" + request.getRemoteAddr() + "/xxxService?application=xxx&foo1=123");
        }
        Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
        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 " + currentUser.getUsername() + " have no privilege of service " + entry.getKey());
                }
                String serviceName = entry.getKey();
                Map<String, String> url2query = CollectionUtils.split(Arrays.asList(entry.getValue()), "?");
                // check whether url contain application info
                for (Map.Entry<String, String> e : url2query.entrySet()) {
                    Map<String, String> query = StringUtils.parseQueryString(e.getValue());
                    String app = query.get("application");
                    if (StringUtils.isBlank(app)) {
                        throw new IllegalStateException("No application for service(" + serviceName + "): "
                                + e.getKey() + "?" + e.getValue());
                    }
                }
                map.put(serviceName, url2query);
            }
        }
        if (map.size() > 0) {
//        	providerDAO.register(registryCache.getCurrentRegistry(), request.getRemoteAddr(), operatorAddress, operator, map, false, true);
        }
        return "RegisterController " + map.size() + " services.";
    }