public IActionResult GetControllerInfoDto() { AssertTrackRequestSource(Request.HttpContext.Connection); ControllerInfoDto dto = new ControllerInfoDto(); dto.FullName = _sutController.GetType().FullName; dto.IsInstrumentationOn = _sutController.IsInstrumentationActivated(); return(Ok(WrappedResponseDto <ControllerInfoDto> .WithData(dto))); }
public IActionResult GetTestResults([FromQuery] string ids) { //java version: List<AdditionalInfo> additionalInfos = noKillSwitch(() -> sutController.getAdditionalInfoList()); IList <AdditionalInfo> additionalInfos = _sutController.GetAdditionalInfoList(); //Fake data here var dto = new TestResultsDto { AdditionalInfoList = Enumerable.Repeat(new AdditionalInfoDto { LastExecutedStatement = "\"TODO: LastExecutedStatement\"" }, additionalInfos.Count).ToList() }; return(Ok(WrappedResponseDto <TestResultsDto> .WithData(dto))); }
public IActionResult GetSutInfo() { string connectionHeader = Request.Headers["Connection"]; if (connectionHeader == null || !connectionHeader.Equals("keep-alive", StringComparison.OrdinalIgnoreCase)) { return(BadRequest( WrappedResponseDto <string> .WithError("Requests should always contain a 'Connection: keep-alive'"))); } AssertTrackRequestSource(Request.HttpContext.Connection); //TODO: uncomment after implementing VerifySqlConnection method // if (!_sutController.VerifySqlConnection ()) { // string msg = "SQL drivers are misconfigured. You must use a 'p6spy' wrapper when you " + // "run the SUT. For example, a database connection URL like 'jdbc:h2:mem:testdb' " + // "should be changed into 'jdbc:p6spy:h2:mem:testdb'. " + // "See documentation on how to configure P6Spy."; // SimpleLogger.Error (msg); // return StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto<string>.WithError(msg)); // } SutInfoDto dto = new SutInfoDto(); dto.IsSutRunning = _sutController.IsSutRunning(); dto.BaseUrlOfSUT = _baseUrlOfSut; dto.InfoForAuthentication = _sutController.GetInfoForAuthentication(); //TODO: uncomment //dto.SqlSchemaDto = _sutController.GetSqlDatabaseSchema (); dto.DefaultOutputFormat = _sutController.GetPreferredOutputFormat(); IProblemInfo info = _sutController.GetProblemInfo(); if (info == null) { string msg = "Undefined problem type in the EM Controller"; SimpleLogger.Error(msg); return(StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto <string> .WithError(msg))); } else if (info is RestProblem) { RestProblem rp = (RestProblem)info; dto.RestProblem = new RestProblemDto(); dto.RestProblem.OpenApiUrl = rp.GetSwaggerJsonUrl(); dto.RestProblem.EndpointsToSkip = rp.GetEndpointsToSkip(); } else { string msg = "Unrecognized problem type: " + info.GetType().FullName; SimpleLogger.Error(msg); return(StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto <string> .WithError(msg))); } dto.UnitsInfoDto = _sutController.GetUnitsInfoDto(); if (dto.UnitsInfoDto == null) { string msg = "Failed to extract units info"; SimpleLogger.Error(msg); return(StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto <string> .WithError(msg))); } return(Ok(WrappedResponseDto <SutInfoDto> .WithData(dto))); }
public IActionResult RunSut([FromBody] SutRunDto dto) { AssertTrackRequestSource(Request.HttpContext.Connection); if (dto == null || !dto.Run.HasValue) { string errorMessage = "Invalid JSON: 'run' field is required"; SimpleLogger.Warn(errorMessage); return(BadRequest(WrappedResponseDto <string> .WithError(errorMessage))); } bool sqlHeuristics = dto.CalculateSqlHeuristics != null && dto.CalculateSqlHeuristics.Value; bool sqlExecution = dto.ExtractSqlExecutionInfo != null && dto.ExtractSqlExecutionInfo.Value; //TODO: uncomment // _sutController.EnableComputeSqlHeuristicsOrExtractExecution (sqlHeuristics, sqlExecution); bool doReset = dto.ResetState != null && dto.ResetState.Value; lock (_lock) { if (dto.Run.HasValue && !dto.Run.Value) { if (doReset) { string errorMessage = "Invalid JSON: cannot reset state and stop service at same time"; SimpleLogger.Warn(errorMessage); return(BadRequest(WrappedResponseDto <string> .WithError(errorMessage))); } //if on, we want to shut down the server if (_sutController.IsSutRunning()) { _sutController.StopSut(); _baseUrlOfSut = null; } } else { /* * If SUT is not up and running, let's start it */ if (!_sutController.IsSutRunning()) { _baseUrlOfSut = _sutController.StartSut(); if (_baseUrlOfSut == null) { //there has been an internal failure in starting the SUT String msg = "Internal failure: cannot start SUT based on given configuration"; SimpleLogger.Warn(msg); return(StatusCode(StatusCodes.Status500InternalServerError, WrappedResponseDto <string> .WithError(msg))); } //TODO: uncomment // _sutController.InitSqlHandler (); } else { //TODO as starting should be blocking, need to check //if initialized, and wait if not } /* * regardless of where it was running or not, need to reset state. * this is controlled by a boolean, although most likely we ll always * want to do it */ if (dto.ResetState.HasValue && dto.ResetState.Value) { try { /* * This should not fail... but, as it is user code, it might fail... * When it does, it is a major issue, as it can leave the system in * an inconsistent state for the following fitness evaluations. * So, we always force a newTest, even when reset fails. * * TODO: a current problem is in Proxyprint, in which after REST calls * it seems there are locks on the DB (this might happen if a transaction * is started but then not committed). Ideally, in the reset of DBs we should * force all lock releases, and possibly point any left lock as a potential bug */ _sutController.ResetStateOfSut(); } finally { _sutController.NewTest(); } } /* * Note: here even if we start the SUT, the starting of a "New Search" * cannot be done here, as in this endpoint we also deal with the reset * of state. When we reset state for a new test run, we do not want to * reset all the other data regarding the whole search */ } return(StatusCode(StatusCodes.Status204NoContent)); } }