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);
}
}
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);
}
Aggregations