use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class CompositeArtifactExtensionManagerTestCase method failsToObtainMissingConfigurationFromProviderName.
@Test
public void failsToObtainMissingConfigurationFromProviderName() 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(empty());
when(parentExtensionManager.getConfigurationProvider(PROVIDER_NAME)).thenReturn(empty());
expectedException.expect(IllegalArgumentException.class);
extensionManager.getConfiguration(PROVIDER_NAME, event);
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class DynamicConfigurationProvider method createConfiguration.
private ConfigurationInstance createConfiguration(Pair<ResolverSetResult, ResolverSetResult> values, CoreEvent event) throws MuleException {
ConfigurationInstance configuration;
ResolverSetResult connectionProviderValues = values.getSecond();
if (connectionProviderValues != null) {
configuration = configurationInstanceFactory.createConfiguration(getName(), values.getFirst(), event, connectionProviderResolver, connectionProviderValues);
} else {
configuration = configurationInstanceFactory.createConfiguration(getName(), values.getFirst(), event, ofNullable(connectionProviderResolver));
}
registerConfiguration(configuration);
return configuration;
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class DynamicConfigurationProvider method getConfiguration.
private ConfigurationInstance getConfiguration(Pair<ResolverSetResult, ResolverSetResult> resolverSetResult, CoreEvent event) throws Exception {
ConfigurationInstance configuration;
cacheReadLock.lock();
try {
configuration = cache.get(resolverSetResult);
if (configuration != null) {
// important to account between the boundaries of the lock to prevent race condition
updateUsageStatistic(configuration);
return configuration;
}
} finally {
cacheReadLock.unlock();
}
cacheWriteLock.lock();
try {
// re-check in case some other thread beat us to it...
configuration = cache.get(resolverSetResult);
if (configuration == null) {
configuration = createConfiguration(resolverSetResult, event);
cache.put(resolverSetResult, configuration);
}
// accounting here for the same reasons as above
updateUsageStatistic(configuration);
return configuration;
} finally {
cacheWriteLock.unlock();
}
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance 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);
}
use of org.mule.runtime.extension.api.runtime.config.ConfigurationInstance in project mule by mulesoft.
the class ExtensionConnectionSupplier method getTransactedConnectionHandler.
private <T extends TransactionalConnection> ConnectionHandler<T> getTransactedConnectionHandler(ExecutionContextAdapter<? extends ComponentModel> executionContext, TransactionConfig transactionConfig) throws ConnectionException, TransactionException {
if (!transactionConfig.isTransacted()) {
return getTransactionlessConnectionHandler(executionContext);
}
ExtensionModel extensionModel = executionContext.getExtensionModel();
ComponentModel componentModel = executionContext.getComponentModel();
ConfigurationInstance configuration = executionContext.getConfiguration().orElseThrow(() -> new IllegalStateException(format("%s '%s' of extension '%s' cannot participate in a transaction because it doesn't have a config", getComponentModelTypeName(componentModel), componentModel.getName(), extensionModel.getName())));
final ExtensionTransactionKey txKey = new ExtensionTransactionKey(configuration);
TransactionBindingDelegate transactionBindingDelegate = new TransactionBindingDelegate(extensionModel, componentModel);
return transactionBindingDelegate.getBoundResource(transactionConfig, txKey, () -> getTransactionlessConnectionHandler(executionContext));
}
Aggregations