use of org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor 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.PolicyTemplateDescriptor in project mule by mulesoft.
the class PolicyTemplateClassLoaderFactoryTestCase method setUp.
@Before
public void setUp() throws Exception {
descriptor = new PolicyTemplateDescriptor("testPolicy");
descriptor.setRootFolder(policyFolder.getRoot());
parentClassLoader = mock(ArtifactClassLoader.class);
when(parentClassLoader.getClassLoader()).thenReturn(getClass().getClassLoader());
when(lookupPolicy.getClassLookupStrategy(anyString())).thenReturn(PARENT_FIRST);
when(parentClassLoader.getClassLoaderLookupPolicy()).thenReturn(lookupPolicy);
}
use of org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor in project mule by mulesoft.
the class PolicyTemplateDescriptorFactoryTestCase method readsRuntimeLibs.
@Test
public void readsRuntimeLibs() throws Exception {
MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID));
mulePolicyModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(FILE_SYSTEM_POLICY_MODEL_LOADER_ID, emptyMap()));
PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).usingLibrary(echoTestJarFile.getAbsolutePath()).describedBy(mulePolicyModelBuilder.build());
File tempFolder = createTempFolder();
unzip(policyFileBuilder.getArtifactFile(), tempFolder);
PolicyTemplateDescriptorFactory descriptorFactory = new PolicyTemplateDescriptorFactory(artifactPluginDescriptorLoader, descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
PolicyTemplateDescriptor desc = descriptorFactory.create(tempFolder, empty());
assertThat(desc.getClassLoaderModel().getUrls().length, equalTo(2));
assertThat(toFile(desc.getClassLoaderModel().getUrls()[0]).getPath(), equalTo(tempFolder.toString()));
assertThat(toFile(desc.getClassLoaderModel().getUrls()[1]).getPath(), equalTo(new File(tempFolder, LIB_DIR + separator + JAR_FILE_NAME).toString()));
}
use of org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor in project mule by mulesoft.
the class PolicyTemplateDescriptorFactoryTestCase method readsPlugin.
@Test
public void readsPlugin() throws Exception {
MulePolicyModelBuilder policyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID)).withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
ArtifactPluginFileBuilder plugin1 = new ArtifactPluginFileBuilder("plugin1");
ArtifactPluginFileBuilder plugin2 = new ArtifactPluginFileBuilder("plugin2");
PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).describedBy(policyModelBuilder.build()).dependingOn(plugin1).dependingOn(plugin2);
File tempFolder = createTempFolder();
unzip(policyFileBuilder.getArtifactFile(), tempFolder);
final ArtifactPluginDescriptorFactory pluginDescriptorFactory = mock(ArtifactPluginDescriptorFactory.class);
final PolicyTemplateDescriptorFactory policyTemplateDescriptorFactory = new PolicyTemplateDescriptorFactory(new ArtifactPluginDescriptorLoader(pluginDescriptorFactory), descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
final ArtifactPluginDescriptor expectedPluginDescriptor1 = new ArtifactPluginDescriptor("plugin1");
final ArtifactPluginDescriptor expectedPluginDescriptor2 = new ArtifactPluginDescriptor("plugin2");
when(pluginDescriptorFactory.create(any(), any())).thenReturn(expectedPluginDescriptor1).thenReturn(expectedPluginDescriptor2);
PolicyTemplateDescriptor descriptor = policyTemplateDescriptorFactory.create(tempFolder, empty());
Set<ArtifactPluginDescriptor> plugins = descriptor.getPlugins();
assertThat(plugins.size(), equalTo(2));
assertThat(plugins, hasItem(equalTo(expectedPluginDescriptor1)));
assertThat(plugins, hasItem(equalTo(expectedPluginDescriptor2)));
}
use of org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor in project mule by mulesoft.
the class PolicyTemplateDescriptorFactoryTestCase method assignsBundleDescriptor.
@Test
public void assignsBundleDescriptor() throws Exception {
MulePolicyModelBuilder mulePolicyModelBuilder = new MulePolicyModelBuilder().setName(POLICY_NAME).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).withBundleDescriptorLoader(createPolicyBundleDescriptorLoader(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID)).withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
PolicyFileBuilder policyFileBuilder = new PolicyFileBuilder(POLICY_NAME).usingLibrary(echoTestJarFile.getAbsolutePath()).describedBy(mulePolicyModelBuilder.build());
File tempFolder = createTempFolder();
unzip(policyFileBuilder.getArtifactFile(), tempFolder);
PolicyTemplateDescriptorFactory descriptorFactory = new PolicyTemplateDescriptorFactory(artifactPluginDescriptorLoader, descriptorLoaderRepository, ArtifactDescriptorValidatorBuilder.builder());
PolicyTemplateDescriptor desc = descriptorFactory.create(tempFolder, empty());
assertThat(desc.getBundleDescriptor().getArtifactId(), equalTo(POLICY_NAME));
assertThat(desc.getBundleDescriptor().getGroupId(), equalTo(POLICY_GROUP_ID));
assertThat(desc.getBundleDescriptor().getClassifier().get(), equalTo(POLICY_CLASSIFIER));
assertThat(desc.getBundleDescriptor().getType(), equalTo(POLICY_ARTIFACT_TYPE));
assertThat(desc.getBundleDescriptor().getVersion(), equalTo(POLICY_VERSION));
}
Aggregations