This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit b644a89a5c23ff2f8fa19b0e2bd3a4e779b60da2 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Fri Jun 28 10:48:07 2024 +0200 CAMEL-20798: EndpointServiceLocation on components to make it possible to know which remote system Camel connects to to assist for monitoring and observability - Google Calendar/Calendar Stream Signed-off-by: Andrea Cosentino <anco...@gmail.com> --- .../google/calendar/GoogleCalendarEndpoint.java | 25 ++++++++++++++++++++- .../stream/GoogleCalendarStreamEndpoint.java | 26 +++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java index 4cb22fb5be9..57a00b0bba7 100644 --- a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java +++ b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/GoogleCalendarEndpoint.java @@ -27,11 +27,13 @@ import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiColl import org.apache.camel.component.google.calendar.internal.GoogleCalendarApiName; import org.apache.camel.component.google.calendar.internal.GoogleCalendarConstants; import org.apache.camel.component.google.calendar.internal.GoogleCalendarPropertiesHelper; +import org.apache.camel.spi.EndpointServiceLocation; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.component.AbstractApiEndpoint; import org.apache.camel.support.component.ApiMethod; import org.apache.camel.support.component.ApiMethodPropertiesHelper; +import org.apache.camel.util.ObjectHelper; /** * Perform various operations on a Google Calendar. @@ -39,7 +41,7 @@ import org.apache.camel.support.component.ApiMethodPropertiesHelper; @UriEndpoint(firstVersion = "2.15.0", scheme = "google-calendar", title = "Google Calendar", syntax = "google-calendar:apiName/methodName", apiSyntax = "apiName/methodName", consumerPrefix = "consumer", category = { Category.API, Category.CLOUD }) -public class GoogleCalendarEndpoint extends AbstractApiEndpoint<GoogleCalendarApiName, GoogleCalendarConfiguration> { +public class GoogleCalendarEndpoint extends AbstractApiEndpoint<GoogleCalendarApiName, GoogleCalendarConfiguration> implements EndpointServiceLocation { @UriParam private GoogleCalendarConfiguration configuration; @@ -122,4 +124,25 @@ public class GoogleCalendarEndpoint extends AbstractApiEndpoint<GoogleCalendarAp return apiProxy; } + @Override + public String getServiceUrl() { + if (ObjectHelper.isNotEmpty(ObjectHelper.isNotEmpty(configuration.getApiName()) && ObjectHelper.isNotEmpty(configuration.getMethodName()))) { + return getServiceProtocol() + ":" + configuration.getApiName() + ":" + configuration.getMethodName(); + } + return null; + } + + @Override + public String getServiceProtocol() { + return "calendar"; + } + + @Override + public Map<String, String> getServiceMetadata() { + if (configuration.getApplicationName() != null) { + return Map.of("applicationName", configuration.getApplicationName()); + } + return null; + } + } diff --git a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java index 87d23f0df7d..7e8c97aea9b 100644 --- a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java +++ b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/stream/GoogleCalendarStreamEndpoint.java @@ -25,11 +25,14 @@ import org.apache.camel.ExchangePattern; import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.spi.EndpointServiceLocation; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.ScheduledPollEndpoint; import org.apache.camel.util.ObjectHelper; +import java.util.Map; + /** * Poll for changes in a Google Calendar. */ @@ -39,7 +42,7 @@ import org.apache.camel.util.ObjectHelper; syntax = "google-calendar-stream:index", consumerOnly = true, category = { Category.CLOUD }, headersClass = GoogleCalendarStreamConstants.class) -public class GoogleCalendarStreamEndpoint extends ScheduledPollEndpoint { +public class GoogleCalendarStreamEndpoint extends ScheduledPollEndpoint implements EndpointServiceLocation { @UriParam private GoogleCalendarStreamConfiguration configuration; @@ -87,4 +90,25 @@ public class GoogleCalendarStreamEndpoint extends ScheduledPollEndpoint { message.setHeader(GoogleCalendarStreamConstants.EVENT_ID, event.getId()); return exchange; } + + @Override + public String getServiceUrl() { + if (ObjectHelper.isNotEmpty(ObjectHelper.isNotEmpty(configuration.getCalendarId()) && ObjectHelper.isNotEmpty(configuration.getUser()))) { + return getServiceProtocol() + ":" + configuration.getUser() + ":" + configuration.getCalendarId(); + } + return null; + } + + @Override + public String getServiceProtocol() { + return "calendar-stream"; + } + + @Override + public Map<String, String> getServiceMetadata() { + if (configuration.getApplicationName() != null) { + return Map.of("applicationName", configuration.getApplicationName()); + } + return null; + } }