@Test public void returnsUnknownStatusWhenUnsupported() { when(instanceStateQuery.getCloudVmInstanceStatuses(any(), any(), eq(instances))) .thenThrow(new CloudOperationNotSupportedException("No check on mock cloud")); subject.accept(event); verifyResult(new GetInstancesStateResult(request.getResourceId(), allInstancesInStatus(InstanceStatus.UNKNOWN))); }
@Override public void accept(Event<GetInstancesStateRequest> event) { LOGGER.debug("Received event: {}", event); GetInstancesStateRequest<GetInstancesStateResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); GetInstancesStateResult result; try { List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses( request.getCloudCredential(), cloudContext, request.getInstances()); result = new GetInstancesStateResult(request.getResourceId(), instanceStatuses); } catch (CloudOperationNotSupportedException e) { List<CloudVmInstanceStatus> unknownStatuses = request.getInstances().stream() .map(instance -> new CloudVmInstanceStatus(instance, InstanceStatus.UNKNOWN)) .collect(Collectors.toList()); result = new GetInstancesStateResult(request.getResourceId(), unknownStatuses); } catch (RuntimeException e) { result = new GetInstancesStateResult("Instance state synchronizing failed", e, request.getResourceId()); } request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }
InstanceStateHandler implements CloudPlatformEventHandler<GetInstancesStateRequest> { @Override public void accept(Event<GetInstancesStateRequest> event) { LOGGER.debug("Received event: {}", event); GetInstancesStateRequest<GetInstancesStateResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); GetInstancesStateResult result; try { List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses( request.getCloudCredential(), cloudContext, request.getInstances()); result = new GetInstancesStateResult(request.getResourceId(), instanceStatuses); } catch (CloudOperationNotSupportedException e) { List<CloudVmInstanceStatus> unknownStatuses = request.getInstances().stream() .map(instance -> new CloudVmInstanceStatus(instance, InstanceStatus.UNKNOWN)) .collect(Collectors.toList()); result = new GetInstancesStateResult(request.getResourceId(), unknownStatuses); } catch (RuntimeException e) { result = new GetInstancesStateResult("Instance state synchronizing failed", e, request.getResourceId()); } request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); } }
InstanceStateHandler implements CloudPlatformEventHandler<GetInstancesStateRequest> { @Override public void accept(Event<GetInstancesStateRequest> event) { LOGGER.debug("Received event: {}", event); GetInstancesStateRequest<GetInstancesStateResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); GetInstancesStateResult result; try { List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses( request.getCloudCredential(), cloudContext, request.getInstances()); result = new GetInstancesStateResult(request.getResourceId(), instanceStatuses); } catch (CloudOperationNotSupportedException e) { List<CloudVmInstanceStatus> unknownStatuses = request.getInstances().stream() .map(instance -> new CloudVmInstanceStatus(instance, InstanceStatus.UNKNOWN)) .collect(Collectors.toList()); result = new GetInstancesStateResult(request.getResourceId(), unknownStatuses); } catch (RuntimeException e) { result = new GetInstancesStateResult("Instance state synchronizing failed", e, request.getResourceId()); } request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }  }
InstanceStateHandler implements CloudPlatformEventHandler<GetInstancesStateRequest> { @Override public void accept(Event<GetInstancesStateRequest> event) { LOGGER.debug("Received event: {}", event); GetInstancesStateRequest<GetInstancesStateResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); GetInstancesStateResult result; try { List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses( request.getCloudCredential(), cloudContext, request.getInstances()); result = new GetInstancesStateResult(request.getResourceId(), instanceStatuses); } catch (CloudOperationNotSupportedException e) { List<CloudVmInstanceStatus> unknownStatuses = request.getInstances().stream() .map(instance -> new CloudVmInstanceStatus(instance, InstanceStatus.UNKNOWN)) .collect(Collectors.toList()); result = new GetInstancesStateResult(request.getResourceId(), unknownStatuses); } catch (RuntimeException e) { result = new GetInstancesStateResult("Instance state synchronizing failed", e, request.getResourceId()); } request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }  @Override Class<GetInstancesStateRequest> type(); @Override void accept(Event<GetInstancesStateRequest> event); }
InstanceStateHandler implements CloudPlatformEventHandler<GetInstancesStateRequest> { @Override public void accept(Event<GetInstancesStateRequest> event) { LOGGER.debug("Received event: {}", event); GetInstancesStateRequest<GetInstancesStateResult> request = event.getData(); CloudContext cloudContext = request.getCloudContext(); GetInstancesStateResult result; try { List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses( request.getCloudCredential(), cloudContext, request.getInstances()); result = new GetInstancesStateResult(request.getResourceId(), instanceStatuses); } catch (CloudOperationNotSupportedException e) { List<CloudVmInstanceStatus> unknownStatuses = request.getInstances().stream() .map(instance -> new CloudVmInstanceStatus(instance, InstanceStatus.UNKNOWN)) .collect(Collectors.toList()); result = new GetInstancesStateResult(request.getResourceId(), unknownStatuses); } catch (RuntimeException e) { result = new GetInstancesStateResult("Instance state synchronizing failed", e, request.getResourceId()); } request.getResult().onNext(result); eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result)); }  @Override Class<GetInstancesStateRequest> type(); @Override void accept(Event<GetInstancesStateRequest> event);  }