Search in sources :

Example 16 with ConnectorDescriptor

use of io.syndesis.common.model.action.ConnectorDescriptor in project syndesis-qe by syndesisio.

the class TwSteps method createTwitterStep.

@Given("^create TW mention step with \"([^\"]*)\" action")
public void createTwitterStep(String twitterAction) {
    final Connector twitterConnector = connectorsEndpoint.get("twitter");
    final Connection twitterConnection = connectionsEndpoint.get(RestConstants.getInstance().getTWITTER_CONNECTION_ID());
    final Action twAction = TestUtils.findConnectorAction(twitterConnector, twitterAction);
    final ConnectorDescriptor connectorDescriptor = getConnectorDescriptor(twAction, new HashMap<>(), RestConstants.getInstance().getTWITTER_CONNECTION_ID());
    final Step twitterStep = new Step.Builder().stepKind(StepKind.endpoint).connection(twitterConnection).id(UUID.randomUUID().toString()).action(generateStepAction(twAction, connectorDescriptor)).build();
    steps.getStepDefinitions().add(new StepDefinition(twitterStep, connectorDescriptor));
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Action(io.syndesis.common.model.action.Action) Connection(io.syndesis.common.model.connection.Connection) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) Step(io.syndesis.common.model.integration.Step) AbstractStep(io.syndesis.qe.bdd.AbstractStep) Given(cucumber.api.java.en.Given)

Example 17 with ConnectorDescriptor

use of io.syndesis.common.model.action.ConnectorDescriptor in project syndesis-qe by syndesisio.

the class UiComplexSteps method dbToDbIntegrationWithPeriodMs.

@Given("^db to db \"([^\"]*)\" integration with period (\\d+) ms$")
public void dbToDbIntegrationWithPeriodMs(String integrationName, int ms) throws IOException {
    final Connection dbConnection = connectionsEndpoint.get(getDbConnectionId());
    final Connector dbConnector = connectorsEndpoint.get("sql");
    final String sqlStartQuery = "SELECT * FROM CONTACT";
    final String sqlFinishQuery = "INSERT INTO TODO(task, completed) VALUES (:#TASK, 2)";
    final String datamapperTemplate = "db-db.json";
    // 1.        @Then("^create start DB periodic sql invocation action step with query \"([^\"]*)\" and period \"([^\"]*)\" ms")
    final Action dbAction1 = TestUtils.findConnectorAction(dbConnector, "sql-start-connector");
    final Map<String, String> properties1 = TestUtils.map("query", sqlStartQuery, "schedulerPeriod", ms);
    final ConnectorDescriptor connectorDescriptor1 = getConnectorDescriptor(dbAction1, properties1, dbConnection.getId().get());
    // to be reported: period is not part of .json step (when checked via browser).
    final Step dbStep1 = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(dbConnection).action(dbAction1).configuredProperties(properties1).build();
    steps.getStepDefinitions().add(new StepDefinition(dbStep1, connectorDescriptor1));
    // 2.A @And("start mapper definition with name: \"([^\"]*)\"")
    String mapperName = "mapping 1";
    final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).name(mapperName).build();
    steps.getStepDefinitions().add(new StepDefinition(mapperStep, new DataMapperDefinition()));
    // 2.B @Then("MAP using Step (\\d+) and field \"([^\"]*)\" to \"([^\"]*)\"")
    int fromStep = 1;
    String fromField = "first_name";
    String toField = "TASK";
    DataMapperStepDefinition newDmStep = new DataMapperStepDefinition();
    newDmStep.setFromStep(fromStep);
    newDmStep.setInputFields(Arrays.asList(fromField));
    newDmStep.setOutputFields(Arrays.asList(toField));
    newDmStep.setMappingType(MappingType.MAP);
    newDmStep.setStrategy(null);
    steps.getLastStepDefinition().getDataMapperDefinition().get().getDataMapperStepDefinition().add(newDmStep);
    // 3.        @Then("^create finish DB invoke sql action step with query \"([^\"]*)\"")
    final Action dbAction2 = TestUtils.findConnectorAction(dbConnector, "sql-connector");
    final Map<String, String> properties2 = TestUtils.map("query", sqlFinishQuery);
    final ConnectorDescriptor connectorDescriptor2 = getConnectorDescriptor(dbAction2, properties2, dbConnection.getId().get());
    final Step dbStep2 = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(dbConnection).action(dbAction2).configuredProperties(properties2).build();
    steps.getStepDefinitions().add(new StepDefinition(dbStep2, connectorDescriptor2));
    // 4.    @When("^create integration with name: \"([^\"]*)\"")
    processMapperSteps();
    Integration integration = new Integration.Builder().steps(steps.getSteps()).name(integrationName).description("Awkward UI integration.").build();
    log.info("Creating integration {}", integration.getName());
    String integrationId = integrationsEndpoint.create(integration).getId().get();
    log.info("Publish integration with ID: {}", integrationId);
    publishIntegration(integrationId);
    log.debug("Flushing used steps");
    steps.flushStepDefinitions();
    // 5.        @Then("^wait for integration with name: \"([^\"]*)\" to become active")
    final List<Integration> integrations = integrationsEndpoint.list().stream().filter(item -> item.getName().equals(integrationName)).collect(Collectors.toList());
    final long start = System.currentTimeMillis();
    // wait for activation
    log.info("Waiting until integration \"{}\" becomes active. This may take a while...", integrationName);
    integrationOverviewEndpoint = new IntegrationOverviewEndpoint(integrationId);
    final IntegrationOverview integrationOverview = integrationOverviewEndpoint.getOverview();
    final boolean activated = TestUtils.waitForPublishing(integrationOverviewEndpoint, integrationOverview, TimeUnit.MINUTES, 10);
    Assertions.assertThat(activated).isEqualTo(true);
    log.info("Integration pod has been started. It took {}s to build the integration.", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start));
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Arrays(java.util.Arrays) Action(io.syndesis.common.model.action.Action) Step(io.syndesis.common.model.integration.Step) Autowired(org.springframework.beans.factory.annotation.Autowired) MappingType(io.atlasmap.v2.MappingType) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Given(cucumber.api.java.en.Given) Assertions(org.assertj.core.api.Assertions) StepKind(io.syndesis.common.model.integration.StepKind) Integration(io.syndesis.common.model.integration.Integration) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) Connector(io.syndesis.common.model.connection.Connector) AtlasMapperGenerator(io.syndesis.qe.bdd.datamapper.AtlasMapperGenerator) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IntegrationOverview(io.syndesis.qe.model.IntegrationOverview) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) TestUtils(io.syndesis.qe.utils.TestUtils) DataMapperDefinition(io.syndesis.qe.bdd.entities.DataMapperDefinition) StepsStorage(io.syndesis.qe.bdd.storage.StepsStorage) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) Connector(io.syndesis.common.model.connection.Connector) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) Action(io.syndesis.common.model.action.Action) Integration(io.syndesis.common.model.integration.Integration) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) DataMapperDefinition(io.syndesis.qe.bdd.entities.DataMapperDefinition) IntegrationOverview(io.syndesis.qe.model.IntegrationOverview) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) Given(cucumber.api.java.en.Given)

