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);
}
}
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);
}
}
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);
}
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);
}
}
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);
}
}
Aggregations