use of io.syndesis.common.model.connection.Connection 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));
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class ProjectGeneratorHelper method sanitize.
public static Integration sanitize(Integration integration, IntegrationResourceManager resourceManager) {
final List<Step> steps = new ArrayList<>(integration.getSteps());
if (steps.isEmpty()) {
return integration;
}
for (int i = 0; i < steps.size(); i++) {
final Step source = steps.get(i);
if (source.getConnection().isPresent()) {
final Connection connection = source.getConnection().get();
// If connector is not set, fetch it from data source and update connection
if (!connection.getConnector().isPresent()) {
Connector connector = resourceManager.loadConnector(connection.getConnectorId()).orElseThrow(() -> new IllegalArgumentException("Unable to fetch connector: " + connection.getConnectorId()));
// Add missing connector to connection.
Connection newConnection = new Connection.Builder().createFrom(connection).connector(connector).build();
// Replace with the new 'sanitized' step
steps.set(i, new Step.Builder().createFrom(source).connection(newConnection).build());
}
}
}
final Integration.Builder builder = new Integration.Builder().createFrom(integration);
// is fully implemented and schedule options are set on integration.
if (!integration.getScheduler().isPresent()) {
Map<String, String> properties = new HashMap<>(steps.get(0).getConfiguredProperties());
String type = properties.remove("schedulerType");
String expr = properties.remove("schedulerExpression");
if (StringUtils.isNotEmpty(expr)) {
if (StringUtils.isEmpty(type)) {
type = "timer";
}
builder.scheduler(new Scheduler.Builder().type(Scheduler.Type.valueOf(type)).expression(expr).build());
}
// Replace first step so underlying connector won't fail uri param
// validation if schedule options were set.
steps.set(0, new Step.Builder().createFrom(steps.get(0)).configuredProperties(properties).build());
}
return builder.steps(steps).build();
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class ProjectGeneratorHelperTest method testSanitizeScheduler.
@Test
public void testSanitizeScheduler() {
TestResourceManager resourceManager = new TestResourceManager();
Integration source = resourceManager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("timer-connection").connector(TestConstants.HTTP_CONNECTOR).build()).putConfiguredProperty("schedulerType", "timer").putConfiguredProperty("schedulerExpression", "1s").action(TestConstants.HTTP_GET_ACTION).build());
assertThat(source.getScheduler().isPresent()).isFalse();
Integration sanitized = ProjectGeneratorHelper.sanitize(source, resourceManager);
assertThat(sanitized.getScheduler().isPresent()).isTrue();
assertThat(sanitized.getScheduler().get()).hasFieldOrPropertyWithValue("type", Scheduler.Type.timer);
assertThat(sanitized.getScheduler().get()).hasFieldOrPropertyWithValue("expression", "1s");
assertThat(sanitized.getSteps().get(0).getStepKind()).isEqualTo(StepKind.endpoint);
assertThat(sanitized.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-type");
assertThat(sanitized.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-expression");
}
use of io.syndesis.common.model.connection.Connection 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);
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class IntegrationHandler method toCurrentConnection.
public Connection toCurrentConnection(Connection c) {
final DataManager dataManager = getDataManager();
final Connection connection = dataManager.fetch(Connection.class, c.getId().get());
final Connector connector = dataManager.fetch(Connector.class, connection.getConnectorId());
return new Connection.Builder().createFrom(connection).connector(connector).build();
}
Aggregations