protected internal override void Apply(IManagementClient managementClient) { _log.Info($"Moving messages from queue '{SourceQueue}' to exchange '{DestinationExchange}'"); if (MessageTypeDeclared) { _log.Info($" MessageType = {MessageType}"); } var virtualHost = managementClient.GetVhost(VirtualHost); var sourceQueue = managementClient.GetQueue(SourceQueue, virtualHost); var destinationExchange = managementClient.GetExchange(DestinationExchange, virtualHost); var messages = managementClient.GetMessagesFromQueue(sourceQueue, new GetMessagesCriteria(long.MaxValue, false)); foreach (var message in messages) { if (MessageTypeDeclared) { message.Properties["type"] = MessageType; } var properties = message.Properties .ToDictionary(property => property.Key, property => property.Value); managementClient.Publish(destinationExchange, new PublishInfo(properties, "#", message.Payload, message.PayloadEncoding)); } }
/// <summary> /// Creates or updates the given asset. /// </summary> /// <param name="client">Content management client instance.</param> /// <param name="identifier">The identifier of the asset.</param> /// <param name="fileContent">Represents the content of the file.</param> /// <param name="upsertModel">Updated values for the asset.</param> /// <returns>The <see cref="AssetModel{T}"/> instance that represents created or updated strongly typed asset.</returns> public async static Task <AssetModel <T> > UpsertAssetAsync <T>(this IManagementClient client, Reference identifier, FileContentSource fileContent, AssetUpsertModel <T> upsertModel) where T : new() { if (identifier == null) { throw new ArgumentNullException(nameof(identifier)); } if (fileContent == null) { throw new ArgumentNullException(nameof(fileContent)); } if (upsertModel == null) { throw new ArgumentNullException(nameof(upsertModel)); } var fileResult = await client.UploadFileAsync(fileContent); upsertModel.FileReference = fileResult; var response = await client.UpsertAssetAsync(identifier, upsertModel); return(response); }
public NetworkClient(INetworkManagementClient client, IComputeManagementClient computeClient, IManagementClient managementClient, ICommandRuntime commandRuntime) { this.client = client; this.computeClient = computeClient; this.managementClient = managementClient; this.commandRuntime = commandRuntime; }
public async Task InitializeAsync() { using (var timeoutCts = new CancellationTokenSource(InitializationTimeout)) { dockerEngineOsPlatform = await dockerProxy.GetDockerEngineOsAsync(timeoutCts.Token).ConfigureAwait(false); dockerNetworkName = dockerEngineOsPlatform == OSPlatform.Windows ? null : "bridgeWhaleNet"; await DisposeAsync(timeoutCts.Token).ConfigureAwait(false); await CreateNetworkAsync(timeoutCts.Token).ConfigureAwait(false); var rabbitMQDockerImage = await PullImageAsync(timeoutCts.Token).ConfigureAwait(false); var containerId = await RunContainerAsync(rabbitMQDockerImage, timeoutCts.Token).ConfigureAwait(false); if (dockerEngineOsPlatform == OSPlatform.Windows) { Host = await dockerProxy.GetContainerIpAsync(containerId, timeoutCts.Token).ConfigureAwait(false); } ManagementClient = new ManagementClient( Host, Configuration.RabbitMqUser, Configuration.RabbitMqPassword, Configuration.RabbitMqManagementPort ); await WaitForRabbitMqReadyAsync(timeoutCts.Token); } }
public void Run(IManagementClient managementClient) { Apply(); _actions.ForEach(action => action.VerifyState()); _actions.ForEach(action => action.Apply(managementClient)); }
protected internal override void Apply(IManagementClient managementClient) { var destinationName = ToQueueDeclared ? ToQueue : ToExchange; _log.Info($"Declaring binding from '{FromExchange}' to '{destinationName}'"); _log.Info($" RoutingKey = {RoutingKey}"); var virtualHost = managementClient.GetVhost(VirtualHost); var exchange = managementClient.GetExchange(FromExchange, virtualHost); var info = new BindingInfo(RoutingKey); if (ToQueueDeclared) { var toQueue = managementClient.GetQueue(ToQueue, virtualHost); managementClient.CreateBinding(exchange, toQueue, info); } if (ToExchangeDeclared) { var toExchange = managementClient.GetExchange(ToExchange, virtualHost); managementClient.CreateBinding(exchange, toExchange, info); } _log.Info($"Finished declaring binding from '{FromExchange}' to '{destinationName}'"); }
public void SetUp() { check = MockRepository.GenerateStub <ICheck>(); check .Stub(x => x.RunCheck(Arg <IManagementClient> .Is.Anything)) .Return(new CheckResult(true, "boo!")) .Repeat.Any(); brokers = new[] { new Broker { ManagementUrl = "http://broker1", Username = "******", Password = "******" }, }; checks = new[] { check, }; managementClient = MockRepository.GenerateStub <IManagementClient>(); managementClientFactory = MockRepository.GenerateStub <IManagementClientFactory>(); managementClientFactory.Stub(x => x.CreateManagementClient(Arg <Broker> .Is.Anything)).Return(managementClient) .Repeat.Any(); alertSink = MockRepository.GenerateStub <IAlertSink>(); monitorRun = new MonitorRun(brokers, checks, managementClientFactory, new[] { alertSink }); }
/// <summary> /// The Get Operation Status operation returns the status of the /// specified operation. After calling an asynchronous operation, you /// can call Get Operation Status to determine whether the operation /// has succeeded, failed, or is still in progress. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.IManagementClient. /// </param> /// <param name='requestId'> /// Required. The request ID for the request you wish to track. The /// request ID is returned in the x-ms-request-id response header for /// every request. /// </param> /// <returns> /// The response body contains the status of the specified asynchronous /// operation, indicating whether it has succeeded, is inprogress, or /// has failed. Note that this status is distinct from the HTTP status /// code returned for the Get Operation Status operation itself. If /// the asynchronous operation succeeded, the response body includes /// the HTTP status code for the successful request. If the /// asynchronous operation failed, the response body includes the HTTP /// status code for the failed request, and also includes error /// information regarding the failure. /// </returns> public static OperationStatusResponse GetOperationStatus(this IManagementClient operations, string requestId) { return(Task.Factory.StartNew((object s) => { return ((IManagementClient)s).GetOperationStatusAsync(requestId); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public CheckResult RunCheck(IManagementClient managementClient) { var overview = managementClient.GetOverview(); var alert = overview.QueueTotals.Messages >= alertQueueCount; var message = string.Format("broker '{0}' queued messages exceed alert level {1}, now {2}", managementClient.HostUrl, alertQueueCount, overview.QueueTotals.Messages); return new CheckResult(alert, message); }
public UserUnitOfWork(IManagementClient managementClient, IUserRepository userRepository, IBus bus, IOpenDistroElasticsearchClient elasticsearchClient, ILogConsumerService logConsumerService, ILogger <UserUnitOfWork> logger) { _managementClient = managementClient; _userRepository = userRepository; _bus = bus; _elasticsearchClient = elasticsearchClient; _logConsumerService = logConsumerService; _logger = logger; }
public CheckResult RunCheck(IManagementClient managementClient) { var overview = managementClient.GetOverview(); var alert = overview.QueueTotals.Messages >= alertQueueCount; var message = string.Format("broker '{0}' queued messages exceed alert level {1}, now {2}", managementClient.HostUrl, alertQueueCount, overview.QueueTotals.Messages); return(new CheckResult(alert, message)); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="RmqSubscriptionManager"/> class. /// </summary> /// <param name="logger">Используемый компонент логирования.</param> /// <param name="managementClient">Фабрика соединений RabbitMQ.</param> /// <param name="vhost">Virtual host RabbitMQ</param> public RmqSubscriptionsManager(ILogger logger, IManagementClient managementClient, string vhost = "/") { this._logger = logger; this._managementClient = managementClient; this._vhostStr = vhost; // TODO: следует ли выносить это в зависимости? this._namingManager = new AmqpNamingManager(); }
public ManagementCodeGenerator(IOptions <CodeGeneratorOptions> options, IOutputProvider outputProvider, IManagementClient managementClient) : base(options, outputProvider) { if (!options.Value.ManagementApi) { throw new InvalidOperationException("Cannot create Management models with Delivery API options."); } _managementClient = managementClient; }
protected internal override void Apply(IManagementClient managementClient) { _log.Info($"Deleting vhost '{Name}'"); var virtualHost = managementClient.GetVhost(Name); managementClient.DeleteVirtualHost(virtualHost); _log.Info($"Finished Deleting vhost '{Name}'"); }
protected internal override void Apply(IManagementClient managementClient) { _log.Info($"Deleting exchange '{Name}' from '{VirtualHost}'"); var virtualHost = managementClient.GetVhost(VirtualHost); var exchange = managementClient.GetExchange(Name, virtualHost); managementClient.DeleteExchange(exchange); _log.Info($"Finished deleting exchange '{Name}' from '{VirtualHost}'"); }
/// <summary> /// Создаёт новый экземпляр класса <see cref="RmqSubscriptionsSynchronizer"/>. /// </summary> /// <param name="logger">Используемый компонент логирования.</param> /// <param name="esbSubscriptionsManager">Менеджер подписок шины.</param> /// <param name="mqSubscriptionsManager">Менеджер подписок </param> public RmqSubscriptionsSynchronizer(ILogger logger, ISubscriptionsManager esbSubscriptionsManager, ISubscriptionsManager mqSubscriptionsManager, IDataService dataService, IManagementClient managementClient, string vhost = "/") { this._logger = logger; this._esbSubscriptionsManager = esbSubscriptionsManager; this._mqSubscriptionsManager = mqSubscriptionsManager; this._dataService = dataService; this._managementClient = managementClient; this._namingManager = new AmqpNamingManager(); this._vhostStr = vhost; }
protected internal override void Apply(IManagementClient managementClient) { _log.Info($"Purging queue '{Name}' on '{VirtualHost}'"); var virtualHost = managementClient.GetVhost(VirtualHost); var queue = managementClient.GetQueue(Name, virtualHost); managementClient.Purge(queue); _log.Info($"Finished purging queue '{Name}' on '{VirtualHost}'"); }
public CheckResult RunCheck(IManagementClient managementClient) { var overview = managementClient.GetOverview(); var alert = overview.ObjectTotals.Channels >= alertChannelCount; var message = string.Format("broker '{0}' channels have exceeded alert level {1}, now {2}", managementClient.HostUrl, alertChannelCount, overview.ObjectTotals.Channels); return(new CheckResult(alert, message)); }
public CheckResult RunCheck(IManagementClient managementClient) { var overview = managementClient.GetOverview(); var alert = overview.object_totals.channels >= alertChannelCount; var message = string.Format("broker '{0}' channels have exceeded alert level {1}, now {2}", managementClient.HostUrl, alertChannelCount, overview.object_totals.channels); return new CheckResult(alert, message); }
protected internal override void Apply(IManagementClient managementClient) { _log.Info($"Deleting queue '{Name}' from '{VirtualHost}'"); var virtualHost = managementClient.GetVhost(VirtualHost); var queue = managementClient.GetQueue(Name, virtualHost); managementClient.DeleteQueue(queue); _log.Info($"Finished deleting queue '{Name}' from '{VirtualHost}'"); }
public Topology Parse(IManagementClient client, Vhost virtualHost) { var topology = new Topology(); foreach (var exchange in client.GetExchanges()) { if (!IsSystemExchange(exchange.Name)) { var modelExchange = new Model.Exchange { Name = exchange.Name, ExchangeType = ExchangeTypeMap[exchange.Type], Durable = exchange.Durable, }; MapArguments(exchange.Arguments, modelExchange.Arguments); topology.Exchanges.Add(modelExchange); } } foreach (var queue in client.GetQueues()) { if (!IsSystemQueue(queue)) { var modelQueue = new Model.Queue { Name = queue.Name, Durable = queue.Durable }; MapArguments(queue.Arguments, modelQueue.Arguments); foreach (var binding in client.GetBindingsForQueue(queue)) { if (!IsSystemBinding(binding)) { var modelBinding = new Model.Binding { Exchange = binding.Source, RoutingKey = binding.RoutingKey }; MapArguments(binding.Arguments, modelBinding.Arguments); modelQueue.Bindings.Add(modelBinding); } } topology.Queues.Add(modelQueue); } } return topology; }
/// <remarks> /// If <see cref="configSettings"/> is null, a default value is used. /// </remarks> public MockInfrastructureCoordinatorFactory(IManagementClient managementClient, IDictionary <string, string> configSettings = null, IQueryClient queryClient = null, IInfrastructureAgentWrapper agent = null) { managementClient.ThrowIfNull("managementClient"); this.managementClient = managementClient; this.configSettings = configSettings != null ? new Dictionary <string, string>(configSettings, StringComparer.OrdinalIgnoreCase) : new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); this.queryClient = queryClient ?? new MockQueryClient(); this.agent = agent ?? new MockInfrastructureAgentWrapper(); }
public CheckResult RunCheck(IManagementClient managementClient) { var vhostsWithErrors = from vhost in managementClient.GetVHosts() let errorQueue = GetErrorQueue(managementClient, vhost) where errorQueue.Messages > 0 select vhost.Name; var message = string.Format(errorMessage, managementClient.HostUrl, string.Join(", ", vhostsWithErrors)); return(new CheckResult(vhostsWithErrors.Any(), message)); }
public CheckResult RunCheck(IManagementClient managementClient) { var vhostsWithErrors = from vhost in managementClient.GetVHosts() let errorQueue = GetErrorQueue(managementClient, vhost) where errorQueue.Messages > 0 select vhost.Name; var message = string.Format(errorMessage, managementClient.HostUrl, string.Join(", ", vhostsWithErrors)); return new CheckResult(vhostsWithErrors.Any(), message); }
public Worker( IAmazonCloudWatch awsCloudWatchClient, IManagementClient rabbitMqClient, ILogger <Worker> logger, IOptionsMonitor <WorkerOptions> options ) { _awsCloudWatchClient = awsCloudWatchClient; _rabbitMqClient = rabbitMqClient; _logger = logger; _interval = options.CurrentValue.Interval; }
public void OccasionallyKillConnections(IManagementClient client) { while (true) { Thread.Sleep(3000); var connections = client.GetConnections(); foreach (var connection in connections) { Console.Out.WriteLine("\nKilling connection: {0}\n", connection.Name); client.CloseConnection(connection); } } }
public WindowsAzureRepairExecutor( WindowsAzureInfrastructureCoordinator coordinator, string internalServiceName, IManagementClient managementClient) { this.fabricClient = new FabricClient(); this.repairManager = fabricClient.RepairManager; this.coordinator = coordinator; this.managementClient = managementClient; this.executorName = "fabric:/System/" + internalServiceName; this.BuildMaintenanceActionMap(); }
public CheckResult RunCheck(IManagementClient managementClient) { var overview = managementClient.GetOverview(); var alert = overview.ObjectTotals.Connections >= alertConnectionCount; var message = alert ? string.Format( "broker {0} connections have exceeded alert level {1}. Now {2}", managementClient.HostUrl, alertConnectionCount, overview.ObjectTotals.Connections) : ""; return(new CheckResult(alert, message)); }
public RmqSendingManager(ILogger logger, ISubscriptionsManager esbSubscriptionsManager, IConnectionFactory connectionFactory, IManagementClient managementClient, IMessageConverter converter, AmqpNamingManager namingManager, string vhost = "/", bool useLegacySenders = true) { this._logger = logger; this._esbSubscriptionsManager = esbSubscriptionsManager; this._connectionFactory = connectionFactory; this._managementClient = managementClient; this._converter = converter; this._namingManager = namingManager; this.MessageSenderCreator = new MessageSenderCreator(_logger, useLegacySenders); this._vhostName = vhost; this.useLegacySenders = useLegacySenders; this._consumers = new List <RmqConsumer>(); }
protected internal override void Apply(IManagementClient managementClient) { _log.Info($"Declaring queue '{Name}' on '{VirtualHost}'"); _log.Info($" AutoDelete = {AutoDelete}"); _log.Info($" Durable = {Durable}"); var vhost = managementClient.GetVhost(VirtualHost); var arguments = new InputArguments(); var queueInfo = new QueueInfo(Name, AutoDelete, Durable, arguments); if (MessageTTLDeclared) { _log.Info($" MessageTTL = {MessageTTL}"); arguments.Add("x-message-ttl", (long)MessageTTL.Value.TotalMilliseconds); } if (AutoExpireDeclared) { _log.Info($" AutoExpire = {AutoExpire}"); arguments.Add("x-expires", (long)AutoExpire.Value.TotalMilliseconds); } if (MaxLengthDeclared) { _log.Info($" MaxLength = {MaxLength}"); arguments.Add("x-max-length", MaxLength.Value); } if (MaxLengthBytesDeclared) { _log.Info($" MaxLengthBytes = {MaxLengthBytes}"); arguments.Add("x-max-length-bytes", MaxLengthBytes.Value); } if (DLXDeclared) { _log.Info($" DeadLetterExchange = {DeadLetterExchange}"); arguments.Add("x-dead-letter-exchange", DeadLetterExchange); } if (DLXRoutingKeyDeclared) { _log.Info($" DeadLetterRoutingKey = {DeadLetterRoutingKey}"); arguments.Add("x-dead-letter-routing-key", DeadLetterRoutingKey); } if (MaxPriorityDeclared) { _log.Info($" MaxPriority = {MaximumPriority}"); arguments.Add("x-max-priority", MaximumPriority.Value); } managementClient.CreateQueue(queueInfo, vhost); _log.Info($"Finished declaring queue '{Name}' on '{VirtualHost}'"); }
public CheckResult RunCheck(IManagementClient managementClient) { var overview = managementClient.GetOverview(); var alert = overview.ObjectTotals.Connections >= alertConnectionCount; var message = alert ? string.Format( "broker {0} connections have exceeded alert level {1}. Now {2}", managementClient.HostUrl, alertConnectionCount, overview.ObjectTotals.Connections) : ""; return new CheckResult(alert, message); }
/// <summary> /// A list of all queues for a virtual host. /// </summary> /// <param name="source"></param> /// <param name="vhost"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static IReadOnlyList <Queue> GetQueues( [NotNull] this IManagementClient source, Vhost vhost, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.GetQueuesAsync(vhost, cancellationToken) .GetAwaiter() .GetResult()); }
/// <summary> /// A list of all open connections. /// </summary> /// <param name="source"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public static IReadOnlyList <Connection> GetConnections( [NotNull] this IManagementClient source, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.GetConnectionsAsync(cancellationToken) .GetAwaiter() .GetResult()); }
/// <summary> /// Delete a topic permission /// </summary> /// <param name="source"></param> /// <param name="permission">The topic permission to delete</param> /// <param name="cancellationToken"></param> public static void DeleteTopicPermission( [NotNull] this IManagementClient source, [NotNull] TopicPermission permission, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } source.DeleteTopicPermissionAsync(permission, cancellationToken) .GetAwaiter() .GetResult(); }
private Queue GetErrorQueue(IManagementClient managementClient, Vhost vhost) { try { return managementClient.GetQueue(easyNetQErrorQueue, vhost); } catch (UnexpectedHttpStatusCodeException exception) { if (exception.StatusCode == HttpStatusCode.NotFound) { return new Queue { Messages = 0 }; } throw; } }
/// <summary> /// Declares a test queue, then publishes and consumes a message. Intended for use /// by monitoring tools. If everything is working correctly, will return true. /// Note: the test queue will not be deleted (to to prevent queue churn if this /// is repeatedly pinged). /// </summary> /// <param name="source"></param> /// <param name="vhost"></param> /// <param name="cancellationToken"></param> public static bool IsAlive( [NotNull] this IManagementClient source, [NotNull] Vhost vhost, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.IsAliveAsync(vhost, cancellationToken) .GetAwaiter() .GetResult()); }
public CheckResult RunCheck(IManagementClient managementClient) { var queues = managementClient.GetQueues(); var alertQueues = from queue in queues where queue.messages >= alertIndividualQueueMessagesCount select string.Format("{0} on {1} with {2} messages", queue.name, queue.vhost, queue.messages); var message = string.Format(alertMessage, managementClient.HostUrl, string.Join(", ", alertQueues), alertIndividualQueueMessagesCount ); return new CheckResult(alertQueues.Any(), message); }
private static CheckResult RunCheckInExceptionHandler(ICheck check, IManagementClient managementClient) { try { return check.RunCheck(managementClient); } catch (UnexpectedHttpStatusCodeException exception) { return new CheckResult(true, string.Format("Check '{0}' got unexpected status code {1} {2}", check.GetType().ToString(), exception.StatusCodeNumber, exception.StatusCode )); } catch (Exception exception) { return new CheckResult(true, exception.ToString()); } }
public RabbitMQTopologyWriter(IManagementClient client, Vhost virtualHost) { this.client = client; this.virtualHost = virtualHost; }
public void SetUp() { ManagementClient = MockRepository.GenerateStub<IManagementClient>(); ManagementClient.Stub(x => x.HostUrl).Return(BrokerUrl); DoSetUp(); }
internal AzureAffinityGroupManager() { ManagementClient = new ManagementClient(Dependencies.Subscription.Credentials, new Uri(Dependencies.Subscription.CoreEndpointUrl)); }
public void SetUp() { managementClient = new ManagementClient(hostUrl, username, password); }