Search in sources :

Example 1 with ArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.

the class ExtensionModelDiscoverer method discoverPluginsExtensionModels.

/**
 * For each artifactPlugin discovers the {@link ExtensionModel}.
 *
 * @param loaderRepository {@link ExtensionModelLoaderRepository} with the available extension loaders.
 * @param artifactPlugins {@link Pair} of {@link ArtifactPluginDescriptor} and {@link ArtifactClassLoader} for artifact plugins
 *        deployed inside the artifact. Non null.
 * @param parentArtifactExtensions {@link Set} of {@link ExtensionModel} to also take into account when parsing extensions
 * @return {@link Set} of {@link Pair} carrying the {@link ArtifactPluginDescriptor} and it's corresponding
 *         {@link ExtensionModel}.
 */
public Set<Pair<ArtifactPluginDescriptor, ExtensionModel>> discoverPluginsExtensionModels(ExtensionModelLoaderRepository loaderRepository, List<Pair<ArtifactPluginDescriptor, ArtifactClassLoader>> artifactPlugins, Set<ExtensionModel> parentArtifactExtensions) {
    final Set<Pair<ArtifactPluginDescriptor, ExtensionModel>> descriptorsWithExtensions = new HashSet<>();
    artifactPlugins.forEach(artifactPlugin -> {
        Set<ExtensionModel> extensions = descriptorsWithExtensions.stream().map(Pair::getSecond).collect(toSet());
        extensions.addAll(parentArtifactExtensions);
        final ArtifactPluginDescriptor artifactPluginDescriptor = artifactPlugin.getFirst();
        Optional<LoaderDescriber> loaderDescriber = artifactPluginDescriptor.getExtensionModelDescriptorProperty();
        ClassLoader artifactClassloader = artifactPlugin.getSecond().getClassLoader();
        String artifactName = artifactPluginDescriptor.getName();
        ExtensionModel extension = loaderDescriber.map(describer -> discoverExtensionThroughJsonDescriber(loaderRepository, describer, extensions, artifactClassloader, artifactName)).orElse(null);
        if (extension != null) {
            descriptorsWithExtensions.add(new Pair<>(artifactPluginDescriptor, extension));
        }
    });
    return descriptorsWithExtensions;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ExtensionModelLoaderRepository(org.mule.runtime.module.extension.internal.loader.ExtensionModelLoaderRepository) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) Collection(java.util.Collection) Set(java.util.Set) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) RuntimeExtensionModelProvider(org.mule.runtime.core.api.extension.RuntimeExtensionModelProvider) HashSet(java.util.HashSet) List(java.util.List) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) Optional(java.util.Optional) Pair(org.mule.runtime.api.util.Pair) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) Collectors.toSet(java.util.stream.Collectors.toSet) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) Pair(org.mule.runtime.api.util.Pair) HashSet(java.util.HashSet)

Example 2 with ArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.

the class ContainerClassLoaderFactoryTestCase method doesNotFindAnyResources.

