tc.admin().cluster().createSnapshot(new CreateSnapshotRequest("vulcangov", "vulcangov_1").indices("vulcangov").includeGlobalState(true).waitForCompletion(true)).actionGet(); tc.admin().cluster().createSnapshot(new CreateSnapshotRequest("searchguard", "searchguard_1").indices("searchguard").includeGlobalState(false).waitForCompletion(true)).actionGet(); tc.admin().cluster().createSnapshot(new CreateSnapshotRequest("all", "all_1").indices("*").includeGlobalState(false).waitForCompletion(true)).actionGet();
@Override protected void masterOperation(final CreateSnapshotRequest request, ClusterState state, final ActionListener<CreateSnapshotResponse> listener) { final String snapshotName = indexNameExpressionResolver.resolveDateMathExpression(request.snapshot()); SnapshotsService.SnapshotRequest snapshotRequest = new SnapshotsService.SnapshotRequest(request.repository(), snapshotName, "create_snapshot [" + snapshotName + "]") .indices(request.indices()) .indicesOptions(request.indicesOptions()) .partial(request.partial()) .settings(request.settings()) .includeGlobalState(request.includeGlobalState()) .masterNodeTimeout(request.masterNodeTimeout()); snapshotsService.createSnapshot(snapshotRequest, new SnapshotsService.CreateSnapshotListener() { @Override
if (name.equals("indices")) { if (entry.getValue() instanceof String) { indices(Strings.splitStringByCommaToArray((String) entry.getValue())); } else if (entry.getValue() instanceof ArrayList) { indices((ArrayList<String>) entry.getValue()); } else { throw new IllegalArgumentException("malformed indices section, should be an array of strings"); partial(nodeBooleanValue(entry.getValue(), "partial")); } else if (name.equals("settings")) { if (!(entry.getValue() instanceof Map)) { throw new IllegalArgumentException("malformed settings section, should indices an inner object"); settings((Map<String, Object>) entry.getValue()); } else if (name.equals("include_global_state")) { includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state"); indicesOptions(IndicesOptions.fromMap(source, indicesOptions)); return this;
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { CreateSnapshotRequest createSnapshotRequest = createSnapshotRequest(request.param("repository"), request.param("snapshot")); request.applyContentParser(p -> createSnapshotRequest.source(p.mapOrdered())); createSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", createSnapshotRequest.masterNodeTimeout())); createSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false)); return channel -> client.admin().cluster().createSnapshot(createSnapshotRequest, new RestToXContentListener<>(channel)); } }
static Request createSnapshot(CreateSnapshotRequest createSnapshotRequest) throws IOException { String endpoint = new RequestConverters.EndpointBuilder().addPathPart("_snapshot") .addPathPart(createSnapshotRequest.repository()) .addPathPart(createSnapshotRequest.snapshot()) .build(); Request request = new Request(HttpPut.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(request); params.withMasterTimeout(createSnapshotRequest.masterNodeTimeout()); params.withWaitForCompletion(createSnapshotRequest.waitForCompletion()); request.setEntity(RequestConverters.createEntity(createSnapshotRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); return request; }
/** * If set to true the request should wait for the snapshot completion before returning. * * @param waitForCompletion true if * @return this builder */ public CreateSnapshotRequestBuilder setWaitForCompletion(boolean waitForCompletion) { request.waitForCompletion(waitForCompletion); return this; }
/** * Sets repository-specific snapshot settings. * <p> * See repository documentation for more information. * * @param settings repository-specific snapshot settings * @return this builder */ public CreateSnapshotRequestBuilder setSettings(Map<String, Object> settings) { request.settings(settings); return this; }
/** * Creates new snapshot * * @param repository repository name * @param snapshot snapshot name * @return create snapshot request */ public static CreateSnapshotRequest createSnapshotRequest(String repository, String snapshot) { return new CreateSnapshotRequest(repository, snapshot); }
/** * Sets the repository name * * @param repository repository name * @return this builder */ public CreateSnapshotRequestBuilder setRepository(String repository) { request.repository(repository); return this; }
/** * Sets the snapshot name * * @param snapshot snapshot name * @return this builder */ public CreateSnapshotRequestBuilder setSnapshot(String snapshot) { request.snapshot(snapshot); return this; }
/** * Sets a list of indices that should be included into the snapshot * <p> * The list of indices supports multi-index syntax. For example: "+test*" ,"-test42" will index all indices with * prefix "test" except index "test42". Aliases are supported. An empty list or {"_all"} will snapshot all open * indices in the cluster. * * @return this builder */ public CreateSnapshotRequestBuilder setIndices(String... indices) { request.indices(indices); return this; }
/** * Set to true if snapshot should include global cluster state * * @param includeGlobalState true if snapshot should include global cluster state * @return this builder */ public CreateSnapshotRequestBuilder setIncludeGlobalState(boolean includeGlobalState) { request.includeGlobalState(includeGlobalState); return this; } }
/** * If set to true the request should snapshot indices with unavailable shards * * @param partial true if request should snapshot indices with unavailable shards * @return this builder */ public CreateSnapshotRequestBuilder setPartial(boolean partial) { request.partial(partial); return this; }
/** * Specifies the indices options. Like what type of requested indices to ignore. For example indices that don't exist. * * @param indicesOptions the desired behaviour regarding indices options * @return this request */ public CreateSnapshotRequestBuilder setIndicesOptions(IndicesOptions indicesOptions) { request.indicesOptions(indicesOptions); return this; }
@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)); } }
if (name.equals("indices")) { if (entry.getValue() instanceof String) { indices(Strings.splitStringByCommaToArray((String) entry.getValue())); } else if (entry.getValue() instanceof ArrayList) { indices((ArrayList<String>) entry.getValue()); } else { throw new IllegalArgumentException("malformed indices section, should be an array of strings"); partial(nodeBooleanValue(entry.getValue(), "partial")); } else if (name.equals("settings")) { if (!(entry.getValue() instanceof Map)) { throw new IllegalArgumentException("malformed settings section, should indices an inner object"); settings((Map<String, Object>) entry.getValue()); } else if (name.equals("include_global_state")) { includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state"); indicesOptions(IndicesOptions.fromMap(source, indicesOptions)); return this;
static Request createSnapshot(CreateSnapshotRequest createSnapshotRequest) throws IOException { String endpoint = new RequestConverters.EndpointBuilder().addPathPart("_snapshot") .addPathPart(createSnapshotRequest.repository()) .addPathPart(createSnapshotRequest.snapshot()) .build(); Request request = new Request(HttpPut.METHOD_NAME, endpoint); RequestConverters.Params params = new RequestConverters.Params(request); params.withMasterTimeout(createSnapshotRequest.masterNodeTimeout()); params.withWaitForCompletion(createSnapshotRequest.waitForCompletion()); request.setEntity(RequestConverters.createEntity(createSnapshotRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE)); return request; }
@Override public void onResponse() { if (request.waitForCompletion()) { snapshotsService.addListener(new SnapshotsService.SnapshotCompletionListener() { @Override public void onSnapshotCompletion(Snapshot snapshot, SnapshotInfo snapshotInfo) { if (snapshot.getRepository().equals(request.repository()) && snapshot.getSnapshotId().getName().equals(snapshotName)) { listener.onResponse(new CreateSnapshotResponse(snapshotInfo)); snapshotsService.removeListener(this); } } @Override public void onSnapshotFailure(Snapshot snapshot, Exception e) { if (snapshot.getRepository().equals(request.repository()) && snapshot.getSnapshotId().getName().equals(snapshotName)) { listener.onFailure(e); snapshotsService.removeListener(this); } } }); } else { listener.onResponse(new CreateSnapshotResponse()); } }
/** * Sets repository-specific snapshot settings. * <p> * See repository documentation for more information. * * @param settings repository-specific snapshot settings * @return this builder */ public CreateSnapshotRequestBuilder setSettings(Settings settings) { request.settings(settings); return this; }
/** * Constructs a new create snapshot request builder with specified repository and snapshot names */ public CreateSnapshotRequestBuilder(ElasticsearchClient client, CreateSnapshotAction action, String repository, String snapshot) { super(client, action, new CreateSnapshotRequest(repository, snapshot)); }