Search in sources :

Example 1 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class DefaultPolicyManager method createOperationPolicy.

@Override
public OperationPolicy createOperationPolicy(Component operation, CoreEvent event, Map<String, Object> operationParameters, OperationExecutionFunction operationExecutionFunction) {
    PolicyPointcutParameters operationPointcutParameters = policyPointcutParametersManager.createOperationPointcutParameters(operation, event, operationParameters);
    List<Policy> parameterizedPolicies = policyProvider.findOperationParameterizedPolicies(operationPointcutParameters);
    if (parameterizedPolicies.isEmpty()) {
        return (operationEvent) -> operationExecutionFunction.execute(operationParameters, operationEvent);
    }
    return new CompositeOperationPolicy(parameterizedPolicies, lookupOperationParametersTransformer(operation.getLocation().getComponentIdentifier().getIdentifier()), operationPolicyProcessorFactory, () -> operationParameters, operationExecutionFunction, streamingManager);
}
Also used : Policy(org.mule.runtime.core.api.policy.Policy) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Processor(org.mule.runtime.core.api.processor.Processor) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) Inject(javax.inject.Inject) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MessageProcessors.process(org.mule.runtime.core.privileged.processor.MessageProcessors.process) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) PolicyStateHandler(org.mule.runtime.core.api.policy.PolicyStateHandler) SourcePolicyParametersTransformer(org.mule.runtime.core.api.policy.SourcePolicyParametersTransformer) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message.of(org.mule.runtime.api.message.Message.of) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) OperationPolicyParametersTransformer(org.mule.runtime.core.api.policy.OperationPolicyParametersTransformer) Either.right(org.mule.runtime.core.api.functional.Either.right) Either(org.mule.runtime.core.api.functional.Either) PolicyProvider(org.mule.runtime.core.api.policy.PolicyProvider) List(java.util.List) Policy(org.mule.runtime.core.api.policy.Policy) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Example 2 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class PolicyPointcutParametersManager method createOperationPointcutParameters.

/**
 * Creates {@link PolicyPointcutParameters} for a specific operation. Stored parameters from the source are included in the
 * newly created parameters to be able to correlate parameters from both source and operation.
 *
 * @param operation the operation component to which policies will be applied
 * @param event the event which will execute the operation policies
 * @param operationParameters a map containing the parameters of the operation
 * @return the created {@link PolicyPointcutParameters}
 */
public PolicyPointcutParameters createOperationPointcutParameters(Component operation, CoreEvent event, Map<String, Object> operationParameters) {
    ComponentIdentifier operationIdentifier = operation.getLocation().getComponentIdentifier().getIdentifier();
    PolicyPointcutParameters sourceParameters = sourceParametersMap.get(event.getContext().getCorrelationId());
    OperationPolicyPointcutParametersParameters parameters = new OperationPolicyPointcutParametersParameters(operation, operationParameters, sourceParameters);
    Function<OperationPolicyPointcutParametersFactory, PolicyPointcutParameters> creationFunction = factory -> {
        try {
            return factory.createPolicyPointcutParameters(parameters);
        } catch (AbstractMethodError error) {
            return factory.createPolicyPointcutParameters(parameters.getOperation(), parameters.getOperationParameters());
        }
    };
    return createPointcutParameters(operation, OperationPolicyPointcutParametersFactory.class, operationPointcutFactories, factory -> factory.supportsOperationIdentifier(operationIdentifier), creationFunction).orElse(new PolicyPointcutParameters(operation, sourceParameters));
}
Also used : Optional.empty(java.util.Optional.empty) SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) Predicate(java.util.function.Predicate) Optional.of(java.util.Optional.of) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collection(java.util.Collection) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Function(java.util.function.Function) String.format(java.lang.String.format) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) OperationPolicyPointcutParametersParameters(org.mule.runtime.policy.api.OperationPolicyPointcutParametersParameters) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) OperationPolicyPointcutParametersParameters(org.mule.runtime.policy.api.OperationPolicyPointcutParametersParameters) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Example 3 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class PolicyPointcutParametersManagerTestCase method createOperationParametersWhenOneFactorySupportsIdentifier.

@Test
public void createOperationParametersWhenOneFactorySupportsIdentifier() {
    Map<String, Object> operationParameters = new HashMap<>();
    PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
    OperationPolicyPointcutParametersFactory factory = mockOperationFactory(true, sourceParameters);
    operationPointcutFactories.add(factory);
    sourcePointcutFactories.add(mockSourceFactory(true));
    PolicyPointcutParameters parameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
    assertThat(parameters.getComponent(), is(component));
    assertThat(parameters.getSourceParameters(), is(of(sourceParameters)));
    verify(factory).supportsOperationIdentifier(identifier);
    verify(factory).createPolicyPointcutParameters(any());
}
Also used : HashMap(java.util.HashMap) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Test(org.junit.Test)

Example 4 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class PolicyPointcutParametersManagerTestCase method createOperationParametersFallbacksToDeprecatedMethod.

@Test
public void createOperationParametersFallbacksToDeprecatedMethod() {
    Map<String, Object> operationParameters = new HashMap<>();
    PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
    OperationPolicyPointcutParametersFactory factory = mockOperationFactory(true, sourceParameters);
    PolicyPointcutParameters parameters = mock(PolicyPointcutParameters.class);
    when(factory.createPolicyPointcutParameters(any())).thenThrow(new AbstractMethodError());
    when(factory.createPolicyPointcutParameters(component, operationParameters)).thenReturn(parameters);
    operationPointcutFactories.add(factory);
    PolicyPointcutParameters returnedParameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
    assertThat(returnedParameters, is(parameters));
    verify(factory).supportsOperationIdentifier(identifier);
    verify(factory).createPolicyPointcutParameters(any());
    verify(factory).createPolicyPointcutParameters(component, operationParameters);
}
Also used : HashMap(java.util.HashMap) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Test(org.junit.Test)

Example 5 with PolicyPointcutParameters

use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.

the class PolicyPointcutParametersManagerTestCase method createSourceParametersWhenEmptyFactory.

@Test
public void createSourceParametersWhenEmptyFactory() {
    PolicyPointcutParameters parameters = parametersManager.createSourcePointcutParameters(component, event);
    assertThat(parameters.getComponent(), is(component));
    assertThat(parameters.getSourceParameters(), empty());
    verify(eventContext).onTerminated(any());
}
Also used : PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Test(org.junit.Test)

Aggregations

PolicyPointcutParameters (org.mule.runtime.policy.api.PolicyPointcutParameters)17 Test (org.junit.Test)11 OperationPolicyPointcutParametersFactory (org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory)10 SourcePolicyPointcutParametersFactory (org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory)8 HashMap (java.util.HashMap)7 Collection (java.util.Collection)4 Map (java.util.Map)4 Optional (java.util.Optional)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Component (org.mule.runtime.api.component.Component)4 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)4 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)4 String.format (java.lang.String.format)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2 Optional.of (java.util.Optional.of)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 Inject (javax.inject.Inject)2