use of io.fabric8.insight.log.support.Predicate in project fabric8 by jboss-fuse.
the class Log4jLogQuery method filterLogResults.
protected LogResults filterLogResults(Predicate<LogEvent> predicate, int maxCount) {
int matched = 0;
long from = Long.MAX_VALUE;
long to = Long.MIN_VALUE;
List<LogEvent> list = new ArrayList<LogEvent>();
Iterable<LoggingEvent> elements = getEvents().getElements();
for (LoggingEvent element : elements) {
LogEvent logEvent = toLogEvent(element);
long timestamp = element.getTimeStamp();
if (timestamp > to) {
to = timestamp;
}
if (timestamp < from) {
from = timestamp;
}
if (logEvent != null) {
if (predicate == null || predicate.matches(logEvent)) {
list.add(logEvent);
matched += 1;
if (maxCount > 0 && matched >= maxCount) {
break;
}
}
}
}
LogResults results = new LogResults();
results.setEvents(list);
if (from < Long.MAX_VALUE) {
results.setFromTimestamp(from);
}
if (to > Long.MIN_VALUE) {
results.setToTimestamp(to);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Requested " + maxCount + " logging items. returning " + results.getEvents().size() + " event(s) from a possible " + getEvents().size());
}
return results;
}
use of io.fabric8.insight.log.support.Predicate in project fabric8 by jboss-fuse.
the class Log4jLogQuery method createPredicate.
private Predicate<LogEvent> createPredicate(LogFilter filter) {
if (filter == null) {
return null;
}
final List<Predicate<LogEvent>> predicates = new ArrayList<Predicate<LogEvent>>();
final Set<String> levels = filter.getLevelsSet();
if (levels.size() > 0) {
predicates.add(new Predicate<LogEvent>() {
@Override
public boolean matches(LogEvent event) {
String level = event.getLevel();
return level != null && levels.contains(level.toString());
}
});
}
final Long before = filter.getBeforeTimestamp();
if (before != null) {
final Date date = new Date(before);
predicates.add(new Predicate<LogEvent>() {
@Override
public boolean matches(LogEvent event) {
Date time = event.getTimestamp();
return time != null && time.before(date);
}
});
}
final Long after = filter.getAfterTimestamp();
if (after != null) {
final Date date = new Date(after);
predicates.add(new Predicate<LogEvent>() {
@Override
public boolean matches(LogEvent event) {
Date time = event.getTimestamp();
return time != null && time.after(date);
}
});
}
final String matchesText = filter.getMatchesText();
if (matchesText != null && matchesText.length() > 0) {
predicates.add(new Predicate<LogEvent>() {
@Override
public boolean matches(LogEvent event) {
if (contains(matchesText, event.getClassName(), event.getMessage(), event.getLogger(), event.getThread())) {
return true;
}
String[] throwableStrRep = event.getException();
if (throwableStrRep != null && contains(matchesText, throwableStrRep)) {
return true;
}
Map properties = event.getProperties();
if (properties != null && contains(matchesText, properties.toString())) {
return true;
}
return false;
}
});
}
if (predicates.size() == 0) {
return null;
} else if (predicates.size() == 1) {
return predicates.get(0);
} else {
return new Predicate<LogEvent>() {
@Override
public String toString() {
return "AndPredicate" + predicates;
}
@Override
public boolean matches(LogEvent event) {
for (Predicate<LogEvent> predicate : predicates) {
if (!predicate.matches(event)) {
return false;
}
}
return true;
}
};
}
}
use of io.fabric8.insight.log.support.Predicate in project strimzi by strimzi.
the class StatefulSetOperator method restartPod.
private Future<Void> restartPod(String namespace, String name, Predicate<String> isReady, String podName) {
Future<Void> result = Future.future();
log.info("Roll {}/{}: Rolling pod {}", namespace, name, podName);
Future<Void> deleted = Future.future();
Future<CompositeFuture> deleteFinished = Future.future();
Watcher<Pod> watcher = new RollingUpdateWatcher(deleted);
Watch watch = podOperations.watch(namespace, podName, watcher);
// Delete the pod
log.debug("Roll {}/{}: Waiting for pod {} to be deleted", namespace, name, podName);
Future podReconcileFuture = podOperations.reconcile(namespace, podName, null);
CompositeFuture.join(podReconcileFuture, deleted).setHandler(deleteResult -> {
watch.close();
if (deleteResult.succeeded()) {
log.debug("Roll {}/{}: Pod {} was deleted", namespace, name, podName);
}
deleteFinished.handle(deleteResult);
});
deleteFinished.compose(ix -> {
log.debug("Roll {}/{}: Waiting for new pod {} to get ready", namespace, name, podName);
Future<Void> readyFuture = Future.future();
vertx.setPeriodic(1_000, timerId -> {
p(isReady, podName).setHandler(x -> {
if (x.succeeded()) {
if (x.result()) {
vertx.cancelTimer(timerId);
readyFuture.complete();
}
// else not ready
} else {
vertx.cancelTimer(timerId);
readyFuture.fail(x.cause());
}
});
});
return readyFuture;
}).setHandler(result);
return result;
}
use of io.fabric8.insight.log.support.Predicate in project fabric8 by jboss-fuse.
the class LogQuery method getLogEventList.
public LogResults getLogEventList(int count, Predicate<PaxLoggingEvent> predicate) {
LogResults answer = new LogResults();
answer.setHost(getHostName());
long from = Long.MAX_VALUE;
long to = Long.MIN_VALUE;
if (appender != null) {
LruList events = appender.getEvents();
if (events != null) {
Iterable<PaxLoggingEvent> iterable = events.getElements();
if (iterable != null) {
int matched = 0;
for (PaxLoggingEvent event : iterable) {
if (event != null) {
long timestamp = event.getTimeStamp();
if (timestamp > to) {
to = timestamp;
}
if (timestamp < from) {
from = timestamp;
}
if (predicate == null || predicate.matches(event)) {
answer.addEvent(Logs.newInstance(event));
matched += 1;
if (count > 0 && matched >= count) {
break;
}
}
}
}
}
}
} else {
LOG.warn("No VmLogAppender available!");
}
answer.setFromTimestamp(from);
answer.setToTimestamp(to);
return answer;
}
use of io.fabric8.insight.log.support.Predicate in project strimzi by strimzi.
the class ControllerTest method configMapRemoved.
// TODO 3way reconcilation where kafka and kube agree
// TODO 3way reconcilation where all three agree
// TODO 3way reconcilation with conflict
// TODO reconciliation where only private state exists => delete the private state
// TODO tests for the other reconciliation cases
// + non-matching predicate
// + error cases
private void configMapRemoved(TestContext context, Exception deleteTopicException, Exception storeException) {
Topic kubeTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "bar")).build();
Topic kafkaTopic = kubeTopic;
Topic privateTopic = kubeTopic;
mockKafka.setCreateTopicResponse(topicName.toString(), null).createTopic(kafkaTopic, ar -> {
});
mockKafka.setTopicMetadataResponse(topicName, Utils.getTopicMetadata(kubeTopic), null);
mockKafka.setDeleteTopicResponse(topicName, deleteTopicException);
mockTopicStore.setCreateTopicResponse(topicName, null).create(privateTopic, ar -> {
});
mockTopicStore.setDeleteTopicResponse(topicName, storeException);
ConfigMap cm = TopicSerialization.toConfigMap(kubeTopic, cmPredicate);
Async async = context.async();
controller.onConfigMapDeleted(cm, ar -> {
if (deleteTopicException != null || storeException != null) {
assertFailed(context, ar);
if (deleteTopicException != null) {
// should still exist
mockKafka.assertExists(context, kafkaTopic.getTopicName());
} else {
mockKafka.assertNotExists(context, kafkaTopic.getTopicName());
}
mockTopicStore.assertExists(context, kafkaTopic.getTopicName());
} else {
assertSucceeded(context, ar);
mockKafka.assertNotExists(context, kafkaTopic.getTopicName());
mockTopicStore.assertNotExists(context, kafkaTopic.getTopicName());
}
async.complete();
});
}
Aggregations