View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.starter.actuate;
20  
21  import java.util.Map;
22  import org.apache.syncope.core.persistence.api.dao.EntityCacheDAO;
23  import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
24  import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
25  import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
26  import org.springframework.boot.actuate.endpoint.annotation.Selector;
27  import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
28  import org.springframework.http.HttpStatus;
29  import org.springframework.web.server.ResponseStatusException;
30  
31  @Endpoint(id = "entityCache")
32  public class EntityCacheEndpoint {
33  
34      protected final EntityCacheDAO entityCacheDAO;
35  
36      public EntityCacheEndpoint(final EntityCacheDAO entityCacheDAO) {
37          this.entityCacheDAO = entityCacheDAO;
38      }
39  
40      @ReadOperation
41      public Map<String, Object> statistics() {
42          return entityCacheDAO.getStatistics();
43      }
44  
45      @WriteOperation
46      public void statistics(final @Selector String operation) {
47          switch (operation) {
48              case "enable":
49              case "ENABLE":
50                  entityCacheDAO.enableStatistics();
51                  break;
52  
53              case "disable":
54              case "DISABLE":
55                  entityCacheDAO.disableStatistics();
56                  break;
57  
58              case "reset":
59              case "RESET":
60                  entityCacheDAO.resetStatistics();
61                  break;
62  
63              default:
64                  throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Unsupported Operation: " + operation);
65          }
66      }
67  
68      @DeleteOperation
69      public void clearCache() {
70          entityCacheDAO.clearCache();
71      }
72  }