Search in sources :

Example 1 with Domain

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

the class DefaultDomainFactory method doCreateArtifact.

@Override
protected Domain doCreateArtifact(File domainLocation, Optional<Properties> deploymentProperties) throws IOException {
    String domainName = domainLocation.getName();
    Domain domain = domainManager.getDomain(domainName);
    if (domain != null) {
        throw new IllegalArgumentException(format("Domain '%s'  already exists", domainName));
    }
    if (domainName.contains(" ")) {
        throw new IllegalArgumentException("Mule domain name may not contain spaces: " + domainName);
    }
    DomainDescriptor domainDescriptor = findDomain(domainName, domainLocation, deploymentProperties);
    List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(emptySet(), domainDescriptor.getPlugins().stream().collect(toList()));
    DomainClassLoaderBuilder artifactClassLoaderBuilder = domainClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
    MuleDeployableArtifactClassLoader domainClassLoader = artifactClassLoaderBuilder.addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[resolvedArtifactPluginDescriptors.size()])).setArtifactId(domainDescriptor.getName()).setArtifactDescriptor(domainDescriptor).build();
    List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(domainClassLoader, resolvedArtifactPluginDescriptors);
    DefaultMuleDomain defaultMuleDomain = new DefaultMuleDomain(domainDescriptor, domainClassLoader, classLoaderRepository, serviceRepository, artifactPlugins, extensionModelLoaderManager);
    DomainWrapper domainWrapper = new DomainWrapper(defaultMuleDomain, this);
    domainManager.addDomain(domainWrapper);
    return domainWrapper;
}
Also used : ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) MuleDeployableArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.MuleDeployableArtifactClassLoader) DomainClassLoaderBuilder(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderBuilder) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainDescriptor(org.mule.runtime.deployment.model.api.domain.DomainDescriptor) DefaultArtifactPlugin(org.mule.runtime.module.deployment.impl.internal.plugin.DefaultArtifactPlugin) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 2 with Domain

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

the class AbstractDeploymentTestCase method findADomain.

/**
 * Finds a deployed domain
 */
protected Domain findADomain(final String domainName) {
    final Domain domain = deploymentService.findDomain(domainName);
    assertNotNull(domain);
    return domain;
}
Also used : Domain(org.mule.runtime.deployment.model.api.domain.Domain) DefaultMuleDomain(org.mule.runtime.module.deployment.impl.internal.domain.DefaultMuleDomain)

Example 3 with Domain

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

the class DomainDeploymentTestCase method appliesApplicationPolicyDuplicatingDomainPlugin.

@Test
public void appliesApplicationPolicyDuplicatingDomainPlugin() throws Exception {
    installEchoService();
    installFooService();
    policyManager.registerPolicyTemplate(policyIncludingPluginFileBuilder.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());
    policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingPluginFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.xml"), emptyList()));
    executeApplicationFlow("main");
    assertThat(invocationCount, equalTo(1));
}
Also used : URL(java.net.URL) Assert.assertNotSame(org.junit.Assert.assertNotSame) DEFAULT_CONFIGURATION_RESOURCE(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_CONFIGURATION_RESOURCE) URISyntaxException(java.net.URISyntaxException) Matchers.not(org.hamcrest.Matchers.not) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) DESTROYED(org.mule.runtime.deployment.model.api.application.ApplicationStatus.DESTROYED) ByteArrayInputStream(java.io.ByteArrayInputStream) Is.is(org.hamcrest.core.Is.is) Assert.fail(org.junit.Assert.fail) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) URI(java.net.URI) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) CompilerUtils(org.mule.tck.util.CompilerUtils) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ApplicationStatus(org.mule.runtime.deployment.model.api.application.ApplicationStatus) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) EXPORTED_CLASS_PACKAGES_PROPERTY(org.mule.runtime.container.internal.ClasspathModuleDiscoverer.EXPORTED_CLASS_PACKAGES_PROPERTY) DomainClassLoaderFactory(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderFactory) FileUtils.forceDelete(org.apache.commons.io.FileUtils.forceDelete) FileUtils.touch(org.apache.commons.io.FileUtils.touch) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) IOUtils(org.mule.runtime.core.api.util.IOUtils) Application(org.mule.runtime.deployment.model.api.application.Application) TestPolicyProcessor.invocationCount(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.invocationCount) Collections.emptyMap(java.util.Collections.emptyMap) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Ignore(org.junit.Ignore) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Paths(java.nio.file.Paths) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) DEFAULT_DOMAIN_NAME(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_DOMAIN_NAME) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) Mockito.reset(org.mockito.Mockito.reset) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) Test(org.junit.Test)

