本文整理汇总了Java中org.elasticsearch.ResourceAlreadyExistsException类的典型用法代码示例。如果您正苦于以下问题:Java ResourceAlreadyExistsException类的具体用法?Java ResourceAlreadyExistsException怎么用?Java ResourceAlreadyExistsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResourceAlreadyExistsException类属于org.elasticsearch包,在下文中一共展示了ResourceAlreadyExistsException类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: validateIndexName
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
/**
* Validate the name for an index against some static rules and a cluster state.
*/
public static void validateIndexName(String index, ClusterState state) {
validateIndexOrAliasName(index, InvalidIndexNameException::new);
if (!index.toLowerCase(Locale.ROOT).equals(index)) {
throw new InvalidIndexNameException(index, "must be lowercase");
}
if (state.routingTable().hasIndex(index)) {
throw new ResourceAlreadyExistsException(state.routingTable().index(index).getIndex());
}
if (state.metaData().hasIndex(index)) {
throw new ResourceAlreadyExistsException(state.metaData().index(index).getIndex());
}
if (state.metaData().hasAlias(index)) {
throw new InvalidIndexNameException(index, "already exists as alias");
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:MetaDataCreateIndexService.java
示例2: updateIndexName
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
private void updateIndexName(Configuration config) {
this.logIndexPrefix = config.getProperty("workflow.elasticsearch.tasklog.index.name", "task_log");
this.logIndexName = this.logIndexPrefix + "_" + sdf.format(new Date());
try {
client.admin().indices().prepareGetIndex().addIndices(logIndexName).execute().actionGet();
} catch (IndexNotFoundException infe) {
try {
client.admin().indices().prepareCreate(logIndexName).execute().actionGet();
} catch (ResourceAlreadyExistsException ilee) {
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
开发者ID:Netflix,项目名称:conductor,代码行数:17,代码来源:ElasticSearchDAO.java
示例3: putMapping
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
public void putMapping(String index,
String type,
MetaObject metaObject) {
checkNotEmpty("index",
index);
checkNotEmpty("type",
type);
checkNotNull("metaObject",
metaObject);
try {
this.getClient().admin().indices().prepareCreate(sanitizeIndex(index)).get();
} catch (ResourceAlreadyExistsException ex) {
logger.debug("Resource Already exists: " + ex.getMessage());
}
Map<String, Object> properties = this.createMappingMap(metaObject.getProperties());
this.getClient().admin().indices()
.preparePutMapping(sanitizeIndex(index))
.setType(sanitizeIndex(type))
.setSource(properties).get();
}
开发者ID:kiegroup,项目名称:appformer,代码行数:21,代码来源:ElasticSearchIndexProvider.java
示例4: testCreateIndexAlreadyExists
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
@Test(expectedExceptions = IndexAlreadyExistsException.class)
public void testCreateIndexAlreadyExists()
{
Index index = Index.create("indexname");
IndexSettings indexSettings = IndexSettings.create(1, 1);
FieldMapping idField = FieldMapping.create("id", MappingType.TEXT, true, emptyList());
Mapping mapping = Mapping.create("type", ImmutableList.of(idField));
Stream<Mapping> mappings = Stream.of(mapping);
when(indicesAdminClient.prepareCreate(any())).thenReturn(createIndexRequestBuilder);
when(createIndexRequestBuilder.setSettings(any(Settings.class))).thenReturn(createIndexRequestBuilder);
when(createIndexRequestBuilder.addMapping(any(), any(XContentBuilder.class))).thenReturn(
createIndexRequestBuilder);
when(createIndexRequestBuilder.get()).thenThrow(new ResourceAlreadyExistsException("Index already exists"));
clientFacade.createIndex(index, indexSettings, mappings);
}
开发者ID:molgenis,项目名称:molgenis,代码行数:19,代码来源:ClientFacadeTest.java
示例5: doExecute
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
@Override
protected void doExecute(final UpdateRequest request, final ActionListener<UpdateResponse> listener) {
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
createIndexAction.execute(new CreateIndexRequest().index(request.index()).cause("auto(update api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
innerExecute(request, listener);
}
@Override
public void onFailure(Exception e) {
if (unwrapCause(e) instanceof ResourceAlreadyExistsException) {
// we have the index, do it
try {
innerExecute(request, listener);
} catch (Exception inner) {
inner.addSuppressed(e);
listener.onFailure(inner);
}
} else {
listener.onFailure(e);
}
}
});
} else {
innerExecute(request, listener);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:TransportUpdateAction.java
示例6: testRolloverOnExistingIndex
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
public void testRolloverOnExistingIndex() throws Exception {
assertAcked(prepareCreate("test_index-0").addAlias(new Alias("test_alias")).get());
index("test_index-0", "type1", "1", "field", "value");
assertAcked(prepareCreate("test_index-000001").get());
index("test_index-000001", "type1", "1", "field", "value");
flush("test_index-0", "test_index-000001");
try {
client().admin().indices().prepareRolloverIndex("test_alias").get();
fail("expected failure due to existing rollover index");
} catch (ResourceAlreadyExistsException e) {
assertThat(e.getIndex().getName(), equalTo("test_index-000001"));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:RolloverIT.java
示例7: create
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
/**
* Create a new index with an initial mapping.
*
* @param indexName the name of the index to create
* @param type the mapping type
* @param mapping the mapping source
*
* @return true if the index was successfully created, false otherwise
*/
public static boolean create(String indexName, String type, String mapping) {
synchronized (Indices.class) {
if (exists(indexName)) {
return true;
}
CreateIndexRequestBuilder builder = self.client.getClient().admin().indices().prepareCreate(indexName);
builder.setSettings(Settings.builder()
.put("number_of_shards", self.properties.getShardsPerIndex())
.put("number_of_replicas", self.properties.getReplicasPerShard())
.build());
if (mapping != null) {
builder.addMapping(type, mapping, XContentType.JSON);
}
log.debug("Creating new index with name {}", indexName);
boolean created;
try {
CreateIndexResponse response = builder.get();
created = response.isAcknowledged();
} catch (ResourceAlreadyExistsException ex) {
created = true;
}
self.client.waitForYellowStatus();
if (created) {
self.indexCache.add(indexName);
}
return created;
}
}
开发者ID:c2mon,项目名称:c2mon,代码行数:45,代码来源:Indices.java
示例8: createIndex
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
/**
* Creates a new {@link IndexService} for the given metadata.
* @param indexMetaData the index metadata to create the index for
* @param builtInListeners a list of built-in lifecycle {@link IndexEventListener} that should should be used along side with the per-index listeners
* @throws ResourceAlreadyExistsException if the index already exists.
*/
@Override
public synchronized IndexService createIndex(IndexMetaData indexMetaData, List<IndexEventListener> builtInListeners, Consumer<ShardId> globalCheckpointSyncer) throws IOException {
ensureChangesAllowed();
if (indexMetaData.getIndexUUID().equals(IndexMetaData.INDEX_UUID_NA_VALUE)) {
throw new IllegalArgumentException("index must have a real UUID found value: [" + indexMetaData.getIndexUUID() + "]");
}
final Index index = indexMetaData.getIndex();
if (hasIndex(index)) {
throw new ResourceAlreadyExistsException(index);
}
List<IndexEventListener> finalListeners = new ArrayList<>(builtInListeners);
final IndexEventListener onStoreClose = new IndexEventListener() {
@Override
public void onStoreClosed(ShardId shardId) {
indicesQueryCache.onClose(shardId);
}
};
finalListeners.add(onStoreClose);
finalListeners.add(oldShardsStats);
final IndexService indexService =
createIndexService(
"create index",
indexMetaData,
indicesQueryCache,
indicesFieldDataCache,
finalListeners,
globalCheckpointSyncer,
indexingMemoryController);
boolean success = false;
try {
indexService.getIndexEventListener().afterIndexCreated(indexService);
indices = newMapBuilder(indices).put(index.getUUID(), indexService).immutableMap();
success = true;
return indexService;
} finally {
if (success == false) {
indexService.close("plugins_failed", true);
}
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:IndicesService.java
示例9: testValidateShrinkIndex
import org.elasticsearch.ResourceAlreadyExistsException; //导入依赖的package包/类
public void testValidateShrinkIndex() {
int numShards = randomIntBetween(2, 42);
ClusterState state = createClusterState("source", numShards, randomIntBetween(0, 10),
Settings.builder().put("index.blocks.write", true).build());
assertEquals("index [source] already exists",
expectThrows(ResourceAlreadyExistsException.class, () ->
MetaDataCreateIndexService.validateShrinkIndex(state, "target", Collections.emptySet(), "source", Settings.EMPTY)
).getMessage());
assertEquals("no such index",
expectThrows(IndexNotFoundException.class, () ->
MetaDataCreateIndexService.validateShrinkIndex(state, "no such index", Collections.emptySet(), "target", Settings.EMPTY)
).getMessage());
assertEquals("can't shrink an index with only one shard",
expectThrows(IllegalArgumentException.class, () -> MetaDataCreateIndexService.validateShrinkIndex(createClusterState("source",
1, 0, Settings.builder().put("index.blocks.write", true).build()), "source", Collections.emptySet(),
"target", Settings.EMPTY)
).getMessage());
assertEquals("the number of target shards must be less that the number of source shards",
expectThrows(IllegalArgumentException.class, () -> MetaDataCreateIndexService.validateShrinkIndex(createClusterState("source",
5, 0, Settings.builder().put("index.blocks.write", true).build()), "source", Collections.emptySet(),
"target", Settings.builder().put("index.number_of_shards", 10).build())
).getMessage());
assertEquals("index source must be read-only to shrink index. use \"index.blocks.write=true\"",
expectThrows(IllegalStateException.class, () ->
MetaDataCreateIndexService.validateShrinkIndex(
createClusterState("source", randomIntBetween(2, 100), randomIntBetween(0, 10), Settings.EMPTY)
, "source", Collections.emptySet(), "target", Settings.EMPTY)
).getMessage());
assertEquals("index source must have all shards allocated on the same node to shrink index",
expectThrows(IllegalStateException.class, () ->
MetaDataCreateIndexService.validateShrinkIndex(state, "source", Collections.emptySet(), "target", Settings.EMPTY)
).getMessage());
assertEquals("the number of source shards [8] must be a must be a multiple of [3]",
expectThrows(IllegalArgumentException.class, () ->
MetaDataCreateIndexService.validateShrinkIndex(createClusterState("source", 8, randomIntBetween(0, 10),
Settings.builder().put("index.blocks.write", true).build()), "source", Collections.emptySet(), "target",
Settings.builder().put("index.number_of_shards", 3).build())
).getMessage());
assertEquals("mappings are not allowed when shrinking indices, all mappings are copied from the source index",
expectThrows(IllegalArgumentException.class, () -> {
MetaDataCreateIndexService.validateShrinkIndex(state, "source", Collections.singleton("foo"),
"target", Settings.EMPTY);
}
).getMessage());
// create one that won't fail
ClusterState clusterState = ClusterState.builder(createClusterState("source", numShards, 0,
Settings.builder().put("index.blocks.write", true).build())).nodes(DiscoveryNodes.builder().add(newNode("node1")))
.build();
AllocationService service = new AllocationService(Settings.builder().build(), new AllocationDeciders(Settings.EMPTY,
Collections.singleton(new MaxRetryAllocationDecider(Settings.EMPTY))),
new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
RoutingTable routingTable = service.reroute(clusterState, "reroute").routingTable();
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
// now we start the shard
routingTable = service.applyStartedShards(clusterState,
routingTable.index("source").shardsWithState(ShardRoutingState.INITIALIZING)).routingTable();
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
int targetShards;
do {
targetShards = randomIntBetween(1, numShards/2);
} while (isShrinkable(numShards, targetShards) == false);
MetaDataCreateIndexService.validateShrinkIndex(clusterState, "source", Collections.emptySet(), "target",
Settings.builder().put("index.number_of_shards", targetShards).build());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:76,代码来源:MetaDataCreateIndexServiceTests.java
注:本文中的org.elasticsearch.ResourceAlreadyExistsException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论