Search in sources :

Example 1 with ChangeEvent

use of io.syndesis.common.model.ChangeEvent in project syndesis by syndesisio.

the class ResourceUpdateController method run.

private void run() {
    for (int h = 0; h < handlers.size(); h++) {
        ResourceUpdateHandler handler = handlers.get(h);
        for (int i = 0; i < allEvents.size(); i++) {
            ChangeEvent event = allEvents.get(i);
            if (handler.canHandle(event)) {
                LOGGER.debug("Trigger handler {}", handler);
                handler.process(event);
                // to trigger the handler multiple time.
                break;
            }
        }
    }
}
Also used : ChangeEvent(io.syndesis.common.model.ChangeEvent)

Example 2 with ChangeEvent

use of io.syndesis.common.model.ChangeEvent in project syndesis by syndesisio.

the class IntegrationSupportHandler method importIntegration.

@POST
@Path("/import")
@Produces(MediaType.APPLICATION_JSON)
public List<ChangeEvent> importIntegration(@Context SecurityContext sec, InputStream is) {
    try (ZipInputStream zis = new ZipInputStream(is)) {
        HashSet<String> extensionIds = new HashSet<>();
        ArrayList<ChangeEvent> changeEvents = new ArrayList<>();
        ModelExport modelExport = null;
        while (true) {
            ZipEntry entry = zis.getNextEntry();
            if (entry == null) {
                break;
            }
            if (EXPORT_MODEL_INFO_FILE_NAME.equals(entry.getName())) {
                modelExport = Json.reader().forType(ModelExport.class).readValue(zis);
            }
            if (EXPORT_MODEL_FILE_NAME.equals(entry.getName())) {
                CloseableJsonDB memJsonDB = MemorySqlJsonDB.create(jsonDB.getIndexes());
                memJsonDB.set("/", nonClosing(zis));
                changeEvents.addAll(importModels(sec, modelExport, memJsonDB));
                memJsonDB.close();
                for (ChangeEvent changeEvent : changeEvents) {
                    if (changeEvent.getKind().get().equals("extension")) {
                        extensionIds.add(changeEvent.getId().get());
                    }
                }
            }
            // import missing extensions that were in the model.
            if (entry.getName().startsWith("extensions/")) {
                for (String extensionId : extensionIds) {
                    if (entry.getName().equals("extensions/" + Names.sanitize(extensionId) + ".jar")) {
                        String path = "/extensions/" + extensionId;
                        InputStream existing = extensionDataManager.getExtensionDataAccess().read(path);
                        if (existing == null) {
                            extensionDataManager.getExtensionDataAccess().write(path, zis);
                        } else {
                            existing.close();
                        }
                    }
                }
            }
            zis.closeEntry();
        }
        if (changeEvents.isEmpty()) {
            LOG.info("Could not import integration: No integration data model found.");
            throw new ClientErrorException("Does not look like an integration export.", Response.Status.BAD_REQUEST);
        }
        return changeEvents;
    } catch (IOException e) {
        if (LOG.isInfoEnabled()) {
            LOG.info("Could not import integration: " + e, e);
        }
        throw new ClientErrorException("Could not import integration: " + e, Response.Status.BAD_REQUEST, e);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) CloseableJsonDB(io.syndesis.server.jsondb.CloseableJsonDB) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) ChangeEvent(io.syndesis.common.model.ChangeEvent) ClientErrorException(javax.ws.rs.ClientErrorException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ModelExport(io.syndesis.common.model.ModelExport) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 3 with ChangeEvent

use of io.syndesis.common.model.ChangeEvent 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)

Aggregations

ChangeEvent (io.syndesis.common.model.ChangeEvent)3 ArrayList (java.util.ArrayList)2 Kind (io.syndesis.common.model.Kind)1 ModelExport (io.syndesis.common.model.ModelExport)1 ConnectionBulletinBoard (io.syndesis.common.model.bulletin.ConnectionBulletinBoard)1 LeveledMessage (io.syndesis.common.model.bulletin.LeveledMessage)1 Connection (io.syndesis.common.model.connection.Connection)1 Connector (io.syndesis.common.model.connection.Connector)1 KeyGenerator (io.syndesis.common.util.KeyGenerator)1 DataManager (io.syndesis.server.dao.manager.DataManager)1 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)1 CloseableJsonDB (io.syndesis.server.jsondb.CloseableJsonDB)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1