Search in sources :

Example 1 with TypedComponentIdentifier

use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.

the class DefaultEventContextTestCase method componentData.

@Test
@Description("Verify that a location produces connector and source data.")
public void componentData() throws Exception {
    TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(SOURCE).identifier(buildFromStringRepresentation("http:listener")).build();
    ComponentLocation location = mock(ComponentLocation.class);
    when(location.getComponentIdentifier()).thenReturn(typedComponentIdentifier);
    when(location.getParts()).thenReturn(asList(new DefaultLocationPart("flow", empty(), empty(), empty())));
    BaseEventContext context = contextWithComponentLocation.apply(location);
    assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is("http"));
    assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("listener"));
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) DefaultLocationPart(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.DefaultLocationPart) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 2 with TypedComponentIdentifier

use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.

the class ApplicationModel method getConfigurationPropertiesProvidersFromComponents.

private List<ConfigurationPropertiesProvider> getConfigurationPropertiesProvidersFromComponents(ArtifactConfig artifactConfig, ConfigurationPropertiesResolver localResolver) {
    Map<ComponentIdentifier, ConfigurationPropertiesProviderFactory> providerFactoriesMap = new HashMap<>();
    ServiceLoader<ConfigurationPropertiesProviderFactory> providerFactories = java.util.ServiceLoader.load(ConfigurationPropertiesProviderFactory.class);
    providerFactories.forEach(service -> {
        ComponentIdentifier componentIdentifier = service.getSupportedComponentIdentifier();
        if (providerFactoriesMap.containsKey(componentIdentifier)) {
            throw new MuleRuntimeException(createStaticMessage("Multiple configuration providers for component: " + componentIdentifier));
        }
        providerFactoriesMap.put(componentIdentifier, service);
    });
    List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = new ArrayList<>();
    artifactConfig.getConfigFiles().stream().forEach(configFile -> configFile.getConfigLines().stream().forEach(configLine -> {
        for (ConfigLine componentConfigLine : configLine.getChildren()) {
            if (componentConfigLine.getNamespace() == null) {
                continue;
            }
            ComponentIdentifier componentIdentifier = ComponentIdentifier.builder().namespace(componentConfigLine.getNamespace()).name(componentConfigLine.getIdentifier()).build();
            if (!providerFactoriesMap.containsKey(componentIdentifier)) {
                continue;
            }
            DefaultConfigurationParameters.Builder configurationParametersBuilder = DefaultConfigurationParameters.builder();
            ConfigurationParameters configurationParameters = resolveConfigurationParameters(configurationParametersBuilder, componentConfigLine, localResolver);
            ConfigurationPropertiesProvider provider = providerFactoriesMap.get(componentIdentifier).createProvider(configurationParameters, externalResourceProvider);
            if (provider instanceof Component) {
                Component providerComponent = (Component) provider;
                TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(UNKNOWN).identifier(componentIdentifier).build();
                DefaultComponentLocation.DefaultLocationPart locationPart = new DefaultComponentLocation.DefaultLocationPart(componentIdentifier.getName(), of(typedComponentIdentifier), of(configFile.getFilename()), of(configLine.getLineNumber()));
                providerComponent.setAnnotations(ImmutableMap.<QName, Object>builder().put(AbstractComponent.LOCATION_KEY, new DefaultComponentLocation(of(componentIdentifier.getName()), singletonList(locationPart))).build());
            }
            configConfigurationPropertiesProviders.add(provider);
            try {
                initialiseIfNeeded(provider);
            } catch (InitialisationException e) {
                throw new MuleRuntimeException(e);
            }
        }
    }));
    return configConfigurationPropertiesProviders;
}
Also used : ResourceProvider(org.mule.runtime.config.api.dsl.model.ResourceProvider) MacroExpansionModulesModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) MULE_ROOT_ELEMENT(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_ROOT_ELEMENT) Optional.of(java.util.Optional.of) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ConfigurationProperty(org.mule.runtime.config.api.dsl.model.properties.ConfigurationProperty) Collections.singletonList(java.util.Collections.singletonList) ClassUtils(org.apache.commons.lang3.ClassUtils) DefaultConfigurationParameters(org.mule.runtime.config.internal.dsl.model.DefaultConfigurationParameters) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) MULE_EE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_EE_DOMAIN_IDENTIFIER) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) DslElementModelFactory(org.mule.runtime.config.api.dsl.model.DslElementModelFactory) ERROR_HANDLER_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.ERROR_HANDLER_IDENTIFIER) ComponentModelReader(org.mule.runtime.config.internal.dsl.model.ComponentModelReader) CompositeConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.CompositeConfigurationPropertiesProvider) PropertiesResolverConfigurationProperties(org.mule.runtime.config.internal.dsl.model.config.PropertiesResolverConfigurationProperties) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) MULE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_DOMAIN_IDENTIFIER) DEFAULT_EXPRESSION_PREFIX(org.mule.runtime.core.api.el.ExpressionManager.DEFAULT_EXPRESSION_PREFIX) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentModelHelper.resolveComponentType(org.mule.runtime.config.internal.dsl.spring.ComponentModelHelper.resolveComponentType) MapConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.MapConfigurationPropertiesProvider) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) UNKNOWN(org.mule.runtime.api.component.TypedComponentIdentifier.ComponentType.UNKNOWN) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ServiceLoader(java.util.ServiceLoader) SOURCE_TYPE(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory.SOURCE_TYPE) NameValidationUtil.verifyStringDoesNotContainsReservedCharacters(org.mule.runtime.internal.util.NameValidationUtil.verifyStringDoesNotContainsReservedCharacters) String.format(java.lang.String.format) FileConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.FileConfigurationPropertiesProvider) ERROR_HANDLER(org.mule.runtime.config.api.dsl.CoreDslConstants.ERROR_HANDLER) I18nMessageFactory(org.mule.runtime.api.i18n.I18nMessageFactory) XmlCustomAttributeHandler(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) List(java.util.List) ElementDeclaration(org.mule.runtime.app.declaration.api.ElementDeclaration) GlobalPropertyConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.GlobalPropertyConfigurationPropertiesProvider) Optional(java.util.Optional) QName(javax.xml.namespace.QName) MuleExtensionModelProvider(org.mule.runtime.core.api.extension.MuleExtensionModelProvider) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) Optional.empty(java.util.Optional.empty) ComponentBuildingDefinitionRegistry(org.mule.runtime.config.api.dsl.model.ComponentBuildingDefinitionRegistry) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ComponentLocationVisitor(org.mule.runtime.config.internal.dsl.model.ComponentLocationVisitor) NameUtils.pluralize(org.mule.runtime.extension.api.util.NameUtils.pluralize) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MULE_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_IDENTIFIER) ConfigurationPropertiesProvider(org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProvider) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) Component(org.mule.runtime.api.component.Component) Node(org.w3c.dom.Node) BiConsumer(java.util.function.BiConsumer) FLOW_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.FLOW_IDENTIFIER) RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) DefaultConfigurationProperty(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty) LinkedList(java.util.LinkedList) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) NameUtils.hyphenize(org.mule.runtime.extension.api.util.NameUtils.hyphenize) ConfigurationParameters(org.mule.runtime.config.api.dsl.model.ConfigurationParameters) ExtensionModelHelper(org.mule.runtime.config.internal.dsl.model.ExtensionModelHelper) ArtifactConfig(org.mule.runtime.config.api.dsl.processor.ArtifactConfig) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) Joiner.on(com.google.common.base.Joiner.on) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesResolver) FLOW_REF_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.FLOW_REF_IDENTIFIER) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationPropertiesProviderFactory(org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProviderFactory) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) CollectionUtils.disjunction(org.apache.commons.collections.CollectionUtils.disjunction) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ANY_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.ANY_IDENTIFIER) ConfigurationPropertiesProviderFactory(org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProviderFactory) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) DefaultConfigurationParameters(org.mule.runtime.config.internal.dsl.model.DefaultConfigurationParameters) ConfigurationParameters(org.mule.runtime.config.api.dsl.model.ConfigurationParameters) CompositeConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.CompositeConfigurationPropertiesProvider) MapConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.MapConfigurationPropertiesProvider) FileConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.FileConfigurationPropertiesProvider) GlobalPropertyConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.GlobalPropertyConfigurationPropertiesProvider) ConfigurationPropertiesProvider(org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProvider) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Component(org.mule.runtime.api.component.Component) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)

