Search in sources :

Example 6 with AutoscaleStackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.

the class StackServiceTest method testGetAllForAutoscaleWithDeleteInProgressStack.

@Test
public void testGetAllForAutoscaleWithDeleteInProgressStack() throws TransactionExecutionException {
    when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> {
        Supplier<AutoscaleStackV4Response> callback = invocation.getArgument(0);
        return callback.get();
    });
    AutoscaleStack availableStack = mock(AutoscaleStack.class);
    when(availableStack.getStackStatus()).thenReturn(Status.AVAILABLE);
    AutoscaleStack deleteInProgressStack = mock(AutoscaleStack.class);
    when(deleteInProgressStack.getStackStatus()).thenReturn(Status.AVAILABLE);
    when(stackRepository.findAliveOnesWithClusterManager()).thenReturn(Set.of(availableStack, deleteInProgressStack));
    ArgumentCaptor<AutoscaleStack> aliveStackCaptor = ArgumentCaptor.forClass(AutoscaleStack.class);
    AutoscaleStackV4Response autoscaleStackResponse = new AutoscaleStackV4Response();
    when(autoscaleStackToAutoscaleStackResponseJsonConverter.convert(aliveStackCaptor.capture())).thenReturn(autoscaleStackResponse);
    Set<AutoscaleStackV4Response> allForAutoscale = underTest.getAllForAutoscale();
    assertNotNull(allForAutoscale);
    assertEquals(autoscaleStackResponse, allForAutoscale.iterator().next());
    AutoscaleStack stackSet = aliveStackCaptor.getValue();
    assertNotNull(stackSet);
    assertEquals(availableStack.getStackStatus(), stackSet.getStackStatus());
}
Also used : AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) Supplier(java.util.function.Supplier) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) Test(org.junit.Test)

Example 7 with AutoscaleStackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.

the class StackServiceTest method testGetAllForAutoscaleWithAvailableStack.

@Test
public void testGetAllForAutoscaleWithAvailableStack() throws TransactionExecutionException {
    when(transactionService.required(any(Supplier.class))).thenAnswer(invocation -> {
        Supplier<AutoscaleStackV4Response> callback = invocation.getArgument(0);
        return callback.get();
    });
    AutoscaleStack stack = mock(AutoscaleStack.class);
    when(stack.getStackStatus()).thenReturn(Status.AVAILABLE);
    when(stackRepository.findAliveOnesWithClusterManager()).thenReturn(Set.of(stack));
    ArgumentCaptor<AutoscaleStack> aliveStackCaptor = ArgumentCaptor.forClass(AutoscaleStack.class);
    AutoscaleStackV4Response autoscaleStackResponse = new AutoscaleStackV4Response();
    when(autoscaleStackToAutoscaleStackResponseJsonConverter.convert(aliveStackCaptor.capture())).thenReturn(autoscaleStackResponse);
    Set<AutoscaleStackV4Response> allForAutoscale = underTest.getAllForAutoscale();
    assertNotNull(allForAutoscale);
    assertEquals(autoscaleStackResponse, allForAutoscale.iterator().next());
    AutoscaleStack stackSet = aliveStackCaptor.getValue();
    assertNotNull(stackSet);
    assertEquals(stack.getStackStatus(), stackSet.getStackStatus());
}
Also used : AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) Supplier(java.util.function.Supplier) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) Test(org.junit.Test)

Example 8 with AutoscaleStackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.

the class ClusterStatusSyncHandlerTest method testOnApplicationEventWhenCBStackStatusActiveCBClusterStatusActive.

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

Example 9 with AutoscaleStackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.

the class RejectedThreadServiceTest method testCreateWhenAutoscaleStackResponseAndRemove.

@Test
public void testCreateWhenAutoscaleStackResponseAndRemove() {
    AutoscaleStackV4Response response = new AutoscaleStackV4Response();
    response.setStackId(1L);
    EvaluatorExecutor task = new TestEvaluatorExecutor(getContext(response));
    underTest.create(task);
    List<RejectedThread> allRejectedCluster = underTest.getAllRejectedCluster();
    Assert.assertFalse(allRejectedCluster.isEmpty());
    Assert.assertEquals(1L, allRejectedCluster.get(0).getId());
    underTest.remove(response);
    allRejectedCluster = underTest.getAllRejectedCluster();
    Assert.assertTrue(allRejectedCluster.isEmpty());
}
Also used : RejectedThread(com.sequenceiq.periscope.model.RejectedThread) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) EvaluatorExecutor(com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor) Test(org.junit.Test)

Example 10 with AutoscaleStackV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response in project cloudbreak by hortonworks.

the class RejectedThreadServiceTest method testCreateWhenAutoscaleStackResponseCountEqualsTwo.

@Test
public void testCreateWhenAutoscaleStackResponseCountEqualsTwo() {
    AutoscaleStackV4Response response = new AutoscaleStackV4Response();
    response.setStackId(1L);
    EvaluatorExecutor task = new TestEvaluatorExecutor(getContext(response));
    underTest.create(task);
    underTest.create(task);
    List<RejectedThread> allRejectedCluster = underTest.getAllRejectedCluster();
    Assert.assertFalse(allRejectedCluster.isEmpty());
    Assert.assertEquals(1L, allRejectedCluster.get(0).getId());
    Assert.assertEquals(2L, allRejectedCluster.get(0).getRejectedCount());
}
Also used : RejectedThread(com.sequenceiq.periscope.model.RejectedThread) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) EvaluatorExecutor(com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor) Test(org.junit.Test)

Aggregations

AutoscaleStackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)12 Test (org.junit.Test)7 RejectedThread (com.sequenceiq.periscope.model.RejectedThread)4 Cluster (com.sequenceiq.periscope.domain.Cluster)3 AutoscaleStack (com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack)2 EvaluatorExecutor (com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor)2 Supplier (java.util.function.Supplier)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings (com.google.common.base.Strings)1 AuthorizationResourceNamesProvider (com.sequenceiq.authorization.service.AuthorizationResourceNamesProvider)1 ResourceWithId (com.sequenceiq.authorization.service.list.ResourceWithId)1 StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)1 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)1 DELETE_IN_PROGRESS (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.DELETE_IN_PROGRESS)1 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)1 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 StackStatusV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackStatusV4Response)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 Measure (com.sequenceiq.cloudbreak.aspect.Measure)1