Improved event's short description

This commit is contained in:
Boaz Leskes 2013-12-17 14:56:14 +01:00
parent 71757bb330
commit 7a2d6d840f
6 changed files with 44 additions and 15 deletions

View file

@ -225,7 +225,7 @@ public class ExportersService extends AbstractLifecycleComponent<ExportersServic
}
for (int shardId : indexService.shardIds()) {
IndexShard indexShard = indexService.shard(shardId);
if (indexShard == null) {
if (indexShard == null || indexShard.state() != IndexShardState.STARTED) {
continue;
}
shardStats.add(new ShardStats(indexShard, CommonStatsFlags.ALL));

View file

@ -55,4 +55,18 @@ public class Utils {
}
return builder;
}
public static String nodeDescription(DiscoveryNode node) {
StringBuilder builder = new StringBuilder().append("[").append(node.name()).append("]");
if (node.address().uniqueAddressTypeId() == 1) { // InetSocket
InetSocketTransportAddress address = (InetSocketTransportAddress) node.address();
InetSocketAddress inetSocketAddress = address.address();
InetAddress inetAddress = inetSocketAddress.getAddress();
if (inetAddress != null) {
builder.append("[").append(inetAddress.getHostAddress()).append(":").append(inetSocketAddress.getPort()).append("]");
}
}
return builder.toString();
}
}

View file

@ -91,7 +91,7 @@ public abstract class NodeEvent extends Event {
@Override
String conciseDescription() {
return node.toString() + (joined ? " joined" : " left");
return Utils.nodeDescription(node) + (joined ? " joined" : " left");
}
@Override

View file

@ -47,6 +47,9 @@ public abstract class RoutingEvent extends Event {
return builder;
}
private static String shardDescription(ShardRouting shardRouting) {
return shardRouting.shardId() + "[" + (shardRouting.primary() ? "P" : "R") + "]";
}
static abstract class RoutingShardEvent extends RoutingEvent {
@ -86,7 +89,7 @@ public abstract class RoutingEvent extends Event {
@Override
String conciseDescription() {
return shardRouting.shardId() + "[" + (shardRouting.primary() ? "P" : "R") + "] set to initializing on " + node;
return shardDescription(shardRouting) + " set to initializing on " + Utils.nodeDescription(node);
}
}
@ -106,11 +109,11 @@ public abstract class RoutingEvent extends Event {
@Override
String conciseDescription() {
String s = shardRouting.shardId() + "[" + (shardRouting.primary() ? "P" : "R") + "] set to relocate";
String s = shardDescription(shardRouting) + " set to relocate";
if (relocatingTo != null) {
s += " to " + relocatingTo;
}
return s + " from " + node;
return s + " from " + Utils.nodeDescription(node);
}
@Override

View file

@ -64,15 +64,15 @@ public class ShardEvent extends Event {
// no shard routing
return new DescriptionBuilder(shardId, "created", node).build();
case RECOVERING:
return new DescriptionBuilder(shardId, "entered recovery", node).relocatedFrom(relocatingNode).build();
return new DescriptionBuilder(shardRouting, "entered recovery", node).relocatedFrom(relocatingNode).build();
case POST_RECOVERY:
return new DescriptionBuilder(shardId, "entered post_recovery", node).relocatedFrom(relocatingNode).build();
return new DescriptionBuilder(shardRouting, "entered post_recovery", node).relocatedFrom(relocatingNode).build();
case STARTED:
return new DescriptionBuilder(shardId, "started", node).relocatedFrom(relocatingNode).build();
return new DescriptionBuilder(shardRouting, "started", node).relocatedFrom(relocatingNode).build();
case RELOCATED:
return new DescriptionBuilder(shardId, "relocated", node).relocatedTo(relocatingNode).build();
return new DescriptionBuilder(shardRouting, "relocated", node).relocatedTo(relocatingNode).build();
case CLOSED:
return new DescriptionBuilder(shardId, "closed", node).relocatedTo(relocatingNode).build();
return new DescriptionBuilder(shardRouting, "closed", node).relocatedTo(relocatingNode).build();
default:
throw new ElasticSearchException("unmapped shard event type [" + shardState + "]");
}
@ -108,20 +108,32 @@ public class ShardEvent extends Event {
private final StringBuilder description = new StringBuilder();
DescriptionBuilder (ShardId shardId, String changeDescription, DiscoveryNode node) {
description.append(shardId).append(' ').append(changeDescription).append(" on ").append(node);
DescriptionBuilder(ShardId shardId, String changeDescription, DiscoveryNode node) {
description.append(shardId).append(' ').append(changeDescription).append(" on ")
.append(Utils.nodeDescription(node));
}
DescriptionBuilder(ShardRouting shardRouting, String changeDescription, DiscoveryNode node) {
description.append(shardRouting.shardId());
if (shardRouting.primary()) {
description.append("[P]");
} else {
description.append("[R]");
}
description.append(' ').append(changeDescription).append(" on ")
.append(Utils.nodeDescription(node));
}
DescriptionBuilder relocatedFrom(DiscoveryNode node) {
if (node != null) {
description.append(", relocated from ").append(node);
description.append(", relocated from ").append(Utils.nodeDescription(node));
}
return this;
}
DescriptionBuilder relocatedTo(DiscoveryNode node) {
if (node != null) {
description.append(", relocated to ").append(node);
description.append(", relocated to ").append(Utils.nodeDescription(node));
}
return this;
}

View file

@ -172,7 +172,7 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement
}
private void sendCloseExportingConnection(HttpURLConnection conn) throws IOException {
logger.trace("sending exporting content");
logger.trace("sending content");
OutputStream os = conn.getOutputStream();
os.close();