Example 3 with TypedComponentIdentifier

use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.

the class ComponentLocationVisitor method getModuleOperationTypeComponentIdentifier.

private Optional<TypedComponentIdentifier> getModuleOperationTypeComponentIdentifier(ComponentModel componentModel) {
    final ComponentIdentifier originalIdentifier = (ComponentIdentifier) componentModel.getCustomAttributes().get(ORIGINAL_IDENTIFIER);
    final String namespace = originalIdentifier.getNamespace();
    final String operationName = originalIdentifier.getName();
    final ComponentIdentifier operationIdentifier = ComponentIdentifier.builder().namespace(namespace).name(operationName).build();
    return of(builder().identifier(operationIdentifier).type(OPERATION).build());
}
Also used : TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier)

Example 4 with TypedComponentIdentifier

use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.

the class ComponentLocationVisitor method processModuleOperationChildren.

/**
 * It rewrites the history for those macro expanded operations that are not direct children from a flow, which means the
 * returned {@link ComponentLocation} are mapped to the new operation rather the original flow.
 *
 * @param componentModel source to generate the new {@link ComponentLocation}, it also relies in its parent
 *        {@link ComponentModel#getParent()}
 * @param operationTypedIdentifier identifier of the current operation
 * @return a fictitious {@link ComponentLocation}
 */
