Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/Nest/DSL/RestoreDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public interface IRestoreRequest : IRepositorySnapshotPath<RestoreRequestParamet
string RenamePattern { get; set; }
[JsonProperty("rename_replacement")]
string RenameReplacement { get; set; }

[JsonProperty("index_settings")]
IUpdateSettingsRequest IndexSettings { get; set; }
[JsonProperty("ignore_index_settings")]
List<string> IgnoreIndexSettings { get; set; }
}

internal static class RestorePathInfo
Expand All @@ -43,6 +46,8 @@ public RestoreRequest(string repository, string snapshot) : base(repository, sna
public string RenamePattern { get; set; }

public string RenameReplacement { get; set; }
public IUpdateSettingsRequest IndexSettings { get; set; }
public List<string> IgnoreIndexSettings { get; set; }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<RestoreRequestParameters> pathInfo)
{
Expand All @@ -61,7 +66,9 @@ public partial class RestoreDescriptor : RepositorySnapshotPathDescriptor<Restor
bool? IRestoreRequest.IncludeGlobalState { get; set; }
string IRestoreRequest.RenamePattern { get; set; }
string IRestoreRequest.RenameReplacement { get; set; }

IUpdateSettingsRequest IRestoreRequest.IndexSettings { get; set; }
List<string> IRestoreRequest.IgnoreIndexSettings { get; set; }

public RestoreDescriptor Index(string index)
{
return this.Indices(index);
Expand Down Expand Up @@ -104,10 +111,30 @@ public RestoreDescriptor RenameReplacement(string renameReplacement)
return this;
}

public RestoreDescriptor IndexSettings(Func<UpdateSettingsDescriptor, UpdateSettingsDescriptor> settingsSelector)
{
settingsSelector.ThrowIfNull("settings");
Self.IndexSettings = settingsSelector(new UpdateSettingsDescriptor());
return this;
}

public RestoreDescriptor IgnoreIndexSettings(List<string> ignoreIndexSettings)
{
ignoreIndexSettings.ThrowIfNull("ignoreIndexSettings");
Self.IgnoreIndexSettings = ignoreIndexSettings;
return this;
}

public RestoreDescriptor IgnoreIndexSettings(params string[] ignoreIndexSettings)
{
ignoreIndexSettings.ThrowIfNull("ignoreIndexSettings");
this.IgnoreIndexSettings(ignoreIndexSettings.ToList());
return this;
}

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<RestoreRequestParameters> pathInfo)
{
RestorePathInfo.Update(pathInfo, this);
}

}
}
112 changes: 75 additions & 37 deletions src/Nest/DSL/UpdateSettingsDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,116 +1,154 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Elasticsearch.Net;
using Newtonsoft.Json;

