Search in sources :

Example 1 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class ActiveMQConnectorTestSupport method newActiveMQEndpointStep.

// **************************
// Helpers
// **************************
protected Step newActiveMQEndpointStep(String actionId, Consumer<Step.Builder> consumer) {
    final Connector connector = getResourceManager().mandatoryLoadConnector("activemq");
    final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId);
    final Step.Builder builder = new Step.Builder().stepKind(StepKind.endpoint).action(action).connection(new io.syndesis.common.model.connection.Connection.Builder().connector(connector).putConfiguredProperty("brokerUrl", broker.getVmURL()).build());
    consumer.accept(builder);
    return builder.build();
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step)

Example 2 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class DataShapeCustomizerTest method setUpComponent.

// ********************
// 
// ********************
protected ComponentProxyComponent setUpComponent(String actionId) {
    Connector connector = mandatoryLookupConnector();
    ConnectorAction action = mandatoryLookupAction(connector, actionId);
    ComponentProxyComponent component = new ComponentProxyComponent("salesforce-1", "salesforce");
    component.setBeforeProducer(BEFORE_PROCESSOR);
    component.setAfterProducer(AFTER_PROCESSOR);
    DataShapeCustomizer customizer = new DataShapeCustomizer();
    customizer.setCamelContext(context());
    action.getDescriptor().getInputDataShape().ifPresent(customizer::setInputDataShape);
    action.getDescriptor().getOutputDataShape().ifPresent(customizer::setOutputDataShape);
    customizer.customize(component, Collections.emptyMap());
    return component;
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) ConnectorAction(io.syndesis.common.model.action.ConnectorAction)

Example 3 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class BaseSwaggerConnectorGenerator method configureConnector.

protected final Connector configureConnector(final ConnectorTemplate connectorTemplate, final Connector connector, final ConnectorSettings connectorSettings) {
    final Connector.Builder builder = new Connector.Builder().createFrom(connector);
    final SwaggerModelInfo info = parseSpecification(connectorSettings, false);
    final Swagger swagger = info.getModel();
    addGlobalParameters(builder, swagger);
    final Map<String, Path> paths = swagger.getPaths();
    final String connectorId = connector.getId().get();
    final String connectorGav = connectorTemplate.getCamelConnectorGAV();
    final String connectorScheme = connectorTemplate.getCamelConnectorPrefix();
    final List<ConnectorAction> actions = new ArrayList<>();
    int idx = 0;
    for (final Entry<String, Path> pathEntry : paths.entrySet()) {
        final Path path = pathEntry.getValue();
        final Map<HttpMethod, Operation> operationMap = path.getOperationMap();
        for (final Entry<HttpMethod, Operation> entry : operationMap.entrySet()) {
            final Operation operation = entry.getValue();
            if (operation.getOperationId() == null) {
                operation.operationId("operation-" + idx++);
            }
            final ConnectorDescriptor descriptor = // 
            createDescriptor(info.getResolvedSpecification(), swagger, operation).camelConnectorGAV(// 
            connectorGav).camelConnectorPrefix(// 
            connectorScheme).connectorId(// 
            connectorId).build();
            final OperationDescription description = SwaggerHelper.operationDescriptionOf(swagger, operation);
            final ConnectorAction action = // 
            new ConnectorAction.Builder().id(// 
            createActionId(connectorId, connectorGav, operation)).name(// 
            description.name).description(// 
            description.description).pattern(// 
            Action.Pattern.To).descriptor(descriptor).tags(// 
            ofNullable(operation.getTags()).orElse(Collections.emptyList())).build();
            actions.add(action);
        }
    }
    actions.sort(ActionComparator.INSTANCE);
    builder.addAllActions(actions);
    builder.putConfiguredProperty("specification", SwaggerHelper.serialize(swagger));
    return builder.build();
}
Also used : Path(io.swagger.models.Path) Connector(io.syndesis.common.model.connection.Connector) ArrayList(java.util.ArrayList) Operation(io.swagger.models.Operation) OperationDescription(io.syndesis.server.connector.generator.swagger.util.OperationDescription) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Swagger(io.swagger.models.Swagger) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HttpMethod(io.swagger.models.HttpMethod)

Example 4 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class ConnectorStepHandler method handle.

