use of org.wso2.carbon.event.processor.core.ExecutionPlanConfiguration in project carbon-apimgt by wso2.
the class PolicyUtilTest method testDeployAllPolicies.
@Test
public void testDeployAllPolicies() throws ExecutionPlanConfigurationException, ThrottlePolicyDeployerException, ExecutionPlanDependencyValidationException {
ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
Map<String, ExecutionPlanConfiguration> executionPlanConfigurationMap = new HashMap<>();
ExecutionPlanConfiguration executionPlanConfiguration = Mockito.mock(ExecutionPlanConfiguration.class);
executionPlanConfigurationMap.put("sample_policy", executionPlanConfiguration);
Mockito.when(eventProcessorService.getAllActiveExecutionConfigurations()).thenReturn(executionPlanConfigurationMap);
SubscriptionPolicyList subscriptionPolicyList = new SubscriptionPolicyList();
SubscriptionPolicy subscriptionPolicy = TestUtil.getPolicySubLevel();
List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
subscriptionPolicies.add(subscriptionPolicy);
subscriptionPolicyList.setList(subscriptionPolicies);
Mockito.when(policyRetriever.getAllSubscriptionPolicies()).thenReturn(subscriptionPolicyList);
ApplicationPolicyList applicationPolicyList = new ApplicationPolicyList();
ApplicationPolicy applicationPolicy = TestUtil.getPolicyAppLevel();
List<ApplicationPolicy> applicationPolicies = new ArrayList<>();
applicationPolicies.add(applicationPolicy);
applicationPolicyList.setList(applicationPolicies);
Mockito.when(policyRetriever.getAllApplicationPolicies()).thenReturn(applicationPolicyList);
ApiPolicyList apiPolicyList = new ApiPolicyList();
ApiPolicy apiPolicy = TestUtil.getPolicyAPILevel();
List<ApiPolicy> apiPolicies = new ArrayList<>();
apiPolicies.add(apiPolicy);
apiPolicyList.setList(apiPolicies);
Mockito.when(policyRetriever.getAllApiPolicies()).thenReturn(apiPolicyList);
GlobalPolicyList globalPolicyList = new GlobalPolicyList();
GlobalPolicy globalPolicy = TestUtil.getPolicyGlobalLevel();
List<GlobalPolicy> globalPolicies = new ArrayList<>();
globalPolicies.add(globalPolicy);
globalPolicyList.setList(globalPolicies);
Mockito.when(policyRetriever.getAllGlobalPolicies()).thenReturn(globalPolicyList);
PolicyUtil.deployAllPolicies();
Mockito.verify(eventProcessorService, Mockito.times(5)).deployExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.event.processor.core.ExecutionPlanConfiguration in project carbon-apimgt by wso2.
the class PolicyUtil method undeployAllPolicies.
/**
* Undeploy all the throttle policies in the Traffic Manager except the excluded ones.
*/
private static void undeployAllPolicies() {
APIManagerConfiguration apiManagerConfiguration = ServiceReferenceHolder.getInstance().getAPIMConfiguration();
EventProcessorService eventProcessorService = ServiceReferenceHolder.getInstance().getEventProcessorService();
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(APIConstants.SUPER_TENANT_DOMAIN, true);
Map<String, ExecutionPlanConfiguration> executionPlanConfigurationMap = eventProcessorService.getAllActiveExecutionConfigurations();
// Undeploy all the policies except the skip ones provided
for (Map.Entry<String, ExecutionPlanConfiguration> pair : executionPlanConfigurationMap.entrySet()) {
String policyPlanName = pair.getKey();
boolean skiped = false;
for (String skipPolicyName : apiManagerConfiguration.getThrottleProperties().getSkipRedeployingPolicies()) {
if (skipPolicyName.equalsIgnoreCase(policyPlanName)) {
skiped = true;
break;
}
}
if (!skiped) {
eventProcessorService.undeployActiveExecutionPlan(policyPlanName);
}
}
} catch (ExecutionPlanConfigurationException e) {
log.error("Error in removing existing throttle policies", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
Aggregations