Skip to content

Commit 124a440

Browse files
committed
Fix bug when get stopped zk state or env.
1 parent b9d5490 commit 124a440

File tree

9 files changed

+44
-37
lines changed

9 files changed

+44
-37
lines changed

docs/definitions.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ __optional__|integer(int32)
380380
|**minLatency** +
381381
__optional__|integer(int32)
382382
|**mode** +
383-
__optional__|enum (Leader, Follower, Observer)
383+
__optional__|enum (Leader, Follower, Observer, Standalone)
384384
|**nodes** +
385385
__optional__|integer(int32)
386386
|**outstanding** +

docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5393,7 +5393,7 @@ <h3 id="_zkserverstat"><a class="anchor" href="#_zkserverstat"></a>5.24. ZkServe
53935393
<tr>
53945394
<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>mode</strong><br>
53955395
<em>optional</em></p></td>
5396-
<td class="tableblock halign-left valign-middle"><p class="tableblock">enum (Leader, Follower, Observer)</p></td>
5396+
<td class="tableblock halign-left valign-middle"><p class="tableblock">enum (Leader, Follower, Observer, Standalone)</p></td>
53975397
</tr>
53985398
<tr>
53995399
<td class="tableblock halign-left valign-middle"><p class="tableblock"><strong>nodes</strong><br>
@@ -5433,7 +5433,7 @@ <h3 id="_zkserverstat"><a class="anchor" href="#_zkserverstat"></a>5.24. ZkServe
54335433
</div>
54345434
<div id="footer">
54355435
<div id="footer-text">
5436-
Last updated 2018-02-10 00:44:08 CST
5436+
Last updated 2018-11-13 00:36:04 +08:00
54375437
</div>
54385438
</div>
54395439
</body>

docs/index.pdf

24 Bytes
Binary file not shown.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<dependency>
9999
<groupId>org.springframework.boot</groupId>
100100
<artifactId>spring-boot-starter-log4j</artifactId>
101-
<version>RELEASE</version>
101+
<version>1.3.8.RELEASE</version>
102102
</dependency>
103103

104104
<dependency>

src/docs/swagger/swagger.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/main/java/org/gnuhpc/bigdata/constant/ZkServerMode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
public enum ZkServerMode {
44
Leader,
55
Follower,
6-
Observer
6+
Observer,
7+
Standalone
78
}
Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.gnuhpc.bigdata.service;
22

33
import com.google.common.net.HostAndPort;
4+
import java.util.HashMap;
5+
import java.util.List;
46
import lombok.extern.log4j.Log4j;
57
import org.gnuhpc.bigdata.constant.ZkServerCommand;
8+
import org.gnuhpc.bigdata.exception.ServiceNotAvailableException;
69
import org.gnuhpc.bigdata.model.ZkServerEnvironment;
710
import org.gnuhpc.bigdata.model.ZkServerStat;
811
import org.gnuhpc.bigdata.utils.ZookeeperUtils;
@@ -15,36 +18,39 @@
1518
@Service
1619
@Log4j
1720
public class ZookeeperService {
18-
@Autowired
19-
private ZookeeperUtils zookeeperUtils;
2021

21-
public Map<HostAndPort, ZkServerStat> stat() {
22-
return zookeeperUtils.getZookeeperConfig().getHostAndPort().stream()
23-
.collect(Collectors.toMap(
24-
hp -> hp,
25-
hp -> zookeeperUtils.parseStatResult(
26-
zookeeperUtils.executeCommand(
27-
hp.getHostText(),
28-
hp.getPort(),
29-
ZkServerCommand.stat.toString()
30-
)
31-
)
32-
));
33-
}
22+
@Autowired
23+
private ZookeeperUtils zookeeperUtils;
3424

35-
public Map<HostAndPort, ZkServerEnvironment> environment() {
36-
return zookeeperUtils.getZookeeperConfig().getHostAndPort().stream()
37-
.collect(Collectors.toMap(
38-
hp -> hp,
39-
hp -> zookeeperUtils.parseEnvResult(
40-
zookeeperUtils.executeCommand(
41-
hp.getHostText(),
42-
hp.getPort(),
43-
ZkServerCommand.envi.toString()
44-
)
45-
)
46-
));
25+
public Map<HostAndPort, ZkServerStat> stat() {
26+
List<HostAndPort> hostAndPortList = zookeeperUtils.getZookeeperConfig().getHostAndPort();
27+
Map<HostAndPort, ZkServerStat> result = new HashMap<>();
28+
for (int i = 0; i < hostAndPortList.size(); i++) {
29+
HostAndPort hp = hostAndPortList.get(i);
30+
try {
31+
result.put(hp, zookeeperUtils.parseStatResult(zookeeperUtils
32+
.executeCommand(hp.getHostText(), hp.getPort(), ZkServerCommand.stat.toString())));
33+
} catch (ServiceNotAvailableException serviceNotAvailbleException) {
34+
log.warn("Execute " + ZkServerCommand.stat.toString() + " command failed. Exception:"
35+
+ serviceNotAvailbleException);
36+
}
4737
}
38+
return result;
39+
}
4840

49-
41+
public Map<HostAndPort, ZkServerEnvironment> environment() {
42+
List<HostAndPort> hostAndPortList = zookeeperUtils.getZookeeperConfig().getHostAndPort();
43+
Map<HostAndPort, ZkServerEnvironment> result = new HashMap<>();
44+
for (int i = 0; i < hostAndPortList.size(); i++) {
45+
HostAndPort hp = hostAndPortList.get(i);
46+
try {
47+
result.put(hp, zookeeperUtils.parseEnvResult(zookeeperUtils
48+
.executeCommand(hp.getHostText(), hp.getPort(), ZkServerCommand.envi.toString())));
49+
} catch (ServiceNotAvailableException serviceNotAvailbleException) {
50+
log.warn("Execute " + ZkServerCommand.envi.toString() + " command failed. Exception:"
51+
+ serviceNotAvailbleException);
52+
}
53+
}
54+
return result;
55+
}
5056
}

src/main/java/org/gnuhpc/bigdata/utils/KafkaUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public KafkaConsumer createNewConsumer(String consumerGroup) {
7474
properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
7575
properties.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, "30000");
7676
properties.put(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, "100000000");
77-
properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, "500");
77+
properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, "5");
7878
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
7979
StringDeserializer.class.getCanonicalName());
8080
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,

src/main/resources/application-tina.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
kafka:
2-
brokers: localhost:9092,localhost:9093,localhost:9094
2+
brokers: localhost:19092,localhost:19093,localhost:19095
33
offset:
44
topic: "__consumer_offsets"
55
partitions: 50
@@ -8,7 +8,7 @@ kafka:
88
topic: "health"
99

1010
zookeeper:
11-
uris: 127.0.0.1:2181
11+
uris: 127.0.0.1:2183,127.0.0.1:2182
1212

1313
jmx:
1414
kafka:

0 commit comments

Comments
 (0)