Search in sources :

Example 1 with TransientDataAccessException

use of org.springframework.dao.TransientDataAccessException in project cloudbreak by hortonworks.

the class ResourcePersistenceHandler method accept.

@Override
public void accept(Event<ResourceNotification> event) {
    LOGGER.info("Resource notification event received: {}", event);
    ResourceNotification notification = event.getData();
    RetryUtil.withDefaultRetries().retry(() -> {
        ResourceNotification notificationPersisted;
        switch(notification.getType()) {
            case CREATE:
                notificationPersisted = cloudResourcePersisterService.persist(notification);
                break;
            case UPDATE:
                notificationPersisted = cloudResourcePersisterService.update(notification);
                break;
            case DELETE:
                notificationPersisted = cloudResourcePersisterService.delete(notification);
                break;
            default:
                throw new IllegalArgumentException("Unsupported notification type: " + notification.getType());
        }
        notificationPersisted.getPromise().onNext(new ResourcePersisted());
    }).checkIfRecoverable(e -> e instanceof TransientDataAccessException).ifNotRecoverable(e -> notification.getPromise().onError(e)).run();
}
Also used : Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) Logger(org.slf4j.Logger) TransientDataAccessException(org.springframework.dao.TransientDataAccessException) Event(reactor.bus.Event) Persister(com.sequenceiq.cloudbreak.cloud.service.Persister) LoggerFactory(org.slf4j.LoggerFactory) ResourceNotification(com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification) ResourcePersisted(com.sequenceiq.cloudbreak.cloud.notification.model.ResourcePersisted) Consumer(reactor.fn.Consumer) RetryUtil(com.sequenceiq.cloudbreak.cloud.retry.RetryUtil) ResourceNotification(com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification) TransientDataAccessException(org.springframework.dao.TransientDataAccessException) ResourcePersisted(com.sequenceiq.cloudbreak.cloud.notification.model.ResourcePersisted)

Aggregations

ResourceNotification (com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification)1 ResourcePersisted (com.sequenceiq.cloudbreak.cloud.notification.model.ResourcePersisted)1 RetryUtil (com.sequenceiq.cloudbreak.cloud.retry.RetryUtil)1 Persister (com.sequenceiq.cloudbreak.cloud.service.Persister)1 Inject (javax.inject.Inject)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 TransientDataAccessException (org.springframework.dao.TransientDataAccessException)1 Component (org.springframework.stereotype.Component)1 Event (reactor.bus.Event)1 Consumer (reactor.fn.Consumer)1