Search in sources :

Example 6 with SyndesisServerException

use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.

the class PrometheusMetricsProviderImpl method getTotalIntegrationMetricsSummary.

@Override
public IntegrationMetricsSummary getTotalIntegrationMetricsSummary() {
    final Optional<Long> totalMessages = getSummaryMetricValue(METRIC_TOTAL, Long.class, "sum");
    final Optional<Long> failedMessages = getSummaryMetricValue(METRIC_FAILED, Long.class, "sum");
    try {
        final Optional<Date> startTime = Optional.of(dateFormat.parse(openShiftClient.pods().withLabelSelector(SELECTOR).list().getItems().get(0).getStatus().getStartTime()));
        // compute last processed time
        final Optional<Date> lastCompletedTime = getAggregateMetricValue(METRIC_COMPLETED_TIMESTAMP, Date.class, "max");
        final Optional<Date> lastFailureTime = getAggregateMetricValue(METRIC_FAILURE_TIMESTAMP, Date.class, "max");
        final Date lastProcessedTime = MAX_DATE.apply(lastCompletedTime.orElse(null), lastFailureTime.orElse(null));
        return new IntegrationMetricsSummary.Builder().metricsProvider("prometheus").start(startTime).lastProcessed(Optional.ofNullable(lastProcessedTime)).messages(totalMessages.orElse(0L)).errors(failedMessages.orElse(0L)).build();
    } catch (ParseException e) {
        throw new SyndesisServerException(e.getMessage(), e);
    }
}
Also used : SyndesisServerException(io.syndesis.common.util.SyndesisServerException) ParseException(java.text.ParseException) Date(java.util.Date)

Example 7 with SyndesisServerException

use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.

the class SalesforceMetadataRetrieval method handle.

@Override
public RuntimeException handle(final Exception e) {
    Throwable current = e;
    while (current != null && current != current.getCause() && !(current instanceof SalesforceException)) {
        current = current.getCause();
    }
    if (current instanceof SalesforceException) {
        final SalesforceException salesforceException = (SalesforceException) current;
        final String message = salesforceException.getErrors().stream().map(error -> error.getErrorCode() + ": " + error.getMessage()).collect(Collectors.joining(". "));
        return new SyndesisServerException("Salesforce: " + message, e);
    }
    if (e instanceof RuntimeException) {
        return (RuntimeException) e;
    }
    return new SyndesisServerException("Salesforce", e);
}
Also used : PropertyPair(io.syndesis.connector.support.verifier.api.PropertyPair) MetaData(org.apache.camel.component.extension.MetaDataExtension.MetaData) HashMap(java.util.HashMap) ComponentMetadataRetrieval(io.syndesis.connector.support.verifier.api.ComponentMetadataRetrieval) HashSet(java.util.HashSet) SimpleTypeSchema(com.fasterxml.jackson.module.jsonSchema.types.SimpleTypeSchema) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonUtils(org.apache.camel.component.salesforce.api.utils.JsonUtils) CamelContext(org.apache.camel.CamelContext) DataShape(io.syndesis.common.model.DataShape) SyndesisMetadata(io.syndesis.connector.support.verifier.api.SyndesisMetadata) JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) ObjectSchema(com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) List(java.util.List) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Entry(java.util.Map.Entry) SalesforceEndpointConfig(org.apache.camel.component.salesforce.SalesforceEndpointConfig) Collections(java.util.Collections) Json(io.syndesis.common.util.Json) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) SyndesisServerException(io.syndesis.common.util.SyndesisServerException)

Example 8 with SyndesisServerException

use of io.syndesis.common.util.SyndesisServerException in project syndesis by syndesisio.

the class DefaultMigrator method performMigration.

private void performMigration(final JsonDB utilized, final int toVersion) {
    final String path = migrationsScriptPrefix() + toVersion + ".js";
    try {
        final Resource resource = resourceLoader.getResource(path);
        if (!resource.exists()) {
            return;
        }
        final String migrationScript = IOStreams.readText(resource.getInputStream());
        LOG.info("Migrating to schema: {}", toVersion);
        final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
        engine.put("internal", map("jsondb", utilized));
        engine.eval(Resources.getResourceAsText("migrations/common.js"));
        engine.eval(migrationScript);
    } catch (IOException | ScriptException e) {
        throw new SyndesisServerException("Unable to perform database migration to version " + toVersion + ", using migration script at: " + path, e);
    }
}
Also used : ScriptException(javax.script.ScriptException) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Resource(org.springframework.core.io.Resource) ScriptEngineManager(javax.script.ScriptEngineManager) IOException(java.io.IOException) ScriptEngine(javax.script.ScriptEngine)

Aggregations

SyndesisServerException (io.syndesis.common.util.SyndesisServerException)8 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonSchema (com.fasterxml.jackson.module.jsonSchema.JsonSchema)1 ObjectSchema (com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema)1 SimpleTypeSchema (com.fasterxml.jackson.module.jsonSchema.types.SimpleTypeSchema)1 Mustache (com.github.mustachejava.Mustache)1 MustacheNotFoundException (com.github.mustachejava.MustacheNotFoundException)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 DataShape (io.syndesis.common.model.DataShape)1