public override string UpdateDatabaseRecord(DatabaseRecord record, long etag) { Watcher.AssertValidReplication(); if (Watcher == null) { return(null); } if (Watcher.TaskId == 0) { Watcher.TaskId = etag; } else { //modified watcher, remove the old one ExternalReplicationBase.RemoveExternalReplication(record.ExternalReplications, Watcher.TaskId); } //this covers the case of a new watcher and edit of an old watcher if (string.IsNullOrEmpty(Watcher.Name)) { Watcher.Name = record.EnsureUniqueTaskName(Watcher.GetDefaultTaskName()); } EnsureTaskNameIsNotUsed(record, Watcher.Name); record.ExternalReplications.Add(Watcher); return(null); }
public override void UpdateDatabaseRecord(DatabaseRecord record, long etag) { Watcher.AssertValidReplication(); if (Watcher == null) { return; } if (Watcher.TaskId == 0) { Watcher.TaskId = etag; } else { //modified watcher, remove the old one ExternalReplicationBase.RemoveExternalReplication(record.ExternalReplications, Watcher.TaskId); } //this covers the case of a new watcher and edit of an old watcher if (string.IsNullOrEmpty(Watcher.Name)) { Watcher.Name = record.EnsureUniqueTaskName(Watcher.GetDefaultTaskName()); } if (Watcher.Name.StartsWith(ServerWideExternalReplication.NamePrefix, StringComparison.OrdinalIgnoreCase)) { var isNewTask = record.ExternalReplications.Exists(x => x.Name.Equals(Watcher.Name, StringComparison.OrdinalIgnoreCase)); throw new InvalidOperationException($"Can't {(isNewTask ? "create" : "update")} task: '{Watcher.Name}'. " + $"A regular (non server-wide) external replication name can't start with prefix '{ServerWideExternalReplication.NamePrefix}'"); } EnsureTaskNameIsNotUsed(record, Watcher.Name); record.ExternalReplications.Add(Watcher); }
public override void UpdateDatabaseRecord(DatabaseRecord record, long etag) { if (PullReplicationAsSink == null) { return; } if (PullReplicationAsSink.TaskId == 0) { PullReplicationAsSink.TaskId = etag; } else { // if new definition doesn't have certificate but there is old one with cert // it means we want to use existing cert or the server certificate if (PullReplicationAsSink.CertificateWithPrivateKey == null) { if (UseServerCertificate == true) { PullReplicationAsSink.CertificateWithPrivateKey = null; } else { var existingDefinition = record.SinkPullReplications.Find(x => x.TaskId == PullReplicationAsSink.TaskId); if (existingDefinition?.CertificateWithPrivateKey != null) { // retain existing certificate PullReplicationAsSink.CertificateWithPrivateKey = existingDefinition.CertificateWithPrivateKey; PullReplicationAsSink.CertificatePassword = existingDefinition.CertificatePassword; } } } ExternalReplicationBase.RemoveExternalReplication(record.SinkPullReplications, PullReplicationAsSink.TaskId); } if (string.IsNullOrEmpty(PullReplicationAsSink.Name)) { PullReplicationAsSink.Name = record.EnsureUniqueTaskName(PullReplicationAsSink.GetDefaultTaskName()); } if (string.IsNullOrEmpty(PullReplicationAsSink.ConnectionStringName)) { throw new ArgumentNullException(nameof(PullReplicationAsSink.ConnectionStringName)); } record.EnsureTaskNameIsNotUsed(PullReplicationAsSink.Name); record.SinkPullReplications.Add(PullReplicationAsSink); }
private static async Task <ModifyOngoingTaskResult> SetupReplication(IDocumentStore store, ExternalReplicationBase watcher) { var result = await store.Maintenance.SendAsync(new PutConnectionStringOperation <RavenConnectionString>(new RavenConnectionString { Name = watcher.ConnectionStringName, Database = watcher.Database, TopologyDiscoveryUrls = new[] { watcher.Url } })); Assert.NotNull(result.RaftCommandIndex); IMaintenanceOperation <ModifyOngoingTaskResult> op; switch (watcher) { case PullReplicationAsSink pull: op = new UpdatePullReplicationAsSinkOperation(pull); break; case ExternalReplication ex: op = new UpdateExternalReplicationOperation(ex); break; default: throw new ArgumentException($"Unrecognized type: {watcher.GetType().FullName}"); } return(await store.Maintenance.SendAsync(op)); }