From 5d5217a4977cde5f58ec79bf4a99253a0cba4ccf Mon Sep 17 00:00:00 2001 From: Simone Pandolfi Date: Mon, 22 Jan 2018 17:27:34 +0100 Subject: [PATCH 1/3] Added support for the 'search' endpoint --- .../appnexus/grafana/client/GrafanaClient.java | 14 ++++++++++++++ .../appnexus/grafana/client/GrafanaService.java | 12 ++++++++++++ .../grafana/client/models/GrafanaSearch.java | 17 +++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/main/java/com/appnexus/grafana/client/models/GrafanaSearch.java diff --git a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java index a76a3cd..72bbdae 100644 --- a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java +++ b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java @@ -9,6 +9,7 @@ import com.appnexus.grafana.client.models.DashboardSuccessfulDelete; import com.appnexus.grafana.client.models.GrafanaDashboard; import com.appnexus.grafana.client.models.GrafanaMessage; +import com.appnexus.grafana.client.models.GrafanaSearch; import com.appnexus.grafana.configuration.GrafanaConfiguration; import com.appnexus.grafana.exceptions.GrafanaDashboardCouldNotDeleteException; import com.appnexus.grafana.exceptions.GrafanaDashboardDoesNotExistException; @@ -274,4 +275,17 @@ public DashboardPanelAlert getAlert(Integer id) throws GrafanaException, IOExcep throw GrafanaException.withErrorBody(response.errorBody()); } } + + public List search(String query, String tag, Boolean starred, Boolean tagcloud) + throws GrafanaException, IOException { + + Response> response = + service.search(apiKey, query, tag, starred, tagcloud).execute(); + + if (response.isSuccessful()) { + return response.body(); + } else { + throw GrafanaException.withErrorBody(response.errorBody()); + } + } } diff --git a/src/main/java/com/appnexus/grafana/client/GrafanaService.java b/src/main/java/com/appnexus/grafana/client/GrafanaService.java index a0b3d9f..233b754 100644 --- a/src/main/java/com/appnexus/grafana/client/GrafanaService.java +++ b/src/main/java/com/appnexus/grafana/client/GrafanaService.java @@ -7,6 +7,7 @@ import com.appnexus.grafana.client.models.DashboardSuccessfulDelete; import com.appnexus.grafana.client.models.GrafanaDashboard; import com.appnexus.grafana.client.models.GrafanaMessage; +import com.appnexus.grafana.client.models.GrafanaSearch; import java.util.List; import retrofit2.Call; import retrofit2.http.Body; @@ -16,11 +17,13 @@ import retrofit2.http.POST; import retrofit2.http.PUT; import retrofit2.http.Path; +import retrofit2.http.Query; public interface GrafanaService { String GRAFANA_DASHBOARDS = "api/dashboards/db/"; String GRAFANA_NOTIFICATIONS = "api/alert-notifications/"; String GRAFANA_ALERTS = "api/alerts/"; + String GRAFANA_SEARCH = "api/search/"; String AUTHORIZATION = "Authorization"; @@ -63,4 +66,13 @@ Call deleteNotification( @GET(GRAFANA_ALERTS + "{id}") Call getAlert( @Header(AUTHORIZATION) String authorization, @Path("id") Integer id); + + // Search + @GET(GRAFANA_SEARCH) + Call> search( + @Header(AUTHORIZATION) String authorization, + @Query("query") String query, + @Query("tag") String tag, + @Query("starred") Boolean starred, + @Query("tagcloud") Boolean tagcloud); } diff --git a/src/main/java/com/appnexus/grafana/client/models/GrafanaSearch.java b/src/main/java/com/appnexus/grafana/client/models/GrafanaSearch.java new file mode 100644 index 0000000..55120e9 --- /dev/null +++ b/src/main/java/com/appnexus/grafana/client/models/GrafanaSearch.java @@ -0,0 +1,17 @@ +/* Licensed under Apache-2.0 */ +package com.appnexus.grafana.client.models; + +import java.util.List; +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(fluent = true) +public class GrafanaSearch { + Long id; + String title; + String uri; + String type; + List tags; + Boolean isStarred; +} From af0647c984928e7ca6b2e31502a8c471163eaa05 Mon Sep 17 00:00:00 2001 From: Simone Pandolfi Date: Thu, 25 Jan 2018 16:07:15 +0100 Subject: [PATCH 2/3] Renamed 'GrafanaSearch' model in 'GrafanaSearchResult' --- .../java/com/appnexus/grafana/client/GrafanaClient.java | 6 +++--- .../java/com/appnexus/grafana/client/GrafanaService.java | 4 ++-- .../models/{GrafanaSearch.java => GrafanaSearchResult.java} | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/com/appnexus/grafana/client/models/{GrafanaSearch.java => GrafanaSearchResult.java} (89%) diff --git a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java index 72bbdae..d5abe39 100644 --- a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java +++ b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java @@ -9,7 +9,7 @@ import com.appnexus.grafana.client.models.DashboardSuccessfulDelete; import com.appnexus.grafana.client.models.GrafanaDashboard; import com.appnexus.grafana.client.models.GrafanaMessage; -import com.appnexus.grafana.client.models.GrafanaSearch; +import com.appnexus.grafana.client.models.GrafanaSearchResult; import com.appnexus.grafana.configuration.GrafanaConfiguration; import com.appnexus.grafana.exceptions.GrafanaDashboardCouldNotDeleteException; import com.appnexus.grafana.exceptions.GrafanaDashboardDoesNotExistException; @@ -276,10 +276,10 @@ public DashboardPanelAlert getAlert(Integer id) throws GrafanaException, IOExcep } } - public List search(String query, String tag, Boolean starred, Boolean tagcloud) + public List search(String query, String tag, Boolean starred, Boolean tagcloud) throws GrafanaException, IOException { - Response> response = + Response> response = service.search(apiKey, query, tag, starred, tagcloud).execute(); if (response.isSuccessful()) { diff --git a/src/main/java/com/appnexus/grafana/client/GrafanaService.java b/src/main/java/com/appnexus/grafana/client/GrafanaService.java index 233b754..46de7ca 100644 --- a/src/main/java/com/appnexus/grafana/client/GrafanaService.java +++ b/src/main/java/com/appnexus/grafana/client/GrafanaService.java @@ -7,7 +7,7 @@ import com.appnexus.grafana.client.models.DashboardSuccessfulDelete; import com.appnexus.grafana.client.models.GrafanaDashboard; import com.appnexus.grafana.client.models.GrafanaMessage; -import com.appnexus.grafana.client.models.GrafanaSearch; +import com.appnexus.grafana.client.models.GrafanaSearchResult; import java.util.List; import retrofit2.Call; import retrofit2.http.Body; @@ -69,7 +69,7 @@ Call getAlert( // Search @GET(GRAFANA_SEARCH) - Call> search( + Call> search( @Header(AUTHORIZATION) String authorization, @Query("query") String query, @Query("tag") String tag, diff --git a/src/main/java/com/appnexus/grafana/client/models/GrafanaSearch.java b/src/main/java/com/appnexus/grafana/client/models/GrafanaSearchResult.java similarity index 89% rename from src/main/java/com/appnexus/grafana/client/models/GrafanaSearch.java rename to src/main/java/com/appnexus/grafana/client/models/GrafanaSearchResult.java index 55120e9..219ae12 100644 --- a/src/main/java/com/appnexus/grafana/client/models/GrafanaSearch.java +++ b/src/main/java/com/appnexus/grafana/client/models/GrafanaSearchResult.java @@ -7,7 +7,7 @@ @Data @Accessors(fluent = true) -public class GrafanaSearch { +public class GrafanaSearchResult { Long id; String title; String uri; From 3256547f320ce6afcb953714ec662ab49b4b0ece Mon Sep 17 00:00:00 2001 From: Simone Pandolfi Date: Fri, 26 Jan 2018 10:11:16 +0100 Subject: [PATCH 3/3] Fixed the formatting of 'GrafanaClient.java' --- src/main/java/com/appnexus/grafana/client/GrafanaClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java index d5abe39..22d2a9b 100644 --- a/src/main/java/com/appnexus/grafana/client/GrafanaClient.java +++ b/src/main/java/com/appnexus/grafana/client/GrafanaClient.java @@ -276,7 +276,8 @@ public DashboardPanelAlert getAlert(Integer id) throws GrafanaException, IOExcep } } - public List search(String query, String tag, Boolean starred, Boolean tagcloud) + public List search( + String query, String tag, Boolean starred, Boolean tagcloud) throws GrafanaException, IOException { Response> response =