Search in sources :

Example 1 with AuditPayload

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;
}
Also used : AuditMessage(co.cask.cdap.proto.audit.AuditMessage) Metadata(co.cask.cdap.api.metadata.Metadata) AuditPayload(co.cask.cdap.proto.audit.AuditPayload) HashSet(java.util.HashSet) MetadataPayload(co.cask.cdap.proto.audit.payload.metadata.MetadataPayload) MetadataScope(co.cask.cdap.api.metadata.MetadataScope)

Example 2 with AuditPayload

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);
}
Also used : EntityId(co.cask.cdap.proto.id.EntityId) AccessPayload(co.cask.cdap.proto.audit.payload.access.AccessPayload) AuditMessage(co.cask.cdap.proto.audit.AuditMessage) AuditType(co.cask.cdap.proto.audit.AuditType) JsonObject(com.google.gson.JsonObject) AuditPayload(co.cask.cdap.proto.audit.AuditPayload) MetadataPayload(co.cask.cdap.proto.audit.payload.metadata.MetadataPayload)

Aggregations

AuditMessage (co.cask.cdap.proto.audit.AuditMessage)2 AuditPayload (co.cask.cdap.proto.audit.AuditPayload)2 MetadataPayload (co.cask.cdap.proto.audit.payload.metadata.MetadataPayload)2 Metadata (co.cask.cdap.api.metadata.Metadata)1 MetadataScope (co.cask.cdap.api.metadata.MetadataScope)1 AuditType (co.cask.cdap.proto.audit.AuditType)1 AccessPayload (co.cask.cdap.proto.audit.payload.access.AccessPayload)1 EntityId (co.cask.cdap.proto.id.EntityId)1 JsonObject (com.google.gson.JsonObject)1 HashSet (java.util.HashSet)1