Commit d69a576e authored by bow's avatar bow
Browse files

Add simple logging to endpoints

parent 956d424d
......@@ -41,11 +41,13 @@ class AnnotationsController(implicit val swagger: Swagger, mongo: MongodbAccessO
protected val annots = new AnnotationsAdapter { val mongo = self.mongo }
options("/?") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
options("/:annotId") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
......@@ -58,6 +60,7 @@ class AnnotationsController(implicit val swagger: Swagger, mongo: MongodbAccessO
// format: ON
get("/:annotId", operation(annotationsRefIdGetOperation)) {
logger.info(requestLog)
val errMsg = ApiMessage("Annotation ID can not be found.")
val annotId = params("annotId")
.getObjectId
......@@ -74,6 +77,7 @@ class AnnotationsController(implicit val swagger: Swagger, mongo: MongodbAccessO
// format: ON
get("/", operation(annotationsGetOperation)) {
logger.info(requestLog)
annots.getAnnotations()
}
}
......@@ -41,11 +41,13 @@ class ReferencesController(implicit val swagger: Swagger, mongo: MongodbAccessOb
protected val refs = new ReferencesAdapter { val mongo = self.mongo }
options("/?") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
options("/:refId") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
......@@ -58,6 +60,7 @@ class ReferencesController(implicit val swagger: Swagger, mongo: MongodbAccessOb
// format: ON
get("/:refId", operation(referencesRefIdGetOperation)) {
logger.info(requestLog)
val errMsg = ApiMessage("Reference ID can not be found.")
val refId = params("refId")
.getObjectId
......@@ -74,6 +77,7 @@ class ReferencesController(implicit val swagger: Swagger, mongo: MongodbAccessOb
// format: ON
get("/", operation(referencesGetOperation)) {
logger.info(requestLog)
refs.getReferences()
}
}
......@@ -75,11 +75,13 @@ class RunsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
}
options("/?") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD,POST")
}
options("/:runId") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "DELETE,GET,HEAD")
}
......@@ -106,6 +108,7 @@ class RunsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// format: ON
delete("/:runId", operation(runsRunIdDeleteOperation)) {
logger.info(requestLog)
val runId = params("runId")
.getObjectId
.getOrElse(halt(404, CommonMessages.MissingRunId))
......@@ -147,6 +150,7 @@ class RunsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// format: ON
get("/:runId", operation(runsRunIdGetOperation)) {
logger.info(requestLog)
val doDownload = params.getAs[Boolean]("download").getOrElse(false)
val runId = params("runId")
.getObjectId
......@@ -192,6 +196,7 @@ class RunsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// format: ON
post("/", operation(runsPostOperation)) {
logger.info(requestLog)
val pipeline = params.getOrElse("pipeline", halt(400, CommonMessages.UnspecifiedPipeline))
val uploadedRun = fileParams.getOrElse("run", halt(400, ApiMessage("Run summary file not specified.")))
......@@ -245,6 +250,7 @@ class RunsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// format: ON
get("/", operation(runsGetOperation)) {
logger.info(requestLog)
val pipelines = splitParam(params.getAs[String]("pipelines"))
val (validPipelines, invalidPipelines) = pipelines.partition { AllowedPipelineParams.contains }
......
......@@ -16,11 +16,14 @@
*/
package nl.lumc.sasc.sentinel.api
import javax.servlet.http.HttpServletRequest
import org.bson.types.ObjectId
import org.json4s._
import org.scalatra.{ CorsSupport, NotFound, ScalatraServlet }
import org.scalatra.json.JacksonJsonSupport
import org.scalatra.swagger.{ DataType, Model, SwaggerSupport }
import org.slf4j.LoggerFactory
import nl.lumc.sasc.sentinel.models.ApiMessage
import nl.lumc.sasc.sentinel.utils.{ SentinelJsonFormats, separateObjectIds, splitParam }
......@@ -31,6 +34,15 @@ abstract class SentinelServlet extends ScalatraServlet
with JacksonJsonSupport
with SwaggerSupport {
/** Logger instance. */
protected val logger = LoggerFactory.getLogger(getClass)
/** Default log string and helper methods for log string. */
protected def reqUri(implicit req: HttpServletRequest): String = req.getRequestURI
protected def reqMethod(implicit req: HttpServletRequest): String = req.getMethod
protected def reqAddress(implicit req: HttpServletRequest): String = req.getRemoteAddr
protected def requestLog: String = s"$reqAddress $reqMethod $reqUri"
override def render(value: JValue)(implicit formats: Formats = DefaultFormats): JValue =
formats.emptyValueStrategy.replaceEmpty(value)
......
......@@ -57,21 +57,25 @@ class StatsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
protected val users = new UsersAdapter { val mongo = self.mongo }
options("/runs") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
options("/gentrap/alignments") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
options("/gentrap/alignments/aggregate") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
options("/gentrap/sequences") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD")
}
......@@ -87,6 +91,7 @@ class StatsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// format: ON
get("/runs", operation(statsRunsGetOperation)) {
logger.info(requestLog)
Ok(runs.getGlobalRunStats())
}
......@@ -141,6 +146,7 @@ class StatsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
get("/gentrap/alignments", operation(statsGentrapAlignmentsGetOperation)) {
logger.info(requestLog)
val runIds = getRunObjectIds(params.getAs[String]("runIds"))
val refIds = getRefObjectIds(params.getAs[String]("refIds"))
val annotIds = getAnnotObjectIds(params.getAs[String]("annotIds"))
......@@ -214,6 +220,7 @@ class StatsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
get("/gentrap/alignments/aggregate", operation(statsGentrapAlignmentsAggregateGetOperation)) {
logger.info(requestLog)
val runIds = getRunObjectIds(params.getAs[String]("runIds"))
val refIds = getRefObjectIds(params.getAs[String]("refIds"))
val annotIds = getAnnotObjectIds(params.getAs[String]("annotIds"))
......@@ -293,6 +300,7 @@ class StatsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
get("/gentrap/sequences", operation(statsGentrapSequencesGetOperation)) {
logger.info(requestLog)
val runIds = getRunObjectIds(params.getAs[String]("runIds"))
val refIds = getRefObjectIds(params.getAs[String]("refIds"))
val annotIds = getAnnotObjectIds(params.getAs[String]("annotIds"))
......@@ -357,6 +365,7 @@ class StatsController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
get("/gentrap/sequences/aggregate", operation(statsGentrapSequencesAggregateGetOperation)) {
logger.info(requestLog)
val runIds = getRunObjectIds(params.getAs[String]("runIds"))
val refIds = getRefObjectIds(params.getAs[String]("refIds"))
val annotIds = getAnnotObjectIds(params.getAs[String]("annotIds"))
......
......@@ -51,11 +51,13 @@ class UsersController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
val patchValidator = new ValidationAdapter { override val validator = createValidator("/schemas/json_patch.json") }
options("/?") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "HEAD,POST")
}
options("/:userRecordId") {
logger.info(requestLog)
response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"))
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD,PATCH")
response.setHeader("Accept-Patch", formats("json"))
......@@ -88,6 +90,7 @@ class UsersController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// TODO: refactor this endpoint ~ use less explicit halts
logger.info(requestLog)
// validate and load patch operations ~ based on the JSON patch spec *not* our own requirements (yet)
val patchOps = Try(patchValidator.parseAndValidate(request.body.getBytes)) match {
......@@ -154,6 +157,7 @@ class UsersController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// format: ON
get("/:userRecordId", operation(usersUserIdGetOperation)) {
logger.info(requestLog)
val userRecordId = params("userRecordId")
val user = simpleKeyAuth(params => params.get("userId"))
if (user.isAdmin || user.id == userRecordId) {
......@@ -185,6 +189,7 @@ class UsersController(implicit val swagger: Swagger, mongo: MongodbAccessObject)
// format: OFF
post("/", operation(usersUserIdPostOperation)) {
logger.info(requestLog)
val userRequest = parsedBody.extractOrElse[UserRequest](halt(400, ApiMessage("Malformed user request.")))
if (userRequest.validationMessages.size > 0)
......
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%msg%n</pattern>
</encoder>
</appender>
<root level="OFF">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment