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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations