Search in sources :

Example 26 with RequestCountLimit

use of org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultSiddhiAppforAppPolicy.

public static String createDefaultSiddhiAppforAppPolicy() {
    ApplicationPolicy policy = createDefaultApplicationPolicy();
    RequestCountLimit limit = (RequestCountLimit) createDefaultApplicationPolicy().getDefaultQuotaPolicy().getLimit();
    String siddhiApp = "@App:name('application_" + policy.getPolicyName() + "')\n" + "@App:description('ExecutionPlan for app_" + policy.getPolicyName() + "')\n" + "@source(type='inMemory', topic='apim', @map(type='passThrough'))\n" + "define stream RequestStream (messageID string, appKey string, appTier string, " + "subscriptionKey string," + " apiKey string, apiTier string, subscriptionTier string, resourceKey string," + " resourceTier string," + " userId string,  apiContext string, apiVersion string, appTenant string, apiTenant string," + " appId " + "string, apiName string, propertiesMap string);\n" + "@sink(type='jms', @map(type='text'),\n" + "factory.initial='org.wso2.andes.jndi.PropertiesFileInitialContextFactory'," + " provider.url='tcp://localhost:5672', destination='TEST.FOO', connection.factory." + "type='topic',\n" + "connection.factory.jndi.name='TopicConnectionFactory')\n" + "define stream GlobalThrottleStream (throttleKey string, isThrottled bool" + ", expiryTimeStamp long);\n" + "FROM RequestStream\n" + "SELECT messageID, (appTier == '" + policy.getPolicyName() + "') AS isEligible, appKey AS throttleKey, " + "propertiesMap\n" + "INSERT INTO EligibilityStream;\n" + "FROM EligibilityStream[isEligible==true]#throttler:timeBatch(" + policy.getDefaultQuotaPolicy().getLimit().getUnitTime() + " " + policy.getDefaultQuotaPolicy().getLimit().getTimeUnit() + ", 0)\n" + "select throttleKey, (count(messageID) >= " + limit.getRequestCount() + ")" + " as isThrottled, expiryTimeStamp group by throttleKey\n" + "INSERT ALL EVENTS into ResultStream;\n" + "from ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)\n" + "select *\n" + "insert into GlobalThrottleStream;\n";
    return siddhiApp;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)

Example 27 with RequestCountLimit

use of org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultPolicy.

public static void createDefaultPolicy(PolicyDAO policyDAO) throws APIMgtDAOException {
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType(REQUEST_COUNT_TYPE);
    quotaPolicy.setLimit(new RequestCountLimit(SECONDS_TIMUNIT, 60, 1));
    unlimitedApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(unlimitedApiPolicy);
    goldApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(goldApiPolicy);
    silverApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(silverApiPolicy);
    bronzeApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(bronzeApiPolicy);
    unlimitedSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(unlimitedSubscriptionPolicy);
    goldSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(goldSubscriptionPolicy);
    silverSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(silverSubscriptionPolicy);
    bronzeSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(bronzeSubscriptionPolicy);
    fiftyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApplicationPolicy(fiftyPerMinApplicationPolicy);
    twentyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApplicationPolicy(twentyPerMinApplicationPolicy);
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Example 28 with RequestCountLimit

use of org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromRequestCountLimitToDTO.

/**
 * Converts a Request Count Limit model object into a Request Count Limit DTO object
 *
 * @param requestCountLimit Request Count Limit model object
 * @return Request Count DTO object derived from model
 */
public static ThrottleLimitDTO fromRequestCountLimitToDTO(RequestCountLimit requestCountLimit) {
    // done
    ThrottleLimitDTO dto = new ThrottleLimitDTO();
    dto = updateFieldsFromLimitToDTO(requestCountLimit, dto);
    dto.setType("RequestCountLimit");
    dto.setRequestCountLimit(new RequestCountLimitDTO());
    dto.getRequestCountLimit().setRequestCount(requestCountLimit.getRequestCount());
    return dto;
}
Also used : RequestCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)

Example 29 with RequestCountLimit

use of org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createAPIPolicyWithRequestLimit.

public static APIPolicy createAPIPolicyWithRequestLimit(String name) {
    APIPolicy apiPolicy = new APIPolicy(name);
    apiPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("requestCount");
    RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
    quotaPolicy.setLimit(requestCountLimit);
    apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    apiPolicy.setDisplayName("displayName");
    return apiPolicy;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy)

Example 30 with RequestCountLimit

use of org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createSubscriptionPolicyWithRequestLimit.

public static SubscriptionPolicy createSubscriptionPolicyWithRequestLimit(String name) {
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(name);
    subscriptionPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("requestCount");
    RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
    quotaPolicy.setLimit(requestCountLimit);
    subscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    return subscriptionPolicy;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Aggregations

RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)33 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)22 Test (org.testng.annotations.Test)14 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)9 ArrayList (java.util.ArrayList)8 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)8 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)7 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)4 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)4 RequestCountLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO)4 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)4 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)3 Condition (org.wso2.carbon.apimgt.core.models.policy.Condition)3 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)3 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)3 QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)3 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)3 Limit (org.wso2.carbon.apimgt.core.models.policy.Limit)2 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)2