Search in sources :

Example 1 with GetInstancesStateRequest

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));
}
Also used : GetInstancesStateRequest(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) GetInstancesStateResult(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateResult)

Example 2 with GetInstancesStateRequest

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;
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) GetInstancesStateRequest(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) GetInstancesStateResult(com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 GetInstancesStateRequest (com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateRequest)2 GetInstancesStateResult (com.sequenceiq.cloudbreak.cloud.event.resource.GetInstancesStateResult)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)1