@SuppressWarnings("PMD")
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String index) {
    // Model
    final Connection connection = step.getConnection().get();
    final Connector connector = connection.getConnector().get();
    final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
    final ConnectorDescriptor descriptor = action.getDescriptor();
    // Camel
    final String scheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
    final CamelContext context = builder.getContext();
    final String componentId = scheme + "-" + index;
    final ComponentProxyComponent component = resolveComponent(componentId, scheme, context, connector, descriptor);
    final List<String> customizers = CollectionsUtils.aggregate(ArrayList::new, connector.getConnectorCustomizers(), descriptor.getConnectorCustomizers());
    final Map<String, String> properties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
    final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
    // Workaround for https://github.com/syndesisio/syndesis/issues/1713
    for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
        if (ObjectHelper.isNotEmpty(entry.getValue().getDefaultValue())) {
            properties.putIfAbsent(entry.getKey(), entry.getValue().getDefaultValue());
        }
    }
    // if the option is marked as secret use property placeholder as the
    // value is added to the integration secret.
    properties.entrySet().stream().filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", scheme, index, e.getKey())));
    // raw values.
    properties.entrySet().stream().filter(Predicates.or(connector::isRaw, action::isRaw)).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
    // Connector/Action properties have the precedence
    connector.getConfiguredProperties().forEach(properties::put);
    descriptor.getConfiguredProperties().forEach(properties::put);
    try {
        final Map<String, Object> proxyProperties = new HashMap<>(properties);
        // Set input/output data shape if the component proxy implements
        // Input/OutputDataShapeAware
        descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(component, ds));
        descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(component, ds));
        // Try to set properties to the component
        setProperties(context, component, proxyProperties);
        for (String customizerType : customizers) {
            final ComponentProxyCustomizer customizer = resolveCustomizer(context, customizerType);
            // Set the camel context if the customizer implements
            // the CamelContextAware interface.
            ObjectHelper.trySetCamelContext(customizer, context);
            // Set input/output data shape if the customizer implements
            // Input/OutputDataShapeAware
            descriptor.getInputDataShape().ifPresent(ds -> trySetInputDataShape(customizer, ds));
            descriptor.getOutputDataShape().ifPresent(ds -> trySetOutputDataShape(customizer, ds));
            // Try to set properties to the component
            setProperties(context, customizer, proxyProperties);
            // Invoke the customizer
            customizer.customize(component, proxyProperties);
        }
        component.setCamelContext(context);
        component.setOptions(proxyProperties);
        // Remove component
        context.removeComponent(component.getComponentId());
        context.removeService(component);
        // Register component
        context.addService(component, true, true);
        context.addComponent(component.getComponentId(), component);
        if (route == null) {
            route = builder.from(componentId);
        } else {
            route = route.to(componentId);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return Optional.ofNullable(route);
}
Also used : CamelContext(org.apache.camel.CamelContext) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) ComponentProxyComponent(io.syndesis.integration.component.proxy.ComponentProxyComponent) ComponentProxyCustomizer(io.syndesis.integration.component.proxy.ComponentProxyCustomizer) HashMap(java.util.HashMap) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class SimpleEndpointStepHandler method handle.

@SuppressWarnings({ "unchecked", "PMD" })
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String index) {
    // Model
    final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
    final ConnectorDescriptor descriptor = action.getDescriptor();
    // Camel
    final String componentScheme = action.getDescriptor().getComponentScheme().get();
    final Map<String, String> configuredProperties = step.getConfiguredProperties();
    final Map<String, String> properties = action.filterEndpointProperties(configuredProperties);
    properties.entrySet().stream().filter(action::isEndpointProperty).filter(action::isSecret).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", componentScheme, index, e.getKey())));
    // raw values.
    properties.entrySet().stream().filter(action::isRaw).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
    // any configuredProperties on action descriptor are considered
    properties.putAll(descriptor.getConfiguredProperties());
    try {
        final RuntimeCamelCatalog catalog = builder.getContext().getRuntimeCamelCatalog();
        final String uri = catalog.asEndpointUri(componentScheme, Map.class.cast(properties), false);
        if (route == null) {
            route = builder.from(uri);
        } else {
            route = route.to(uri);
        }
    } catch (URISyntaxException e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
    return Optional.ofNullable(route);
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) URISyntaxException(java.net.URISyntaxException) RuntimeCamelCatalog(org.apache.camel.runtimecatalog.RuntimeCamelCatalog) Map(java.util.Map)

Aggregations

ConnectorAction (io.syndesis.common.model.action.ConnectorAction)21 Connector (io.syndesis.common.model.connection.Connector)16 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)11 Step (io.syndesis.common.model.integration.Step)8 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)5 Connection (io.syndesis.common.model.connection.Connection)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DataShape (io.syndesis.common.model.DataShape)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Test (org.junit.Test)3 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)2 Integration (io.syndesis.common.model.integration.Integration)2 MavenProperties (io.syndesis.common.util.MavenProperties)2 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)2 ComponentProxyComponent (io.syndesis.integration.component.proxy.ComponentProxyComponent)2 File (java.io.File)2