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();
}
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();
}
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);
}
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);
}
}
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);
}
}
Aggregations