Package org.elasticsearch.cluster.metadata

Examples of org.elasticsearch.cluster.metadata.IndexMetaData$Custom


        // and collection_type information would be lost.
        String[] indexNames = getIndexNames(analysis.table(), analysis.partitionName().orNull());
        PutMappingRequest request = new PutMappingRequest();
        request.indices(indexNames);
        request.type(Constants.DEFAULT_MAPPING_TYPE);
        IndexMetaData indexMetaData = clusterService.state().getMetaData().getIndices().get(indexNames[0]);
        try {
            Map mergedMeta = (Map)indexMetaData.getMappings()
                    .get(Constants.DEFAULT_MAPPING_TYPE)
                    .getSourceAsMap()
                    .get("_meta");
            if (mergedMeta != null) {
                XContentHelper.update(mergedMeta, (Map) mapping.get("_meta"));
View Full Code Here


   * @param index Index name
   * @param type Mapping name
   * @return true if mapping exists
   */
  private boolean isMappingExist(String index, String type) {
        IndexMetaData imd = null;
        try {
            ClusterState cs = client.admin().cluster().prepareState().setIndices(index).execute().actionGet().getState();
            imd = cs.getMetaData().index(index);
        } catch (IndexMissingException e) {
            // If there is no index, there is no mapping either
        }

        if (imd == null) return false;

    MappingMetaData mdd = imd.mapping(type);

    if (mdd != null) return true;
    return false;
  }
View Full Code Here

        assertThat(node, not(nullValue()));
        return node;
    }

    protected boolean isMappingExist(Client client, String index, String type) {
        IndexMetaData imd = null;
        try {
            ClusterState cs = client.admin().cluster().prepareState().setIndices(index).execute().actionGet().getState();
            imd = cs.getMetaData().index(index);
        } catch (IndexMissingException e) {
            // If there is no index, there is no mapping either
        }

        if (imd == null) return false;

        MappingMetaData mdd = imd.mapping(type);

        if (mdd != null) return true;
        return false;
    }
View Full Code Here

    public void testSettings() {
        String path = getClass().getResource("/importdata/import_9").getPath();
        executeImportRequest("{\"directory\": \"" + path + "\", \"settings\": true}");

        ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().filteredIndices("index1");
        IndexMetaData stats = esSetup.client().admin().cluster().state(clusterStateRequest).actionGet().getState().metaData().index("index1");
        assertEquals(2, stats.numberOfShards());
        assertEquals(1, stats.numberOfReplicas());
    }
View Full Code Here

        clusterStateRequest.listenerThreaded(false);

        ClusterStateResponse response = client.state(clusterStateRequest).actionGet();
        MetaData metaData = response.getState().metaData();
        IndexMetaData indexMetaData = metaData.iterator().next();
        if (context.settings()) {
            try {
                XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
                builder.startObject();
                builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
                builder.startObject("settings");
                Settings settings = settingsFilter.filterSettings(indexMetaData.settings());
                for (Map.Entry<String, String> entry: settings.getAsMap().entrySet()) {
                    builder.field(entry.getKey(), entry.getValue());
                }
                builder.endObject();
                builder.endObject();
                builder.endObject();
                File settingsFile = new File(context.outputFile() + ".settings");
                if (!context.forceOverride() && settingsFile.exists()) {
                    throw new IOException("File exists: " + settingsFile.getAbsolutePath());
                }
                OutputStream os = new FileOutputStream(settingsFile);
                os.write(builder.bytes().toBytes());
                os.flush();
                os.close();
            } catch (IOException e) {
                throw new ExportException(context, "Failed to write settings for index " + indexMetaData.index(), e);
            }
        }
        if (context.mappings()) {
            try {
                XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
                builder.startObject();
                builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE);
                Set<String> types = new HashSet<String>(Arrays.asList(context.types()));
                boolean noTypes = types.isEmpty();
                for (MappingMetaData mappingMetaData : indexMetaData.mappings().values()) {
                    if (noTypes || types.contains(mappingMetaData.type())) {
                        builder.field(mappingMetaData.type());
                        builder.map(mappingMetaData.sourceAsMap());
                    }
                }
                builder.endObject();
                builder.endObject();
                File mappingsFile = new File(context.outputFile() + ".mapping");
                if (!context.forceOverride() && mappingsFile.exists()) {
                    throw new IOException("File exists: " + mappingsFile.getAbsolutePath());
                }
                OutputStream os = new FileOutputStream(mappingsFile);
                os.write(builder.bytes().toBytes());
                os.flush();
                os.close();
            } catch (IOException e) {
                throw new ExportException(context, "Failed to write mappings for index " + indexMetaData.index(), e);
            }
        }
    }
View Full Code Here

        assertTrue(existsWithField("1", "name", "item1", "users", "d"));
        assertTrue(existsWithField("2", "name", "item2", "users", "d"));

        ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().filteredIndices("users");
        IndexMetaData metaData = esSetup.client().admin().cluster().state(clusterStateRequest).actionGet().getState().metaData().index("users");
        assertEquals("{\"d\":{\"properties\":{\"name\":{\"type\":\"string\",\"index\":\"not_analyzed\",\"store\":true,\"omit_norms\":true,\"index_options\":\"docs\"}}}}",
                metaData.mappings().get("d").source().toString());
        assertEquals(2, metaData.numberOfShards());
        assertEquals(0, metaData.numberOfReplicas());
    }
