public async Task <MicrowaveServiceNode> GetDependantServices(Uri serviceAddress) { var client = await _factory.GetClient(serviceAddress); try { var response = await client.GetAsync("Dicovery/ServiceDependencies"); _logger.LogTrace($"Response for Servicedependencies was {response.StatusCode}"); if (!response.IsSuccessStatusCode) { return(MicrowaveServiceNode.UnreachableMicrowaveServiceNode(new ServiceEndPoint(serviceAddress), new List <ServiceEndPoint>())); } var content = await response.Content.ReadAsStringAsync(); var remoteNode = JsonConvert.DeserializeObject <MicrowaveServiceNodeDto>(content); var newNode = MicrowaveServiceNode.ReachableMicrowaveServiceNode( new ServiceEndPoint(serviceAddress, remoteNode.ServiceEndPoint.Name), remoteNode.ConnectedServices); return(newNode); } catch (HttpRequestException) { return(MicrowaveServiceNode.UnreachableMicrowaveServiceNode(new ServiceEndPoint(serviceAddress), new List <ServiceEndPoint>())); } }
public async Task <ServiceMap> GetServiceMap() { var mongoCollection = _database.GetCollection <ServiceMapDbo>(StatusDbName); var mapDbo = await mongoCollection.FindSync(e => e.Id == nameof(ServiceMap)).SingleOrDefaultAsync(); var services = mapDbo?.Services.Select(s => s.IsReachable ? MicrowaveServiceNode.ReachableMicrowaveServiceNode(s.ServiceEndPoint, s.Services) : MicrowaveServiceNode.UnreachableMicrowaveServiceNode(s.ServiceEndPoint, s.Services)); return(mapDbo == null ? null : new ServiceMap(services)); }
public async Task SaveAndLoadServiceMap(PersistenceLayerProvider layerProvider) { var statusRepository = layerProvider.StatusRepository; var map = new ServiceMap(new List <MicrowaveServiceNode> { MicrowaveServiceNode.ReachableMicrowaveServiceNode(new ServiceEndPoint(new Uri("http://123.de"), "Name"), new List <ServiceEndPoint> { new ServiceEndPoint(new Uri("http://www.uri1.de"), "Name") }), MicrowaveServiceNode.ReachableMicrowaveServiceNode(new ServiceEndPoint(new Uri("http://123.de"), "Name2"), new List <ServiceEndPoint> { new ServiceEndPoint(new Uri("http://www.uri2.de"), "Name2"), new ServiceEndPoint(new Uri("http://www.uri1.de"), "Name") }), MicrowaveServiceNode.UnreachableMicrowaveServiceNode(new ServiceEndPoint(new Uri("http://123.de")), new List <ServiceEndPoint>()) }); await statusRepository.SaveServiceMap(map); var mapLoaded = await statusRepository.GetServiceMap(); var serviceDependenciesDtos = mapLoaded.AllServices.ToList(); Assert.AreEqual("Name", serviceDependenciesDtos[0].ServiceEndPoint.Name); Assert.AreEqual("Name2", serviceDependenciesDtos[1].ServiceEndPoint.Name); Assert.IsTrue(serviceDependenciesDtos[1].IsReachable); Assert.IsFalse(serviceDependenciesDtos[2].IsReachable); Assert.AreEqual(new Uri("http://www.uri1.de"), serviceDependenciesDtos[0].ConnectedServices.First().ServiceBaseAddress); Assert.AreEqual(new Uri("http://www.uri2.de"), serviceDependenciesDtos[1].ConnectedServices.First().ServiceBaseAddress); Assert.AreEqual(new Uri("http://www.uri1.de"), serviceDependenciesDtos[1].ConnectedServices.Skip(1).First().ServiceBaseAddress); Assert.AreEqual("Name", serviceDependenciesDtos[0].ConnectedServices.First().Name); Assert.AreEqual("Name2", serviceDependenciesDtos[1].ConnectedServices.First().Name); Assert.AreEqual("Name", serviceDependenciesDtos[1].ConnectedServices.Skip(1).First().Name); }