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);
}
}
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);
}
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;
}
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"));
}
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()));
}
Aggregations