Search in sources :

Example 1 with DatasetUsage

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);
}
Also used : Retries(io.cdap.cdap.common.service.Retries) RetryStrategy(io.cdap.cdap.common.service.RetryStrategy) Iterables(com.google.common.collect.Iterables) StoreRequestBuilder(io.cdap.cdap.messaging.client.StoreRequestBuilder) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Inject(com.google.inject.Inject) MessagingService(io.cdap.cdap.messaging.MessagingService) ProgramId(io.cdap.cdap.proto.id.ProgramId) RetryStrategies(io.cdap.cdap.common.service.RetryStrategies) StoreRequest(io.cdap.cdap.messaging.StoreRequest) EntityId(io.cdap.cdap.proto.id.EntityId) TopicId(io.cdap.cdap.proto.id.TopicId) StandardCharsets(java.nio.charset.StandardCharsets) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) DatasetId(io.cdap.cdap.proto.id.DatasetId) Gson(com.google.gson.Gson) Constants(io.cdap.cdap.common.conf.Constants) StreamSupport(java.util.stream.StreamSupport) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) StoreRequest(io.cdap.cdap.messaging.StoreRequest) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) ProgramId(io.cdap.cdap.proto.id.ProgramId)

Example 2 with DatasetUsage

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);
    }
}
Also used : MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) StoreRequest(io.cdap.cdap.messaging.StoreRequest)

Aggregations

MetadataMessage (io.cdap.cdap.data2.metadata.writer.MetadataMessage)2 StoreRequest (io.cdap.cdap.messaging.StoreRequest)2 Iterables (com.google.common.collect.Iterables)1 Gson (com.google.gson.Gson)1 Inject (com.google.inject.Inject)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 Constants (io.cdap.cdap.common.conf.Constants)1 Retries (io.cdap.cdap.common.service.Retries)1 RetryStrategies (io.cdap.cdap.common.service.RetryStrategies)1 RetryStrategy (io.cdap.cdap.common.service.RetryStrategy)1 MessagingService (io.cdap.cdap.messaging.MessagingService)1 StoreRequestBuilder (io.cdap.cdap.messaging.client.StoreRequestBuilder)1 DatasetId (io.cdap.cdap.proto.id.DatasetId)1 EntityId (io.cdap.cdap.proto.id.EntityId)1 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)1 ProgramId (io.cdap.cdap.proto.id.ProgramId)1 TopicId (io.cdap.cdap.proto.id.TopicId)1 StandardCharsets (java.nio.charset.StandardCharsets)1 StreamSupport (java.util.stream.StreamSupport)1