Java Code Examples for org.elasticsearch.common.collect.ImmutableOpenMap#size()

The following examples show how to use org.elasticsearch.common.collect.ImmutableOpenMap#size() . 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: ESDatabaseMetaData.java    From sql4es with Apache License 2.0 6 votes vote down vote up
@Override
public ResultSet getSchemas() throws SQLException {
	ImmutableOpenMap<String, IndexMetaData> indices = client.admin().cluster()
		    .prepareState().get().getState()
		    .getMetaData().getIndices();
	
	SortedMap<String, AliasOrIndex> aliasAndIndices = client.admin().cluster().prepareState().get().getState()
   		.getMetaData().getAliasAndIndexLookup();
	
	Heading heading = new Heading();
	heading.add(new Column("TABLE_SCHEM"));
	heading.add(new Column("TABLE_CATALOG"));
	ESResultSet result = new ESResultSet(heading, indices.size(), heading.getColumnCount());
	for(String key : aliasAndIndices.keySet()){
		List<Object> row = result.getNewRow();
		row.set(0, key);
		row.set(1, "elasticsearch" /* aliasAndIndices.get(key).isAlias() ? "alias" : "index"*/);
		result.add(row);
	}
	return result;
}
 
Example 2
Source File: RoutingProvider.java    From crate with Apache License 2.0 6 votes vote down vote up
public Routing forRandomMasterOrDataNode(RelationName relationName, DiscoveryNodes nodes) {
    DiscoveryNode localNode = nodes.getLocalNode();
    if (localNode.isMasterNode() || localNode.isDataNode()) {
        return forTableOnSingleNode(relationName, localNode.getId());
    }
    ImmutableOpenMap<String, DiscoveryNode> masterAndDataNodes = nodes.getMasterAndDataNodes();
    int randomIdx = seed % masterAndDataNodes.size();
    Iterator<DiscoveryNode> it = masterAndDataNodes.valuesIt();
    int currIdx = 0;
    while (it.hasNext()) {
        if (currIdx == randomIdx) {
            return forTableOnSingleNode(relationName, it.next().getId());
        }
        currIdx++;
    }
    throw new AssertionError("Cannot find a master or data node with given random index " + randomIdx);
}
 
Example 3
Source File: IndexServiceImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, Object> show(String indexName) throws IOException {
    GetIndexRequest request = new GetIndexRequest();
    request.indices(indexName);
    GetIndexResponse getIndexResponse = elasticsearchRestTemplate.getClient()
            .indices().get(request, RequestOptions.DEFAULT);
    ImmutableOpenMap<String, MappingMetaData> mappOpenMap = getIndexResponse.getMappings().get(indexName);
    List<AliasMetaData> indexAliases = getIndexResponse.getAliases().get(indexName);

    String settingsStr = getIndexResponse.getSettings().get(indexName).toString();
    Object settingsObj = null;
    if (StrUtil.isNotEmpty(settingsStr)) {
        settingsObj = JSONObject.parse(settingsStr);
    }
    Map<String, Object> result = new HashMap<>(1);
    Map<String, Object> indexMap = new HashMap<>(3);
    Map<String, Object> mappMap = new HashMap<>(mappOpenMap.size());
    List<String> aliasesList = new ArrayList<>(indexAliases.size());
    indexMap.put("aliases", aliasesList);
    indexMap.put("settings", settingsObj);
    indexMap.put("mappings", mappMap);
    result.put(indexName, indexMap);
    //获取mappings数据
    for (ObjectCursor<String> key : mappOpenMap.keys()) {
        MappingMetaData data = mappOpenMap.get(key.value);
        Map<String, Object> dataMap = data.getSourceAsMap();
        mappMap.put(key.value, dataMap);
    }
    //获取aliases数据
    for (AliasMetaData aliases : indexAliases) {
        aliasesList.add(aliases.getAlias());
    }
    return result;
}
 
Example 4
Source File: Elasticsearch2Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    //----es scher error --
    Thread.currentThread().setName("getTable_001");
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 5
Source File: Elasticsearch6Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 6
Source File: Elasticsearch5Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ElasticsearchTable getTable(SchemaTableName tableName)
{
    String indexWildcard = tableName.getTableName();
    GetIndexRequest getIndexRequest = createGetIndexRequest(indexWildcard);
    Thread.currentThread().setName("getTable_001"); //----es scher error --
    GetIndexResponse response = client.admin().indices()
            .getIndex(getIndexRequest).actionGet();
    if (response.getIndices() == null || response.getIndices().length == 0) {
        return null;
    }
    //TODO: es中运行index名访问时可以使用*进行匹配,所以可能会返回多个index的mapping, 因此下面需要进行mapping merge  test table = test1"*"
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = response.getMappings();

    List<IndexResolution> resolutions;
    if (mappings.size() > 0) {
        resolutions = new ArrayList<>(mappings.size());
        for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> indexMappings : mappings) {
            resolutions.add(buildGetIndexResult(indexMappings.key, indexMappings.value));
        }
    }
    else {
        resolutions = emptyList();
    }

    IndexResolution indexWithMerged = merge(resolutions, indexWildcard);
    return new ElasticsearchTable(typeManager, tableName.getSchemaName(), tableName.getTableName(), indexWithMerged.get());
}
 
Example 7
Source File: DiskThresholdDecider.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link DiskUsage} for the {@link RoutingNode} using the
 * average usage of other nodes in the disk usage map.
 * @param node Node to return an averaged DiskUsage object for
 * @param usages Map of nodeId to DiskUsage for all known nodes
 * @return DiskUsage representing given node using the average disk usage
 */
DiskUsage averageUsage(RoutingNode node, ImmutableOpenMap<String, DiskUsage> usages) {
    if (usages.size() == 0) {
        return new DiskUsage(node.nodeId(), node.node().getName(), "_na_", 0, 0);
    }
    long totalBytes = 0;
    long freeBytes = 0;
    for (ObjectCursor<DiskUsage> du : usages.values()) {
        totalBytes += du.value.getTotalBytes();
        freeBytes += du.value.getFreeBytes();
    }
    return new DiskUsage(node.nodeId(), node.node().getName(), "_na_", totalBytes / usages.size(), freeBytes / usages.size());
}
 
Example 8
Source File: CollectionMatchers.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void describeMismatchSafely(final ImmutableOpenMap map, final Description mismatchDescription) {
    if (map.size() == 0) {
        mismatchDescription.appendText("was empty");
    } else {
        mismatchDescription.appendText(" was ").appendValue(map);
    }
}
 
Example 9
Source File: CollectionMatchers.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void describeMismatchSafely(final ImmutableOpenMap map, final Description mismatchDescription) {
    if (map.size() == 0) {
        mismatchDescription.appendText("was empty");
    } else {
        mismatchDescription.appendText("was ").appendValue(map.keys());
    }
}