use of org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor 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);
}
use of org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor in project mule by mulesoft.
the class TestPolicyManager method registerPolicyTemplate.
/**
* Registers a policy template that can be later used to register a parameterized policy
*
* @param policyTemplate policy artifact file. Non null.
*/
public void registerPolicyTemplate(File policyTemplate) {
final File tempFolder = new File(getPoliciesTempFolder(), getBaseName(policyTemplate.getName()));
try {
unzip(policyTemplate, tempFolder);
} catch (IOException e) {
throw new IllegalStateException("Error processing policy ZIP file: " + policyTemplate, e);
}
final PolicyTemplateDescriptor policyTemplateDescriptor = policyTemplateDescriptorFactory.create(tempFolder, empty());
policyTemplateDescriptors.add(policyTemplateDescriptor);
}
use of org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor in project mule by mulesoft.
the class ArtifactAwareContextSelectorTestCase method returnsParentContextForPolicyClassloader.
@Test
public void returnsParentContextForPolicyClassloader() throws MalformedURLException {
ClassLoader childClassLoader = new URLClassLoader(new URL[0], regionClassLoader);
PolicyTemplateDescriptor policyTemplateDescriptor = new PolicyTemplateDescriptor(POLICY_TEMPLATE_NAME, empty());
RegionClassLoader policyRegionClassLoader = spy(getPolicyRegionClassLoader(policyTemplateDescriptor));
MuleArtifactClassLoader policyClassLoader = getPolicyArtifactClassLoader(policyTemplateDescriptor, policyRegionClassLoader);
LoggerContext appCtx = selector.getContext("", childClassLoader, true);
LoggerContext policyCtx = selector.getContext("", policyClassLoader, true);
assertThat(policyCtx, sameInstance(appCtx));
}
Aggregations