Search in sources :

Example 1 with AuditPayload

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

Example 2 with AuditPayload

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

Aggregations

AuditMessage (io.cdap.cdap.proto.audit.AuditMessage)2 AuditPayload (io.cdap.cdap.proto.audit.AuditPayload)2 MetadataPayload (io.cdap.cdap.proto.audit.payload.metadata.MetadataPayload)2 JsonObject (com.google.gson.JsonObject)1 Metadata (io.cdap.cdap.api.metadata.Metadata)1 MetadataEntity (io.cdap.cdap.api.metadata.MetadataEntity)1 MetadataScope (io.cdap.cdap.api.metadata.MetadataScope)1 AuditType (io.cdap.cdap.proto.audit.AuditType)1 AccessPayload (io.cdap.cdap.proto.audit.payload.access.AccessPayload)1 EntityId (io.cdap.cdap.proto.id.EntityId)1