Search in sources :

Example 1 with ReconnectionConfig

use of org.mule.runtime.core.internal.retry.ReconnectionConfig in project mule by mulesoft.

the class LifecycleAwareConfigurationInstance method testConnectivity.

private void testConnectivity() throws MuleException {
    ConnectionProvider provider = connectionProvider.get();
    if (provider instanceof NoConnectivityTest) {
        return;
    }
    Scheduler retryScheduler = schedulerService.ioScheduler();
    RetryPolicyTemplate retryTemplate = connectionManager.getRetryTemplateFor(provider);
    ReconnectionConfig reconnectionConfig = connectionManager.getReconnectionConfigFor(provider);
    RetryCallback retryCallback = new RetryCallback() {

        @Override
        public void doWork(RetryContext context) throws Exception {
            Lock lock = testConnectivityLock;
            if (lock != null) {
                final boolean lockAcquired = lock.tryLock();
                if (lockAcquired) {
                    LOGGER.info("Doing testConnectivity() for config " + getName());
                    try {
                        ConnectionValidationResult result = connectionManager.testConnectivity(LifecycleAwareConfigurationInstance.this);
                        if (result.isValid()) {
                            context.setOk();
                        } else {
                            if ((reconnectionConfig.isFailsDeployment())) {
                                context.setFailed(result.getException());
                                throw new ConnectionException(format("Connectivity test failed for config '%s'", getName()), result.getException());
                            } else {
                                if (LOGGER.isInfoEnabled()) {
                                    LOGGER.info(format("Connectivity test failed for config '%s'. Application deployment will continue. Error was: ", getName(), result.getMessage()), result.getException());
                                }
                            }
                        }
                    } finally {
                        lock.unlock();
                    }
                } else {
                    LOGGER.warn("There is a testConnectivity() already running for config " + getName());
                }
            }
        }

        @Override
        public String getWorkDescription() {
            return format("Testing connectivity for config '%s'", getName());
        }

        @Override
        public Object getWorkOwner() {
            return value;
        }
    };
    try {
        retryTemplate.execute(retryCallback, retryScheduler);
    } catch (Exception e) {
        throw new DefaultMuleException(createStaticMessage(format("Could not perform connectivity testing for config '%s'", getName())), e);
    } finally {
        if (retryScheduler != null) {
            retryScheduler.stop();
        }
    }
}
Also used : RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) Scheduler(org.mule.runtime.api.scheduler.Scheduler) RetryContext(org.mule.runtime.core.api.retry.RetryContext) ReconnectionConfig(org.mule.runtime.core.internal.retry.ReconnectionConfig) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) Lock(java.util.concurrent.locks.Lock) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ConnectionValidationResult(org.mule.runtime.api.connection.ConnectionValidationResult) NoConnectivityTest(org.mule.runtime.extension.api.connectivity.NoConnectivityTest) ConnectionException(org.mule.runtime.api.connection.ConnectionException) RetryCallback(org.mule.runtime.core.api.retry.RetryCallback)

Example 2 with ReconnectionConfig

use of org.mule.runtime.core.internal.retry.ReconnectionConfig in project mule by mulesoft.

the class ConnectionProviderDefinitionParser method doParse.

@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
    Builder finalBuilder = definitionBuilder.withIdentifier(connectionDsl.getElementName()).withTypeDefinition(fromType(ConnectionProviderResolver.class)).withObjectFactoryType(ConnectionProviderObjectFactory.class).withConstructorParameterDefinition(fromFixedValue(providerModel).build()).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromReferenceObject(ExtensionsOAuthManager.class).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withSetterParameterDefinition("reconnectionConfig", fromChildConfiguration(ReconnectionConfig.class).build()).withSetterParameterDefinition("poolingProfile", fromChildConfiguration(PoolingProfile.class).build());
    parseParameters(providerModel);
    return finalBuilder;
}
Also used : ExtensionsOAuthManager(org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.ExtensionsOAuthManager) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) ReconnectionConfig(org.mule.runtime.core.internal.retry.ReconnectionConfig)

Example 3 with ReconnectionConfig

use of org.mule.runtime.core.internal.retry.ReconnectionConfig in project mule by mulesoft.

the class DefaultExecutionMediatorTestCase method before.

