Search in sources :

Example 1 with DetailedStackStatus

use of com.sequenceiq.cloudbreak.api.model.DetailedStackStatus in project cloudbreak by hortonworks.

the class StackUpdaterTest method updateStackStatusWithoutStatusReasonThenNoNotificationSentOnWebsocket.

@Test
public void updateStackStatusWithoutStatusReasonThenNoNotificationSentOnWebsocket() {
    Stack stack = TestUtil.stack();
    DetailedStackStatus newStatus = DetailedStackStatus.DELETE_COMPLETED;
    StackStatus testStackStatus = new StackStatus(stack, newStatus.getStatus(), "", newStatus);
    when(stackStatusRepository.save(any(StackStatus.class))).thenReturn(testStackStatus);
    when(stackRepository.findOne(anyLong())).thenReturn(stack);
    when(stackRepository.save(any(Stack.class))).thenReturn(stack);
    doNothing().when(cloudbreakEventService).fireCloudbreakEvent(anyLong(), anyString(), anyString());
    when(statusToPollGroupConverter.convert(newStatus.getStatus())).thenReturn(PollGroup.POLLABLE);
    Stack newStack = underTest.updateStackStatus(1L, DetailedStackStatus.DELETE_COMPLETED);
    assertEquals(newStatus.getStatus(), newStack.getStatus());
    assertEquals("", newStack.getStatusReason());
    verify(cloudbreakEventService, times(0)).fireCloudbreakEvent(anyLong(), anyString(), anyString());
}
Also used : DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Stack(com.sequenceiq.cloudbreak.domain.Stack) Test(org.junit.Test)

Example 2 with DetailedStackStatus

use of com.sequenceiq.cloudbreak.api.model.DetailedStackStatus in project cloudbreak by hortonworks.

the class StackTerminationService method handleStackTerminationError.

public void handleStackTerminationError(StackView stackView, StackFailureEvent payload, boolean forced, Boolean deleteDependencies) {
    String stackUpdateMessage;
    Msg eventMessage;
    DetailedStackStatus status;
    if (!forced) {
        Exception errorDetails = payload.getException();
        stackUpdateMessage = "Termination failed: " + errorDetails.getMessage();
        status = DetailedStackStatus.DELETE_FAILED;
        eventMessage = Msg.STACK_INFRASTRUCTURE_DELETE_FAILED;
        stackUpdater.updateStackStatus(stackView.getId(), status, stackUpdateMessage);
        LOGGER.error("Error during stack termination flow: ", errorDetails);
    } else {
        terminationService.finalizeTermination(stackView.getId(), true);
        clusterService.updateClusterStatusByStackId(stackView.getId(), DELETE_COMPLETED);
        stackUpdateMessage = "Stack was force terminated.";
        status = DetailedStackStatus.DELETE_COMPLETED;
        eventMessage = Msg.STACK_FORCED_DELETE_COMPLETED;
        if (deleteDependencies) {
            dependecyDeletionService.deleteDependencies(stackView);
        }
    }
    flowMessageService.fireEventAndLog(stackView.getId(), eventMessage, status.name(), stackUpdateMessage);
    if (stackView.getClusterView() != null && stackView.getClusterView().getEmailNeeded()) {
        String ambariIp = stackUtil.extractAmbariIp(stackView);
        if (forced) {
            emailSenderService.sendTerminationSuccessEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), ambariIp, stackView.getClusterView().getName());
        } else {
            emailSenderService.sendTerminationFailureEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), ambariIp, stackView.getClusterView().getName());
        }
        flowMessageService.fireEventAndLog(stackView.getId(), Msg.STACK_NOTIFICATION_EMAIL, status.name());
    }
}
Also used : Msg(com.sequenceiq.cloudbreak.core.flow2.stack.Msg) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)

Example 3 with DetailedStackStatus

use of com.sequenceiq.cloudbreak.api.model.DetailedStackStatus in project cloudbreak by hortonworks.

the class StackStartStopService method handleError.

