Search in sources :

Example 26 with Issue

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

the class AutomaticTroubleshooterImpl method getIssueSummaryMessage.

@Override
public String getIssueSummaryMessage() throws TroubleshooterException {
    List<Issue> issues = issueRepository.getAll();
    TextStringBuilder sb = new TextStringBuilder();
    sb.appendln("");
    sb.appendln("vvvvv============= Issues (summary) =============vvvvv");
    for (int i = 0; i < issues.size(); i++) {
        Issue issue = issues.get(i);
        sb.appendln("%s) %s %s %s | source: %s", i + 1, issue.getSeverity().toString(), issue.getCode(), issue.getSummary(), issue.getSourceClass());
    }
    sb.append("^^^^^=============================================^^^^^");
    return sb.toString();
}
Also used : Issue(org.apache.gobblin.runtime.troubleshooter.Issue) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 27 with Issue

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

the class AutomaticTroubleshooterImpl method getIssueDetailsMessage.

@Override
public String getIssueDetailsMessage() throws TroubleshooterException {
    List<Issue> issues = issueRepository.getAll();
    TextStringBuilder sb = new TextStringBuilder();
    sb.appendln("");
    sb.appendln("vvvvv============= Issues (detailed) =============vvvvv");
    for (int i = 0; i < issues.size(); i++) {
        Issue issue = issues.get(i);
        sb.appendln("%s) %s %s %s", i + 1, issue.getSeverity().toString(), issue.getCode(), issue.getSummary());
        sb.appendln("\tsource: %s", issue.getSourceClass());
        if (issue.getDetails() != null) {
            sb.appendln("\t" + issue.getDetails().replaceAll(System.lineSeparator(), System.lineSeparator() + "\t"));
        }
        if (issue.getProperties() != null) {
            issue.getProperties().forEach((key, value) -> {
                sb.appendln("\t%s: %s", key, value);
            });
        }
    }
    sb.append("^^^^^================================================^^^^^");
    return sb.toString();
}
Also used : Issue(org.apache.gobblin.runtime.troubleshooter.Issue) TextStringBuilder(org.apache.commons.text.TextStringBuilder)

Example 28 with Issue

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

the class AutoTroubleshooterLogAppenderTest method canLogWarning.

@Test
public void canLogWarning() throws Exception {
    appender.append(new LoggingEvent(log.getName(), log, System.currentTimeMillis(), Level.WARN, "test", null));
    Issue issue = issueRepository.getAll().get(0);
    Assert.assertEquals(issue.getSeverity(), IssueSeverity.WARN);
    Assert.assertEquals(issue.getSummary(), "test");
    Assert.assertEquals(issue.getSourceClass(), getClass().getName());
    Assert.assertTrue(issue.getTime().isAfter(ZonedDateTime.now().minus(1, ChronoUnit.MINUTES)));
    Assert.assertTrue(issue.getTime().isBefore(ZonedDateTime.now().plus(1, ChronoUnit.MINUTES)));
    Assert.assertTrue(issue.getCode().length() > 1);
    assertEquals(appender.getProcessedEventCount(), 1);
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Issue(org.apache.gobblin.runtime.troubleshooter.Issue) Test(org.testng.annotations.Test)

Example 29 with Issue

use of org.apache.gobblin.runtime.troubleshooter.Issue in project incubator-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 30 with Issue

use of org.apache.gobblin.runtime.troubleshooter.Issue in project incubator-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

Issue (org.apache.gobblin.runtime.troubleshooter.Issue)48 Test (org.testng.annotations.Test)32 TroubleshooterException (org.apache.gobblin.runtime.troubleshooter.TroubleshooterException)10 ArrayList (java.util.ArrayList)8 LoggingEvent (org.apache.log4j.spi.LoggingEvent)8 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)6 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 Random (java.util.Random)4 TextStringBuilder (org.apache.commons.text.TextStringBuilder)4 StringMap (com.linkedin.data.template.StringMap)2 Type (java.lang.reflect.Type)2 ResultSet (java.sql.ResultSet)2 Timestamp (java.sql.Timestamp)2 ZonedDateTime (java.time.ZonedDateTime)2 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)2 IssueEventBuilder (org.apache.gobblin.runtime.troubleshooter.IssueEventBuilder)2