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");
}
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));
}
}
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;
}
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);
}
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;
}
Aggregations