Search in sources :

Example 1 with TroubleshooterException

use of org.apache.gobblin.runtime.troubleshooter.TroubleshooterException in project incubator-gobblin by apache.

the class AutoTroubleshooterLogAppender method append.

@Override
protected void append(LoggingEvent event) {
    processedEventCount.incrementAndGet();
    Issue issue = convertToIssue(event);
    try {
        repository.put(issue);
    } catch (TroubleshooterException e) {
        if (reportedRepositoryError.compareAndSet(false, true)) {
            log.warn("Failed to save the issue to the repository", e);
        }
    }
}
Also used : TroubleshooterException(org.apache.gobblin.runtime.troubleshooter.TroubleshooterException) Issue(org.apache.gobblin.runtime.troubleshooter.Issue)

Example 2 with TroubleshooterException

use of org.apache.gobblin.runtime.troubleshooter.TroubleshooterException in project incubator-gobblin by apache.

the class MySqlMultiContextIssueRepository method remove.

@Override
public void remove(String contextId, String issueCode) throws TroubleshooterException {
    Objects.requireNonNull(contextId, "contextId should not be null");
    Objects.requireNonNull(issueCode, "issueCode should not be null");
    String statementSql = "delete from issues where context_id=? and code=?";
    try (Connection connection = databaseProvider.getDatasource().getConnection();
        PreparedStatement statement = connection.prepareStatement(statementSql)) {
        statement.setString(1, contextId);
        statement.setString(2, issueCode);
        statement.executeUpdate();
    } catch (SQLException e) {
        throw new TroubleshooterException("Cannot remove issue from the database", e);
    }
}
Also used : TroubleshooterException(org.apache.gobblin.runtime.troubleshooter.TroubleshooterException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 3 with TroubleshooterException

use of org.apache.gobblin.runtime.troubleshooter.TroubleshooterException in project gobblin by apache.

the class MySqlMultiContextIssueRepositoryTest method runLoadTestThread.

private void runLoadTestThread(MySqlMultiContextIssueRepository repository, int threadNumber, int contextsPerThread, int issuesPerContext, boolean useBatching) {
    Random random = new Random(threadNumber);
    try {
        for (int i = 0; i < contextsPerThread; i++) {
            String contextId = "load-test-" + testId + "-thread-" + threadNumber + "-context-" + i;
            List<Issue> issues = new ArrayList<>();
            for (int j = 0; j < issuesPerContext; j++) {
                Issue issue = getLargeTestIssue("load-test-1-" + random.nextInt(), "code-" + random.nextInt());
                issues.add(issue);
                if (!useBatching) {
                    repository.put(contextId, issue);
                }
            }
            if (useBatching) {
                repository.put(contextId, issues);
            }
            List<Issue> retrievedIssues = repository.getAll(contextId);
            assertThat(retrievedIssues).usingRecursiveComparison().isEqualTo(issues);
        }
    } catch (TroubleshooterException e) {
        throw new RuntimeException(e);
    }
}
Also used : TroubleshooterException(org.apache.gobblin.runtime.troubleshooter.TroubleshooterException) Issue(org.apache.gobblin.runtime.troubleshooter.Issue) Random(java.util.Random) ArrayList(java.util.ArrayList)

Example 4 with TroubleshooterException

use of org.apache.gobblin.runtime.troubleshooter.TroubleshooterException in project gobblin by apache.

the class MySqlMultiContextIssueRepository method put.

@Override
public void put(String contextId, List<Issue> issues) throws TroubleshooterException {
    Objects.requireNonNull(contextId, "contextId should not be null");
    Objects.requireNonNull(issues, "issues should not be null");
    String statementSql = "replace into issues (context_id, code, time, severity,summary,details,source_class,exception_class,properties) " + "values (?,?,?,?,?,?,?,?,?)";
    try (Connection connection = databaseProvider.getDatasource().getConnection();
        PreparedStatement statement = connection.prepareStatement(statementSql)) {
        connection.setAutoCommit(false);
        for (Issue issue : issues) {
            statement.setString(1, contextId);
            statement.setString(2, issue.getCode());
            statement.setTimestamp(3, new Timestamp(issue.getTime().toInstant().toEpochMilli()));
            statement.setString(4, issue.getSeverity().toString());
            statement.setString(5, issue.getSummary());
            statement.setString(6, issue.getDetails());
            statement.setString(7, issue.getSourceClass());
            statement.setString(8, issue.getExceptionClass());
            String serializedProperties = null;
            if (issue.getProperties() != null) {
                serializedProperties = GsonUtils.GSON_WITH_DATE_HANDLING.toJson(issue.getProperties());
            }
            statement.setString(9, serializedProperties);
            statement.executeUpdate();
        }
        connection.commit();
    } catch (SQLException e) {
        throw new TroubleshooterException("Cannot save issue to the database", e);
    }
}
Also used : TroubleshooterException(org.apache.gobblin.runtime.troubleshooter.TroubleshooterException) Issue(org.apache.gobblin.runtime.troubleshooter.Issue) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 5 with TroubleshooterException

use of org.apache.gobblin.runtime.troubleshooter.TroubleshooterException in project gobblin by apache.

the class MySqlMultiContextIssueRepository method getAll.

@Override
public List<Issue> getAll(String contextId) throws TroubleshooterException {
    Objects.requireNonNull(contextId, "contextId should not be null");
    String querySql = "select code, time, severity, summary, details, source_class, exception_class, properties " + "from issues where context_id = ? order by position";
    try (Connection connection = databaseProvider.getDatasource().getConnection();
        PreparedStatement statement = connection.prepareStatement(querySql)) {
        statement.setString(1, contextId);
        ArrayList<Issue> issues = new ArrayList<>();
        try (ResultSet results = statement.executeQuery()) {
            while (results.next()) {
                Issue.IssueBuilder issue = Issue.builder();
                issue.code(results.getString(1));
                issue.time(ZonedDateTime.ofInstant(Instant.ofEpochMilli(results.getTimestamp(2).getTime()), ZoneOffset.UTC));
                issue.severity(IssueSeverity.valueOf(results.getString(3)));
                issue.summary(results.getString(4));
                issue.details(results.getString(5));
                issue.sourceClass(results.getString(6));
                issue.exceptionClass(results.getString(7));
                String serializedProperties = results.getString(8);
                if (serializedProperties != null) {
                    Type mapType = new TypeToken<HashMap<String, String>>() {
                    }.getType();
                    HashMap<String, String> properties = GsonUtils.GSON_WITH_DATE_HANDLING.fromJson(serializedProperties, mapType);
                    issue.properties(properties);
                }
                issues.add(issue.build());
            }
        }
        return issues;
    } catch (SQLException e) {
        throw new TroubleshooterException("Cannot read issues from the database", e);
    }
}
Also used : TroubleshooterException(org.apache.gobblin.runtime.troubleshooter.TroubleshooterException) Issue(org.apache.gobblin.runtime.troubleshooter.Issue) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Type(java.lang.reflect.Type) ResultSet(java.sql.ResultSet)

Aggregations

TroubleshooterException (org.apache.gobblin.runtime.troubleshooter.TroubleshooterException)12 Issue (org.apache.gobblin.runtime.troubleshooter.Issue)10 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)4 Type (java.lang.reflect.Type)2 ResultSet (java.sql.ResultSet)2 Timestamp (java.sql.Timestamp)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2 Test (org.testng.annotations.Test)2