namespace Nest
{
{
public class UpdatableSettings
{
public const string NumberOfReplicas = "index.number_of_replicas";
public const string AutoExpandReplicas = "index.auto_expand_replicas";
public const string BlocksReadOnly = "index.blocks.read_only";
public const string BlocksRead = "index.blocks.read";
public const string BlocksWrite = "index.blocks.write";
public const string BlocksMetadata = "index.blocks.metadata";
public const string RefreshInterval = "index.refresh_interval";
public const string IndexConcurrency = "index.index_concurrency";
public const string Codec = "index.codec";
public const string CodecBloomLoad = "index.codec.bloom.load";
public const string FailOnMergeFailure = "index.fail_on_merge_failure";
public const string TranslogFlushTreshHoldOps = "index.translog.flush_threshold_ops";
public const string TranslogFlushThresholdSize = "index.translog.flush_threshold_size";
public const string TranslogFlushThresholdPeriod = "index.translog.flush_threshold_period";
public const string TranslogDisableFlush = "index.translog.disable_flush";
public const string CacheFilterMaxSize = "index.cache.filter.max_size";
public const string CacheFilterExpire = "index.cache.filter.expire";
public const string CacheQueryEnable = "index.cache.query.enable";
public const string GatewaySnapshotInterval = "index.gateway.snapshot_interval";
public const string RoutingAllocationInclude = "index.routing.allocation.include";
public const string RoutingAllocationExclude = "index.routing.allocation.exclude";
public const string RoutingAllocationRequire = "index.routing.allocation.require";
public const string RoutingAllocationEnable = "index.routing.allocation.enable";
public const string RoutingAllocationDisableAllication = "index.routing.allocation.disable_allocation";
public const string RoutingAllocationDisableNewAllocation = "index.routing.allocation.disable_new_allocation";
public const string RoutingAllocationDisableReplicaAllocation = "index.routing.allocation.disable_replica_allocation";
public const string RoutingAllocationTotalShardsPerNode = "index.routing.allocation.total_shards_per_node";
public const string RecoveryInitialShards = "index.recovery.initial_shards";
public const string GcDeletes = "index.gc_deletes";
public const string TtlDisablePurge = "index.ttl.disable_purge";
public const string TranslogFsType = "index.translog.fs.type";
public const string CompoundFormat = "index.compound_format";
public const string CompoundOnFlush = "index.compound_on_flush";
public const string WarmersEnabled = "index.warmer.enabled";
public const string Analysis = "analysis";
}

public interface IUpdateSettingsRequest : IIndexOptionalPath<UpdateSettingsRequestParameters>
{
[JsonProperty("index.number_of_replicas")]
[JsonProperty(UpdatableSettings.NumberOfReplicas)]
int? NumberOfReplicas { get; set; }

[JsonProperty("index.auto_expand_replicas")]
[JsonProperty(UpdatableSettings.AutoExpandReplicas)]
object AutoExpandReplicas { get; set; }

[JsonProperty("index.blocks.read_only")]
[JsonProperty(UpdatableSettings.BlocksReadOnly)]
bool? BlocksReadOnly { get; set; }

[JsonProperty("index.blocks.read")]
[JsonProperty(UpdatableSettings.BlocksRead)]
bool? BlocksRead { get; set; }

[JsonProperty("index.blocks.write")]
[JsonProperty(UpdatableSettings.BlocksWrite)]
bool? BlocksWrite { get; set; }

[JsonProperty("index.blocks.metadata")]
[JsonProperty(UpdatableSettings.BlocksMetadata)]
bool? BlocksMetadata { get; set; }

[JsonProperty("index.refresh_interval")]
[JsonProperty(UpdatableSettings.RefreshInterval)]
string RefreshInterval { get; set; }

[JsonProperty("index.index_concurrency")]
[JsonProperty(UpdatableSettings.IndexConcurrency)]
int? IndexConcurrency { get; set; }

[JsonProperty("index.codec")]
[JsonProperty(UpdatableSettings.Codec)]
string Codec { get; set; }

[JsonProperty("index.codec.bloom.load")]
[JsonProperty(UpdatableSettings.CodecBloomLoad)]
bool? CodecBloomLoad { get; set; }

[JsonProperty("index.fail_on_merge_failure")]
[JsonProperty(UpdatableSettings.FailOnMergeFailure)]
bool? FailOnMergeFailure { get; set; }

[JsonProperty("index.translog.flush_threshold_ops")]
[JsonProperty(UpdatableSettings.TranslogFlushTreshHoldOps)]
string TranslogFlushTreshHoldOps { get; set; }

[JsonProperty("index.translog.flush_threshold_size")]
[JsonProperty(UpdatableSettings.TranslogFlushThresholdSize)]
string TranslogFlushThresholdSize { get; set; }

[JsonProperty("index.translog.flush_threshold_period")]
[JsonProperty(UpdatableSettings.TranslogFlushThresholdPeriod)]
string TranslogFlushThresholdPeriod { get; set; }

[JsonProperty("index.translog.disable_flush")]
[JsonProperty(UpdatableSettings.TranslogDisableFlush)]
bool? TranslogDisableFlush { get; set; }

[JsonProperty("index.cache.filter.max_size")]
[JsonProperty(UpdatableSettings.CacheFilterMaxSize)]
string CacheFilterMaxSize { get; set; }

[JsonProperty("index.cache.filter.expire")]
[JsonProperty(UpdatableSettings.CacheFilterExpire)]
string CacheFilterExpire { get; set; }

[JsonProperty("index.cache.query.enable")]
[JsonProperty(UpdatableSettings.CacheQueryEnable)]
bool? CacheQueryEnable { get; set; }

[JsonProperty("index.gateway.snapshot_interval")]
[JsonProperty(UpdatableSettings.GatewaySnapshotInterval)]
string GatewaySnapshotInterval { get; set; }

[JsonProperty("index.routing.allocation.include")]
[JsonProperty(UpdatableSettings.RoutingAllocationInclude)]
IDictionary<string, object> RoutingAllocationInclude { get; set; }

[JsonProperty("index.routing.allocation.exclude")]
[JsonProperty(UpdatableSettings.RoutingAllocationExclude)]
IDictionary<string, object> RoutingAllocationExclude { get; set; }

[JsonProperty("index.routing.allocation.require")]
[JsonProperty(UpdatableSettings.RoutingAllocationRequire)]
IDictionary<string, object> RoutingAllocationRequire { get; set; }

[JsonProperty("index.routing.allocation.enable")]
[JsonProperty(UpdatableSettings.RoutingAllocationEnable)]
RoutingAllocationEnableOption? RoutingAllocationEnable { get; set; }

[JsonProperty("index.routing.allocation.disable_allocation")]
[JsonProperty(UpdatableSettings.RoutingAllocationDisableAllication)]
bool? RoutingAllocationDisableAllication { get; set; }

[JsonProperty("index.routing.allocation.disable_new_allocation")]
[JsonProperty(UpdatableSettings.RoutingAllocationDisableNewAllocation)]
bool? RoutingAllocationDisableNewAllocation { get; set; }

[JsonProperty("index.routing.allocation.disable_replica_allocation")]
[JsonProperty(UpdatableSettings.RoutingAllocationDisableReplicaAllocation)]
bool? RoutingAllocationDisableReplicaAllocation { get; set; }

[JsonProperty("index.routing.allocation.total_shards_per_node")]
[JsonProperty(UpdatableSettings.RoutingAllocationTotalShardsPerNode)]
int? RoutingAllocationTotalShardsPerNode { get; set; }

[JsonProperty("index.recovery.initial_shards")]
[JsonProperty(UpdatableSettings.RecoveryInitialShards)]
string RecoveryInitialShards { get; set; }

[JsonProperty("index.gc_deletes")]
[JsonProperty(UpdatableSettings.GcDeletes)]
bool? GcDeletes { get; set; }

[JsonProperty("index.ttl.disable_purge")]
[JsonProperty(UpdatableSettings.TtlDisablePurge)]
bool? TtlDisablePurge { get; set; }

[JsonProperty("index.translog.fs.type")]
[JsonProperty(UpdatableSettings.TranslogFsType)]
string TranslogFsType { get; set; }

[JsonProperty("index.compound_format")]
[JsonProperty(UpdatableSettings.CompoundFormat)]
bool? CompoundFormat { get; set; }

[JsonProperty("index.compound_on_flush")]
[JsonProperty(UpdatableSettings.CompoundOnFlush)]
bool? CompoundOnFlush { get; set; }

[JsonProperty("index.warmer.enabled")]
[JsonProperty(UpdatableSettings.WarmersEnabled)]
bool? WarmersEnabled { get; set; }

[JsonProperty("analysis")]
[JsonProperty(UpdatableSettings.Analysis)]
AnalysisSettings Analysis { get; set; }
}

Expand Down
39 changes: 38 additions & 1 deletion src/Tests/Nest.Tests.Integration/Core/Repository/RestoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void SnapshotRestore()

var indexExistsResponse = this.Client.IndexExists(f => f.Index(_restoredIndexName));
indexExistsResponse.Exists.Should().BeTrue();

var count = this.Client.Count<ElasticsearchProject>(descriptor => descriptor.Index(_restoredIndexName)).Count;

var indexContent = this.Client.SourceMany<ElasticsearchProject>(_indexedElements.Select(x => (long)x.Id), _restoredIndexName);
Expand All @@ -99,6 +99,43 @@ public void SnapshotRestore()
indexContent.ShouldBeEquivalentTo(_indexedElements);
}

[Test]
[SkipVersion("0 - 1.4.9", "Requires index_settings and ignore_index_settings parameters which have been added in ES 1.5.0")]
public void SnapshotRestore_IndexSettings()
{
var updateSettingsResponse = this.Client.UpdateSettings(descriptor => descriptor.BlocksWrite());
updateSettingsResponse.IsValid.Should().BeTrue();

var snapshotResponse = this.Client.Snapshot(_repositoryName, _snapshotName, selector: f => f
.Index(_indexName)
.WaitForCompletion(true)
.IgnoreUnavailable()
.Partial());
snapshotResponse.IsValid.Should().BeTrue();

var d = ElasticsearchConfiguration.DefaultIndex;
var restoreResponse = this.Client.Restore(_repositoryName, _snapshotName, r => r
.WaitForCompletion(true)
.RenamePattern(d + "_(.+)")
.RenameReplacement(d + "_restored_$1")
.Index(_indexName)
.IgnoreUnavailable(true)
.IndexSettings(descriptor => descriptor
.RefreshInterval("123s"))
.IgnoreIndexSettings(UpdatableSettings.BlocksWrite));

restoreResponse.IsValid.Should().BeTrue();
_restoredIndexName = _indexName.Replace(d + "_", d + "_restored_");

var indexExistsResponse = this.Client.IndexExists(f => f.Index(_restoredIndexName));
indexExistsResponse.Exists.Should().BeTrue();

var indexSettingsResponse = this.Client.GetIndexSettings(descriptor => descriptor.Index(_restoredIndexName));
indexSettingsResponse.IsValid.Should().BeTrue();
indexSettingsResponse.IndexSettings.Settings[UpdatableSettings.RefreshInterval].Should().Be("123s");
indexSettingsResponse.IndexSettings.Settings[UpdatableSettings.BlocksWrite].Should().BeNull();
}

[Test]
[SkipVersion("0 - 1.0.9", "Requires the snapshot status api which was added in ES 1.1")]
public void SnapshotRestoreObservable()
Expand Down
13 changes: 13 additions & 0 deletions src/Tests/Nest.Tests.Unit/Core/Repository/Restore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"indices": [
"index"
],
"index_settings": {
"index.number_of_replicas": 0,
"index.blocks.read": true
},
"ignore_index_settings": [
"index.refresh_interval",
"index.auto_expand_replicas"
]
}
54 changes: 54 additions & 0 deletions src/Tests/Nest.Tests.Unit/Core/Repository/RestoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Elasticsearch.Net;
using FluentAssertions;
using NUnit.Framework;

