Search in sources :

Example 71 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class ProjectGeneratorTest method testGenerateApplicationProperties.

@Test
public void testGenerateApplicationProperties() throws IOException {
    // ******************
    // NEW STYLE
    // ******************
    final ConnectorAction newAction = new ConnectorAction.Builder().id(KeyGenerator.createKey()).descriptor(new ConnectorDescriptor.Builder().connectorId("new").componentScheme("http4").build()).build();
    final Connector newConnector = new Connector.Builder().id("new").addAction(newAction).putProperty("username", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("password", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("token", new ConfigurationProperty.Builder().componentProperty(true).secret(true).build()).build();
    // ******************
    // Integration
    // ******************
    Step s1 = new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id(KeyGenerator.createKey()).connector(newConnector).build()).putConfiguredProperty("username", "my-username-2").putConfiguredProperty("password", "my-password-2").putConfiguredProperty("token", "my-token-2").action(newAction).build();
    TestResourceManager resourceManager = new TestResourceManager();
    ProjectGeneratorConfiguration configuration = new ProjectGeneratorConfiguration();
    ProjectGenerator generator = new ProjectGenerator(configuration, resourceManager, TestConstants.MAVEN_PROPERTIES);
    Integration integration = new Integration.Builder().createFrom(resourceManager.newIntegration(s1)).putConfiguredProperty("integration", "property").build();
    Properties properties = generator.generateApplicationProperties(integration);
    assertThat(properties).containsOnly(entry("integration", "property"), entry("flow-0.http4-0.token", "my-token-2"), entry("flow-0.http4-0.username", "my-username-2"), entry("flow-0.http4-0.password", "my-password-2"));
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) Properties(java.util.Properties) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 72 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class ProjectGeneratorTest method testDependencyCollection.

// *****************************
// Helpers
// *****************************
// ***************************
// Tests
// ***************************
@Test
public void testDependencyCollection() throws Exception {
    TestResourceManager resourceManager = new TestResourceManager();
    Integration integration = resourceManager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("timer-connection").connector(TestConstants.TIMER_CONNECTOR).build()).putConfiguredProperty("period", "5000").action(TestConstants.PERIODIC_TIMER_ACTION).build(), new Step.Builder().stepKind(StepKind.mapper).putConfiguredProperty("atlasmapping", "{}").build(), new Step.Builder().stepKind(StepKind.ruleFilter).putConfiguredProperty("predicate", "AND").putConfiguredProperty("rules", "[{ \"path\": \"in.header.counter\", \"op\": \">\", \"value\": \"10\" }]").addDependency(Dependency.maven("org.myStep:someLib1:1.0")).addDependency(Dependency.maven("org.myStep:someLib2:1.0")).addDependency(Dependency.maven("org.myStep:someLib3:1.0")).build(), new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("http-connection").connector(TestConstants.HTTP_CONNECTOR).build()).putConfiguredProperty("httpUri", "http://localhost:8080/hello").putConfiguredProperty("username", "admin").putConfiguredProperty("password", "admin").putConfiguredProperty("token", "mytoken").action(TestConstants.HTTP_GET_ACTION).build());
    Collection<Dependency> dependencies = resourceManager.collectDependencies(integration);
    /*
         * Should return
         * - 3 step dependencies from the rule filter step
         */
    assertEquals(3, dependencies.size());
}
Also used : Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) Dependency(io.syndesis.common.model.Dependency) Test(org.junit.Test)

Example 73 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class IntegrationResourceManager method collectDependencies.

