Search in sources :

Example 51 with MuleException

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);
    }
}
Also used : DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) 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) MuleException(org.mule.runtime.api.exception.MuleException)

Example 52 with MuleException

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);
    }
}
Also used : ArtifactContextBuilder(org.mule.runtime.module.deployment.impl.internal.artifact.ArtifactContextBuilder) CompositeArtifactExtensionManagerFactory(org.mule.runtime.module.deployment.impl.internal.artifact.CompositeArtifactExtensionManagerFactory) HashMap(java.util.HashMap) DefaultExtensionManagerFactory(org.mule.runtime.module.extension.api.manager.DefaultExtensionManagerFactory) Registry(org.mule.runtime.api.artifact.Registry) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 53 with MuleException

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);
    }
}
Also used : DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) MuleException(org.mule.runtime.api.exception.MuleException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) DeploymentStartException(org.mule.runtime.deployment.model.api.DeploymentStartException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) FileNotFoundException(java.io.FileNotFoundException) DeploymentInitException(org.mule.runtime.deployment.model.api.DeploymentInitException) DeploymentStopException(org.mule.runtime.deployment.model.api.DeploymentStopException)

Example 54 with MuleException

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]);
}
Also used : MuleException(org.mule.runtime.api.exception.MuleException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Thread.currentThread(java.lang.Thread.currentThread)

Example 55 with MuleException

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);
}
Also used : IntrospectionUtils.getMemberName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getMemberName) FieldOperationParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FieldOperationParameterModelProperty) Optional.of(java.util.Optional.of) Mono.subscriberContext(reactor.core.publisher.Mono.subscriberContext) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ResolverUtils.resolveValue(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverUtils.resolveValue) ParameterValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ParameterValueResolver) PROCESSOR_SCHEDULER_CONTEXT_KEY(org.mule.runtime.core.internal.processor.strategy.AbstractProcessingStrategy.PROCESSOR_SCHEDULER_CONTEXT_KEY) Scheduler(org.mule.runtime.api.scheduler.Scheduler) IMMEDIATE_SCHEDULER(org.mule.runtime.core.internal.util.rx.ImmediateScheduler.IMMEDIATE_SCHEDULER) MuleExtensionUtils.getOperationExecutorFactory(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getOperationExecutorFactory) Map(java.util.Map) TARGET_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_PARAMETER_NAME) OperationArgumentResolverFactory(org.mule.runtime.module.extension.internal.runtime.execution.OperationArgumentResolverFactory) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Exceptions(org.mule.runtime.core.api.rx.Exceptions) PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) ParametersResolverProcessor(org.mule.runtime.core.internal.processor.ParametersResolverProcessor) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) String.format(java.lang.String.format) OperationPolicy(org.mule.runtime.core.internal.policy.OperationPolicy) MuleExtensionUtils.getInitialiserEvent(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.getInitialiserEvent) ObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.ObjectBuilder) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) List(java.util.List) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty) Optional(java.util.Optional) CursorProviderFactory(org.mule.runtime.core.api.streaming.CursorProviderFactory) ValueResolvingContext.from(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext.from) ComponentExecutorFactory(org.mule.runtime.extension.api.runtime.operation.ComponentExecutorFactory) Optional.empty(java.util.Optional.empty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) Flux.from(reactor.core.publisher.Flux.from) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ComponentExecutor(org.mule.runtime.extension.api.runtime.operation.ComponentExecutor) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) Processor(org.mule.runtime.core.api.processor.Processor) TARGET_VALUE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TARGET_VALUE_PARAMETER_NAME) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) MuleException(org.mule.runtime.api.exception.MuleException) Flux.error(reactor.core.publisher.Flux.error) BiConsumer(java.util.function.BiConsumer) DEFAULT_GROUP_NAME(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) Mono.fromCallable(reactor.core.publisher.Mono.fromCallable) ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) DefaultExecutionContext(org.mule.runtime.module.extension.internal.runtime.DefaultExecutionContext) Logger(org.slf4j.Logger) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) Exceptions.checkedFunction(org.mule.runtime.core.api.rx.Exceptions.checkedFunction) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) ComponentLocationProvider.resolveProcessorRepresentation(org.mule.runtime.api.util.ComponentLocationProvider.resolveProcessorRepresentation) LifecycleUtils.startIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.startIfNeeded) Mono(reactor.core.publisher.Mono) Field(java.lang.reflect.Field) ExtensionComponent(org.mule.runtime.module.extension.internal.runtime.ExtensionComponent) LazyExecutionContext(org.mule.runtime.module.extension.internal.runtime.LazyExecutionContext) Interceptor(org.mule.runtime.extension.api.runtime.operation.Interceptor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) INTERCEPTION_RESOLVED_CONTEXT(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent.INTERCEPTION_RESOLVED_CONTEXT) Collectors.toList(java.util.stream.Collectors.toList) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) LazyValue(org.mule.runtime.api.util.LazyValue) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) IntrospectionUtils.isVoid(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isVoid) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) DefaultFlowCallStack(org.mule.runtime.core.internal.context.notification.DefaultFlowCallStack) ValueResolvingContext(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext) OperationExecutionFunction(org.mule.runtime.core.internal.policy.OperationExecutionFunction) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) FieldOperationParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FieldOperationParameterModelProperty) LazyValue(org.mule.runtime.api.util.LazyValue) Optional(java.util.Optional) HashMap(java.util.HashMap) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.ObjectBuilder) DefaultObjectBuilder(org.mule.runtime.module.extension.internal.runtime.objectbuilder.DefaultObjectBuilder) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ValueResolvingContext(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException)

Aggregations

MuleException (org.mule.runtime.api.exception.MuleException)68 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)21 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Test (org.junit.Test)15 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)14 Processor (org.mule.runtime.core.api.processor.Processor)12 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 Logger (org.slf4j.Logger)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)6 Map (java.util.Map)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleContext (org.mule.runtime.core.api.MuleContext)5 LifecycleUtils.stopIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded)5 Thread.currentThread (java.lang.Thread.currentThread)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Startable (org.mule.runtime.api.lifecycle.Startable)4