use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class DefaultMuleApplication method start.
@Override
public void start() {
withContextClassLoader(null, () -> {
if (logger.isInfoEnabled()) {
logger.info(miniSplash(format("Starting app '%s'", descriptor.getName())));
}
});
try {
this.artifactContext.getMuleContext().start();
// null CCL ensures we log at 'system' level
// TODO getDomainClassLoader a more usable wrapper for any logger to be logged at sys level
withContextClassLoader(null, () -> {
if (logger.isInfoEnabled()) {
ApplicationStartedSplashScreen splashScreen = new ApplicationStartedSplashScreen();
splashScreen.createMessage(descriptor);
logger.info(splashScreen.toString());
}
});
} catch (Exception e) {
setStatusToFailed();
// log it here so it ends up in app log, sys log will only log a message without stacktrace
if (e instanceof MuleException) {
logger.error(((MuleException) e).getDetailedMessage());
} else {
logger.error(null, getRootCause(e));
}
throw new DeploymentStartException(createStaticMessage(format("Error starting application '%s'", descriptor.getName())), e);
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class DefaultApplicationPolicyInstance method initPolicyContext.
private void initPolicyContext() throws InitialisationException {
ArtifactContextBuilder artifactBuilder = newBuilder().setArtifactType(POLICY).setArtifactProperties(new HashMap<>(parametrization.getParameters())).setArtifactName(parametrization.getId()).setConfigurationFiles(parametrization.getConfig().getAbsolutePath()).setExecutionClassloader(template.getArtifactClassLoader().getClassLoader()).setServiceRepository(serviceRepository).setClassLoaderRepository(classLoaderRepository).setArtifactPlugins(artifactPlugins).setParentArtifact(application).setExtensionManagerFactory(new CompositeArtifactExtensionManagerFactory(application, extensionModelLoaderRepository, artifactPlugins, new DefaultExtensionManagerFactory())).setMuleContextListener(muleContextListener);
artifactBuilder.withServiceConfigurator(customizationService -> {
Registry applicationRegistry = application.getRegistry();
/*
* OBJECT_POLICY_MANAGER_STATE_HANDLER is not proxied as it doesn't implement any lifecycle interfaces (Startable, Stoppable
* or Disposable)
*/
customizationService.overrideDefaultServiceImpl(OBJECT_POLICY_MANAGER_STATE_HANDLER, applicationRegistry.lookupByName(OBJECT_POLICY_MANAGER_STATE_HANDLER).get());
customizationService.overrideDefaultServiceImpl(OBJECT_LOCK_PROVIDER, createLifecycleFilterProxy(applicationRegistry.lookupByName(OBJECT_LOCK_PROVIDER).get()));
customizationService.overrideDefaultServiceImpl(BASE_PERSISTENT_OBJECT_STORE_KEY, createLifecycleFilterProxy(applicationRegistry.lookupByName(BASE_PERSISTENT_OBJECT_STORE_KEY).get()));
customizationService.overrideDefaultServiceImpl(BASE_IN_MEMORY_OBJECT_STORE_KEY, createLifecycleFilterProxy(applicationRegistry.lookupByName(BASE_IN_MEMORY_OBJECT_STORE_KEY).get()));
customizationService.overrideDefaultServiceImpl(OBJECT_TIME_SUPPLIER, createLifecycleFilterProxy(applicationRegistry.lookupByName(OBJECT_TIME_SUPPLIER).get()));
applicationRegistry.lookupByName(CLUSTER_MANAGER_ID).ifPresent(muleClusterManager -> customizationService.registerCustomServiceImpl(CLUSTER_MANAGER_ID, createLifecycleFilterProxy(muleClusterManager)));
});
try {
policyContext = artifactBuilder.build();
enableNotificationListeners(parametrization.getNotificationListeners());
policyContext.getMuleContext().start();
} catch (MuleException e) {
throw new InitialisationException(createStaticMessage("Cannot create artifact context for the policy instance"), e, this);
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class DefaultMuleDomain method start.
@Override
public void start() {
try {
if (this.artifactContext != null) {
try {
this.artifactContext.getMuleContext().start();
} catch (MuleException e) {
logger.error(null, getRootCause(e));
throw new DeploymentStartException(createStaticMessage(getRootCauseMessage(e)), e);
}
}
// null CCL ensures we log at 'system' level
// TODO create a more usable wrapper for any logger to be logged at sys level
withContextClassLoader(null, () -> {
DomainStartedSplashScreen splashScreen = new DomainStartedSplashScreen();
splashScreen.createMessage(descriptor);
logger.info(splashScreen.toString());
});
} catch (Exception e) {
throw new DeploymentStartException(createStaticMessage("Failure trying to start domain " + getArtifactName()), e);
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class AbstractDeploymentTestCase method doSynchronizedArtifactDeploymentActionTest.
protected void doSynchronizedArtifactDeploymentActionTest(final Action deploymentAction, final Action assertAction, DeploymentListener domainDeploymentListener, String artifactId) {
Thread deploymentServiceThread = new Thread(() -> {
try {
startDeployment();
} catch (MuleException e) {
throw new RuntimeException("Unable to start deployment service");
}
});
final boolean[] deployedFromClient = new boolean[1];
doAnswer(invocation -> {
Thread deploymentClientThread = new Thread(() -> {
try {
deploymentAction.perform();
} catch (Exception e) {
// Ignore
}
});
deploymentClientThread.start();
deploymentClientThread.join();
try {
assertAction.perform();
} catch (AssertionError e) {
deployedFromClient[0] = true;
}
return null;
}).when(domainDeploymentListener).onDeploymentStart(artifactId);
deploymentServiceThread.start();
assertDeploymentSuccess(domainDeploymentListener, artifactId);
assertFalse("Able to perform a deployment action while another deployment operation was in progress", deployedFromClient[0]);
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class ComponentMessageProcessor method createComponentExecutor.
private ComponentExecutor<T> createComponentExecutor() {
Map<String, Object> params = new HashMap<>();
LazyValue<Optional<ConfigurationInstance>> staticConfiguration = new LazyValue<>(this::getStaticConfiguration);
LazyValue<ValueResolvingContext> resolvingContext = new LazyValue<>(() -> {
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent();
return from(initialiserEvent, staticConfiguration.get());
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
});
componentModel.getParameterGroupModels().stream().forEach(group -> {
if (group.getName().equals(DEFAULT_GROUP_NAME)) {
group.getParameterModels().stream().filter(p -> p.getModelProperty(FieldOperationParameterModelProperty.class).isPresent()).forEach(p -> {
ValueResolver<?> resolver = resolverSet.getResolvers().get(p.getName());
if (resolver != null) {
try {
params.put(getMemberName(p), resolveValue(resolver, resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
} else {
ParameterGroupDescriptor groupDescriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(g -> g.getDescriptor()).orElse(null);
if (groupDescriptor == null) {
return;
}
List<ParameterModel> fieldParameters = getGroupsOfFieldParameters(group);
if (fieldParameters.isEmpty()) {
return;
}
ObjectBuilder groupBuilder = createFieldParameterGroupBuilder(groupDescriptor, fieldParameters);
try {
params.put(((Field) groupDescriptor.getContainer()).getName(), groupBuilder.build(resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
return getOperationExecutorFactory(componentModel).createExecutor(componentModel, params);
}
Aggregations