Search in sources :

Example 31 with EventListener

use of org.springframework.context.event.EventListener in project metacat by Netflix.

the class SNSNotificationServiceImpl method notifyOfTableUpdate.

/**
 * {@inheritDoc}
 */
@Override
@EventListener
public void notifyOfTableUpdate(final MetacatUpdateTablePostEvent event) {
    log.debug("Received UpdateTableEvent {}", event);
    UpdateTableMessage message = null;
    try {
        message = this.createUpdateTableMessage(UUID.randomUUID().toString(), event.getRequestContext().getTimestamp(), event.getRequestContext().getId(), event.getName().toString(), event.getOldTable(), event.getCurrentTable());
        this.publishNotification(this.tableTopicArn, message, event.getName(), "Unable to publish update table notification", Metrics.CounterSNSNotificationTableUpdate.getMetricName(), true);
    } catch (final Exception e) {
        this.notificationMetric.handleException(event.getName(), "Unable to create json patch for update table notification", Metrics.CounterSNSNotificationTableUpdate.getMetricName(), message, e);
    }
}
Also used : UpdateTableMessage(com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTableMessage) InvalidParameterException(com.amazonaws.services.sns.model.InvalidParameterException) IOException(java.io.IOException) InvalidParameterValueException(com.amazonaws.services.sns.model.InvalidParameterValueException) EventListener(org.springframework.context.event.EventListener)

Example 32 with EventListener

use of org.springframework.context.event.EventListener in project metacat by Netflix.

the class ElasticSearchEventHandlers method metacatCreateTablePostEventHandler.

/**
 * Subscriber.
 *
 * @param event event
 */
@EventListener
public void metacatCreateTablePostEventHandler(final MetacatCreateTablePostEvent event) {
    log.debug("Received CreateTableEvent {}", event);
    this.tableCreateEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
    this.tableCreateTimer.record(() -> {
        final TableDto dto = event.getTable();
        final ElasticSearchDoc doc = new ElasticSearchDoc(dto.getName().toString(), dto, event.getRequestContext().getUserName(), false);
        es.save(ElasticSearchDoc.Type.table.name(), doc.getId(), doc);
    });
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) EventListener(org.springframework.context.event.EventListener)

Example 33 with EventListener

use of org.springframework.context.event.EventListener in project metacat by Netflix.

the class ElasticSearchEventHandlers method metacatUpdateTablePostEventHandler.

/**
 * Subscriber.
 *
 * @param event event
 */
@EventListener
public void metacatUpdateTablePostEventHandler(final MetacatUpdateTablePostEvent event) {
    log.debug("Received UpdateTableEvent {}", event);
    this.tableUpdateEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
    this.tableUpdateTimer.record(() -> {
        final TableDto dto = event.getCurrentTable();
        final ElasticSearchDoc doc = new ElasticSearchDoc(dto.getName().toString(), dto, event.getRequestContext().getUserName(), false);
        final ElasticSearchDoc oldDoc = es.get(ElasticSearchDoc.Type.table.name(), doc.getId());
        es.save(ElasticSearchDoc.Type.table.name(), doc.getId(), doc);
        if (oldDoc == null || oldDoc.getDto() == null || !Objects.equals(((TableDto) oldDoc.getDto()).getDataMetadata(), dto.getDataMetadata())) {
            updateEntitiesWithSameUri(ElasticSearchDoc.Type.table.name(), dto, event.getRequestContext().getUserName());
        }
    });
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) EventListener(org.springframework.context.event.EventListener)

Example 34 with EventListener

use of org.springframework.context.event.EventListener in project ArachneCentralAPI by OHDSI.

the class AntivirusServiceImpl method processRequest.

@EventListener
@Async(value = "antivirusScanExecutor")
public void processRequest(AntivirusJobEvent event) {
    final AntivirusJob antivirusJob = event.getAntivirusJob();
    final AntivirusJobFileType fileType = antivirusJob.getAntivirusJobFileType();
    final Long fileId = antivirusJob.getFileId();
    logger.debug(PROCESSING_SCAN_REQUEST, fileId, fileType);
    String description = null;
    AntivirusStatus status;
    try {
        final ScanResult scan = retryTemplate.execute((RetryCallback<ScanResult, Exception>) retryContext -> {
            logger.debug(PROCESSING_SCAN_ATTEMPT, fileId, fileType);
            return scan(antivirusJob.getContent());
        });
        if (scan instanceof ScanResult.OK) {
            status = AntivirusStatus.OK;
        } else {
            status = AntivirusStatus.INFECTED;
            description = scan.toString();
        }
    } catch (Exception e) {
        logger.error("Error scanning file: {}", e.getMessage());
        if (e instanceof ClamavException) {
            final Throwable cause = e.getCause();
            description = cause.getMessage();
        } else {
            description = e.getMessage();
        }
        status = AntivirusStatus.NOT_SCANNED;
    }
    logger.debug(PROCESSING_SCAN_RESULT, fileId, fileType, status);
    publishResponse(fileType, fileId, status, description);
}
Also used : Async(org.springframework.scheduling.annotation.Async) LoggerFactory(org.slf4j.LoggerFactory) AntivirusJobResponse(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse) Autowired(org.springframework.beans.factory.annotation.Autowired) ScanResult(xyz.capybara.clamav.commands.scan.result.ScanResult) AntivirusStatus(com.odysseusinc.arachne.portal.model.AntivirusStatus) AntivirusJobStudyFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobStudyFileResponseEvent) Value(org.springframework.beans.factory.annotation.Value) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ClamavException(xyz.capybara.clamav.ClamavException) AntivirusJobPaperProtocolFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperProtocolFileResponseEvent) Logger(org.slf4j.Logger) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) AntivirusJobAnalysisFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobAnalysisFileResponseEvent) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) AntivirusJobPaperPaperFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobPaperPaperFileResponseEvent) AntivirusJobResponseEventBase(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponseEventBase) ClamavClient(xyz.capybara.clamav.ClamavClient) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) RetryCallback(org.springframework.retry.RetryCallback) RetryTemplate(org.springframework.retry.support.RetryTemplate) InputStream(java.io.InputStream) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) ScanResult(xyz.capybara.clamav.commands.scan.result.ScanResult) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) AntivirusStatus(com.odysseusinc.arachne.portal.model.AntivirusStatus) ClamavException(xyz.capybara.clamav.ClamavException) IOException(java.io.IOException) ClamavException(xyz.capybara.clamav.ClamavException) Async(org.springframework.scheduling.annotation.Async) EventListener(org.springframework.context.event.EventListener)

Aggregations

EventListener (org.springframework.context.event.EventListener)34 TableDto (com.netflix.metacat.common.dto.TableDto)10 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)6 AbstractCasEvent (org.apereo.cas.support.events.AbstractCasEvent)4 CasEvent (org.apereo.cas.support.events.dao.CasEvent)4 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)3 AntivirusJobResponse (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse)3 IOException (java.io.IOException)3 List (java.util.List)3 Transactional (org.springframework.transaction.annotation.Transactional)3 InvalidParameterException (com.amazonaws.services.sns.model.InvalidParameterException)2 InvalidParameterValueException (com.amazonaws.services.sns.model.InvalidParameterValueException)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)2 NameDateDto (com.netflix.metacat.common.NameDateDto)2 QualifiedName (com.netflix.metacat.common.QualifiedName)2 UpdateTableMessage (com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTableMessage)2 UpdateTablePartitionsMessage (com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage)2 TablePartitionsUpdatePayload (com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload)2 MetacatJsonLocator (com.netflix.metacat.common.json.MetacatJsonLocator)2