use of org.wso2.carbon.event.processor.core.EventProcessorService in project carbon-apimgt by wso2.
the class PolicyUtil method undeployPolicies.
/**
* Undeploy the throttle policies passed as a list from the Traffic Manager.
*
* @param policyFileNames list of policy file names
*/
private static void undeployPolicies(List<String> policyFileNames) {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(APIConstants.SUPER_TENANT_DOMAIN, true);
EventProcessorService eventProcessorService = ServiceReferenceHolder.getInstance().getEventProcessorService();
for (String policyFileName : policyFileNames) {
String executionPlan = null;
try {
executionPlan = eventProcessorService.getActiveExecutionPlan(policyFileName);
} catch (ExecutionPlanConfigurationException e) {
// Do nothing when execution plan not found
}
if (executionPlan != null) {
eventProcessorService.undeployActiveExecutionPlan(policyFileName);
}
}
} catch (ExecutionPlanConfigurationException e) {
log.error("Error in removing execution plan", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.event.processor.core.EventProcessorService 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();
}
}
use of org.wso2.carbon.event.processor.core.EventProcessorService in project carbon-apimgt by wso2.
the class PolicyUtilTest method testAddPolicy_APPType.
@Test
public void testAddPolicy_APPType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
ApplicationPolicy policy = TestUtil.getPolicyAppLevel();
ApplicationPolicyEvent policyEvent = new ApplicationPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_CREATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType());
PolicyUtil.deployPolicy(policy, policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).deployExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.event.processor.core.EventProcessorService in project carbon-apimgt by wso2.
the class PolicyUtilTest method testDeletePolicy_AppType.
@Test
public void testDeletePolicy_AppType() throws ExecutionPlanConfigurationException {
ApplicationPolicy policy = TestUtil.getPolicyAppLevel();
ApplicationPolicyEvent policyEvent = new ApplicationPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_UPDATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType());
Mockito.when(eventProcessorService.getActiveExecutionPlan(policy.getTenantDomain() + "_" + PolicyConstants.POLICY_LEVEL_APP + "_" + policy.getName())).thenReturn("EXECUTION_PLAN");
PolicyUtil.undeployPolicy(policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).undeployActiveExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.event.processor.core.EventProcessorService in project carbon-apimgt by wso2.
the class PolicyUtilTest method testAddPolicy_GlobalType.
@Test
public void testAddPolicy_GlobalType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
GlobalPolicy policy = TestUtil.getPolicyGlobalLevel();
GlobalPolicyEvent policyEvent = new GlobalPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_CREATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName());
PolicyUtil.deployPolicy(policy, policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).deployExecutionPlan(Mockito.anyString());
}
Aggregations