org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse. 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: RestCreateSnapshotAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    CreateSnapshotRequest createSnapshotRequest = createSnapshotRequest(request.param("repository"), request.param("snapshot"));
    createSnapshotRequest.source(request.content().toUtf8());
    createSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createSnapshotRequest.masterNodeTimeout()));
    createSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
    client.admin().cluster().createSnapshot(createSnapshotRequest, new RestToXContentListener<CreateSnapshotResponse>(channel));
}
 
Example #2
Source File: SnapshotBackupManager.java    From Raigad with Apache License 2.0 5 votes vote down vote up
public void runSnapshotBackup() throws Exception {
    // Create or Get Repository
    String repositoryName = repository.createOrGetSnapshotRepository();

    // StartBackup
    String snapshotName = getSnapshotName(config.getCommaSeparatedIndicesToBackup(), config.includeIndexNameInSnapshot());
    logger.info("Repository Name : <" + repositoryName + "> Snapshot Name : <" + snapshotName + "> Indices : <" + config.getCommaSeparatedIndicesToBackup() + "> \nRunning Snapshot now ... ");

    Client esTransportClient = ElasticsearchTransportClient.instance(config).getTransportClient();

    Stopwatch snapshotTimer = snapshotDuration.start();
    //This is a blocking call. It'll wait until Snapshot is finished.
    CreateSnapshotResponse createSnapshotResponse = getCreateSnapshotResponse(esTransportClient, repositoryName, snapshotName);

    logger.info("Snapshot Status = " + createSnapshotResponse.status().toString());
    if (createSnapshotResponse.status() == RestStatus.OK) {
        //TODO Add Servo Monitoring so that it can be verified from dashboard
        printSnapshotDetails(createSnapshotResponse);
        snapshotSuccess.incrementAndGet();
    } else if (createSnapshotResponse.status() == RestStatus.INTERNAL_SERVER_ERROR) {
        //TODO Add Servo Monitoring so that it can be verified from dashboard
        logger.info("Snapshot Completely Failed");
        snapshotFailure.incrementAndGet();
    }
    //Stop the timer
    snapshotTimer.stop();
}
 
Example #3
Source File: SnapshotBackupManager.java    From Raigad with Apache License 2.0 5 votes vote down vote up
public void printSnapshotDetails(CreateSnapshotResponse createSnapshotResponse) {
    StringBuilder builder = new StringBuilder();
    builder.append("Snapshot Details:");
    builder.append("\n\t Name = " + createSnapshotResponse.getSnapshotInfo().snapshotId().getName());
    builder.append("\n\t Indices : ");
    for (String index : createSnapshotResponse.getSnapshotInfo().indices()) {
        builder.append("\n\t\t Index = " + index);
    }
    builder.append("\n\t Start Time = " + createSnapshotResponse.getSnapshotInfo().startTime());
    builder.append("\n\t End Time = " + createSnapshotResponse.getSnapshotInfo().endTime());
    long minuteDuration = (createSnapshotResponse.getSnapshotInfo().endTime() - createSnapshotResponse.getSnapshotInfo().startTime()) / (1000 * 60);
    builder.append("\n\t Total Time Taken = " + minuteDuration + " Minutes");
    builder.append("\n\t Total Shards = " + createSnapshotResponse.getSnapshotInfo().totalShards());
    builder.append("\n\t Successful Shards = " + createSnapshotResponse.getSnapshotInfo().successfulShards());
    builder.append("\n\t Total Failed Shards = " + createSnapshotResponse.getSnapshotInfo().failedShards());

    if (createSnapshotResponse.getSnapshotInfo().failedShards() > 0) {
        for (SnapshotShardFailure failedShard : createSnapshotResponse.getSnapshotInfo().shardFailures()) {
            builder.append("\n\t Failed Shards : ");
            builder.append("\n\t\t Index = " + failedShard.index());
            builder.append("\n\t\t Shard Id = " + failedShard.shardId());
            builder.append("\n\t\t Node Id = " + failedShard.nodeId());
            builder.append("\n\t\t Reason = " + failedShard.reason());
        }
    }

    logger.info(builder.toString());
}
 
Example #4
Source File: SnapshotBackupManager.java    From Raigad with Apache License 2.0 5 votes vote down vote up
public CreateSnapshotResponse getCreateSnapshotResponse(Client esTransportClient, String repositoryName, String snapshotName) {
    return esTransportClient.admin().cluster().prepareCreateSnapshot(repositoryName, snapshotName)
            .setWaitForCompletion(config.waitForCompletionOfBackup())
            .setIndices(config.getCommaSeparatedIndicesToBackup().split(COMMA_SEPARATOR))
            .setIncludeGlobalState(config.includeGlobalStateDuringBackup())
            .setPartial(config.partiallyBackupIndices()).get();
}
 
Example #5
Source File: TestBackupRestore.java    From Raigad with Apache License 2.0 5 votes vote down vote up
@Mock
public CreateSnapshotResponse getCreateSnapshotResponse(Client esTransportClient, String repositoryName, String snapshotName) {
    return client0.admin().cluster().prepareCreateSnapshot(repositoryName, snapshotName)
            .setWaitForCompletion(configuration.waitForCompletionOfBackup())
            .setIndices(configuration.getCommaSeparatedIndicesToBackup())
            .setIncludeGlobalState(configuration.includeGlobalStateDuringBackup())
            .setPartial(configuration.partiallyBackupIndices()).get();
}
 
Example #6
Source File: SysSnapshotsTest.java    From crate with Apache License 2.0 5 votes vote down vote up
private void createSnapshot(String snapshotName, String table) {
    CreateSnapshotResponse createSnapshotResponse = client().admin().cluster()
        .prepareCreateSnapshot(REPOSITORY_NAME, snapshotName)
        .setWaitForCompletion(true).setIndices(getFqn(table)).get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    snapshots.add(snapshotName);

}
 
Example #7
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<CreateSnapshotResponse> createSnapshot(CreateSnapshotRequest request) {
    return execute(CreateSnapshotAction.INSTANCE, request);
}
 
Example #8
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void createSnapshot(CreateSnapshotRequest request, ActionListener<CreateSnapshotResponse> listener) {
    execute(CreateSnapshotAction.INSTANCE, request, listener);
}
 
Example #9
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new snapshot.
 */
ActionFuture<CreateSnapshotResponse> createSnapshot(CreateSnapshotRequest request);
 
Example #10
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new snapshot.
 */
void createSnapshot(CreateSnapshotRequest request, ActionListener<CreateSnapshotResponse> listener);