Search in sources :

Example 1 with TablePartitionsUpdatePayload

use of com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload in project metacat by Netflix.

the class SNSNotificationServiceImpl method notifyOfPartitionDeletion.

/**
     * {@inheritDoc}
     */
@Override
@EventListener
public void notifyOfPartitionDeletion(@NonNull final MetacatDeleteTablePartitionPostEvent event) {
    log.debug("Received DeleteTablePartition event {}", event);
    final String name = event.getName().toString();
    final long timestamp = event.getRequestContext().getTimestamp();
    final String requestId = event.getRequestContext().getId();
    DeletePartitionMessage message = null;
    try {
        for (final String partitionId : event.getPartitionIds()) {
            message = new DeletePartitionMessage(UUID.randomUUID().toString(), timestamp, requestId, name, partitionId);
            this.publishNotification(this.partitionTopicArn, message);
            this.registry.counter(this.registry.createId(Metrics.CounterSNSNotificationPartitionDelete.name()).withTags(Metrics.statusSuccessMap)).increment();
            log.debug("Published delete partition message {} on {}", message, this.partitionTopicArn);
        }
    } catch (final Exception e) {
        handleException(event.getName(), "Unable to publish partition deletion notification", Metrics.CounterSNSNotificationPartitionDelete.name(), message, e);
    }
    UpdateTablePartitionsMessage tableMessage = null;
    try {
        // Publish a global message stating how many partitions were updated for the table to the table topic
        tableMessage = new UpdateTablePartitionsMessage(UUID.randomUUID().toString(), timestamp, requestId, name, new TablePartitionsUpdatePayload(0, event.getPartitionIds().size()));
        this.publishNotification(this.tableTopicArn, tableMessage);
        this.registry.counter(this.registry.createId(Metrics.CounterSNSNotificationTablePartitionDelete.name()).withTags(Metrics.statusSuccessMap)).increment();
    } catch (final Exception e) {
        this.handleException(event.getName(), "Unable to publish table partition delete notification", Metrics.CounterSNSNotificationTablePartitionDelete.name(), tableMessage, e);
    }
}
Also used : TablePartitionsUpdatePayload(com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload) UpdateTablePartitionsMessage(com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage) DeletePartitionMessage(com.netflix.metacat.common.dto.notifications.sns.messages.DeletePartitionMessage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) EventListener(org.springframework.context.event.EventListener)

Example 2 with TablePartitionsUpdatePayload

use of com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload in project metacat by Netflix.

the class SNSNotificationServiceImpl method notifyOfPartitionAddition.

/**
     * {@inheritDoc}
     */
@Override
@EventListener
public void notifyOfPartitionAddition(@NonNull final MetacatSaveTablePartitionPostEvent event) {
    log.debug("Received SaveTablePartitionPostEvent {}", event);
    final String name = event.getName().toString();
    final long timestamp = event.getRequestContext().getTimestamp();
    final String requestId = event.getRequestContext().getId();
    AddPartitionMessage message = null;
    try {
        for (final PartitionDto partition : event.getPartitions()) {
            message = new AddPartitionMessage(UUID.randomUUID().toString(), timestamp, requestId, name, partition);
            this.publishNotification(this.partitionTopicArn, message);
            log.debug("Published create partition message {} on {}", message, this.partitionTopicArn);
            this.registry.counter(this.registry.createId(Metrics.CounterSNSNotificationPartitionAdd.name()).withTags(Metrics.statusSuccessMap)).increment();
        }
    } catch (final Exception e) {
        this.handleException(event.getName(), "Unable to publish partition creation notification", Metrics.CounterSNSNotificationPartitionAdd.name(), message, e);
    }
    UpdateTablePartitionsMessage tableMessage = null;
    try {
        // Publish a global message stating how many partitions were updated for the table to the table topic
        tableMessage = new UpdateTablePartitionsMessage(UUID.randomUUID().toString(), timestamp, requestId, name, new TablePartitionsUpdatePayload(event.getPartitions().size(), 0));
        this.publishNotification(this.tableTopicArn, tableMessage);
        this.registry.counter(this.registry.createId(Metrics.CounterSNSNotificationTablePartitionAdd.name()).withTags(Metrics.statusSuccessMap)).increment();
    } catch (final Exception e) {
        this.handleException(event.getName(), "Unable to publish table partition add notification", Metrics.CounterSNSNotificationTablePartitionAdd.name(), tableMessage, e);
    }
}
Also used : TablePartitionsUpdatePayload(com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) UpdateTablePartitionsMessage(com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage) AddPartitionMessage(com.netflix.metacat.common.dto.notifications.sns.messages.AddPartitionMessage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) EventListener(org.springframework.context.event.EventListener)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 UpdateTablePartitionsMessage (com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage)2 TablePartitionsUpdatePayload (com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload)2 IOException (java.io.IOException)2 EventListener (org.springframework.context.event.EventListener)2 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)1 AddPartitionMessage (com.netflix.metacat.common.dto.notifications.sns.messages.AddPartitionMessage)1 DeletePartitionMessage (com.netflix.metacat.common.dto.notifications.sns.messages.DeletePartitionMessage)1