Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] ResumeStatus resumeStatus)
        {
            if (id != resumeStatus.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(resumeStatus);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ResumeStatusExists(resumeStatus.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(resumeStatus));
        }
Пример #2
0
        public async Task <IActionResult> Resume([FromServices] IScriptHostManager scriptHostManager)
        {
            try
            {
                await _resumeSemaphore.WaitAsync();

                ScriptHostState currentState = scriptHostManager.State;

                _logger.LogDebug($"Received request to resume a draining host - host status: {currentState.ToString()}");

                if (currentState != ScriptHostState.Running ||
                    !Utility.TryGetHostService(scriptHostManager, out IDrainModeManager drainModeManager))
                {
                    _logger.LogDebug("The host is not in a state where we can resume.");
                    return(StatusCode(StatusCodes.Status409Conflict));
                }

                _logger.LogDebug($"Drain mode enabled: {drainModeManager.IsDrainModeEnabled}");

                if (drainModeManager.IsDrainModeEnabled)
                {
                    _logger.LogDebug("Starting a new host");
                    await scriptHostManager.RestartHostAsync();
                }

                var status = new ResumeStatus {
                    State = scriptHostManager.State
                };
                return(Ok(status));
            }
            finally
            {
                _resumeSemaphore.Release();
            }
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] ResumeStatus resumeStatus)
        {
            if (ModelState.IsValid)
            {
                _context.Add(resumeStatus);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(resumeStatus));
        }
Пример #4
0
        public async Task ResumeHost_HostRunning_DrainModeNotEnabled_DoesNotStartNewHost_ReturnHostStatus()
        {
            var scriptHostManagerMock = new Mock <IScriptHostManager>(MockBehavior.Strict);
            var serviceProviderMock   = scriptHostManagerMock.As <IServiceProvider>();
            var drainModeManager      = new Mock <IDrainModeManager>(MockBehavior.Strict);

            serviceProviderMock.Setup(x => x.GetService(typeof(IDrainModeManager))).Returns(drainModeManager.Object);
            scriptHostManagerMock.SetupGet(p => p.State).Returns(ScriptHostState.Running);
            drainModeManager.Setup(x => x.IsDrainModeEnabled).Returns(false);

            var expectedBody = new ResumeStatus {
                State = ScriptHostState.Running
            };
            var result = (OkObjectResult)await _hostController.Resume(scriptHostManagerMock.Object);

            Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
            Assert.Equal(expectedBody.State, (result.Value as ResumeStatus).State);
            scriptHostManagerMock.Verify(p => p.RestartHostAsync(It.IsAny <CancellationToken>()), Times.Never());
        }