Skip to content

Commit 10a245e

Browse files
committed
fix problem with transport client starting
1 parent bcc59ac commit 10a245e

File tree

10 files changed

+145
-134
lines changed

10 files changed

+145
-134
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/ExceptionsHelper.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,31 @@
1919

2020
package org.elasticsearch;
2121

22+
import org.elasticsearch.util.logging.ESLogger;
23+
import org.elasticsearch.util.logging.Loggers;
24+
2225
/**
23-
* @author kimchy (Shay Banon)
26+
* @author kimchy (shay.banon)
2427
*/
2528
public final class ExceptionsHelper {
2629

30+
private static final ESLogger logger = Loggers.getLogger(ExceptionsHelper.class);
31+
2732
public static Throwable unwrapCause(Throwable t) {
33+
int counter = 0;
2834
Throwable result = t;
2935
while (result instanceof ElasticSearchWrapperException) {
36+
if (t.getCause() == null) {
37+
return result;
38+
}
39+
if (t.getCause() == t) {
40+
return result;
41+
}
42+
if (counter++ > 10) {
43+
// dear god, if we got more than 10 levels down, WTF? just bail
44+
logger.warn("Exception cause unwrapping ran for 10 levels...", t);
45+
return result;
46+
}
3047
result = t.getCause();
3148
}
3249
return result;

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/JmxNetworkProbe.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ public class JmxNetworkProbe extends AbstractComponent implements NetworkProbe {
4242
stats.timestamp = System.currentTimeMillis();
4343
return stats;
4444
}
45+
46+
@Override public String ifconfig() {
47+
return "NA";
48+
}
4549
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkProbe.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ public interface NetworkProbe {
2727
NetworkInfo networkInfo();
2828

2929
NetworkStats networkStats();
30+
31+
String ifconfig();
3032
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/NetworkService.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
import org.elasticsearch.util.inject.Inject;
2424
import org.elasticsearch.util.settings.Settings;
2525

26+
import java.net.InetAddress;
27+
import java.net.NetworkInterface;
28+
import java.util.Enumeration;
29+
2630
/**
2731
* @author kimchy (shay.banon)
2832
*/
@@ -37,6 +41,36 @@ public class NetworkService extends AbstractComponent {
3741
this.probe = probe;
3842

3943
this.info = probe.networkInfo();
44+
45+
if (logger.isDebugEnabled()) {
46+
StringBuilder netDebug = new StringBuilder("net_info");
47+
try {
48+
Enumeration<NetworkInterface> enum_ = NetworkInterface.getNetworkInterfaces();
49+
String hostName = InetAddress.getLocalHost().getHostName();
50+
netDebug.append("\nhost [").append(hostName).append("]\n");
51+
while (enum_.hasMoreElements()) {
52+
NetworkInterface net = enum_.nextElement();
53+
54+
netDebug.append(net.getName()).append('\t').append("display_name [").append(net.getDisplayName()).append("]\n");
55+
Enumeration<InetAddress> addresses = net.getInetAddresses();
56+
netDebug.append("\t\taddress ");
57+
while (addresses.hasMoreElements()) {
58+
netDebug.append("[").append(addresses.nextElement()).append("] ");
59+
}
60+
netDebug.append('\n');
61+
netDebug.append("\t\tmtu [").append(net.getMTU()).append("] multicast [").append(net.supportsMulticast()).append("] ptp [").append(net.isPointToPoint())
62+
.append("] loopback [").append(net.isLoopback()).append("] up [").append(net.isUp()).append("] virtual [").append(net.isVirtual()).append("]")
63+
.append('\n');
64+
}
65+
} catch (Exception ex) {
66+
netDebug.append("Failed to get Network Interface Info [" + ex.getMessage() + "]");
67+
}
68+
logger.debug(netDebug.toString());
69+
}
70+
71+
if (logger.isTraceEnabled()) {
72+
logger.trace("ifconfig\n\n" + ifconfig());
73+
}
4074
}
4175

4276
public NetworkInfo info() {
@@ -46,4 +80,8 @@ public NetworkInfo info() {
4680
public NetworkStats stats() {
4781
return probe.networkStats();
4882
}
83+
84+
public String ifconfig() {
85+
return probe.ifconfig();
86+
}
4987
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/network/SigarNetworkProbe.java

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import org.elasticsearch.util.component.AbstractComponent;
2424
import org.elasticsearch.util.inject.Inject;
2525
import org.elasticsearch.util.settings.Settings;
26-
import org.hyperic.sigar.NetInterfaceConfig;
27-
import org.hyperic.sigar.Sigar;
28-
import org.hyperic.sigar.SigarException;
29-
import org.hyperic.sigar.Tcp;
26+
import org.hyperic.sigar.*;
3027

3128
/**
3229
* @author kimchy (shay.banon)
@@ -80,4 +77,85 @@ public class SigarNetworkProbe extends AbstractComponent implements NetworkProbe
8077

8178
return stats;
8279
}
80+
81+
@Override public String ifconfig() {
82+
Sigar sigar = sigarService.sigar();
83+
StringBuilder sb = new StringBuilder();
84+
try {
85+
for (String ifname : sigar.getNetInterfaceList()) {
86+
NetInterfaceConfig ifconfig = null;
87+
try {
88+
ifconfig = sigar.getNetInterfaceConfig(ifname);
89+
} catch (SigarException e) {
90+
sb.append(ifname + "\t" + "Not Avaialbe [" + e.getMessage() + "]");
91+
}
92+
long flags = ifconfig.getFlags();
93+
94+
String hwaddr = "";
95+
if (!NetFlags.NULL_HWADDR.equals(ifconfig.getHwaddr())) {
96+
hwaddr = " HWaddr " + ifconfig.getHwaddr();
97+
}
98+
99+
if (!ifconfig.getName().equals(ifconfig.getDescription())) {
100+
sb.append(ifconfig.getDescription()).append('\n');
101+
}
102+
103+
sb.append(ifconfig.getName() + "\t" + "Link encap:" + ifconfig.getType() + hwaddr).append('\n');
104+
105+
String ptp = "";
106+
if ((flags & NetFlags.IFF_POINTOPOINT) > 0) {
107+
ptp = " P-t-P:" + ifconfig.getDestination();
108+
}
109+
110+
String bcast = "";
111+
if ((flags & NetFlags.IFF_BROADCAST) > 0) {
112+
bcast = " Bcast:" + ifconfig.getBroadcast();
113+
}
114+
115+
sb.append("\t" +
116+
"inet addr:" + ifconfig.getAddress() +
117+
ptp + //unlikely
118+
bcast +
119+
" Mask:" + ifconfig.getNetmask()).append('\n');
120+
121+
sb.append("\t" +
122+
NetFlags.getIfFlagsString(flags) +
123+
" MTU:" + ifconfig.getMtu() +
124+
" Metric:" + ifconfig.getMetric()).append('\n');
125+
try {
126+
NetInterfaceStat ifstat = sigar.getNetInterfaceStat(ifname);
127+
128+
sb.append("\t" +
129+
"RX packets:" + ifstat.getRxPackets() +
130+
" errors:" + ifstat.getRxErrors() +
131+
" dropped:" + ifstat.getRxDropped() +
132+
" overruns:" + ifstat.getRxOverruns() +
133+
" frame:" + ifstat.getRxFrame()).append('\n');
134+
135+
sb.append("\t" +
136+
"TX packets:" + ifstat.getTxPackets() +
137+
" errors:" + ifstat.getTxErrors() +
138+
" dropped:" + ifstat.getTxDropped() +
139+
" overruns:" + ifstat.getTxOverruns() +
140+
" carrier:" + ifstat.getTxCarrier()).append('\n');
141+
sb.append("\t" + "collisions:" +
142+
ifstat.getTxCollisions()).append('\n');
143+
144+
long rxBytes = ifstat.getRxBytes();
145+
long txBytes = ifstat.getTxBytes();
146+
147+
sb.append("\t" +
148+
"RX bytes:" + rxBytes +
149+
" (" + Sigar.formatSize(rxBytes) + ")" +
150+
" " +
151+
"TX bytes:" + txBytes +
152+
" (" + Sigar.formatSize(txBytes) + ")").append('\n');
153+
} catch (SigarException e) {
154+
}
155+
}
156+
return sb.toString();
157+
} catch (SigarException e) {
158+
return "NA";
159+
}
160+
}
83161
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/JmxOsProbe.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,4 @@ public class JmxOsProbe extends AbstractComponent implements OsProbe {
4141
stats.timestamp = System.currentTimeMillis();
4242
return stats;
4343
}
44-
45-
@Override public String ifconfig() {
46-
return "NA";
47-
}
4844
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsProbe.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,4 @@ public interface OsProbe {
2727
OsInfo osInfo();
2828

2929
OsStats osStats();
30-
31-
String ifconfig();
3230
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/OsService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,4 @@ public OsInfo info() {
4848
public OsStats stats() {
4949
return probe.osStats();
5050
}
51-
52-
public String ifconfig() {
53-
return probe.ifconfig();
54-
}
5551
}

modules/elasticsearch/src/main/java/org/elasticsearch/monitor/os/SigarOsProbe.java

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -126,85 +126,4 @@ public class SigarOsProbe extends AbstractComponent implements OsProbe {
126126

127127
return stats;
128128
}
129-
130-
@Override public String ifconfig() {
131-
Sigar sigar = sigarService.sigar();
132-
StringBuilder sb = new StringBuilder();
133-
try {
134-
for (String ifname : sigar.getNetInterfaceList()) {
135-
NetInterfaceConfig ifconfig = null;
136-
try {
137-
ifconfig = sigar.getNetInterfaceConfig(ifname);
138-
} catch (SigarException e) {
139-
sb.append(ifname + "\t" + "Not Avaialbe [" + e.getMessage() + "]");
140-
}
141-
long flags = ifconfig.getFlags();
142-
143-
String hwaddr = "";
144-
if (!NetFlags.NULL_HWADDR.equals(ifconfig.getHwaddr())) {
145-
hwaddr = " HWaddr " + ifconfig.getHwaddr();
146-
}
147-
148-
if (!ifconfig.getName().equals(ifconfig.getDescription())) {
149-
sb.append(ifconfig.getDescription()).append('\n');
150-
}
151-
152-
sb.append(ifconfig.getName() + "\t" + "Link encap:" + ifconfig.getType() + hwaddr).append('\n');
153-
154-
String ptp = "";
155-
if ((flags & NetFlags.IFF_POINTOPOINT) > 0) {
156-
ptp = " P-t-P:" + ifconfig.getDestination();
157-
}
158-
159-
String bcast = "";
160-
if ((flags & NetFlags.IFF_BROADCAST) > 0) {
161-
bcast = " Bcast:" + ifconfig.getBroadcast();
162-
}
163-
164-
sb.append("\t" +
165-
"inet addr:" + ifconfig.getAddress() +
166-
ptp + //unlikely
167-
bcast +
168-
" Mask:" + ifconfig.getNetmask()).append('\n');
169-
170-
sb.append("\t" +
171-
NetFlags.getIfFlagsString(flags) +
172-
" MTU:" + ifconfig.getMtu() +
173-
" Metric:" + ifconfig.getMetric()).append('\n');
174-
try {
175-
NetInterfaceStat ifstat = sigar.getNetInterfaceStat(ifname);
176-
177-
sb.append("\t" +
178-
"RX packets:" + ifstat.getRxPackets() +
179-
" errors:" + ifstat.getRxErrors() +
180-
" dropped:" + ifstat.getRxDropped() +
181-
" overruns:" + ifstat.getRxOverruns() +
182-
" frame:" + ifstat.getRxFrame()).append('\n');
183-
184-
sb.append("\t" +
185-
"TX packets:" + ifstat.getTxPackets() +
186-
" errors:" + ifstat.getTxErrors() +
187-
" dropped:" + ifstat.getTxDropped() +
188-
" overruns:" + ifstat.getTxOverruns() +
189-
" carrier:" + ifstat.getTxCarrier()).append('\n');
190-
sb.append("\t" + "collisions:" +
191-
ifstat.getTxCollisions()).append('\n');
192-
193-
long rxBytes = ifstat.getRxBytes();
194-
long txBytes = ifstat.getTxBytes();
195-
196-
sb.append("\t" +
197-
"RX bytes:" + rxBytes +
198-
" (" + Sigar.formatSize(rxBytes) + ")" +
199-
" " +
200-
"TX bytes:" + txBytes +
201-
" (" + Sigar.formatSize(txBytes) + ")").append('\n');
202-
} catch (SigarException e) {
203-
}
204-
}
205-
return sb.toString();
206-
} catch (SigarException e) {
207-
return "NA";
208-
}
209-
}
210129
}

modules/elasticsearch/src/main/java/org/elasticsearch/util/network/NetworkService.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.elasticsearch.util.network;
2121

22-
import org.elasticsearch.monitor.os.JmxOsProbe;
23-
import org.elasticsearch.monitor.os.OsService;
2422
import org.elasticsearch.util.MapBuilder;
2523
import org.elasticsearch.util.collect.ImmutableMap;
2624
import org.elasticsearch.util.component.AbstractComponent;
@@ -32,7 +30,6 @@
3230
import java.net.NetworkInterface;
3331
import java.net.UnknownHostException;
3432
import java.util.Collection;
35-
import java.util.Enumeration;
3633

3734
/**
3835
* @author kimchy (shay.banon)
@@ -59,42 +56,8 @@ public static interface CustomNameResolver {
5956

6057
private volatile ImmutableMap<String, CustomNameResolver> customNameResolvers = ImmutableMap.of();
6158

62-
public NetworkService(Settings settings) {
63-
this(settings, new OsService(settings, new JmxOsProbe(settings)));
64-
}
65-
66-
@Inject public NetworkService(Settings settings, OsService service) {
59+
@Inject public NetworkService(Settings settings) {
6760
super(settings);
68-
69-
if (logger.isDebugEnabled()) {
70-
StringBuilder netDebug = new StringBuilder("net_info");
71-
try {
72-
Enumeration<NetworkInterface> enum_ = NetworkInterface.getNetworkInterfaces();
73-
String hostName = InetAddress.getLocalHost().getHostName();
74-
netDebug.append("\nhost [").append(hostName).append("]\n");
75-
while (enum_.hasMoreElements()) {
76-
NetworkInterface net = enum_.nextElement();
77-
78-
netDebug.append(net.getName()).append('\t').append("display_name [").append(net.getDisplayName()).append("]\n");
79-
Enumeration<InetAddress> addresses = net.getInetAddresses();
80-
netDebug.append("\t\taddress ");
81-
while (addresses.hasMoreElements()) {
82-
netDebug.append("[").append(addresses.nextElement()).append("] ");
83-
}
84-
netDebug.append('\n');
85-
netDebug.append("\t\tmtu [").append(net.getMTU()).append("] multicast [").append(net.supportsMulticast()).append("] ptp [").append(net.isPointToPoint())
86-
.append("] loopback [").append(net.isLoopback()).append("] up [").append(net.isUp()).append("] virtual [").append(net.isVirtual()).append("]")
87-
.append('\n');
88-
}
89-
} catch (Exception ex) {
90-
netDebug.append("Failed to get Network Interface Info [" + ex.getMessage() + "]");
91-
}
92-
logger.debug(netDebug.toString());
93-
}
94-
95-
if (logger.isTraceEnabled()) {
96-
logger.trace("ifconfig\n\n" + service.ifconfig());
97-
}
9861
}
9962

10063
public void addCustomNameResolver(String name, CustomNameResolver customNameResolver) {

0 commit comments

Comments
 (0)