use of io.cdap.cdap.proto.audit.AuditPayload in project cdap by caskdata.
the class SystemMetadataAuditPublishTest method addAllSystemMetadata.
private int addAllSystemMetadata(Set<String> allMetadata) {
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.size();
}
use of io.cdap.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();
MetadataEntity metadataEntity;
EntityId entityId = context.deserialize(jsonObj.getAsJsonObject("entityId"), EntityId.class);
if (entityId != null) {
metadataEntity = entityId.toMetadataEntity();
} else {
metadataEntity = context.deserialize(jsonObj.getAsJsonObject("metadataEntity"), MetadataEntity.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, metadataEntity, user, auditType, payload);
}
Aggregations