Search in sources :

Example 1 with Application

use of org.mule.runtime.deployment.model.api.application.Application 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);
    }
}
Also used : Disposable(org.mule.runtime.api.lifecycle.Disposable) PolicyTemplate(org.mule.runtime.deployment.model.api.policy.PolicyTemplate) Optional.of(java.util.Optional.of) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) PolicyInstanceProviderFactory(org.mule.runtime.module.deployment.impl.internal.policy.PolicyInstanceProviderFactory) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) PolicyProvider(org.mule.runtime.core.api.policy.PolicyProvider) PolicyTemplateDescriptor(org.mule.runtime.deployment.model.api.policy.PolicyTemplateDescriptor) List(java.util.List) Integer.compare(java.lang.Integer.compare) ApplicationPolicyInstance(org.mule.runtime.module.deployment.impl.internal.policy.ApplicationPolicyInstance) Policy(org.mule.runtime.core.api.policy.Policy) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) Application(org.mule.runtime.deployment.model.api.application.Application) LinkedList(java.util.LinkedList) PolicyTemplateFactory(org.mule.runtime.module.deployment.impl.internal.policy.PolicyTemplateFactory) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) ApplicationPolicyInstance(org.mule.runtime.module.deployment.impl.internal.policy.ApplicationPolicyInstance) PolicyTemplate(org.mule.runtime.deployment.model.api.policy.PolicyTemplate) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)

Example 2 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class AbstractDeploymentTestCase method assertStatus.

private void assertStatus(String appName, ApplicationStatus status, int expectedApps) {
    Application app = findApp(appName, expectedApps);
    assertThat(app, notNullValue());
    assertStatus(app, status);
}
Also used : Application(org.mule.runtime.deployment.model.api.application.Application)

Example 3 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class AbstractDeploymentTestCase method findApp.

/**
 * Find a deployed app, performing some basic assertions.
 */
protected Application findApp(final String appName, int totalAppsExpected) {
    // list all apps to validate total count
    final List<Application> apps = deploymentService.getApplications();
    assertNotNull(apps);
    if (totalAppsExpected >= 0) {
        assertEquals(totalAppsExpected, apps.size());
    }
    final Application app = deploymentService.findApplication(appName);
    assertNotNull(app);
    return app;
}
Also used : Application(org.mule.runtime.deployment.model.api.application.Application)

Example 4 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class ApplicationDeploymentTestCase method deploysAppWithPluginBootstrapProperty.

@Test
public void deploysAppWithPluginBootstrapProperty() throws Exception {
    final ArtifactPluginFileBuilder pluginFileBuilder = new ArtifactPluginFileBuilder("bootstrapPlugin").containingResource("plugin-bootstrap.properties", BOOTSTRAP_PROPERTIES).containingClass(echoTestClassFile, "org/foo/EchoTest.class").configuredWith(EXPORTED_RESOURCE_PROPERTY, BOOTSTRAP_PROPERTIES);
    ApplicationFileBuilder applicationFileBuilder = new ApplicationFileBuilder("app-with-plugin-bootstrap").definedBy("app-with-plugin-bootstrap.xml").dependingOn(pluginFileBuilder);
    addPackedAppFromBuilder(applicationFileBuilder);
    startDeployment();
    assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
    final Application application = findApp(applicationFileBuilder.getId(), 1);
    final Optional<Object> lookupObject = application.getRegistry().lookupByName("plugin.echotest");
    assertThat(lookupObject.isPresent(), is(true));
    assertThat(lookupObject.get().getClass().getName(), equalTo("org.foo.EchoTest"));
}
Also used : ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) Application(org.mule.runtime.deployment.model.api.application.Application) Test(org.junit.Test)

Example 5 with Application

use of org.mule.runtime.deployment.model.api.application.Application in project mule by mulesoft.

the class ApplicationDeploymentTestCase method deploysAppZipOnStartup.

@Test
public void deploysAppZipOnStartup() throws Exception {
    addPackedAppFromBuilder(dummyAppDescriptorFileBuilder);
    startDeployment();
    assertApplicationDeploymentSuccess(applicationDeploymentListener, dummyAppDescriptorFileBuilder.getId());
    assertAppsDir(NONE, new String[] { dummyAppDescriptorFileBuilder.getId() }, true);
    assertApplicationAnchorFileExists(dummyAppDescriptorFileBuilder.getId());
    // just assert no privileged entries were put in the registry
    final Application app = findApp(dummyAppDescriptorFileBuilder.getId(), 1);
    // Checks that the configuration's ID was properly configured
    assertThat(app.getRegistry().<MuleConfiguration>lookupByName(OBJECT_MULE_CONFIGURATION).get().getId(), equalTo(dummyAppDescriptorFileBuilder.getId()));
}
Also used : Application(org.mule.runtime.deployment.model.api.application.Application) Test(org.junit.Test)

Aggregations

Application (org.mule.runtime.deployment.model.api.application.Application)35 Test (org.junit.Test)19 File (java.io.File)7 Domain (org.mule.runtime.deployment.model.api.domain.Domain)6 ApplicationFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 IOException (java.io.IOException)4 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)4 PolicyParametrization (org.mule.runtime.core.api.policy.PolicyParametrization)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 ApplicationDescriptor (org.mule.runtime.deployment.model.api.application.ApplicationDescriptor)3 PolicyRegistrationException (org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException)3 DeploymentListener (org.mule.runtime.module.deployment.api.DeploymentListener)3 URI (java.net.URI)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)2