Search in sources :

Example 16 with Domain

use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.

the class DefaultToolingService method doCreateApplication.

private Application doCreateApplication(File toolingApplicationContent, Optional<Properties> deploymentProperties) throws IOException {
    Optional<Properties> mergedDeploymentProperties = of(createDeploymentProperties(deploymentProperties));
    MuleApplicationModel.MuleApplicationModelBuilder applicationArtifactModelBuilder = applicationDescriptorFactory.createArtifactModelBuilder(toolingApplicationContent);
    String domainName = mergedDeploymentProperties.get().getProperty(DEPLOYMENT_DOMAIN_NAME_REF);
    if (domainName != null) {
        Domain domain = domainRepository.getDomain(domainName);
        if (domain == null) {
            throw new IllegalArgumentException(format("Domain '%s' is expected to be deployed", domainName));
        }
        MuleArtifactLoaderDescriptor classLoaderModelDescriptorLoader = applicationArtifactModelBuilder.getClassLoaderModelDescriptorLoader();
        Map<String, Object> extendedAttributes = new HashMap<>(classLoaderModelDescriptorLoader.getAttributes());
        extendedAttributes.put(CLASSLOADER_MODEL_MAVEN_REACTOR_RESOLVER, new DomainMavenReactorResolver(domain.getLocation(), domain.getDescriptor().getBundleDescriptor()));
        applicationArtifactModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(classLoaderModelDescriptorLoader.getId(), extendedAttributes));
        ApplicationDescriptor applicationDescriptor = applicationDescriptorFactory.createArtifact(toolingApplicationContent, mergedDeploymentProperties, applicationArtifactModelBuilder.build());
        applicationDescriptor.setDomainName(domain.getArtifactName());
        return new ToolingApplicationWrapper(doCreateApplication(applicationDescriptor));
    }
    return new ToolingApplicationWrapper(doCreateApplication(applicationDescriptorFactory.create(toolingApplicationContent, mergedDeploymentProperties)));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) HashMap(java.util.HashMap) Properties(java.util.Properties) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) MuleApplicationModel(org.mule.runtime.api.deployment.meta.MuleApplicationModel) Domain(org.mule.runtime.deployment.model.api.domain.Domain)

Example 17 with Domain

use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.

the class DefaultApplicationFactory method createArtifact.

