public void should_use_token() { var token = "test token"; var config = new ConsulRegistryConfiguration(_consulScheme, _consulHost, _port, _serviceName, token); _provider = new Consul(config, _factory.Object, _clientFactory); var serviceEntryOne = new ServiceEntry() { Service = new AgentService() { Service = _serviceName, Address = "localhost", Port = 50881, ID = Guid.NewGuid().ToString(), Tags = new string[0], }, }; this.Given(_ => GivenThereIsAFakeConsulServiceDiscoveryProvider(_fakeConsulServiceDiscoveryUrl, _serviceName)) .And(_ => GivenTheServicesAreRegisteredWithConsul(serviceEntryOne)) .When(_ => WhenIGetTheServices()) .Then(_ => ThenTheCountIs(1)) .And(_ => ThenTheTokenIs(token)) .BDDfy(); }
public void Resolver_ReturnsBaseUri_ForUnregisteredType() { var baseUri = "http://testuri/"; var expected = baseUri.CombineWith("/json/reply/ConsulTests.TestDTO"); plugin.Settings.AddServiceDiscovery(new TestServiceDiscovery()); Consul.ResolveTypedUrl(new JsonServiceClient(baseUri), null, new TestDTO()).Should().Be(expected); }
public void Resolver_ReturnsRegisteredType_ByName(string method, string expected) { var discovery = new TestServiceDiscovery(); var remoteuri = "http://remoteUri:1234/"; discovery.DtoTypes.Add(typeof(TestDTO2), remoteuri); plugin.Settings.AddServiceDiscovery(discovery); Consul.ResolveTypedUrl(new JsonServiceClient("http://localhost"), method, new TestDTO2()).Should().Be(remoteuri.CombineWith(expected)); }
/// <summary> /// Releases all associated resources. /// </summary> /// <param name="disposing">Pass <c>true</c> if we're disposing, <c>false</c> if we're finalizing.</param> protected virtual void Dispose(bool disposing) { if (disposing) { Consul.Dispose(); Vault.Dispose(); Headend.Dispose(); GC.SuppressFinalize(this); } }
public void Resolver_ReturnsDefaultRoute_ByDTOTypeName() { var remoteuri = "http://remoteuri:1234/api/"; var expected = remoteuri.CombineWith("/json/reply/ConsulTests.TestDTO"); var discovery = new TestServiceDiscovery(); discovery.DtoTypes.Add(typeof(TestDTO), remoteuri); plugin.Settings.AddServiceDiscovery(discovery); Consul.ResolveTypedUrl(new JsonServiceClient("http://localhost/"), "GET", new TestDTO()).Should().Be(expected); }
public void Set(Consul save) { var obj = this.List.FirstOrDefault(o => o.Key == save.Key); if (obj != null) { List.Remove(obj); } this.SaveChanges(); List.Add(save); this.SaveChanges(); }
public ConsulServiceDiscoveryProviderTests() { _serviceName = "test"; _port = 8500; _consulHost = "localhost"; _fakeConsulServiceDiscoveryUrl = $"http://{_consulHost}:{_port}"; _serviceEntries = new List <ServiceEntry>(); _factory = new Mock <IOcelotLoggerFactory>(); _clientFactory = new ConsulClientFactory(); _logger = new Mock <IOcelotLogger>(); _factory.Setup(x => x.CreateLogger <Consul>()).Returns(_logger.Object); _factory.Setup(x => x.CreateLogger <PollConsul>()).Returns(_logger.Object); var config = new ConsulRegistryConfiguration(_consulHost, _port, _serviceName, null); _provider = new Consul(config, _factory.Object, _clientFactory); }
public void Resolver_ReturnsNull_ForUnregisteredType() { plugin.Settings.AddServiceDiscovery(new TestServiceDiscovery()); Consul.ResolveTypedUrl(null, null, new TestDTO()).Should().BeNull(); }
public void Validate() { Provisioner = Provisioner ?? defaultProvisioner; DrivePrefix = DrivePrefix ?? defaultDrivePrefix; Setup = Setup ?? new SetupOptions(); Hosting = Hosting ?? new HostingOptions(); Vpn = Vpn ?? new VpnOptions(); HiveNode = HiveNode ?? new HiveNodeOptions(); Docker = Docker ?? new DockerOptions(); Image = Image ?? new ImageOptions(); Network = Network ?? new NetworkOptions(); Consul = Consul ?? new ConsulOptions(); Vault = Vault ?? new VaultOptions(); Log = Log ?? new LogOptions(); Dashboard = Dashboard ?? new DashboardOptions(); HiveFS = HiveFS ?? new HiveFSOptions(); Proxy = Proxy ?? new ProxyOptions(); HiveMQ = HiveMQ ?? new HiveMQOptions(); Setup.Validate(this); Network.Validate(this); Hosting.Validate(this); Vpn.Validate(this); HiveNode.Validate(this); Docker.Validate(this); Image.Validate(this); Consul.Validate(this); Vault.Validate(this); Log.Validate(this); Dashboard.Validate(this); HiveFS.Validate(this); Proxy.Validate(this); HiveMQ.Validate(this); new HostingManagerFactory().Validate(this); if (TimeSources == null || TimeSources.Length == 0 || TimeSources.Count(ts => string.IsNullOrWhiteSpace(ts)) > 0) { TimeSources = new string[] { "pool.ntp.org" }; } if (NodeDefinitions == null || NodeDefinitions.Count == 0) { throw new HiveDefinitionException("At least one hive node must be defined."); } foreach (var node in NodeDefinitions.Values) { node.Validate(this); } if (Name == null) { throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Name)}] property is required."); } if (!IsValidName(Name)) { throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Name)}={Name}] property is not valid. Only letters, numbers, periods, dashes, and underscores are allowed."); } if (Datacenter == null) { throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Datacenter)}] property is required."); } if (!IsValidName(Datacenter)) { throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Datacenter)}={Datacenter}] property is not valid. Only letters, numbers, periods, dashes, and underscores are allowed."); } if (!string.IsNullOrEmpty(PackageProxy)) { var packageCacheUris = PackageProxy.Split(','); for (int i = 0; i < packageCacheUris.Length; i++) { packageCacheUris[i] = packageCacheUris[i].Trim(); if (!Uri.TryCreate(packageCacheUris[i], UriKind.Absolute, out var aptProxyUri)) { throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(PackageProxy)}={PackageProxy}] includes [{packageCacheUris[i]}] which is not a valid URI."); } if (aptProxyUri.Scheme != "http") { throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(PackageProxy)}={PackageProxy}] includes [{packageCacheUris[i]}] which does not have the [http] scheme."); } } } var managementNodeCount = Managers.Count(); if (managementNodeCount == 0) { throw new HiveDefinitionException("Hives must have at least one management node."); } else if (managementNodeCount > 5) { throw new HiveDefinitionException("Hives may not have more than [5] management nodes."); } else if (!NeonHelper.IsOdd(managementNodeCount)) { throw new HiveDefinitionException("Hives must have an odd number of management nodes: [1, 3, or 5]"); } // Ensure that each node has a valid unique or NULL IP address. NetworkCidr nodesSubnet = null; NetworkCidr vpnPoolSubnet = null; if (Network.NodesSubnet != null) { nodesSubnet = NetworkCidr.Parse(Network.NodesSubnet); } if (Vpn.Enabled) { vpnPoolSubnet = NetworkCidr.Parse(Network.VpnPoolSubnet); } var addressToNode = new Dictionary <string, NodeDefinition>(); foreach (var node in SortedNodes) { if (node.PrivateAddress != null) { NodeDefinition conflictNode; if (addressToNode.TryGetValue(node.PrivateAddress, out conflictNode)) { throw new HiveDefinitionException($"Node [name={node.Name}] has invalid private IP address [{node.PrivateAddress}] that conflicts with node [name={conflictNode.Name}]."); } } } foreach (var node in SortedNodes) { if (node.PrivateAddress != null) { if (!IPAddress.TryParse(node.PrivateAddress, out var address)) { throw new HiveDefinitionException($"Node [name={node.Name}] has invalid private IP address [{node.PrivateAddress}]."); } if (vpnPoolSubnet != null && vpnPoolSubnet.Contains(address)) { throw new HiveDefinitionException($"Node [name={node.Name}] has private IP address [{node.PrivateAddress}] within the hosting [{nameof(Network.VpnPoolSubnet)}={Network.VpnPoolSubnet}]."); } if (nodesSubnet != null && !nodesSubnet.Contains(address)) { throw new HiveDefinitionException($"Node [name={node.Name}] has private IP address [{node.PrivateAddress}] that is not within the hosting [{nameof(Network.NodesSubnet)}={Network.NodesSubnet}]."); } } else if (!Hosting.IsCloudProvider) { throw new HiveDefinitionException($"Node [name={node.Name}] is not assigned a private IP address. This is required when deploying to a [{nameof(Environment)}={Environment}] hosting environment."); } } // Verify that we have nodes identified for persisting log data if logging is enabled. if (Log.Enabled) { if (Nodes.Where(n => n.Labels.LogEsData).Count() == 0) { throw new HiveDefinitionException($"At least one node must be configured to store log data by setting [{nameof(NodeDefinition.Labels)}.{nameof(NodeLabels.LogEsData)}=true] when hive logging is enabled."); } } }
public void Dispose() { Consul.Dispose(); Source.Dispose(); RefreshCacheTask.Dispose(); }