Search in sources :

Example 1 with AuditLogger

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();
                }
            };
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) AuditLogger(org.apache.helix.rest.server.auditlog.AuditLogger) TestContainer(org.glassfish.jersey.test.spi.TestContainer) ArrayList(java.util.ArrayList) HelixRestNamespace(org.apache.helix.rest.common.HelixRestNamespace) URI(java.net.URI) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) IOException(java.io.IOException) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory)

Example 2 with AuditLogger

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);
    }
}
Also used : AuditLogger(org.apache.helix.rest.server.auditlog.AuditLogger) AuditLog(org.apache.helix.rest.server.auditlog.AuditLog) Date(java.util.Date) IOException(java.io.IOException)

Example 3 with AuditLogger

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;
}
Also used : AuditLogger(org.apache.helix.rest.server.auditlog.AuditLogger) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) IOException(java.io.IOException) AuditLogFilter(org.apache.helix.rest.server.filters.AuditLogFilter)

Aggregations

IOException (java.io.IOException)3 AuditLogger (org.apache.helix.rest.server.auditlog.AuditLogger)3 TestContainerException (org.glassfish.jersey.test.spi.TestContainerException)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HelixRestNamespace (org.apache.helix.rest.common.HelixRestNamespace)1 AuditLog (org.apache.helix.rest.server.auditlog.AuditLog)1 AuditLogFilter (org.apache.helix.rest.server.filters.AuditLogFilter)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 DeploymentContext (org.glassfish.jersey.test.DeploymentContext)1 TestContainer (org.glassfish.jersey.test.spi.TestContainer)1 TestContainerFactory (org.glassfish.jersey.test.spi.TestContainerFactory)1