Skip to content

Commit

Permalink
CB-22304 Update the Pillar data for the Gateway topology with the Ran…
Browse files Browse the repository at this point in the history
…ger location in case of EDL. The EDL does not have Ranger Admin on the Gateway host therefore we have to customize the topology to point the request to the Master host group
  • Loading branch information
RokolyA94 authored and doktoric committed Jun 28, 2023
1 parent e879da9 commit 286eb71
Show file tree
Hide file tree
Showing 5 changed files with 1,559 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,9 @@ private Map<String, Object> createLoadBalancerProperties(StackDto stackDto) {

private List<Map<String, String>> getFrontendMap(Set<LoadBalancer> loadBalancers) {
return loadBalancers.stream()
.filter(lb -> isNotEmpty(lb.getIp()))
.map(lb -> Map.of("type", lb.getType().name(), "ip", lb.getIp()))
.collect(Collectors.toList());
.filter(lb -> isNotEmpty(lb.getIp()))
.map(lb -> Map.of("type", lb.getType().name(), "ip", lb.getIp()))
.collect(Collectors.toList());
}

private boolean isFloatingIpEnabled(Set<LoadBalancer> loadBalancers) {
Expand Down Expand Up @@ -897,6 +897,10 @@ private List<String> getRangerFqdn(StackDto stackDto, String primaryGatewayFqdn,
List<String> hosts = rangerLocations.stream()
.filter(s -> s.contains(gatewayGroupName))
.collect(Collectors.toList());
// If the ranger is not on Gateway node we have to expose other node.
if (CollectionUtils.isEmpty(hosts)) {
return asList(rangerLocations.iterator().next());
}
return hosts;
}
return rangerLocations.contains(primaryGatewayFqdn) ? asList(primaryGatewayFqdn) : asList(rangerLocations.iterator().next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.sequenceiq.cloudbreak.TestUtil;
import com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType;
import com.sequenceiq.cloudbreak.api.endpoint.v4.database.base.DatabaseType;
import com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType;
import com.sequenceiq.cloudbreak.api.service.ExposedService;
import com.sequenceiq.cloudbreak.api.service.ExposedServiceCollector;
import com.sequenceiq.cloudbreak.auth.CMLicenseParser;
Expand Down Expand Up @@ -122,6 +123,7 @@
import com.sequenceiq.cloudbreak.util.NodesUnreachableException;
import com.sequenceiq.cloudbreak.util.StackUtil;
import com.sequenceiq.cloudbreak.view.ClusterView;
import com.sequenceiq.cloudbreak.view.InstanceGroupView;
import com.sequenceiq.cloudbreak.view.InstanceMetadataView;
import com.sequenceiq.cloudbreak.view.StackView;
import com.sequenceiq.common.api.type.LoadBalancerType;
Expand Down Expand Up @@ -728,6 +730,123 @@ private void setupMocksForRunClusterServices() {
when(stackToTemplatePreparationObjectConverter.convert(any())).thenReturn(templatePreparationObject);
}

@Test
@MockitoSettings(strictness = Strictness.LENIENT)
void testEDLRangerToplogy() throws IOException, CloudbreakOrchestratorFailedException {
setupMocksForRunClusterServices();
Set<Node> nodes = Sets.newHashSet(node("fqdn1"), node("fqdn2"), node("fqdn3"),
node("gateway1"), node("master1"));
when(stackUtil.collectNodes(any())).thenReturn(nodes);
when(exposedServiceCollector.getAllServiceNames()).thenReturn(Set.of("RANGER"));
Map<String, List<String>> locations = new HashMap<>();
locations.put("RANGER", List.of("master1", "master2"));
when(componentLocator.getComponentLocation(any(), any())).thenReturn(locations);
StackView stackViewMock = mock(StackView.class);
when(stackViewMock.getId()).thenReturn(STACK_ID);
ReflectionTestUtils.setField(stack, "stack", stackViewMock);
InstanceGroupView instanceGroupView = mock(InstanceGroupView.class);
InstanceMetadataView instanceMetadataView = mock(InstanceMetadataView.class);
when(instanceMetadataView.getInstanceMetadataType()).thenReturn(InstanceMetadataType.GATEWAY_PRIMARY);
when(instanceGroupView.getGroupName()).thenReturn("GATEWAY");
Map<String, InstanceGroupDto> instanceGroups = new HashMap<>();
InstanceGroupDto instanceGroupDto = new InstanceGroupDto(instanceGroupView, List.of(instanceMetadataView));
instanceGroups.put("GATEWAY", instanceGroupDto);
String edlBP = FileReaderUtils.readFileFromClasspath("cdp-sdx-enterprise.bp");
Blueprint bp = new Blueprint();
bp.setBlueprintText(edlBP);
ReflectionTestUtils.setField(stack, "instanceGroups", instanceGroups);
ReflectionTestUtils.setField(stack, "blueprint", bp);
underTest.redeployGatewayPillarOnly(stack);
ArgumentCaptor<SaltConfig> saltConfigCaptor = ArgumentCaptor.forClass(SaltConfig.class);
verify(hostOrchestrator).uploadGatewayPillar(any(), allNodesCaptor.capture(), any(), saltConfigCaptor.capture());
Set<Node> allNodes = allNodesCaptor.getValue();
assertEquals(5, allNodes.size());
SaltConfig saltConfig = saltConfigCaptor.getValue();
SaltPillarProperties gatewayPillarProperties = saltConfig.getServicePillarConfig().get("gateway");
Map<String, Object> props = (HashMap<String, Object>) gatewayPillarProperties.getProperties().get("gateway");
Map<String, List<String>> location = (HashMap<String, List<String>>) props.get("location");
List<String> ranger = location.get("RANGER");
assertTrue(ranger.contains("master1"));
}

@Test
@MockitoSettings(strictness = Strictness.LENIENT)
void testMDRangerToplogy() throws IOException, CloudbreakOrchestratorFailedException {
setupMocksForRunClusterServices();
Set<Node> nodes = Sets.newHashSet(node("fqdn1"), node("fqdn2"), node("fqdn3"),
node("gateway1"), node("master1"));
when(stackUtil.collectNodes(any())).thenReturn(nodes);
when(exposedServiceCollector.getAllServiceNames()).thenReturn(Set.of("RANGER"));
Map<String, List<String>> locations = new HashMap<>();
locations.put("RANGER", List.of("master1", "master2"));
when(componentLocator.getComponentLocation(any(), any())).thenReturn(locations);
StackView stackViewMock = mock(StackView.class);
when(stackViewMock.getId()).thenReturn(STACK_ID);
ReflectionTestUtils.setField(stack, "stack", stackViewMock);
InstanceGroupView instanceGroupView = mock(InstanceGroupView.class);
InstanceMetadataView instanceMetadataView = mock(InstanceMetadataView.class);
when(instanceMetadataView.getInstanceMetadataType()).thenReturn(InstanceMetadataType.GATEWAY_PRIMARY);
when(instanceGroupView.getGroupName()).thenReturn("GATEWAY");
Map<String, InstanceGroupDto> instanceGroups = new HashMap<>();
InstanceGroupDto instanceGroupDto = new InstanceGroupDto(instanceGroupView, List.of(instanceMetadataView));
instanceGroups.put("GATEWAY", instanceGroupDto);
String mediumDutyBP = FileReaderUtils.readFileFromClasspath("cdp-sdx-medium-ha.bp");
Blueprint bp = new Blueprint();
bp.setBlueprintText(mediumDutyBP);
ReflectionTestUtils.setField(stack, "instanceGroups", instanceGroups);
ReflectionTestUtils.setField(stack, "blueprint", bp);
underTest.redeployGatewayPillarOnly(stack);
ArgumentCaptor<SaltConfig> saltConfigCaptor = ArgumentCaptor.forClass(SaltConfig.class);
verify(hostOrchestrator).uploadGatewayPillar(any(), allNodesCaptor.capture(), any(), saltConfigCaptor.capture());
Set<Node> allNodes = allNodesCaptor.getValue();
assertEquals(5, allNodes.size());
SaltConfig saltConfig = saltConfigCaptor.getValue();
SaltPillarProperties gatewayPillarProperties = saltConfig.getServicePillarConfig().get("gateway");
Map<String, Object> props = (HashMap<String, Object>) gatewayPillarProperties.getProperties().get("gateway");
Map<String, List<String>> location = (HashMap<String, List<String>>) props.get("location");
List<String> ranger = location.get("RANGER");
assertTrue(ranger.contains("master1"));
}

@Test
@MockitoSettings(strictness = Strictness.LENIENT)
void testLDRangerToplogy() throws IOException, CloudbreakOrchestratorFailedException {
setupMocksForRunClusterServices();
Set<Node> nodes = Sets.newHashSet(node("fqdn1"), node("fqdn2"), node("fqdn3"),
node("gateway1"), node("master1"));
when(stackUtil.collectNodes(any())).thenReturn(nodes);
when(exposedServiceCollector.getAllServiceNames()).thenReturn(Set.of("RANGER"));
Map<String, List<String>> locations = new HashMap<>();
locations.put("RANGER", List.of("master1", "master2"));
when(componentLocator.getComponentLocation(any(), any())).thenReturn(locations);
StackView stackViewMock = mock(StackView.class);
when(stackViewMock.getId()).thenReturn(STACK_ID);
ReflectionTestUtils.setField(stack, "stack", stackViewMock);
InstanceGroupView instanceGroupView = mock(InstanceGroupView.class);
InstanceMetadataView instanceMetadataView = mock(InstanceMetadataView.class);
when(instanceMetadataView.getInstanceMetadataType()).thenReturn(InstanceMetadataType.GATEWAY_PRIMARY);
when(instanceGroupView.getGroupName()).thenReturn("GATEWAY");
Map<String, InstanceGroupDto> instanceGroups = new HashMap<>();
InstanceGroupDto instanceGroupDto = new InstanceGroupDto(instanceGroupView, List.of(instanceMetadataView));
instanceGroups.put("GATEWAY", instanceGroupDto);
String lightDutyBP = FileReaderUtils.readFileFromClasspath("cdp-sdx.bp");
Blueprint bp = new Blueprint();
bp.setBlueprintText(lightDutyBP);
ReflectionTestUtils.setField(stack, "instanceGroups", instanceGroups);
ReflectionTestUtils.setField(stack, "blueprint", bp);
underTest.redeployGatewayPillarOnly(stack);
ArgumentCaptor<SaltConfig> saltConfigCaptor = ArgumentCaptor.forClass(SaltConfig.class);
verify(hostOrchestrator).uploadGatewayPillar(any(), allNodesCaptor.capture(), any(), saltConfigCaptor.capture());
Set<Node> allNodes = allNodesCaptor.getValue();
assertEquals(5, allNodes.size());
SaltConfig saltConfig = saltConfigCaptor.getValue();
SaltPillarProperties gatewayPillarProperties = saltConfig.getServicePillarConfig().get("gateway");
Map<String, Object> props = (HashMap<String, Object>) gatewayPillarProperties.getProperties().get("gateway");
Map<String, List<String>> location = (HashMap<String, List<String>>) props.get("location");
List<String> ranger = location.get("RANGER");
assertTrue(ranger.contains("master1"));
}

private void createInstanceGroup(Template template, List<InstanceGroupDto> instanceGroups, String fqdn1, String fqdn2,
String privateIp1, String privateIp2) {
InstanceGroup instanceGroup = new InstanceGroup();
Expand Down
Loading

0 comments on commit 286eb71

Please sign in to comment.