use of io.cdap.cdap.data2.audit.payload.builder.MetadataPayloadBuilder in project cdap by caskdata.
the class DefaultMetadataStore method publishAudit.
private void publishAudit(MetadataRecord previous, MetadataRecord additions, MetadataRecord deletions) {
MetadataPayloadBuilder builder = new MetadataPayloadBuilder();
builder.addPrevious(previous);
builder.addAdditions(additions);
builder.addDeletions(deletions);
AuditPublishers.publishAudit(auditPublisher, previous.getEntityId(), AuditType.METADATA_CHANGE, builder.build());
}
use of io.cdap.cdap.data2.audit.payload.builder.MetadataPayloadBuilder in project cdap by caskdata.
the class AuditMetadataStorage method publishAudit.
private void publishAudit(MetadataChange change, MetadataScope scope) {
Map<String, String> propsBefore = change.getBefore().getProperties(scope);
Map<String, String> propsAfter = change.getAfter().getProperties(scope);
Set<String> tagsBefore = change.getBefore().getTags(scope);
Set<String> tagsAfter = change.getAfter().getTags(scope);
boolean propsChanged = !propsBefore.equals(propsAfter);
boolean tagsChanged = !tagsBefore.equals(tagsAfter);
if (!propsChanged && !tagsChanged) {
// no change to log
return;
}
// previous state is already given
MetadataRecord previous = new MetadataRecord(change.getEntity(), scope, propsBefore, tagsBefore);
// compute what was added
@SuppressWarnings("ConstantConditions") Map<String, String> propsAdded = Maps.filterEntries(propsAfter, entry -> !entry.getValue().equals(propsBefore.get(entry.getKey())));
Set<String> tagsAdded = Sets.difference(tagsAfter, tagsBefore);
MetadataRecord additions = new MetadataRecord(change.getEntity(), scope, propsAdded, tagsAdded);
// compute what was deleted
@SuppressWarnings("ConstantConditions") Map<String, String> propsDeleted = Maps.filterEntries(propsBefore, entry -> !entry.getValue().equals(propsAfter.get(entry.getKey())));
Set<String> tagsDeleted = Sets.difference(tagsBefore, tagsAfter);
MetadataRecord deletions = new MetadataRecord(change.getEntity(), scope, propsDeleted, tagsDeleted);
// and publish
MetadataPayload payload = new MetadataPayloadBuilder().addPrevious(previous).addAdditions(additions).addDeletions(deletions).build();
AuditPublishers.publishAudit(auditPublisher, previous.getMetadataEntity(), AuditType.METADATA_CHANGE, payload);
}
Aggregations