本文整理汇总了Java中org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse类的典型用法代码示例。如果您正苦于以下问题:Java GetSnapshotsResponse类的具体用法?Java GetSnapshotsResponse怎么用?Java GetSnapshotsResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetSnapshotsResponse类属于org.elasticsearch.action.admin.cluster.snapshots.get包,在下文中一共展示了GetSnapshotsResponse类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: doCatRequest
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest()
.repository(request.param("repository"))
.snapshots(new String[]{GetSnapshotsRequest.ALL_SNAPSHOTS});
getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
return channel ->
client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {
@Override
public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
}
});
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:RestSnapshotAction.java
示例2: doRequest
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
@Override
protected void doRequest(final RestRequest request, RestChannel channel, Client client) {
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest()
.repository(request.param("repository"))
.snapshots(new String[]{GetSnapshotsRequest.ALL_SNAPSHOTS});
getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {
@Override
public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
}
});
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:18,代码来源:RestSnapshotAction.java
示例3: blockForSnapshot
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
/**
* Block for index snapshots to be complete
*
* @param snapshotRepoName
* @param indicies
* @param timeoutMS
*/
private void blockForSnapshot(String snapshotRepoName, List<String> indicies, long timeoutMS) {
long start = System.currentTimeMillis();
while(System.currentTimeMillis() - start < timeoutMS) {
GetSnapshotsResponse repos = node.client().admin().cluster().getSnapshots(new GetSnapshotsRequest(snapshotRepoName)).actionGet();
for(SnapshotInfo i : repos.getSnapshots()) {
if(i.state().completed() && i.successfulShards() == i.totalShards() && i.totalShards() >= indicies.size()) {
logger.info("Snapshot completed {} out of {} indicies. Snapshot state {}. ", i.successfulShards(), i.totalShards(), i.state().completed());
return;
} else {
logger.info("Snapshotted {} out of {} indicies, polling for completion. Snapshot state {}.", i.successfulShards(), i.totalShards(), i.state().completed());
}
}
try {
// Don't slam ES with snapshot status requests in a tight loop
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
开发者ID:MyPureCloud,项目名称:elasticsearch-lambda,代码行数:29,代码来源:ESEmbededContainer.java
示例4: buildTable
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
private Table buildTable(RestRequest req, GetSnapshotsResponse getSnapshotsResponse) {
Table table = getTableWithHeader(req);
for (SnapshotInfo snapshotStatus : getSnapshotsResponse.getSnapshots()) {
table.startRow();
table.addCell(snapshotStatus.snapshotId().getName());
table.addCell(snapshotStatus.state());
table.addCell(TimeUnit.SECONDS.convert(snapshotStatus.startTime(), TimeUnit.MILLISECONDS));
table.addCell(dateFormat.print(snapshotStatus.startTime()));
table.addCell(TimeUnit.SECONDS.convert(snapshotStatus.endTime(), TimeUnit.MILLISECONDS));
table.addCell(dateFormat.print(snapshotStatus.endTime()));
final long durationMillis;
if (snapshotStatus.state() == SnapshotState.IN_PROGRESS) {
durationMillis = System.currentTimeMillis() - snapshotStatus.startTime();
} else {
durationMillis = snapshotStatus.endTime() - snapshotStatus.startTime();
}
table.addCell(TimeValue.timeValueMillis(durationMillis));
table.addCell(snapshotStatus.indices().size());
table.addCell(snapshotStatus.successfulShards());
table.addCell(snapshotStatus.failedShards());
table.addCell(snapshotStatus.totalShards());
table.addCell(snapshotStatus.reason());
table.endRow();
}
return table;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:RestSnapshotAction.java
示例5: testGetSnapshotWithBlocks
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
public void testGetSnapshotWithBlocks() {
// This test checks that the Get Snapshot operation is never blocked, even if the cluster is read only.
try {
setClusterReadOnly(true);
GetSnapshotsResponse response = client().admin().cluster().prepareGetSnapshots(REPOSITORY_NAME).execute().actionGet();
assertThat(response.getSnapshots(), hasSize(1));
assertThat(response.getSnapshots().get(0).snapshotId().getName(), equalTo(SNAPSHOT_NAME));
} finally {
setClusterReadOnly(false);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:SnapshotBlocksIT.java
示例6: handleRequest
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
String repository = request.param("repository");
String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(snapshots);
getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestToXContentListener<GetSnapshotsResponse>(channel));
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:RestGetSnapshotsAction.java
示例7: buildTable
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
private Table buildTable(RestRequest req, GetSnapshotsResponse getSnapshotsResponse) {
Table table = getTableWithHeader(req);
for (SnapshotInfo snapshotStatus : getSnapshotsResponse.getSnapshots()) {
table.startRow();
table.addCell(snapshotStatus.name());
table.addCell(snapshotStatus.state());
table.addCell(TimeUnit.SECONDS.convert(snapshotStatus.startTime(), TimeUnit.MILLISECONDS));
table.addCell(dateFormat.print(snapshotStatus.startTime()));
table.addCell(TimeUnit.SECONDS.convert(snapshotStatus.endTime(), TimeUnit.MILLISECONDS));
table.addCell(dateFormat.print(snapshotStatus.endTime()));
final long durationMillis;
if (snapshotStatus.state() == SnapshotState.IN_PROGRESS) {
durationMillis = System.currentTimeMillis() - snapshotStatus.startTime();
} else {
durationMillis = snapshotStatus.endTime() - snapshotStatus.startTime();
}
table.addCell(TimeValue.timeValueMillis(durationMillis));
table.addCell(snapshotStatus.indices().size());
table.addCell(snapshotStatus.successfulShards());
table.addCell(snapshotStatus.failedShards());
table.addCell(snapshotStatus.totalShards());
table.addCell(snapshotStatus.reason());
table.endRow();
}
return table;
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:RestSnapshotAction.java
示例8: getAvailableSnapshots
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
public static List<String> getAvailableSnapshots(Client transportClient, String repositoryName) {
logger.info("Searching for available snapshots");
List<String> snapshots = new ArrayList<>();
GetSnapshotsResponse getSnapshotsResponse = transportClient.admin().cluster()
.prepareGetSnapshots(repositoryName)
.get();
for (SnapshotInfo snapshotInfo : getSnapshotsResponse.getSnapshots()) {
snapshots.add(snapshotInfo.snapshotId().getName());
}
return snapshots;
}
开发者ID:Netflix,项目名称:Raigad,代码行数:15,代码来源:ElasticsearchUtils.java
示例9: testUrlRepository
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
public void testUrlRepository() throws Exception {
Client client = client();
logger.info("--> creating repository");
Path repositoryLocation = randomRepoPath();
assertAcked(client.admin().cluster().preparePutRepository("test-repo")
.setType(FsRepository.TYPE).setSettings(Settings.builder()
.put(FsRepository.LOCATION_SETTING.getKey(), repositoryLocation)
.put(FsRepository.COMPRESS_SETTING.getKey(), randomBoolean())
.put(FsRepository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
createIndex("test-idx");
ensureGreen();
logger.info("--> indexing some data");
for (int i = 0; i < 100; i++) {
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
}
refresh();
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
logger.info("--> snapshot");
CreateSnapshotResponse createSnapshotResponse = client
.admin()
.cluster()
.prepareCreateSnapshot("test-repo", "test-snap")
.setWaitForCompletion(true)
.setIndices("test-idx")
.get();
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
int actualTotalShards = createSnapshotResponse.getSnapshotInfo().totalShards();
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(actualTotalShards));
SnapshotState state = client
.admin()
.cluster()
.prepareGetSnapshots("test-repo")
.setSnapshots("test-snap")
.get()
.getSnapshots()
.get(0)
.state();
assertThat(state, equalTo(SnapshotState.SUCCESS));
logger.info("--> delete index");
cluster().wipeIndices("test-idx");
logger.info("--> create read-only URL repository");
assertAcked(client.admin().cluster().preparePutRepository("url-repo")
.setType(URLRepository.TYPE).setSettings(Settings.builder()
.put(URLRepository.URL_SETTING.getKey(), repositoryLocation.toUri().toURL())
.put("list_directories", randomBoolean())));
logger.info("--> restore index after deletion");
RestoreSnapshotResponse restoreSnapshotResponse = client
.admin()
.cluster()
.prepareRestoreSnapshot("url-repo", "test-snap")
.setWaitForCompletion(true)
.setIndices("test-idx")
.execute()
.actionGet();
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
logger.info("--> list available shapshots");
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
logger.info("--> delete snapshot");
DeleteSnapshotResponse deleteSnapshotResponse = client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap").get();
assertAcked(deleteSnapshotResponse);
logger.info("--> list available shapshot again, no snapshots should be returned");
getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(0));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:80,代码来源:URLSnapshotRestoreTests.java
示例10: getSnapshots
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
@Override
public ActionFuture<GetSnapshotsResponse> getSnapshots(GetSnapshotsRequest request) {
return execute(GetSnapshotsAction.INSTANCE, request);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AbstractClient.java
示例11: testOldSnapshot
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
private void testOldSnapshot(String version, String repo, String snapshot) throws IOException {
logger.info("--> get snapshot and check its version");
GetSnapshotsResponse getSnapshotsResponse = client().admin().cluster().prepareGetSnapshots(repo).setSnapshots(snapshot).get();
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
SnapshotInfo snapshotInfo = getSnapshotsResponse.getSnapshots().get(0);
assertThat(snapshotInfo.version().toString(), equalTo(version));
logger.info("--> restoring snapshot");
RestoreSnapshotResponse response = client().admin().cluster().prepareRestoreSnapshot(repo, snapshot).setRestoreGlobalState(true).setWaitForCompletion(true).get();
assertThat(response.status(), equalTo(RestStatus.OK));
RestoreInfo restoreInfo = response.getRestoreInfo();
assertThat(restoreInfo.successfulShards(), greaterThan(0));
assertThat(restoreInfo.successfulShards(), equalTo(restoreInfo.totalShards()));
assertThat(restoreInfo.failedShards(), equalTo(0));
String index = restoreInfo.indices().get(0);
logger.info("--> check search");
SearchResponse searchResponse = client().prepareSearch(index).get();
assertThat(searchResponse.getHits().getTotalHits(), greaterThan(1L));
logger.info("--> check settings");
ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
assertThat(clusterState.metaData().persistentSettings().get(FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + "version_attr"), equalTo(version));
logger.info("--> check templates");
IndexTemplateMetaData template = clusterState.getMetaData().templates().get("template_" + version.toLowerCase(Locale.ROOT));
assertThat(template, notNullValue());
assertThat(template.patterns(), equalTo(Collections.singletonList("te*")));
assertThat(template.settings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), equalTo(1));
assertThat(template.mappings().size(), equalTo(1));
assertThat(template.mappings().get("type1").string(),
anyOf(
equalTo("{\"type1\":{\"_source\":{\"enabled\":false}}}"),
equalTo("{\"type1\":{\"_source\":{\"enabled\":\"false\"}}}"),
equalTo("{\"type1\":{\"_source\":{\"enabled\":\"0\"}}}"),
equalTo("{\"type1\":{\"_source\":{\"enabled\":0}}}"),
equalTo("{\"type1\":{\"_source\":{\"enabled\":\"off\"}}}"),
equalTo("{\"type1\":{\"_source\":{\"enabled\":\"no\"}}}")
));
assertThat(template.aliases().size(), equalTo(3));
assertThat(template.aliases().get("alias1"), notNullValue());
assertThat(template.aliases().get("alias2").filter().string(), containsString(version));
assertThat(template.aliases().get("alias2").indexRouting(), equalTo("kimchy"));
assertThat(template.aliases().get("{index}-alias"), notNullValue());
logger.info("--> cleanup");
cluster().wipeIndices(restoreInfo.indices().toArray(new String[restoreInfo.indices().size()]));
cluster().wipeTemplates();
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:51,代码来源:RestoreBackwardsCompatIT.java
示例12: testSnapshotFileFailureDuringSnapshot
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
public void testSnapshotFileFailureDuringSnapshot() throws Exception {
Client client = client();
logger.info("--> creating repository");
assertAcked(client.admin().cluster().preparePutRepository("test-repo")
.setType("mock").setSettings(
Settings.builder()
.put("location", randomRepoPath())
.put("random", randomAsciiOfLength(10))
.put("random_control_io_exception_rate", 0.2))
.setVerify(false));
createIndex("test-idx");
ensureGreen();
logger.info("--> indexing some data");
for (int i = 0; i < 100; i++) {
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
}
refresh();
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
logger.info("--> snapshot");
try {
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
if (createSnapshotResponse.getSnapshotInfo().totalShards() == createSnapshotResponse.getSnapshotInfo().successfulShards()) {
// If we are here, that means we didn't have any failures, let's check it
assertThat(getFailureCount("test-repo"), equalTo(0L));
} else {
assertThat(getFailureCount("test-repo"), greaterThan(0L));
assertThat(createSnapshotResponse.getSnapshotInfo().shardFailures().size(), greaterThan(0));
for (SnapshotShardFailure shardFailure : createSnapshotResponse.getSnapshotInfo().shardFailures()) {
assertThat(shardFailure.reason(), containsString("Random IOException"));
assertThat(shardFailure.nodeId(), notNullValue());
assertThat(shardFailure.index(), equalTo("test-idx"));
}
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap").get();
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
SnapshotInfo snapshotInfo = getSnapshotsResponse.getSnapshots().get(0);
if (snapshotInfo.state() == SnapshotState.SUCCESS) {
assertThat(snapshotInfo.shardFailures().size(), greaterThan(0));
assertThat(snapshotInfo.totalShards(), greaterThan(snapshotInfo.successfulShards()));
}
}
} catch (Exception ex) {
logger.info("--> caught a top level exception, asserting what's expected", ex);
assertThat(getFailureCount("test-repo"), greaterThan(0L));
assertThat(ExceptionsHelper.detailedMessage(ex), containsString("IOException"));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:51,代码来源:SharedClusterSnapshotRestoreIT.java
示例13: testDataFileFailureDuringSnapshot
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
public void testDataFileFailureDuringSnapshot() throws Exception {
Client client = client();
logger.info("--> creating repository");
assertAcked(client.admin().cluster().preparePutRepository("test-repo")
.setType("mock").setSettings(
Settings.builder()
.put("location", randomRepoPath())
.put("random", randomAsciiOfLength(10))
.put("random_data_file_io_exception_rate", 0.3)));
createIndex("test-idx");
ensureGreen();
logger.info("--> indexing some data");
for (int i = 0; i < 100; i++) {
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
}
refresh();
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
logger.info("--> snapshot");
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
if (createSnapshotResponse.getSnapshotInfo().totalShards() == createSnapshotResponse.getSnapshotInfo().successfulShards()) {
logger.info("--> no failures");
// If we are here, that means we didn't have any failures, let's check it
assertThat(getFailureCount("test-repo"), equalTo(0L));
} else {
logger.info("--> some failures");
assertThat(getFailureCount("test-repo"), greaterThan(0L));
assertThat(createSnapshotResponse.getSnapshotInfo().shardFailures().size(), greaterThan(0));
for (SnapshotShardFailure shardFailure : createSnapshotResponse.getSnapshotInfo().shardFailures()) {
assertThat(shardFailure.nodeId(), notNullValue());
assertThat(shardFailure.index(), equalTo("test-idx"));
}
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap").get();
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
SnapshotInfo snapshotInfo = getSnapshotsResponse.getSnapshots().get(0);
assertThat(snapshotInfo.state(), equalTo(SnapshotState.PARTIAL));
assertThat(snapshotInfo.shardFailures().size(), greaterThan(0));
assertThat(snapshotInfo.totalShards(), greaterThan(snapshotInfo.successfulShards()));
// Verify that snapshot status also contains the same failures
SnapshotsStatusResponse snapshotsStatusResponse = client.admin().cluster().prepareSnapshotStatus("test-repo").addSnapshots("test-snap").get();
assertThat(snapshotsStatusResponse.getSnapshots().size(), equalTo(1));
SnapshotStatus snapshotStatus = snapshotsStatusResponse.getSnapshots().get(0);
assertThat(snapshotStatus.getIndices().size(), equalTo(1));
SnapshotIndexStatus indexStatus = snapshotStatus.getIndices().get("test-idx");
assertThat(indexStatus, notNullValue());
assertThat(indexStatus.getShardsStats().getFailedShards(), equalTo(snapshotInfo.failedShards()));
assertThat(indexStatus.getShardsStats().getDoneShards(), equalTo(snapshotInfo.successfulShards()));
assertThat(indexStatus.getShards().size(), equalTo(snapshotInfo.totalShards()));
int numberOfFailures = 0;
for (SnapshotIndexShardStatus shardStatus : indexStatus.getShards().values()) {
if (shardStatus.getStage() == SnapshotIndexShardStage.FAILURE) {
assertThat(shardStatus.getFailure(), notNullValue());
numberOfFailures++;
} else {
assertThat(shardStatus.getFailure(), nullValue());
}
}
assertThat(indexStatus.getShardsStats().getFailedShards(), equalTo(numberOfFailures));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:65,代码来源:SharedClusterSnapshotRestoreIT.java
示例14: testReadonlyRepository
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
@TestLogging("_root:DEBUG") // this fails every now and then: https://github.com/elastic/elasticsearch/issues/18121 but without
// more logs we cannot find out why
public void testReadonlyRepository() throws Exception {
Client client = client();
logger.info("--> creating repository");
Path repositoryLocation = randomRepoPath();
assertAcked(client.admin().cluster().preparePutRepository("test-repo")
.setType("fs").setSettings(Settings.builder()
.put("location", repositoryLocation)
.put("compress", randomBoolean())
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
createIndex("test-idx");
ensureGreen();
logger.info("--> indexing some data");
for (int i = 0; i < 100; i++) {
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
}
refresh();
logger.info("--> snapshot");
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
logger.info("--> delete index");
cluster().wipeIndices("test-idx");
logger.info("--> create read-only URL repository");
assertAcked(client.admin().cluster().preparePutRepository("readonly-repo")
.setType("fs").setSettings(Settings.builder()
.put("location", repositoryLocation)
.put("compress", randomBoolean())
.put("readonly", true)
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
logger.info("--> restore index after deletion");
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("readonly-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").execute().actionGet();
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
logger.info("--> list available shapshots");
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("readonly-repo").get();
assertThat(getSnapshotsResponse.getSnapshots(), notNullValue());
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
logger.info("--> try deleting snapshot");
assertThrows(client.admin().cluster().prepareDeleteSnapshot("readonly-repo", "test-snap"), RepositoryException.class, "cannot delete snapshot from a readonly repository");
logger.info("--> try making another snapshot");
assertThrows(client.admin().cluster().prepareCreateSnapshot("readonly-repo", "test-snap-2").setWaitForCompletion(true).setIndices("test-idx"), RepositoryException.class, "cannot create snapshot in a readonly repository");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:56,代码来源:SharedClusterSnapshotRestoreIT.java
示例15: purgeOldSnapshots
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
private void purgeOldSnapshots() {
logger.info("Purging expired snapshot(s) for index(es): {} ", this.snapshotSettings.getIndices());
// get old snapshots to remove
GetSnapshotsRequestBuilder getBuilder = new GetSnapshotsRequestBuilder(this.client.admin().cluster(), this.snapshotSettings.getRepository());
GetSnapshotsResponse getResp = getBuilder.get();
Set<String> configIndices = getConfiguredIndicesAsSet();
if (getResp != null && getResp.getSnapshots() != null) {
ImmutableList<SnapshotInfo> snapshots = getResp.getSnapshots();
if (snapshots == null || snapshots.isEmpty()) {
return;
}
logger.debug("Found a total of {} snapshots in the repository", snapshots.size());
List<String> purgeSnapshots = new ArrayList<String>();
for (Iterator<SnapshotInfo> i = snapshots.iterator(); i.hasNext();) {
SnapshotInfo snap = i.next();
logger.debug("This snapshot [{}] includes the following indices: {}", snap.name(), StringUtils.toString(snap.indices()));
if(this.snapshotSettings.isPurgeIndicesMustMatch()){
// if number of indices don't match, do not purge
if (snap.indices().size() != configIndices.size()) {
logger.info("Snapshot [{}] not purged. The number of indices in the snapshot ({}) must match the number of indices in the current configuration ({}). To purge all snapshots, configure purge_indices_must_match:false.", snap.name(), snap.indices().size(), configIndices.size());
continue;
}
// if the size matches, verify that the indexes within the snapshot are exactly the same as those
// configured for the river
if (!snapshotIndicesMatch(snap, configIndices)) {
logger.info("Snapshot [{}] not purged. In order to purge a snapshot automatically, the specific indexes must match exactly. The snapshot does not match current purge configuration indices. To purge all snapshots, configure purge_indices_must_match:false.", snap.name());
continue;
}
}
// finally check if the snapshot is beyond the purgeAfter age
Date expiration = new Date(snap.startTime() + this.snapshotSettings.getPurgeAfter().millis());
if (expiration.before(new Date())) {
purgeSnapshots.add(snap.name());
}
}
// remove old snapshots
logger.debug("{} snapshots are scheduled to be purged.", purgeSnapshots.size());
for (String snapshotName : purgeSnapshots) {
DeleteSnapshotRequestBuilder deleteBuilder = new DeleteSnapshotRequestBuilder(this.client.admin().cluster());
deleteBuilder.setRepository(this.snapshotSettings.getRepository());
deleteBuilder.setSnapshot(snapshotName);
DeleteSnapshotResponse deleteResp = deleteBuilder.get();
if (deleteResp.isAcknowledged()) {
logger.info("Expired snapshot [{}] has been deleted.", snapshotName);
} else {
logger.error("Not able to delete expired snapshot [{}]", snapshotName);
}
}
}
}
开发者ID:garmin,项目名称:elasticsearch-river-snapshot,代码行数:57,代码来源:SnapshotsExecutor.java
示例16: restoreDictionarySnapshot
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
public void restoreDictionarySnapshot(final String repository,
final String snapshot, final String[] indices,
final ActionListener<Void> listener) {
final String dictionarySnapshot = snapshot + dictionaryIndex + "_"
+ repository + "_" + snapshot;
client.admin().cluster().prepareGetSnapshots(repository)
.addSnapshots(dictionarySnapshot)
.execute(new ActionListener<GetSnapshotsResponse>() {
@Override
public void onResponse(final GetSnapshotsResponse response) {
final List<SnapshotInfo> snapshots = response
.getSnapshots();
if (!snapshots.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug(
"Restoring {} dictionaries in {} repository.",
repository, snapshot);
}
restoreDictionaryIndex(repository, snapshot,
dictionarySnapshot, indices, listener);
} else {
if (logger.isDebugEnabled()) {
logger.debug(
"{} snapshot in {} repository does not have dictionaries.",
repository, snapshot);
}
listener.onResponse(null);
}
}
@Override
public void onFailure(final Throwable e) {
if (e instanceof SnapshotMissingException) {
listener.onResponse(null);
} else {
listener.onFailure(new DictionaryException(
"Failed to find " + dictionarySnapshot
+ " snapshot.", e));
}
}
});
}
开发者ID:codelibs,项目名称:elasticsearch-dictionary,代码行数:44,代码来源:DictionaryRestoreService.java
示例17: getSnapshots
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
/**
* Get snapshot.
*/
ActionFuture<GetSnapshotsResponse> getSnapshots(GetSnapshotsRequest request);
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:ClusterAdminClient.java
示例18: test_snapshot_using_gridfs
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; //导入依赖的package包/类
@Test
public void test_snapshot_using_gridfs() {
MongoServer server = new MongoServer(new MemoryBackend());
InetSocketAddress serverAddress = server.bind();
int port = serverAddress.getPort();
String repositoryName = randomAsciiOfLengthBetween(10, 50).toLowerCase();
String indexName = randomAsciiOfLengthBetween(10, 50).toLowerCase();
String snapshotName = randomAsciiOfLengthBetween(10, 50).toLowerCase();
client().admin().cluster().preparePutRepository(repositoryName).setType("gridfs")
.setSettings(ImmutableSettings.builder()
.put("database", "test")
.put("bucket", "test")
.put("gridfs_host", "localhost")
.put("gridfs_port", port)
)
.get();
client().admin().indices().prepareCreate(indexName).get(); // create index
IndicesExistsResponse existsResponse1 = client().admin().indices().prepareExists(indexName).get();
assertThat(existsResponse1.isExists(), equalTo(true)); // check index exist
client().admin().cluster().prepareCreateSnapshot(repositoryName, snapshotName).setWaitForCompletion(true).get(); // create a snapshot
client().admin().indices().prepareDelete(indexName).get(); // delete index
IndicesExistsResponse existsResponse2 = client().admin().indices().prepareExists(indexName).get();
assertThat(existsResponse2.isExists(), equalTo(false)); // make sure index been deleted
GetSnapshotsResponse getSnapshotsResponse1 = client().admin().cluster().prepareGetSnapshots(repositoryName).addSnapshots(snapshotName).get();
assertThat(getSnapshotsResponse1.getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS)); // check index has been created successfully
client().admin().cluster().prepareRestoreSnapshot(repositoryName, snapshotName).setWaitForCompletion(true).get(); // restore the previous snapshot
IndicesExistsResponse existsResponse3 = client().admin().indices().prepareExists(indexName).get();
assertThat(existsResponse3.isExists(), equalTo(true)); // make sure index has been restored
client().admin().cluster().prepareDeleteSnapshot(repositoryName, snapshotName).get(); // delete snapshot
GetSnapshotsResponse getSnapshotsResponse2 = client().admin().cluster().prepareGetSnapshots(repositoryName).get();
assertThat(getSnapshotsResponse2.getSnapshots(), emptyIterable()); // make sure snapshot has been deleted
server.shutdownNow();
}
开发者ID:kzwang,项目名称:elasticsearch-repository-gridfs,代码行数:51,代码来源:GridFsRepositoryTest.java
注:本文中的org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论