Search in sources :

Example 1 with MetadataMessage

use of io.cdap.cdap.data2.metadata.writer.MetadataMessage in project cdap by caskdata.

the class AdminEventPublisher method publishMessage.

private void publishMessage(EntityId entityId, MetadataMessage.Type type, Object payload) {
    MetadataMessage message = new MetadataMessage(type, entityId, GSON.toJsonTree(payload));
    LOG.trace("Publishing message: {}", message);
    try {
        Retries.supplyWithRetries(() -> {
            try {
                messagingContext.getMessagePublisher().publish(NamespaceId.SYSTEM.getNamespace(), topic.getTopic(), GSON.toJson(message));
            } catch (TopicNotFoundException | ServiceUnavailableException e) {
                throw new RetryableException(e);
            } catch (IOException | AccessException e) {
                throw Throwables.propagate(e);
            }
            return null;
        }, retryStrategy);
    } catch (Exception e) {
        throw new RuntimeException(String.format("Failed to publish profile metadata request for entity id %s", entityId), e);
    }
}
Also used : RetryableException(io.cdap.cdap.api.retry.RetryableException) AccessException(io.cdap.cdap.api.security.AccessException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) IOException(java.io.IOException) AccessException(io.cdap.cdap.api.security.AccessException) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) RetryableException(io.cdap.cdap.api.retry.RetryableException) IOException(java.io.IOException) TopicNotFoundException(io.cdap.cdap.api.messaging.TopicNotFoundException)

Example 2 with MetadataMessage

use of io.cdap.cdap.data2.metadata.writer.MetadataMessage in project cdap by caskdata.

the class MessagingWorkflowStateWriter method setWorkflowToken.

@Override
public void setWorkflowToken(ProgramRunId workflowRunId, WorkflowToken token) {
    MetadataMessage message = new MetadataMessage(MetadataMessage.Type.WORKFLOW_TOKEN, workflowRunId, GSON.toJsonTree(token));
    StoreRequest request = StoreRequestBuilder.of(topic).addPayload(GSON.toJson(message)).build();
    try {
        Retries.callWithRetries(() -> messagingService.publish(request), retryStrategy, Retries.ALWAYS_TRUE);
    } catch (Exception e) {
        // Don't log the workflow token, as it can be large and may contain sensitive data
        throw new RuntimeException("Failed to publish workflow token for workflow run " + workflowRunId, e);
    }
}
Also used : MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) StoreRequest(io.cdap.cdap.messaging.StoreRequest)

Example 3 with MetadataMessage

use of io.cdap.cdap.data2.metadata.writer.MetadataMessage 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 4 with MetadataMessage

use of io.cdap.cdap.data2.metadata.writer.MetadataMessage in project cdap by caskdata.

the class MessagingWorkflowStateWriter method addWorkflowNodeState.

@Override
public void addWorkflowNodeState(ProgramRunId workflowRunId, WorkflowNodeStateDetail state) {
    MetadataMessage message = new MetadataMessage(MetadataMessage.Type.WORKFLOW_STATE, workflowRunId, GSON.toJsonTree(state));
    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 workflow node state for workflow run " + workflowRunId + "of node " + state.getNodeId() + " with state " + state.getNodeStatus(), e);
    }
}
Also used : MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) StoreRequest(io.cdap.cdap.messaging.StoreRequest)

Example 5 with MetadataMessage

use of io.cdap.cdap.data2.metadata.writer.MetadataMessage 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)6 StoreRequest (io.cdap.cdap.messaging.StoreRequest)4 Iterables (com.google.common.collect.Iterables)1 Gson (com.google.gson.Gson)1 Inject (com.google.inject.Inject)1 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)1 RetryableException (io.cdap.cdap.api.retry.RetryableException)1 AccessException (io.cdap.cdap.api.security.AccessException)1 ConflictException (io.cdap.cdap.common.ConflictException)1 ServiceUnavailableException (io.cdap.cdap.common.ServiceUnavailableException)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 ProfileMetadataMessageProcessor (io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor)1 EntityType (io.cdap.cdap.proto.element.EntityType)1 DatasetId (io.cdap.cdap.proto.id.DatasetId)1