Search in sources :

Example 41 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationRouteBuilder method loadIntegration.

protected Integration loadIntegration() throws IOException {
    final Integration integration;
    try (InputStream is = ResourceHelper.resolveResourceAsInputStream(getContext().getClassResolver(), configurationUri)) {
        if (is != null) {
            LOGGER.info("Loading integration from: {}", configurationUri);
            integration = Json.reader().forType(Integration.class).readValue(is);
        } else {
            throw new IllegalStateException("Unable to load deployment: " + configurationUri);
        }
    }
    return integration;
}
Also used : Integration(io.syndesis.common.model.integration.Integration) InputStream(java.io.InputStream)

Example 42 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class Application method generateIntegrationProject.

private void generateIntegrationProject(File project) throws IOException {
    final ReadApiClientData reader = new ReadApiClientData();
    final ArrayList<Step> steps = new ArrayList<>();
    String deploymentText;
    try (InputStream is = resourceLoader.getResource("io/syndesis/server/dao/deployment.json").getInputStream()) {
        deploymentText = reader.from(is);
    }
    final List<ModelData<?>> modelList = reader.readDataFromString(deploymentText);
    for (final ModelData<?> model : modelList) {
        if (model.getKind() == Kind.Connector) {
            final Connector connector = (Connector) model.getData();
            for (final Action action : connector.getActions()) {
                steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
            }
        }
        if (model.getKind() == Kind.ConnectorTemplate) {
            final ConnectorTemplate template = (ConnectorTemplate) model.getData();
            steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connectorId("connector-" + template.getId()).build()).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().camelConnectorGAV(template.getCamelConnectorGAV()).camelConnectorPrefix(template.getCamelConnectorPrefix()).build()).build()).build());
        }
    }
    try {
        final ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
        final Resource[] resources = resolver.getResources("classpath:/META-INF/syndesis/connector/*.json");
        if (resources != null) {
            for (Resource resource : resources) {
                Connector connector = Json.reader().forType(Connector.class).readValue(resource.getInputStream());
                if (connector != null) {
                    for (final Action action : connector.getActions()) {
                        steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
                    }
                }
            }
        }
    } catch (FileNotFoundException ignored) {
    // ignore
    }
    Integration integration = new Integration.Builder().id("Integration").name("Integration").description("This integration is used to prime the .m2 repo").steps(steps).build();
    generate(integration, project);
}
Also used : ModelData(io.syndesis.common.model.ModelData) Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) Integration(io.syndesis.common.model.integration.Integration) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) Step(io.syndesis.common.model.integration.Step) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData)

Example 43 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationSchedulerTest method integrationSchedulerTest.

@Test
public void integrationSchedulerTest() throws Exception {
    final CamelContext context = new SpringCamelContext(applicationContext);
    try {
        final RouteBuilder routes = new IntegrationRouteBuilder("", Collections.emptyList()) {

            @Override
            protected Integration loadIntegration() throws IOException {
                Integration integration = newIntegration(new Step.Builder().id("step-1").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("log").putConfiguredProperty("loggerName", "timer").build()).build()).build(), new Step.Builder().id("step-2").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("mock").putConfiguredProperty("name", "timer").build()).build()).build());
                return new Integration.Builder().createFrom(integration).scheduler(new Scheduler.Builder().type(Scheduler.Type.timer).expression("1s").build()).build();
            }
        };
        // Set up the camel context
        context.addRoutes(routes);
        context.start();
        dumpRoutes(context);
        RouteDefinition routeDefinition = context.getRouteDefinition("test-integration");
        assertThat(routeDefinition).isNotNull();
        assertThat(routeDefinition).hasFieldOrPropertyWithValue("id", "test-integration");
        assertThat(routeDefinition.getInputs()).hasSize(1);
        assertThat(routeDefinition.getInputs().get(0).getEndpointUri()).isEqualTo("timer:integration?period=1s");
        assertThat(routeDefinition.getOutputs()).hasSize(4);
        assertThat(routeDefinition.getOutputs().get(0)).hasFieldOrPropertyWithValue("endpointUri", "log:timer");
        assertThat(routeDefinition.getOutputs().get(1)).isInstanceOf(ProcessDefinition.class);
        assertThat(routeDefinition.getOutputs().get(2)).hasFieldOrPropertyWithValue("endpointUri", "mock:timer");
        assertThat(routeDefinition.getOutputs().get(3)).isInstanceOf(ProcessDefinition.class);
        assertThat(routeDefinition.getInputs().get(0)).hasFieldOrPropertyWithValue("id", "integration-scheduler");
        assertThat(routeDefinition.getOutputs().get(0)).hasFieldOrPropertyWithValue("id", "step-1");
        assertThat(routeDefinition.getOutputs().get(1)).hasFieldOrPropertyWithValue("id", "step-1-capture");
        assertThat(routeDefinition.getOutputs().get(2)).hasFieldOrPropertyWithValue("id", "step-2");
        assertThat(routeDefinition.getOutputs().get(3)).hasFieldOrPropertyWithValue("id", "step-2-capture");
    } finally {
        context.stop();
    }
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelContext(org.apache.camel.CamelContext) Integration(io.syndesis.common.model.integration.Integration) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(io.syndesis.common.model.integration.Scheduler) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Step(io.syndesis.common.model.integration.Step) RouteDefinition(org.apache.camel.model.RouteDefinition) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 44 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationHandler method update.

@Override
public void update(String id, @ConvertGroup(from = Default.class, to = AllValidations.class) Integration integration) {
    Integration existing = getIntegration(id);
    Integration updatedIntegration = new Integration.Builder().createFrom(encryptionSupport.encrypt(integration)).version(existing.getVersion() + 1).updatedAt(System.currentTimeMillis()).build();
    getDataManager().update(updatedIntegration);
}
Also used : Integration(io.syndesis.common.model.integration.Integration)

Example 45 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationHandler method get.

@Override
public IntegrationOverview get(String id) {
    final DataManager dataManager = getDataManager();
    final Integration integration = dataManager.fetch(Integration.class, id);
    if (integration == null) {
        throw new EntityNotFoundException();
    }
    if (integration.isDeleted()) {
        // Cause that test, is using NoopHandlerProvider, so that means no controllers.
        throw new EntityNotFoundException(String.format("Integration %s has been deleted", integration.getId()));
    }
    return toCurrentIntegrationOverview(integration);
}
Also used : Integration(io.syndesis.common.model.integration.Integration) DataManager(io.syndesis.server.dao.manager.DataManager) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Aggregations

Integration (io.syndesis.common.model.integration.Integration)57 Test (org.junit.Test)19 Step (io.syndesis.common.model.integration.Step)17 List (java.util.List)16 Connection (io.syndesis.common.model.connection.Connection)15 Connector (io.syndesis.common.model.connection.Connector)11 DataManager (io.syndesis.server.dao.manager.DataManager)11 IOException (java.io.IOException)11 Set (java.util.Set)10 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)9 Collectors (java.util.stream.Collectors)9 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)8 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)7 Map (java.util.Map)7 Action (io.syndesis.common.model.action.Action)6 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)6 StepKind (io.syndesis.common.model.integration.StepKind)6