Search in sources :

Example 1 with StopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesResult in project cloudbreak by hortonworks.

the class StopStackComponentTest method testStopStack.

@Test
public void testStopStack() {
    StopInstancesResult result = sendCloudRequest();
    assertEquals(1, result.getResults().getResults().size());
    assertEquals(InstanceStatus.STOPPED, result.getResults().getResults().get(0).getStatus());
    assertFalse(result.getStatus().equals(EventStatus.FAILED));
    assertNull(result.getErrorDetails());
}
Also used : StopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesResult) Test(org.junit.Test)

Example 2 with StopInstancesResult

use of com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesResult in project cloudbreak by hortonworks.

the class StopStackHandler method accept.

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

Aggregations

StopInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesResult)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 InstancesStatusResult (com.sequenceiq.cloudbreak.cloud.event.instance.InstancesStatusResult)1 StopInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesRequest)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 Test (org.junit.Test)1 Event (reactor.bus.Event)1