use of org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException in project mule by mulesoft.
the class MuleApplicationPolicyProvider method addPolicy.
@Override
public synchronized void addPolicy(PolicyTemplateDescriptor policyTemplateDescriptor, PolicyParametrization parametrization) throws PolicyRegistrationException {
try {
checkArgument(application != null, "application was not configured on the policy provider");
Optional<RegisteredPolicyInstanceProvider> registeredPolicyInstanceProvider = registeredPolicyInstanceProviders.stream().filter(p -> p.getPolicyId().equals(parametrization.getId())).findFirst();
if (registeredPolicyInstanceProvider.isPresent()) {
throw new IllegalArgumentException(createPolicyAlreadyRegisteredError(parametrization.getId()));
}
Optional<RegisteredPolicyTemplate> registeredPolicyTemplate = registeredPolicyTemplates.stream().filter(p -> p.policyTemplate.getDescriptor().getBundleDescriptor().getArtifactId().equals(policyTemplateDescriptor.getBundleDescriptor().getArtifactId())).findAny();
if (!registeredPolicyTemplate.isPresent()) {
PolicyTemplate policyTemplate = policyTemplateFactory.createArtifact(application, policyTemplateDescriptor);
registeredPolicyTemplate = of(new RegisteredPolicyTemplate(policyTemplate));
registeredPolicyTemplates.add(registeredPolicyTemplate.get());
}
ApplicationPolicyInstance applicationPolicyInstance = policyInstanceProviderFactory.create(application, registeredPolicyTemplate.get().policyTemplate, parametrization);
applicationPolicyInstance.initialise();
registeredPolicyInstanceProviders.add(new RegisteredPolicyInstanceProvider(applicationPolicyInstance, parametrization.getId()));
registeredPolicyInstanceProviders.sort(null);
registeredPolicyTemplate.get().count++;
} catch (Exception e) {
throw new PolicyRegistrationException(createPolicyRegistrationError(parametrization.getId()), e);
}
}
use of org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method failsToApplyApplicationPolicyWithPluginVersionMismatch.
@Test
public void failsToApplyApplicationPolicyWithPluginVersionMismatch() throws Exception {
policyManager.registerPolicyTemplate(policyIncludingHelloPluginV2FileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
try {
policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingHelloPluginV2FileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.xml"), emptyList()));
fail("Policy application should have failed");
} catch (PolicyRegistrationException expected) {
}
}
use of org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException in project mule by mulesoft.
the class DomainDeploymentTestCase method failsToApplyApplicationPolicyWithDomainPluginVersionMismatch.
@Test
public void failsToApplyApplicationPolicyWithDomainPluginVersionMismatch() throws Exception {
installEchoService();
installFooService();
policyManager.registerPolicyTemplate(policyIncludingHelloPluginV2FileBuilder.getArtifactFile());
DomainFileBuilder domainFileBuilder = new DomainFileBuilder("dummy-domain-bundle").definedBy("empty-domain-config.xml").dependingOn(helloExtensionV1Plugin);
ApplicationFileBuilder applicationFileBuilder = new ApplicationFileBuilder("dummyWithHelloExtension").definedBy(APP_WITH_EXTENSION_PLUGIN_CONFIG).dependingOn(domainFileBuilder);
addPackedDomainFromBuilder(domainFileBuilder);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
try {
policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingHelloPluginV2FileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.xml"), emptyList()));
fail("Policy application should have failed");
} catch (PolicyRegistrationException expected) {
}
}
use of org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException in project mule by mulesoft.
the class ApplicationPolicyDeploymentTestCase method failsToApplyBrokenApplicationPolicy.
@Test
public void failsToApplyBrokenApplicationPolicy() throws Exception {
PolicyFileBuilder brokenPolicyFileBuilder = new PolicyFileBuilder(BAR_POLICY_NAME).describedBy(new MulePolicyModel.MulePolicyModelBuilder().setMinMuleVersion(MIN_MULE_VERSION).setName(BAR_POLICY_NAME).setRequiredProduct(MULE).withBundleDescriptorLoader(createBundleDescriptorLoader(BAR_POLICY_NAME, MULE_POLICY_CLASSIFIER, PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID)).withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap())).build());
policyManager.registerPolicyTemplate(brokenPolicyFileBuilder.getArtifactFile());
ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin);
addPackedAppFromBuilder(applicationFileBuilder);
startDeployment();
assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
try {
policyManager.addPolicy(applicationFileBuilder.getId(), brokenPolicyFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, parameters -> true, 1, emptyMap(), getResourceFile("/brokenPolicy.xml"), emptyList()));
fail("Policy application should have failed");
} catch (PolicyRegistrationException expected) {
}
}
use of org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException 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);
}
Aggregations