use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project crate by crate.
the class TableCreator method deleteOrphans.
private void deleteOrphans(final CreateTableResponseListener listener, final CreateTableAnalyzedStatement statement) {
if (clusterService.state().metaData().hasAlias(statement.tableIdent().fqn()) && PartitionName.isPartition(clusterService.state().metaData().getAliasAndIndexLookup().get(statement.tableIdent().fqn()).getIndices().iterator().next().getIndex())) {
logger.debug("Deleting orphaned partitions with alias: {}", statement.tableIdent().fqn());
transportActionProvider.transportDeleteIndexAction().execute(new DeleteIndexRequest(statement.tableIdent().fqn()), new ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse response) {
if (!response.isAcknowledged()) {
warnNotAcknowledged("deleting orphaned alias");
}
deleteOrphanedPartitions(listener, statement.tableIdent());
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
});
} else {
deleteOrphanedPartitions(listener, statement.tableIdent());
}
}
use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project elasticsearch by elastic.
the class IndexLifecycleActionIT method testIndexLifecycleActionsWith11Shards1Backup.
public void testIndexLifecycleActionsWith11Shards1Backup() throws Exception {
Settings settings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, 11).put(SETTING_NUMBER_OF_REPLICAS, 1).build();
// start one server
logger.info("Starting sever1");
final String server_1 = internalCluster().startNode();
final String node1 = getLocalNodeId(server_1);
logger.info("Creating index [test]");
CreateIndexResponse createIndexResponse = client().admin().indices().create(createIndexRequest("test").settings(settings)).actionGet();
assertAcked(createIndexResponse);
ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
RoutingNode routingNodeEntry1 = clusterState.getRoutingNodes().node(node1);
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));
logger.info("Starting server2");
// start another server
String server_2 = internalCluster().startNode();
// first wait for 2 nodes in the cluster
logger.info("Waiting for replicas to be assigned");
ClusterHealthResponse clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
logger.info("Done Cluster Health, status {}", clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
final String node2 = getLocalNodeId(server_2);
// explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join)
client().admin().cluster().prepareReroute().execute().actionGet();
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2").waitForNoRelocatingShards(true)).actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
assertThat(clusterHealth.getNumberOfDataNodes(), equalTo(2));
assertThat(clusterHealth.getInitializingShards(), equalTo(0));
assertThat(clusterHealth.getUnassignedShards(), equalTo(0));
assertThat(clusterHealth.getRelocatingShards(), equalTo(0));
assertThat(clusterHealth.getActiveShards(), equalTo(22));
assertThat(clusterHealth.getActivePrimaryShards(), equalTo(11));
clusterState = client().admin().cluster().prepareState().get().getState();
assertNodesPresent(clusterState.getRoutingNodes(), node1, node2);
routingNodeEntry1 = clusterState.getRoutingNodes().node(node1);
assertThat(routingNodeEntry1.numberOfShardsWithState(RELOCATING), equalTo(0));
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), equalTo(11));
RoutingNode routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
assertThat(routingNodeEntry2.numberOfShardsWithState(INITIALIZING), equalTo(0));
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), equalTo(11));
logger.info("Starting server3");
// start another server
String server_3 = internalCluster().startNode();
// first wait for 3 nodes in the cluster
logger.info("Waiting for replicas to be assigned");
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("3")).actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
final String node3 = getLocalNodeId(server_3);
// explicitly call reroute, so shards will get relocated to the new node (we delay it in ES in case other nodes join)
client().admin().cluster().prepareReroute().execute().actionGet();
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("3").waitForNoRelocatingShards(true)).actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
assertThat(clusterHealth.getNumberOfDataNodes(), equalTo(3));
assertThat(clusterHealth.getInitializingShards(), equalTo(0));
assertThat(clusterHealth.getUnassignedShards(), equalTo(0));
assertThat(clusterHealth.getRelocatingShards(), equalTo(0));
assertThat(clusterHealth.getActiveShards(), equalTo(22));
assertThat(clusterHealth.getActivePrimaryShards(), equalTo(11));
clusterState = client().admin().cluster().prepareState().get().getState();
assertNodesPresent(clusterState.getRoutingNodes(), node1, node2, node3);
routingNodeEntry1 = clusterState.getRoutingNodes().node(node1);
routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
RoutingNode routingNodeEntry3 = clusterState.getRoutingNodes().node(node3);
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED) + routingNodeEntry2.numberOfShardsWithState(STARTED) + routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(22));
assertThat(routingNodeEntry1.numberOfShardsWithState(RELOCATING), equalTo(0));
assertThat(routingNodeEntry1.numberOfShardsWithState(STARTED), anyOf(equalTo(7), equalTo(8)));
assertThat(routingNodeEntry2.numberOfShardsWithState(RELOCATING), equalTo(0));
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), anyOf(equalTo(7), equalTo(8)));
assertThat(routingNodeEntry3.numberOfShardsWithState(INITIALIZING), equalTo(0));
assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(7));
logger.info("Closing server1");
// kill the first server
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(server_1));
// verify health
logger.info("Running Cluster Health");
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNodes("2")).actionGet();
logger.info("Done Cluster Health, status {}", clusterHealth.getStatus());
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
client().admin().cluster().prepareReroute().get();
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus().waitForNoRelocatingShards(true).waitForNodes("2")).actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
assertThat(clusterHealth.getRelocatingShards(), equalTo(0));
assertThat(clusterHealth.getActiveShards(), equalTo(22));
assertThat(clusterHealth.getActivePrimaryShards(), equalTo(11));
clusterState = client().admin().cluster().prepareState().get().getState();
assertNodesPresent(clusterState.getRoutingNodes(), node3, node2);
routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
routingNodeEntry3 = clusterState.getRoutingNodes().node(node3);
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED) + routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(22));
assertThat(routingNodeEntry2.numberOfShardsWithState(RELOCATING), equalTo(0));
assertThat(routingNodeEntry2.numberOfShardsWithState(STARTED), equalTo(11));
assertThat(routingNodeEntry3.numberOfShardsWithState(RELOCATING), equalTo(0));
assertThat(routingNodeEntry3.numberOfShardsWithState(STARTED), equalTo(11));
logger.info("Deleting index [test]");
// last, lets delete the index
DeleteIndexResponse deleteIndexResponse = client().admin().indices().prepareDelete("test").execute().actionGet();
assertThat(deleteIndexResponse.isAcknowledged(), equalTo(true));
clusterState = client().admin().cluster().prepareState().get().getState();
assertNodesPresent(clusterState.getRoutingNodes(), node3, node2);
routingNodeEntry2 = clusterState.getRoutingNodes().node(node2);
assertThat(routingNodeEntry2.isEmpty(), equalTo(true));
routingNodeEntry3 = clusterState.getRoutingNodes().node(node3);
assertThat(routingNodeEntry3.isEmpty(), equalTo(true));
}
use of org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse in project graylog2-server by Graylog2.
the class CountsTest method tearDown.
@After
public void tearDown() throws Exception {
final DeleteIndexResponse deleteIndexResponse1 = client.admin().indices().prepareDelete(INDEX_NAME_1).setTimeout(TimeValue.timeValueSeconds(10L)).execute().get();
assumeTrue(deleteIndexResponse1.isAcknowledged());
final DeleteIndexResponse deleteIndexResponse2 = client.admin().indices().prepareDelete(INDEX_NAME_2).setTimeout(TimeValue.timeValueSeconds(10L)).execute().get();
assumeTrue(deleteIndexResponse2.isAcknowledged());
}
Aggregations