Search in sources :

Example 1 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class CompositeArtifactExtensionManagerTestCase method returnsConfigurationFromProviderName.

@Test
public void returnsConfigurationFromProviderName() throws Exception {
    ExtensionModel childExtension = mock(ExtensionModel.class);
    Set<ExtensionModel> childExtensions = singleton(childExtension);
    when(childExtensionManager.getExtensions()).thenReturn(childExtensions);
    when(parentExtensionManager.getExtensions()).thenReturn(emptySet());
    CompositeArtifactExtensionManager extensionManager = new CompositeArtifactExtensionManager(parentExtensionManager, childExtensionManager);
    CoreEvent event = mock(CoreEvent.class);
    ConfigurationProvider childConfigurationProvider = mock(ConfigurationProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(childConfigurationProvider.get(event)).thenReturn(configurationInstance);
    when(childExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(of(childConfigurationProvider));
    when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
    ConfigurationInstance configuration = extensionManager.getConfiguration(PROVIDER_NAME, event);
    assertThat(configuration, is(configurationInstance));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class ExtensionComponent method getMetadataContext.

private MetadataContext getMetadataContext() throws MetadataResolvingException {
    CoreEvent fakeEvent = null;
    try {
        fakeEvent = getInitialiserEvent(muleContext);
        Optional<ConfigurationInstance> configuration = getConfiguration(fakeEvent);
        if (configuration.isPresent()) {
            ConfigurationProvider configurationProvider = findConfigurationProvider().orElseThrow(() -> new MetadataResolvingException("Failed to create the required configuration for Metadata retrieval", INVALID_CONFIGURATION));
            if (configurationProvider instanceof DynamicConfigurationProvider) {
                throw new MetadataResolvingException("Configuration used for Metadata fetch cannot be dynamic", INVALID_CONFIGURATION);
            }
        }
        String cacheId = configuration.map(ConfigurationInstance::getName).orElseGet(() -> extensionModel.getName() + "|" + componentModel.getName());
        return new DefaultMetadataContext(() -> configuration, connectionManager, metadataService.getMetadataCache(cacheId), typeLoader);
    } finally {
        if (fakeEvent != null) {
            ((BaseEventContext) fakeEvent.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) DynamicConfigurationProvider(org.mule.runtime.module.extension.internal.runtime.config.DynamicConfigurationProvider) DynamicConfigurationProvider(org.mule.runtime.module.extension.internal.runtime.config.DynamicConfigurationProvider) DefaultMetadataContext(org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 3 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class DefaultConfigurationProviderFactory method createStaticConfigurationProvider.

/**
 * {@inheritDoc}
 */
@Override
public ConfigurationProvider createStaticConfigurationProvider(String name, ExtensionModel extensionModel, ConfigurationModel configurationModel, ResolverSet resolverSet, ConnectionProviderValueResolver connectionProviderResolver, ReflectionCache reflectionCache, MuleContext muleContext) throws Exception {
    return withExtensionClassLoader(extensionModel, () -> {
        configureConnectionProviderResolver(name, connectionProviderResolver);
        ConfigurationInstance configuration;
        CoreEvent initialiserEvent = null;
        try {
            initialiserEvent = getInitialiserEvent(muleContext);
            initialiseIfNeeded(resolverSet, true, muleContext);
            configuration = new ConfigurationInstanceFactory(extensionModel, configurationModel, resolverSet, reflectionCache, muleContext).createConfiguration(name, initialiserEvent, connectionProviderResolver);
        } catch (MuleException e) {
            throw new ConfigurationException(createStaticMessage(format("Could not create configuration '%s' for the '%s'", name, extensionModel.getName())), e);
        } finally {
            if (initialiserEvent != null) {
                ((BaseEventContext) initialiserEvent.getContext()).success();
            }
        }
        return new ConfigurationProviderToolingAdapter(name, extensionModel, configurationModel, configuration, reflectionCache, muleContext);
    });
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) MuleException(org.mule.runtime.api.exception.MuleException) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 4 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class DefaultImplicitConfigurationProviderFactory method createImplicitConfigurationProvider.

/**
 * {@inheritDoc}
 */
@Override
public ConfigurationProvider createImplicitConfigurationProvider(ExtensionModel extensionModel, ConfigurationModel implicitConfigurationModel, CoreEvent event, ReflectionCache reflectionCache, MuleContext muleContext) {
    if (implicitConfigurationModel == null || !canBeUsedImplicitly(implicitConfigurationModel)) {
        throw new IllegalStateException("Could not find a config for extension '" + extensionModel.getName() + "' and none can be created automatically. Please define one");
    }
    final String providerName = getImplicitConfigurationProviderName(extensionModel, implicitConfigurationModel);
    Callable<ResolverSet> resolverSetCallable = () -> buildImplicitResolverSet(implicitConfigurationModel, reflectionCache, muleContext);
    ClassLoader pluginClassloader = getClassLoader(extensionModel);
    final ResolverSet resolverSet = withContextClassLoader(pluginClassloader, resolverSetCallable);
    try {
        ImplicitConnectionProviderValueResolver implicitConnectionProviderValueResolver = new ImplicitConnectionProviderValueResolver(implicitConfigurationModel.getName(), extensionModel, implicitConfigurationModel, reflectionCache, muleContext);
        ConfigurationInstance configurationInstance = withContextClassLoader(pluginClassloader, () -> new ConfigurationInstanceFactory(extensionModel, implicitConfigurationModel, resolverSet, reflectionCache, muleContext).createConfiguration(providerName, event, implicitConnectionProviderValueResolver));
        if (resolverSet.isDynamic() || needsDynamicConnectionProvider(extensionModel, implicitConfigurationModel, implicitConnectionProviderValueResolver)) {
            return new DynamicConfigurationProvider(providerName, extensionModel, implicitConfigurationModel, resolverSet, implicitConnectionProviderValueResolver, ImmutableExpirationPolicy.getDefault(new LocalTimeSupplier()), reflectionCache, muleContext);
        }
        return new ConfigurationProviderToolingAdapter(providerName, extensionModel, implicitConfigurationModel, configurationInstance, reflectionCache, muleContext);
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage(format("Could not create an implicit configuration '%s' for the extension '%s'", implicitConfigurationModel.getName(), extensionModel.getName())), e);
    }
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ImplicitObjectUtils.buildImplicitResolverSet(org.mule.runtime.module.extension.internal.loader.utils.ImplicitObjectUtils.buildImplicitResolverSet) ImplicitConnectionProviderValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver) LocalTimeSupplier(org.mule.runtime.core.internal.time.LocalTimeSupplier) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 5 with ConfigurationInstance

use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.

the class UnauthorizeOperationExecutor method execute.

@Override
public Publisher<Object> execute(ExecutionContext<ComponentModel> executionContext) {
    ConfigurationInstance config = executionContext.getConfiguration().get();
    String ownerId = executionContext.hasParameter(RESOURCE_OWNER_ID_PARAMETER_NAME) ? executionContext.getParameter(RESOURCE_OWNER_ID_PARAMETER_NAME) : DEFAULT_RESOURCE_OWNER_ID;
    oauthManager.invalidate(config.getName(), ownerId);
    return Mono.empty();
}
Also used : ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Aggregations

ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)25 Test (org.junit.Test)12 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)9 SmallTest (org.mule.tck.size.SmallTest)9 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)7 ConfigurationProvider (org.mule.runtime.extension.api.runtime.config.ConfigurationProvider)7 MuleException (org.mule.runtime.api.exception.MuleException)5 ExtensionsTestUtils.mockConfigurationInstance (org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance)5 List (java.util.List)4 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)4 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)4 ReflectionCache (org.mule.runtime.module.extension.internal.util.ReflectionCache)4 String.format (java.lang.String.format)3 Optional (java.util.Optional)3 Optional.empty (java.util.Optional.empty)3 Optional.of (java.util.Optional.of)3 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)3 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)3 ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)3 ResolverSetResult (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult)3