Search in sources :

Example 11 with ExecutionPlanConfigurationException

use of org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException in project carbon-apimgt by wso2.

the class PolicyUtilTest method testAddPolicy_APIType.

@Test
public void testAddPolicy_APIType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
    ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
    Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
    ApiPolicy policy = TestUtil.getPolicyAPILevel();
    APIPolicyEvent policyEvent = new APIPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_CREATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType(), null, null);
    PolicyUtil.deployPolicy(policy, policyEvent);
    Mockito.verify(eventProcessorService, Mockito.times(2)).deployExecutionPlan(Mockito.anyString());
}
Also used : APIPolicyEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIPolicyEvent) ApiPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy) ExecutionPlanConfigurationException(org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with ExecutionPlanConfigurationException

use of org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException in project carbon-apimgt by wso2.

the class PolicyUtilTest method testDeletePolicy_GlobalType.

@Test
public void testDeletePolicy_GlobalType() throws ExecutionPlanConfigurationException {
    GlobalPolicy policy = TestUtil.getPolicyGlobalLevel();
    GlobalPolicyEvent policyEvent = new GlobalPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_DELETE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName());
    Mockito.when(eventProcessorService.getActiveExecutionPlan(PolicyConstants.POLICY_LEVEL_GLOBAL + "_" + policy.getName())).thenReturn("EXECUTION_PLAN");
    PolicyUtil.undeployPolicy(policyEvent);
    Mockito.verify(eventProcessorService, Mockito.times(1)).undeployActiveExecutionPlan(Mockito.anyString());
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy) GlobalPolicyEvent(org.wso2.carbon.apimgt.impl.notifier.events.GlobalPolicyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with ExecutionPlanConfigurationException

use of org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException 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();
    }
}
Also used : ExecutionPlanConfigurationException(org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException) EventProcessorService(org.wso2.carbon.event.processor.core.EventProcessorService)

Example 14 with ExecutionPlanConfigurationException

use of org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException 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();
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ExecutionPlanConfiguration(org.wso2.carbon.event.processor.core.ExecutionPlanConfiguration) ExecutionPlanConfigurationException(org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map) EventProcessorService(org.wso2.carbon.event.processor.core.EventProcessorService)

Example 15 with ExecutionPlanConfigurationException

use of org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException 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());
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy) ExecutionPlanConfigurationException(org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException) ApplicationPolicyEvent(org.wso2.carbon.apimgt.impl.notifier.events.ApplicationPolicyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 ExecutionPlanConfigurationException (org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException)9 ApiPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy)5 ApplicationPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy)5 GlobalPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy)5 SubscriptionPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicy)5 ArrayList (java.util.ArrayList)4 APIPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.APIPolicyEvent)4 HashMap (java.util.HashMap)3 ApplicationPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.ApplicationPolicyEvent)3 GlobalPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.GlobalPolicyEvent)3 SubscriptionPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionPolicyEvent)3 EventProcessorService (org.wso2.carbon.event.processor.core.EventProcessorService)3 Map (java.util.Map)2 ExecutionPlanConfiguration (org.wso2.carbon.event.processor.core.ExecutionPlanConfiguration)2 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 APITemplateException (org.wso2.carbon.apimgt.impl.template.APITemplateException)1 ApiPolicyList (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicyList)1 ApplicationPolicyList (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicyList)1