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());
}
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");
}
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());
}
}
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;
}
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();
}
Aggregations