Search in sources :

Example 16 with Integration

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

the class ReadApiClientDataTest method deserializeModelDataTest.

@Test
public void deserializeModelDataTest() throws IOException {
    Integration integrationIn = new Integration.Builder().tags(new TreeSet<>(Arrays.asList("tag1", "tag2"))).createdAt(System.currentTimeMillis()).build();
    String integrationJson = Json.writer().writeValueAsString(integrationIn);
    Integration integrationOut = Json.reader().forType(Integration.class).readValue(integrationJson);
    // serialize
    ConnectorGroup cg = new ConnectorGroup.Builder().id("label").name("label").build();
    ModelData<ConnectorGroup> mdIn = new ModelData<>(Kind.ConnectorGroup, cg);
    Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdIn.getDataAsJson());
    // deserialize
    String json = Json.writer().writeValueAsString(mdIn);
    ModelData<?> mdOut = Json.reader().forType(ModelData.class).readValue(json);
    Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdOut.getDataAsJson());
}
Also used : ModelData(io.syndesis.common.model.ModelData) Integration(io.syndesis.common.model.integration.Integration) ConnectorGroup(io.syndesis.common.model.connection.ConnectorGroup) Test(org.junit.Test)

Example 17 with Integration

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

the class EventsITCase method wsEventsWithToken.

@Test
public void wsEventsWithToken() throws Exception {
    OkHttpClient client = new OkHttpClient();
    ResponseEntity<EventMessage> r1 = post("/api/v1/event/reservations", null, EventMessage.class);
    assertThat(r1.getBody().getEvent().get()).as("event").isEqualTo("uuid");
    String uuid = (String) r1.getBody().getData().get();
    assertThat(uuid).as("data").isNotNull();
    String uriTemplate = EventBusToWebSocket.DEFAULT_PATH + "/" + uuid;
    String url = resolveURI(uriTemplate).toString().replaceFirst("^http", "ws");
    Request request = new Request.Builder().url(url).addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + tokenRule.validToken()).build();
    // lets setup an event handler that we can inspect events on..
    WebSocketListener listener = recorder(mock(WebSocketListener.class), WebSocketListener.class);
    List<Recordings.Invocation> invocations = recordedInvocations(listener);
    CountDownLatch countDownLatch = resetRecorderLatch(listener, 2);
    WebSocket ws = client.newWebSocket(request, listener);
    // We auto get a message letting us know we connected.
    assertThat(countDownLatch.await(1000, TimeUnit.SECONDS)).isTrue();
    assertThat(invocations.get(0).getMethod().getName()).isEqualTo("onOpen");
    assertThat(invocations.get(1).getMethod().getName()).isEqualTo("onMessage");
    assertThat(invocations.get(1).getArgs()[1]).isEqualTo(EventMessage.of("message", "connected").toJson());
    // ///////////////////////////////////////////////////
    // Test that we get notified of created entities
    // ///////////////////////////////////////////////////
    invocations.clear();
    countDownLatch = resetRecorderLatch(listener, 1);
    Integration integration = new Integration.Builder().id("1002").name("test").build();
    post("/api/v1/integrations", integration, Integration.class);
    assertThat(countDownLatch.await(1000, TimeUnit.SECONDS)).isTrue();
    assertThat(invocations.get(0).getMethod().getName()).isEqualTo("onMessage");
    assertThat(invocations.get(0).getArgs()[1]).isEqualTo(EventMessage.of("change-event", ChangeEvent.of("created", "integration", "1002").toJson()).toJson());
    ws.close(1000, "closing");
}
Also used : WebSocketListener(okhttp3.WebSocketListener) Integration(io.syndesis.common.model.integration.Integration) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocket(okhttp3.WebSocket) EventMessage(io.syndesis.common.model.EventMessage) Test(org.junit.Test)

Example 18 with Integration

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

the class EventsITCase method sseEventsWithToken.

@Test
public void sseEventsWithToken() throws Exception {
    ResponseEntity<EventMessage> r1 = post("/api/v1/event/reservations", null, EventMessage.class);
    assertThat(r1.getBody().getEvent().get()).as("event").isEqualTo("uuid");
    String uuid = (String) r1.getBody().getData().get();
    assertThat(uuid).as("data").isNotNull();
    URI uri = resolveURI(EventBusToServerSentEvents.DEFAULT_PATH + "/" + uuid);
    // lets setup an event handler that we can inspect events on..
    EventHandler handler = recorder(mock(EventHandler.class), EventHandler.class);
    List<Recordings.Invocation> invocations = recordedInvocations(handler);
    CountDownLatch countDownLatch = resetRecorderLatch(handler, 2);
    try (EventSource eventSource = new EventSource.Builder(handler, uri).build()) {
        eventSource.start();
        assertThat(countDownLatch.await(1000, TimeUnit.SECONDS)).isTrue();
        // workaround issues in EventSource
        reorderEventSourceInvocations(invocations);
        assertThat(invocations.get(0).getMethod().getName()).isEqualTo("onOpen");
        // We auto get a message letting us know we connected.
        assertThat(invocations.get(1).getMethod().getName()).isEqualTo("onMessage");
        assertThat(invocations.get(1).getArgs()[0]).isEqualTo("message");
        assertThat(((MessageEvent) invocations.get(1).getArgs()[1]).getData()).isEqualTo("connected");
        // ///////////////////////////////////////////////////
        // Test that we get notified of created entities
        // ///////////////////////////////////////////////////
        invocations.clear();
        countDownLatch = resetRecorderLatch(handler, 1);
        Integration integration = new Integration.Builder().id("1001").name("test").build();
        post("/api/v1/integrations", integration, Integration.class);
        assertThat(countDownLatch.await(1000, TimeUnit.SECONDS)).isTrue();
        assertThat(invocations.get(0).getArgs()[0]).isEqualTo("change-event");
        assertThat(((MessageEvent) invocations.get(0).getArgs()[1]).getData()).isEqualTo(ChangeEvent.of("created", "integration", "1001").toJson());
    }
}
Also used : Integration(io.syndesis.common.model.integration.Integration) MessageEvent(com.launchdarkly.eventsource.MessageEvent) EventHandler(com.launchdarkly.eventsource.EventHandler) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) EventSource(com.launchdarkly.eventsource.EventSource) EventMessage(io.syndesis.common.model.EventMessage) Test(org.junit.Test)

