| | |
| | | /// 获取所有实例列表 |
| | | /// </summary> |
| | | [HttpGet] |
| | | [ProducesResponseType(typeof(IEnumerable<InstanceState>), StatusCodes.Status200OK)] |
| | | public ActionResult<IEnumerable<InstanceState>> GetAllInstances() |
| | | [ProducesResponseType(typeof(IEnumerable<object>), StatusCodes.Status200OK)] |
| | | public ActionResult GetAllInstances() |
| | | { |
| | | try |
| | | { |
| | | var instances = _instanceManager.GetAllInstances(); |
| | | var states = instances.Select(i => i.GetState()).ToList(); |
| | | return Ok(states); |
| | | var result = instances.Select(i => new |
| | | { |
| | | instanceId = i.Config.Id, |
| | | name = i.Config.Name, |
| | | plcType = i.Config.PLCType.ToString(), |
| | | port = i.Config.Port, |
| | | status = i.GetState().Status.ToString(), |
| | | clientCount = i.GetState().ClientCount, |
| | | totalRequests = i.GetState().TotalRequests, |
| | | startTime = i.GetState().StartTime, |
| | | lastActivityTime = i.GetState().LastActivityTime, |
| | | errorMessage = i.GetState().ErrorMessage |
| | | }).ToList(); |
| | | return Ok(result); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取指定实例的配置 |
| | | /// </summary> |
| | | [HttpGet("{id}/config")] |
| | | [ProducesResponseType(typeof(InstanceConfig), StatusCodes.Status200OK)] |
| | | [ProducesResponseType(StatusCodes.Status404NotFound)] |
| | | public ActionResult<InstanceConfig> GetInstanceConfig(string id) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrWhiteSpace(id)) |
| | | { |
| | | return BadRequest(new { error = "Instance ID is required" }); |
| | | } |
| | | |
| | | var instance = _instanceManager.GetInstance(id); |
| | | if (instance == null) |
| | | { |
| | | return NotFound(new { error = $"Instance with ID '{id}' not found" }); |
| | | } |
| | | |
| | | return Ok(instance.Config); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError(ex, "Failed to get instance config {InstanceId}", id); |
| | | return StatusCode(StatusCodes.Status500InternalServerError, new { error = "Failed to retrieve instance config" }); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新实例配置 |
| | | /// </summary> |
| | | [HttpPut("{id}")] |