@Before
public void before() throws Exception {
    when(configurationInstance.getStatistics()).thenReturn(configurationStats);
    when(configurationInstance.getName()).thenReturn(DUMMY_NAME);
    when(configurationInstance.getModel()).thenReturn(configurationModel);
    when(extensionModel.getName()).thenReturn(DUMMY_NAME);
    when(extensionModel.getModelProperty(ClassLoaderModelProperty.class)).thenReturn(empty());
    mockExceptionEnricher(extensionModel, null);
    mockExceptionEnricher(operationModel, null);
    when(operationExecutor.execute(operationContext)).thenReturn(just(result));
    when(operationExceptionExecutor.execute(operationContext)).thenReturn(error(exception));
    when(operationContext.getConfiguration()).thenReturn(Optional.of(configurationInstance));
    when(operationContext.getExtensionModel()).thenReturn(extensionModel);
    when(operationContext.getTransactionConfig()).thenReturn(empty());
    when(operationContext.getRetryPolicyTemplate()).thenReturn(empty());
    when(operationContext.getCurrentScheduler()).thenReturn(IMMEDIATE_SCHEDULER);
    when(extensionModel.getXmlDslModel()).thenReturn(XmlDslModel.builder().setPrefix("test-extension").build());
    mediator = new DefaultExecutionMediator(extensionModel, operationModel, new DefaultConnectionManager(muleContext), muleContext.getErrorTypeRepository());
    final ReconnectableConnectionProviderWrapper<Object> connectionProviderWrapper = new ReconnectableConnectionProviderWrapper<>(null, new ReconnectionConfig(true, new SimpleRetryPolicyTemplate(10, RETRY_COUNT)));
    initialiseIfNeeded(connectionProviderWrapper, true, muleContext);
    Optional<ConnectionProvider> connectionProvider = Optional.of(connectionProviderWrapper);
    when(configurationInstance.getConnectionProvider()).thenReturn(connectionProvider);
    when(exceptionEnricher.enrichException(exception)).thenReturn(new HeisenbergException(ERROR));
    setInterceptors((Interceptable) configurationInstance, configurationInterceptor1, configurationInterceptor2);
    setInterceptors((Interceptable) operationExecutor, operationInterceptor1, operationInterceptor2);
    defineOrder(configurationInterceptor1, configurationInterceptor2, operationInterceptor1, operationInterceptor2);
}
Also used : DefaultConnectionManager(org.mule.runtime.core.internal.connection.DefaultConnectionManager) SimpleRetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate) DefaultExecutionMediator(org.mule.runtime.module.extension.internal.runtime.operation.DefaultExecutionMediator) HeisenbergException(org.mule.test.heisenberg.extension.exception.HeisenbergException) ReconnectionConfig(org.mule.runtime.core.internal.retry.ReconnectionConfig) ReconnectableConnectionProviderWrapper(org.mule.runtime.core.internal.connection.ReconnectableConnectionProviderWrapper) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) Before(org.junit.Before)

Aggregations

ReconnectionConfig (org.mule.runtime.core.internal.retry.ReconnectionConfig)3 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)2 Lock (java.util.concurrent.locks.Lock)1 Before (org.junit.Before)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 ConnectionValidationResult (org.mule.runtime.api.connection.ConnectionValidationResult)1 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)1 MuleException (org.mule.runtime.api.exception.MuleException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Scheduler (org.mule.runtime.api.scheduler.Scheduler)1 RetryCallback (org.mule.runtime.core.api.retry.RetryCallback)1 RetryContext (org.mule.runtime.core.api.retry.RetryContext)1 RetryPolicyTemplate (org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate)1 SimpleRetryPolicyTemplate (org.mule.runtime.core.api.retry.policy.SimpleRetryPolicyTemplate)1 DefaultConnectionManager (org.mule.runtime.core.internal.connection.DefaultConnectionManager)1 ReconnectableConnectionProviderWrapper (org.mule.runtime.core.internal.connection.ReconnectableConnectionProviderWrapper)1 Builder (org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder)1 NoConnectivityTest (org.mule.runtime.extension.api.connectivity.NoConnectivityTest)1 ExtensionsOAuthManager (org.mule.runtime.module.extension.internal.runtime.connectivity.oauth.ExtensionsOAuthManager)1 DefaultExecutionMediator (org.mule.runtime.module.extension.internal.runtime.operation.DefaultExecutionMediator)1