Example 19 with Integration

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

the class IntegrationUpdateHandler method compute.

@SuppressWarnings({ "PMD.ExcessiveMethodLength", "PMD.NPathComplexity" })
@Override
protected List<IntegrationBulletinBoard> compute(ChangeEvent event) {
    final List<IntegrationBulletinBoard> boards = new ArrayList<>();
    final DataManager dataManager = getDataManager();
    final List<Integration> integrations = dataManager.fetchAll(Integration.class).getItems();
    final List<LeveledMessage> messages = new ArrayList<>();
    for (int i = 0; i < integrations.size(); i++) {
        final Integration integration = integrations.get(i);
        final List<Step> steps = integration.getSteps();
        final String id = integration.getId().get();
        final IntegrationBulletinBoard board = dataManager.fetchByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id).orElse(null);
        final IntegrationBulletinBoard.Builder builder;
        if (board != null) {
            builder = new IntegrationBulletinBoard.Builder().createFrom(board).updatedAt(System.currentTimeMillis());
        } else {
            builder = new IntegrationBulletinBoard.Builder().id(KeyGenerator.createKey()).targetResourceId(id).createdAt(System.currentTimeMillis());
        }
        // reuse messages
        messages.clear();
        // to the resources the properties apply to
        for (int s = 0; s < steps.size(); s++) {
            final int index = s;
            final Step step = steps.get(s);
            final Supplier<LeveledMessage.Builder> supplier = () -> new LeveledMessage.Builder().putMetadata("step", step.getId().orElse("step-" + index));
            if (!step.getAction().isPresent()) {
                continue;
            }
            // **********************
            // Integration
            // **********************
            messages.addAll(computeValidatorMessages(supplier, integration));
            // **********************
            // Extension
            // **********************
            step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> {
                Extension extension = step.getExtension().orElse(null);
                if (extension == null) {
                    return;
                }
                // When an extension is updated a new entity is written to the db
                // so we can't simply lookup by ID but whe need to search for the
                // latest installed extension.
                // 
                // This fetchIdsByPropertyValue is not really optimized as it
                // ends up in multiple statements sent to the db, we maybe need
                // to have a better support for this use-case.
                Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name());
                if (ids.size() != 1) {
                    return;
                }
                Extension newExtension = dataManager.fetch(Extension.class, ids.iterator().next());
                if (newExtension == null) {
                    messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS004).build());
                } else {
                    Action newAction = newExtension.findActionById(action.getId().get()).orElse(null);
                    if (newAction == null) {
                        messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS005).build());
                    } else {
                        messages.addAll(computePropertiesDiffMessages(supplier, action.getProperties(), newAction.getProperties()));
                        messages.addAll(computeMissingMandatoryPropertiesMessages(supplier, newAction.getProperties(), step.getConfiguredProperties()));
                        messages.addAll(computeSecretsUpdateMessages(supplier, newAction.getProperties(), step.getConfiguredProperties()));
                    }
                }
            });
            // **********************
            // Connector
            // **********************
            step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).ifPresent(action -> {
                Connection connection = step.getConnection().orElse(null);
                if (connection == null) {
                    return;
                }
                Connector newConnector = dataManager.fetch(Connector.class, connection.getConnectorId());
                if (newConnector == null) {
                    messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS003).build());
                } else {
                    Action newAction = newConnector.findActionById(action.getId().get()).orElse(null);
                    if (newAction == null) {
                        messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS005).build());
                    } else {
                        Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
                        messages.addAll(computeValidatorMessages(supplier, connection));
                        messages.addAll(computePropertiesDiffMessages(supplier, action.getProperties(), newAction.getProperties()));
                        messages.addAll(computeMissingMandatoryPropertiesMessages(supplier, newAction.getProperties(), configuredProperties));
                        messages.addAll(computeSecretsUpdateMessages(supplier, newAction.getProperties(), configuredProperties));
                    }
                }
            });
        }
        builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages));
        builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages));
        builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages));
        builder.putMetadata("integration-id", id);
        builder.putMetadata("integration-version", Integer.toString(integration.getVersion()));
        builder.messages(messages);
        boards.add(builder.build());
    }
    return boards;
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) StepAction(io.syndesis.common.model.action.StepAction) IntegrationBulletinBoard(io.syndesis.common.model.bulletin.IntegrationBulletinBoard) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager) Step(io.syndesis.common.model.integration.Step) Extension(io.syndesis.common.model.extension.Extension) StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Example 20 with Integration

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

the class IntegrationsITCase method shouldDetermineValidityForValidIntegrations.

@Test
public void shouldDetermineValidityForValidIntegrations() {
    final Integration integration = new Integration.Builder().name("Test integration").build();
    final ResponseEntity<List<Violation>> got = post("/api/v1/integrations/validation", integration, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    assertThat(got.getBody()).isNull();
}
Also used : Integration(io.syndesis.common.model.integration.Integration) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

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