use of org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit in project carbon-apimgt by wso2.
the class TierMappingUtil method fromTierToDTO.
/**
* Converts a Tier object into TierDTO
*
* @param tier Tier object
* @param tierLevel tier level (api/application or resource)
* @return TierDTO corresponds to Tier object
*/
public static TierDTO fromTierToDTO(Policy tier, String tierLevel) {
TierDTO dto = new TierDTO();
dto.setName(tier.getPolicyName());
dto.setDescription(tier.getDescription());
dto.setTierLevel(TierDTO.TierLevelEnum.valueOf(StringUtils.upperCase(tierLevel)));
dto.setUnitTime((long) tier.getDefaultQuotaPolicy().getLimit().getUnitTime());
Limit limit = tier.getDefaultQuotaPolicy().getLimit();
if (limit instanceof RequestCountLimit) {
dto.setRequestCount((long) ((RequestCountLimit) limit).getRequestCount());
} else if (limit instanceof BandwidthLimit) {
dto.setRequestCount((long) ((BandwidthLimit) limit).getDataAmount());
}
// // TODO: 08/12/16 More fields to map
return dto;
}
use of org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit 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;
}
use of org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit 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.core.models.policy.BandwidthLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method updateAPIPolicy.
/**
* Updated the given API policy
*
* @param apiPolicy {@link APIPolicy} instance to be updated
* @return updated {@link APIPolicy} instance
*/
public static APIPolicy updateAPIPolicy(APIPolicy apiPolicy) {
apiPolicy.setDisplayName(UPDATED_SAMPLE_API_POLICY);
apiPolicy.setDescription(UPDATED_SAMPLE_API_POLICY_DESCRIPTION);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
defaultQuotaPolicy.setLimit(bandwidthLimit);
apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
apiPolicy.setPipelines(createDefaultPipelines());
apiPolicy.getPipelines().add(createNewIPRangePipeline());
return apiPolicy;
}
use of org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createAPIPolicyWithBndwidthLimit.
public static APIPolicy createAPIPolicyWithBndwidthLimit(String name) {
APIPolicy apiPolicy = new APIPolicy(name);
apiPolicy.setDescription("testDescription");
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("bandwidth");
BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
quotaPolicy.setLimit(bandwidthLimit);
apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
apiPolicy.setDisplayName("displayName");
return apiPolicy;
}
Aggregations