default Collection<Dependency> collectDependencies(Collection<? extends Step> steps, boolean resolveExtensionTags) {
    final List<Dependency> dependencies = new ArrayList<>();
    for (Step step : steps) {
        dependencies.addAll(step.getDependencies());
        step.getAction().filter(WithDependencies.class::isInstance).map(WithDependencies.class::cast).map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
        List<Dependency> connectorDependencies = step.getConnection().flatMap(Connection::getConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
        dependencies.addAll(connectorDependencies);
        List<Dependency> lookedUpConnectorDependencies = step.getConnection().filter(c -> !c.getConnector().isPresent()).map(Connection::getConnectorId).flatMap(this::loadConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
        dependencies.addAll(lookedUpConnectorDependencies);
        // Custom Icon
        step.getConnection().flatMap(ConnectionBase::getConnector).flatMap(ctr -> Optional.ofNullable(ctr.getIcon())).filter(icon -> icon.startsWith("db:")).ifPresent(icon -> dependencies.add(Dependency.from(Dependency.Type.ICON, icon)));
        // Connector extension
        Stream.concat(connectorDependencies.stream(), lookedUpConnectorDependencies.stream()).filter(Dependency::isExtension).map(Dependency::getId).map(this::loadExtension).filter(Optional::isPresent).map(Optional::get).map(Extension::getDependencies).forEach(dependencies::addAll);
        // Step extension
        step.getExtension().map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
        step.getExtension().map(Extension::getExtensionId).map(Dependency::extension).ifPresent(dependencies::add);
    }
    if (resolveExtensionTags) {
        return dependencies.stream().flatMap(dep -> {
            if (dep.isExtensionTag()) {
                List<Extension> extensions = this.loadExtensionsByTag(dep.getId());
                Stream<Dependency> extensionDependency = extensions.stream().map(ext -> Dependency.extension(ext.getExtensionId()));
                Stream<Dependency> transitive = extensions.stream().map(Extension::getDependencies).flatMap(Collection::stream);
                return Stream.concat(extensionDependency, transitive);
            } else {
                return Stream.of(dep);
            }
        }).collect(Collectors.toCollection(ArrayList::new));
    } else {
        return dependencies;
    }
}
Also used : TemplateStepLanguage(io.syndesis.common.model.integration.step.template.TemplateStepLanguage) OpenApi(io.syndesis.common.model.openapi.OpenApi) ListIterator(java.util.ListIterator) Step(io.syndesis.common.model.integration.Step) Scheduler(io.syndesis.common.model.integration.Scheduler) HashMap(java.util.HashMap) Names(io.syndesis.common.util.Names) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Integration(io.syndesis.common.model.integration.Integration) SuppressFBWarnings(io.syndesis.common.util.SuppressFBWarnings) Collection(java.util.Collection) Connector(io.syndesis.common.model.connection.Connector) Extension(io.syndesis.common.model.extension.Extension) WithDependencies(io.syndesis.common.model.WithDependencies) Collectors(java.util.stream.Collectors) Flow(io.syndesis.common.model.integration.Flow) Dependency(io.syndesis.common.model.Dependency) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Collections(java.util.Collections) ConnectionBase(io.syndesis.common.model.connection.ConnectionBase) InputStream(java.io.InputStream) Extension(io.syndesis.common.model.extension.Extension) WithDependencies(io.syndesis.common.model.WithDependencies) Optional(java.util.Optional) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) Dependency(io.syndesis.common.model.Dependency) Step(io.syndesis.common.model.integration.Step)

Example 74 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class IntegrationResourceManagerTest method testSanitizeScheduler.

@Test
public void testSanitizeScheduler() {
    Integration source = newIntegration(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("timer-connection").connector(getHttpConnector()).build()).putConfiguredProperty("schedulerType", "timer").putConfiguredProperty("schedulerExpression", "1s").action(getHttpGetAction()).build());
    assertThat(source.getFlows().get(0).getScheduler().isPresent()).isFalse();
    Integration sanitized = resourceManager.sanitize(source);
    final Flow sanitizedFlow = sanitized.getFlows().get(0);
    assertThat(sanitizedFlow.getScheduler().isPresent()).isTrue();
    assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("type", Scheduler.Type.timer);
    assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("expression", "1s");
    assertThat(sanitizedFlow.getSteps().get(0).getStepKind()).isEqualTo(StepKind.endpoint);
    assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-type");
    assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-expression");
}
Also used : Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) Flow(io.syndesis.common.model.integration.Flow) Test(org.junit.Test)

