use of org.wso2.carbon.apimgt.api.model.policy.Pipeline 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.api.model.policy.Pipeline 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.api.model.policy.Pipeline in project carbon-apimgt by wso2.
the class APIThrottlePolicyTemplateBuilder method getThrottlePolicyTemplateForAPILevelDefaultCondition.
/**
* Generate default policy for api level throttling
*
* @return throttle policies for default api
* @throws APITemplateException throws if generation failure occur
*/
public String getThrottlePolicyTemplateForAPILevelDefaultCondition() throws APITemplateException {
if (log.isDebugEnabled()) {
log.debug("Generating Siddhi App for apiLevel :" + apiPolicy.toString());
}
// get velocity template for API policy and generate the template
Set<String> conditionsSet = new HashSet<String>();
List<Pipeline> pipelines = apiPolicy.getPipelines();
VelocityEngine velocityengine = initVelocityEngine();
Template template = velocityengine.getTemplate(getTemplatePathForAPIDefaultPolicy());
StringWriter writer;
VelocityContext context;
// when APIPolicy contains pipelines, get template as a string
if (pipelines != null) {
for (Pipeline pipeline : pipelines) {
String conditionString = getPolicyConditionForDefault(pipeline.getConditions());
if (!StringUtils.isEmpty(conditionString)) {
conditionsSet.add(conditionString);
}
}
}
// for default API policy
context = new VelocityContext();
setConstantContext(context);
// default policy is defined as 'elseCondition' , set values for velocity context
context.put(PIPELINE, ELSE_CONDITION);
context.put(PIPELINE_ITEM, null);
context.put(POLICY, apiPolicy);
context.put(QUOTA_POLICY, apiPolicy.getDefaultQuotaPolicy());
String conditionSetString = getConditionForDefault(conditionsSet);
if (!StringUtils.isEmpty(conditionSetString)) {
context.put(CONDITION, AND + conditionSetString);
} else {
context.put(CONDITION, EMPTY_STRING);
}
writer = new StringWriter();
template.merge(context, writer);
if (log.isDebugEnabled()) {
log.debug("Generated Siddhi App : " + writer.toString());
}
return writer.toString();
}
use of org.wso2.carbon.apimgt.api.model.policy.Pipeline in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtil method fromAdvancedPolicyDTOToPolicy.
/**
* Converts a single Advanced Policy DTO into a model object
*
* @param dto Advanced policy DTO object
* @return Converted Advanced policy model object
* @throws UnsupportedThrottleLimitTypeException - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static APIPolicy fromAdvancedPolicyDTOToPolicy(AdvancedThrottlePolicyDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
APIPolicy apiPolicy = new APIPolicy(dto.getId(), dto.getPolicyName());
apiPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, apiPolicy);
List<Pipeline> pipelines = CommonThrottleMappingUtil.fromConditionalGroupDTOListToPipelineList(dto.getConditionalGroups());
apiPolicy.setPipelines(pipelines);
if (dto.getDefaultLimit() != null) {
apiPolicy.setDefaultQuotaPolicy(CommonThrottleMappingUtil.fromDTOToQuotaPolicy(dto.getDefaultLimit()));
}
return apiPolicy;
}
use of org.wso2.carbon.apimgt.api.model.policy.Pipeline in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromConditionalGroupDTOToPipeline.
/**
* Converts a single Conditional Group DTO into a Pipeline object
*
* @param dto Conditional Group DTO
* @return Derived Pipeline object from Conditional Group DTO
* @throws UnsupportedThrottleLimitTypeException - If error occurs
* @throws UnsupportedThrottleConditionTypeException - If error occurs
*/
public static Pipeline fromConditionalGroupDTOToPipeline(ConditionalGroupDTO dto) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
Pipeline pipeline = new Pipeline();
pipeline.setDescription(dto.getDescription());
pipeline.setEnabled(true);
pipeline.setQuotaPolicy(fromDTOToQuotaPolicy(dto.getLimit()));
List<Condition> conditions = fromDTOListToConditionList(dto.getConditions());
pipeline.setConditions(conditions);
return pipeline;
}
Aggregations