use of com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack in project cloudbreak by hortonworks.
the class StackService method getAllForAutoscale.
public Set<AutoscaleStackV4Response> getAllForAutoscale() {
try {
return transactionService.required(() -> {
Set<AutoscaleStack> aliveOnes = stackRepository.findAliveOnesWithClusterManager();
Set<AutoscaleStack> aliveNotUnderDeletion = Optional.ofNullable(aliveOnes).orElse(Set.of()).stream().filter(stack -> !DELETE_IN_PROGRESS.equals(stack.getStackStatus())).collect(Collectors.toSet());
return aliveNotUnderDeletion.stream().map(a -> autoscaleStackToAutoscaleStackResponseJsonConverter.convert(a)).collect(Collectors.toSet());
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack 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());
}
use of com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack 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());
}
Aggregations