Java Code Examples for org.elasticsearch.common.xcontent.XContentBuilder#humanReadableField()

The following examples show how to use org.elasticsearch.common.xcontent.XContentBuilder#humanReadableField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllocateUnassignedDecision.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    checkDecisionState();
    builder.field("can_allocate", getAllocationDecision());
    builder.field("allocate_explanation", getExplanation());
    if (targetNode != null) {
        builder.startObject("target_node");
        discoveryNodeToXContent(targetNode, true, builder);
        builder.endObject();
    }
    if (allocationId != null) {
        builder.field("allocation_id", allocationId);
    }
    if (allocationStatus == AllocationStatus.DELAYED_ALLOCATION) {
        builder.humanReadableField("configured_delay_in_millis", "configured_delay",
            TimeValue.timeValueMillis(configuredDelayInMillis));
        builder.humanReadableField("remaining_delay_in_millis", "remaining_delay",
            TimeValue.timeValueMillis(remainingDelayInMillis));
    }
    nodeDecisionsToXContent(nodeDecisions, builder, params);
    return builder;
}
 
Example 2
Source File: SnapshotDeletionsInProgress.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startArray(TYPE);
    for (Entry entry : entries) {
        builder.startObject();
        {
            builder.field("repository", entry.snapshot.getRepository());
            builder.field("snapshot", entry.snapshot.getSnapshotId().getName());
            builder.humanReadableField("start_time_millis", "start_time", new TimeValue(entry.startTime));
            builder.field("repository_state_id", entry.repositoryStateId);
        }
        builder.endObject();
    }
    builder.endArray();
    return builder;
}
 
Example 3
Source File: RecoveryState.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.field(Fields.RECOVERED, recovered);
    builder.field(Fields.TOTAL, total);
    builder.field(Fields.PERCENT, String.format(Locale.ROOT, "%1.1f%%", recoveredPercent()));
    builder.field(Fields.TOTAL_ON_START, totalOnStart);
    builder.humanReadableField(Fields.TOTAL_TIME_IN_MILLIS, Fields.TOTAL_TIME, new TimeValue(time()));
    return builder;
}
 
Example 4
Source File: RecoveryState.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field(Fields.NAME, name);
    builder.humanReadableField(Fields.LENGTH_IN_BYTES, Fields.LENGTH, new ByteSizeValue(length));
    builder.field(Fields.REUSED, reused);
    builder.humanReadableField(Fields.RECOVERED_IN_BYTES, Fields.RECOVERED, new ByteSizeValue(recovered));
    builder.endObject();
    return builder;
}
 
Example 5
Source File: RecoveryState.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    // stream size first, as it matters more and the files section can be long
    builder.startObject(Fields.SIZE);
    builder.humanReadableField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, new ByteSizeValue(totalBytes()));
    builder.humanReadableField(Fields.REUSED_IN_BYTES, Fields.REUSED, new ByteSizeValue(reusedBytes()));
    builder.humanReadableField(Fields.RECOVERED_IN_BYTES, Fields.RECOVERED, new ByteSizeValue(recoveredBytes()));
    builder.field(Fields.PERCENT, String.format(Locale.ROOT, "%1.1f%%", recoveredBytesPercent()));
    builder.endObject();

    builder.startObject(Fields.FILES);
    builder.field(Fields.TOTAL, totalFileCount());
    builder.field(Fields.REUSED, reusedFileCount());
    builder.field(Fields.RECOVERED, recoveredFileCount());
    builder.field(Fields.PERCENT, String.format(Locale.ROOT, "%1.1f%%", recoveredFilesPercent()));
    if (params.paramAsBoolean("details", false)) {
        builder.startArray(Fields.DETAILS);
        for (File file : fileDetails.values()) {
            file.toXContent(builder, params);
        }
        builder.endArray();
    }
    builder.endObject();
    builder.humanReadableField(Fields.TOTAL_TIME_IN_MILLIS, Fields.TOTAL_TIME, new TimeValue(time()));
    builder.humanReadableField(Fields.SOURCE_THROTTLE_TIME_IN_MILLIS, Fields.SOURCE_THROTTLE_TIME, sourceThrottling());
    builder.humanReadableField(Fields.TARGET_THROTTLE_TIME_IN_MILLIS, Fields.TARGET_THROTTLE_TIME, targetThrottling());
    return builder;
}
 