namespace Nest.Tests.Unit.Core.Repository
{
public class RestoreTests : BaseJsonTests
{
[Test]
public void Restore()
{
var restoreResponse = _client.Restore("repository", "snapshotName",
descriptor => descriptor
.Index("index")
.IndexSettings(settingsDescriptor => settingsDescriptor
.NumberOfReplicas(0)
.BlocksRead())
.IgnoreIndexSettings(UpdatableSettings.RefreshInterval, UpdatableSettings.AutoExpandReplicas));

restoreResponse.ConnectionStatus.RequestUrl.Should().Be("http://localhost:9200/_snapshot/repository/snapshotName/_restore");
this.JsonEquals(restoreResponse.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void Null_IgnoreIndexSettings_ThorwException()
{
List<string> ignoreIndexSettings = null;
_client.Restore("repository", "snapshotName",
descriptor => descriptor
.Index("index")
.IgnoreIndexSettings(ignoreIndexSettings));
}

[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void Null_IndexSettings_ThorwException()
{
Func<UpdateSettingsDescriptor, UpdateSettingsDescriptor> settingsSelector = null;

var restoreResponse = _client.Restore("repository", "snapshotName",
descriptor => descriptor
.Index("index")
.IndexSettings(settingsSelector));
}
}
}
4 changes: 4 additions & 0 deletions src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
</None>
<Compile Include="Core\MultiPercolate\MultiPercolateTests.cs" />
<Compile Include="Core\Map\Transform\MappingTansformTests.cs" />
<Compile Include="Core\Repository\RestoreTests.cs" />
<Compile Include="Core\Script\DeleteScriptRequestTests.cs" />
<Compile Include="Core\Script\GetScriptRequestTests.cs" />
<Compile Include="Core\Script\PutScriptRequestTests.cs" />
Expand Down Expand Up @@ -683,6 +684,9 @@
<None Include="Core\MultiPercolate\MultiPercolateJson.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Core\Repository\Restore.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Core\Script\PutScript.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down