@Test
public void doesNotFindAnyResources() throws Exception {
    final ContainerClassLoaderFactory factory = createClassLoaderExportingBootstrapProperties();
    final ArtifactClassLoader containerClassLoader = factory.createContainerClassLoader(this.getClass().getClassLoader());
    final Enumeration<URL> resources = containerClassLoader.findResources(BOOTSTRAP_PROPERTIES);
    assertThat(resources.hasMoreElements(), is(false));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.

the class ContainerClassLoaderFactoryTestCase method getResourcesFromParent.

@Test
public void getResourcesFromParent() throws Exception {
    final ContainerClassLoaderFactory factory = createClassLoaderExportingBootstrapProperties();
    final ArtifactClassLoader containerClassLoader = factory.createContainerClassLoader(this.getClass().getClassLoader());
    final Enumeration<URL> resources = containerClassLoader.getClassLoader().getResources(BOOTSTRAP_PROPERTIES);
    assertThat(resources.hasMoreElements(), is(true));
    Set<String> items = new HashSet<>();
    int size = 0;
    while (resources.hasMoreElements()) {
        final String url = resources.nextElement().toString();
        items.add(url);
        size++;
    }
    assertThat(size, equalTo(items.size()));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.

the class ContainerClassLoaderFactoryTestCase method doesNotFindAnyResource.

@Test
public void doesNotFindAnyResource() throws Exception {
    final ContainerClassLoaderFactory factory = createClassLoaderExportingBootstrapProperties();
    final ArtifactClassLoader containerClassLoader = factory.createContainerClassLoader(this.getClass().getClassLoader());
    final URL resource = containerClassLoader.findResource(BOOTSTRAP_PROPERTIES);
    assertThat(resource, is(nullValue()));
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) URL(java.net.URL) Test(org.junit.Test)

Example 5 with ArtifactClassLoader

use of org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader in project mule by mulesoft.

the class DomainDeploymentTestCase method refreshDomainClassloaderAfterRedeployment.

@Ignore("MULE-6926: flaky test")
@Test
public void refreshDomainClassloaderAfterRedeployment() throws Exception {
    startDeployment();
    // Deploy domain and apps and wait until success
    addPackedDomainFromBuilder(sharedDomainFileBuilder);
    addPackedAppFromBuilder(sharedAAppFileBuilder);
    addPackedAppFromBuilder(sharedBAppFileBuilder);
    assertDeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
    assertDeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
    assertDeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
    // Ensure resources are registered at domain's registry
    Domain domain = findADomain(sharedDomainFileBuilder.getId());
    assertThat(domain.getRegistry().lookupByName("http-listener-config").isPresent(), is(true));
    ArtifactClassLoader initialArtifactClassLoader = domain.getArtifactClassLoader();
    reset(domainDeploymentListener);
    reset(applicationDeploymentListener);
    // Force redeployment by touching the domain's config file
    File domainFolder = new File(domainsDir.getPath(), sharedDomainFileBuilder.getId());
    File configFile = new File(domainFolder, sharedDomainFileBuilder.getConfigFile());
    long firstFileTimestamp = configFile.lastModified();
    touch(configFile);
    alterTimestampIfNeeded(configFile, firstFileTimestamp);
    assertUndeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
    assertUndeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
    assertUndeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
    assertDeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
    assertDeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
    assertDeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
    domain = findADomain(sharedDomainFileBuilder.getId());
    ArtifactClassLoader artifactClassLoaderAfterRedeployment = domain.getArtifactClassLoader();
    // Ensure that after redeployment the domain's class loader has changed
    assertThat(artifactClassLoaderAfterRedeployment, not(sameInstance(initialArtifactClassLoader)));
    // Undeploy domain and apps
    removeAppAnchorFile(sharedAAppFileBuilder.getId());
    removeAppAnchorFile(sharedBAppFileBuilder.getId());
    removeDomainAnchorFile(sharedDomainFileBuilder.getId());
    assertUndeploymentSuccess(applicationDeploymentListener, sharedAAppFileBuilder.getId());
    assertUndeploymentSuccess(applicationDeploymentListener, sharedBAppFileBuilder.getId());
    assertUndeploymentSuccess(domainDeploymentListener, sharedDomainFileBuilder.getId());
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) Domain(org.mule.runtime.deployment.model.api.domain.Domain) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) File(java.io.File) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)58 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)17 URL (java.net.URL)12 ClassLoaderLookupPolicy (org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy)12 Pair (org.mule.runtime.api.util.Pair)10 ArtifactPluginDescriptor (org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor)10 MuleArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader)10 Service (org.mule.runtime.api.service.Service)8 SmallTest (org.mule.tck.size.SmallTest)8 LookupStrategy (org.mule.runtime.module.artifact.api.classloader.LookupStrategy)7 Map (java.util.Map)6 RegionClassLoader (org.mule.runtime.module.artifact.api.classloader.RegionClassLoader)6 File (java.io.File)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 MuleModule (org.mule.runtime.container.api.MuleModule)5 ContainerOnlyLookupStrategy (org.mule.runtime.container.internal.ContainerOnlyLookupStrategy)5 HashSet (java.util.HashSet)4