Example 6
Source File: HttpInfo.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.HTTP);
    builder.array(Fields.BOUND_ADDRESS, (Object[]) address.boundAddresses());
    builder.field(Fields.PUBLISH_ADDRESS, address.publishAddress().toString());
    builder.humanReadableField(Fields.MAX_CONTENT_LENGTH_IN_BYTES, Fields.MAX_CONTENT_LENGTH, maxContentLength());
    builder.endObject();
    return builder;
}
 
Example 7
Source File: StoreStats.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.STORE);
    builder.humanReadableField(Fields.SIZE_IN_BYTES, Fields.SIZE, size());
    builder.endObject();
    return builder;
}
 
Example 8
Source File: NodeAllocationResult.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject("store");
    {
        if (matchingBytes < 0) {
            // dealing with a primary shard
            if (allocationId == null && storeException == null) {
                // there was no information we could obtain of any shard data on the node
                builder.field("found", false);
            } else {
                builder.field("in_sync", inSync);
            }
        }
        if (allocationId != null) {
            builder.field("allocation_id", allocationId);
        }
        if (matchingBytes >= 0) {
            if (hasMatchingSyncId()) {
                builder.field("matching_sync_id", true);
            } else {
                builder.humanReadableField("matching_size_in_bytes", "matching_size", new ByteSizeValue(matchingBytes));
            }
        }
        if (storeException != null) {
            builder.startObject("store_exception");
            ElasticsearchException.generateThrowableXContent(builder, params, storeException);
            builder.endObject();
        }
    }
    builder.endObject();
    return builder;
}
 
Example 9
Source File: SnapshotsInProgress.java    From crate with Apache License 2.0 5 votes vote down vote up
public void toXContent(Entry entry, XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject();
    builder.field(REPOSITORY, entry.snapshot().getRepository());
    builder.field(SNAPSHOT, entry.snapshot().getSnapshotId().getName());
    builder.field(UUID, entry.snapshot().getSnapshotId().getUUID());
    builder.field(INCLUDE_GLOBAL_STATE, entry.includeGlobalState());
    builder.field(PARTIAL, entry.partial());
    builder.field(STATE, entry.state());
    builder.startArray(INDICES);
    {
        for (IndexId index : entry.indices()) {
            index.toXContent(builder, params);
        }
    }
    builder.endArray();
    builder.humanReadableField(START_TIME_MILLIS, START_TIME, new TimeValue(entry.startTime()));
    builder.field(REPOSITORY_STATE_ID, entry.getRepositoryStateId());
    builder.startArray(SHARDS);
    {
        for (ObjectObjectCursor<ShardId, ShardSnapshotStatus> shardEntry : entry.shards) {
            ShardId shardId = shardEntry.key;
            ShardSnapshotStatus status = shardEntry.value;
            builder.startObject();
            {
                builder.field(INDEX, shardId.getIndex());
                builder.field(SHARD, shardId.getId());
                builder.field(STATE, status.state());
                builder.field(NODE, status.nodeId());
            }
            builder.endObject();
        }
    }
    builder.endArray();
    builder.endObject();
}
 
Example 10
Source File: DiskUsage.java    From crate with Apache License 2.0 5 votes vote down vote up
XContentBuilder toShortXContent(XContentBuilder builder) throws IOException {
    builder.field("path", this.path);
    builder.humanReadableField("total_bytes", "total", new ByteSizeValue(this.totalBytes));
    builder.humanReadableField("used_bytes", "used", new ByteSizeValue(this.getUsedBytes()));
    builder.humanReadableField("free_bytes", "free", new ByteSizeValue(this.freeBytes));
    builder.field("free_disk_percent", truncatePercent(this.getFreeDiskAsPercentage()));
    builder.field("used_disk_percent", truncatePercent(this.getUsedDiskAsPercentage()));
    return builder;
}
 
Example 11
Source File: ProcessInfo.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.PROCESS);
    builder.humanReadableField(Fields.REFRESH_INTERVAL_IN_MILLIS, Fields.REFRESH_INTERVAL, new TimeValue(refreshInterval));
    builder.field(Fields.ID, id);
    builder.field(Fields.MLOCKALL, mlockall);
    builder.endObject();
    return builder;
}
 
