Search in sources :

Example 1 with Event

use of reactor.bus.Event in project cloudbreak by hortonworks.

the class CollectMetadataHandler method accept.

@Override
public void accept(Event<CollectMetadataRequest> collectMetadataRequestEvent) {
    LOGGER.info("Received event: {}", collectMetadataRequestEvent);
    CollectMetadataRequest request = collectMetadataRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        List<CloudVmMetaDataStatus> instanceStatuses = connector.metadata().collect(ac, request.getCloudResource(), request.getVms());
        CollectMetadataResult collectMetadataResult = new CollectMetadataResult(request, instanceStatuses);
        request.getResult().onNext(collectMetadataResult);
        eventBus.notify(collectMetadataResult.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), collectMetadataResult));
        LOGGER.info("Metadata collection successfully finished");
    } catch (RuntimeException e) {
        CollectMetadataResult failure = new CollectMetadataResult(e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), failure));
    }
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)

Example 2 with Event

use of reactor.bus.Event in project cloudbreak by hortonworks.

the class UnhealthyInstancesDetectionHandlerTest method shouldCreateResponseWithExactInstances.

@Test
public void shouldCreateResponseWithExactInstances() throws CloudbreakSecuritySetupException {
    long stackId = 1L;
    UnhealthyInstancesDetectionRequest unhealthyInstancesDetectionRequest = new UnhealthyInstancesDetectionRequest(stackId);
    Event event = mock(Event.class);
    when(event.getData()).thenReturn(unhealthyInstancesDetectionRequest);
    Stack stack = mock(Stack.class);
    when(stackService.getById(stackId)).thenReturn(stack);
    Set<InstanceMetaData> unhealthyInstances = new HashSet<>();
    InstanceMetaData imd1 = mock(InstanceMetaData.class);
    InstanceMetaData imd2 = mock(InstanceMetaData.class);
    InstanceMetaData imd3 = mock(InstanceMetaData.class);
    unhealthyInstances.add(imd1);
    unhealthyInstances.add(imd2);
    unhealthyInstances.add(imd3);
    when(candidateUnhealthyInstanceSelector.selectCandidateUnhealthyInstances(stack.getId())).thenReturn(unhealthyInstances);
    Set<String> unhealthyInstanceIds = new HashSet<>();
    unhealthyInstanceIds.add("i-0f1e0605506aaaaaa");
    unhealthyInstanceIds.add("i-0f1e0605506cccccc");
    when(unhealthyInstancesFinalizer.finalizeUnhealthyInstances(stack, unhealthyInstances)).thenReturn(unhealthyInstanceIds);
    unhealthyInstancesDetectionHandler.accept(event);
    verify(eventBus).notify(eq(EventSelectorUtil.selector(UnhealthyInstancesDetectionResult.class)), argThat(new UnhealthyInstancesResultMatcher(unhealthyInstanceIds)));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Event(reactor.bus.Event) UnhealthyInstancesDetectionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest) Stack(com.sequenceiq.cloudbreak.domain.Stack) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Event

use of reactor.bus.Event in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method setUp.

@Before
public void setUp() {
    reset(reactor);
    reset(eventFactory);
    when(reactor.notify((Object) anyObject(), any(Event.class))).thenReturn(new EventBus(new ThreadPoolExecutorDispatcher(1, 1)));
    Acceptable acceptable = new Acceptable() {

        @Override
        public Promise<Boolean> accepted() {
            Promise<Boolean> a = new Promise<>();
            a.accept(true);
            return a;
        }

        @Override
        public Long getStackId() {
            return stackId;
        }
    };
    Stack stack = TestUtil.stack();
    stack.setCluster(TestUtil.cluster());
    when(stackService.get(anyLong())).thenReturn(stack);
    when(stackService.getById(anyLong())).thenReturn(TestUtil.stack());
    when(stackService.getByIdView(anyLong())).thenReturn(TestUtil.stackView());
    when(eventFactory.createEventWithErrHandler(anyObject())).thenReturn(new Event<>(acceptable));
}
Also used : Promise(reactor.rx.Promise) Acceptable(com.sequenceiq.cloudbreak.cloud.Acceptable) Event(reactor.bus.Event) ClusterTerminationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.termination.ClusterTerminationEvent) ThreadPoolExecutorDispatcher(reactor.core.dispatch.ThreadPoolExecutorDispatcher) EventBus(reactor.bus.EventBus) Stack(com.sequenceiq.cloudbreak.domain.Stack) Before(org.junit.Before)

Example 4 with Event

use of reactor.bus.Event in project cloudbreak by hortonworks.

the class LogContextAspects method buildLogContextForCloudPlatformEventHandler.

@Before("com.sequenceiq.cloudbreak.logger.LogContextAspects.interceptCloudPlatformEventHandlersAcceptMethod()")
public void buildLogContextForCloudPlatformEventHandler(JoinPoint joinPoint) {
    Event<CloudPlatformRequest> event = (Event<CloudPlatformRequest>) joinPoint.getArgs()[0];
    CloudPlatformRequest cloudPlatformRequest = event.getData();
    CloudContext cloudContext = cloudPlatformRequest.getCloudContext();
    buildMdcContext(cloudContext, event);
    LOGGER.info("A CloudPlatformEventHandler's 'accept' method has been intercepted: {}, MDC logger context is built.", joinPoint.toShortString());
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) CloudPlatformRequest(com.sequenceiq.cloudbreak.cloud.event.CloudPlatformRequest) Before(org.aspectj.lang.annotation.Before)

Example 5 with Event

use of reactor.bus.Event in project cloudbreak by hortonworks.

the class StartStackHandler method accept.

@Override
public void accept(Event<StartInstancesRequest> event) {
    LOGGER.info("Received event: {}", event);
    StartInstancesRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudInstance> instances = request.getCloudInstances();
        List<CloudVmInstanceStatus> instanceStatuses = connector.instances().start(authenticatedContext, request.getResources(), instances);
        PollTask<InstancesStatusResult> task = statusCheckFactory.newPollInstanceStateTask(authenticatedContext, instances, Sets.newHashSet(InstanceStatus.STARTED, InstanceStatus.FAILED));
        InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, instanceStatuses);
        if (!task.completed(statusResult)) {
            statusResult = syncPollingScheduler.schedule(task);
        }
        StartInstancesResult result = new StartInstancesResult(request, cloudContext, statusResult);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    } catch (Exception e) {
        StartInstancesResult failure = new StartInstancesResult("Failed to start stack", e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) StartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) InstancesStatusResult(com.sequenceiq.cloudbreak.cloud.event.instance.InstancesStatusResult) StartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesResult) Event(reactor.bus.Event)

Aggregations

Event (reactor.bus.Event)16 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)10 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)10 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)3 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 InstancesStatusResult (com.sequenceiq.cloudbreak.cloud.event.instance.InstancesStatusResult)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)2 ResourceNotification (com.sequenceiq.cloudbreak.cloud.notification.model.ResourceNotification)2 UnhealthyInstancesDetectionRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest)2 Before (org.aspectj.lang.annotation.Before)2 Test (org.junit.Test)2 Acceptable (com.sequenceiq.cloudbreak.cloud.Acceptable)1 CloudPlatformRequest (com.sequenceiq.cloudbreak.cloud.event.CloudPlatformRequest)1