View Javadoc
1   /*
2    * The coLAB project
3    * Copyright (C) 2021-2023 AlbaSim, MEI, HEIG-VD, HES-SO
4    *
5    * Licensed under the MIT License
6    */
7   package ch.colabproject.colab.api.rest.monitoring;
8   
9   import ch.colabproject.colab.api.controller.monitoring.LevelDescriptor;
10  import ch.colabproject.colab.api.controller.monitoring.MonitoringManager;
11  import ch.colabproject.colab.api.controller.monitoring.VersionDetails;
12  import ch.colabproject.colab.generator.model.annotations.AdminResource;
13  import java.util.Map;
14  import javax.inject.Inject;
15  import javax.ws.rs.Consumes;
16  import javax.ws.rs.GET;
17  import javax.ws.rs.Path;
18  import javax.ws.rs.PathParam;
19  import javax.ws.rs.Produces;
20  import javax.ws.rs.core.MediaType;
21  
22  /**
23   * REST MonitoringRestEndpoint to monitor the system
24   *
25   * @author maxence
26   */
27  @Path("monitoring")
28  @Consumes(MediaType.APPLICATION_JSON)
29  @Produces(MediaType.APPLICATION_JSON)
30  public class MonitoringRestEndpoint {
31  
32      /**
33       * Monitoring business logic
34       */
35      @Inject
36      private MonitoringManager monitoringManager;
37  
38      /**
39       * Simple dummy method which return 200 OK
40       *
41       * @return "Running"
42       */
43      @GET
44      @Path("status")
45      public String getStatus() {
46          return "Running";
47      }
48  
49      /**
50       * Get current version
51       *
52       * @return details about current deployed version
53       */
54      @GET
55      @Path("version")
56      public VersionDetails getVersion() {
57          return monitoringManager.getVersionDetails();
58      }
59  
60      /**
61       * Change level of a logger
62       *
63       * @param loggerName name of the logger to update
64       * @param level      new level of the logger
65       */
66      @GET
67      @Path("SetLoggerLevel/{loggerName}/{level}")
68      @AdminResource
69      public void changeLoggerLevel(
70          @PathParam("loggerName") String loggerName,
71          @PathParam("level") String level
72      ) {
73          monitoringManager.changeLogerLevelClusterWide(loggerName, level);
74      }
75  
76      /**
77       * Get the description of all known co.LAB logger by providing their current level.
78       *
79       * @return all known levelDescriptor mapped by the name of the logger
80       */
81      @GET
82      @Path("GetLoggerLevels")
83      @AdminResource
84      public Map<String, LevelDescriptor> getLoggerLevels() {
85          return monitoringManager.getLoggerLevels();
86      }
87  }