Search in sources :

Example 1 with ApplicationPolicyManager

use of org.mule.runtime.deployment.model.api.application.ApplicationPolicyManager in project mule by mulesoft.

the class TestPolicyManager method addPolicy.

/**
 * Adds a parameterized policy
 *
 * @param appName application where the policy must be applied. Non empty.
 * @param policyTemplateName template that must be used to instantiate the parametrized policy. Non empty.
 * @param policyParametrization parametrization to instantiate the policy. Non null.
 */
public void addPolicy(String appName, String policyTemplateName, PolicyParametrization policyParametrization) throws PolicyRegistrationException {
    checkArgument(!isEmpty(appName), "appName cannot be empty");
    checkArgument(!isEmpty(policyTemplateName), "policyTemplateName cannot be empty");
    checkArgument(policyParametrization != null, "policyParametrization cannot be ull");
    Optional<PolicyTemplateDescriptor> policyTemplateDescriptor = policyTemplateDescriptors.stream().filter(template -> template.getName().equals(policyTemplateName)).findFirst();
    if (!policyTemplateDescriptor.isPresent()) {
        throw new IllegalStateException("Cannot find policy template descriptor with name: " + policyTemplateName);
    }
    Application application = deploymentService.findApplication(appName);
    ApplicationPolicyManager policyManager = application.getPolicyManager();
    policyManager.addPolicy(policyTemplateDescriptor.get(), policyParametrization);
}
Also used : DeploymentService(org.mule.runtime.module.deployment.api.DeploymentService) Optional.empty(java.util.Optional.empty) PolicyTemplateDescriptorFactory(org.mule.runtime.module.deployment.impl.internal.policy.PolicyTemplateDescriptorFactory) ApplicationPolicyManager(org.mule.runtime.deployment.model.api.application.ApplicationPolicyManager) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) IOException(java.io.IOException) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) File(java.io.File) ArrayList(java.util.ArrayList) FilenameUtils.getBaseName(org.apache.commons.io.FilenameUtils.getBaseName) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) List(java.util.List) FileUtils.unzip(org.mule.runtime.core.api.util.FileUtils.unzip) MuleFoldersUtil.getExecutionFolder(org.mule.runtime.container.api.MuleFoldersUtil.getExecutionFolder) Optional(java.util.Optional) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) Application(org.mule.runtime.deployment.model.api.application.Application) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) ApplicationPolicyManager(org.mule.runtime.deployment.model.api.application.ApplicationPolicyManager) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) Application(org.mule.runtime.deployment.model.api.application.Application)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 FilenameUtils.getBaseName (org.apache.commons.io.FilenameUtils.getBaseName)1 StringUtils.isEmpty (org.apache.commons.lang3.StringUtils.isEmpty)1 Preconditions.checkArgument (org.mule.runtime.api.util.Preconditions.checkArgument)1 MuleFoldersUtil.getExecutionFolder (org.mule.runtime.container.api.MuleFoldersUtil.getExecutionFolder)1 PolicyParametrization (org.mule.runtime.core.api.policy.PolicyParametrization)1 FileUtils.unzip (org.mule.runtime.core.api.util.FileUtils.unzip)1 Application (org.mule.runtime.deployment.model.api.application.Application)1 ApplicationPolicyManager (org.mule.runtime.deployment.model.api.application.ApplicationPolicyManager)1 PolicyRegistrationException (org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)1 PolicyTemplateDescriptor (org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor)1 DeploymentListener (org.mule.runtime.module.deployment.api.DeploymentListener)1 DeploymentService (org.mule.runtime.module.deployment.api.DeploymentService)1 PolicyTemplateDescriptorFactory (org.mule.runtime.module.deployment.impl.internal.policy.PolicyTemplateDescriptorFactory)1