use of com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest in project cloudbreak by hortonworks.
the class InstanceStateHandler method accept.
@Override
public void accept(Event<GetInstancesStateRequest> event) {
LOGGER.info("Received event: {}", event);
GetInstancesStateRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
GetInstancesStateResult result;
try {
List<CloudVmInstanceStatus> instanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(request.getCloudCredential(), cloudContext, request.getInstances());
result = new GetInstancesStateResult(request, instanceStatuses);
} catch (RuntimeException e) {
result = new GetInstancesStateResult("Instance state synchronizing failed", e, request);
}
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest in project cloudbreak by hortonworks.
the class ServiceProviderMetadataAdapter method getState.
public InstanceSyncState getState(Stack stack, InstanceGroup instanceGroup, String instanceId) {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
InstanceGroup ig = stack.getInstanceGroupByInstanceGroupName(instanceGroup.getGroupName());
CloudInstance instance = null;
for (InstanceMetaData metaData : ig.getAllInstanceMetaData()) {
if (instanceId.equalsIgnoreCase(metaData.getInstanceId())) {
instance = metadataConverter.convert(metaData);
break;
}
}
if (instance != null) {
GetInstancesStateRequest<GetInstancesStateResult> stateRequest = new GetInstancesStateRequest<>(cloudContext, cloudCredential, Collections.singletonList(instance));
LOGGER.info("Triggering event: {}", stateRequest);
eventBus.notify(stateRequest.selector(), eventFactory.createEvent(stateRequest));
try {
GetInstancesStateResult res = stateRequest.await();
LOGGER.info("Result: {}", res);
if (res.isFailed()) {
LOGGER.error("Failed to retrieve instance state", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return transform(res.getStatuses().get(0).getStatus());
} catch (InterruptedException e) {
LOGGER.error(format("Error while retrieving instance state of: %s", cloudContext), e);
throw new OperationException(e);
}
} else {
return InstanceSyncState.DELETED;
}
}
Aggregations