Beispiel #1
0
        public async Task ShouldReturnAllNodesInfoWhenGetNodesCalled()
        {
            //Given
            _swarmClient.GetNodes().Returns(x => {
                return(Task.FromResult <IEnumerable <NodeListResponse> >(new [] { _any.Create <NodeListResponse>(), _any.Create <NodeListResponse>() }));
            });
            var nodeService    = new NodeService(_swarmClient, _loggerFactory);
            var nodeController = new NodeController(nodeService);

            //When
            var response = await nodeController.GetNode(null, SwarmRole.Unknown);

            var jsonResult = response as JsonResult;
            var value      = jsonResult?.Value as IEnumerable <NodeListResponse>;

            //Then
            Assert.NotNull(jsonResult);
            Assert.NotNull(value);
            Assert.Equal(200, jsonResult.StatusCode);
            Assert.Equal(2, value.Count());
        }
Beispiel #2
0
        public async Task <IActionResult> GetNodeAsync(NodeFilterParameters filterParameters)
        {
            try
            {
                var nodes = await _swarmClient.GetNodes();

                if (filterParameters.Hostname.IsNotNullOrEmpty())
                {
                    nodes = nodes.Where(t => t.Description.Hostname == filterParameters.Hostname);
                }
                if (filterParameters.Role != SwarmRole.Unknown)
                {
                    nodes = nodes.Where(t => t.Spec.Role.Equals(filterParameters.Role.ToString(), StringComparison.OrdinalIgnoreCase));
                }
                _logger.LogInformation("Fetch swarm nodes.");
                return(Json(nodes.ToArray()));
            }
            catch (Exception ex)
            {
                return(CreateErrorResponse(ex, "Cannot fetch information about nodes."));
            }
        }