Search in sources :

Example 21 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class Overrides method edit.

public void edit(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>();
    List<String> methods = CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(override.getService())));
    if (methods != null && methods.isEmpty()) {
        for (String m : methods) {
            parseMock(m, parameters.get(m + MOCK_JSON_KEY_POSTFIX), method2Force, method2Json);
            parameters.remove(m + MOCK_JSON_KEY_POSTFIX);
        }
    }
    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("methods", methods);
    context.put("methodForces", method2Force);
    context.put("methodJsons", method2Json);
    context.put("parameters", parameters);
    context.put("override", override);
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class Overrides method show.

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);
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class Providers method update.

public boolean update(Provider newProvider, Map<String, Object> context) {
    Long id = newProvider.getId();
    String parameters = newProvider.getParameters();
    Provider provider = providerService.findProvider(id);
    if (provider == null) {
        context.put("message", getMessage("NoSuchOperationData", id));
        return false;
    }
    String service = provider.getService();
    if (!super.currentUser.hasServicePrivilege(service)) {
        context.put("message", getMessage("HaveNoServicePrivilege", service));
        return false;
    }
    Map<String, String> oldMap = StringUtils.parseQueryString(provider.getParameters());
    Map<String, String> newMap = StringUtils.parseQueryString(parameters);
    for (Map.Entry<String, String> entry : oldMap.entrySet()) {
        if (entry.getValue().equals(newMap.get(entry.getKey()))) {
            newMap.remove(entry.getKey());
        }
    }
    if (provider.isDynamic()) {
        String address = provider.getAddress();
        List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
        OverrideUtils.setProviderOverrides(provider, overrides);
        Override override = provider.getOverride();
        if (override != null) {
            if (newMap.size() > 0) {
                override.setParams(StringUtils.toQueryString(newMap));
                override.setEnabled(true);
                override.setOperator(operator);
                override.setOperatorAddress(operatorAddress);
                overrideService.updateOverride(override);
            } else {
                overrideService.deleteOverride(override.getId());
            }
        } else {
            override = new Override();
            override.setService(service);
            override.setAddress(address);
            override.setParams(StringUtils.toQueryString(newMap));
            override.setEnabled(true);
            override.setOperator(operator);
            override.setOperatorAddress(operatorAddress);
            overrideService.saveOverride(override);
        }
    } else {
        provider.setParameters(parameters);
        providerService.updateProvider(provider);
    }
    return true;
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) Override(com.alibaba.dubbo.registry.common.domain.Override) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 24 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class OwnerServiceImpl method saveOwner.

public void saveOwner(Owner owner) {
    List<Override> overrides = overrideService.findByServiceAndAddress(owner.getService(), Constants.ANYHOST_VALUE);
    if (overrides == null || overrides.size() == 0) {
        Override override = new Override();
        override.setAddress(Constants.ANYHOST_VALUE);
        override.setService(owner.getService());
        override.setEnabled(true);
        override.setParams("owner=" + owner.getUsername());
        overrideService.saveOverride(override);
    } else {
        for (Override override : overrides) {
            Map<String, String> params = StringUtils.parseQueryString(override.getParams());
            String usernames = params.get("owner");
            if (usernames == null || usernames.length() == 0) {
                usernames = owner.getUsername();
            } else {
                usernames = usernames + "," + owner.getUsername();
            }
            params.put("owner", usernames);
            override.setParams(StringUtils.toQueryString(params));
            overrideService.updateOverride(override);
        }
    }
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 25 with Override

use of com.alibaba.dubbo.registry.common.domain.Override in project dubbo by alibaba.

the class OwnerServiceImpl method deleteOwner.

public void deleteOwner(Owner owner) {
    List<Override> overrides = overrideService.findByServiceAndAddress(owner.getService(), Constants.ANYHOST_VALUE);
    if (overrides == null || overrides.size() == 0) {
        Override override = new Override();
        override.setAddress(Constants.ANYHOST_VALUE);
        override.setService(owner.getService());
        override.setEnabled(true);
        override.setParams("owner=" + owner.getUsername());
        overrideService.saveOverride(override);
    } else {
        for (Override override : overrides) {
            Map<String, String> params = StringUtils.parseQueryString(override.getParams());
            String usernames = params.get("owner");
            if (usernames != null && usernames.length() > 0) {
                if (usernames.equals(owner.getUsername())) {
                    params.remove("owner");
                } else {
                    usernames = usernames.replace(owner.getUsername() + ",", "").replace("," + owner.getUsername(), "");
                    params.put("owner", usernames);
                }
                if (params.size() > 0) {
                    override.setParams(StringUtils.toQueryString(params));
                    overrideService.updateOverride(override);
                } else {
                    overrideService.deleteOverride(override.getId());
                }
            }
        }
    }
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Aggregations

Override (com.alibaba.dubbo.registry.common.domain.Override)30 ArrayList (java.util.ArrayList)10 Provider (com.alibaba.dubbo.registry.common.domain.Provider)8 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Consumer (com.alibaba.dubbo.registry.common.domain.Consumer)4 Route (com.alibaba.dubbo.registry.common.domain.Route)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 LoadBalance (com.alibaba.dubbo.registry.common.domain.LoadBalance)1 Owner (com.alibaba.dubbo.registry.common.domain.Owner)1 Weight (com.alibaba.dubbo.registry.common.domain.Weight)1