Skip to content

Commit 10f431e

Browse files
akantoKrisztian Horvath
authored and
Krisztian Horvath
committed
CLOUD-67831 Avoid timeouts when IPV6 is disabled saltstack/salt#32719
1 parent d5a233d commit 10f431e

File tree

14 files changed

+106
-53
lines changed

14 files changed

+106
-53
lines changed

core-model/src/main/java/com/sequenceiq/cloudbreak/domain/HostMetadata.java

+9
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,13 @@ public boolean equals(Object o) {
9898
return EqualsBuilder.reflectionEquals(this, o, "hostGroup");
9999
}
100100

101+
@Override
102+
public String toString() {
103+
return "HostMetadata{"
104+
+ "id=" + id
105+
+ ", hostName='" + hostName + '\''
106+
+ ", hostGroupName=" + (hostGroup != null ? hostGroup.getName() : null)
107+
+ ", hostMetadataState=" + hostMetadataState
108+
+ '}';
109+
}
101110
}

core/src/main/java/com/sequenceiq/cloudbreak/reactor/api/event/resource/DecommissionResult.java

+7
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ public DecommissionResult(String statusReason, Exception errorDetails, Decommiss
2020
public Set<String> getHostNames() {
2121
return hostNames;
2222
}
23+
24+
@Override
25+
public String toString() {
26+
return "DecommissionResult{"
27+
+ "hostNames=" + hostNames
28+
+ '}';
29+
}
2330
}

core/src/main/java/com/sequenceiq/cloudbreak/service/cluster/filter/HostFilterService.java

+4
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,21 @@ public class HostFilterService {
4040

4141
public List<HostMetadata> filterHostsForDecommission(Cluster cluster, Set<HostMetadata> hosts, String hostGroup) throws CloudbreakSecuritySetupException {
4242
List<HostMetadata> filteredList = new ArrayList<>(hosts);
43+
LOGGER.info("Ambari service config, hostGroup: {}, originalList: {}", hostGroup, filteredList);
4344
HttpClientConfig clientConfig = tlsSecurityService.buildTLSClientConfig(cluster.getStack().getId(), cluster.getAmbariIp());
4445
AmbariClient ambariClient = ambariClientProvider.getAmbariClient(clientConfig, cluster.getStack().getGatewayPort(), cluster.getUserName(),
4546
cluster.getPassword());
4647
Map<String, String> config = configurationService.getConfiguration(ambariClient, hostGroup);
48+
LOGGER.info("Ambari service config, hostGroup: {}, config: {}", hostGroup, config);
4749
for (HostFilter hostFilter : hostFilters) {
4850
try {
4951
filteredList = hostFilter.filter(cluster.getId(), config, filteredList);
52+
LOGGER.info("Filtered with hostfilter: {}, filteredList: {}", hostFilter.getClass().getSimpleName(), filteredList);
5053
} catch (HostFilterException e) {
5154
LOGGER.warn("Filter didn't succeed, moving to next filter", e);
5255
}
5356
}
57+
LOGGER.info("Returned filtered hosts: {}", filteredList);
5458
return filteredList;
5559
}
5660
}

core/src/main/java/com/sequenceiq/cloudbreak/service/cluster/flow/AmbariDecommissioner.java

