use of org.apache.helix.rest.server.auditlog.AuditLogger in project helix by apache.
the class AbstractTestClass method getTestContainerFactory.
@Override
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
return new TestContainerFactory() {
@Override
public TestContainer create(final URI baseUri, DeploymentContext deploymentContext) {
return new TestContainer() {
private HelixRestServer _helixRestServer;
@Override
public ClientConfig getClientConfig() {
return null;
}
@Override
public URI getBaseUri() {
return baseUri;
}
@Override
public void start() {
// Create namespace manifest map
List<HelixRestNamespace> namespaces = new ArrayList<>();
// Add test namespace
namespaces.add(new HelixRestNamespace(TEST_NAMESPACE, HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, _zkAddrTestNS, false));
// Add default namesapce
namespaces.add(new HelixRestNamespace(ZK_ADDR));
try {
_helixRestServer = new HelixRestServer(namespaces, baseUri.getPort(), baseUri.getPath(), Arrays.<AuditLogger>asList(_auditLogger));
_helixRestServer.start();
} catch (Exception ex) {
throw new TestContainerException(ex);
}
}
@Override
public void stop() {
_helixRestServer.shutdown();
}
};
}
};
}
use of org.apache.helix.rest.server.auditlog.AuditLogger in project helix by apache.
the class AuditLogFilter method filter.
@Override
public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException {
AuditLog.Builder auditLogBuilder;
try {
auditLogBuilder = (AuditLog.Builder) request.getProperty(AuditLog.ATTRIBUTE_NAME);
auditLogBuilder.completeTime(new Date()).responseCode(response.getStatus());
Object entity = response.getEntity();
if (entity != null && entity instanceof String) {
auditLogBuilder.responseEntity((String) response.getEntity());
}
AuditLog auditLog = auditLogBuilder.build();
if (_auditLoggers != null) {
for (AuditLogger logger : _auditLoggers) {
logger.write(auditLog);
}
}
} catch (Exception ex) {
_logger.error("Failed to add audit log " + ex);
}
}
use of org.apache.helix.rest.server.auditlog.AuditLogger in project helix by apache.
the class AbstractTestClass method configure.
@Override
protected Application configure() {
// start zk
try {
if (_zkServer == null) {
_zkServer = TestHelper.startZkServer(ZK_ADDR);
Assert.assertTrue(_zkServer != null);
ZKClientPool.reset();
}
if (_zkServerTestNS == null) {
_zkServerTestNS = TestHelper.startZkServer(_zkAddrTestNS);
Assert.assertTrue(_zkServerTestNS != null);
ZKClientPool.reset();
}
} catch (Exception e) {
Assert.assertTrue(false, String.format("Failed to start ZK server: %s", e.toString()));
}
// Configure server context
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.packages(AbstractResource.class.getPackage().getName());
ServerContext serverContext = new ServerContext(ZK_ADDR);
resourceConfig.property(ContextPropertyKeys.SERVER_CONTEXT.name(), serverContext);
resourceConfig.register(new AuditLogFilter(Arrays.<AuditLogger>asList(new MockAuditLogger())));
return resourceConfig;
}
Aggregations