Search in sources :

Example 86 with Cluster

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));
}
Also used : CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with Cluster

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;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 88 with Cluster

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());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with Cluster

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());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with Cluster

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());
}
Also used : Set(java.util.Set) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedList(java.util.LinkedList) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Map(java.util.Map) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)407 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)248 Test (org.junit.jupiter.api.Test)125 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)63 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)60 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)58 Optional (java.util.Optional)51 Test (org.junit.Test)50 List (java.util.List)49 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)47 Set (java.util.Set)43 Json (com.sequenceiq.cloudbreak.common.json.Json)39 Map (java.util.Map)39 Collectors (java.util.stream.Collectors)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)36 Inject (javax.inject.Inject)36 Logger (org.slf4j.Logger)36 LoggerFactory (org.slf4j.LoggerFactory)36 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)35