Example 4 with Domain

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

the class DomainDeploymentTestCase method appliesApplicationPolicyUsingDomainPlugin.

@Test
public void appliesApplicationPolicyUsingDomainPlugin() throws Exception {
    installEchoService();
    installFooService();
    policyManager.registerPolicyTemplate(policyIncludingPluginFileBuilder.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());
    policyManager.addPolicy(applicationFileBuilder.getId(), policyIncludingPluginFileBuilder.getArtifactId(), new PolicyParametrization(FOO_POLICY_ID, s -> true, 1, emptyMap(), getResourceFile("/appPluginPolicy.xml"), emptyList()));
    executeApplicationFlow("main");
    assertThat(invocationCount, equalTo(1));
}
Also used : URL(java.net.URL) Assert.assertNotSame(org.junit.Assert.assertNotSame) DEFAULT_CONFIGURATION_RESOURCE(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_CONFIGURATION_RESOURCE) URISyntaxException(java.net.URISyntaxException) Matchers.not(org.hamcrest.Matchers.not) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) DESTROYED(org.mule.runtime.deployment.model.api.application.ApplicationStatus.DESTROYED) ByteArrayInputStream(java.io.ByteArrayInputStream) Is.is(org.hamcrest.core.Is.is) Assert.fail(org.junit.Assert.fail) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) URI(java.net.URI) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) CompilerUtils(org.mule.tck.util.CompilerUtils) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ApplicationStatus(org.mule.runtime.deployment.model.api.application.ApplicationStatus) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) EXPORTED_CLASS_PACKAGES_PROPERTY(org.mule.runtime.container.internal.ClasspathModuleDiscoverer.EXPORTED_CLASS_PACKAGES_PROPERTY) DomainClassLoaderFactory(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderFactory) FileUtils.forceDelete(org.apache.commons.io.FileUtils.forceDelete) FileUtils.touch(org.apache.commons.io.FileUtils.touch) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) IOUtils(org.mule.runtime.core.api.util.IOUtils) Application(org.mule.runtime.deployment.model.api.application.Application) TestPolicyProcessor.invocationCount(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.invocationCount) Collections.emptyMap(java.util.Collections.emptyMap) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Ignore(org.junit.Ignore) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Paths(java.nio.file.Paths) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) DEFAULT_DOMAIN_NAME(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_DOMAIN_NAME) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) Mockito.reset(org.mockito.Mockito.reset) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) Test(org.junit.Test)

Example 5 with Domain

use of org.mule.runtime.deployment.model.api.domain.Domain 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) {
    }
}
Also used : URL(java.net.URL) Assert.assertNotSame(org.junit.Assert.assertNotSame) DEFAULT_CONFIGURATION_RESOURCE(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_CONFIGURATION_RESOURCE) URISyntaxException(java.net.URISyntaxException) Matchers.not(org.hamcrest.Matchers.not) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) DESTROYED(org.mule.runtime.deployment.model.api.application.ApplicationStatus.DESTROYED) ByteArrayInputStream(java.io.ByteArrayInputStream) Is.is(org.hamcrest.core.Is.is) Assert.fail(org.junit.Assert.fail) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) URI(java.net.URI) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) CompilerUtils(org.mule.tck.util.CompilerUtils) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) Domain(org.mule.runtime.deployment.model.api.domain.Domain) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ApplicationStatus(org.mule.runtime.deployment.model.api.application.ApplicationStatus) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) EXPORTED_CLASS_PACKAGES_PROPERTY(org.mule.runtime.container.internal.ClasspathModuleDiscoverer.EXPORTED_CLASS_PACKAGES_PROPERTY) DomainClassLoaderFactory(org.mule.runtime.deployment.model.internal.domain.DomainClassLoaderFactory) FileUtils.forceDelete(org.apache.commons.io.FileUtils.forceDelete) FileUtils.touch(org.apache.commons.io.FileUtils.touch) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) IOUtils(org.mule.runtime.core.api.util.IOUtils) Application(org.mule.runtime.deployment.model.api.application.Application) TestPolicyProcessor.invocationCount(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.invocationCount) Collections.emptyMap(java.util.Collections.emptyMap) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Ignore(org.junit.Ignore) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Paths(java.nio.file.Paths) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) DEFAULT_DOMAIN_NAME(org.mule.runtime.deployment.model.api.domain.DomainDescriptor.DEFAULT_DOMAIN_NAME) FileUtils.copyFile(org.apache.commons.io.FileUtils.copyFile) Mockito.reset(org.mockito.Mockito.reset) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) DomainFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.DomainFileBuilder) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) 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