use of io.fabric8.kubernetes.api.model.Event 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.kubernetes.api.model.Event 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.kubernetes.api.model.Event in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method checkPendingPatches.
@Override
public void checkPendingPatches() {
File[] pendingPatches = patchesDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.exists() && pathname.getName().endsWith(".pending");
}
});
if (pendingPatches == null || pendingPatches.length == 0) {
return;
}
final String dataCache = systemContext.getProperty("org.osgi.framework.storage");
for (File pending : pendingPatches) {
try {
Pending what = Pending.valueOf(FileUtils.readFileToString(pending));
final String prefix = what == Pending.ROLLUP_INSTALLATION ? "install" : "rollback";
String name = pending.getName().replaceFirst("\\.pending$", "");
if (isStandaloneChild()) {
if (name.endsWith("." + System.getProperty("karaf.name") + ".patch")) {
name = name.replaceFirst("\\." + System.getProperty("karaf.name"), "");
} else {
continue;
}
}
File patchFile = new File(pending.getParentFile(), name);
if (!patchFile.isFile()) {
Activator.log(LogService.LOG_INFO, "Ignoring patch result file: " + patchFile.getName());
continue;
}
PatchData patchData = PatchData.load(new FileInputStream(patchFile));
Patch patch = loadPatch(new PatchDetailsRequest(patchData.getId()));
String dataFilesName = patchData.getId() + ".datafiles";
if (isStandaloneChild()) {
dataFilesName = patchData.getId() + "." + System.getProperty("karaf.name") + ".datafiles";
}
final File dataFilesBackupDir = new File(pending.getParentFile(), dataFilesName);
final Properties backupProperties = new Properties();
FileInputStream inStream = new FileInputStream(new File(dataFilesBackupDir, "backup-" + prefix + ".properties"));
backupProperties.load(inStream);
IOUtils.closeQuietly(inStream);
// maybe one of those bundles has data directory to restore?
for (Bundle b : systemContext.getBundles()) {
if (b.getSymbolicName() != null) {
String key = String.format("%s$$%s", stripSymbolicName(b.getSymbolicName()), b.getVersion().toString());
if (backupProperties.containsKey(key)) {
String backupDirName = backupProperties.getProperty(key);
File backupDir = new File(dataFilesBackupDir, prefix + "/" + backupDirName + "/data");
restoreDataDirectory(dataCache, b, backupDir);
// we no longer want to restore this dir
backupProperties.remove(key);
}
}
}
// 2. We can however have more bundle data backups - we'll restore them after each bundle
// is INSTALLED and we'll use listener for this
BundleListener bundleListener = new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
Bundle b = event.getBundle();
if (event.getType() == BundleEvent.INSTALLED && b.getSymbolicName() != null) {
String key = String.format("%s$$%s", stripSymbolicName(b.getSymbolicName()), b.getVersion().toString());
if (backupProperties.containsKey(key)) {
String backupDirName = backupProperties.getProperty(key);
File backupDir = new File(dataFilesBackupDir, prefix + "/" + backupDirName + "/data");
restoreDataDirectory(dataCache, b, backupDir);
}
}
}
};
systemContext.addBundleListener(bundleListener);
pendingPatchesListeners.put(patchData.getId(), bundleListener);
} catch (Exception e) {
Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
}
}
}
use of io.fabric8.kubernetes.api.model.Event in project fabric8 by jboss-fuse.
the class HttpGatewayConnectionTimeoutTest method testConnectionTimeout.
@Test
public void testConnectionTimeout() throws Exception {
startRestEndpoint();
startHttpGateway();
LOG.info("Requesting...");
final FutureHandler<HttpClientResponse> future = new FutureHandler<>();
vertx.createHttpClient().setHost("localhost").setPort(8080).get("/hello/world?wsdl", new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse event) {
future.handle(event);
}
}).end();
HttpClientResponse response = future.await();
assertEquals(response.statusCode(), 504);
stopHttpGateway();
stopVertx();
}
use of io.fabric8.kubernetes.api.model.Event in project fabric8 by jboss-fuse.
the class HttpGatewayRequestTimeoutTest method testRequestTimeout.
@Test
public void testRequestTimeout() throws Exception {
startRestEndpoint();
startHttpGateway();
LOG.info("Requesting...");
final FutureHandler<HttpClientResponse> future = new FutureHandler<>();
vertx.createHttpClient().setHost("localhost").setPort(8080).get("/hello/world?wsdl", new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse event) {
future.handle(event);
}
}).end();
HttpClientResponse response = future.await();
assertEquals(response.statusCode(), 504);
stopHttpGateway();
stopVertx();
}
Aggregations