use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class MountDisksTest method mountDisksOnNewNodesShouldUseReachableNodes.
@Test
public void mountDisksOnNewNodesShouldUseReachableNodes() throws CloudbreakException, CloudbreakOrchestratorFailedException {
Set<String> newNodeAddresses = Set.of("node-1");
when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
when(stack.getPlatformVariant()).thenReturn(CloudConstants.MOCK);
when(stack.getCluster()).thenReturn(new Cluster());
CloudbreakDetails cloudbreakDetails = new CloudbreakDetails();
cloudbreakDetails.setVersion("2.34.0");
when(componentConfigProviderService.getCloudbreakDetails(any())).thenReturn(cloudbreakDetails);
Node node1 = new Node("1.1.1.1", "1.1.1.1", "id1", "m5.xlarge", "node-1", "worker");
Node node2 = new Node("1.1.1.2", "1.1.1.2", "id2", "m5.xlarge", "node-2", "worker");
Set<Node> reachableNodes = new HashSet<>();
reachableNodes.add(node1);
reachableNodes.add(node2);
Set<Node> newNodesWithDiskData = new HashSet<>();
newNodesWithDiskData.add(node1);
when(stackUtil.collectNewNodesWithDiskData(stack, newNodeAddresses)).thenReturn(newNodesWithDiskData);
underTest.mountDisksOnNewNodes(1L, newNodeAddresses, reachableNodes);
verify(stackUtil).collectNewNodesWithDiskData(stack, newNodeAddresses);
verify(hostOrchestrator).formatAndMountDisksOnNodes(any(), any(), targetsCaptor.capture(), allNodesCaptor.capture(), any(), eq(CloudConstants.MOCK));
Set<Node> capturedTargets = targetsCaptor.getValue();
Set<Node> capturedAllNode = allNodesCaptor.getValue();
assertTrue(capturedTargets.contains(node1));
assertFalse(capturedTargets.contains(node2));
assertTrue(capturedAllNode.contains(node1));
assertTrue(capturedAllNode.contains(node2));
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class ClusterTemplateV4RequestToClusterTemplateConverterTest method createStack.
private Stack createStack() {
Stack stack = stack(AVAILABLE, awsCredential());
Cluster cluster = cluster(blueprint(), stack, 1L);
stack.setCluster(cluster);
return stack;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class StackOperationServiceTest method testStartWhenClusterStopFailed.
@Test
public void testStartWhenClusterStopFailed() {
Stack stack = new Stack();
stack.setId(9876L);
stack.setStackStatus(new StackStatus(stack, Status.STOPPED, "", STOPPED));
Cluster cluster = new Cluster();
stack.setCluster(cluster);
underTest.start(stack);
verify(flowManager, times(1)).triggerStackStart(stack.getId());
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class StackOperationServiceTest method testTriggerStackStopIfNeededWhenCheckCallEnvironmentCheck.
@Test
public void testTriggerStackStopIfNeededWhenCheckCallEnvironmentCheck() {
Stack stack = new Stack();
stack.setId(9876L);
stack.setStackStatus(new StackStatus(stack, AVAILABLE));
Cluster cluster = new Cluster();
stack.setCluster(cluster);
when(spotInstanceUsageCondition.isStackRunsOnSpotInstances(stack)).thenReturn(false);
when(stackStopRestrictionService.isInfrastructureStoppable(any())).thenReturn(StopRestrictionReason.NONE);
underTest.triggerStackStopIfNeeded(stack, cluster, true);
verify(environmentService).checkEnvironmentStatus(stack, EnvironmentStatus.stoppable());
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster in project cloudbreak by hortonworks.
the class StackOperationServiceTest method testRemoveInstances.
@Test
public void testRemoveInstances() {
Stack stack = new Stack();
stack.setId(9876L);
stack.setStackStatus(new StackStatus(stack, AVAILABLE));
Cluster cluster = new Cluster();
cluster.setStatus(Status.AVAILABLE);
stack.setCluster(cluster);
Collection<String> instanceIds = new LinkedList<>();
InstanceMetaData im1 = createInstanceMetadataForTest(1L, "group1");
InstanceMetaData im2 = createInstanceMetadataForTest(2L, "group1");
InstanceMetaData im3 = createInstanceMetadataForTest(3L, "group1");
instanceIds.add("i1");
instanceIds.add("i2");
instanceIds.add("i3");
// This ends up skipping the actual validation that is run here.
doReturn(im1).when(updateNodeCountValidator).validateInstanceForDownscale(im1.getInstanceId(), stack);
doReturn(im2).when(updateNodeCountValidator).validateInstanceForDownscale(im2.getInstanceId(), stack);
doReturn(im3).when(updateNodeCountValidator).validateInstanceForDownscale(im3.getInstanceId(), stack);
doNothing().when(updateNodeCountValidator).validateServiceRoles(any(), anyMap());
doNothing().when(updateNodeCountValidator).validateScalabilityOfInstanceGroup(any(), anyString(), anyInt());
doNothing().when(updateNodeCountValidator).validateInstanceGroupForStopStart(any(), anyString(), anyInt());
doNothing().when(updateNodeCountValidator).validateInstanceGroup(any(), anyString());
doNothing().when(updateNodeCountValidator).validateScalingAdjustment(anyString(), anyInt(), any());
ArgumentCaptor<Map<String, Set<Long>>> capturedInstances;
Map<String, Set<Long>> captured;
// Verify non stop-start invocation
capturedInstances = ArgumentCaptor.forClass(Map.class);
underTest.removeInstances(stack, instanceIds, false);
verify(flowManager).triggerStackRemoveInstances(eq(stack.getId()), capturedInstances.capture(), eq(false));
captured = capturedInstances.getValue();
assertEquals(1, captured.size());
assertEquals("group1", captured.keySet().iterator().next());
assertEquals(3, captured.entrySet().iterator().next().getValue().size());
// This ends up skipping the actual validation that is run here.
doReturn(im1).when(updateNodeCountValidator).validateInstanceForStop(im1.getInstanceId(), stack);
doReturn(im2).when(updateNodeCountValidator).validateInstanceForStop(im2.getInstanceId(), stack);
doReturn(im3).when(updateNodeCountValidator).validateInstanceForStop(im3.getInstanceId(), stack);
// Verify stop-start invocation
reset(flowManager);
capturedInstances = ArgumentCaptor.forClass(Map.class);
underTest.stopInstances(stack, instanceIds, false);
verify(flowManager).triggerStopStartStackDownscale(eq(stack.getId()), capturedInstances.capture(), eq(false));
captured = capturedInstances.getValue();
assertEquals(1, captured.size());
assertEquals("group1", captured.keySet().iterator().next());
assertEquals(3, captured.entrySet().iterator().next().getValue().size());
// No requestIds sent - BadRequest stopstart
assertThatThrownBy(() -> underTest.stopInstances(stack, null, false)).isInstanceOf(BadRequestException.class).hasMessage("Stop request cannot process an empty instanceIds collection");
// stopstart supports a single hostGroup only
reset(flowManager);
InstanceMetaData im4 = createInstanceMetadataForTest(4L, "group2");
doReturn(im4).when(updateNodeCountValidator).validateInstanceForStop(im4.getInstanceId(), stack);
instanceIds.add("i4");
assertThatThrownBy(() -> underTest.stopInstances(stack, instanceIds, false)).isInstanceOf(BadRequestException.class).hasMessage("Downscale via Instance Stop cannot process more than one host group");
// regular scaling supports multiple hostgroups
reset(flowManager);
doReturn(im4).when(updateNodeCountValidator).validateInstanceForDownscale(im4.getInstanceId(), stack);
underTest.removeInstances(stack, instanceIds, false);
verify(flowManager).triggerStackRemoveInstances(eq(stack.getId()), capturedInstances.capture(), eq(false));
captured = capturedInstances.getValue();
assertEquals(2, captured.size());
assertTrue(captured.containsKey("group1"));
assertTrue(captured.containsKey("group2"));
assertEquals(3, captured.get("group1").size());
assertEquals(1, captured.get("group2").size());
}
Aggregations