Search in sources :

Example 1 with AuditLog

use of org.apache.helix.rest.server.auditlog.AuditLog 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 2 with AuditLog

use of org.apache.helix.rest.server.auditlog.AuditLog in project helix by apache.

the class TestClusterAccessor method testGetClusters.

@Test
public void testGetClusters() throws IOException {
    System.out.println("Start test :" + TestHelper.getTestMethodName());
    _auditLogger.clearupLogs();
    String body = get("clusters", Response.Status.OK.getStatusCode(), true);
    JsonNode node = _mapper.readTree(body);
    String clustersStr = node.get(ClusterAccessor.ClusterProperties.clusters.name()).toString();
    Assert.assertNotNull(clustersStr);
    Set<String> clusters = _mapper.readValue(clustersStr, _mapper.getTypeFactory().constructCollectionType(Set.class, String.class));
    Assert.assertEquals(clusters, _clusters, "clusters from response: " + clusters + " vs clusters actually: " + _clusters);
    Assert.assertEquals(_auditLogger.getAuditLogs().size(), 1);
    AuditLog auditLog = _auditLogger.getAuditLogs().get(0);
    validateAuditLog(auditLog, HTTPMethods.GET.name(), "clusters", Response.Status.OK.getStatusCode(), body);
}
Also used : Set(java.util.Set) JsonNode(org.codehaus.jackson.JsonNode) AuditLog(org.apache.helix.rest.server.auditlog.AuditLog) Test(org.testng.annotations.Test)

Example 3 with AuditLog

use of org.apache.helix.rest.server.auditlog.AuditLog in project helix by apache.

the class TestClusterAccessor method updateClusterConfigFromRest.

private void updateClusterConfigFromRest(String cluster, ClusterConfig newConfig, Command command) throws IOException {
    _auditLogger.clearupLogs();
    Entity entity = Entity.entity(_mapper.writeValueAsString(newConfig.getRecord()), MediaType.APPLICATION_JSON_TYPE);
    post("clusters/" + cluster + "/configs", ImmutableMap.of("command", command.name()), entity, Response.Status.OK.getStatusCode());
    Assert.assertEquals(_auditLogger.getAuditLogs().size(), 1);
    AuditLog auditLog = _auditLogger.getAuditLogs().get(0);
    validateAuditLog(auditLog, HTTPMethods.POST.name(), "clusters/" + cluster + "/configs", Response.Status.OK.getStatusCode(), null);
}
Also used : Entity(javax.ws.rs.client.Entity) AuditLog(org.apache.helix.rest.server.auditlog.AuditLog)

Aggregations

AuditLog (org.apache.helix.rest.server.auditlog.AuditLog)3 IOException (java.io.IOException)1 Date (java.util.Date)1 Set (java.util.Set)1 Entity (javax.ws.rs.client.Entity)1 AuditLogger (org.apache.helix.rest.server.auditlog.AuditLogger)1 JsonNode (org.codehaus.jackson.JsonNode)1 Test (org.testng.annotations.Test)1