Example 12
Source File: RecoveryState.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {

    builder.field(Fields.ID, shardId.id());
    builder.field(Fields.TYPE, recoverySource.getType());
    builder.field(Fields.STAGE, stage.toString());
    builder.field(Fields.PRIMARY, primary);
    builder.timeField(Fields.START_TIME_IN_MILLIS, Fields.START_TIME, timer.startTime);
    if (timer.stopTime > 0) {
        builder.timeField(Fields.STOP_TIME_IN_MILLIS, Fields.STOP_TIME, timer.stopTime);
    }
    builder.humanReadableField(Fields.TOTAL_TIME_IN_MILLIS, Fields.TOTAL_TIME, new TimeValue(timer.time()));

    if (recoverySource.getType() == RecoverySource.Type.PEER) {
        builder.startObject(Fields.SOURCE);
        builder.field(Fields.ID, sourceNode.getId());
        builder.field(Fields.HOST, sourceNode.getHostName());
        builder.field(Fields.TRANSPORT_ADDRESS, sourceNode.getAddress().toString());
        builder.field(Fields.IP, sourceNode.getHostAddress());
        builder.field(Fields.NAME, sourceNode.getName());
        builder.endObject();
    } else {
        builder.startObject(Fields.SOURCE);
        recoverySource.addAdditionalFields(builder, params);
        builder.endObject();
    }

    builder.startObject(Fields.TARGET);
    builder.field(Fields.ID, targetNode.getId());
    builder.field(Fields.HOST, targetNode.getHostName());
    builder.field(Fields.TRANSPORT_ADDRESS, targetNode.getAddress().toString());
    builder.field(Fields.IP, targetNode.getHostAddress());
    builder.field(Fields.NAME, targetNode.getName());
    builder.endObject();

    builder.startObject(Fields.INDEX);
    index.toXContent(builder, params);
    builder.endObject();

    builder.startObject(Fields.TRANSLOG);
    translog.toXContent(builder, params);
    builder.endObject();

    builder.startObject(Fields.VERIFY_INDEX);
    verifyIndex.toXContent(builder, params);
    builder.endObject();

    return builder;
}
 
Example 13
Source File: RecoveryState.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.humanReadableField(Fields.CHECK_INDEX_TIME_IN_MILLIS, Fields.CHECK_INDEX_TIME, new TimeValue(checkIndexTime));
    builder.humanReadableField(Fields.TOTAL_TIME_IN_MILLIS, Fields.TOTAL_TIME, new TimeValue(time()));
    return builder;
}
 
Example 14
Source File: SnapshotInfo.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
    // write snapshot info to repository snapshot blob format
    if (CONTEXT_MODE_SNAPSHOT.equals(params.param(CONTEXT_MODE_PARAM))) {
        return toXContentInternal(builder, params);
    }

    final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE);
    // write snapshot info for the API and any other situations
    builder.startObject();
    builder.field(SNAPSHOT, snapshotId.getName());
    builder.field(UUID, snapshotId.getUUID());
    if (version != null) {
        builder.field(VERSION_ID, version.internalId);
        builder.field(VERSION, version.toString());
    }
    builder.startArray(INDICES);
    for (String index : indices) {
        builder.value(index);
    }
    builder.endArray();
    if (includeGlobalState != null) {
        builder.field(INCLUDE_GLOBAL_STATE, includeGlobalState);
    }
    if (verbose || state != null) {
        builder.field(STATE, state);
    }
    if (reason != null) {
        builder.field(REASON, reason);
    }
    if (verbose || startTime != 0) {
        builder.field(START_TIME, DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(startTime).atZone(ZoneOffset.UTC)));
        builder.field(START_TIME_IN_MILLIS, startTime);
    }
    if (verbose || endTime != 0) {
        builder.field(END_TIME, DATE_TIME_FORMATTER.format(Instant.ofEpochMilli(endTime).atZone(ZoneOffset.UTC)));
        builder.field(END_TIME_IN_MILLIS, endTime);
        builder.humanReadableField(DURATION_IN_MILLIS, DURATION, new TimeValue(endTime - startTime));
    }
    if (verbose || !shardFailures.isEmpty()) {
        builder.startArray(FAILURES);
        for (SnapshotShardFailure shardFailure : shardFailures) {
            builder.startObject();
            shardFailure.toXContent(builder, params);
            builder.endObject();
        }
        builder.endArray();
    }
    if (verbose || totalShards != 0) {
        builder.startObject(SHARDS);
        builder.field(TOTAL, totalShards);
        builder.field(FAILED, failedShards());
        builder.field(SUCCESSFUL, successfulShards);
        builder.endObject();
    }
    builder.endObject();
    return builder;
}