View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.statistics.api;
23  
24  
25  import java.time.Duration;
26  import java.time.Instant;
27  import java.time.ZoneId;
28  import java.util.Optional;
29  import java.util.Set;
30  import java.util.concurrent.TimeUnit;
31  
32  /**
33   * Statistics service API.
34   *
35   */
36  public interface StatisticsService {
37  
38    /**
39     * Identifier for service registration and location
40     */
41    String JOB_TYPE = "org.opencastproject.statistics";
42  
43    /**
44     * @return All active providers.
45     */
46    Set<StatisticsProvider> getProviders();
47  
48    /**
49     * @param resourceType
50     *          The resource type.
51     *
52     * @return All active providers for the given resource type.
53     */
54    Set<StatisticsProvider> getProviders(ResourceType resourceType);
55  
56    /**
57     * @param providerId
58     *          The provider id.
59     *
60     * @return Optionally return the provider with the given id (if any).
61     */
62    Optional<StatisticsProvider> getProvider(String providerId);
63  
64    /**
65     * Get time series statistics data from the given Provider.
66     *
67     * @param provider
68     *          The provider to retrieve statistics from.
69     * @param resourceId
70     *          The id to access the resource to get statistics for (e.g. episode Id, organization Id or series Id).
71     * @param from
72     *          The start date to calculate the statistics for.
73     * @param to
74     *          The end date to calculate the statistics for.
75     * @param resolution
76     *          The resolution to get the statistics with.
77     * @param zoneId
78     *          The timezone to use for date calculations.
79     * @return The time series data.
80     */
81    TimeSeries getTimeSeriesData(
82        StatisticsProvider provider,
83        String resourceId,
84        Instant from,
85        Instant to,
86        DataResolution resolution,
87        ZoneId zoneId
88    );
89  
90    /**
91     * Write a duration to a statistics data base
92     *
93     * @param organizationId Organization ID of the data point
94     * @param measurementName Measurement name of the data point
95     * @param retentionPolicy Retention policy of the data point
96     * @param organizationIdResourceName Resource name for the organization
97     * @param fieldName Field name to write
98     * @param temporalResolution The temporal resolution to store it in
99     * @param duration The actual duration to write
100    */
101   void writeDuration(
102           String organizationId,
103           String measurementName,
104           String retentionPolicy,
105           String organizationIdResourceName,
106           String fieldName,
107           TimeUnit temporalResolution,
108           Duration duration);
109 }