Search in sources :

Example 1 with SizeValue

use of org.elasticsearch.common.unit.SizeValue in project elasticsearch by elastic.

the class FixedExecutorBuilder method build.

@Override
ThreadPool.ExecutorHolder build(final FixedExecutorSettings settings, final ThreadContext threadContext) {
    int size = settings.size;
    int queueSize = settings.queueSize;
    final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(EsExecutors.threadName(settings.nodeName, name()));
    final ExecutorService executor = EsExecutors.newFixed(name(), size, queueSize, threadFactory, threadContext);
    final ThreadPool.Info info = new ThreadPool.Info(name(), ThreadPool.ThreadPoolType.FIXED, size, size, null, queueSize < 0 ? null : new SizeValue(queueSize));
    return new ThreadPool.ExecutorHolder(executor, info);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) SizeValue(org.elasticsearch.common.unit.SizeValue) ExecutorService(java.util.concurrent.ExecutorService)

Example 2 with SizeValue

use of org.elasticsearch.common.unit.SizeValue in project elasticsearch by elastic.

the class RestTable method renderValue.

private static String renderValue(RestRequest request, Object value) {
    if (value == null) {
        return null;
    }
    if (value instanceof ByteSizeValue) {
        ByteSizeValue v = (ByteSizeValue) value;
        String resolution = request.param("bytes");
        if ("b".equals(resolution)) {
            return Long.toString(v.getBytes());
        } else if ("k".equals(resolution) || "kb".equals(resolution)) {
            return Long.toString(v.getKb());
        } else if ("m".equals(resolution) || "mb".equals(resolution)) {
            return Long.toString(v.getMb());
        } else if ("g".equals(resolution) || "gb".equals(resolution)) {
            return Long.toString(v.getGb());
        } else if ("t".equals(resolution) || "tb".equals(resolution)) {
            return Long.toString(v.getTb());
        } else if ("p".equals(resolution) || "pb".equals(resolution)) {
            return Long.toString(v.getPb());
        } else {
            return v.toString();
        }
    }
    if (value instanceof SizeValue) {
        SizeValue v = (SizeValue) value;
        String resolution = request.param("size");
        if ("".equals(resolution)) {
            return Long.toString(v.singles());
        } else if ("k".equals(resolution)) {
            return Long.toString(v.kilo());
        } else if ("m".equals(resolution)) {
            return Long.toString(v.mega());
        } else if ("g".equals(resolution)) {
            return Long.toString(v.giga());
        } else if ("t".equals(resolution)) {
            return Long.toString(v.tera());
        } else if ("p".equals(resolution)) {
            return Long.toString(v.peta());
        } else {
            return v.toString();
        }
    }
    if (value instanceof TimeValue) {
        TimeValue v = (TimeValue) value;
        String resolution = request.param("time");
        if ("nanos".equals(resolution)) {
            return Long.toString(v.nanos());
        } else if ("micros".equals(resolution)) {
            return Long.toString(v.micros());
        } else if ("ms".equals(resolution)) {
            return Long.toString(v.millis());
        } else if ("s".equals(resolution)) {
            return Long.toString(v.seconds());
        } else if ("m".equals(resolution)) {
            return Long.toString(v.minutes());
        } else if ("h".equals(resolution)) {
            return Long.toString(v.hours());
        } else if ("d".equals(resolution)) {
            return Long.toString(v.days());
        } else {
            return v.toString();
        }
    }
    // Add additional built in data points we can render based on request parameters?
    return value.toString();
}
Also used : SizeValue(org.elasticsearch.common.unit.SizeValue) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 3 with SizeValue

use of org.elasticsearch.common.unit.SizeValue in project elasticsearch-skywalker by jprante.

the class RestConsistencyCheckAction method handleRequest.

@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    ConsistencyCheckRequest r = new ConsistencyCheckRequest();
    client.admin().cluster().execute(ConsistencyCheckAction.INSTANCE, r, new RestResponseListener<ConsistencyCheckResponse>(channel) {

        @Override
        public RestResponse buildResponse(ConsistencyCheckResponse response) throws Exception {
            XContentBuilder builder = XContentFactory.jsonBuilder();
            builder.startObject();
            builder.field("ok", true);
            builder.startObject("state");
            response.getState().toXContent(builder, ToXContent.EMPTY_PARAMS);
            builder.startArray("files");
            for (File file : response.getFiles()) {
                Instant instant = new Instant(file.lastModified());
                builder.startObject().field("path", file.getAbsolutePath()).field("lastmodified", instant.toDateTime().toString()).field("size", new SizeValue(file.length(), SizeUnit.SINGLE).toString()).field("totalspace", new SizeValue(file.getTotalSpace(), SizeUnit.SINGLE).toString()).field("usablespace", new SizeValue(file.getUsableSpace(), SizeUnit.SINGLE).toString()).field("freespace", new SizeValue(file.getFreeSpace(), SizeUnit.SINGLE).toString()).endObject();
            }
            builder.endArray();
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : ConsistencyCheckRequest(org.xbib.elasticsearch.action.admin.cluster.state.ConsistencyCheckRequest) SizeValue(org.elasticsearch.common.unit.SizeValue) Instant(org.elasticsearch.common.joda.time.Instant) File(java.io.File) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ConsistencyCheckResponse(org.xbib.elasticsearch.action.admin.cluster.state.ConsistencyCheckResponse)

Example 4 with SizeValue

use of org.elasticsearch.common.unit.SizeValue in project crate by crate.

the class FixedExecutorBuilder method build.

@Override
ThreadPool.ExecutorHolder build(final FixedExecutorSettings settings) {
    int size = settings.size;
    int queueSize = settings.queueSize;
    final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(EsExecutors.threadName(settings.nodeName, name()));
    final ExecutorService executor = EsExecutors.newFixed(settings.nodeName + "/" + name(), size, queueSize, threadFactory);
    final ThreadPool.Info info = new ThreadPool.Info(name(), ThreadPool.ThreadPoolType.FIXED, size, size, null, queueSize < 0 ? null : new SizeValue(queueSize));
    return new ThreadPool.ExecutorHolder(executor, info);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) SizeValue(org.elasticsearch.common.unit.SizeValue) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

SizeValue (org.elasticsearch.common.unit.SizeValue)4 ExecutorService (java.util.concurrent.ExecutorService)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 File (java.io.File)1 Instant (org.elasticsearch.common.joda.time.Instant)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 ConsistencyCheckRequest (org.xbib.elasticsearch.action.admin.cluster.state.ConsistencyCheckRequest)1 ConsistencyCheckResponse (org.xbib.elasticsearch.action.admin.cluster.state.ConsistencyCheckResponse)1