@Test public void shouldTriggerStopWhenStackRunsOnOnDemandInstances() { Stack stack = new Stack(); stack.setId(9876L); stack.setStackStatus(new StackStatus(stack, AVAILABLE)); stack.setInstanceGroups(Set.of(createInstanceGroup(0), createInstanceGroup(null))); when(stackService.getByIdWithLists(stack.getId())).thenReturn(stack); underTest.updateStatus(stack.getId(), StatusRequest.STOPPED, true, new User()); verify(stackUpdater).updateStackStatus(stack.getId(), STOP_REQUESTED); }
public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user) { Stack stack = stackService.getByIdWithLists(stackId); Cluster cluster = null; if (stack.getCluster() != null) { cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null); } switch (status) { case SYNC: return sync(stack, false, user); case FULL_SYNC: return sync(stack, true, user); case REPAIR_FAILED_NODES: return repairFailedNodes(stack, user); case STOPPED: return stop(stack, cluster, updateCluster, user); case STARTED: return start(stack, cluster, updateCluster, user); default: throw new BadRequestException("Cannot update the status of stack because status request not valid."); } }
StackOperationService { public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user) { Stack stack = stackService.getByIdWithLists(stackId); Cluster cluster = null; if (stack.getCluster() != null) { cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null); } switch (status) { case SYNC: return sync(stack, false, user); case FULL_SYNC: return sync(stack, true, user); case REPAIR_FAILED_NODES: return repairFailedNodes(stack, user); case STOPPED: return stop(stack, cluster, updateCluster, user); case STARTED: return start(stack, cluster, updateCluster, user); default: throw new BadRequestException("Cannot update the status of stack because status request not valid."); } } }
StackOperationService { public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user) { Stack stack = stackService.getByIdWithLists(stackId); Cluster cluster = null; if (stack.getCluster() != null) { cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null); } switch (status) { case SYNC: return sync(stack, false, user); case FULL_SYNC: return sync(stack, true, user); case REPAIR_FAILED_NODES: return repairFailedNodes(stack, user); case STOPPED: return stop(stack, cluster, updateCluster, user); case STARTED: return start(stack, cluster, updateCluster, user); default: throw new BadRequestException("Cannot update the status of stack because status request not valid."); } }  }
StackOperationService { public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user) { Stack stack = stackService.getByIdWithLists(stackId); Cluster cluster = null; if (stack.getCluster() != null) { cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null); } switch (status) { case SYNC: return sync(stack, false, user); case FULL_SYNC: return sync(stack, true, user); case REPAIR_FAILED_NODES: return repairFailedNodes(stack, user); case STOPPED: return stop(stack, cluster, updateCluster, user); case STARTED: return start(stack, cluster, updateCluster, user); default: throw new BadRequestException("Cannot update the status of stack because status request not valid."); } }  FlowIdentifier removeInstance(Stack stack, Long workspaceId, String instanceId, boolean forced, User user); FlowIdentifier removeInstances(Stack stack, Long workspaceId, Collection<String> instanceIds, boolean forced, User user); FlowIdentifier updateImage(Long stackId, Long workspaceId, String imageId, String imageCatalogName, String imageCatalogUrl, User user); FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user); FlowIdentifier updateNodeCount(Stack stack, InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson, boolean withClusterEvent, User user); void renewCertificate(String stackName); }
StackOperationService { public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user) { Stack stack = stackService.getByIdWithLists(stackId); Cluster cluster = null; if (stack.getCluster() != null) { cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null); } switch (status) { case SYNC: return sync(stack, false, user); case FULL_SYNC: return sync(stack, true, user); case REPAIR_FAILED_NODES: return repairFailedNodes(stack, user); case STOPPED: return stop(stack, cluster, updateCluster, user); case STARTED: return start(stack, cluster, updateCluster, user); default: throw new BadRequestException("Cannot update the status of stack because status request not valid."); } }  FlowIdentifier removeInstance(Stack stack, Long workspaceId, String instanceId, boolean forced, User user); FlowIdentifier removeInstances(Stack stack, Long workspaceId, Collection<String> instanceIds, boolean forced, User user); FlowIdentifier updateImage(Long stackId, Long workspaceId, String imageId, String imageCatalogName, String imageCatalogUrl, User user); FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster, User user); FlowIdentifier updateNodeCount(Stack stack, InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson, boolean withClusterEvent, User user); void renewCertificate(String stackName);  }