public Application createArtifact(ApplicationDescriptor descriptor) throws IOException {
    Domain domain = getApplicationDomain(descriptor);
    List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(domain.getDescriptor().getPlugins(), new ArrayList<>(getArtifactPluginDescriptors(descriptor)));
    // Refreshes the list of plugins on the descriptor with the resolved from domain and transitive plugin dependencies
    Set resolvedArtifactPlugins = new LinkedHashSet<>();
    resolvedArtifactPlugins.addAll(resolvedArtifactPluginDescriptors);
    descriptor.setPlugins(resolvedArtifactPlugins);
    ApplicationClassLoaderBuilder artifactClassLoaderBuilder = applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
    MuleDeployableArtifactClassLoader applicationClassLoader = artifactClassLoaderBuilder.setDomain(domain).addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[0])).setArtifactId(descriptor.getName()).setArtifactDescriptor(descriptor).build();
    List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(applicationClassLoader, resolvedArtifactPluginDescriptors);
    MuleApplicationPolicyProvider applicationPolicyProvider = new MuleApplicationPolicyProvider(new DefaultPolicyTemplateFactory(policyTemplateClassLoaderBuilderFactory, pluginDependenciesResolver, licenseValidator), new DefaultPolicyInstanceProviderFactory(serviceRepository, classLoaderRepository, extensionModelLoaderRepository));
    DefaultMuleApplication delegate = new DefaultMuleApplication(descriptor, applicationClassLoader, artifactPlugins, domainRepository, serviceRepository, extensionModelLoaderRepository, descriptor.getArtifactLocation(), classLoaderRepository, applicationPolicyProvider);
    applicationPolicyProvider.setApplication(delegate);
    return new ApplicationWrapper(delegate);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ApplicationClassLoaderBuilder(org.mule.runtime.deployment.model.internal.application.ApplicationClassLoaderBuilder) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) DefaultPolicyInstanceProviderFactory(org.mule.runtime.module.deployment.impl.internal.policy.DefaultPolicyInstanceProviderFactory) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DefaultPolicyTemplateFactory(org.mule.runtime.module.deployment.impl.internal.policy.DefaultPolicyTemplateFactory) DefaultArtifactPlugin(org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 18 with Domain

use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.

the class DefaultMuleApplication method doInit.

private void doInit(boolean lazy, boolean disableXmlValidations) {
    withContextClassLoader(null, () -> {
        if (logger.isInfoEnabled()) {
            logger.info(miniSplash(format("Initializing app '%s'", descriptor.getName())));
        }
    });
    try {
        ArtifactContextBuilder artifactBuilder = newBuilder().setArtifactProperties(merge(descriptor.getAppProperties(), getProperties())).setArtifactType(APP).setDataFolderName(descriptor.getDataFolderName()).setArtifactName(descriptor.getName()).setArtifactInstallationDirectory(descriptor.getArtifactLocation()).setConfigurationFiles(descriptor.getConfigResources().toArray(new String[descriptor.getConfigResources().size()])).setDefaultEncoding(descriptor.getEncoding()).setArtifactPlugins(artifactPlugins).setExecutionClassloader(deploymentClassLoader.getClassLoader()).setEnableLazyInit(lazy).setDisableXmlValidations(disableXmlValidations).setServiceRepository(serviceRepository).setExtensionModelLoaderRepository(extensionModelLoaderRepository).setClassLoaderRepository(classLoaderRepository).setArtifactDeclaration(descriptor.getArtifactDeclaration()).setProperties(ofNullable(resolveDeploymentProperties(descriptor.getDataFolderName(), descriptor.getDeploymentProperties()))).setPolicyProvider(policyManager);
        Domain domain = domainRepository.getDomain(descriptor.getDomainName());
        if (domain.getRegistry() != null) {
            artifactBuilder.setParentArtifact(domain);
        }
        if (muleContextListener != null) {
            artifactBuilder.setMuleContextListener(muleContextListener);
        }
        artifactContext = artifactBuilder.build();
        setMuleContext(artifactContext.getMuleContext(), artifactContext.getRegistry());
    } catch (Exception e) {
        setStatusToFailed();
        // log it here so it ends up in app log, sys log will only log a message without stacktrace
        logger.error(null, getRootCause(e));
        throw new DeploymentInitException(createStaticMessage(getRootCauseMessage(e)), e);
    }
}
Also used : ArtifactContextBuilder(org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder) Domain(org.mule.runtime.deployment.model.api.domain.Domain) InstallException(org.mule.runtime.deployment.model.api.InstallException) DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) DeploymentStopException(org.mule.runtime.deployment.model.api.DeploymentStopException) MuleException(org.mule.runtime.api.exception.MuleException) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException)

Example 19 with Domain

use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.

the class DefaultPolicyTemplateFactoryTestCase method createApplication.

private Application createApplication(RegionClassLoader regionClassLoader) {
    ApplicationDescriptor appDescriptor = mock(ApplicationDescriptor.class);
    when(appDescriptor.getPlugins()).thenReturn(emptySet());
    Application application = mock(Application.class);
    when(application.getRegionClassLoader()).thenReturn(regionClassLoader);
    when(application.getDescriptor()).thenReturn(appDescriptor);
    final Domain domain = mock(Domain.class);
    when(domain.getDescriptor()).thenReturn(new DomainDescriptor("testDomain"));
    when(application.getDomain()).thenReturn(domain);
    return application;
}
Also used : Domain(org.mule.runtime.deployment.model.api.domain.Domain) Application(org.mule.runtime.deployment.model.api.application.Application) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)

Example 20 with Domain

use of org.mule.runtime.deployment.model.api.domain.Domain in project mule by mulesoft.

the class DefaultApplicationFactoryTestCase method createsApplication.

