Search in sources :

Example 1 with ResourceNotification

use of com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification in project cloudbreak by hortonworks.

the class ResourceNotifier method notifyAllocation.

@Override
public ResourcePersisted notifyAllocation(CloudResource cloudResource, CloudContext cloudContext) {
    ResourceNotification notification = new ResourceNotification(cloudResource, cloudContext, ResourceNotificationType.CREATE);
    LOGGER.info("Sending resource allocation notification: {}, context: {}", notification, cloudContext);
    eventBus.notify("resource-persisted", eventFactory.createEvent(notification));
    return notification.getResult();
}
Also used : ResourceNotification(com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification)

Example 2 with ResourceNotification

use of com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification in project cloudbreak by hortonworks.

the class ResourceNotifier method notifyDeletion.

@Override
public ResourcePersisted notifyDeletion(CloudResource cloudResource, CloudContext cloudContext) {
    ResourceNotification notification = new ResourceNotification(cloudResource, cloudContext, ResourceNotificationType.DELETE);
    LOGGER.info("Sending resource deletion notification: {}, context: {}", notification, cloudContext);
    eventBus.notify("resource-persisted", eventFactory.createEvent(notification));
    return notification.getResult();
}
Also used : ResourceNotification(com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification)

Example 3 with ResourceNotification

use of com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification in project cloudbreak by hortonworks.

the class ResourceNotifier method notifyUpdate.

@Override
public ResourcePersisted notifyUpdate(CloudResource cloudResource, CloudContext cloudContext) {
    ResourceNotification notification = new ResourceNotification(cloudResource, cloudContext, ResourceNotificationType.UPDATE);
    LOGGER.info("Sending resource update notification: {}, context: {}", notification, cloudContext);
    eventBus.notify("resource-persisted", eventFactory.createEvent(notification));
    return notification.getResult();
}
Also used : ResourceNotification(com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification)

Example 4 with ResourceNotification

use of com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification 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)

Example 5 with ResourceNotification

use of com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification in project cloudbreak by hortonworks.

the class LogContextAspects method buildLogContextForPersistenceHandler.

@Before("com.sequenceiq.cloudbreak.logger.LogContextAspects.interceptResourcePersistenceHandlerAcceptMethod()")
public void buildLogContextForPersistenceHandler(JoinPoint joinPoint) {
    Event<ResourceNotification> event = (Event<ResourceNotification>) joinPoint.getArgs()[0];
    CloudContext cloudContext = event.getData().getCloudContext();
    buildMdcContext(cloudContext, event);
    LOGGER.debug("A Resource persistence handler's 'accept' method has been intercepted: {}, MDC logger context is built.", joinPoint.toShortString());
}
Also used : ResourceNotification(com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) Before(org.aspectj.lang.annotation.Before)

Aggregations

ResourceNotification (com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification)5 Event (reactor.bus.Event)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)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 Before (org.aspectj.lang.annotation.Before)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 TransientDataAccessException (org.springframework.dao.TransientDataAccessException)1 Component (org.springframework.stereotype.Component)1 Consumer (reactor.fn.Consumer)1