Search in sources :

Example 6 with Override

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

the class Services method mock.

private boolean mock(Map<String, Object> context, String mock) throws Exception {
    String services = (String) context.get("service");
    String application = (String) context.get("application");
    if (services == null || services.length() == 0 || application == null || application.length() == 0) {
        context.put("message", getMessage("NoSuchOperationData"));
        return false;
    }
    for (String service : SPACE_SPLIT_PATTERN.split(services)) {
        if (!super.currentUser.hasServicePrivilege(service)) {
            context.put("message", getMessage("HaveNoServicePrivilege", service));
            return false;
        }
    }
    for (String service : SPACE_SPLIT_PATTERN.split(services)) {
        List<Override> overrides = overrideService.findByServiceAndApplication(service, application);
        if (overrides != null && overrides.size() > 0) {
            for (Override override : overrides) {
                Map<String, String> map = StringUtils.parseQueryString(override.getParams());
                if (mock == null || mock.length() == 0) {
                    map.remove("mock");
                } else {
                    map.put("mock", URL.encode(mock));
                }
                if (map.size() > 0) {
                    override.setParams(StringUtils.toQueryString(map));
                    override.setEnabled(true);
                    override.setOperator(operator);
                    override.setOperatorAddress(operatorAddress);
                    overrideService.updateOverride(override);
                } else {
                    overrideService.deleteOverride(override.getId());
                }
            }
        } else if (mock != null && mock.length() > 0) {
            Override override = new Override();
            override.setService(service);
            override.setApplication(application);
            override.setParams("mock=" + URL.encode(mock));
            override.setEnabled(true);
            override.setOperator(operator);
            override.setOperatorAddress(operatorAddress);
            overrideService.saveOverride(override);
        }
    }
    return true;
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 7 with Override

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

the class Tool method isProviderEnabled.

public static boolean isProviderEnabled(Provider provider, List<Override> oList) {
    for (Override o : oList) {
        if (o.isMatch(provider)) {
            Map<String, String> params = StringUtils.parseQueryString(o.getParams());
            String disbaled = params.get(Constants.DISABLED_KEY);
            if (disbaled != null && disbaled.length() > 0) {
                return !"true".equals(disbaled);
            }
        }
    }
    return provider.isEnabled();
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 8 with Override

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

the class Consumers method update.

public boolean update(Consumer newConsumer, Map<String, Object> context) {
    Long id = newConsumer.getId();
    String parameters = newConsumer.getParameters();
    Consumer consumer = consumerService.findConsumer(id);
    if (consumer == null) {
        context.put("message", getMessage("NoSuchOperationData", id));
        return false;
    }
    String service = consumer.getService();
    if (!super.currentUser.hasServicePrivilege(service)) {
        context.put("message", getMessage("HaveNoServicePrivilege", service));
        return false;
    }
    Map<String, String> oldMap = StringUtils.parseQueryString(consumer.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());
        }
    }
    String address = consumer.getAddress();
    List<Override> overrides = overrideService.findByServiceAndAddress(consumer.getService(), consumer.getAddress());
    OverrideUtils.setConsumerOverrides(consumer, overrides);
    Override override = consumer.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);
    }
    return true;
}
Also used : Consumer(com.alibaba.dubbo.registry.common.domain.Consumer) HashMap(java.util.HashMap) Map(java.util.Map) Override(com.alibaba.dubbo.registry.common.domain.Override)

Example 9 with Override

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

the class Consumers method show.

public void show(Long id, Map<String, Object> context) {
    Consumer consumer = consumerService.findConsumer(id);
    List<Provider> providers = providerService.findByService(consumer.getService());
    List<Route> routes = routeService.findByService(consumer.getService());
    List<Override> overrides = overrideService.findByService(consumer.getService());
    List<Route> routed = new ArrayList<Route>();
    consumer.setProviders(RouteUtils.route(consumer.getService(), consumer.getAddress(), consumer.getParameters(), providers, overrides, routes, null, routed));
    consumer.setRoutes(routed);
    OverrideUtils.setConsumerOverrides(consumer, overrides);
    context.put("consumer", consumer);
    context.put("providers", consumer.getProviders());
    context.put("routes", consumer.getRoutes());
    context.put("overrides", consumer.getOverrides());
}
Also used : Consumer(com.alibaba.dubbo.registry.common.domain.Consumer) ArrayList(java.util.ArrayList) Override(com.alibaba.dubbo.registry.common.domain.Override) Route(com.alibaba.dubbo.registry.common.domain.Route) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

Example 10 with Override

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

the class Providers method show.

public void show(Long id, Map<String, Object> context) {
    Provider provider = providerService.findProvider(id);
    if (provider != null && provider.isDynamic()) {
        List<Override> overrides = overrideService.findByServiceAndAddress(provider.getService(), provider.getAddress());
        OverrideUtils.setProviderOverrides(provider, overrides);
    }
    context.put("provider", provider);
}
Also used : Override(com.alibaba.dubbo.registry.common.domain.Override) Provider(com.alibaba.dubbo.registry.common.domain.Provider)

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