@Test
public void createsApplication() throws Exception {
    final ApplicationDescriptor descriptor = new ApplicationDescriptor(APP_NAME);
    descriptor.setClassLoaderModel(createClassLoaderModelWithDomain());
    final File[] resourceFiles = new File[] { new File("mule-config.xml") };
    when(applicationDescriptorFactory.create(any(), any())).thenReturn(descriptor);
    final ArtifactPluginDescriptor coreArtifactPluginDescriptor = new ArtifactPluginDescriptor(FAKE_ARTIFACT_PLUGIN);
    coreArtifactPluginDescriptor.setClassLoaderModel(new ClassLoaderModel.ClassLoaderModelBuilder().build());
    final ArtifactPlugin appPlugin = mock(ArtifactPlugin.class);
    final ArtifactClassLoader artifactClassLoader = mock(ArtifactClassLoader.class);
    when(appPlugin.getArtifactClassLoader()).thenReturn(artifactClassLoader);
    when(artifactClassLoader.getArtifactId()).thenReturn(FAKE_ARTIFACT_PLUGIN);
    when(appPlugin.getDescriptor()).thenReturn(coreArtifactPluginDescriptor);
    final Domain domain = createDomain(DOMAIN_NAME);
    final ClassLoaderLookupPolicy sharedLibLookupPolicy = mock(ClassLoaderLookupPolicy.class);
    when(domain.getArtifactClassLoader().getClassLoaderLookupPolicy().extend(anyMap())).thenReturn(sharedLibLookupPolicy);
    final MuleApplicationClassLoader applicationArtifactClassLoader = mock(MuleApplicationClassLoader.class);
    when(applicationArtifactClassLoader.getArtifactId()).thenReturn(APP_ID);
    ApplicationClassLoaderBuilder applicationClassLoaderBuilderMock = mock(ApplicationClassLoaderBuilder.class);
    when(applicationClassLoaderBuilderMock.setDomain(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.setArtifactDescriptor(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.setArtifactId(any())).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]))).thenReturn(applicationClassLoaderBuilderMock);
    when(applicationClassLoaderBuilderMock.build()).thenReturn(applicationArtifactClassLoader);
    when(applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder()).thenReturn(applicationClassLoaderBuilderMock);
    List<ArtifactClassLoader> pluginClassLoaders = new ArrayList<>();
    pluginClassLoaders.add(artifactClassLoader);
    when(applicationArtifactClassLoader.getArtifactPluginClassLoaders()).thenReturn(pluginClassLoaders);
    final Application application = applicationFactory.createArtifact(new File(APP_NAME), empty());
    assertThat(application.getDomain(), is(domain));
    assertThat(application.getArtifactClassLoader(), is(applicationArtifactClassLoader));
    assertThat(application.getDescriptor(), is(descriptor));
    assertThat(application.getArtifactName(), is(APP_NAME));
    assertThat(application.getResourceFiles(), is(resourceFiles));
    verify(domainRepository, times(2)).getDomain(DOMAIN_ARTIFACT_FILE_NAME);
    verify(applicationClassLoaderBuilderMock).setDomain(domain);
    verify(applicationClassLoaderBuilderMock).addArtifactPluginDescriptors(descriptor.getPlugins().toArray(new ArtifactPluginDescriptor[0]));
    verify(applicationClassLoaderBuilderMock).setArtifactDescriptor(descriptor);
    verify(applicationClassLoaderBuilderMock).setArtifactId(APP_NAME);
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ApplicationClassLoaderBuilder(org.mule.runtime.deployment.model.internal.application.ApplicationClassLoaderBuilder) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ClassLoaderLookupPolicy(org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy) ArrayList(java.util.ArrayList) ApplicationDescriptor(org.mule.runtime.deployment.model.api.application.ApplicationDescriptor) Domain(org.mule.runtime.deployment.model.api.domain.Domain) MuleApplicationClassLoader(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader) File(java.io.File) Application(org.mule.runtime.deployment.model.api.application.Application) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin) Test(org.junit.Test)

Aggregations

Domain (org.mule.runtime.deployment.model.api.domain.Domain)26 Test (org.junit.Test)13 File (java.io.File)10 Application (org.mule.runtime.deployment.model.api.application.Application)9 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)7 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)6 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)6 IOException (java.io.IOException)5 URI (java.net.URI)5 Collection (java.util.Collection)5 Properties (java.util.Properties)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileInputStream (java.io.FileInputStream)4 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 Paths (java.nio.file.Paths)4 Collections.emptyList (java.util.Collections.emptyList)4 Collections.emptyMap (java.util.Collections.emptyMap)4 SECONDS (java.util.concurrent.TimeUnit.SECONDS)4 FileUtils.forceDelete (org.apache.commons.io.FileUtils.forceDelete)4