Search in sources :

Example 1 with PolicyRetriever

use of org.wso2.carbon.apimgt.throttle.policy.deployer.PolicyRetriever in project carbon-apimgt by wso2.

the class PolicyUtil method deployAllPolicies.

/**
 * Deploy all the throttle policies retrieved from the database in the Traffic Manager.
 */
public static void deployAllPolicies() {
    // Undeploy all existing policies
    undeployAllPolicies();
    PolicyRetriever policyRetriever = new PolicyRetriever();
    try {
        // Deploy all the policies retrieved from the database
        SubscriptionPolicyList subscriptionPolicies = policyRetriever.getAllSubscriptionPolicies();
        for (SubscriptionPolicy subscriptionPolicy : subscriptionPolicies.getList()) {
            if (!(APIConstants.UNLIMITED_TIER.equalsIgnoreCase(subscriptionPolicy.getName()) || APIConstants.DEFAULT_SUB_POLICY_ASYNC_UNLIMITED.equalsIgnoreCase(subscriptionPolicy.getName()) || APIConstants.DEFAULT_SUB_POLICY_ASYNC_WH_UNLIMITED.equalsIgnoreCase(subscriptionPolicy.getName()))) {
                deployPolicy(subscriptionPolicy, null);
            }
        }
        ApplicationPolicyList applicationPolicies = policyRetriever.getAllApplicationPolicies();
        for (ApplicationPolicy applicationPolicy : applicationPolicies.getList()) {
            if (!APIConstants.UNLIMITED_TIER.equalsIgnoreCase(applicationPolicy.getName())) {
                deployPolicy(applicationPolicy, null);
            }
        }
        ApiPolicyList apiPolicies = policyRetriever.getAllApiPolicies();
        for (ApiPolicy apiPolicy : apiPolicies.getList()) {
            if (!APIConstants.UNLIMITED_TIER.equalsIgnoreCase(apiPolicy.getName())) {
                deployPolicy(apiPolicy, null);
            }
        }
        GlobalPolicyList globalPolicies = policyRetriever.getAllGlobalPolicies();
        for (GlobalPolicy globalPolicy : globalPolicies.getList()) {
            deployPolicy(globalPolicy, null);
        }
    } catch (ThrottlePolicyDeployerException e) {
        log.error("Error in retrieving throttle policies", e);
    }
}
Also used : ThrottlePolicyDeployerException(org.wso2.carbon.apimgt.throttle.policy.deployer.exception.ThrottlePolicyDeployerException) ApplicationPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicyList) SubscriptionPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicy) GlobalPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy) SubscriptionPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicyList) ApiPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy) ApiPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicyList) GlobalPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicyList) PolicyRetriever(org.wso2.carbon.apimgt.throttle.policy.deployer.PolicyRetriever)

Example 2 with PolicyRetriever

use of org.wso2.carbon.apimgt.throttle.policy.deployer.PolicyRetriever in project carbon-apimgt by wso2.

the class PolicyUtilTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("carbon.home", PolicyUtilTest.class.getResource("/").getFile());
    PowerMockito.mockStatic(PrivilegedCarbonContext.class);
    PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
    Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("carbon.super");
    PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
    eventProcessorService = Mockito.mock(EventProcessorService.class);
    PowerMockito.mockStatic(ServiceReferenceHolder.class);
    ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
    Mockito.when(serviceReferenceHolder.getEventProcessorService()).thenReturn(eventProcessorService);
    APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
    ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
    String[] skipThrottlePolicies = { "skipPolicy1" };
    Mockito.when(throttleProperties.getSkipRedeployingPolicies()).thenReturn(skipThrottlePolicies);
    Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
    Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.VELOCITY_LOGGER)).thenReturn(null);
    Mockito.when(serviceReferenceHolder.getAPIMConfiguration()).thenReturn(apiManagerConfiguration);
    PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
    policyRetriever = Mockito.mock(PolicyRetriever.class);
    PowerMockito.whenNew(PolicyRetriever.class).withNoArguments().thenReturn(policyRetriever);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) EventProcessorService(org.wso2.carbon.event.processor.core.EventProcessorService) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) PolicyRetriever(org.wso2.carbon.apimgt.throttle.policy.deployer.PolicyRetriever) Before(org.junit.Before)

Aggregations

PolicyRetriever (org.wso2.carbon.apimgt.throttle.policy.deployer.PolicyRetriever)2 Before (org.junit.Before)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)1 ApiPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy)1 ApiPolicyList (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicyList)1 ApplicationPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy)1 ApplicationPolicyList (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicyList)1 GlobalPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy)1 GlobalPolicyList (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicyList)1 SubscriptionPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicy)1 SubscriptionPolicyList (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicyList)1 ThrottlePolicyDeployerException (org.wso2.carbon.apimgt.throttle.policy.deployer.exception.ThrottlePolicyDeployerException)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 EventProcessorService (org.wso2.carbon.event.processor.core.EventProcessorService)1