Search in sources :

Example 21 with QuotaPolicy

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

the class SampleTestObjectCreator method createSubscriptionPolicyWithBndwidthLimit.

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

Example 22 with QuotaPolicy

use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy 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;
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline)

Example 23 with QuotaPolicy

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

the class SampleTestObjectCreator method createDefaultAPIPolicyWithBandwidthLimit.

/**
 * Create default api policy with bandwidth limit as quota policy
 *
 * @return APIPolicy object with bandwidth limit as quota policy is returned
 */
public static APIPolicy createDefaultAPIPolicyWithBandwidthLimit() {
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_MONTH, 1, 1000, PolicyConstants.MB);
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
    defaultQuotaPolicy.setLimit(bandwidthLimit);
    // set default API Policy
    APIPolicy apiPolicy = new APIPolicy(SAMPLE_API_POLICY);
    apiPolicy.setUuid(UUID.randomUUID().toString());
    apiPolicy.setDisplayName(SAMPLE_API_POLICY);
    apiPolicy.setDescription(SAMPLE_API_POLICY_DESCRIPTION);
    apiPolicy.setUserLevel(APIMgtConstants.ThrottlePolicyConstants.API_LEVEL);
    apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    return apiPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 24 with QuotaPolicy

use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy 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;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Example 25 with QuotaPolicy

use of org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy 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;
}
Also used : JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) Condition(org.wso2.carbon.apimgt.core.models.policy.Condition) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) JWTClaimsCondition(org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) HeaderCondition(org.wso2.carbon.apimgt.core.models.policy.HeaderCondition) ArrayList(java.util.ArrayList) QueryParameterCondition(org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline) IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Aggregations

QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)34 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)23 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)16 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)10 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)9 Test (org.testng.annotations.Test)6 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)6 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)4 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)4 ArrayList (java.util.ArrayList)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)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)1 Limit (org.wso2.carbon.apimgt.core.models.policy.Limit)1 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)1