Search in sources :

Example 11 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class ExtensionDataManagerTest method shouldGetCorrectDataByExtensionId.

@Test
public void shouldGetCorrectDataByExtensionId() throws IOException {
    final DataManager dataManager = mock(DataManager.class);
    final FileDAO extensionDataAccess = mock(FileDAO.class);
    final FileDataManager extensionDataManager = new FileDataManager(dataManager, extensionDataAccess);
    String sampleBinaryData = "Hello";
    Extension sampleMetadata = new Extension.Builder().id("1234").status(Extension.Status.Installed).extensionId("extensionId").description("Description").build();
    when(extensionDataAccess.read("/extensions/1234")).thenReturn(new ByteArrayInputStream(sampleBinaryData.getBytes(StandardCharsets.UTF_8)));
    when(dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", "extensionId", "status", Extension.Status.Installed.name())).thenReturn(Collections.singleton("1234"));
    when(dataManager.fetch(Extension.class, "1234")).thenReturn(sampleMetadata);
    assertThat(extensionDataManager.getExtensionMetadata("extensionId")).isEqualTo(sampleMetadata);
    assertThat(IOUtils.toString(extensionDataManager.getExtensionBinaryFile("extensionId"), StandardCharsets.UTF_8)).isEqualTo(sampleBinaryData);
}
Also used : Extension(io.syndesis.common.model.extension.Extension) ByteArrayInputStream(java.io.ByteArrayInputStream) DataManager(io.syndesis.server.dao.manager.DataManager) Test(org.junit.Test)

Example 12 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class MetricsCollectorTest method before.

@Before
public void before() throws IOException, ParseException {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
    DBI dbi = new DBI(ds);
    this.jsondb = new SqlJsonDB(dbi, null, Arrays.asList(new Index("/pair", "key")));
    try {
        this.jsondb.dropTables();
    } catch (Exception e) {
    }
    this.jsondb.createTables();
    jsondbRM = new JsonDBRawMetrics(jsondb);
    load();
    CacheManager cacheManager = new LRUCacheManager(100);
    EncryptionComponent encryptionComponent = new EncryptionComponent(null);
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    // Create Data Manager
    dataManager = new DataManager(cacheManager, Collections.emptyList(), null, encryptionComponent, resourceLoader);
    intMH = new IntegrationMetricsHandler(dataManager);
}
Also used : DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DBI(org.skife.jdbi.v2.DBI) Index(io.syndesis.server.jsondb.impl.Index) DataManager(io.syndesis.server.dao.manager.DataManager) ParseException(java.text.ParseException) IOException(java.io.IOException) SqlJsonDB(io.syndesis.server.jsondb.impl.SqlJsonDB) LRUCacheManager(io.syndesis.common.util.cache.LRUCacheManager) CacheManager(io.syndesis.common.util.cache.CacheManager) LRUCacheManager(io.syndesis.common.util.cache.LRUCacheManager) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Before(org.junit.Before)

Example 13 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class ConnectionUpdateHandler method compute.

@Override
protected List<ConnectionBulletinBoard> compute(ChangeEvent event) {
    final List<ConnectionBulletinBoard> boards = new ArrayList<>();
    final DataManager dataManager = getDataManager();
    final List<Connector> connectors = dataManager.fetchAll(Connector.class).getItems();
    for (int i = 0; i < connectors.size(); i++) {
        final Connector connector = connectors.get(i);
        final String id = connector.getId().get();
        dataManager.fetchAllByPropertyValue(Connection.class, "connectorId", id).filter(connection -> connection.getConnector().isPresent()).map(connection -> computeBoard(connection, connection.getConnector().get(), connector)).forEach(boards::add);
    }
    return boards;
}
Also used : LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage) Arrays(java.util.Arrays) KeyGenerator(io.syndesis.common.util.KeyGenerator) Kind(io.syndesis.common.model.Kind) Validator(javax.validation.Validator) Connector(io.syndesis.common.model.connection.Connector) ArrayList(java.util.ArrayList) List(java.util.List) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Connection(io.syndesis.common.model.connection.Connection) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard) DataManager(io.syndesis.server.dao.manager.DataManager) ChangeEvent(io.syndesis.common.model.ChangeEvent) Connector(io.syndesis.common.model.connection.Connector) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard)

Example 14 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class ConnectionUpdateHandler method computeBoard.

private ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) {
    final DataManager dataManager = getDataManager();
    final String id = connection.getId().get();
    final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null);
    final ConnectionBulletinBoard.Builder builder;
    if (board != null) {
        builder = new ConnectionBulletinBoard.Builder().createFrom(board).updatedAt(System.currentTimeMillis());
    } else {
        builder = new ConnectionBulletinBoard.Builder().id(KeyGenerator.createKey()).targetResourceId(id).createdAt(System.currentTimeMillis());
    }
    List<LeveledMessage> messages = new ArrayList<>();
    messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection));
    messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties()));
    messages.addAll(computeMissingMandatoryPropertiesMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties()));
    messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties()));
    builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages));
    builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages));
    builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages));
    builder.putMetadata("connector-id", newConnector.getId().get());
    builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion()));
    builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion()));
    builder.messages(messages);
    return builder.build();
}
Also used : ArrayList(java.util.ArrayList) DataManager(io.syndesis.server.dao.manager.DataManager) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Example 15 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class CredentialProviderRegistryTest method shouldComplainAboutUnregisteredProviders.

@Test(expected = IllegalArgumentException.class)
public void shouldComplainAboutUnregisteredProviders() {
    final DataManager dataManager = mock(DataManager.class);
    final CredentialProviderRegistry registry = new CredentialProviderRegistry(dataManager);
    registry.providerWithId("unregistered");
}
Also used : DataManager(io.syndesis.server.dao.manager.DataManager) Test(org.junit.Test)

Aggregations

DataManager (io.syndesis.server.dao.manager.DataManager)15 Connector (io.syndesis.common.model.connection.Connector)6 Connection (io.syndesis.common.model.connection.Connection)5 ConnectionBulletinBoard (io.syndesis.common.model.bulletin.ConnectionBulletinBoard)4 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)4 ArrayList (java.util.ArrayList)4 LeveledMessage (io.syndesis.common.model.bulletin.LeveledMessage)3 Integration (io.syndesis.common.model.integration.Integration)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 Before (org.junit.Before)3 Test (org.junit.Test)3 IntegrationBulletinBoard (io.syndesis.common.model.bulletin.IntegrationBulletinBoard)2 ConnectionOverview (io.syndesis.common.model.connection.ConnectionOverview)2 Extension (io.syndesis.common.model.extension.Extension)2 LRUCacheManager (io.syndesis.common.util.cache.LRUCacheManager)2 Validator (javax.validation.Validator)2 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)2 ResourceLoader (org.springframework.core.io.ResourceLoader)2 ChangeEvent (io.syndesis.common.model.ChangeEvent)1 Kind (io.syndesis.common.model.Kind)1