davsclaus commented on code in PR #30592:
URL: https://github.com/apache/camel/pull/30592#discussion_r4657725111
##########
dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderKamelet.java:
##########
@@ -109,6 +134,131 @@ public void loadRouteTemplate(Resource resource) {
}
}
+ @Override
+ public void onAddRouteDefinition(RouteDefinition routeDefinition) {
+ // the Kamelets of the route are created after all the routes, when
the CamelContext is initialized: their
+ // dependencies are downloaded now, so the route can use their classes
(CAMEL-27364)
+ if (downloader == null) {
+ return;
+ }
+ List<String> uris = new ArrayList<>();
+ if (routeDefinition.getInput() != null) {
+ uris.add(routeDefinition.getInput().getEndpointUri());
+ }
+ for (EndpointRequiredDefinition erd :
ProcessorDefinitionHelper.filterTypeInOutputs(routeDefinition.getOutputs(),
+ EndpointRequiredDefinition.class)) {
+ uris.add(erd.getEndpointUri());
+ }
+ for (String uri : uris) {
+ String name = kameletName(uri);
+ if (name != null && kamelets.add(name)) {
+ try {
+ Resource resource = resolveKamelet(name,
kameletLocation(uri));
+ if (resource != null) {
+ LOG.debug("Downloading the dependencies of Kamelet: {}
used by route: {}", name,
+ routeDefinition.getRouteId());
+ loadRouteTemplate(resource);
+ }
+ } catch (Exception e) {
+ // the dependencies are then downloaded when the Kamelet
is loaded, which reports the error
+ LOG.debug("Cannot download the dependencies of Kamelet: {}
due to: {}", name, e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onRemoveRouteDefinition(RouteDefinition routeDefinition) {
+ // noop
+ }
+
+ @Override
+ public void onAddRouteTemplateDefinition(RouteTemplateDefinition
routeTemplateDefinition) {
+ // noop
+ }
+
+ @Override
+ public void onRemoveRouteTemplateDefinition(RouteTemplateDefinition
routeTemplateDefinition) {
+ // noop
+ }
+
+ /**
+ * The name of the Kamelet of a kamelet: endpoint uri, or null when it is
not one, it is kamelet:source or
+ * kamelet:sink (the template of a Kamelet), or the name is a placeholder
or an expression.
+ */
+ static String kameletName(String uri) {
+ if (uri == null || !uri.startsWith("kamelet:")) {
+ return null;
+ }
+ String name =
FileUtil.stripLeadingSeparator(uri.substring("kamelet:".length()));
+ int q = name.indexOf('?');
+ if (q >= 0) {
+ name = name.substring(0, q);
+ }
+ int slash = name.indexOf('/');
+ if (slash >= 0) {
+ // kamelet:name/routeId
+ name = name.substring(0, slash);
+ }
+ if (name.isEmpty() || Kamelet.SOURCE_ID.equals(name) ||
Kamelet.SINK_ID.equals(name)
+ || name.contains("{{") || name.contains("${")) {
+ return null;
+ }
+ return name;
+ }
+
+ /**
+ * The location of the Kamelets: the location option of the endpoint,
otherwise the one of the kamelet component.
+ */
+ private String kameletLocation(String uri) {
+ int q = uri.indexOf('?');
+ if (q >= 0) {
+ try {
+ Map<String, Object> parameters =
URISupport.parseQuery(uri.substring(q + 1));
+ Object loc = parameters.get(Kamelet.PARAM_LOCATION);
+ if (loc != null) {
+ return loc.toString();
+ }
+ } catch (Exception e) {
+ // use the location of the component
+ }
Review Comment:
Fixed in 0b7f19689293: the catch now logs at DEBUG (the uri sanitized, with
the exception) that the query cannot be parsed and the location of the kamelet
component is used.
_Claude Code on behalf of davsclaus_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]