Example 75 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class KnativeCustomizerTest method testKnativeCustomizerEndpoints.

@Test
public void testKnativeCustomizerEndpoints() throws IOException {
    Connector connector;
    ConnectorAction sinkAction;
    ConnectorAction sourceAction;
    try (InputStream is = KnativeCustomizerTest.class.getResourceAsStream("/META-INF/syndesis/connector/knative.json")) {
        connector = JsonUtils.readFromStream(is, Connector.class);
        sinkAction = connector.getActions(ConnectorAction.class).stream().filter(a -> a.getId().get().equals("io.syndesis:knative-endpoint-call-connector")).findFirst().orElseThrow(() -> new IllegalArgumentException());
        sourceAction = connector.getActions(ConnectorAction.class).stream().filter(a -> a.getId().get().equals("io.syndesis:knative-endpoint-expose-connector")).findFirst().orElseThrow(() -> new IllegalArgumentException());
    }
    TestResourceManager manager = new TestResourceManager();
    Integration integration = manager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).putConfiguredProperty("name", "my-endpoint-sink").action(sinkAction).connection(new Connection.Builder().connector(connector).build()).build(), new Step.Builder().stepKind(StepKind.endpoint).putConfiguredProperty("name", "my-endpoint-source").action(sourceAction).connection(new Connection.Builder().connector(connector).build()).build());
    IntegrationDeployment deployment = new IntegrationDeployment.Builder().userId("user").id("idId").spec(integration).build();
    CamelKIntegrationCustomizer customizer = new KnativeCustomizer();
    io.syndesis.server.controller.integration.camelk.crd.Integration i = customizer.customize(deployment, new io.syndesis.server.controller.integration.camelk.crd.Integration(), EnumSet.of(Exposure.SERVICE));
    assertThat(i.getSpec().getTraits()).containsKey("knative");
    assertThat(i.getSpec().getTraits().get("knative").getConfiguration()).containsOnly(entry("enabled", "true"), entry("channel-sources", ""), entry("channel-sinks", ""), entry("endpoint-sources", "default"), entry("endpoint-sinks", "my-endpoint-sink"));
}
Also used : ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step) TestResourceManager(io.syndesis.server.controller.integration.camelk.TestResourceManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Connector(io.syndesis.common.model.connection.Connector) IOException(java.io.IOException) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) JsonUtils(io.syndesis.common.util.json.JsonUtils) Connection(io.syndesis.common.model.connection.Connection) Exposure(io.syndesis.server.openshift.Exposure) StepKind(io.syndesis.common.model.integration.StepKind) Integration(io.syndesis.common.model.integration.Integration) EnumSet(java.util.EnumSet) InputStream(java.io.InputStream) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) InputStream(java.io.InputStream) Connection(io.syndesis.common.model.connection.Connection) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) TestResourceManager(io.syndesis.server.controller.integration.camelk.TestResourceManager) Test(org.junit.Test)

Aggregations

Connection (io.syndesis.common.model.connection.Connection)111 Connector (io.syndesis.common.model.connection.Connector)65 Test (org.junit.Test)48 Step (io.syndesis.common.model.integration.Step)40 Integration (io.syndesis.common.model.integration.Integration)38 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)26 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)26 List (java.util.List)24 HashMap (java.util.HashMap)21 Action (io.syndesis.common.model.action.Action)18 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)18 ArrayList (java.util.ArrayList)17 Map (java.util.Map)16 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)13 StepDefinition (io.syndesis.qe.bdd.entities.StepDefinition)12 DataManager (io.syndesis.server.dao.manager.DataManager)11 Given (cucumber.api.java.en.Given)10 Flow (io.syndesis.common.model.integration.Flow)10