Example 18 with ConnectorDescriptor

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

the class IntegrationRouteBuilder method handleConnectorSplit.

private Optional<ProcessorDefinition> handleConnectorSplit(Step step, ProcessorDefinition route, String index) {
    if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) {
        final ConnectorAction action = step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get();
        final ConnectorDescriptor descriptor = action.getDescriptor();
        if (descriptor.getSplit().isPresent()) {
            final Split split = descriptor.getSplit().get();
            final Step.Builder splitBuilder = new Step.Builder().stepKind(StepKind.split);
            split.getLanguage().ifPresent(s -> splitBuilder.putConfiguredProperty("language", s));
            split.getExpression().ifPresent(s -> splitBuilder.putConfiguredProperty("expression", s));
            return new SplitStepHandler().handle(splitBuilder.build(), route, this, index);
        }
    }
    return Optional.empty();
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step) Split(io.syndesis.common.model.Split) SplitStepHandler(io.syndesis.integration.runtime.handlers.SplitStepHandler)

Example 19 with ConnectorDescriptor

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

the class EndpointStepHandler method handle.

@SuppressWarnings({ "unchecked", "PMD" })
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String stepIndex) {
    // 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 componentScheme = action.getDescriptor().getCamelConnectorPrefix();
    final Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
    final Map<String, String> properties = CollectionsUtils.aggregate(connector.filterEndpointProperties(configuredProperties), action.filterEndpointProperties(configuredProperties));
    properties.entrySet().stream().filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)).filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", componentScheme, stepIndex, e.getKey())));
    // raw values.
    properties.entrySet().stream().filter(Predicates.or(connector::isRaw, action::isRaw)).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
    // any configuredProperties on action descriptor are considered
    properties.putAll(descriptor.getConfiguredProperties());
    String uri = String.format("%s-%s", componentScheme, stepIndex);
    if (ObjectHelper.isNotEmpty(uri) && ObjectHelper.isNotEmpty(properties)) {
        try {
            uri = URISupport.appendParametersToURI(uri, Map.class.cast(properties));
        } catch (UnsupportedEncodingException | URISyntaxException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }
    if (route == null) {
        route = builder.from(uri);
    } else {
        route = route.to(uri);
    }
    return Optional.ofNullable(route);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Connection(io.syndesis.common.model.connection.Connection) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) URISyntaxException(java.net.URISyntaxException)