private void handleError(StackView stackView, Exception exception, DetailedStackStatus detailedStackStatus, Msg msg, String logMessage) {
    LOGGER.error(logMessage, exception);
    Status stackStatus = detailedStackStatus.getStatus();
    stackUpdater.updateStackStatus(stackView.getId(), detailedStackStatus, logMessage + exception.getMessage());
    flowMessageService.fireEventAndLog(stackView.getId(), msg, stackStatus.name(), exception.getMessage());
    if (stackView.getClusterView() != null) {
        clusterService.updateClusterStatusByStackId(stackView.getId(), STOPPED);
        if (stackView.getClusterView().getEmailNeeded()) {
            emailSenderService.sendStopFailureEmail(stackView.getClusterView().getOwner(), stackView.getClusterView().getEmailTo(), stackUtil.extractAmbariIp(stackView), stackView.getClusterView().getName());
            flowMessageService.fireEventAndLog(stackView.getId(), Msg.STACK_NOTIFICATION_EMAIL, stackStatus.name());
        }
    }
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) BillingStatus(com.sequenceiq.cloudbreak.common.type.BillingStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)

Example 4 with DetailedStackStatus

use of com.sequenceiq.cloudbreak.api.model.DetailedStackStatus in project cloudbreak by hortonworks.

the class StackUpdaterTest method updateStackStatusAndReasonThenNotificationSentOnWebsocket.

@Test
public void updateStackStatusAndReasonThenNotificationSentOnWebsocket() {
    Stack stack = TestUtil.stack();
    DetailedStackStatus newStatus = DetailedStackStatus.DELETE_COMPLETED;
    String newStatusReason = "test";
    StackStatus testStackStatus = new StackStatus(stack, newStatus.getStatus(), newStatusReason, newStatus);
    when(stackStatusRepository.save(any(StackStatus.class))).thenReturn(testStackStatus);
    when(stackRepository.findOne(anyLong())).thenReturn(stack);
    when(stackRepository.save(any(Stack.class))).thenReturn(stack);
    doNothing().when(cloudbreakEventService).fireCloudbreakEvent(anyLong(), anyString(), anyString());
    when(statusToPollGroupConverter.convert(newStatus.getStatus())).thenReturn(PollGroup.POLLABLE);
    Stack newStack = underTest.updateStackStatus(1L, newStatus, newStatusReason);
    assertEquals(newStatus.getStatus(), newStack.getStatus());
    assertEquals(newStatusReason, newStack.getStatusReason());
}
Also used : DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Matchers.anyString(org.mockito.Matchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.Stack) Test(org.junit.Test)

Example 5 with DetailedStackStatus

use of com.sequenceiq.cloudbreak.api.model.DetailedStackStatus in project cloudbreak by hortonworks.

the class StackUpdater method doUpdateStackStatus.

private Stack doUpdateStackStatus(Long stackId, DetailedStackStatus detailedStatus, String statusReason) {
    Stack stack = stackRepository.findOne(stackId);
    Status status = detailedStatus.getStatus();
    if (!stack.isDeleteCompleted()) {
        stack.setStackStatus(new StackStatus(stack, status, statusReason, detailedStatus));
        if (status.isRemovableStatus()) {
            InMemoryStateStore.deleteStack(stackId);
            if (stack.getCluster() != null && stack.getCluster().getStatus().isRemovableStatus()) {
                InMemoryStateStore.deleteCluster(stack.getCluster().getId());
            }
        } else {
            InMemoryStateStore.putStack(stackId, statusToPollGroupConverter.convert(status));
        }
        stack = stackRepository.save(stack);
    }
    return stack;
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)5 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 StackStatus (com.sequenceiq.cloudbreak.domain.StackStatus)3 Status (com.sequenceiq.cloudbreak.api.model.Status)2 Test (org.junit.Test)2 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)1 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 BillingStatus (com.sequenceiq.cloudbreak.common.type.BillingStatus)1 Msg (com.sequenceiq.cloudbreak.core.flow2.stack.Msg)1 Matchers.anyString (org.mockito.Matchers.anyString)1