+4
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ private boolean doesHostGroupContainDataNode(AmbariClient client, String bluepri
258258
private List<HostMetadata> checkAndSortByAvailableSpace(Stack stack, AmbariClient client, int replication, int adjustment,
259259
List<HostMetadata> filteredHostList) {
260260
int removeCount = Math.abs(adjustment);
261+
LOGGER.info("removeCount: {}, replication: {}, filteredHostList size: {}, filteredHostList: {}",
262+
removeCount, replication, filteredHostList.size(), filteredHostList);
261263
Map<String, Map<Long, Long>> dfsSpace = getDFSSpace(stack, client);
262264
Map<String, Long> sortedAscending = sortByUsedSpace(dfsSpace, false);
265+
LOGGER.info("sortedAscending: {}", sortedAscending);
263266
Map<String, Long> selectedNodes = selectNodes(sortedAscending, filteredHostList, removeCount);
264267
Map<String, Long> remainingNodes = removeSelected(sortedAscending, selectedNodes);
265268
LOGGER.info("Selected nodes for decommission: {}", selectedNodes);
@@ -290,6 +293,7 @@ private Map<String, Map<Long, Long>> getDFSSpace(Stack stack, AmbariClient clien
290293
}
291294

292295
private Map<String, Long> selectNodes(Map<String, Long> sortedAscending, List<HostMetadata> filteredHostList, int removeCount) {
296+
LOGGER.info("sortedAscending: {}, filteredHostList: {}", sortedAscending, filteredHostList);
293297
Map<String, Long> select = new HashMap<>();
294298
int i = 0;
295299
for (String host : sortedAscending.keySet()) {

core/src/main/java/com/sequenceiq/cloudbreak/service/stack/flow/HostMetadataSetup.java

+1-33
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
18-
import org.springframework.beans.factory.annotation.Value;
1918
import org.springframework.stereotype.Service;
20-
import org.springframework.util.StringUtils;
2119

2220
import com.sequenceiq.cloudbreak.client.RestClientUtil;
2321
import com.sequenceiq.cloudbreak.common.type.OrchestratorConstants;
@@ -36,10 +34,6 @@ public class HostMetadataSetup {
3634

3735
private static final Logger LOGGER = LoggerFactory.getLogger(HostMetadataSetup.class);
3836
private static final String HOSTNAME_ENDPOINT = "saltboot/hostname/distribute";
39-
private static final String DEFAULT_DOMAIN = ".example.com";
40-
41-
@Value("${cb.host.discovery.custom.domain:}")
42-
private String customDomain;
4337

4438
@Inject
4539
private StackService stackService;
@@ -100,8 +94,7 @@ private void updateWithHostData(HttpClientConfig clientConfig, Stack stack, Set<
10094
String address = members.get(privateIp);
10195
// TODO remove column
10296
instanceMetaData.setConsulServer(false);
103-
String fqdn = determineFqdn(instanceMetaData.getInstanceId(), instanceMetaData.getPrivateIp(), address);
104-
instanceMetaData.setDiscoveryFQDN(fqdn);
97+
instanceMetaData.setDiscoveryFQDN(address);
10598
LOGGER.info("Domain used for isntance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), address,
10699
instanceMetaData.getDiscoveryFQDN());
107100
}
@@ -114,29 +107,4 @@ private void updateWithHostData(HttpClientConfig clientConfig, Stack stack, Set<
114107
}
115108
}
116109

117-
private String determineFqdn(String id, String ip, String address) {
118-
String fqdn;
119-
if (StringUtils.isEmpty(customDomain)) {
120-
if (address.split("\\.").length == 1) {
121-
//if there is no domain, we need to add one since ambari fails without domain, actually it does nothing just hangs...
122-
fqdn = address + DEFAULT_DOMAIN;
123-
LOGGER.warn("Default domain is used, since there is no proper domain configured for instance: {}, ip: {}, original: {}, fqdn: {}",
124-
id, ip, address, fqdn);
125-
} else {
126-
fqdn = address;
127-
}
128-
} else {
129-
String hostname = address.split("\\.")[0];
130-
// this is just for convenience
131-
if (customDomain.startsWith(".")) {
132-
fqdn = hostname + customDomain;
133-
} else {
134-
fqdn = hostname + "." + customDomain;
135-
}
136-
LOGGER.warn("Domain of instance will be overwritten instance: {}, ip: {}, original: {}, fqdn: {}",
137-
id, ip, address, fqdn);
138-
}
139-
return fqdn;
140-
}
141-
142110
}

integration-test/src/main/java/com/sequenceiq/it/cloudbreak/mock/MockClusterCreationWithSaltSuccessTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private void addSaltMappings(int numberOfServers) {
183183
new ServerAddressGenerator(numberOfServers).iterateOver(address -> {
184184
GenericResponse genericResponse = new GenericResponse();
185185
genericResponse.setAddress(address);
186-
genericResponse.setStatus("host-" + address.replace(".", "-"));
186+
genericResponse.setStatus("host-" + address.replace(".", "-") + ".example.com");
187187
responses.add(genericResponse);
188188
});
189189
genericResponses.setResponses(responses);

integration-test/src/main/java/com/sequenceiq/it/cloudbreak/mock/MockClusterScalingTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private void addMockEndpoints(int numberOfServers, int scalingAdjustment) {
166166
serverAddressGenerator.iterateOver(address -> {
167167
GenericResponse genericResponse = new GenericResponse();
168168
genericResponse.setAddress(address);
169-
genericResponse.setStatus("host-" + address.replace(".", "-"));
169+
genericResponse.setStatus("host-" + address.replace(".", "-") + ".example.com");
170170
responses.add(genericResponse);
171171
});
172172
genericResponses.setResponses(responses);

orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/SaltOrchestrator.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.zip.ZipEntry;
2020
import java.util.zip.ZipOutputStream;
2121

22+
import javax.inject.Inject;
23+
2224
import org.apache.commons.io.IOUtils;
2325
import org.slf4j.Logger;
2426
import org.slf4j.LoggerFactory;
@@ -54,6 +56,7 @@
5456
import com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner;
5557
import com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner;
5658
import com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner;
59+
import com.sequenceiq.cloudbreak.orchestrator.salt.service.HostDiscoveryService;
5760
import com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates;
5861
import com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria;
5962
import com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel;
@@ -73,8 +76,8 @@ public class SaltOrchestrator implements HostOrchestrator {
7376
@Value("${cb.smartsense.configure:false}")
7477
private boolean configureSmartSense;
7578

76-
@Value("${cb.host.discovery.custom.domain:}")
77-
private String customDomain;
79+
@Inject
80+
private HostDiscoveryService hostDiscoveryService;
7881

7982
private ParallelOrchestratorComponentRunner parallelOrchestratorComponentRunner;
8083
private ExitCriteria exitCriteria;
@@ -96,7 +99,7 @@ public void bootstrap(GatewayConfig gatewayConfig, Set<Node> targets, ExitCriter
9699
Future<Boolean> saltPillarRunnerFuture = getParallelOrchestratorComponentRunner().submit(saltPillarRunner);
97100
saltPillarRunnerFuture.get();
98101

99-
SaltBootstrap saltBootstrap = new SaltBootstrap(sc, gatewayConfig, targets);
102+
SaltBootstrap saltBootstrap = new SaltBootstrap(sc, gatewayConfig, targets, hostDiscoveryService.determineDomain());
100103
Callable<Boolean> saltBootstrapRunner = runner(saltBootstrap, exitCriteria, exitCriteriaModel);
101104
Future<Boolean> saltBootstrapRunnerFuture = getParallelOrchestratorComponentRunner().submit(saltBootstrapRunner);
102105
saltBootstrapRunnerFuture.get();
@@ -109,7 +112,7 @@ public void bootstrap(GatewayConfig gatewayConfig, Set<Node> targets, ExitCriter
109112
@Override
110113
public void bootstrapNewNodes(GatewayConfig gatewayConfig, Set<Node> targets, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorException {
111114
try (SaltConnector sc = new SaltConnector(gatewayConfig, restDebug)) {
112-
SaltBootstrap saltBootstrap = new SaltBootstrap(sc, gatewayConfig, targets);
115+
SaltBootstrap saltBootstrap = new SaltBootstrap(sc, gatewayConfig, targets, hostDiscoveryService.determineDomain());
113116
Callable<Boolean> saltBootstrapRunner = runner(saltBootstrap, exitCriteria, exitCriteriaModel);
114117
Future<Boolean> saltBootstrapRunnerFuture = getParallelOrchestratorComponentRunner().submit(saltBootstrapRunner);
115118
saltBootstrapRunnerFuture.get();
@@ -123,7 +126,7 @@ public void bootstrapNewNodes(GatewayConfig gatewayConfig, Set<Node> targets, Ex
123126
public void runService(GatewayConfig gatewayConfig, Set<Node> allNodes, SaltPillarConfig pillarConfig,
124127
ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorException {
125128
try (SaltConnector sc = new SaltConnector(gatewayConfig, restDebug)) {
126-
PillarSave hostSave = new PillarSave(sc, allNodes, !StringUtils.isEmpty(customDomain));
129+
PillarSave hostSave = new PillarSave(sc, allNodes, !StringUtils.isEmpty(hostDiscoveryService.determineDomain()));
127130
Callable<Boolean> saltPillarRunner = runner(hostSave, exitCriteria, exitCriteriaModel);
128131
Future<Boolean> saltPillarRunnerFuture = getParallelOrchestratorComponentRunner().submit(saltPillarRunner);
129132
saltPillarRunnerFuture.get();
@@ -138,11 +141,7 @@ public void runService(GatewayConfig gatewayConfig, Set<Node> allNodes, SaltPill
138141
Set<String> server = Sets.newHashSet(gatewayConfig.getPrivateAddress());
139142
Set<String> all = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
140143

141-
LOGGER.info("Pillar saved, starting to set up discovery...");
142-
//run discovery only
143-
runNewService(sc, new HighStateRunner(all, allNodes), exitCriteriaModel);
144-
145-
LOGGER.info("Pillar saved, discovery has been set up with highstate");
144+
LOGGER.info("Pillar saved, setting up grains...");
146145

147146
// ambari server
148147
runSaltCommand(sc, new GrainAddRunner(server, allNodes, "ambari_server"), exitCriteriaModel);

orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/domain/Minion.java

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Minion {
99
private String server;
1010
private String hostGroup;
1111

12+
private String domain;
13+
1214
public String getAddress() {
1315
return address;
1416
}
@@ -40,4 +42,12 @@ public String getHostGroup() {
4042
public void setHostGroup(String hostGroup) {
4143
this.hostGroup = hostGroup;
4244
}
45+
46+
public String getDomain() {
47+
return domain;
48+
}
49+
50+
public void setDomain(String domain) {
51+
this.domain = domain;
52+
}
4353
}

orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/domain/SaltMaster.java

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class SaltMaster {
66

77
private SaltAuth auth;
88

9+
private String domain;
10+
911
public String getAddress() {
1012
return address;
1113
}
@@ -21,4 +23,12 @@ public SaltAuth getAuth() {
2123
public void setAuth(SaltAuth auth) {
2224
this.auth = auth;
2325
}
26+
27+
public String getDomain() {
28+
return domain;
29+
}
30+
31+
public void setDomain(String domain) {
32+
this.domain = domain;
33+
}
2434
}

orchestrator-salt/src/main/java/com/sequenceiq/cloudbreak/orchestrator/salt/poller/SaltBootstrap.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ public class SaltBootstrap implements OrchestratorBootstrap {
3333
private final GatewayConfig gatewayConfig;
3434
private final Set<Node> originalTargets;
3535
private Set<Node> targets;
36+
private String domain;
3637

37-
public SaltBootstrap(SaltConnector sc, GatewayConfig gatewayConfig, Set<Node> targets) {
38+
public SaltBootstrap(SaltConnector sc, GatewayConfig gatewayConfig, Set<Node> targets, String domain) {
3839
this.sc = sc;
3940
this.gatewayConfig = gatewayConfig;
4041
this.originalTargets = Collections.unmodifiableSet(targets);
4142
this.targets = targets;
43+
this.domain = domain;
4244
}
4345

4446
@Override
@@ -89,6 +91,7 @@ private SaltAction createBootstrap() {
8991
SaltMaster master = new SaltMaster();
9092
master.setAddress(getGatewayPrivateIp());
9193
master.setAuth(auth);
94+
master.setDomain(domain);
9295
saltAction.setMaster(master);
9396
//set due to compatibility reason
9497
saltAction.setServer(getGatewayPrivateIp());
@@ -109,6 +112,7 @@ private Minion createMinion(Node node) {
109112
minion.setRoles(Collections.emptyList());
110113
minion.setServer(getGatewayPrivateIp());
111114
minion.setHostGroup(node.getHostGroup());
115+
minion.setDomain(domain);
112116
return minion;
113117
}
114118

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.sequenceiq.cloudbreak.orchestrator.salt.service;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.stereotype.Service;
7+
import org.springframework.util.StringUtils;
8+
9+
@Service
10+
public class HostDiscoveryService {
11+
12+
private static final Logger LOGGER = LoggerFactory.getLogger(HostDiscoveryService.class);
13+
14+
@Value("${cb.host.discovery.custom.domain:}")
15+
private String customDomain;
16+
17+
public String determineDomain() {
18+
String domainName = null;
19+
if (!StringUtils.isEmpty(customDomain)) {
20+
// this is just for convenience
21+
if (customDomain.startsWith(".")) {
22+
domainName = customDomain;
23+
} else {
24+
domainName = "." + customDomain;
25+
}
26+
LOGGER.info("Custom domain defined: {}", domainName);
27+
28+
}
29+
return domainName;
30+
}
31+
}

0 commit comments

Comments
 (0)