use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createNewIPRangePipeline.
/**
* Creates a new {@link Pipeline} instance
*
* @return created Pipeline instance
*/
public static Pipeline createNewIPRangePipeline() {
IPCondition ipCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
ipCondition.setStartingIP("10.100.0.105");
ipCondition.setEndingIP("10.100.0.115");
Pipeline pipeline = new Pipeline();
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType(REQUEST_COUNT_TYPE);
quotaPolicy.setLimit(requestCountLimit);
pipeline.setQuotaPolicy(quotaPolicy);
pipeline.setConditions(Arrays.asList(ipCondition));
return pipeline;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultApplicationPolicy.
public static ApplicationPolicy createDefaultApplicationPolicy() {
ApplicationPolicy applicationPolicy = new ApplicationPolicy(SAMPLE_APP_POLICY);
applicationPolicy.setUuid(UUID.randomUUID().toString());
applicationPolicy.setDisplayName(SAMPLE_APP_POLICY);
applicationPolicy.setDescription(SAMPLE_APP_POLICY_DESCRIPTION);
applicationPolicy.setCustomAttributes(SAMPLE_CUSTOM_ATTRIBUTE.getBytes());
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 10000, 1000);
defaultQuotaPolicy.setLimit(requestCountLimit);
applicationPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
return applicationPolicy;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultPipelines.
/**
* create default pipeline for api policy
*
* @return list of Pipeline objects is returned
*/
public static List<Pipeline> createDefaultPipelines() {
// Pipeline 1
IPCondition ipCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
ipCondition.setStartingIP("192.168.12.3");
ipCondition.setEndingIP("192.168.88.19");
IPCondition ipConditionSpecific = new IPCondition(PolicyConstants.IP_SPECIFIC_TYPE);
ipConditionSpecific.setSpecificIP("123.42.14.56");
// adding above conditions to condition list of pipeline 1
// contains conditions for each pipeline
List<Condition> conditionsList = new ArrayList<>();
conditionsList.add(ipCondition);
conditionsList.add(ipConditionSpecific);
// set quota policy with bandwidth limit
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_MONTH, 1, 1000, PolicyConstants.MB);
QuotaPolicy quotaPolicy1 = new QuotaPolicy();
quotaPolicy1.setType(PolicyConstants.BANDWIDTH_TYPE);
quotaPolicy1.setLimit(bandwidthLimit);
Pipeline pipeline1 = new Pipeline();
pipeline1.setConditions(conditionsList);
pipeline1.setQuotaPolicy(quotaPolicy1);
// End of pipeline 1 -> Beginning of pipeline 2
HeaderCondition headerCondition = new HeaderCondition();
headerCondition.setHeader("Browser");
headerCondition.setValue("Chrome");
JWTClaimsCondition jwtClaimsCondition = new JWTClaimsCondition();
jwtClaimsCondition.setClaimUrl("/path/path2");
jwtClaimsCondition.setAttribute("attributed");
QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
queryParameterCondition.setParameter("Location");
queryParameterCondition.setValue("Colombo");
// adding conditions to condition list of pipeline2
conditionsList = new ArrayList<>();
conditionsList.add(headerCondition);
conditionsList.add(jwtClaimsCondition);
conditionsList.add(queryParameterCondition);
// pipeline 2 with request count as quota policy
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
QuotaPolicy quotaPolicy2 = new QuotaPolicy();
quotaPolicy2.setType(PolicyConstants.REQUEST_COUNT_TYPE);
quotaPolicy2.setLimit(requestCountLimit);
Pipeline pipeline2 = new Pipeline();
pipeline2.setConditions(conditionsList);
pipeline2.setQuotaPolicy(quotaPolicy2);
// adding pipelines
// contains all the default pipelines
List<Pipeline> pipelineList = new ArrayList<>();
pipelineList.add(pipeline1);
pipelineList.add(pipeline2);
return pipelineList;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.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.throttle.policy.deployer.dto.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);
}
Aggregations