View Full Code Here

    public void warmTopReader(WarmerContext context) {
        warmInternal(context, true);
    }

    private void warmInternal(final WarmerContext context, boolean topReader) {
        final IndexMetaData indexMetaData = clusterService.state().metaData().index(context.shardId().index().name());
        if (indexMetaData == null) {
            return;
        }
        if (!indexMetaData.settings().getAsBoolean(INDEX_WARMER_ENABLED, settings.getAsBoolean(INDEX_WARMER_ENABLED, true))) {
            return;
        }
        IndexService indexService = indicesService.indexService(context.shardId().index().name());
        if (indexService == null) {
            return;
View Full Code Here

            return currentState;
        }

        RiversRouting.Builder routingBuilder = RiversRouting.builder().routing(currentState.routing());
        boolean dirty = false;
        IndexMetaData indexMetaData = newClusterState.metaData().index(riverIndexName);

        boolean metaFound = true;
        // go over and create new river routing (with no node) for new types (rivers names)
        for (ObjectCursor<MappingMetaData> cursor : indexMetaData.mappings().values()) {
            String mappingType = cursor.value.type(); // mapping type is the name of the river
            if (MapperService.DEFAULT_MAPPING.equals(mappingType)) {
                continue;
            }
            if (!currentState.routing().hasRiverByName(mappingType)) {
                // no river, we need to add it to the routing with no node allocation
                try {
                    GetResponse getResponse = client.prepareGet(riverIndexName, mappingType, "_meta").setPreference("_primary").get();
                    if (getResponse.isExists()) {

                        logger.debug("{}/{}/_meta document found.", riverIndexName, mappingType);

                        String riverType = XContentMapValues.nodeStringValue(getResponse.getSourceAsMap().get("type"), null);
                        if (riverType == null) {
                            logger.warn("no river type provided for [{}], ignoring...", riverIndexName);
                        } else {
                            routingBuilder.put(new RiverRouting(new RiverName(riverType, mappingType), null));
                            dirty = true;
                        }
                    } else {
                        // At least one type does not have _meta
                        metaFound = false;
                    }
                } catch (NoShardAvailableActionException e) {
                    // ignore, we will get it next time...
                } catch (ClusterBlockException e) {
                    // ignore, we will get it next time
                } catch (IndexMissingException e) {
                    // ignore, we will get it next time
                } catch (IllegalIndexShardStateException e) {
                    // ignore, we will get it next time
                } catch (Exception e) {
                    logger.warn("failed to get/parse _meta for [{}]", e, mappingType);
                }
            }
        }

        // At least one type does not have _meta, so we are
        // going to reschedule some checks
        if (!metaFound) {
            if (countDown.countDown()) {
                logger.warn("no river _meta document found after {} attempts", RIVER_START_MAX_RETRIES);
            } else {
                logger.debug("no river _meta document found retrying in {} ms", RIVER_START_RETRY_INTERVAL.millis());
                try {
                    threadPool.schedule(RIVER_START_RETRY_INTERVAL, ThreadPool.Names.GENERIC, new Runnable() {
                        @Override
                        public void run() {
                            riverClusterService.submitStateUpdateTask(source, new RiverClusterStateUpdateTask() {
                                @Override
                                public RiverClusterState execute(RiverClusterState currentState) {
                                    return updateRiverClusterState(source, currentState, riverClusterService.state(), countDown);
                                }
                            });
                        }
                    });
                } catch (EsRejectedExecutionException ex) {
                    logger.debug("Couldn't schedule river start retry, node might be shutting down", ex);
                }
            }
        }

        // now, remove routings that were deleted
        // also, apply nodes that were removed and rivers were running on
        for (RiverRouting routing : currentState.routing()) {
            if (!indexMetaData.mappings().containsKey(routing.riverName().name())) {
                routingBuilder.remove(routing);
                dirty = true;
            } else if (routing.node() != null && !newClusterState.nodes().nodeExists(routing.node().id())) {
                routingBuilder.remove(routing);
                routingBuilder.put(new RiverRouting(routing.riverName(), null));
View Full Code Here

        }
    }

    private void cleanMismatchedIndexUUIDs(final ClusterChangedEvent event) {
        for (IndexService indexService : indicesService) {
            IndexMetaData indexMetaData = event.state().metaData().index(indexService.index().name());
            if (indexMetaData == null) {
                // got deleted on us, will be deleted later
                continue;
            }
            if (!indexMetaData.isSameUUID(indexService.indexUUID())) {
                logger.debug("[{}] mismatch on index UUIDs between cluster state and local state, cleaning the index so it will be recreated", indexMetaData.index());
                removeIndex(indexMetaData.index(), "mismatch on index UUIDs between cluster state and local state, cleaning the index so it will be recreated");
            }
        }
    }
View Full Code Here

    private void applyCleanedIndices(final ClusterChangedEvent event) {
        // handle closed indices, since they are not allocated on a node once they are closed
        // so applyDeletedIndices might not take them into account
        for (Map.Entry<String, IndexService> entry : indicesService.indices().entrySet()) {
            String index = entry.getKey();
            IndexMetaData indexMetaData = event.state().metaData().index(index);
            if (indexMetaData != null && indexMetaData.state() == IndexMetaData.State.CLOSE) {
                IndexService indexService = entry.getValue();
                for (Integer shardId : indexService.shardIds()) {
                    logger.debug("[{}][{}] removing shard (index is closed)", index, shardId);
                    try {
                        indexService.removeShard(shardId, "removing shard (index is closed)");
View Full Code Here

TOP

Related Classes of org.elasticsearch.cluster.metadata.IndexMetaData$Custom

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.