Search in sources :

Example 6 with QuotaPolicy

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

the class SampleTestObjectCreator method updateSubscriptionPolicy.

public static SubscriptionPolicy updateSubscriptionPolicy(SubscriptionPolicy subscriptionPolicy) {
    subscriptionPolicy.setDisplayName(UPDATED_SAMPLE_SUBSCRIPTION_POLICY);
    subscriptionPolicy.setDescription(UPDATED_SAMPLE_SUBSCRIPTION_POLICY_DESCRIPTION);
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
    defaultQuotaPolicy.setLimit(bandwidthLimit);
    subscriptionPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    return subscriptionPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 7 with QuotaPolicy

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

the class SampleTestObjectCreator method createApplicationPolicyWithRequestLimit.

public static ApplicationPolicy createApplicationPolicyWithRequestLimit(String name) {
    ApplicationPolicy applicationPolicy = new ApplicationPolicy(name);
    applicationPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("requestCount");
    RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
    quotaPolicy.setLimit(requestCountLimit);
    applicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    applicationPolicy.setDisplayName("displayName");
    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 8 with QuotaPolicy

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

the class SampleTestObjectCreator method createApplicationPolicyWithBndwidthLimit.

public static ApplicationPolicy createApplicationPolicyWithBndwidthLimit(String name) {
    ApplicationPolicy applicationPolicy = new ApplicationPolicy(name);
    applicationPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("bandwidth");
    BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
    quotaPolicy.setLimit(bandwidthLimit);
    applicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    applicationPolicy.setDisplayName("displayName");
    return applicationPolicy;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 9 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("bandwidth");
    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 10 with QuotaPolicy

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

the class CommonThrottleMappingUtil method fromQuotaPolicyToDTO.

/**
 * Converts a Quota Policy object into a Throttle Limit DTO object
 *
 * @param quotaPolicy Quota Policy object
 * @return Throttle Limit DTO object derived from the Quota Policy object
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static ThrottleLimitDTO fromQuotaPolicyToDTO(QuotaPolicy quotaPolicy) throws UnsupportedThrottleLimitTypeException {
    Limit limit = quotaPolicy.getLimit();
    String throttleLimitType = quotaPolicy.getType();
    if (PolicyConstants.REQUEST_COUNT_TYPE.equals(throttleLimitType)) {
        if (limit instanceof RequestCountLimit) {
            RequestCountLimit requestCountLimit = (RequestCountLimit) limit;
            return fromRequestCountLimitToDTO(requestCountLimit);
        } else {
            String msg = "Throttle limit type " + throttleLimitType + " is not of type RequestCountLimit";
            log.error(msg);
            throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
        }
    } else if (PolicyConstants.BANDWIDTH_TYPE.equals(throttleLimitType)) {
        if (limit instanceof BandwidthLimit) {
            BandwidthLimit bandwidthLimit = (BandwidthLimit) limit;
            return fromBandwidthLimitToDTO(bandwidthLimit);
        } else {
            String msg = "Throttle limit type " + throttleLimitType + " is not of type BandwidthLimit";
            log.error(msg);
            throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
        }
    } else {
        String msg = "Throttle limit type " + throttleLimitType + " is not supported";
        log.error(msg);
        throw new UnsupportedThrottleLimitTypeException(msg, ExceptionCodes.UNSUPPORTED_THROTTLE_LIMIT_TYPE);
    }
}
Also used : UnsupportedThrottleLimitTypeException(org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) Limit(org.wso2.carbon.apimgt.core.models.policy.Limit) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit) 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