Search in sources :

Example 56 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class MetadataSetupServiceTest method saveLoadBalancerMetadataAndSetEndpointToOldStack.

@Test
public void saveLoadBalancerMetadataAndSetEndpointToOldStack() {
    Stack oldStack = new Stack();
    oldStack.setId(OLD_STACK_ID);
    oldStack.setName(OLD_STACK_NAME);
    oldStack.setCloudPlatform("DEFAULT");
    oldStack.setEnvironmentCrn(STACK_CRN);
    oldStack.setDisplayName(STACK_DISPLAY_NAME);
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setId(INSTANCE_GROUP_ID);
    instanceGroup.setGroupName(GROUP_NAME);
    instanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
    pgwInstanceMetadata.setInstanceStatus(STOPPED);
    pgwInstanceMetadata.setDiscoveryFQDN("master0.subdomain.cldr.work");
    pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
    instanceGroup.setInstanceMetaData(Set.of(pgwInstanceMetadata));
    oldStack.setInstanceGroups(Set.of(instanceGroup));
    stack.setName(STACK_NAME);
    stack.setCloudPlatform("DEFAULT");
    stack.setEnvironmentCrn(STACK_CRN);
    stack.setDisplayName(STACK_DISPLAY_NAME);
    LoadBalancer loadBalancer = new LoadBalancer();
    loadBalancer.setStack(stack);
    loadBalancer.setType(LoadBalancerType.PUBLIC);
    Set<LoadBalancer> loadBalancerSet = new HashSet<>();
    loadBalancerSet.add(loadBalancer);
    when(loadBalancerPersistenceService.findByStackId(STACK_ID)).thenReturn(loadBalancerSet);
    when(loadBalancerPersistenceService.findByStackId(OLD_STACK_ID)).thenReturn(new HashSet<>());
    when(loadBalancerConfigService.generateLoadBalancerEndpoint(stack)).thenCallRealMethod();
    StackIdView stackIdView = new StackIdViewImpl(STACK_ID, STACK_NAME, "no");
    StackStatus stackStatus = new StackStatus();
    stackStatus.setStatus(Status.AVAILABLE);
    stackStatus.setStack(stack);
    StackIdView stackIdViewOld = new StackIdViewImpl(OLD_STACK_ID, OLD_STACK_NAME, "old_no");
    StackStatus stoppedStackStatus = new StackStatus();
    stoppedStackStatus.setStatus(Status.STOPPED);
    stoppedStackStatus.setStack(oldStack);
    when(stackService.getByEnvironmentCrnAndStackType(STACK_CRN, StackType.DATALAKE)).thenReturn(List.of(stackIdView, stackIdViewOld));
    when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(STACK_ID)).thenReturn(Optional.of(stackStatus));
    when(stackStatusService.findFirstByStackIdOrderByCreatedDesc(OLD_STACK_ID)).thenReturn(Optional.of(stoppedStackStatus));
    when(stackService.getByIdWithGatewayInTransaction(OLD_STACK_ID)).thenReturn(oldStack);
    when(targetGroupPersistenceService.findByLoadBalancerId(any())).thenReturn(Set.of());
    Iterable<CloudLoadBalancerMetadata> cloudLoadBalancerMetaDataStatuses = getCloudLoadBalancerMetaDataStatuses();
    underTest.saveLoadBalancerMetadata(stack, cloudLoadBalancerMetaDataStatuses);
    verify(loadBalancerPersistenceService).save(loadBalancerCaptor.capture());
    LoadBalancer loadBalancerValue = loadBalancerCaptor.getValue();
    assertThat(loadBalancerValue.getHostedZoneId()).isSameAs(HOSTED_ZONE);
    assertThat(loadBalancerValue.getIp()).isSameAs(PUBLIC_IP);
    assertThat(loadBalancerValue.getDns()).isSameAs(CLOUD_DNS);
    assertThat(loadBalancerValue.getEndpoint()).isEqualTo("master0");
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackIdViewImpl(com.sequenceiq.cloudbreak.service.stack.StackIdViewImpl) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) HashSet(java.util.HashSet) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class UpdateNodeCountValidatorTest method testValidateScalabilityOfInstanceGroup.

