Search in sources :

Example 6 with Extension

use of io.syndesis.common.model.extension.Extension 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 7 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class GenerateMetadataMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    tryImportingPartialJSON();
    processAnnotations();
    overrideConfigFromMavenPlugin();
    includeDependencies();
    addIcon();
    generateAtlasMapInspections();
    detectExtensionType();
    Extension extension = extensionBuilder.actions(actions.values()).build();
    saveExtensionMetaData(extension);
}
Also used : Extension(io.syndesis.common.model.extension.Extension)

Example 8 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class GenerateMetadataMojo method overrideConfigFromMavenPlugin.

@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.NPathComplexity", "PMD.StdCyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity" })
protected void overrideConfigFromMavenPlugin() {
    getLog().info("Looking for configuration to override at Maven Plugin configuration level. ");
    Extension fragment = extensionBuilder.build();
    if (StringUtils.isNotEmpty(extensionId)) {
        extensionBuilder.extensionId(extensionId);
    } else if (StringUtils.isEmpty(fragment.getExtensionId())) {
        extensionBuilder.extensionId(project.getGroupId() + ":" + project.getArtifactId());
    }
    if (StringUtils.isNotEmpty(version)) {
        extensionBuilder.version(version);
    } else if (StringUtils.isEmpty(fragment.getVersion())) {
        extensionBuilder.version(project.getVersion());
    }
    if (StringUtils.isNotEmpty(name)) {
        extensionBuilder.name(name);
    } else if (StringUtils.isEmpty(fragment.getName())) {
        extensionBuilder.name(project.getName());
    }
    if (StringUtils.isNotEmpty(description)) {
        extensionBuilder.description(description);
    } else if (StringUtils.isEmpty(fragment.getDescription())) {
        extensionBuilder.description(project.getDescription());
    }
    if (StringUtils.isNotEmpty(icon)) {
        extensionBuilder.icon(icon);
    }
    if (StringUtils.isNotEmpty(tags)) {
        String[] split = tags.split(",");
        extensionBuilder.addAllTags(Arrays.asList(split));
    }
}
Also used : Extension(io.syndesis.common.model.extension.Extension)

Example 9 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class DefaultBinaryExtensionAnalyzer method doGetExtension.

private Extension doGetExtension(InputStream binaryExtension) throws IOException {
    Optional<InputStream> entry = readPath(binaryExtension, MANIFEST_LOCATION);
    if (!entry.isPresent()) {
        throw new IllegalArgumentException("Cannot find manifest file (" + MANIFEST_LOCATION + ") inside JAR");
    }
    JsonNode tree = Json.reader().readTree(entry.get());
    Extension extension = ExtensionConverter.getDefault().toInternalExtension(tree);
    if (extension == null) {
        throw new IllegalArgumentException("Cannot extract Extension from manifest file (" + MANIFEST_LOCATION + ") inside JAR");
    }
    return extension;
}
Also used : Extension(io.syndesis.common.model.extension.Extension) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 10 with Extension

use of io.syndesis.common.model.extension.Extension in project syndesis by syndesisio.

the class ExtensionSchemaValidationTest method addSchemaVersionInPublicModelExtensionTest.

@Test
public void addSchemaVersionInPublicModelExtensionTest() throws ProcessingException, IOException {
    String syndesisExtensionSchema = "/syndesis/syndesis-extension-definition-schema.json";
    JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema("resource:" + syndesisExtensionSchema);
    ExtensionConverter converter = new DefaultExtensionConverter();
    ObjectNode tree = OBJECT_MAPPER.createObjectNode().put("extensionId", "my-extension").put("name", "Name").put("description", "Description").put("version", "1.0.0");
    ProcessingReport report = schema.validate(tree);
    assertFalse(report.toString(), report.iterator().hasNext());
    Extension extension = converter.toInternalExtension(tree);
    assertEquals(ExtensionConverter.getCurrentSchemaVersion(), extension.getSchemaVersion());
}
Also used : Extension(io.syndesis.common.model.extension.Extension) ProcessingReport(com.github.fge.jsonschema.core.report.ProcessingReport) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonSchema(com.github.fge.jsonschema.main.JsonSchema) Test(org.junit.Test)

Aggregations

Extension (io.syndesis.common.model.extension.Extension)19 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Test (org.junit.Test)5 Connection (io.syndesis.common.model.connection.Connection)4 Step (io.syndesis.common.model.integration.Step)4 ProcessingReport (com.github.fge.jsonschema.core.report.ProcessingReport)3 JsonSchema (com.github.fge.jsonschema.main.JsonSchema)3 Connector (io.syndesis.common.model.connection.Connector)3 Integration (io.syndesis.common.model.integration.Integration)3 Date (java.util.Date)3 Action (io.syndesis.common.model.action.Action)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 StepAction (io.syndesis.common.model.action.StepAction)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ApiResponses (io.swagger.annotations.ApiResponses)1