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));
}
}
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)));
}
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));
}
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());
}
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));
}
}
Aggregations