@ParameterizedTest(name = "The master node count is {0} this will be scaled with {2} " + "node and the minimum is {1} the ScalabilityOption is {3}.")
@MethodSource("testValidateScalabilityOfInstanceGroupData")
public void testValidateScalabilityOfInstanceGroup(int instanceGroupNodeCount, int minimumNodeCount, int scalingNodeCount, ScalabilityOption scalabilityOption, Optional<String> errorMessageSegment) {
    Stack stack = mock(Stack.class);
    InstanceGroupAdjustmentV4Request instanceGroupAdjustmentV4Request = mock(InstanceGroupAdjustmentV4Request.class);
    InstanceGroup instanceGroup = mock(InstanceGroup.class);
    when(instanceGroupAdjustmentV4Request.getInstanceGroup()).thenReturn("master");
    when(instanceGroupAdjustmentV4Request.getScalingAdjustment()).thenReturn(scalingNodeCount);
    when(stack.getInstanceGroupByInstanceGroupName("master")).thenReturn(instanceGroup);
    when(stack.getName()).thenReturn("master-stack");
    when(instanceGroup.getGroupName()).thenReturn("master");
    when(instanceGroup.getMinimumNodeCount()).thenReturn(minimumNodeCount);
    when(instanceGroup.getNodeCount()).thenReturn(instanceGroupNodeCount);
    when(instanceGroup.getScalabilityOption()).thenReturn(scalabilityOption);
    if (errorMessageSegment.isPresent()) {
        BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> {
            underTest.validateScalabilityOfInstanceGroup(stack, instanceGroupAdjustmentV4Request);
        });
        Assert.assertTrue(badRequestException.getMessage().contains(errorMessageSegment.get()));
    } else {
        assertDoesNotThrow(() -> underTest.validateScalabilityOfInstanceGroup(stack, instanceGroupAdjustmentV4Request));
    }
}
Also used : InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 58 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class CandidateUnhealthyInstancesSelectorTest method setupInstanceGroup.

private InstanceGroup setupInstanceGroup(InstanceGroupType instanceGroupType) {
    InstanceGroup slaveGroup = mock(InstanceGroup.class);
    when(slaveGroup.getInstanceGroupType()).thenReturn(instanceGroupType);
    return slaveGroup;
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 59 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class StackRepairServiceTest method shouldGroupUnhealthyInstancesByHostGroup.

@Test
public void shouldGroupUnhealthyInstancesByHostGroup() {
    String instanceId1 = "i-0f1e0605506aaaaaa";
    String instanceId2 = "i-0f1e0605506bbbbbb";
    String instanceId3 = "i-0f1e0605506cccccc";
    String privateIp1 = "ip-10-0-0-1.ec2.internal";
    String privateIp2 = "ip-10-0-0-2.ec2.internal";
    String privateIp3 = "ip-10-0-0-3.ec2.internal";
    String slaveGroup1 = "slave_group1";
    String slaveGroup2 = "slave_group2";
    InstanceGroup slaveInstanceGroup1 = new InstanceGroup();
    slaveInstanceGroup1.setGroupName(slaveGroup1);
    InstanceGroup slaveInstanceGroup2 = new InstanceGroup();
    slaveInstanceGroup2.setGroupName(slaveGroup2);
    Set<String> instanceIds = new HashSet<>();
    instanceIds.add(instanceId1);
    instanceIds.add(instanceId2);
    instanceIds.add(instanceId3);
    setupInstanceMetadata(stack.getId(), instanceId1, privateIp1, slaveInstanceGroup1);
    setupInstanceMetadata(stack.getId(), instanceId2, privateIp2, slaveInstanceGroup2);
    setupInstanceMetadata(stack.getId(), instanceId3, privateIp3, slaveInstanceGroup2);
    underTest.add(stack, instanceIds);
    UnhealthyInstances expectedUnhealthyInstances = new UnhealthyInstances();
    expectedUnhealthyInstances.addInstance(instanceId1, slaveGroup1);
    expectedUnhealthyInstances.addInstance(instanceId2, slaveGroup2);
    expectedUnhealthyInstances.addInstance(instanceId3, slaveGroup2);
    verify(executorService).submit(argThat(new StackRepairFlowSubmitterMatcher(stack.getId(), expectedUnhealthyInstances)));
    verify(flowMessageService).fireEventAndLog(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), STACK_REPAIR_ATTEMPTING);
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 60 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class InstanceMetaDataServiceTest method stack.

private Stack stack(int instanceGroupCount) {
    Stack stack = new Stack();
    stack.setEnvironmentCrn(ENVIRONMENT_CRN);
    Set<InstanceGroup> instanceGroups = new HashSet<>(instanceGroupCount);
    for (int i = 0; i < instanceGroupCount; i++) {
        instanceGroups.add(instanceGroup(i));
    }
    stack.setInstanceGroups(instanceGroups);
    return stack;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)288 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)132 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)93 Test (org.junit.jupiter.api.Test)91 HashSet (java.util.HashSet)68 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)47 Template (com.sequenceiq.cloudbreak.domain.Template)45 Test (org.junit.Test)44 Json (com.sequenceiq.cloudbreak.common.json.Json)38 Set (java.util.Set)37 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)34 ArrayList (java.util.ArrayList)31 LinkedHashSet (java.util.LinkedHashSet)31 Map (java.util.Map)28 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)27 List (java.util.List)26 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)25 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22