Example 20 with ConnectorDescriptor

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

the class ConnectionActionHandler method applyMetadataTo.

private static ConnectorDescriptor applyMetadataTo(final ConnectorDescriptor descriptor, final DynamicActionMetadata dynamicMetadata) {
    final Map<String, List<DynamicActionMetadata.ActionPropertySuggestion>> actionPropertySuggestions = dynamicMetadata.properties();
    final ConnectorDescriptor.Builder enriched = new ConnectorDescriptor.Builder().createFrom(descriptor);
    actionPropertySuggestions.forEach((k, vals) -> enriched.replaceConfigurationProperty(k, b -> b.addAllEnum(vals.stream().map(s -> ConfigurationProperty.PropertyValue.Builder.from(s))::iterator)));
    // Setting the defaultValue as suggested by the metadata
    for (final Entry<String, List<DynamicActionMetadata.ActionPropertySuggestion>> suggestions : actionPropertySuggestions.entrySet()) {
        if (suggestions.getValue().size() == 1) {
            for (final DynamicActionMetadata.ActionPropertySuggestion suggestion : suggestions.getValue()) {
                enriched.replaceConfigurationProperty(suggestion.displayValue(), v -> v.defaultValue(suggestion.value()));
            }
        }
    }
    final DataShape input = dynamicMetadata.inputShape();
    if (shouldEnrichDataShape(descriptor.getInputDataShape(), input)) {
        enriched.inputDataShape(input);
    }
    final DataShape output = dynamicMetadata.outputShape();
    if (shouldEnrichDataShape(descriptor.getOutputDataShape(), output)) {
        enriched.outputDataShape(output);
    }
    return adaptDataShapes(enriched);
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) ApiResponses(io.swagger.annotations.ApiResponses) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Map(java.util.Map) EntityNotFoundException(javax.persistence.EntityNotFoundException) Api(io.swagger.annotations.Api) Status(javax.ws.rs.core.Response.Status) POST(javax.ws.rs.POST) DataShape(io.syndesis.common.model.DataShape) MetadataConfigurationProperties(io.syndesis.server.verifier.MetadataConfigurationProperties) Connector(io.syndesis.common.model.connection.Connector) Collectors(java.util.stream.Collectors) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) Meta(io.syndesis.server.endpoint.v1.dto.Meta) List(java.util.List) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) HystrixExecutable(com.netflix.hystrix.HystrixExecutable) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) Entry(java.util.Map.Entry) Optional(java.util.Optional) ConnectionBase(io.syndesis.common.model.connection.ConnectionBase) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) List(java.util.List) DataShape(io.syndesis.common.model.DataShape)

Aggregations

ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)27 Connector (io.syndesis.common.model.connection.Connector)18 Connection (io.syndesis.common.model.connection.Connection)15 Step (io.syndesis.common.model.integration.Step)12 Action (io.syndesis.common.model.action.Action)11 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)11 StepDefinition (io.syndesis.qe.bdd.entities.StepDefinition)10 AbstractStep (io.syndesis.qe.bdd.AbstractStep)9 Map (java.util.Map)8 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)7 Test (org.junit.Test)7 HystrixInvokableInfo (com.netflix.hystrix.HystrixInvokableInfo)6 Given (cucumber.api.java.en.Given)6 DataShape (io.syndesis.common.model.DataShape)6 Meta (io.syndesis.server.endpoint.v1.dto.Meta)6 HashMap (java.util.HashMap)6 Response (javax.ws.rs.core.Response)6 DynamicActionMetadata (io.syndesis.common.model.connection.DynamicActionMetadata)5 DataShapeKinds (io.syndesis.common.model.DataShapeKinds)4 IOException (java.io.IOException)4