private DefaultComponentLocation processModuleOperationChildren(ComponentModel componentModel, Optional<TypedComponentIdentifier> operationTypedIdentifier) {
    final Optional<TypedComponentIdentifier> parentOperationTypedIdentifier = getModuleOperationTypeComponentIdentifier(componentModel.getParent());
    final String operationName = parentOperationTypedIdentifier.get().getIdentifier().getName();
    return new DefaultComponentLocation(of(operationName), emptyList()).appendLocationPart(operationName, parentOperationTypedIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber()).appendLocationPart(PROCESSORS_PART_NAME, empty(), empty(), empty()).appendLocationPart(findProcessorPath(componentModel), operationTypedIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
}
Also used : TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)

Example 5 with TypedComponentIdentifier

use of org.mule.runtime.api.component.TypedComponentIdentifier in project mule by mulesoft.

the class ComponentLocationVisitor method accept.

/**
 * For every {@link ComponentModel} in the configuration, sets the {@link DefaultComponentLocation} associated within an
 * annotation under the key {@link AbstractComponent#LOCATION_KEY}.
 *
 * @param componentModel the component model that will be assign it's {@link DefaultComponentLocation}.
 */
@Override
public void accept(ComponentModel componentModel) {
    if (componentModel.getParent() == null) {
        // do not process root element
        return;
    }
    DefaultComponentLocation componentLocation;
    Optional<TypedComponentIdentifier> typedComponentIdentifier = of(builder().identifier(componentModel.getIdentifier()).type(componentModel.getComponentType().orElse(UNKNOWN)).build());
    if (componentModel.isRoot()) {
        String componentModelNameAttribute = componentModel.getNameAttribute();
        ImmutableList<DefaultLocationPart> parts = ImmutableList.<DefaultLocationPart>builder().add(new DefaultLocationPart(componentModelNameAttribute, typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber())).build();
        componentLocation = new DefaultComponentLocation(ofNullable(componentModelNameAttribute), parts);
    } else if (existsWithinRootContainer(componentModel)) {
        ComponentModel parentComponentModel = componentModel.getParent();
        DefaultComponentLocation parentComponentLocation = parentComponentModel.getComponentLocation();
        if (isHttpProxyPart(componentModel)) {
            componentLocation = parentComponentLocation.appendLocationPart(componentModel.getIdentifier().getName(), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
        } else if (isRootProcessorScope(parentComponentModel)) {
            componentLocation = processFlowDirectChild(componentModel, parentComponentLocation, typedComponentIdentifier);
        } else if (isMunitFlowIdentifier(parentComponentModel)) {
            componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
        } else if (isErrorHandler(componentModel)) {
            componentLocation = processErrorHandlerComponent(componentModel, parentComponentLocation, typedComponentIdentifier);
        } else if (isTemplateOnErrorHandler(componentModel)) {
            componentLocation = processOnErrorModel(componentModel, parentComponentLocation, typedComponentIdentifier);
        } else if (parentComponentIsRouter(componentModel)) {
            if (isRoute(componentModel)) {
                componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), of(TypedComponentIdentifier.builder().type(SCOPE).identifier(ROUTE_COMPONENT_IDENTIFIER).build()), componentModel.getConfigFileName(), componentModel.getLineNumber());
            } else if (isProcessor(componentModel)) {
                // this is the case of the routes directly inside the router as with scatter-gather
                componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findProcessorPath(componentModel), empty(), empty(), empty()).appendProcessorsPart().appendLocationPart("0", typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
            } else {
                // this is the case of the when element inside the choice
                componentLocation = parentComponentLocation.appendRoutePart().appendLocationPart(findNonProcessorPath(componentModel), of(TypedComponentIdentifier.builder().type(UNKNOWN).identifier(ROUTE_COMPONENT_IDENTIFIER).build()), empty(), empty());
            }
        } else if (isProcessor(componentModel)) {
            if (isModuleOperation(componentModel.getParent())) {
                final Optional<TypedComponentIdentifier> operationTypedIdentifier = ApplicationModel.MODULE_OPERATION_CHAIN.equals(typedComponentIdentifier.get().getIdentifier()) ? getModuleOperationTypeComponentIdentifier(componentModel) : typedComponentIdentifier;
                componentLocation = processModuleOperationChildren(componentModel, operationTypedIdentifier);
            } else {
                componentLocation = parentComponentLocation.appendProcessorsPart().appendLocationPart(findProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
            }
        } else {
            if (isBatchAggregator(componentModel)) {
                componentLocation = parentComponentLocation.appendLocationPart(BATCH_AGGREGATOR_COMPONENT_IDENTIFIER.getName(), of(TypedComponentIdentifier.builder().type(UNKNOWN).identifier(BATCH_AGGREGATOR_COMPONENT_IDENTIFIER).build()), componentModel.getConfigFileName(), componentModel.getLineNumber());
            } else {
                componentLocation = parentComponentLocation.appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
            }
        }
    } else {
        DefaultComponentLocation parentComponentLocation = componentModel.getParent().getComponentLocation();
        componentLocation = parentComponentLocation.appendLocationPart(findNonProcessorPath(componentModel), typedComponentIdentifier, componentModel.getConfigFileName(), componentModel.getLineNumber());
    }
    componentModel.setComponentLocation(componentLocation);
}
Also used : DefaultLocationPart(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.DefaultLocationPart) Optional(java.util.Optional) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)

Aggregations

TypedComponentIdentifier (org.mule.runtime.api.component.TypedComponentIdentifier)5 DefaultComponentLocation (org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)3 Optional (java.util.Optional)2 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)2 Joiner.on (com.google.common.base.Joiner.on)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Description (io.qameta.allure.Description)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional.empty (java.util.Optional.empty)1