use of io.fabric8.common.util.Filter 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.common.util.Filter in project fabric8 by jboss-fuse.
the class Log4jTest method assertLogQuery.
protected void assertLogQuery(LogQuerySupportMBean mBean) throws Exception {
LogResults results = mBean.allLogResults();
List<LogEvent> logEvents = assertNotEmpty(results);
assertMatches(logEvents, messagePredicate("INFO", info1));
assertMatches(logEvents, messagePredicate("INFO", info2));
assertMatches(logEvents, messagePredicate("ERROR", error1));
assertMatches(logEvents, messagePredicate("ERROR", error2));
// test a filter
LogFilter filter = new LogFilter();
filter.setLevels(new String[] { "ERROR" });
logEvents = assertNotEmpty(mBean.queryLogResults(filter));
assertMatches(logEvents, messagePredicate("ERROR", error1));
assertMatches(logEvents, messagePredicate("ERROR", error2));
assertNotMatches(logEvents, messagePredicate("INFO", info1));
assertNotMatches(logEvents, messagePredicate("INFO", info2));
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class LogQuerySupport method logResultsSince.
@Override
public LogResults logResultsSince(long time) throws IOException {
LogFilter filter = new LogFilter();
filter.setAfterTimestamp(time);
return queryLogResults(filter);
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class ServiceFactoryTest method testDiscoveryOnRestartCurator.
@Test
public void testDiscoveryOnRestartCurator() throws Exception {
underTest = new ActiveMQServiceFactory();
underTest.curator = curator;
Properties props = new Properties();
props.put("config", "amq.xml");
props.put("broker-name", "amq");
props.put("group", "amq");
props.put("connectors", "openwire");
props.put("openwire-port", "0");
props.put("container.ip", "localhost");
underTest.updated("b", props);
final AtomicReference<CuratorFramework> curatorFrameworkAtomicReference = new AtomicReference<>(curator);
OsgiFabricDiscoveryAgent osgiFabricDiscoveryAgent = new OsgiFabricDiscoveryAgent(new BundleContext() {
@Override
public String getProperty(String s) {
return null;
}
@Override
public Bundle getBundle() {
return null;
}
@Override
public Bundle installBundle(String s, InputStream inputStream) throws BundleException {
return null;
}
@Override
public Bundle installBundle(String s) throws BundleException {
return null;
}
@Override
public Bundle getBundle(long l) {
return null;
}
@Override
public Bundle[] getBundles() {
return new Bundle[0];
}
@Override
public void addServiceListener(ServiceListener serviceListener, String s) throws InvalidSyntaxException {
}
@Override
public void addServiceListener(ServiceListener serviceListener) {
}
@Override
public void removeServiceListener(ServiceListener serviceListener) {
}
@Override
public void addBundleListener(BundleListener bundleListener) {
}
@Override
public void removeBundleListener(BundleListener bundleListener) {
}
@Override
public void addFrameworkListener(FrameworkListener frameworkListener) {
}
@Override
public void removeFrameworkListener(FrameworkListener frameworkListener) {
}
@Override
public ServiceRegistration<?> registerService(String[] strings, Object o, Dictionary<String, ?> dictionary) {
return null;
}
@Override
public ServiceRegistration<?> registerService(String s, Object o, Dictionary<String, ?> dictionary) {
return null;
}
@Override
public <S> ServiceRegistration<S> registerService(Class<S> aClass, S s, Dictionary<String, ?> dictionary) {
return null;
}
@Override
public ServiceReference<?>[] getServiceReferences(String s, String s1) throws InvalidSyntaxException {
return new ServiceReference<?>[0];
}
@Override
public ServiceReference<?>[] getAllServiceReferences(String s, String s1) throws InvalidSyntaxException {
return new ServiceReference<?>[0];
}
@Override
public ServiceReference<?> getServiceReference(String s) {
return null;
}
@Override
public <S> ServiceReference<S> getServiceReference(Class<S> aClass) {
return null;
}
@Override
public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> aClass, String s) throws InvalidSyntaxException {
return null;
}
@Override
public <S> S getService(ServiceReference<S> serviceReference) {
return (S) curatorFrameworkAtomicReference.get();
}
@Override
public boolean ungetService(ServiceReference<?> serviceReference) {
return false;
}
@Override
public File getDataFile(String s) {
return null;
}
@Override
public Filter createFilter(String s) throws InvalidSyntaxException {
return null;
}
@Override
public Bundle getBundle(String s) {
return null;
}
});
final LinkedBlockingQueue<DiscoveryEvent> discoveryEvents = new LinkedBlockingQueue<DiscoveryEvent>(10);
osgiFabricDiscoveryAgent.setDiscoveryListener(new DiscoveryListener() {
@Override
public void onServiceAdd(DiscoveryEvent discoveryEvent) {
discoveryEvents.offer(discoveryEvent);
}
@Override
public void onServiceRemove(DiscoveryEvent discoveryEvent) {
}
});
// will call into dummy bundle and get curator
osgiFabricDiscoveryAgent.addingService(null);
osgiFabricDiscoveryAgent.setGroupName("amq");
osgiFabricDiscoveryAgent.start();
DiscoveryEvent event = discoveryEvents.poll(5, TimeUnit.SECONDS);
LOG.info("event: " + event);
assertNotNull("got added service", event);
underTest.deleted("b");
// swap curator ref
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).sessionTimeoutMs(15000).retryPolicy(new RetryNTimes(5000, 1000));
curator = builder.build();
LOG.debug("Starting new curator " + curator);
curator.start();
curatorFrameworkAtomicReference.get().close();
curatorFrameworkAtomicReference.set(curator);
// will call into dummy bundle and get new curator ref
osgiFabricDiscoveryAgent.addingService(null);
// start broker again
underTest.curator = curator;
underTest.updated("b", props);
event = discoveryEvents.poll(5, TimeUnit.SECONDS);
LOG.info("new event: " + event);
assertNotNull("got newly added service", event);
underTest.deleted("b");
}
use of io.fabric8.common.util.Filter in project fabric8 by jboss-fuse.
the class FabricHTTPGateway method getGatewayVersion.
/**
* Returns the default profile version used to filter out the current versions of services
* if no version expression is used the URI template
*/
String getGatewayVersion() {
assertValid();
Container currentContainer = fabricService.get().getCurrentContainer();
if (currentContainer != null) {
Version version = currentContainer.getVersion();
if (version != null) {
return version.getId();
}
}
return null;
}
Aggregations