use of co.cask.cdap.proto.audit.AuditPayload in project cdap by caskdata.
the class SystemMetadataAuditPublishTest method getAllSystemMetadata.
private Set<String> getAllSystemMetadata() {
Set<String> allMetadata = new HashSet<>();
for (AuditMessage auditMessage : getMetadataUpdateMessages()) {
AuditPayload payload = auditMessage.getPayload();
Assert.assertTrue(payload instanceof MetadataPayload);
MetadataPayload metadataPayload = (MetadataPayload) payload;
Map<MetadataScope, Metadata> additions = metadataPayload.getAdditions();
if (additions.containsKey(MetadataScope.SYSTEM)) {
allMetadata.addAll(additions.get(MetadataScope.SYSTEM).getProperties().keySet());
allMetadata.addAll(additions.get(MetadataScope.SYSTEM).getTags());
}
Map<MetadataScope, Metadata> deletions = metadataPayload.getDeletions();
if (deletions.containsKey(MetadataScope.SYSTEM)) {
allMetadata.addAll(deletions.get(MetadataScope.SYSTEM).getProperties().keySet());
allMetadata.addAll(deletions.get(MetadataScope.SYSTEM).getTags());
}
}
return allMetadata;
}
use of co.cask.cdap.proto.audit.AuditPayload in project cdap by caskdata.
the class AuditMessageTypeAdapter method deserialize.
@Override
public AuditMessage deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
long timeMillis = jsonObj.get("time").getAsLong();
EntityId entityId = context.deserialize(jsonObj.getAsJsonObject("entityId"), EntityId.class);
String user = jsonObj.get("user").getAsString();
AuditType auditType = context.deserialize(jsonObj.getAsJsonPrimitive("type"), AuditType.class);
AuditPayload payload;
JsonObject jsonPayload = jsonObj.getAsJsonObject("payload");
switch(auditType) {
case METADATA_CHANGE:
payload = context.deserialize(jsonPayload, MetadataPayload.class);
break;
case ACCESS:
payload = context.deserialize(jsonPayload, AccessPayload.class);
break;
default:
payload = AuditPayload.EMPTY_PAYLOAD;
}
return new AuditMessage(timeMillis, entityId, user, auditType, payload);
}
Aggregations