Search in sources :

Example 16 with AbstractQpsStrategy

use of org.apache.servicecomb.qps.strategy.AbstractQpsStrategy in project java-chassis by ServiceComb.

the class QpsControllerManager method searchQpsController.

/**
 * <p> Use qualifiedNameKey to search {@link QpsStrategy}.
 * Firstly try to search "microservice.schema.operation". If no valid result found, then try "microservice.schema",
 * and then "microservice" or global qpsController(If there is a global qpsController).</p>
 * <p> This method ensures that there is always an existing qpsController returned, as the relevant qpsController has
 * been created and stored in {@link #create(String, String, Invocation)}</p>
 *
 * @param qualifiedNameKey qualifiedNameKey in {@link #qualifiedNameControllerMap}
 * @return a qps controller, lower level controllers with valid qpsLimit have priority.
 */
private AbstractQpsStrategy searchQpsController(String qualifiedNameKey) {
    AbstractQpsStrategy qpsStrategy = configQpsControllerMap.get(qualifiedNameKey);
    if (isValidQpsController(qpsStrategy)) {
        return qpsStrategy;
    }
    int index = qualifiedNameKey.lastIndexOf(SEPARATOR);
    while (index > 0) {
        qpsStrategy = configQpsControllerMap.get(qualifiedNameKey.substring(0, index));
        if (isValidQpsController(qpsStrategy)) {
            return qpsStrategy;
        }
        index = qualifiedNameKey.lastIndexOf(SEPARATOR, index - 1);
    }
    if (isValidQpsController(qpsStrategy)) {
        return qpsStrategy;
    }
    return null;
}
Also used : AbstractQpsStrategy(org.apache.servicecomb.qps.strategy.AbstractQpsStrategy)

Example 17 with AbstractQpsStrategy

use of org.apache.servicecomb.qps.strategy.AbstractQpsStrategy in project java-chassis by ServiceComb.

the class QpsControllerManager method updateObjMap.

protected void updateObjMap(String configKey) {
    Iterator<Entry<String, AbstractQpsStrategy>> it = qualifiedNameControllerMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, AbstractQpsStrategy> entry = it.next();
        if (keyMatch(configKey, entry)) {
            AbstractQpsStrategy qpsStrategy = searchQpsController(entry.getKey());
            if (qpsStrategy != null) {
                entry.setValue(qpsStrategy);
                LOGGER.info("QpsController updated, operationId = [{}], configKey = [{}], qpsLimit = [{}]", entry.getKey(), qpsStrategy.getKey(), qpsStrategy.getQpsLimit());
            } else {
                it.remove();
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) AbstractQpsStrategy(org.apache.servicecomb.qps.strategy.AbstractQpsStrategy) Map(java.util.Map)

Aggregations

AbstractQpsStrategy (org.apache.servicecomb.qps.strategy.AbstractQpsStrategy)17 Test (org.junit.Test)10 FixedWindowStrategy (org.apache.servicecomb.qps.strategy.FixedWindowStrategy)7 Expectations (mockit.Expectations)5 MockUp (mockit.MockUp)4 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)3 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)2 DynamicProperty (com.netflix.config.DynamicProperty)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ServiceCombException (org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)1 IStrategyFactory (org.apache.servicecomb.qps.strategy.IStrategyFactory)1 ExpectedException (org.junit.rules.ExpectedException)1