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);
}
}
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);
}
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);
}
Aggregations