use of io.cdap.cdap.data2.registry.DatasetUsage in project cdap by caskdata.
the class MessagingUsageWriter method doRegisterAll.
private void doRegisterAll(Iterable<? extends EntityId> users, EntityId entityId) throws Exception {
// Only record usage from program
StoreRequest request = StoreRequestBuilder.of(topic).addPayloads(StreamSupport.stream(users.spliterator(), false).filter(ProgramId.class::isInstance).map(ProgramId.class::cast).map(id -> new MetadataMessage(MetadataMessage.Type.USAGE, id, GSON.toJsonTree(new DatasetUsage(entityId)))).map(GSON::toJson).map(s -> s.getBytes(StandardCharsets.UTF_8)).iterator()).build();
Retries.callWithRetries(() -> messagingService.publish(request), retryStrategy, Retries.ALWAYS_TRUE);
}
use of io.cdap.cdap.data2.registry.DatasetUsage in project cdap by caskdata.
the class MessagingUsageWriter method register.
@Override
public void register(ProgramId programId, DatasetId datasetId) {
MetadataMessage message = new MetadataMessage(MetadataMessage.Type.USAGE, programId, GSON.toJsonTree(new DatasetUsage(datasetId)));
StoreRequest request = StoreRequestBuilder.of(topic).addPayload(GSON.toJson(message)).build();
try {
Retries.callWithRetries(() -> messagingService.publish(request), retryStrategy, Retries.ALWAYS_TRUE);
} catch (Exception e) {
throw new RuntimeException("Failed to publish usage for " + datasetId + " for program " + programId, e);
}
}
Aggregations