Search in sources :

Example 6 with MetadataMessage

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

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 7 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 8 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)

Example 9 with MetadataMessage

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

the class MetadataSubscriberService method processMessages.

@Override
protected void processMessages(StructuredTableContext structuredTableContext, Iterator<ImmutablePair<String, MetadataMessage>> messages) throws IOException, ConflictException {
    Map<MetadataMessage.Type, MetadataMessageProcessor> processors = new HashMap<>();
    // Loop over all fetched messages and process them with corresponding MetadataMessageProcessor
    while (messages.hasNext()) {
        ImmutablePair<String, MetadataMessage> next = messages.next();
        String messageId = next.getFirst();
        MetadataMessage message = next.getSecond();
        MetadataMessageProcessor processor = processors.computeIfAbsent(message.getType(), type -> {
            switch(type) {
                case LINEAGE:
                    return new DataAccessLineageProcessor();
                case FIELD_LINEAGE:
                    return new FieldLineageProcessor();
                case USAGE:
                    return new UsageProcessor();
                case WORKFLOW_TOKEN:
                case WORKFLOW_STATE:
                    return new WorkflowProcessor();
                case METADATA_OPERATION:
                    return new MetadataOperationProcessor(cConf);
                case PROFILE_ASSIGNMENT:
                case PROFILE_UNASSIGNMENT:
                case ENTITY_CREATION:
                case ENTITY_DELETION:
                    return new ProfileMetadataMessageProcessor(metadataStorage, structuredTableContext, metricsCollectionService);
                default:
                    return null;
            }
        });
        // noinspection ConstantConditions
        if (processor == null) {
            LOG.warn("Unsupported metadata message type {}. Message ignored.", message.getType());
            continue;
        }
        try {
            processor.processMessage(message, structuredTableContext);
            conflictCount = 0;
        } catch (ConflictException e) {
            if (messageId.equals(conflictMessageId)) {
                conflictCount++;
                if (conflictCount >= maxRetriesOnConflict) {
                    LOG.warn("Skipping metadata message {} after processing it has caused {} consecutive conflicts: {}", message, conflictCount, e.getMessage());
                    continue;
                }
            } else {
                conflictMessageId = messageId;
                conflictCount = 1;
            }
            throw e;
        }
    }
}
Also used : HashMap(java.util.HashMap) ConflictException(io.cdap.cdap.common.ConflictException) ProfileMetadataMessageProcessor(io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor) EntityType(io.cdap.cdap.proto.element.EntityType) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) ProfileMetadataMessageProcessor(io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor)

Example 10 with MetadataMessage

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

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)

Aggregations

MetadataMessage (io.cdap.cdap.data2.metadata.writer.MetadataMessage)12 StoreRequest (io.cdap.cdap.messaging.StoreRequest)8 Iterables (com.google.common.collect.Iterables)2 Gson (com.google.gson.Gson)2 Inject (com.google.inject.Inject)2 TopicNotFoundException (io.cdap.cdap.api.messaging.TopicNotFoundException)2 RetryableException (io.cdap.cdap.api.retry.RetryableException)2 AccessException (io.cdap.cdap.api.security.AccessException)2 ConflictException (io.cdap.cdap.common.ConflictException)2 ServiceUnavailableException (io.cdap.cdap.common.ServiceUnavailableException)2 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 Constants (io.cdap.cdap.common.conf.Constants)2 Retries (io.cdap.cdap.common.service.Retries)2 RetryStrategies (io.cdap.cdap.common.service.RetryStrategies)2 RetryStrategy (io.cdap.cdap.common.service.RetryStrategy)2 MessagingService (io.cdap.cdap.messaging.MessagingService)2 StoreRequestBuilder (io.cdap.cdap.messaging.client.StoreRequestBuilder)2 ProfileMetadataMessageProcessor (io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor)2 EntityType (io.cdap.cdap.proto.element.EntityType)2 DatasetId (io.cdap.cdap.proto.id.DatasetId)2