org.elasticsearch.action.admin.indices.status.IndexStatus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.status;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.common.collect.Lists.*;
/**
* @author kimchy (shay.banon)
*/
public class IndexStatus implements Iterable {
private final String index;
private final Map indexShards;
private final Settings settings;
IndexStatus(String index, Settings settings, ShardStatus[] shards) {
this.index = index;
this.settings = settings;
Map> tmpIndexShards = Maps.newHashMap();
for (ShardStatus shard : shards) {
List lst = tmpIndexShards.get(shard.shardRouting().id());
if (lst == null) {
lst = newArrayList();
tmpIndexShards.put(shard.shardRouting().id(), lst);
}
lst.add(shard);
}
indexShards = Maps.newHashMap();
for (Map.Entry> entry : tmpIndexShards.entrySet()) {
indexShards.put(entry.getKey(), new IndexShardStatus(entry.getValue().get(0).shardRouting().shardId(), entry.getValue().toArray(new ShardStatus[entry.getValue().size()])));
}
}
public String index() {
return this.index;
}
public String getIndex() {
return index();
}
/**
* A shard id to index shard status map (note, index shard status is the replication shard group that maps
* to the shard id).
*/
public Map shards() {
return this.indexShards;
}
public Map getShards() {
return shards();
}
public Settings settings() {
return this.settings;
}
public Settings getSettings() {
return settings();
}
public ByteSizeValue storeSize() {
long bytes = -1;
for (IndexShardStatus shard : this) {
if (shard.storeSize() != null) {
if (bytes == -1) {
bytes = 0;
}
bytes += shard.storeSize().bytes();
}
}
if (bytes == -1) {
return null;
}
return new ByteSizeValue(bytes);
}
public ByteSizeValue getStoreSize() {
return storeSize();
}
public long translogOperations() {
long translogOperations = -1;
for (IndexShardStatus shard : this) {
if (shard.translogOperations() != -1) {
if (translogOperations == -1) {
translogOperations = 0;
}
translogOperations += shard.translogOperations();
}
}
return translogOperations;
}
public long getTranslogOperations() {
return translogOperations();
}
private transient DocsStatus docs;
public DocsStatus docs() {
if (docs != null) {
return docs;
}
DocsStatus docs = null;
for (IndexShardStatus shard : this) {
if (shard.docs() == null) {
continue;
}
if (docs == null) {
docs = new DocsStatus();
}
docs.numDocs += shard.docs().numDocs();
docs.maxDoc += shard.docs().maxDoc();
docs.deletedDocs += shard.docs().deletedDocs();
}
this.docs = docs;
return docs;
}
public DocsStatus getDocs() {
return docs();
}
@Override public Iterator iterator() {
return indexShards.values().iterator();
}
}