public OperatorPolicyRequest(string pattern, IDictionary <string, ulong> arguments, int priority, OperatorPolicyAppliedTo applyTo) { Pattern = pattern; Arguments = arguments; Priority = priority; ApplyTo = applyTo; }
/// <summary> /// Creates the specified operator policy on the target RabbitMQ virtual host. /// </summary> /// <param name="factory">The object factory that implements the underlying functionality.</param> /// <param name="policy">Name of the operator policy.</param> /// <param name="pattern">The pattern to apply the policy on.</param> /// <param name="vhost">The virtual host for which the policy should be applied to.</param> /// <param name="configurator">Describes how the operator policy will be created by setting arguments through set methods.</param> /// <param name="appliedTo">The broker object for which the policy is to be applied to.</param> /// <param name="priority"></param> /// <param name="cancellationToken">Token used to cancel the operation running on the current thread.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">Throws ArgumentNullException if BrokerObjectFactory is null.</exception> public static async Task <Result> CreateOperatorPolicy(this IBrokerObjectFactory factory, string policy, string pattern, string vhost, Action <OperatorPolicyConfigurator> configurator, OperatorPolicyAppliedTo appliedTo = default, int priority = default, CancellationToken cancellationToken = default) { if (factory.IsNull()) { throw new ArgumentNullException(nameof(factory)); } return(await factory.Object <OperatorPolicy>() .Create(policy, pattern, vhost, configurator, appliedTo, priority, cancellationToken) .ConfigureAwait(false)); }
public async Task <Result> Create(string policy, string pattern, string vhost, Action <OperatorPolicyConfigurator> configurator, OperatorPolicyAppliedTo appliedTo = default, int priority = default, CancellationToken cancellationToken = default) { cancellationToken.RequestCanceled(); var impl = new OperatorPolicyConfiguratorImpl(); configurator?.Invoke(impl); impl.Validate(); OperatorPolicyRequest request = new () { Pattern = pattern, Priority = priority, Arguments = impl.Arguments.Value, ApplyTo = appliedTo }; Debug.Assert(request != null); var errors = new List <Error>(); errors.AddRange(impl.Errors.Value); if (string.IsNullOrWhiteSpace(policy)) { errors.Add(new(){ Reason = "The name of the operator policy is missing." }); } if (string.IsNullOrWhiteSpace(vhost)) { errors.Add(new (){ Reason = "The name of the virtual host is missing." }); } string url = $"api/operator-policies/{vhost.ToSanitizedName()}/{policy}"; if (errors.Any()) { return new FaultedResult { DebugInfo = new (){ URL = url, Request = request.ToJsonString(Deserializer.Options), Errors = errors } } } ; return(await PutRequest(url, request, cancellationToken).ConfigureAwait(false)); }