Search in sources :

Example 1 with ClusterStatusSyncEvent

use of com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStackStatusInActiveCBClusterStatusActive.

@Test
public void testOnApplicationEventWhenCBStackStatusInActiveCBClusterStatusActive() {
    Cluster cluster = getACluster(ClusterState.SUSPENDED);
    when(clusterService.findById(anyLong())).thenReturn(cluster);
    StackStatusV4Response stackStatusV4Response = new StackStatusV4Response();
    stackStatusV4Response.setStatus(Status.UPDATE_IN_PROGRESS);
    stackStatusV4Response.setClusterStatus(Status.AVAILABLE);
    when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenReturn(stackStatusV4Response);
    underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID));
    verify(clusterService, never()).setState(anyLong(), any(ClusterState.class));
    verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN);
}
Also used : ClusterState(com.sequenceiq.periscope.api.model.ClusterState) ClusterStatusSyncEvent(com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) StackStatusV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response) Test(org.junit.Test)

Example 2 with ClusterStatusSyncEvent

use of com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStatusFails.

@Test(expected = RuntimeException.class)
public void testOnApplicationEventWhenCBStatusFails() {
    Cluster cluster = getACluster(ClusterState.RUNNING);
    when(clusterService.findById(anyLong())).thenReturn(cluster);
    when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenThrow(new RuntimeException("some error in communication"));
    underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID));
    verify(clusterService).findById(AUTOSCALE_CLUSTER_ID);
    verify(clusterService, never()).removeById(AUTOSCALE_CLUSTER_ID);
    verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN);
}
Also used : ClusterStatusSyncEvent(com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) Test(org.junit.Test)

Example 3 with ClusterStatusSyncEvent

use of com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStatusDeleted.

@Test
public void testOnApplicationEventWhenCBStatusDeleted() {
    Cluster cluster = getACluster(ClusterState.RUNNING);
    when(clusterService.findById(anyLong())).thenReturn(cluster);
    when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenReturn(getStackResponse(Status.DELETE_COMPLETED));
    when(clusterService.countByEnvironmentCrn("testEnvironmentCrn")).thenReturn(2);
    underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID));
    verify(clusterService).removeById(AUTOSCALE_CLUSTER_ID);
    verify(clusterService, never()).save(cluster);
    verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN);
    verify(altusMachineUserService, never()).deleteMachineUserForEnvironment(anyString(), anyString(), anyString());
}
Also used : ClusterStatusSyncEvent(com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) Test(org.junit.Test)

Example 4 with ClusterStatusSyncEvent

use of com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStatusStoppedAndPeriscopeClusterSuspended.

@Test
public void testOnApplicationEventWhenCBStatusStoppedAndPeriscopeClusterSuspended() {
    Cluster cluster = getACluster(ClusterState.SUSPENDED);
    cluster.setState(ClusterState.SUSPENDED);
    when(clusterService.findById(anyLong())).thenReturn(cluster);
    when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenReturn(getStackResponse(Status.STOPPED));
    underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID));
    verify(clusterService, never()).setState(AUTOSCALE_CLUSTER_ID, ClusterState.SUSPENDED);
    verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN);
}
Also used : ClusterStatusSyncEvent(com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) Test(org.junit.Test)

Example 5 with ClusterStatusSyncEvent

use of com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStatusDeletedAndNoMoreEnvironmentClusters.

@Test
public void testOnApplicationEventWhenCBStatusDeletedAndNoMoreEnvironmentClusters() {
    Cluster cluster = getACluster(ClusterState.RUNNING);
    cluster.setMachineUserCrn("testMachineUserCrn");
    when(clusterService.findById(anyLong())).thenReturn(cluster);
    when(clusterService.countByEnvironmentCrn("testEnvironmentCrn")).thenReturn(1);
    when(cloudbreakCommunicator.getStackStatusByCrn(anyString())).thenReturn(getStackResponse(Status.DELETE_COMPLETED));
    underTest.onApplicationEvent(new ClusterStatusSyncEvent(AUTOSCALE_CLUSTER_ID));
    verify(clusterService).removeById(AUTOSCALE_CLUSTER_ID);
    verify(clusterService, never()).save(cluster);
    verify(cloudbreakCommunicator).getStackStatusByCrn(CLOUDBREAK_STACK_CRN);
    verify(altusMachineUserService, times(1)).deleteMachineUserForEnvironment("testTenant", cluster.getMachineUserCrn(), "testEnvironmentCrn");
}
Also used : ClusterStatusSyncEvent(com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) Test(org.junit.Test)

Aggregations

Cluster (com.sequenceiq.periscope.domain.Cluster)15 ClusterStatusSyncEvent (com.sequenceiq.periscope.monitor.event.ClusterStatusSyncEvent)15 Test (org.junit.Test)15 ClusterState (com.sequenceiq.periscope.api.model.ClusterState)5 StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)3 AutoscaleStackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)1